mirror of
https://github.com/kdave/btrfs-progs
synced 2024-12-25 23:52:17 +00:00
btrfs-progs: introduce helper for parsing args without options
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>
This commit is contained in:
parent
c26dc1ef33
commit
a6cc8ea10a
@ -70,7 +70,7 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.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 \
|
||||
@ -260,9 +260,9 @@ btrfs-%: $(objects) $(libs_static) btrfs-%.o
|
||||
$(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)
|
||||
@echo " [LD] $@"
|
||||
$(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)
|
||||
|
28
utils.c
28
utils.c
@ -37,6 +37,7 @@
|
||||
#include <sys/vfs.h>
|
||||
#include <sys/statfs.h>
|
||||
#include <linux/magic.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "kerncompat.h"
|
||||
#include "radix-tree.h"
|
||||
@ -47,6 +48,7 @@
|
||||
#include "utils.h"
|
||||
#include "volumes.h"
|
||||
#include "ioctl.h"
|
||||
#include "commands.h"
|
||||
|
||||
#ifndef BLKDISCARD
|
||||
#define BLKDISCARD _IO(0x12,119)
|
||||
@ -3119,3 +3121,29 @@ int string_is_numerical(const char *str)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
utils.h
1
utils.h
@ -274,6 +274,7 @@ const char *get_argv0_buf(void);
|
||||
"-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)))
|
||||
|
Loading…
Reference in New Issue
Block a user