diff --git a/src/.gitignore b/src/.gitignore index 8ab6874..4220d68 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,2 +1,3 @@ +*.new.c +bees-usage.c bees-version.[ch] -bees-version.new.c diff --git a/src/Makefile b/src/Makefile index 90cbaad..aef8cbc 100644 --- a/src/Makefile +++ b/src/Makefile @@ -23,6 +23,10 @@ bees-version.c: bees.h $(BEES_OBJS:.o=.cc) Makefile echo "const char *BEES_VERSION = \"$(BEES_VERSION)\";" > bees-version.new.c mv -f bees-version.new.c bees-version.c +bees-usage.c: bees-usage.txt Makefile + (echo 'const char *BEES_USAGE = '; sed -r 's/^(.*)$$/"\1\\n"/' < bees-usage.txt; echo ';') > bees-usage.new.c + mv -f bees-usage.new.c bees-usage.c + .depends: mkdir -p $@ @@ -41,10 +45,9 @@ $(BEES_OBJS) fiemap.o fiewalk.o: %.o: %.cc $(PROGRAMS): ../bin/%: %.o $(CXX) $(BEES_CXXFLAGS) $(BEES_LDFLAGS) -o $@ $< $(LIBS) -bees-version.o: %.o: %.c - $(CC) $(BEES_CFLAGS) -o $@ -c $< +$(PROGRAMS): ../lib/libcrucible.a -$(BEES): $(BEES_OBJS) bees-version.o +$(BEES): $(BEES_OBJS) bees-version.o bees-usage.o $(CXX) $(BEES_CXXFLAGS) $(BEES_LDFLAGS) -o $@ $^ $(LIBS) clean: diff --git a/src/bees-usage.txt b/src/bees-usage.txt new file mode 100644 index 0000000..cc35bde --- /dev/null +++ b/src/bees-usage.txt @@ -0,0 +1,35 @@ +Usage: %s [options] fs-root-path +Performs best-effort extent-same deduplication on btrfs. + +fs-root-path MUST be the root of a btrfs filesystem tree (subvol id 5). +Other directories will be rejected. + +Options: + -h, --help Show this help + +Load management options: + -c, --thread-count Worker thread count (default CPU count * factor) + -C, --thread-factor Worker thread factor (default 1) + -G, --thread-min Minimum worker thread count (default 0) + -g, --loadavg-target Target load average for worker threads (default none) + +Filesystem tree traversal options: + -m, --scan-mode Scanning mode (0..2, default 0) + +Workarounds: + -a, --workaround-btrfs-send Workaround for btrfs send + (ignore RO snapshots) + +Logging options: + -t, --timestamps Show timestamps in log output (default) + -T, --no-timestamps Omit timestamps in log output + -p, --absolute-paths Show absolute paths (default) + -P, --strip-paths Strip $CWD from beginning of all paths in the log + -v, --verbose Set maximum log level (0..8, default 8) + +Optional environment variables: + BEESHOME Path to hash table and configuration files + (default is .beeshome/ in the root of the filesystem). + + BEESSTATUS File to write status to (tmpfs recommended, e.g. /run). + No status is written if this variable is unset. diff --git a/src/bees.cc b/src/bees.cc index 4e17130..e570c0f 100644 --- a/src/bees.cc +++ b/src/bees.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -35,44 +36,7 @@ int bees_log_level = 8; void do_cmd_help(char *argv[]) { - // 80col 01234567890123456789012345678901234567890123456789012345678901234567890123456789 - cerr << "Usage: " << argv[0] << " [options] fs-root-path [fs-root-path-2...]\n" - "Performs best-effort extent-same deduplication on btrfs.\n" - "\n" - "fs-root-path MUST be the root of a btrfs filesystem tree (id 5).\n" - "Other directories will be rejected.\n" - "\n" - "Options:\n" - " -h, --help Show this help\n" - "\n" - "Load management options:\n" - " -c, --thread-count Worker thread count (default CPU count * factor)\n" - " -C, --thread-factor Worker thread factor (default " << BEES_DEFAULT_THREAD_FACTOR << ")\n" - " -G, --thread-min Minimum worker thread count (default 0)\n" - " -g, --loadavg-target Target load average for worker threads (default none)\n" - "\n" - "Filesystem tree traversal options:\n" - " -m, --scan-mode Scanning mode (0..2, default 0)\n" - "\n" - "Workarounds:\n" - " -a, --workaround-btrfs-send Workaround for btrfs send\n" - "\n" - "Logging options:\n" - " -t, --timestamps Show timestamps in log output (default)\n" - " -T, --no-timestamps Omit timestamps in log output\n" - " -p, --absolute-paths Show absolute paths (default)\n" - " -P, --strip-paths Strip $CWD from beginning of all paths in the log\n" - " -v, --verbose Set maximum log level (0..8, default 8)\n" - "\n" - "Optional environment variables:\n" - " BEESHOME Path to hash table and configuration files\n" - " (default is .beeshome/ in the root of each filesystem).\n" - "\n" - " BEESSTATUS File to write status to (tmpfs recommended, e.g. /run).\n" - " No status is written if this variable is unset.\n" - "\n" - // 80col 01234567890123456789012345678901234567890123456789012345678901234567890123456789 - << endl; + fprintf(stderr, BEES_USAGE, argv[0]); } // tracing ---------------------------------------- diff --git a/src/bees.h b/src/bees.h index 31b9bc1..1fe1238 100644 --- a/src/bees.h +++ b/src/bees.h @@ -866,6 +866,7 @@ public: // And now, a giant pile of extern declarations extern int bees_log_level; +extern const char *BEES_USAGE; extern const char *BEES_VERSION; string pretty(double d); void bees_sync(int fd);