btrfs-progs: add OPEN_CTREE_INVALIDATE_FST flag
[platform/upstream/btrfs-progs.git] / mkfs.c
diff --git a/mkfs.c b/mkfs.c
index 1e66f55..e501a93 100644 (file)
--- a/mkfs.c
+++ b/mkfs.c
@@ -344,24 +344,30 @@ static int create_data_reloc_tree(struct btrfs_trans_handle *trans,
 
 static void print_usage(int ret)
 {
-       printf("usage: mkfs.btrfs [options] dev [ dev ... ]\n");
-       printf("options:\n");
-       printf("\t-A|--alloc-start START  the offset to start the FS\n");
-       printf("\t-b|--byte-count SIZE    total number of bytes in the FS\n");
+       printf("Usage: mkfs.btrfs [options] dev [ dev ... ]\n");
+       printf("Options:\n");
+       printf("  allocation profiles:\n");
        printf("\t-d|--data PROFILE       data profile, raid0, raid1, raid5, raid6, raid10, dup or single\n");
-       printf("\t-f|--force              force overwrite of existing filesystem\n");
-       printf("\t-l|--leafsize SIZE      deprecated, alias for nodesize\n");
-       printf("\t-L|--label LABEL        set a label\n");
-       printf("\t-m|--metadata PROFILE   metadata profile, values like data profile\n");
+       printf("\t-m|--metadata PROFILE   metadata profile, values like for data profile\n");
        printf("\t-M|--mixed              mix metadata and data together\n");
+       printf("  features:\n");
        printf("\t-n|--nodesize SIZE      size of btree nodes\n");
-       printf("\t-s|--sectorsize SIZE    min block allocation (may not mountable by current kernel)\n");
-       printf("\t-r|--rootdir DIR        the source directory\n");
+       printf("\t-s|--sectorsize SIZE    data block size (may not be mountable by current kernel)\n");
+       printf("\t-O|--features LIST      comma separated list of filesystem features (use '-O list-all' to list features)\n");
+       printf("\t-L|--label LABEL        set the filesystem label\n");
+       printf("\t-U|--uuid UUID          specify the filesystem UUID (must be unique)\n");
+       printf("  creation:\n");
+       printf("\t-b|--byte-count SIZE    set filesystem size to SIZE (on the first device)\n");
+       printf("\t-r|--rootdir DIR        copy files from DIR to the image root directory\n");
        printf("\t-K|--nodiscard          do not perform whole device TRIM\n");
-       printf("\t-O|--features LIST      comma separated list of filesystem features, use '-O list-all' to list features\n");
-       printf("\t-U|--uuid UUID          specify the filesystem UUID\n");
+       printf("\t-f|--force              force overwrite of existing filesystem\n");
+       printf("  general:\n");
        printf("\t-q|--quiet              no messages except errors\n");
        printf("\t-V|--version            print the mkfs.btrfs version and exit\n");
+       printf("\t--help                  print this help and exit\n");
+       printf("  deprecated:\n");
+       printf("\t-A|--alloc-start START  the offset to start the filesytem\n");
+       printf("\t-l|--leafsize SIZE      deprecated, alias for nodesize\n");
        exit(ret);
 }
 
@@ -494,11 +500,11 @@ static int fill_inode_item(struct btrfs_trans_handle *trans,
 
 static int directory_select(const struct direct *entry)
 {
-       if ((strncmp(entry->d_name, ".", entry->d_reclen) == 0) ||
-               (strncmp(entry->d_name, "..", entry->d_reclen) == 0))
+       if (entry->d_name[0] == '.' &&
+               (entry->d_name[1] == 0 ||
+                (entry->d_name[1] == '.' && entry->d_name[2] == 0)))
                return 0;
-       else
-               return 1;
+       return 1;
 }
 
 static void free_namelist(struct direct **files, int count)
@@ -1310,15 +1316,10 @@ static int cleanup_temp_chunks(struct btrfs_fs_info *fs_info,
        struct btrfs_root *root = fs_info->extent_root;
        struct btrfs_key key;
        struct btrfs_key found_key;
-       struct btrfs_path *path;
+       struct btrfs_path path;
        int ret = 0;
 
-       path = btrfs_alloc_path();
-       if (!path) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
+       btrfs_init_path(&path);
        trans = btrfs_start_transaction(root, 1);
 
        key.objectid = 0;
@@ -1330,32 +1331,32 @@ static int cleanup_temp_chunks(struct btrfs_fs_info *fs_info,
                 * as the rest of the loop may modify the tree, we need to
                 * start a new search each time.
                 */
-               ret = btrfs_search_slot(trans, root, &key, path, 0, 0);
+               ret = btrfs_search_slot(trans, root, &key, &path, 0, 0);
                if (ret < 0)
                        goto out;
 
-               btrfs_item_key_to_cpu(path->nodes[0], &found_key,
-                                     path->slots[0]);
+               btrfs_item_key_to_cpu(path.nodes[0], &found_key,
+                                     path.slots[0]);
                if (found_key.objectid < key.objectid)
                        goto out;
                if (found_key.type != BTRFS_BLOCK_GROUP_ITEM_KEY) {
-                       ret = next_block_group(root, path);
+                       ret = next_block_group(root, &path);
                        if (ret < 0)
                                goto out;
                        if (ret > 0) {
                                ret = 0;
                                goto out;
                        }
-                       btrfs_item_key_to_cpu(path->nodes[0], &found_key,
-                                             path->slots[0]);
+                       btrfs_item_key_to_cpu(path.nodes[0], &found_key,
+                                             path.slots[0]);
                }
 
-               bgi = btrfs_item_ptr(path->nodes[0], path->slots[0],
+               bgi = btrfs_item_ptr(path.nodes[0], path.slots[0],
                                     struct btrfs_block_group_item);
-               if (is_temp_block_group(path->nodes[0], bgi,
+               if (is_temp_block_group(path.nodes[0], bgi,
                                        data_profile, meta_profile,
                                        sys_profile)) {
-                       u64 flags = btrfs_disk_block_group_flags(path->nodes[0],
+                       u64 flags = btrfs_disk_block_group_flags(path.nodes[0],
                                                             bgi);
 
                        ret = btrfs_free_block_group(trans, fs_info,
@@ -1377,13 +1378,13 @@ static int cleanup_temp_chunks(struct btrfs_fs_info *fs_info,
                                  BTRFS_BLOCK_GROUP_DATA))
                                alloc->mixed -= found_key.offset;
                }
-               btrfs_release_path(path);
+               btrfs_release_path(&path);
                key.objectid = found_key.objectid + found_key.offset;
        }
 out:
        if (trans)
                btrfs_commit_transaction(trans, root);
-       btrfs_free_path(path);
+       btrfs_release_path(&path);
        return ret;
 }
 
@@ -1894,7 +1895,7 @@ raid_groups:
                char features_buf[64];
 
                printf("Label:              %s\n", label);
-               printf("UUID:               %s\n", fs_uuid);
+               printf("UUID:               %s\n", mkfs_cfg.fs_uuid);
                printf("Node size:          %u\n", nodesize);
                printf("Sector size:        %u\n", sectorsize);
                printf("Filesystem size:    %s\n",