btrfs-progs: mkfs: move btrfs_make_root_dir from utils.c

The helper is used in several tools but logically belongs to mkfs, so
put it to the common section.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-04-30 00:07:15 +02:00
parent d591cd7c08
commit cfbcfaa4e4
6 changed files with 48 additions and 43 deletions

View File

@ -188,7 +188,8 @@ libbtrfsutil_objects = libbtrfsutil/errors.o libbtrfsutil/filesystem.o \
libbtrfsutil/subvolume.o libbtrfsutil/qgroup.o \
libbtrfsutil/stubs.o
convert_objects = convert/main.o convert/common.o convert/source-fs.o \
convert/source-ext2.o convert/source-reiserfs.o
convert/source-ext2.o convert/source-reiserfs.o \
mkfs/common.o
mkfs_objects = mkfs/main.o mkfs/common.o mkfs/rootdir.o
image_objects = image/main.o image/sanitize.o
all_objects = $(objects) $(cmds_objects) $(libbtrfs_objects) $(convert_objects) \

View File

@ -47,6 +47,7 @@
#include "check/mode-lowmem.h"
#include "check/qgroup-verify.h"
#include "common/open-utils.h"
#include "mkfs/common.h"
u64 bytes_used = 0;
u64 total_csum_bytes = 0;

View File

@ -59,45 +59,6 @@ static unsigned short rand_seed[3];
struct btrfs_config bconf;
int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid)
{
int ret;
struct btrfs_inode_item inode_item;
time_t now = time(NULL);
memset(&inode_item, 0, sizeof(inode_item));
btrfs_set_stack_inode_generation(&inode_item, trans->transid);
btrfs_set_stack_inode_size(&inode_item, 0);
btrfs_set_stack_inode_nlink(&inode_item, 1);
btrfs_set_stack_inode_nbytes(&inode_item, root->fs_info->nodesize);
btrfs_set_stack_inode_mode(&inode_item, S_IFDIR | 0755);
btrfs_set_stack_timespec_sec(&inode_item.atime, now);
btrfs_set_stack_timespec_nsec(&inode_item.atime, 0);
btrfs_set_stack_timespec_sec(&inode_item.ctime, now);
btrfs_set_stack_timespec_nsec(&inode_item.ctime, 0);
btrfs_set_stack_timespec_sec(&inode_item.mtime, now);
btrfs_set_stack_timespec_nsec(&inode_item.mtime, 0);
btrfs_set_stack_timespec_sec(&inode_item.otime, now);
btrfs_set_stack_timespec_nsec(&inode_item.otime, 0);
if (root->fs_info->tree_root == root)
btrfs_set_super_root_dir(root->fs_info->super_copy, objectid);
ret = btrfs_insert_inode(trans, root, objectid, &inode_item);
if (ret)
goto error;
ret = btrfs_insert_inode_ref(trans, root, "..", 2, objectid, objectid, 0);
if (ret)
goto error;
btrfs_set_root_dirid(&root->root_item, objectid);
ret = 0;
error:
return ret;
}
struct pending_dir {
struct list_head list;
char name[PATH_MAX];

View File

@ -42,9 +42,6 @@ enum exclusive_operation {
BTRFS_EXCLOP_UNKNOWN = -1,
};
int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid);
enum btrfs_csum_type parse_csum_type(const char *s);
u64 parse_size_from_string(const char *s);
u64 parse_qgroupid(const char *p);

View File

@ -22,6 +22,7 @@
#include "kernel-shared/ctree.h"
#include "kernel-shared/disk-io.h"
#include "kernel-shared/volumes.h"
#include "kernel-shared/transaction.h"
#include "kernel-shared/zoned.h"
#include "common/utils.h"
#include "common/path-utils.h"
@ -490,6 +491,45 @@ out:
return ret;
}
int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid)
{
int ret;
struct btrfs_inode_item inode_item;
time_t now = time(NULL);
memset(&inode_item, 0, sizeof(inode_item));
btrfs_set_stack_inode_generation(&inode_item, trans->transid);
btrfs_set_stack_inode_size(&inode_item, 0);
btrfs_set_stack_inode_nlink(&inode_item, 1);
btrfs_set_stack_inode_nbytes(&inode_item, root->fs_info->nodesize);
btrfs_set_stack_inode_mode(&inode_item, S_IFDIR | 0755);
btrfs_set_stack_timespec_sec(&inode_item.atime, now);
btrfs_set_stack_timespec_nsec(&inode_item.atime, 0);
btrfs_set_stack_timespec_sec(&inode_item.ctime, now);
btrfs_set_stack_timespec_nsec(&inode_item.ctime, 0);
btrfs_set_stack_timespec_sec(&inode_item.mtime, now);
btrfs_set_stack_timespec_nsec(&inode_item.mtime, 0);
btrfs_set_stack_timespec_sec(&inode_item.otime, now);
btrfs_set_stack_timespec_nsec(&inode_item.otime, 0);
if (root->fs_info->tree_root == root)
btrfs_set_super_root_dir(root->fs_info->super_copy, objectid);
ret = btrfs_insert_inode(trans, root, objectid, &inode_item);
if (ret)
goto error;
ret = btrfs_insert_inode_ref(trans, root, "..", 2, objectid, objectid, 0);
if (ret)
goto error;
btrfs_set_root_dirid(&root->root_item, objectid);
ret = 0;
error:
return ret;
}
/*
* Btrfs minimum size calculation is complicated, it should include at least:
* 1. system group size

View File

@ -38,6 +38,9 @@
#define BTRFS_MKFS_DEFAULT_DATA_MULTI_DEVICE 0 /* SINGLE */
#define BTRFS_MKFS_DEFAULT_META_MULTI_DEVICE BTRFS_BLOCK_GROUP_RAID1
struct btrfs_trans_handle;
struct btrfs_root;
/*
* Tree root blocks created during mkfs
*/
@ -79,6 +82,8 @@ struct btrfs_mkfs_config {
};
int make_btrfs(int fd, struct btrfs_mkfs_config *cfg);
int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid);
u64 btrfs_min_dev_size(u32 nodesize, int mixed, u64 meta_profile,
u64 data_profile);
int test_minimum_size(const char *file, u64 min_dev_size);