btrfs-progs: typo review of strings and comments
[platform/upstream/btrfs-progs.git] / btrfs-list.c
index 875a89d..4cc2ed4 100644 (file)
@@ -226,13 +226,12 @@ struct btrfs_list_comparer_set *btrfs_list_alloc_comparer_set(void)
 
        size = sizeof(struct btrfs_list_comparer_set) +
               BTRFS_LIST_NCOMPS_INCREASE * sizeof(struct btrfs_list_comparer);
-       set = malloc(size);
+       set = calloc(1, size);
        if (!set) {
                fprintf(stderr, "memory allocation failed\n");
                exit(1);
        }
 
-       memset(set, 0, size);
        set->total = BTRFS_LIST_NCOMPS_INCREASE;
 
        return set;
@@ -254,11 +253,15 @@ static int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
        BUG_ON(set->ncomps > set->total);
 
        if (set->ncomps == set->total) {
+               void *tmp;
+
                size = set->total + BTRFS_LIST_NCOMPS_INCREASE;
                size = sizeof(*set) + size * sizeof(struct btrfs_list_comparer);
+               tmp = set;
                set = realloc(set, size);
                if (!set) {
                        fprintf(stderr, "memory allocation failed\n");
+                       free(tmp);
                        exit(1);
                }
 
@@ -470,12 +473,11 @@ static int add_root(struct root_lookup *root_lookup,
        if (!ret)
                return 0;
 
-       ri = malloc(sizeof(*ri));
+       ri = calloc(1, sizeof(*ri));
        if (!ri) {
                printf("memory allocation failed\n");
                exit(1);
        }
-       memset(ri, 0, sizeof(*ri));
        ri->root_id = root_id;
 
        if (name && name_len > 0) {
@@ -562,7 +564,7 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri,
                int add_len;
 
                /*
-                * ref_tree = 0 indicates the subvolumes
+                * ref_tree = 0 indicates the subvolume
                 * has been deleted.
                 */
                if (!found->ref_tree) {
@@ -628,7 +630,7 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri,
 static int lookup_ino_path(int fd, struct root_info *ri)
 {
        struct btrfs_ioctl_ino_lookup_args args;
-       int ret, e;
+       int ret;
 
        if (ri->path)
                return 0;
@@ -641,15 +643,14 @@ static int lookup_ino_path(int fd, struct root_info *ri)
        args.objectid = ri->dir_id;
 
        ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
-       e = errno;
-       if (ret) {
-               if (e == ENOENT) {
+       if (ret < 0) {
+               if (errno == ENOENT) {
                        ri->ref_tree = 0;
                        return -ENOENT;
                }
                fprintf(stderr, "ERROR: Failed to lookup path for root %llu - %s\n",
                        (unsigned long long)ri->ref_tree,
-                       strerror(e));
+                       strerror(errno));
                return ret;
        }
 
@@ -677,7 +678,7 @@ static int lookup_ino_path(int fd, struct root_info *ri)
 }
 
 /* finding the generation for a given path is a two step process.
- * First we use the inode loookup routine to find out the root id
+ * First we use the inode lookup routine to find out the root id
  *
  * Then we use the tree search ioctl to scan all the root items for a
  * given root id and spit out the latest generation we can find
@@ -692,18 +693,16 @@ static u64 find_root_gen(int fd)
        unsigned long off = 0;
        u64 max_found = 0;
        int i;
-       int e;
 
        memset(&ino_args, 0, sizeof(ino_args));
        ino_args.objectid = BTRFS_FIRST_FREE_OBJECTID;
 
        /* this ioctl fills in ino_args->treeid */
        ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &ino_args);
-       e = errno;
-       if (ret) {
+       if (ret < 0) {
                fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu - %s\n",
                        (unsigned long long)BTRFS_FIRST_FREE_OBJECTID,
-                       strerror(e));
+                       strerror(errno));
                return 0;
        }
 
@@ -726,10 +725,9 @@ static u64 find_root_gen(int fd)
 
        while (1) {
                ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
-               e = errno;
                if (ret < 0) {
                        fprintf(stderr, "ERROR: can't perform the search - %s\n",
-                               strerror(e));
+                               strerror(errno));
                        return 0;
                }
                /* the ioctl returns the number of item it found in nr_items */
@@ -783,16 +781,14 @@ static char *__ino_resolve(int fd, u64 dirid)
        struct btrfs_ioctl_ino_lookup_args args;
        int ret;
        char *full;
-       int e;
 
        memset(&args, 0, sizeof(args));
        args.objectid = dirid;
 
        ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
-       e = errno;
-       if (ret) {
+       if (ret < 0) {
                fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu - %s\n",
-                       (unsigned long long)dirid, strerror(e);
+                       (unsigned long long)dirid, strerror(errno));
                return ERR_PTR(ret);
        }
 
@@ -850,7 +846,6 @@ static char *ino_resolve(int fd, u64 ino, u64 *cache_dirid, char **cache_name)
        struct btrfs_ioctl_search_header *sh;
        unsigned long off = 0;
        int namelen;
-       int e;
 
        memset(&args, 0, sizeof(args));
 
@@ -869,10 +864,9 @@ static char *ino_resolve(int fd, u64 ino, u64 *cache_dirid, char **cache_name)
        sk->nr_items = 1;
 
        ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
-       e = errno;
        if (ret < 0) {
                fprintf(stderr, "ERROR: can't perform the search - %s\n",
-                       strerror(e));
+                       strerror(errno));
                return NULL;
        }
        /* the ioctl returns the number of item it found in nr_items */
@@ -882,9 +876,9 @@ static char *ino_resolve(int fd, u64 ino, u64 *cache_dirid, char **cache_name)
        off = 0;
        sh = (struct btrfs_ioctl_search_header *)(args.buf + off);
 
-       if (sh->type == BTRFS_INODE_REF_KEY) {
+       if (btrfs_search_header_type(sh) == BTRFS_INODE_REF_KEY) {
                struct btrfs_inode_ref *ref;
-               dirid = sh->offset;
+               dirid = btrfs_search_header_offset(sh);
 
                ref = (struct btrfs_inode_ref *)(sh + 1);
                namelen = btrfs_stack_inode_ref_name_len(ref);
@@ -953,7 +947,7 @@ int btrfs_list_get_default_subvolume(int fd, u64 *default_id)
 
        sh = (struct btrfs_ioctl_search_header *)args.buf;
 
-       if (sh->type == BTRFS_DIR_ITEM_KEY) {
+       if (btrfs_search_header_type(sh) == BTRFS_DIR_ITEM_KEY) {
                struct btrfs_dir_item *di;
                int name_len;
                char *name;
@@ -1204,13 +1198,12 @@ struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void)
 
        size = sizeof(struct btrfs_list_filter_set) +
               BTRFS_LIST_NFILTERS_INCREASE * sizeof(struct btrfs_list_filter);
-       set = malloc(size);
+       set = calloc(1, size);
        if (!set) {
                fprintf(stderr, "memory allocation failed\n");
                exit(1);
        }
 
-       memset(set, 0, size);
        set->total = BTRFS_LIST_NFILTERS_INCREASE;
 
        return set;
@@ -1232,11 +1225,15 @@ int btrfs_list_setup_filter(struct btrfs_list_filter_set **filter_set,
        BUG_ON(set->nfilters > set->total);
 
        if (set->nfilters == set->total) {
+               void *tmp;
+
                size = set->total + BTRFS_LIST_NFILTERS_INCREASE;
                size = sizeof(*set) + size * sizeof(struct btrfs_list_filter);
+               tmp = set;
                set = realloc(set, size);
                if (!set) {
                        fprintf(stderr, "memory allocation failed\n");
+                       free(tmp);
                        exit(1);
                }
 
@@ -1605,17 +1602,18 @@ static int print_one_extent(int fd, struct btrfs_ioctl_search_header *sh,
        int flags = 0;
        char *name = NULL;
 
-       if (sh->objectid == *cache_ino) {
+       if (btrfs_search_header_objectid(sh) == *cache_ino) {
                name = *cache_full_name;
        } else if (*cache_full_name) {
                free(*cache_full_name);
                *cache_full_name = NULL;
        }
        if (!name) {
-               name = ino_resolve(fd, sh->objectid, cache_dirid,
+               name = ino_resolve(fd, btrfs_search_header_objectid(sh),
+                                  cache_dirid,
                                   cache_dir_name);
                *cache_full_name = name;
-               *cache_ino = sh->objectid;
+               *cache_ino = btrfs_search_header_objectid(sh);
        }
        if (!name)
                return -EIO;
@@ -1636,16 +1634,16 @@ static int print_one_extent(int fd, struct btrfs_ioctl_search_header *sh,
                printf("unhandled extent type %d for inode %llu "
                       "file offset %llu gen %llu\n",
                        type,
-                       (unsigned long long)sh->objectid,
-                       (unsigned long long)sh->offset,
+                       (unsigned long long)btrfs_search_header_objectid(sh),
+                       (unsigned long long)btrfs_search_header_offset(sh),
                        (unsigned long long)found_gen);
 
                return -EIO;
        }
        printf("inode %llu file offset %llu len %llu disk start %llu "
               "offset %llu gen %llu flags ",
-              (unsigned long long)sh->objectid,
-              (unsigned long long)sh->offset,
+              (unsigned long long)btrfs_search_header_objectid(sh),
+              (unsigned long long)btrfs_search_header_offset(sh),
               (unsigned long long)len,
               (unsigned long long)disk_start,
               (unsigned long long)disk_offset,
@@ -1681,7 +1679,6 @@ int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen)
        u64 found_gen;
        u64 max_found = 0;
        int i;
-       int e;
        u64 cache_dirid = 0;
        u64 cache_ino = 0;
        char *cache_dir_name = NULL;
@@ -1708,10 +1705,9 @@ int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen)
        max_found = find_root_gen(fd);
        while(1) {
                ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
-               e = errno;
                if (ret < 0) {
                        fprintf(stderr, "ERROR: can't perform the search - %s\n",
-                               strerror(e));
+                               strerror(errno));
                        break;
                }
                /* the ioctl returns the number of item it found in nr_items */