mirror of
https://git.sr.ht/~cismonx/bookmarkfs
synced 2025-06-07 19:58:50 +00:00
bookmarkctl: better handling of command-line args
This commit is contained in:
parent
68aafe3d8d
commit
2ce0be8a18
3 changed files with 81 additions and 79 deletions
|
@ -9,14 +9,13 @@ bookmarkctl - manage a mounted BookmarkFS filesystem
|
|||
.RI [ args ]
|
||||
.PP
|
||||
.B "bookmarkctl permd"
|
||||
.I pathname
|
||||
.I op
|
||||
.RI [ options ]
|
||||
.I name1
|
||||
.I name2
|
||||
.I pathname
|
||||
.PP
|
||||
.B "bookmarkctl fsck"
|
||||
.I pathname
|
||||
.I op
|
||||
.PP
|
||||
.B "bookmarkctl help"
|
||||
.PP
|
||||
|
@ -30,7 +29,8 @@ filesystem.
|
|||
.SS Permute directory entries
|
||||
The
|
||||
.B permd
|
||||
sub-command re-arranges the order of the directory entries returned from
|
||||
sub-command re-arranges the order of the directory entries to be returned
|
||||
from future
|
||||
.BR readdir (3)
|
||||
calls.
|
||||
.PP
|
||||
|
@ -42,41 +42,38 @@ The
|
|||
and
|
||||
.I name2
|
||||
arguments are filenames under that directory.
|
||||
.PP
|
||||
.SS Filesystem check
|
||||
The
|
||||
.I op
|
||||
argument is the operation to perform on the directory:
|
||||
.B fsck
|
||||
sub-command displays a list of filesystem errors found under the directory
|
||||
referred to by
|
||||
.IR pathname .
|
||||
It does not recurse into subdirectories.
|
||||
.PP
|
||||
For the full fsck functionalities, use
|
||||
.BR fsck.bookmarkfs (1).
|
||||
.
|
||||
.SH OPTIONS
|
||||
.SS Permute directory entries
|
||||
.TP
|
||||
.B swap
|
||||
.B \-s
|
||||
Exchange the positions of the directory entries represented by
|
||||
.I name1
|
||||
and
|
||||
.IR name2 .
|
||||
.TP
|
||||
.BR move\-before | move\-after
|
||||
.BR \-b ", " \-a
|
||||
Move the directory entry represented by
|
||||
.I name1
|
||||
to the position just before/after the one represented by
|
||||
.IR name2 .
|
||||
.SS Filesystem check
|
||||
The
|
||||
.B fsck
|
||||
sub-command checks for errors within a BookmarkFS filesystem.
|
||||
.PP
|
||||
The
|
||||
.I pathname
|
||||
argument is the path to the directory to perform checks on.
|
||||
.PP
|
||||
The
|
||||
.I op
|
||||
argument is the operation to perform on the directory:
|
||||
.TP
|
||||
.B list
|
||||
Display a list of errors found under the given directory.
|
||||
Will not recurse into subdirectories.
|
||||
.PP
|
||||
For the full fsck functionalities, use
|
||||
.BR fsck.bookmarkfs (1).
|
||||
.BR \-s ", " \-b
|
||||
and
|
||||
.B \-a
|
||||
options are mutually exclusive.
|
||||
If multiple options are provided, the last one takes effect.
|
||||
.
|
||||
.SH EXIT STATUS
|
||||
.TP
|
||||
|
|
|
@ -547,59 +547,55 @@ Sub-commands:
|
|||
|
||||
@table @command
|
||||
@item permd
|
||||
Rearranges the order of the directory entries obtained from @code{readdir()}.
|
||||
Rearranges the order of the directory entries to be returned from
|
||||
future calls to @code{readdir()}.
|
||||
@xref{Permute Directory Entries}.
|
||||
|
||||
@example
|
||||
bookmarkctl permd @var{pathname} @var{op} @var{name1} @var{name2}
|
||||
bookmarkctl permd [@var{options}] @var{name1} @var{name2} @var{pathname}
|
||||
@end example
|
||||
|
||||
@table @var
|
||||
@item pathname
|
||||
Path to the directory.
|
||||
|
||||
@item name1
|
||||
@item name2
|
||||
Filename of entries under the directory.
|
||||
|
||||
@item op
|
||||
Operation to perform on the directory:
|
||||
@item pathname
|
||||
Path to the parent directory.
|
||||
@end table
|
||||
|
||||
@table @samp
|
||||
@item swap
|
||||
Options:
|
||||
|
||||
@table @option
|
||||
@item -s
|
||||
Exchange the positions of the directory entries represented by @var{name1}
|
||||
and @var{name2}.
|
||||
|
||||
@item move-before
|
||||
@item -b
|
||||
Move the directory entry represented by @var{name1} to the position just
|
||||
@emph{before} the one represented by @var{name2}.
|
||||
|
||||
@item move-after
|
||||
@item -a
|
||||
Move the directory entry represented by @var{name1} to the position just
|
||||
@emph{after} the one represented by @var{name2}.
|
||||
@end table
|
||||
@end table
|
||||
|
||||
The @option{-s}, @option{-b} and @option{-a} options are mutually exclusive.
|
||||
If multiple options are provided, the last one takes effect.
|
||||
|
||||
@item fsck
|
||||
Check for errors within a BookmarkFS filesystem.
|
||||
Displays a list of filesystem errors found under the given directory.
|
||||
@xref{Filesystem Check}.
|
||||
|
||||
Does not recurse into subdirectories.
|
||||
|
||||
@example
|
||||
bookmarkctl fsck @var{pathname} @var{op}
|
||||
bookmarkctl fsck @var{pathname}
|
||||
@end example
|
||||
|
||||
@table @var
|
||||
@item pathname
|
||||
Path to the directory to perform checks on.
|
||||
|
||||
@item op
|
||||
Operation to perform on the directory:
|
||||
|
||||
@table @samp
|
||||
@item list
|
||||
Display a list of errors found under the given directory.
|
||||
Will not recurse into subdirectories.
|
||||
@end table
|
||||
@end table
|
||||
|
||||
For the full fsck functionalities, @pxref{fsck.bookmarkfs}.
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "frontend_util.h"
|
||||
#include "fsck_util.h"
|
||||
#include "ioctl.h"
|
||||
#include "macros.h"
|
||||
|
@ -104,21 +105,15 @@ subcmd_fsck (
|
|||
int argc,
|
||||
char *argv[]
|
||||
) {
|
||||
#define FSCK_NARGS 2
|
||||
if (--argc != FSCK_NARGS) {
|
||||
log_printf("fsck: " STRINGIFY(FSCK_NARGS) " args expected, %d given",
|
||||
argc);
|
||||
return -1;
|
||||
}
|
||||
char const *path = *(++argv);
|
||||
char const *opstr = *(++argv);
|
||||
|
||||
if (0 == strcmp("list", opstr)) {
|
||||
// NOOP
|
||||
} else {
|
||||
log_printf("fsck: bad operation name '%s'", opstr);
|
||||
if (--argc != 1) {
|
||||
if (argc == 0) {
|
||||
log_puts("fsck: pathname must be specified");
|
||||
} else {
|
||||
log_puts("fsck: too many arguments");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
char const *path = *(++argv);
|
||||
|
||||
int dirfd = open(path, O_RDONLY | O_DIRECTORY);
|
||||
if (dirfd < 0) {
|
||||
|
@ -138,8 +133,10 @@ subcmd_fsck (
|
|||
break;
|
||||
}
|
||||
} while (status != BOOKMARKFS_FSCK_RESULT_END);
|
||||
|
||||
close(dirfd);
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -147,29 +144,41 @@ subcmd_permd (
|
|||
int argc,
|
||||
char *argv[]
|
||||
) {
|
||||
#define PERMD_NARGS 4
|
||||
if (--argc != PERMD_NARGS) {
|
||||
log_printf("permd: " STRINGIFY(PERMD_NARGS) " args expected, %d given",
|
||||
argc);
|
||||
int op = -1;
|
||||
|
||||
OPT_START(argc, argv, "sba")
|
||||
OPT_OPT('s') {
|
||||
op = BOOKMARKFS_PERMD_OP_SWAP;
|
||||
break;
|
||||
}
|
||||
OPT_OPT('b') {
|
||||
op = BOOKMARKFS_PERMD_OP_MOVE_BEFORE;
|
||||
break;
|
||||
}
|
||||
OPT_OPT('a') {
|
||||
op = BOOKMARKFS_PERMD_OP_MOVE_AFTER;
|
||||
break;
|
||||
}
|
||||
OPT_END
|
||||
|
||||
if (op < 0) {
|
||||
log_puts("permd: no operation specified");
|
||||
return -1;
|
||||
}
|
||||
char const *path = *(++argv);
|
||||
char const *opstr = *(++argv);
|
||||
char const *name1 = *(++argv);
|
||||
char const *name2 = *(++argv);
|
||||
|
||||
struct bookmarkfs_permd_data permd_data;
|
||||
permd_data.op = op;
|
||||
|
||||
if (0 == strcmp("swap", opstr)) {
|
||||
permd_data.op = BOOKMARKFS_PERMD_OP_SWAP;
|
||||
} else if (0 == strcmp("move-before", opstr)) {
|
||||
permd_data.op = BOOKMARKFS_PERMD_OP_MOVE_BEFORE;
|
||||
} else if (0 == strcmp("move-after", opstr)) {
|
||||
permd_data.op = BOOKMARKFS_PERMD_OP_MOVE_AFTER;
|
||||
} else {
|
||||
log_printf("permd: bad operation name '%s'", opstr);
|
||||
if (argc != 3) {
|
||||
if (argc < 3) {
|
||||
log_puts("permd: dentry names and dir path must be specified");
|
||||
} else {
|
||||
log_puts("permd: too many arguments");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
char const *name1 = argv[0];
|
||||
char const *name2 = argv[1];
|
||||
char const *path = argv[2];
|
||||
|
||||
#define COPY_NAME(dst, src) \
|
||||
if ((dst) + sizeof(dst) == stpncpy(dst, src, sizeof(dst))) { \
|
||||
|
|
Loading…
Add table
Reference in a new issue