All commands should support the "--" option separator. This is
transparently handled by getopt, but we don't use that everywhere.
Introduce a helper for commands that take no options (just the path).
The object file dependencies need to be adjusted a bit.
Signed-off-by: David Sterba <dsterba@suse.com>
extent-cache.o extent_io.o volumes.o utils.o repair.o \
qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
extent-cache.o extent_io.o volumes.o utils.o repair.o \
qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
- inode.o file.o find-root.o free-space-tree.o
+ inode.o file.o find-root.o free-space-tree.o help.o
cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
$(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o $(libs_static) \
$(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
$(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o $(libs_static) \
$(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
-btrfs: $(objects) btrfs.o help.o $(cmds_objects) $(libs_static)
+btrfs: $(objects) btrfs.o $(cmds_objects) $(libs_static)
- $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
+ $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o $(cmds_objects) \
$(objects) $(libs_static) $(LDFLAGS) $(LIBS)
btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
$(objects) $(libs_static) $(LDFLAGS) $(LIBS)
btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
#include <sys/vfs.h>
#include <sys/statfs.h>
#include <linux/magic.h>
#include <sys/vfs.h>
#include <sys/statfs.h>
#include <linux/magic.h>
#include "kerncompat.h"
#include "radix-tree.h"
#include "kerncompat.h"
#include "radix-tree.h"
#include "utils.h"
#include "volumes.h"
#include "ioctl.h"
#include "utils.h"
#include "volumes.h"
#include "ioctl.h"
#ifndef BLKDISCARD
#define BLKDISCARD _IO(0x12,119)
#ifndef BLKDISCARD
#define BLKDISCARD _IO(0x12,119)
+
+/*
+ * Preprocess @argv with getopt_long to reorder options and consume the "--"
+ * option separator.
+ * Unknown short and long options are reported, optionally the @usage is printed
+ * before exit.
+ */
+void clean_args_no_options(int argc, char *argv[], const char * const *usagestr)
+{
+ static const struct option long_options[] = {
+ {NULL, 0, NULL, 0}
+ };
+
+ while (1) {
+ int c = getopt_long(argc, argv, "", long_options, NULL);
+
+ if (c < 0)
+ break;
+
+ switch (c) {
+ default:
+ if (usagestr)
+ usage(usagestr);
+ }
+ }
+}
"-t|--tbytes show sizes in TiB, or TB with --si"
unsigned int get_unit_mode_from_arg(int *argc, char *argv[], int df_mode);
"-t|--tbytes show sizes in TiB, or TB with --si"
unsigned int get_unit_mode_from_arg(int *argc, char *argv[], int df_mode);
+void clean_args_no_options(int argc, char *argv[], const char * const *usage);
int string_is_numerical(const char *str);
__attribute__ ((format (printf, 1, 2)))
int string_is_numerical(const char *str);
__attribute__ ((format (printf, 1, 2)))