Goffredo Baroncelli
2011-Jul-19 16:11 UTC
[PATCH 0/6] Move the infor for the help/man page in the source
The following series implement a way to generate the help messages and the btrfs man page from the sources comments for the "btrfs" commanda . The syntax and the detailed help of every subcommand are stored in the comments before the function which implements the subcommand. The fact that the help messages and the man page are generated from the same source should help to avoid incoherencies and mistakes. Moreover tha fact that the source and the help are strictly linked helps to avoid man page/help outdated. You can pull the changes from You can download the source from http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git branch extended-help and/or browse the code at http://cassiopea.homelinux.net/git/?p=btrfs-progs-unstable.git BR G.Baroncelli --- Goffredo Baroncelli (6): Add info for the commands. Add the header/footer/introduction of the man page. helpextract: tool to extract the info for the help from the source. Update the makefile for generating the man page. Show the help messages from the info in the comment. Update the makefile for generating the help messages. Makefile | 28 +++ btrfs.c | 210 +++++++++++++++++++++++++ btrfs_cmds.c | 276 +++++++++++++++++++++++++++++++++ helpextract.c | 435 ++++++++++++++++++++++++++++++++++++++++++++++++++++ man/btrfs.8.in | 359 ------------------------------------------- man/btrfs.8.in.old | 359 +++++++++++++++++++++++++++++++++++++++++++ scrub.c | 79 +++++++++ 7 files changed, 1380 insertions(+), 366 deletions(-) create mode 100644 helpextract.c delete mode 100644 man/btrfs.8.in create mode 100644 man/btrfs.8.in.old -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Goffredo Baroncelli <kreijack@inwind.it> Add info for every btrfs sub-commands in the sources. --- btrfs_cmds.c | 276 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ scrub.c | 79 +++++++++++++++++ 2 files changed, 355 insertions(+), 0 deletions(-) diff --git a/btrfs_cmds.c b/btrfs_cmds.c index 0612f34..3cdebea 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -156,6 +156,42 @@ static int parse_compress_type(char *s) }; } + +/**** man: btrfs filesystem defragment + * + * \Bbtrfs\b \Bfilesystem defragment\b -c[zlib|lzo] [-l \Ilen\i] [-s \Istart\i] [-t \Isize\i] -[vf] <\Ifile\i>|<\Idir\i> [<\Ifile\i>|<\Idir\i>...] + * + * Defragment a file or a directory. + * + * Defragment file data and/or directory metadata. To defragment all files in a + * directory you have to specify each one on its own or use your shell + * wildcards. + * + * The start position and the number of bytes to deframention can be specified + * by \Istart\i and \Ilen\i. Any extent bigger than \Ithresh\i will be + * considered already defragged. Use 0 to take the kernel default, and use 1 + * to say eveery single extent must be rewritten. You can also turn on + * compression in defragment operations. + * + * \B-v\b be verbose + * + * \B-c\b compress file contents while defragmenting + * + * \B-f\b flush filesystem after defragmenting + * + * \B-s start\b defragment only from byte \Istart\i onward + * + * \B-l len\b defragment only up to \Ilen\i bytes + * + * \B-t size\b defragment only files at least \Isize\i bytes big + * + * NOTE: defragmenting with kernels up to 2.6.37 will unlink COW-ed copies of + * data, don''t use it if you use snapshots, have de-duplicated your data or + * made copies with + * + * \Bcp --reflink\b. + ****/ + int do_defrag(int ac, char **av) { int fd; @@ -268,6 +304,16 @@ int do_defrag(int ac, char **av) return errors + 20; } + +/**** man: btrfs subvolume find-new + * + * \Bbtrfs\b \Bsubvolume find-new\b\I <subvolume> <last_gen>\i + * + * List the recently modified files in a filesystem. + * + * List the recently modified files in a subvolume, after \I<last_gen>\i ID. + ****/ + int do_find_newer(int argc, char **argv) { int fd; @@ -299,6 +345,25 @@ int do_find_newer(int argc, char **argv) return 0; } + +/**** man: btrfs subvolume list + * + * \Bbtrfs\b \Bsubvolume list\b\I [-p] <path>\i + * + * List the snapshot/subvolume of a filesystem. + * + * List the subvolumes present in the filesystem \I<path>\i. For every + * subvolume the following information is shown by default. + * ID <ID> top level <ID> path <path> + * where path is the relative path of the subvolume to the \Itop level\i + * subvolume. + * The subvolume''s ID may be used by the \Bsubvolume set-default\b command, or + * at mount time via the \Isubvol=\i option. + * If \I-p\i is given, then \Iparent <ID>\i is added to the output between ID + * and top level. The parent''s ID may be used at mount time via the + * \Isubvolrootid=\i option. + ****/ + int do_subvol_list(int argc, char **argv) { int fd; @@ -346,6 +411,20 @@ int do_subvol_list(int argc, char **argv) return 0; } + +/**** man: btrfs subvolume snapshot + * + * \Bbtrfs\b \Bsubvolume snapshot\b\I [-r] <source> [<dest>/]<name>\i + * + * Create a writable/readonly snapshot of the subvolume <source> with + * the name <name> in the <dest> directory. + * + * Create a writable/readonly snapshot of the subvolume \I<source>\i with the + * name \I<name>\i in the \I<dest>\i directory. If \I<source>\i is not a + * subvolume, \Bbtrfs\b returns an error. If \I-r\i is given, the snapshot + * will be readonly. + ****/ + int do_clone(int argc, char **argv) { char *subvol, *dst; @@ -463,6 +542,17 @@ int do_clone(int argc, char **argv) } + +/**** man: btrfs subvolume delete + * + * \Bbtrfs\b \Bsubvolume delete\b\I <subvolume>\i + * + * Delete the subvolume <subvolume>. + * + * Delete the subvolume \I<subvolume>\i. If \I<subvolume>\i is not a + * subvolume, \Bbtrfs\b returns an error. + ****/ + int do_delete_subvolume(int argc, char **argv) { int res, fd, len, e; @@ -525,6 +615,18 @@ int do_delete_subvolume(int argc, char **argv) } + +/**** man: btrfs subvolume create + * + * \Bbtrfs\b \Bsubvolume create\b\I [<dest>/]<name>\i + * + * Create a subvolume in <dest> (or the current directory if + * not passed). + * + * Create a subvolume in \I<dest>\i (or in the current directory if + * \I<dest>\i is omitted). + ****/ + int do_create_subvol(int argc, char **argv) { int res, fddst, len, e; @@ -581,6 +683,16 @@ int do_create_subvol(int argc, char **argv) } + +/**** man: btrfs filesystem sync + * + * \Bbtrfs\b \Bfilesystem sync\b\I <path> \i + * + * Force a sync on the filesystem <path>. + * + * Force a sync for the filesystem identified by \I<path>\i. + ****/ + int do_fssync(int argc, char **argv) { int fd, res, e; @@ -605,6 +717,21 @@ int do_fssync(int argc, char **argv) return 0; } + +/**** man: btrfs device scan + * + * \Bbtrfs\b \Bdevice scan\b \I[--all-devices|<device> [<device>...]\i + * + * Scan all device for or the passed device for a btrfs + * filesystem. + * + * If one or more devices are passed, these are scanned for a btrfs filesystem. + * If no devices are passed, \Bbtrfs\b scans all the block devices listed + * in the /proc/partitions file. + * Finally, if \B--all-devices\b is passed, all the devices under /dev are + * scanned. + ****/ + int do_scan(int argc, char **argv) { int i, fd, e; @@ -672,6 +799,32 @@ int do_scan(int argc, char **argv) } + +/**** man: btrfs filesystem resize + * + * \Bbtrfs\b \Bfilesystem resize\b\I [+/\-]<size>[gkm]|max <path>\i + * + * Resize the file system. If ''max'' is passed, the filesystem + * will occupe all available space on the device. + * + * Resize a filesystem identified by \I<path>\i. + * The \I<size>\i parameter specifies the new size of the filesystem. + * If the prefix \I+\i or \I\-\i is present the size is increased or decreased + * by the quantity \I<size>\i. + * If no units are specified, the unit of the \I<size>\i parameter defaults to + * bytes. Optionally, the size parameter may be suffixed by one of the following + * the units designators: ''K'', ''M'', or ''G'', kilobytes, megabytes, or gigabytes, + * respectively. + * + * If ''max'' is passed, the filesystem will occupy all available space on the + * volume(s). + * + * The \Bresize\b command \Bdoes not\b manipulate the size of underlying + * partition. If you wish to enlarge/reduce a filesystem, you must make sure + * you can expand the partition before enlarging the filesystem and shrink the + * partition after reducing the size of the filesystem. + ****/ + int do_resize(int argc, char **argv) { @@ -762,6 +915,20 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices) printf("\n"); } + +/**** man: btrfs filesystem show + * + * \Bbtrfs\b \Bfilesystem show\b [--all-devices|<uuid>|<label>]\b + * + * Show the info of a btrfs filesystem. If no argument + * is passed, info of all the btrfs filesystem are shown. + * + * Show the btrfs filesystem with some additional info. If no \IUUID\i or + * \Ilabel\i is passed, \Bbtrfs\b show info of all the btrfs filesystem. + * If \B--all-devices\b is passed, all the devices under /dev are scanned; + * otherwise the devices list is extracted from the /proc/partitions file. + ****/ + int do_show_filesystem(int argc, char **argv) { struct list_head *all_uuids; @@ -807,6 +974,16 @@ int do_show_filesystem(int argc, char **argv) return 0; } + +/**** man: btrfs device add + * + * \Bbtrfs\b \Bdevice add\b\I <dev> [<dev>..] <path>\i + * + * Add a device to a filesystem. + * + * Add device(s) to the filesystem identified by \I<path>\i. + ****/ + int do_add_volume(int nargs, char **args) { @@ -1068,6 +1245,34 @@ int parse_filter(struct btrfs_ioctl_balance_start *args, char *filters_string) return 0; } + +/**** man: btrfs filesystem balance + * + * \Bbtrfs\b \Bfilesystem balance\b [\B-wcv\b] [\B--wait\b] [\B--count\b] [\B--verbose\b] [\B-f\b|\Bfilter=\b\I<filter>\i] \I<path>\i + * + * Balance chunks across the devices. --filter=help for help on filters. + * --count to count chunks only (no balance performed). + * + * Balance chunks across the devices. --filter=help for help on filters. + * --count to count chunks only (no balance performed). + ****/ + +/**** man: btrfs balance start + * + * \Bbtrfs\b \Bbalance start\b [\B-wcv\b] [\B--wait\b] [\B--count\b] [\B--verbose\b] [\B-f\b|\Bfilter=\b\I<filter>\i] \I<path>\i + * + * Synonym for "btrfs filesystem balance". + * + * Balance the chunks of the filesystem identified by \I<path>\i across + * the devices. The command returns immediately, and the balance + * operation runs in the background. Use \B--wait\b to run + * synchronously instead. Use \B--count\b to scan the filesystem and + * report the number of chunks that would be processed. Use + * \B--verbose\b in synchronous mode to report the number of chunks + * examined and balanced. See \BBALANCE FILTERS\b, below, for details + * of the different filter types and syntax. + ****/ + int do_balance(int argc, char **argv) { int fdmnt, ret=0, e; @@ -1205,6 +1410,18 @@ const struct option progress_options[] = { { NULL, 0, NULL, 0 } }; + +/**** man: btrfs balance progress + * + * \Bbtrfs\b \Bbalance progress\b [\B-m\b|\B--monitor\b] \I<path>\i + * + * Show progress of the balance operation running on <path>. + * + * Report progress on the currently-running balance operation on the + * filesystem mounted at \I<path>\i. Use --monitor to report progress + * continually, including an estimate of completion time. + ****/ + int do_balance_progress(int argc, char **argv) { char *path; @@ -1325,6 +1542,17 @@ int do_balance_progress(int argc, char **argv) return 0; } + +/**** man: btrfs balance cancel + * + * \Bbtrfs\b \Bbalance cancel\b \I<path>\i + * + * Cancel the balance operation running on <path>. + * + * Cancel the balance currently running on the filesystem mounted at + * \I<path>\i. + ****/ + int do_balance_cancel(int nargs, char **argv) { char *path = argv[1]; @@ -1366,6 +1594,16 @@ int do_balance_cancel(int nargs, char **argv) return err; } + +/**** man: btrfs device delete + * + * \Bbtrfs\b \Bdevice delete\b\I <dev> [<dev>..] <path>\i + * + * Remove a device from a filesystem. + * + * Remove device(s) from a filesystem identified by \I<path>\i. + ****/ + int do_remove_volume(int nargs, char **args) { @@ -1399,6 +1637,19 @@ int do_remove_volume(int nargs, char **args) return 0; } + +/**** man: btrfs subvolume set-default + * + * \Bbtrfs\b \Bsubvolume set-default\b\I <id> <path>\i + * + * Set the subvolume of the filesystem <path> which will be mounted + * as default. + * + * Set the subvolume of the filesystem \I<path>\i which is mounted as + * \Idefault\i. The subvolume is identified by \I<id>\i, which + * is returned by the \Bsubvolume list\b command. + ****/ + int do_set_default_subvol(int nargs, char **argv) { int ret=0, fd, e; @@ -1428,6 +1679,31 @@ int do_set_default_subvol(int nargs, char **argv) return 0; } + +/**** man: btrfs filesystem label + * + * \Bbtrfs\b \Bfilesystem label\b\I <dev> [newlabel]\i + * + * With one argument, get the label of filesystem on <device>. + * If <newlabel> is passed, set the filesystem label to <newlabel>. + * The filesystem must be unmounted. + * + * Show or update the label of a filesystem. \I<dev>\i is used to identify the + * filesystem. + * If a \Inewlabel\i optional argument is passed, the label is changed. The + * following costraints exist for a label: + * \t + * - the maximum allowable lenght shall be less or equal than 256 chars + * \t + * - the label shall not contain the ''/'' or ''\\'' characters. + * + * NOTE: Currently there are the following limitations: + * \t + * - the filesystem has to be unmounted + * \t + * - the filesystem should not have more than one device. + ****/ + int do_change_label(int nargs, char **argv) { /* check the number of argument */ diff --git a/scrub.c b/scrub.c index 22052ed..4c58ab8 100644 --- a/scrub.c +++ b/scrub.c @@ -1378,16 +1378,76 @@ out: return !!err; } + +/**** man: btrfs scrub start + * + * \Bbtrfs\b \Bscrub start\b [-Bdqru] {\I<path>\i|\I<device>\i} + * + * Start a new scrub. + * + * Start a scrub on all devices of the filesystem identified by \I<path>\i or on + * a single \I<device>\i. Without options, scrub is started as a background + * process. Progress can be obtained with the \Bscrub status\b command. + * Scrubbing involves reading all data from all disks and verifying checksums. + * Errors are corrected along the way if possible. + * \w + * + * \IOptions\i + * \t -B 5 + * Do not background and print scrub statistics when finished. + * \t -d 5 + * Print separate statistics for each device of the filesystem (-B only). + * \t -q 5 + * Quiet. Omit error messages and statistics. + * \t -r 5 + * Read only mode. Do not attempt to correct anything. + * \t -u 5 + * Scrub unused space as well. (NOT IMPLEMENTED) + * \q + ****/ + int do_scrub_start(int argc, char **argv) { return scrub_start(argc, argv, 0); } + +/**** man: btrfs scrub resume + * + * \Bbtrfs\b \Bscrub resume\b [-Bdqru] {\I<path>\i|\I<device>\i} + * + * Resume previously canceled or interrupted scrub. + * + * Resume a canceled or interrupted scrub cycle on the filesystem identified by + * \I<path>\i or on a given \I<device>\i. Does not start a new scrub if the + * last scrub finished successfully. + * \w + * + * \IOptions\i + * \p + * see \Bscrub start\b. + * \q + ****/ + int do_scrub_resume(int argc, char **argv) { return scrub_start(argc, argv, 1); } + +/**** man: btrfs scrub cancel + * + * \Bbtrfs\b \Bscrub cancel\b {\I<path>\i|\I<device>\i} + * + * Cancel a running scrub. + * + * If a scrub is running on the filesystem identified by \I<path>\i, cancel it. + * Progress is saved in the scrub progress file and scrubbing can be resumed later + * using the \Bscrub resume\b command. + * If a \I<device>\i is given, the corresponding filesystem is found and + * \Bscrub cancel\b behaves as if it was called on that filesystem. + ****/ + int do_scrub_cancel(int argc, char **argv) { char *path = argv[1]; @@ -1433,6 +1493,25 @@ again: return 0; } + +/**** man: btrfs scrub status + * + * \Bbtrfs\b \Bscrub status\b [-d] {\I<path>\i|\I<device>\i} + * + * Show status of running or finished scrub. + * + * Show status of a running scrub for the filesystem identified by \I<path>\i or + * for the specified \I<device>\i. + * If no scrub is running, show statistics of the last finished or canceled scrub + * for that filesystem or device. + * \w + * + * \IOptions\i + * \t -d 5 + * Print separate statistics for each device of the filesystem. + * \q + ****/ + int do_scrub_status(int argc, char **argv) { -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Goffredo Baroncelli
2011-Jul-19 16:12 UTC
[PATCH 2/6] Add the header/footer/introduction of the man page.
From: Goffredo Baroncelli <kreijack@inwind.it> Add the header/footer/introduction of the man page. There is also an introduction to the syntax recognized by the tool helpextract to format the information. --- btrfs.c | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 176 insertions(+), 0 deletions(-) diff --git a/btrfs.c b/btrfs.c index 67d6f6f..98abb6c 100644 --- a/btrfs.c +++ b/btrfs.c @@ -26,6 +26,182 @@ #define BASIC_HELP 0 #define ADVANCED_HELP 1 +/** + ** The comments below are used to make the man page + ** + ** There are: + ** - Header, + ** - The synopsis title section (the content are extracted from other + ** comments) + ** - The synopsis format, which is a template: the ''%s'' is replaced by + ** the command line "syntax" + ** - The btrfs introduction section + ** - The btfrs command title section (the content are extracted from other + ** comments) + ** - The command format, which is a template: the first ''%s'' is replaced by + ** the command line "syntax"; the ssecond ''%s'' is replaced by the + ** detailed descritpion + ** - The "notes" section + ** - The footer (currentli empty) + ** + ** The comments are the following sytax [replace ''{slash}'' with ''/''] + ** + ** If the comment starts with ''{slash}**** text: '', then all the text below + ** are used until '' ***''. The text after ''text: '' are the key used to + ** index teh content. + ** + ** If the comment starts with ''{slash}**** man: '', then below the comment are + ** divided in three section: + ** 1) (one line) command line syntax + ** 2) (multiple line) short description (showed in the command "btrfs help") + ** 3) (multiple line) detailled description (showed in the man page and + ** command "btrfs <subcommand> --help") + ** The text after ''man: '' are the key used to index the content. This must + ** be equal to the subcommand which the info is referred. + ** + ** Below the escape sequence which may be used in the text + ** + ** escape troff + ** sequence command + ** + ** \B \fB bold + ** \b \fP end bold + ** \I \fI italic + ** \i \fP end italic + ** \c .\" comment + ** \P .PP start paragraph + ** \p .TP indented paragraph + ** \h .SH header + ** \d .BR bold regular + ** \e .B bold + ** \t .IP indented paragraph + ** \w .RS move the left margin + ** \q .RE move the left margin back + ** \- \- minus (it *must* escaped ) + ** + ** + **/ + + +/**** text: man btrfs header + * .TH BTRFS 8 "" "btrfs" "btrfs" + * .\" + * .\" Man page for the "btrfs" tool + * .\" + * .SH NAME + * btrfs \- control a btrfs filesystem + ****/ + +/**** text: man btrfs synopsis + * .SH SYNOPSIS + ****/ + +/**** text: man btrfs synopsis format + * \fB%s\fP + * .PP + ****/ + +/**** text: btrfs introduction + * \h DESCRIPTION + * \Bbtrfs\b is used to control the filesystem and the files and directories + * stored. It is the tool to create or destroy a snapshot or a subvolume for + * the filesystem, to defrag a file or a directory, flush the data to the disk, + * to resize the filesystem, to scan the device. + * + * It is possible to abbreviate the commands unless the commands are ambiguous. + * For example: it is possible to run + * \Ibtrfs sub snaps\i instead of \Ibtrfs subvolume snapshot\i. But \Ibtrfs + * file s\i is not allowed, because \Ifile s\i may be interpreted both as + * \Ifilesystem show\i and as \Ifilesystem sync\i. + * + * If a command is terminated by \I--help\i, the detailed help is showed. + * If the passed command matches more commands, detailed help of all the + * matched commands is showed. For example \Ibtrfs dev --help\i shows the + * help of all \Idevice*\i commands. + ****/ + +/**** text: man btrfs command format + * + * .TP + * %s%s + ****/ + +/**** text: man btrfs commands + * .SH COMMANDS + * .TP + */ + +/**** text: btrfs notes + * \h BALANCE FILTERS + * + * With balance filters, it is possible to perform a balance operation on + * only a subset of the available chunks. Filters are specified with the + * \B--filter\b option of \Bbtrfs filesystem balance\b or \Bbtrfs + * balance start\b. Multiple filters may be given, either with multiple + * \B--filter\b options, or in a colon-separated list. When multiple + * filters are given, only the chunks meeting all of the selection + * critera are balanced. Help on the avaialble filters can be obtained + * with \B--filter=help\b. + * + * + * \Btype\b=[\B~\b]\I<flagname>\i[\B,\b...] + * + * Select only the chunks with the given type flag(s). Requiring a flag + * to be off can be specified with a \B~\b preceding the flag + * name. Flag names are: + * + * \Bmeta\b, \Bdata\b, \Bsys\b for metadata, file data and system + * chunk types. + * + * \Braid0\b, \Braid1\b, \Braid10\b, \Bdup\b for chunks of the + * given replication levels. + * + * + * \Bdevid\b=\I<n>\i + * + * Select chunks which have data on device ID \I<n>\i. This can be + * used, for example, to reduplicate data in a mirrored configuration + * where one drive has been lost due to hardware failure. + * + * + * \Bvrange\b=\I<start>\i,\I<end>\i + * + * Select chunks which have btrfs-internal virtual addresses within the + * range \I<start>\i (inclusive) to \I<end>\i (exclusive). Given the + * address of the last chunk moved, this filter can be used to restart a + * cancelled or interrupted balance operation, by supplying a range of + * \I0,<chunkaddr+1>\i. + * + * \Bdrange\b=\I<start>\i,\I<end>\i + * + * Select chunks which contain data in the address range \I<start>\i + * (inclusive) to \I<end>\i (exclusive) on \Iany\i block device in + * the filesystem. Can be mixed with the \Bdevid\b filter to select + * chunks in a given address range on a specific device. + * + * \h EXIT STATUS + * \Bbtrfs\b returns a zero exist status if it succeeds. Non zero is returned in + * case of failure. + * + * \h AVAILABILITY + * \Bbtrfs\b is part of btrfs-progs. Btrfs filesystem is currently under + * heavy development, and not suitable for any uses other than benchmarking and + * review. + * + * Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for + * further details. + * + * \h SEE ALSO + * \Bmkfs.btrfs (8)\b + ****/ + +/**** text: man btrfs footer + ****/ + + + + + typedef int (*CommandFunction)(int argc, char **argv); struct Command { -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Goffredo Baroncelli
2011-Jul-19 16:12 UTC
[PATCH 3/6] helpextract: tool to extract the info for the help from the source.
From: Goffredo Baroncelli <kreijack@inwind.it> It is created the file helpextract.c, which is the source for the tool "helpextract". This program extract the info showed in the man page and the help command from the sources comments. --- helpextract.c | 435 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 435 insertions(+), 0 deletions(-) create mode 100644 helpextract.c diff --git a/helpextract.c b/helpextract.c new file mode 100644 index 0000000..9489ea0 --- /dev/null +++ b/helpextract.c @@ -0,0 +1,435 @@ +#include <stdio.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> + +#define PREFIX_MAN "/**** man: " +#define PREFIX_TEXT "/**** text: " +#define PREFIX_END " ****" +#define PREFIX_SKIP " * " + +#define LINEBUF 1024 + +char **msgs=0; +int nmsg=0; + +static char *xstrdup(char *str){ + char *new = strdup(str); + if(!new){ + fprintf(stderr,"*** Memory allocation fail ! (xstrdup)\n"); + exit(101); + } + return new; +} + +static void *xrealloc(void *ptr, int newsize){ + void *new = realloc(ptr, newsize); + if(!new){ + fprintf(stderr,"*** Memory allocation fail ! (xrealloc)\n"); + exit(101); + } + return new; + + +} + +static char *xstrip(char *s){ + + char *last=NULL; + char *first; + + while(*s && isspace(*s) ) s++; + + first=s; + + while(*s){ + if(isspace(*s)) last=s; + s++; + } + + if(last) *last=0; + return first; + + +} + +static void addtuple(char *key, char *cmdline, char *short_help, + char *long_help){ + + msgs = (char**)xrealloc(msgs, sizeof(char *)*(nmsg+1)*4); + + key = xstrip(key); + + if( !long_help || !strcmp(long_help,"\n")) + long_help = short_help; + else if(!short_help || !strcmp(short_help, "\n")) + short_help = long_help; + + msgs[nmsg*4] = key; + msgs[nmsg*4+1] = cmdline; + msgs[nmsg*4+2] = short_help; + msgs[nmsg*4+3] = long_help; + nmsg++; +} + + +static int search_in_file(char *nf){ + char buf[LINEBUF+1]; + FILE *fp; + int status; + char *key=NULL; + char *cmdline=NULL; + char *short_help=NULL; + char *long_help=NULL; + + fp = fopen(nf,"r"); + if(!fp){ + int e=errno; + fprintf(stderr, "*** Cannot open ''%s''; error = %d - ''%s''\n", + nf, e, strerror(e)); + return -1; + } + + status = 0; + while(fgets(buf,LINEBUF,fp)){ + // printf("status = %d, buf=%s",status, buf); + + if(status == 0){ + if(!strncmp(buf,PREFIX_MAN, strlen(PREFIX_MAN)) ){ + key = xstrdup(buf+strlen(PREFIX_MAN)); + status++; + }else if(!strncmp(buf,PREFIX_TEXT, + strlen(PREFIX_TEXT))){ + key = xstrdup(buf+strlen(PREFIX_TEXT)); + status=5; + } + continue; + + } + + if( !strncmp(buf,PREFIX_END, strlen(PREFIX_END)) || + strncmp(buf, PREFIX_SKIP,2)){ + + addtuple(key, cmdline, short_help, long_help); + key = cmdline = short_help = long_help = 0; + status = 0; + + continue; + } + if( status == 2){ + if(strlen(buf)>strlen(PREFIX_SKIP)) + cmdline = xstrdup(buf+strlen(PREFIX_SKIP)); + status++; + continue; + } + if( status == 4){ + int len; + int len2; + char *p; + + if(strlen(buf)<=strlen(PREFIX_SKIP)){ + status++; + continue; + } + p=buf+3; + while(isspace(*p) && *p ) p++; + if(!*p){ + status++; + continue; + } + + len2 = strlen(buf)-strlen(PREFIX_SKIP); + + if(short_help) + len = strlen(short_help); + else + len = 0; + short_help = (char*)xrealloc(short_help, len+len2+1); + strcpy(short_help+len,buf+strlen(PREFIX_SKIP)); + continue; + } + if( status == 5){ + int len; + int len2 = strlen(buf)-strlen(PREFIX_SKIP); + + if(long_help) + len = strlen(long_help); + else + len = 0; + long_help = (char*)xrealloc(long_help, len+len2+1); + strcpy(long_help+len,buf+strlen(PREFIX_SKIP)); + continue; + } + if( status == 1 || status == 3 ){ + status++; + continue; + } + + fprintf(stderr,"*** Internal error: status = %d\n",status); + exit(100); + + } + + if( status != 0 ){ + fprintf(stderr,"*** Parse error: file = ''%s'', " + "status = %d at the end of file\n", + nf, status); + exit(100); + + } + + fclose(fp); + + return 0; +} + +/* remove all the escape sequence excepet \\ */ +static char * my_escape(char *src, char *filters[] ){ + + static char buffer[LINEBUF*5]; + + int i=0; + while(*src){ + int j; + int next_char = *(src+1); + if(*src != ''\\''){ + buffer[i++]=*src++; + continue; + } + if(!next_char){ + buffer[i++]=*src++; + continue; + } + if( !filters ){ + src +=2; + continue; + } + + j=0; + while(filters[j]){ + if(filters[j][0] == next_char ){ + strcpy(buffer+i, filters[j]+2); + i+=strlen(filters[j]+2); + break; + } + j++; + } + if(!filters[j]){ + char *p=src; + int l=40; + fprintf(stderr, + "Unknow escape sequence ''\%c'' in [\"", + next_char); + while(*p && l--) fputc(*p++, stderr); + fprintf(stderr, "\"...]\n"); + } + src += 2; + + } + + buffer[i]=0; + return buffer; + +} + +static char * escape_c_array(char *src ){ + static char *filters[]={ + + /* remove the all know esc-sequence */ + + "B ", /* bold */ + "b ", /* end bold */ + "I ", /* italic */ + "i ", /* end italic */ + "c ", /* comment */ + "P ", /* start paragraph */ + "p ", /* indented paragraph */ + "h ", /* header */ + "d ", /* bold regular */ + "e ", /* bold */ + "t ", /* indented paragraph */ + "w ", /* move the left margin */ + "q ", /* move the left margin back */ + + "\\ \\\\", + "- -", + + 0 + }; + + return my_escape(src, filters); +} + +static char *escape_man_page(char *src){ + /* from Gnu troff manual */ + static char *filters[]={ + "B \\fB", /* bold */ + "b \\fP", /* end bold */ + "I \\fI", /* italic */ + "i \\fP", /* end italic */ + "c .\\\"", /* comment */ + "P .PP", /* start paragraph */ + "p .TP", /* indented paragraph */ + "h .SH", /* header */ + "d .BR", /* bold regular */ + "e .B", /* bold */ + "t .IP", /* indented paragraph */ + "w .RS", /* move the left margin */ + "q .RE", /* move the left margin back */ + + "- \\-", /* escape the minus sign */ + "\\ \\", + + 0 + }; + + return my_escape(src, filters); +} + + +static void dump_c_array(){ + + int i; + + printf("{"); + for(i=0; i < nmsg*4 ; i++){ + char *c = msgs[i]; + int begin; + + if(!(i%4) && strncmp(c,"btrfs ",5)){ + i+=3; + continue; + } + + if(i>0){ + putchar('',''); + if(!(i%4)) putchar(''\n''); + } + + if(!c){ + printf("\n NULL"); + continue; + } + + c = escape_c_array(c); + + begin = 1; + while( *c ){ + if(begin) + printf("\n \""); + begin = 0; + if( *c == ''\n'' ){ + printf("\\n\""); + begin = 1; + }else if( *c == ''"'' ){ + printf("\\\""); + }else{ + putchar(*c); + } + + c++; + } + if(!begin) putchar(''"''); + } + printf(",\n\n "); + for(i=0; i < 4; i++){ + if(i>0) putchar('',''); + printf("NULL"); + } + printf("\n}\n"); + +} + +static int my_sort_cmp(const void *p1, const void *p2){ + return strcmp(*(char**)p1, *(char **)p2); +} + +static void my_sort(){ + qsort(msgs, nmsg, sizeof(char*)*4, my_sort_cmp); +} + +static int find_section(char *key){ + int i; + for(i = 0 ; i < nmsg ; i++ ) + if(!strcmp( msgs[i*4],key) ) return i; + + return -1; +} + +static void dump_man_page(){ + + int i, fmt; + + i = find_section("man btrfs header"); + if( i>= 0 ) printf(msgs[i*4+3]); + + i = find_section("man btrfs synopsis"); + if( i>= 0 ) printf(msgs[i*4+3]); + + fmt = find_section("man btrfs synopsis format"); + for(i = 0; i < nmsg && fmt>=0; i++ ){ + if( strncmp("btrfs ",msgs[i*4], 6) || + !strcmp("btrfs introduction", msgs[i*4] ) || + !strcmp("btrfs notes", msgs[i*4] ) ) + continue; + + printf(msgs[fmt*4+3], escape_man_page(msgs[i*4+1])); + } + + i = find_section("btrfs introduction"); + if( i>= 0 ) printf(escape_man_page(msgs[i*4+3])); + + i = find_section("man btrfs commands"); + if( i>= 0 ) printf(msgs[i*4+3]); + + fmt = find_section("man btrfs command format"); + for(i = 0; i < nmsg && fmt>=0; i++ ){ + + char big2[LINEBUF*5]; + if( strncmp("btrfs ",msgs[i*4], 6) || + !strcmp("btrfs introduction", msgs[i*4] ) || + !strcmp("btrfs notes", msgs[i*4] ) ) + continue; + + strcpy(big2, escape_man_page(msgs[i*4+3])); + printf(msgs[fmt*4+3], escape_man_page(msgs[i*4+1]), big2); + + } + + i = find_section("man btrfs notes"); + if( i>= 0 ) printf(msgs[i*4+3]); + + i = find_section("btrfs notes"); + if( i>= 0 ) printf(escape_man_page(msgs[i*4+3])); + + i = find_section("man btrfs footer"); + if( i>= 0 ) printf(msgs[i*4+3]); +} + +static void usage(char *np){ + printf("usage: %s --man-page|--c-array <file> [<file> [...]]\n", np); +} + +int main(int argc, char **argv ){ + + int i; + if( argc < 3 || ( strcmp(argv[1],"--man-page") && + strcmp(argv[1],"--c-array") )){ + usage(argv[0]); + return 0; + } + + for(i=2; i < argc ; i++) + search_in_file(argv[i]); + + my_sort(); + + if(!strcmp(argv[1], "--man-page")) + dump_man_page(); + else if (!strcmp(argv[1], "--c-array")) + dump_c_array(); + + return 0; + +} -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Goffredo Baroncelli
2011-Jul-19 16:12 UTC
[PATCH 4/6] Update the makefile for generating the man page.
From: Goffredo Baroncelli <kreijack@inwind.it> The makefile is update in order to generate the man/btrfs.8.in by the helpextract tool on the basis of the sources comments. The old man page is renamed as btrfs.8.in.old. --- Makefile | 11 +- man/btrfs.8.in | 359 ---------------------------------------------------- man/btrfs.8.in.old | 359 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 369 insertions(+), 360 deletions(-) delete mode 100644 man/btrfs.8.in create mode 100644 man/btrfs.8.in.old diff --git a/Makefile b/Makefile index edee1a0..dc1342f 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,8 @@ LIBS = -luuid progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \ btrfs btrfs-map-logical +btrfs_man_page_source = btrfs.c btrfs_cmds.c scrub.c + # make C=1 to enable sparse ifdef C check = sparse $(CHECKFLAGS) @@ -84,13 +86,20 @@ convert: $(objects) convert.o ioctl-test: $(objects) ioctl-test.o $(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS) -manpages: +helpextract: helpextract.o + $(CC) $(CFLAGS) -o $@ helpextract.o + +man/btrfs.8.in: helpextract $(btrfs_man_page_source) + ./helpextract --man-page $(btrfs_man_page_source) >$@ + +manpages: man/btrfs.8.in cd man; make install-man: cd man; make install clean : + rm -f man/btrfs.8.in rm -f $(progs) cscope.out *.o .*.d btrfs-convert btrfs-image btrfs-select-super \ btrfs-zero-log btrfstune dir-test ioctl-test quick-test version.h cd man; make clean diff --git a/man/btrfs.8.in b/man/btrfs.8.in deleted file mode 100644 index 84a60cd..0000000 --- a/man/btrfs.8.in +++ /dev/null @@ -1,359 +0,0 @@ -.TH BTRFS 8 "" "btrfs" "btrfs" -.\" -.\" Man page written by Goffredo Baroncelli <kreijack@inwind.it> (Feb 2010) -.\" -.SH NAME -btrfs \- control a btrfs filesystem -.SH SYNOPSIS -\fBbtrfs\fP \fBsubvolume snapshot\fP\fI [-r] <source> [<dest>/]<name>\fP -.PP -\fBbtrfs\fP \fBsubvolume delete\fP\fI <subvolume>\fP -.PP -\fBbtrfs\fP \fBsubvolume create\fP\fI [<dest>/]<name>\fP -.PP -\fBbtrfs\fP \fBsubvolume list\fP\fI [-p] <path>\fP -.PP -\fBbtrfs\fP \fBsubvolume set-default\fP\fI <id> <path>\fP -.PP -\fBbtrfs\fP \fBfilesystem sync\fP\fI <path> \fP -.PP -\fBbtrfs\fP \fBfilesystem resize\fP\fI [+/\-]<size>[gkm]|max <filesystem>\fP -.PP -\fBbtrfs\fP \fBfilesystem label\fP\fI <dev> [newlabel]\fP -.PP -\fBbtrfs\fP \fBfilesystem defrag\fP\fI [options] <file>|<dir> [<file>|<dir>...]\fP -.PP -\fBbtrfs\fP \fBsubvolume find-new\fP\fI <subvolume> <last_gen>\fP -.PP -\fBbtrfs\fP \fBfilesystem balance\fP [\fB-wcv\fP] [\fB--wait\fP] [\fB--count\fP] [\fB--verbose\fP] [\fB-f\fP|\fBfilter=\fP\fI<filter>\fP] \fI<path>\fP -.PP -\fBbtrfs\fP \fBbalance start\fP [\fB-wcv\fP] [\fB--wait\fP] [\fB--count\fP] [\fB--verbose\fP] [\fB-f\fP|\fBfilter=\fP\fI<filter>\fP] \fI<path>\fP -.PP -\fBbtrfs\fP \fBbalance progress\fP [\fB-m\fP|\fB--monitor\fP] \fI<path>\fP -.PP -\fBbtrfs\fP \fBbalance cancel\fP \fI<path>\fP -.PP -\fBbtrfs\fP \fBfilesystem defragment\fP\fI <file>|<dir> [<file>|<dir>...]\fP -.PP -\fBbtrfs\fP \fBdevice scan\fP\fI [--all-devices|<device> [<device>...]]\fP -.PP -\fBbtrfs\fP \fBdevice show\fP\fI [--all-devices|<uuid>|<label>]\fP -.PP -\fBbtrfs\fP \fBdevice add\fP\fI <device> [<device>...] <path> \fP -.PP -\fBbtrfs\fP \fBdevice delete\fP\fI <device> [<device>...] <path> \fP -.PP -\fBbtrfs\fP \fBscrub start\fP [-Bdqru] {\fI<path>\fP|\fI<device>\fP} -.PP -\fBbtrfs\fP \fBscrub cancel\fP {\fI<path>\fP|\fI<device>\fP} -.PP -\fBbtrfs\fP \fBscrub resume\fP [-Bdqru] {\fI<path>\fP|\fI<device>\fP} -.PP -\fBbtrfs\fP \fBscrub status\fP [-d] {\fI<path>\fP|\fI<device>\fP} -.PP -\fBbtrfs\fP \fBhelp|\-\-help|\-h \fP\fI\fP -.PP -\fBbtrfs\fP \fB<command> \-\-help \fP\fI\fP -.PP -.SH DESCRIPTION -.B btrfs -is used to control the filesystem and the files and directories stored. It is -the tool to create or destroy a snapshot or a subvolume for the -filesystem, to defrag a file or a directory, flush the data to the disk, -to resize the filesystem, to scan the device. - -It is possible to abbreviate the commands unless the commands are ambiguous. -For example: it is possible to run -.I btrfs sub snaps -instead of -.I btrfs subvolume snapshot. -But -.I btrfs file s -is not allowed, because -.I file s -may be interpreted both as -.I filesystem show -and as -.I filesystem sync. -In this case -.I btrfs -returnsfilesystem sync -If a command is terminated by -.I --help -, the detailed help is showed. If the passed command matches more commands, -detailed help of all the matched commands is showed. For example -.I btrfs dev --help -shows the help of all -.I device* -commands. - -.SH COMMANDS -.TP - -\fBsubvolume snapshot\fR\fI [-r] <source> [<dest>/]<name>\fR -Create a writable/readonly snapshot of the subvolume \fI<source>\fR with the -name \fI<name>\fR in the \fI<dest>\fR directory. If \fI<source>\fR is not a -subvolume, \fBbtrfs\fR returns an error. If \fI-r\fR is given, the snapshot -will be readonly. -.TP - -\fBsubvolume delete\fR\fI <subvolume>\fR -Delete the subvolume \fI<subvolume>\fR. If \fI<subvolume>\fR is not a -subvolume, \fBbtrfs\fR returns an error. -.TP - -\fBsubvolume create\fR\fI [<dest>/]<name>\fR -Create a subvolume in \fI<dest>\fR (or in the current directory if -\fI<dest>\fR is omitted). -.TP - -\fBsubvolume list\fR\fI [-p] <path>\fR -List the subvolumes present in the filesystem \fI<path>\fR. For every -subvolume the following information is shown by default. -ID <ID> top level <ID> path <path> -where path is the relative path of the subvolume to the \fItop level\fR -subvolume. -The subvolume''s ID may be used by the \fBsubvolume set-default\fR command, or -at mount time via the \fIsubvol=\fR option. -If \fI-p\fR is given, then \fIparent <ID>\fR is added to the output between ID -and top level. The parent''s ID may be used at mount time via the -\fIsubvolrootid=\fR option. -.TP - -\fBsubvolume set-default\fR\fI <id> <path>\fR -Set the subvolume of the filesystem \fI<path>\fR which is mounted as -\fIdefault\fR. The subvolume is identified by \fI<id>\fR, which -is returned by the \fBsubvolume list\fR command. -.TP - -\fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] [-s \fIstart\fR] [-t \fIsize\fR] -[vf] <\fIfile\fR>|<\fIdir\fR> [<\fIfile\fR>|<\fIdir\fR>...] - -Defragment file data and/or directory metadata. To defragment all files in a -directory you have to specify each one on its own or use your shell wildcards. - -The start position and the number of bytes to deframention can be specified by \fIstart\fR and \fIlen\fR. Any extent bigger than \fIthresh\fR will be considered already defragged. Use 0 to take the kernel default, and use 1 to say eveery single extent must be rewritten. You can also turn on compression in defragment operations. - -\fB-v\fP be verbose - -\fB-c\fP compress file contents while defragmenting - -\fB-f\fP flush filesystem after defragmenting - -\fB-s start\fP defragment only from byte \fIstart\fR onward - -\fB-l len\fP defragment only up to \fIlen\fR bytes - -\fB-t size\fP defragment only files at least \fIsize\fR bytes big - -NOTE: defragmenting with kernels up to 2.6.37 will unlink COW-ed copies of data, don''t -use it if you use snapshots, have de-duplicated your data or made copies with -\fBcp --reflink\fP. -\fBsubvolume find-new\fR\fI <subvolume> <last_gen>\fR -List the recently modified files in a subvolume, after \fI<last_gen>\fR ID. -.TP - -\fBfilesystem sync\fR\fI <path> \fR -Force a sync for the filesystem identified by \fI<path>\fR. -.TP - -.\" -.\" Some wording are extracted by the resize2fs man page -.\" - -\fBfilesystem resize\fR\fI [+/\-]<size>[gkm]|max <path>\fR -Resize a filesystem identified by \fI<path>\fR. -The \fI<size>\fR parameter specifies the new size of the filesystem. -If the prefix \fI+\fR or \fI\-\fR is present the size is increased or decreased -by the quantity \fI<size>\fR. -If no units are specified, the unit of the \fI<size>\fR parameter defaults to -bytes. Optionally, the size parameter may be suffixed by one of the following -the units designators: ''K'', ''M'', or ''G'', kilobytes, megabytes, or gigabytes, -respectively. - -If ''max'' is passed, the filesystem will occupy all available space on the -volume(s). - -The \fBresize\fR command \fBdoes not\fR manipulate the size of underlying -partition. If you wish to enlarge/reduce a filesystem, you must make sure you -can expand the partition before enlarging the filesystem and shrink the -partition after reducing the size of the filesystem. -.TP - -\fBbtrfs\fP \fBfilesystem label\fP\fI <dev> [newlabel]\fP -Show or update the label of a filesystem. \fI<dev>\fR is used to identify the -filesystem. -If a \fInewlabel\fR optional argument is passed, the label is changed. The -following costraints exist for a label: -.IP -- the maximum allowable lenght shall be less or equal than 256 chars -.IP -- the label shall not contain the ''/'' or ''\\'' characters. - -NOTE: Currently there are the following limitations: -.IP -- the filesystem has to be unmounted -.IP -- the filesystem should not have more than one device. -.TP - -\fBfilesystem show\fR [--all-devices|<uuid>|<label>]\fR -Show the btrfs filesystem with some additional info. If no \fIUUID\fP or -\fIlabel\fP is passed, \fBbtrfs\fR show info of all the btrfs filesystem. -If \fB--all-devices\fP is passed, all the devices under /dev are scanned; -otherwise the devices list is extracted from the /proc/partitions file. -.TP - -\fBdevice balance\fP [\fB-wcv\fP] [\fB--wait\fP] [\fB--count\fP] [\fB--verbose\fP] [\fB-f\fP|\fBfilter=\fP\fI<filter>\fP] \fI<path>\fP -.TP -\fBbalance start\fR [\fB-wcv\fP] [\fB--wait\fP] [\fB--count\fP] [\fB--verbose\fP] [\fB-f\fP|\fBfilter=\fP\fI<filter>\fP] \fI<path>\fP - -Balance the chunks of the filesystem identified by \fI<path>\fR across -the devices. The command returns immediately, and the balance -operation runs in the background. Use \fB--wait\fP to run -synchronously instead. Use \fB--count\fP to scan the filesystem and -report the number of chunks that would be processed. Use -\fB--verbose\fP in synchronous mode to report the number of chunks -examined and balanced. See \fBBALANCE FILTERS\fR, below, for details -of the different filter types and syntax. -.TP - -\fBdevice add\fR\fI <dev> [<dev>..] <path>\fR -Add device(s) to the filesystem identified by \fI<path>\fR. -.TP - -\fBdevice delete\fR\fI <dev> [<dev>..] <path>\fR -Remove device(s) from a filesystem identified by \fI<path>\fR. -.TP - -\fBdevice scan\fR \fI[--all-devices|<device> [<device>...]\fR -If one or more devices are passed, these are scanned for a btrfs filesystem. -If no devices are passed, \fBbtrfs\fR scans all the block devices listed -in the /proc/partitions file. -Finally, if \fB--all-devices\fP is passed, all the devices under /dev are -scanned. -.TP - -\fBscrub start\fP [-Bdqru] {\fI<path>\fP|\fI<device>\fP} -Start a scrub on all devices of the filesystem identified by \fI<path>\fR or on -a single \fI<device>\fR. Without options, scrub is started as a background -process. Progress can be obtained with the \fBscrub status\fR command. Scrubbing -involves reading all data from all disks and verifying checksums. Errors are -corrected along the way if possible. -.RS - -\fIOptions\fR -.IP -B 5 -Do not background and print scrub statistics when finished. -.IP -d 5 -Print separate statistics for each device of the filesystem (-B only). -.IP -q 5 -Quiet. Omit error messages and statistics. -.IP -r 5 -Read only mode. Do not attempt to correct anything. -.IP -u 5 -Scrub unused space as well. (NOT IMPLEMENTED) -.RE -.TP - -\fBscrub cancel\fP {\fI<path>\fP|\fI<device>\fP} -If a scrub is running on the filesystem identified by \fI<path>\fR, cancel it. -Progress is saved in the scrub progress file and scrubbing can be resumed later -using the \fBscrub resume\fR command. -If a \fI<device>\fR is given, the corresponding filesystem is found and -\fBscrub cancel\fP behaves as if it was called on that filesystem. -.TP - -\fBscrub resume\fP [-Bdqru] {\fI<path>\fP|\fI<device>\fP} -Resume a canceled or interrupted scrub cycle on the filesystem identified by -\fI<path>\fR or on a given \fI<device>\fR. Does not start a new scrub if the -last scrub finished successfully. -.RS - -\fIOptions\fR -.TP -see \fBscrub start\fP. -.RE -.TP - -\fBscrub status\fP [-d] {\fI<path>\fP|\fI<device>\fP} -Show status of a running scrub for the filesystem identified by \fI<path>\fR or -for the specified \fI<device>\fR. -If no scrub is running, show statistics of the last finished or canceled scrub -for that filesystem or device. -.RS - -\fIOptions\fR -.IP -d 5 -Print separate statistics for each device of the filesystem. -.RE - -.PP - -\fBbalance progress\fP [\fB-m\fP|\fB--monitor\fP] \fI<path>\fP -Report progress on the currently-running balance operation on the -filesystem mounted at \fI<path>\fP. Use --monitor to report progress -continually, including an estimate of completion time. - -\fBbalance cancel\fP \fI<path>\fP -Cancel the balance currently running on the filesystem mounted at -\fI<path>\fP. - -.SH BALANCE FILTERS -With balance filters, it is possible to perform a balance operation on -only a subset of the available chunks. Filters are specified with the -\fB--filter\fR option of \fBbtrfs device balance\fR or \fBbtrfs -balance start\fR. Multiple filters may be given, either with multiple -\fB--filter\fR options, or in a colon-separated list. When multiple -filters are given, only the chunks meeting all of the selection -critera are balanced. Help on the avaialble filters can be obtained -with \fB--filter=help\fR. - -.TP -\fBtype\fR=[\fB~\fR]\fI<flagname>\fR[\fB,\fR...] - -Select only the chunks with the given type flag(s). Requiring a flag -to be off can be specified with a \fB~\fR preceding the flag -name. Flag names are: - -\fBmeta\fR, \fBdata\fR, \fBsys\fR for metadata, file data and system -chunk types. - -\fBraid0\fR, \fBraid1\fR, \fBraid10\fR, \fBdup\fR for chunks of the -given replication levels. - -.TP -\fBdevid\fR=\fI<n>\fR - -Select chunks which have data on device ID \fI<n>\fR. This can be -used, for example, to reduplicate data in a mirrored configuration -where one drive has been lost due to hardware failure. - -.TP -\fBvrange\fR=\fI<start>\fB,\fI<end>\fR - -Select chunks which have btrfs-internal virtual addresses within the -range \fI<start>\fR (inclusive) to \fI<end>\fR (exclusive). Given the -address of the last chunk moved, this filter can be used to restart a -cancelled or interrupted balance operation, by supplying a range of -\fB0,\fI<chunkaddr+1>\fR. - -.TP -\fBdrange\fR=\fI<start>\fB,\fI<end>\fR - -Select chunks which contain data in the address range \fI<start>\fR -(inclusive) to \fI<end>\fR (exclusive) on \fIany\fR block device in -the filesystem. Can be mixed with the \fBdevid\fR filter to select -chunks in a given address range on a specific device. - -.SH EXIT STATUS -\fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in -case of failure. - -.SH AVAILABILITY -.B btrfs -is part of btrfs-progs. Btrfs filesystem is currently under heavy development, -and not suitable for any uses other than benchmarking and review. -Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for -further details. -.SH SEE ALSO -.BR mkfs.btrfs (8) diff --git a/man/btrfs.8.in.old b/man/btrfs.8.in.old new file mode 100644 index 0000000..84a60cd --- /dev/null +++ b/man/btrfs.8.in.old @@ -0,0 +1,359 @@ +.TH BTRFS 8 "" "btrfs" "btrfs" +.\" +.\" Man page written by Goffredo Baroncelli <kreijack@inwind.it> (Feb 2010) +.\" +.SH NAME +btrfs \- control a btrfs filesystem +.SH SYNOPSIS +\fBbtrfs\fP \fBsubvolume snapshot\fP\fI [-r] <source> [<dest>/]<name>\fP +.PP +\fBbtrfs\fP \fBsubvolume delete\fP\fI <subvolume>\fP +.PP +\fBbtrfs\fP \fBsubvolume create\fP\fI [<dest>/]<name>\fP +.PP +\fBbtrfs\fP \fBsubvolume list\fP\fI [-p] <path>\fP +.PP +\fBbtrfs\fP \fBsubvolume set-default\fP\fI <id> <path>\fP +.PP +\fBbtrfs\fP \fBfilesystem sync\fP\fI <path> \fP +.PP +\fBbtrfs\fP \fBfilesystem resize\fP\fI [+/\-]<size>[gkm]|max <filesystem>\fP +.PP +\fBbtrfs\fP \fBfilesystem label\fP\fI <dev> [newlabel]\fP +.PP +\fBbtrfs\fP \fBfilesystem defrag\fP\fI [options] <file>|<dir> [<file>|<dir>...]\fP +.PP +\fBbtrfs\fP \fBsubvolume find-new\fP\fI <subvolume> <last_gen>\fP +.PP +\fBbtrfs\fP \fBfilesystem balance\fP [\fB-wcv\fP] [\fB--wait\fP] [\fB--count\fP] [\fB--verbose\fP] [\fB-f\fP|\fBfilter=\fP\fI<filter>\fP] \fI<path>\fP +.PP +\fBbtrfs\fP \fBbalance start\fP [\fB-wcv\fP] [\fB--wait\fP] [\fB--count\fP] [\fB--verbose\fP] [\fB-f\fP|\fBfilter=\fP\fI<filter>\fP] \fI<path>\fP +.PP +\fBbtrfs\fP \fBbalance progress\fP [\fB-m\fP|\fB--monitor\fP] \fI<path>\fP +.PP +\fBbtrfs\fP \fBbalance cancel\fP \fI<path>\fP +.PP +\fBbtrfs\fP \fBfilesystem defragment\fP\fI <file>|<dir> [<file>|<dir>...]\fP +.PP +\fBbtrfs\fP \fBdevice scan\fP\fI [--all-devices|<device> [<device>...]]\fP +.PP +\fBbtrfs\fP \fBdevice show\fP\fI [--all-devices|<uuid>|<label>]\fP +.PP +\fBbtrfs\fP \fBdevice add\fP\fI <device> [<device>...] <path> \fP +.PP +\fBbtrfs\fP \fBdevice delete\fP\fI <device> [<device>...] <path> \fP +.PP +\fBbtrfs\fP \fBscrub start\fP [-Bdqru] {\fI<path>\fP|\fI<device>\fP} +.PP +\fBbtrfs\fP \fBscrub cancel\fP {\fI<path>\fP|\fI<device>\fP} +.PP +\fBbtrfs\fP \fBscrub resume\fP [-Bdqru] {\fI<path>\fP|\fI<device>\fP} +.PP +\fBbtrfs\fP \fBscrub status\fP [-d] {\fI<path>\fP|\fI<device>\fP} +.PP +\fBbtrfs\fP \fBhelp|\-\-help|\-h \fP\fI\fP +.PP +\fBbtrfs\fP \fB<command> \-\-help \fP\fI\fP +.PP +.SH DESCRIPTION +.B btrfs +is used to control the filesystem and the files and directories stored. It is +the tool to create or destroy a snapshot or a subvolume for the +filesystem, to defrag a file or a directory, flush the data to the disk, +to resize the filesystem, to scan the device. + +It is possible to abbreviate the commands unless the commands are ambiguous. +For example: it is possible to run +.I btrfs sub snaps +instead of +.I btrfs subvolume snapshot. +But +.I btrfs file s +is not allowed, because +.I file s +may be interpreted both as +.I filesystem show +and as +.I filesystem sync. +In this case +.I btrfs +returnsfilesystem sync +If a command is terminated by +.I --help +, the detailed help is showed. If the passed command matches more commands, +detailed help of all the matched commands is showed. For example +.I btrfs dev --help +shows the help of all +.I device* +commands. + +.SH COMMANDS +.TP + +\fBsubvolume snapshot\fR\fI [-r] <source> [<dest>/]<name>\fR +Create a writable/readonly snapshot of the subvolume \fI<source>\fR with the +name \fI<name>\fR in the \fI<dest>\fR directory. If \fI<source>\fR is not a +subvolume, \fBbtrfs\fR returns an error. If \fI-r\fR is given, the snapshot +will be readonly. +.TP + +\fBsubvolume delete\fR\fI <subvolume>\fR +Delete the subvolume \fI<subvolume>\fR. If \fI<subvolume>\fR is not a +subvolume, \fBbtrfs\fR returns an error. +.TP + +\fBsubvolume create\fR\fI [<dest>/]<name>\fR +Create a subvolume in \fI<dest>\fR (or in the current directory if +\fI<dest>\fR is omitted). +.TP + +\fBsubvolume list\fR\fI [-p] <path>\fR +List the subvolumes present in the filesystem \fI<path>\fR. For every +subvolume the following information is shown by default. +ID <ID> top level <ID> path <path> +where path is the relative path of the subvolume to the \fItop level\fR +subvolume. +The subvolume''s ID may be used by the \fBsubvolume set-default\fR command, or +at mount time via the \fIsubvol=\fR option. +If \fI-p\fR is given, then \fIparent <ID>\fR is added to the output between ID +and top level. The parent''s ID may be used at mount time via the +\fIsubvolrootid=\fR option. +.TP + +\fBsubvolume set-default\fR\fI <id> <path>\fR +Set the subvolume of the filesystem \fI<path>\fR which is mounted as +\fIdefault\fR. The subvolume is identified by \fI<id>\fR, which +is returned by the \fBsubvolume list\fR command. +.TP + +\fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] [-s \fIstart\fR] [-t \fIsize\fR] -[vf] <\fIfile\fR>|<\fIdir\fR> [<\fIfile\fR>|<\fIdir\fR>...] + +Defragment file data and/or directory metadata. To defragment all files in a +directory you have to specify each one on its own or use your shell wildcards. + +The start position and the number of bytes to deframention can be specified by \fIstart\fR and \fIlen\fR. Any extent bigger than \fIthresh\fR will be considered already defragged. Use 0 to take the kernel default, and use 1 to say eveery single extent must be rewritten. You can also turn on compression in defragment operations. + +\fB-v\fP be verbose + +\fB-c\fP compress file contents while defragmenting + +\fB-f\fP flush filesystem after defragmenting + +\fB-s start\fP defragment only from byte \fIstart\fR onward + +\fB-l len\fP defragment only up to \fIlen\fR bytes + +\fB-t size\fP defragment only files at least \fIsize\fR bytes big + +NOTE: defragmenting with kernels up to 2.6.37 will unlink COW-ed copies of data, don''t +use it if you use snapshots, have de-duplicated your data or made copies with +\fBcp --reflink\fP. +\fBsubvolume find-new\fR\fI <subvolume> <last_gen>\fR +List the recently modified files in a subvolume, after \fI<last_gen>\fR ID. +.TP + +\fBfilesystem sync\fR\fI <path> \fR +Force a sync for the filesystem identified by \fI<path>\fR. +.TP + +.\" +.\" Some wording are extracted by the resize2fs man page +.\" + +\fBfilesystem resize\fR\fI [+/\-]<size>[gkm]|max <path>\fR +Resize a filesystem identified by \fI<path>\fR. +The \fI<size>\fR parameter specifies the new size of the filesystem. +If the prefix \fI+\fR or \fI\-\fR is present the size is increased or decreased +by the quantity \fI<size>\fR. +If no units are specified, the unit of the \fI<size>\fR parameter defaults to +bytes. Optionally, the size parameter may be suffixed by one of the following +the units designators: ''K'', ''M'', or ''G'', kilobytes, megabytes, or gigabytes, +respectively. + +If ''max'' is passed, the filesystem will occupy all available space on the +volume(s). + +The \fBresize\fR command \fBdoes not\fR manipulate the size of underlying +partition. If you wish to enlarge/reduce a filesystem, you must make sure you +can expand the partition before enlarging the filesystem and shrink the +partition after reducing the size of the filesystem. +.TP + +\fBbtrfs\fP \fBfilesystem label\fP\fI <dev> [newlabel]\fP +Show or update the label of a filesystem. \fI<dev>\fR is used to identify the +filesystem. +If a \fInewlabel\fR optional argument is passed, the label is changed. The +following costraints exist for a label: +.IP +- the maximum allowable lenght shall be less or equal than 256 chars +.IP +- the label shall not contain the ''/'' or ''\\'' characters. + +NOTE: Currently there are the following limitations: +.IP +- the filesystem has to be unmounted +.IP +- the filesystem should not have more than one device. +.TP + +\fBfilesystem show\fR [--all-devices|<uuid>|<label>]\fR +Show the btrfs filesystem with some additional info. If no \fIUUID\fP or +\fIlabel\fP is passed, \fBbtrfs\fR show info of all the btrfs filesystem. +If \fB--all-devices\fP is passed, all the devices under /dev are scanned; +otherwise the devices list is extracted from the /proc/partitions file. +.TP + +\fBdevice balance\fP [\fB-wcv\fP] [\fB--wait\fP] [\fB--count\fP] [\fB--verbose\fP] [\fB-f\fP|\fBfilter=\fP\fI<filter>\fP] \fI<path>\fP +.TP +\fBbalance start\fR [\fB-wcv\fP] [\fB--wait\fP] [\fB--count\fP] [\fB--verbose\fP] [\fB-f\fP|\fBfilter=\fP\fI<filter>\fP] \fI<path>\fP + +Balance the chunks of the filesystem identified by \fI<path>\fR across +the devices. The command returns immediately, and the balance +operation runs in the background. Use \fB--wait\fP to run +synchronously instead. Use \fB--count\fP to scan the filesystem and +report the number of chunks that would be processed. Use +\fB--verbose\fP in synchronous mode to report the number of chunks +examined and balanced. See \fBBALANCE FILTERS\fR, below, for details +of the different filter types and syntax. +.TP + +\fBdevice add\fR\fI <dev> [<dev>..] <path>\fR +Add device(s) to the filesystem identified by \fI<path>\fR. +.TP + +\fBdevice delete\fR\fI <dev> [<dev>..] <path>\fR +Remove device(s) from a filesystem identified by \fI<path>\fR. +.TP + +\fBdevice scan\fR \fI[--all-devices|<device> [<device>...]\fR +If one or more devices are passed, these are scanned for a btrfs filesystem. +If no devices are passed, \fBbtrfs\fR scans all the block devices listed +in the /proc/partitions file. +Finally, if \fB--all-devices\fP is passed, all the devices under /dev are +scanned. +.TP + +\fBscrub start\fP [-Bdqru] {\fI<path>\fP|\fI<device>\fP} +Start a scrub on all devices of the filesystem identified by \fI<path>\fR or on +a single \fI<device>\fR. Without options, scrub is started as a background +process. Progress can be obtained with the \fBscrub status\fR command. Scrubbing +involves reading all data from all disks and verifying checksums. Errors are +corrected along the way if possible. +.RS + +\fIOptions\fR +.IP -B 5 +Do not background and print scrub statistics when finished. +.IP -d 5 +Print separate statistics for each device of the filesystem (-B only). +.IP -q 5 +Quiet. Omit error messages and statistics. +.IP -r 5 +Read only mode. Do not attempt to correct anything. +.IP -u 5 +Scrub unused space as well. (NOT IMPLEMENTED) +.RE +.TP + +\fBscrub cancel\fP {\fI<path>\fP|\fI<device>\fP} +If a scrub is running on the filesystem identified by \fI<path>\fR, cancel it. +Progress is saved in the scrub progress file and scrubbing can be resumed later +using the \fBscrub resume\fR command. +If a \fI<device>\fR is given, the corresponding filesystem is found and +\fBscrub cancel\fP behaves as if it was called on that filesystem. +.TP + +\fBscrub resume\fP [-Bdqru] {\fI<path>\fP|\fI<device>\fP} +Resume a canceled or interrupted scrub cycle on the filesystem identified by +\fI<path>\fR or on a given \fI<device>\fR. Does not start a new scrub if the +last scrub finished successfully. +.RS + +\fIOptions\fR +.TP +see \fBscrub start\fP. +.RE +.TP + +\fBscrub status\fP [-d] {\fI<path>\fP|\fI<device>\fP} +Show status of a running scrub for the filesystem identified by \fI<path>\fR or +for the specified \fI<device>\fR. +If no scrub is running, show statistics of the last finished or canceled scrub +for that filesystem or device. +.RS + +\fIOptions\fR +.IP -d 5 +Print separate statistics for each device of the filesystem. +.RE + +.PP + +\fBbalance progress\fP [\fB-m\fP|\fB--monitor\fP] \fI<path>\fP +Report progress on the currently-running balance operation on the +filesystem mounted at \fI<path>\fP. Use --monitor to report progress +continually, including an estimate of completion time. + +\fBbalance cancel\fP \fI<path>\fP +Cancel the balance currently running on the filesystem mounted at +\fI<path>\fP. + +.SH BALANCE FILTERS +With balance filters, it is possible to perform a balance operation on +only a subset of the available chunks. Filters are specified with the +\fB--filter\fR option of \fBbtrfs device balance\fR or \fBbtrfs +balance start\fR. Multiple filters may be given, either with multiple +\fB--filter\fR options, or in a colon-separated list. When multiple +filters are given, only the chunks meeting all of the selection +critera are balanced. Help on the avaialble filters can be obtained +with \fB--filter=help\fR. + +.TP +\fBtype\fR=[\fB~\fR]\fI<flagname>\fR[\fB,\fR...] + +Select only the chunks with the given type flag(s). Requiring a flag +to be off can be specified with a \fB~\fR preceding the flag +name. Flag names are: + +\fBmeta\fR, \fBdata\fR, \fBsys\fR for metadata, file data and system +chunk types. + +\fBraid0\fR, \fBraid1\fR, \fBraid10\fR, \fBdup\fR for chunks of the +given replication levels. + +.TP +\fBdevid\fR=\fI<n>\fR + +Select chunks which have data on device ID \fI<n>\fR. This can be +used, for example, to reduplicate data in a mirrored configuration +where one drive has been lost due to hardware failure. + +.TP +\fBvrange\fR=\fI<start>\fB,\fI<end>\fR + +Select chunks which have btrfs-internal virtual addresses within the +range \fI<start>\fR (inclusive) to \fI<end>\fR (exclusive). Given the +address of the last chunk moved, this filter can be used to restart a +cancelled or interrupted balance operation, by supplying a range of +\fB0,\fI<chunkaddr+1>\fR. + +.TP +\fBdrange\fR=\fI<start>\fB,\fI<end>\fR + +Select chunks which contain data in the address range \fI<start>\fR +(inclusive) to \fI<end>\fR (exclusive) on \fIany\fR block device in +the filesystem. Can be mixed with the \fBdevid\fR filter to select +chunks in a given address range on a specific device. + +.SH EXIT STATUS +\fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in +case of failure. + +.SH AVAILABILITY +.B btrfs +is part of btrfs-progs. Btrfs filesystem is currently under heavy development, +and not suitable for any uses other than benchmarking and review. +Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for +further details. +.SH SEE ALSO +.BR mkfs.btrfs (8) -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Goffredo Baroncelli
2011-Jul-19 16:12 UTC
[PATCH 5/6] Show the help messages from the info in the comment.
From: Goffredo Baroncelli <kreijack@inwind.it> The makefile is update in order to use the tool "helpextract" to extract the info from the sources comments and to generate the file "helpmsg.c" which contains an array of string with all the information. Then the function "print_help" prints these information. --- btrfs.c | 34 +++++++++++++++++++++++++++++----- 1 files changed, 29 insertions(+), 5 deletions(-) diff --git a/btrfs.c b/btrfs.c index 98abb6c..53422f7 100644 --- a/btrfs.c +++ b/btrfs.c @@ -357,6 +357,8 @@ static struct Command commands[] = { { 0, 0, 0, 0 } }; +extern char * help_messages[]; + static char *get_prgname(char *programname) { char *np; @@ -372,21 +374,43 @@ static char *get_prgname(char *programname) static void print_help(char *programname, struct Command *cmd, int helptype) { char *pc; + int i; + char *adv_help; + char *std_help; + + /* printf("\t%s %s ", programname, cmd->verb ); */ + + adv_help = cmd->adv_help; + std_help = cmd->help; + + for(i = 0; help_messages[i]; i+= 4 ){ + if(!strncmp(help_messages[i],"btrfs ",6) && + !strcmp(help_messages[i]+6,cmd->verb) ){ + if(help_messages[i+2]) + std_help = help_messages[i+2]; + if(help_messages[i+3]) + adv_help = help_messages[i+3]; + printf("\t%s\t\t",help_messages[i+1]); + break; + } + } - printf("\t%s %s ", programname, cmd->verb ); + if( !help_messages[i]) + printf("\t%s %s ", programname, cmd->verb ); - if (helptype == ADVANCED_HELP && cmd->adv_help) - for(pc = cmd->adv_help; *pc; pc++){ + if (helptype == ADVANCED_HELP && adv_help){ + for(pc = adv_help; *pc; pc++){ putchar(*pc); if(*pc == ''\n'') printf("\t\t"); } - else - for(pc = cmd->help; *pc; pc++){ + }else{ + for(pc = std_help; *pc; pc++){ putchar(*pc); if(*pc == ''\n'') printf("\t\t"); } + } putchar(''\n''); } -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Goffredo Baroncelli
2011-Jul-19 16:12 UTC
[PATCH 6/6] Update the makefile for generating the help messages.
From: Goffredo Baroncelli <kreijack@inwind.it> Update the makefile for generating the help messages. --- Makefile | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/Makefile b/Makefile index dc1342f..7b25b47 100644 --- a/Makefile +++ b/Makefile @@ -37,8 +37,9 @@ all: version $(progs) manpages version: bash version.sh -btrfs: $(objects) btrfs.o btrfs_cmds.o scrub.o +btrfs: $(objects) btrfs.o btrfs_cmds.o scrub.o helpmsg.o $(CC) -lpthread $(CFLAGS) -o btrfs btrfs.o btrfs_cmds.o scrub.o \ + helpmsg.o \ $(objects) $(LDFLAGS) $(LIBS) btrfsctl: $(objects) btrfsctl.o @@ -95,6 +96,19 @@ man/btrfs.8.in: helpextract $(btrfs_man_page_source) manpages: man/btrfs.8.in cd man; make +helpmsg.c: helpextract $(btrfs_man_page_source) + echo >$@ "/*" + echo >>$@ " * this file contains the help messages. It is " + echo >>$@ " * automatically generated. do not edit ! " + echo >>$@ " */" + echo >>$@ + echo >>$@ "#define NULL 0" + echo >>$@ + + echo -n "char * help_messages[] = " >>$@ + ./helpextract --c-array $(btrfs_man_page_source) >>$@ + echo >>$@ ";" + install-man: cd man; make install @@ -102,6 +116,7 @@ clean : rm -f man/btrfs.8.in rm -f $(progs) cscope.out *.o .*.d btrfs-convert btrfs-image btrfs-select-super \ btrfs-zero-log btrfstune dir-test ioctl-test quick-test version.h + rm -f helpmsg.c cd man; make clean install: $(progs) install-man -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Seemingly Similar Threads
- [Btrfs-Progs] Update for lzo support
- [RFC] Improve btrfs subvolume find-new command
- [PATCH 4/5][REPOST][BTRFS-PROGS] Avoid to scan cdrom and floppy
- [Request for review] [RFC] Add label support for snapshots and subvols
- [PATCH] BTRFS-PROG: recursively subvolume snapshot and delete