From d7c7ec0174cde9436879fb204f89f8ca508a700e Mon Sep 17 00:00:00 2001 From: CismonX Date: Wed, 19 Mar 2025 12:25:30 +0800 Subject: [PATCH] bookmarkctl: xattr: misc refactor --- doc/bookmarkctl.1 | 10 ++++++++-- doc/bookmarkfs.texi | 8 ++++++++ src/bookmarkctl.c | 30 ++++++++++++------------------ src/xattr.c | 2 +- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/doc/bookmarkctl.1 b/doc/bookmarkctl.1 index 1254185..849901f 100644 --- a/doc/bookmarkctl.1 +++ b/doc/bookmarkctl.1 @@ -120,10 +120,16 @@ Exchange the positions of the directory entries represented by and .IR name2 . .TP -.BR \-b ", " \-a +.B \-b Move the directory entry represented by .I name1 -to the position just before/after the one represented by +to the position just before the one represented by +.IR name2 . +.TP +.B \-a +Move the directory entry represented by +.I name1 +to the position just after the one represented by .IR name2 . .PP The diff --git a/doc/bookmarkfs.texi b/doc/bookmarkfs.texi index ed4e147..00ebc4a 100644 --- a/doc/bookmarkfs.texi +++ b/doc/bookmarkfs.texi @@ -697,8 +697,16 @@ If this option is not provided, the new value is read from standard input. @item help Print help text, and then exit. +@example +bookmarkctl help +@end example + @item version Print version information, and then exit. + +@example +bookmarkctl version +@end example @end table diff --git a/src/bookmarkctl.c b/src/bookmarkctl.c index 9124726..bf33234 100644 --- a/src/bookmarkctl.c +++ b/src/bookmarkctl.c @@ -41,16 +41,14 @@ #include "xattr.h" #include "xstd.h" -#define BMCTL_XATTR_GET_NOEOL (1u << 0) -#define BMCTL_XATTR_GET_BINARY (1u << 1) -#define BMCTL_XATTR_GET_MULTI (1u << 2) -#define BMCTL_XATTR_GET_QUIET (1u << 3) - struct xattr_get_ctx { char const *prefix; + unsigned quiet; char sep; char eol; - uint32_t flags; + + unsigned binary : 1; + unsigned multi_name : 1; }; // Forward declaration start @@ -248,18 +246,15 @@ subcmd_xattr_get ( break; } OPT_OPT('b') { - ctx.flags |= BMCTL_XATTR_GET_BINARY; + ctx.binary = 1; break; } OPT_OPT('m') { - ctx.flags |= BMCTL_XATTR_GET_MULTI; + ctx.multi_name = 1; break; } OPT_OPT('q') { - if (ctx.flags & BMCTL_XATTR_GET_QUIET) { - ctx.flags |= BMCTL_XATTR_GET_NOEOL; - } - ctx.flags |= BMCTL_XATTR_GET_QUIET; + ++ctx.quiet; break; } OPT_OPT('s') { @@ -274,7 +269,7 @@ subcmd_xattr_get ( return -1; } - if (ctx.flags & BMCTL_XATTR_GET_MULTI) { + if (ctx.multi_name) { return xattr_get_one(argv[argc - 1], argv, argc - 1, &ctx); } for (int i = 1; i < argc; ++i) { @@ -379,14 +374,13 @@ xattr_get_cb ( ) { struct xattr_get_ctx const *ctx = user_data; - uint32_t flags = ctx->flags; - if (!(flags & BMCTL_XATTR_GET_QUIET)) { + if (ctx->quiet < 1) { if (0 > printf("%s%c", ctx->prefix, ctx->sep)) { log_printf("printf(): %s", strerror(errno)); return -1; } } - if (!(flags & BMCTL_XATTR_GET_BINARY)) { + if (!ctx->binary) { for (unsigned char *s = buf, *end = s; s < end; ++s) { if (iscntrl(*s)) { *s = '?'; @@ -397,7 +391,7 @@ xattr_get_cb ( log_printf("fwrite(): %s", strerror(errno)); return -1; } - if (!(flags & BMCTL_XATTR_GET_NOEOL)) { + if (ctx->quiet < 2) { if (EOF == fputc(ctx->eol, stdout)) { log_printf("fputc(): %s", strerror(errno)); return -1; @@ -422,7 +416,7 @@ xattr_get_one ( for (int i = 0; i < names_cnt; ++i) { char const *name = names[i]; - ctx->prefix = (ctx->flags & BMCTL_XATTR_GET_MULTI) ? name : path; + ctx->prefix = ctx->multi_name ? name : path; status = bookmarkfs_xattr_get(fd, name, xattr_get_cb, ctx); if (status < 0) { goto end; diff --git a/src/xattr.c b/src/xattr.c index f7e696c..6d632ce 100644 --- a/src/xattr.c +++ b/src/xattr.c @@ -107,7 +107,7 @@ xattr_do_set ( size_t buf_len ) { #if defined(__linux__) - if (0 != fsetxattr(fd, name, buf, buf_len, 0)) { + if (0 != fsetxattr(fd, name, buf, buf_len, XATTR_REPLACE)) { log_printf("fsetxattr(): %s", strerror(errno)); return -1; }