X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=cmds-filesystem.c;h=25d3c0cfae00051336326357b6ebecc39ab31985;hb=e764625f90f947f927f78b4166a34d9d5755ef63;hp=46aa497362ad3144c20f60cd0737f9fde72453ee;hpb=a624f1616731da6113ab9c6613be733ab41e664b;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 46aa497..25d3c0c 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -150,7 +150,7 @@ static int cmd_filesystem_df(int argc, char **argv) return !!ret; } -static int match_search_item_kernel(__u8 *fsid, char *mnt, char *label, +static int match_search_item_kernel(u8 *fsid, char *mnt, char *label, char *search) { char uuidbuf[BTRFS_UUID_UNPARSED_SIZE]; @@ -173,7 +173,6 @@ static int match_search_item_kernel(__u8 *fsid, char *mnt, char *label, static int uuid_search(struct btrfs_fs_devices *fs_devices, const char *search) { char uuidbuf[BTRFS_UUID_UNPARSED_SIZE]; - struct list_head *cur; struct btrfs_device *device; int search_len = strlen(search); @@ -182,8 +181,7 @@ static int uuid_search(struct btrfs_fs_devices *fs_devices, const char *search) if (!strncmp(uuidbuf, search, search_len)) return 1; - list_for_each(cur, &fs_devices->devices) { - device = list_entry(cur, struct btrfs_device, dev_list); + list_for_each_entry(device, &fs_devices->devices, dev_list) { if ((device->label && strcmp(device->label, search) == 0) || strcmp(device->name, search) == 0) return 1; @@ -431,33 +429,6 @@ out: return !found; } -static int dev_to_fsid(const char *dev, __u8 *fsid) -{ - struct btrfs_super_block *disk_super; - char buf[BTRFS_SUPER_INFO_SIZE]; - int ret; - int fd; - - fd = open(dev, O_RDONLY); - if (fd < 0) { - ret = -errno; - return ret; - } - - disk_super = (struct btrfs_super_block *)buf; - ret = btrfs_read_dev_super(fd, disk_super, - BTRFS_SUPER_INFO_OFFSET, SBREAD_DEFAULT); - if (ret) - goto out; - - memcpy(fsid, disk_super->fsid, BTRFS_FSID_SIZE); - ret = 0; - -out: - close(fd); - return ret; -} - static void free_fs_devices(struct btrfs_fs_devices *fs_devices) { struct btrfs_fs_devices *cur_seed, *next_seed; @@ -705,7 +676,7 @@ static int cmd_filesystem_show(int argc, char **argv) int type = 0; char mp[PATH_MAX]; char path[PATH_MAX]; - __u8 fsid[BTRFS_FSID_SIZE]; + u8 fsid[BTRFS_FSID_SIZE]; char uuid_buf[BTRFS_UUID_UNPARSED_SIZE]; unsigned unit_mode; int found = 0; @@ -1056,23 +1027,22 @@ static int cmd_filesystem_defrag(int argc, char **argv) if (fd < 0) { error("cannot open %s: %s", argv[i], strerror(errno)); - defrag_global_errors++; - close_file_or_dir(fd, dirstream); - continue; + ret = -errno; + goto next; } - if (fstat(fd, &st)) { + + ret = fstat(fd, &st); + if (ret) { error("failed to stat %s: %s", argv[i], strerror(errno)); - defrag_global_errors++; - close_file_or_dir(fd, dirstream); - continue; + ret = -errno; + goto next; } if (!(S_ISDIR(st.st_mode) || S_ISREG(st.st_mode))) { error("%s is not a directory or a regular file", argv[i]); - defrag_global_errors++; - close_file_or_dir(fd, dirstream); - continue; + ret = -EINVAL; + goto next; } if (recursive && S_ISDIR(st.st_mode)) { ret = nftw(argv[i], defrag_callback, 10, @@ -1087,20 +1057,25 @@ static int cmd_filesystem_defrag(int argc, char **argv) ret = ioctl(fd, BTRFS_IOC_DEFRAG_RANGE, &defrag_global_range); defrag_err = errno; - } - close_file_or_dir(fd, dirstream); - if (ret && defrag_err == ENOTTY) { - error( + if (ret && defrag_err == ENOTTY) { + error( "defrag range ioctl not supported in this kernel version, 2.6.33 and newer is required"); - defrag_global_errors++; - break; + defrag_global_errors++; + close_file_or_dir(fd, dirstream); + break; + } + if (ret) { + error("defrag failed on %s: %s", argv[i], + strerror(defrag_err)); + goto next; + } } - if (ret) { - error("defrag failed on %s: %s", argv[i], - strerror(defrag_err)); +next: + if (ret) defrag_global_errors++; - } + close_file_or_dir(fd, dirstream); } + if (defrag_global_errors) fprintf(stderr, "total %d failures\n", defrag_global_errors);