diff options
author | ghigo <ghigo@kreijack.homelinux.net> | 2010-01-24 18:00:05 +0100 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2010-03-11 13:45:47 -0500 |
commit | 6d2cf042471cc728b5399b2beae54603739bc66a (patch) | |
tree | 0d8ea823ec7c1e4676630153eee998cc6fcfb62c /btrfs-list.c | |
parent | 06cbf62fda156d1399022158d671353d1a3aeaec (diff) |
new util: 'btrfs'
This commit introduces a new command called 'btrfs' for managing
a btrfs filesystem. 'btrfs' handles:
- snapshot/subvolume creation
- adding/removal of volume (ie: disk)
- defragment of a tree
- scan of a device searching a btrfs filesystem
- re-balancing of the chunk on the disks
- listing subvolumes and snapshots
This has also been updated to include the new defrag range ioctl.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'btrfs-list.c')
-rw-r--r-- | btrfs-list.c | 55 |
1 files changed, 4 insertions, 51 deletions
diff --git a/btrfs-list.c b/btrfs-list.c index c922f097..6305d3c5 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -154,39 +154,6 @@ static struct root_info *tree_search(struct rb_root *root, u64 root_id) } /* - * helper to open either a file or directory so that - * we can run ioctls on it. - */ -static int open_file_or_dir(const char *fname) -{ - int ret; - struct stat st; - DIR *dirstream; - int fd; - - ret = stat(fname, &st); - if (ret < 0) { - perror("stat:"); - exit(1); - } - if (S_ISDIR(st.st_mode)) { - dirstream = opendir(fname); - if (!dirstream) { - perror("opendir"); - exit(1); - } - fd = dirfd(dirstream); - } else { - fd = open(fname, O_RDWR); - } - if (fd < 0) { - perror("open"); - exit(1); - } - return fd; -} - -/* * this allocates a new root in the lookup tree. * * root_id should be the object id of the root @@ -205,11 +172,12 @@ static int add_root(struct root_lookup *root_lookup, { struct root_info *ri; struct rb_node *ret; - ri = malloc(sizeof(*ri) + name_len); + ri = malloc(sizeof(*ri) + name_len + 1); if (!ri) { printf("memory allocation failed\n"); exit(1); } + memset(ri, 0, sizeof(*ri) + name_len + 1); ri->path = NULL; ri->dir_id = dir_id; ri->root_id = root_id; @@ -301,9 +269,9 @@ static int lookup_ino_path(int fd, struct root_info *ri) if (ri->path) return 0; + memset(&args, 0, sizeof(args)); args.treeid = ri->ref_tree; args.objectid = ri->dir_id; - args.name[0] = '\0'; ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args); if (ret) { @@ -335,7 +303,7 @@ static int lookup_ino_path(int fd, struct root_info *ri) return 0; } -static int list_subvols(int fd) +int list_subvols(int fd) { struct root_lookup root_lookup; struct rb_node *n; @@ -447,20 +415,5 @@ static int list_subvols(int fd) n = rb_prev(n); } - printf("%s\n", BTRFS_BUILD_VERSION); return ret; } - -int main(int ac, char **av) -{ - int fd; - - if (ac != 2) { - fprintf(stderr, "usage: btrfs-list mount_point\n"); - exit(1); - } - fd = open_file_or_dir(av[1]); - - return list_subvols(fd); -} - |