2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public
4 * License v2 as published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 * General Public License for more details.
11 * You should have received a copy of the GNU General Public
12 * License along with this program; if not, write to the
13 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14 * Boston, MA 021110-1307, USA.
18 #include <uuid/uuid.h>
19 #include <blkid/blkid.h>
26 #include "mkfs/common.h"
28 static u64 reference_root_table[] = {
29 [1] = BTRFS_ROOT_TREE_OBJECTID,
30 [2] = BTRFS_EXTENT_TREE_OBJECTID,
31 [3] = BTRFS_CHUNK_TREE_OBJECTID,
32 [4] = BTRFS_DEV_TREE_OBJECTID,
33 [5] = BTRFS_FS_TREE_OBJECTID,
34 [6] = BTRFS_CSUM_TREE_OBJECTID,
38 * @fs_uuid - if NULL, generates a UUID, returns back the new filesystem UUID
40 * The superblock signature is not valid, denotes a partially created
41 * filesystem, needs to be finalized.
43 int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
45 struct btrfs_super_block super;
46 struct extent_buffer *buf;
47 struct btrfs_root_item root_item;
48 struct btrfs_disk_key disk_key;
49 struct btrfs_extent_item *extent_item;
50 struct btrfs_inode_item *inode_item;
51 struct btrfs_chunk *chunk;
52 struct btrfs_dev_item *dev_item;
53 struct btrfs_dev_extent *dev_extent;
54 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
64 int skinny_metadata = !!(cfg->features &
65 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA);
68 buf = malloc(sizeof(*buf) + max(cfg->sectorsize, cfg->nodesize));
72 first_free = BTRFS_SUPER_INFO_OFFSET + cfg->sectorsize * 2 - 1;
73 first_free &= ~((u64)cfg->sectorsize - 1);
75 memset(&super, 0, sizeof(super));
77 num_bytes = (cfg->num_bytes / cfg->sectorsize) * cfg->sectorsize;
79 if (uuid_parse(cfg->fs_uuid, super.fsid) != 0) {
80 error("cannot not parse UUID: %s", cfg->fs_uuid);
84 if (!test_uuid_unique(cfg->fs_uuid)) {
85 error("non-unique UUID: %s", cfg->fs_uuid);
90 uuid_generate(super.fsid);
91 uuid_unparse(super.fsid, cfg->fs_uuid);
93 uuid_generate(super.dev_item.uuid);
94 uuid_generate(chunk_tree_uuid);
96 cfg->blocks[0] = BTRFS_SUPER_INFO_OFFSET;
97 for (i = 1; i < 7; i++) {
98 cfg->blocks[i] = BTRFS_SUPER_INFO_OFFSET + 1024 * 1024 +
102 btrfs_set_super_bytenr(&super, cfg->blocks[0]);
103 btrfs_set_super_num_devices(&super, 1);
104 btrfs_set_super_magic(&super, BTRFS_MAGIC_PARTIAL);
105 btrfs_set_super_generation(&super, 1);
106 btrfs_set_super_root(&super, cfg->blocks[1]);
107 btrfs_set_super_chunk_root(&super, cfg->blocks[3]);
108 btrfs_set_super_total_bytes(&super, num_bytes);
109 btrfs_set_super_bytes_used(&super, 6 * cfg->nodesize);
110 btrfs_set_super_sectorsize(&super, cfg->sectorsize);
111 btrfs_set_super_leafsize(&super, cfg->nodesize);
112 btrfs_set_super_nodesize(&super, cfg->nodesize);
113 btrfs_set_super_stripesize(&super, cfg->stripesize);
114 btrfs_set_super_csum_type(&super, BTRFS_CSUM_TYPE_CRC32);
115 btrfs_set_super_chunk_root_generation(&super, 1);
116 btrfs_set_super_cache_generation(&super, -1);
117 btrfs_set_super_incompat_flags(&super, cfg->features);
119 __strncpy_null(super.label, cfg->label, BTRFS_LABEL_SIZE - 1);
121 /* create the tree of root objects */
122 memset(buf->data, 0, cfg->nodesize);
123 buf->len = cfg->nodesize;
124 btrfs_set_header_bytenr(buf, cfg->blocks[1]);
125 btrfs_set_header_nritems(buf, 4);
126 btrfs_set_header_generation(buf, 1);
127 btrfs_set_header_backref_rev(buf, BTRFS_MIXED_BACKREF_REV);
128 btrfs_set_header_owner(buf, BTRFS_ROOT_TREE_OBJECTID);
129 write_extent_buffer(buf, super.fsid, btrfs_header_fsid(),
132 write_extent_buffer(buf, chunk_tree_uuid,
133 btrfs_header_chunk_tree_uuid(buf),
136 /* create the items for the root tree */
137 memset(&root_item, 0, sizeof(root_item));
138 inode_item = &root_item.inode;
139 btrfs_set_stack_inode_generation(inode_item, 1);
140 btrfs_set_stack_inode_size(inode_item, 3);
141 btrfs_set_stack_inode_nlink(inode_item, 1);
142 btrfs_set_stack_inode_nbytes(inode_item, cfg->nodesize);
143 btrfs_set_stack_inode_mode(inode_item, S_IFDIR | 0755);
144 btrfs_set_root_refs(&root_item, 1);
145 btrfs_set_root_used(&root_item, cfg->nodesize);
146 btrfs_set_root_generation(&root_item, 1);
148 memset(&disk_key, 0, sizeof(disk_key));
149 btrfs_set_disk_key_type(&disk_key, BTRFS_ROOT_ITEM_KEY);
150 btrfs_set_disk_key_offset(&disk_key, 0);
153 itemoff = __BTRFS_LEAF_DATA_SIZE(cfg->nodesize) - sizeof(root_item);
154 btrfs_set_root_bytenr(&root_item, cfg->blocks[2]);
155 btrfs_set_disk_key_objectid(&disk_key, BTRFS_EXTENT_TREE_OBJECTID);
156 btrfs_set_item_key(buf, &disk_key, nritems);
157 btrfs_set_item_offset(buf, btrfs_item_nr(nritems), itemoff);
158 btrfs_set_item_size(buf, btrfs_item_nr(nritems),
160 write_extent_buffer(buf, &root_item, btrfs_item_ptr_offset(buf,
161 nritems), sizeof(root_item));
164 itemoff = itemoff - sizeof(root_item);
165 btrfs_set_root_bytenr(&root_item, cfg->blocks[4]);
166 btrfs_set_disk_key_objectid(&disk_key, BTRFS_DEV_TREE_OBJECTID);
167 btrfs_set_item_key(buf, &disk_key, nritems);
168 btrfs_set_item_offset(buf, btrfs_item_nr(nritems), itemoff);
169 btrfs_set_item_size(buf, btrfs_item_nr(nritems),
171 write_extent_buffer(buf, &root_item,
172 btrfs_item_ptr_offset(buf, nritems),
176 itemoff = itemoff - sizeof(root_item);
177 btrfs_set_root_bytenr(&root_item, cfg->blocks[5]);
178 btrfs_set_disk_key_objectid(&disk_key, BTRFS_FS_TREE_OBJECTID);
179 btrfs_set_item_key(buf, &disk_key, nritems);
180 btrfs_set_item_offset(buf, btrfs_item_nr(nritems), itemoff);
181 btrfs_set_item_size(buf, btrfs_item_nr(nritems),
183 write_extent_buffer(buf, &root_item,
184 btrfs_item_ptr_offset(buf, nritems),
188 itemoff = itemoff - sizeof(root_item);
189 btrfs_set_root_bytenr(&root_item, cfg->blocks[6]);
190 btrfs_set_disk_key_objectid(&disk_key, BTRFS_CSUM_TREE_OBJECTID);
191 btrfs_set_item_key(buf, &disk_key, nritems);
192 btrfs_set_item_offset(buf, btrfs_item_nr(nritems), itemoff);
193 btrfs_set_item_size(buf, btrfs_item_nr(nritems),
195 write_extent_buffer(buf, &root_item,
196 btrfs_item_ptr_offset(buf, nritems),
201 csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
202 ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[1]);
203 if (ret != cfg->nodesize) {
204 ret = (ret < 0 ? -errno : -EIO);
208 /* create the items for the extent tree */
209 memset(buf->data + sizeof(struct btrfs_header), 0,
210 cfg->nodesize - sizeof(struct btrfs_header));
212 itemoff = __BTRFS_LEAF_DATA_SIZE(cfg->nodesize);
213 for (i = 1; i < 7; i++) {
214 item_size = sizeof(struct btrfs_extent_item);
215 if (!skinny_metadata)
216 item_size += sizeof(struct btrfs_tree_block_info);
218 if (cfg->blocks[i] < first_free) {
219 error("block[%d] below first free: %llu < %llu",
220 i, (unsigned long long)cfg->blocks[i],
221 (unsigned long long)first_free);
225 if (cfg->blocks[i] < cfg->blocks[i - 1]) {
226 error("blocks %d and %d in reverse order: %llu < %llu",
228 (unsigned long long)cfg->blocks[i],
229 (unsigned long long)cfg->blocks[i - 1]);
234 /* create extent item */
235 itemoff -= item_size;
236 btrfs_set_disk_key_objectid(&disk_key, cfg->blocks[i]);
237 if (skinny_metadata) {
238 btrfs_set_disk_key_type(&disk_key,
239 BTRFS_METADATA_ITEM_KEY);
240 btrfs_set_disk_key_offset(&disk_key, 0);
242 btrfs_set_disk_key_type(&disk_key,
243 BTRFS_EXTENT_ITEM_KEY);
244 btrfs_set_disk_key_offset(&disk_key, cfg->nodesize);
246 btrfs_set_item_key(buf, &disk_key, nritems);
247 btrfs_set_item_offset(buf, btrfs_item_nr(nritems),
249 btrfs_set_item_size(buf, btrfs_item_nr(nritems),
251 extent_item = btrfs_item_ptr(buf, nritems,
252 struct btrfs_extent_item);
253 btrfs_set_extent_refs(buf, extent_item, 1);
254 btrfs_set_extent_generation(buf, extent_item, 1);
255 btrfs_set_extent_flags(buf, extent_item,
256 BTRFS_EXTENT_FLAG_TREE_BLOCK);
259 /* create extent ref */
260 ref_root = reference_root_table[i];
261 btrfs_set_disk_key_objectid(&disk_key, cfg->blocks[i]);
262 btrfs_set_disk_key_offset(&disk_key, ref_root);
263 btrfs_set_disk_key_type(&disk_key, BTRFS_TREE_BLOCK_REF_KEY);
264 btrfs_set_item_key(buf, &disk_key, nritems);
265 btrfs_set_item_offset(buf, btrfs_item_nr(nritems),
267 btrfs_set_item_size(buf, btrfs_item_nr(nritems), 0);
270 btrfs_set_header_bytenr(buf, cfg->blocks[2]);
271 btrfs_set_header_owner(buf, BTRFS_EXTENT_TREE_OBJECTID);
272 btrfs_set_header_nritems(buf, nritems);
273 csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
274 ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[2]);
275 if (ret != cfg->nodesize) {
276 ret = (ret < 0 ? -errno : -EIO);
280 /* create the chunk tree */
281 memset(buf->data + sizeof(struct btrfs_header), 0,
282 cfg->nodesize - sizeof(struct btrfs_header));
284 item_size = sizeof(*dev_item);
285 itemoff = __BTRFS_LEAF_DATA_SIZE(cfg->nodesize) - item_size;
287 /* first device 1 (there is no device 0) */
288 btrfs_set_disk_key_objectid(&disk_key, BTRFS_DEV_ITEMS_OBJECTID);
289 btrfs_set_disk_key_offset(&disk_key, 1);
290 btrfs_set_disk_key_type(&disk_key, BTRFS_DEV_ITEM_KEY);
291 btrfs_set_item_key(buf, &disk_key, nritems);
292 btrfs_set_item_offset(buf, btrfs_item_nr(nritems), itemoff);
293 btrfs_set_item_size(buf, btrfs_item_nr(nritems), item_size);
295 dev_item = btrfs_item_ptr(buf, nritems, struct btrfs_dev_item);
296 btrfs_set_device_id(buf, dev_item, 1);
297 btrfs_set_device_generation(buf, dev_item, 0);
298 btrfs_set_device_total_bytes(buf, dev_item, num_bytes);
299 btrfs_set_device_bytes_used(buf, dev_item,
300 BTRFS_MKFS_SYSTEM_GROUP_SIZE);
301 btrfs_set_device_io_align(buf, dev_item, cfg->sectorsize);
302 btrfs_set_device_io_width(buf, dev_item, cfg->sectorsize);
303 btrfs_set_device_sector_size(buf, dev_item, cfg->sectorsize);
304 btrfs_set_device_type(buf, dev_item, 0);
306 write_extent_buffer(buf, super.dev_item.uuid,
307 (unsigned long)btrfs_device_uuid(dev_item),
309 write_extent_buffer(buf, super.fsid,
310 (unsigned long)btrfs_device_fsid(dev_item),
312 read_extent_buffer(buf, &super.dev_item, (unsigned long)dev_item,
316 item_size = btrfs_chunk_item_size(1);
317 itemoff = itemoff - item_size;
319 /* then we have chunk 0 */
320 btrfs_set_disk_key_objectid(&disk_key, BTRFS_FIRST_CHUNK_TREE_OBJECTID);
321 btrfs_set_disk_key_offset(&disk_key, 0);
322 btrfs_set_disk_key_type(&disk_key, BTRFS_CHUNK_ITEM_KEY);
323 btrfs_set_item_key(buf, &disk_key, nritems);
324 btrfs_set_item_offset(buf, btrfs_item_nr(nritems), itemoff);
325 btrfs_set_item_size(buf, btrfs_item_nr(nritems), item_size);
327 chunk = btrfs_item_ptr(buf, nritems, struct btrfs_chunk);
328 btrfs_set_chunk_length(buf, chunk, BTRFS_MKFS_SYSTEM_GROUP_SIZE);
329 btrfs_set_chunk_owner(buf, chunk, BTRFS_EXTENT_TREE_OBJECTID);
330 btrfs_set_chunk_stripe_len(buf, chunk, BTRFS_STRIPE_LEN);
331 btrfs_set_chunk_type(buf, chunk, BTRFS_BLOCK_GROUP_SYSTEM);
332 btrfs_set_chunk_io_align(buf, chunk, cfg->sectorsize);
333 btrfs_set_chunk_io_width(buf, chunk, cfg->sectorsize);
334 btrfs_set_chunk_sector_size(buf, chunk, cfg->sectorsize);
335 btrfs_set_chunk_num_stripes(buf, chunk, 1);
336 btrfs_set_stripe_devid_nr(buf, chunk, 0, 1);
337 btrfs_set_stripe_offset_nr(buf, chunk, 0, 0);
340 write_extent_buffer(buf, super.dev_item.uuid,
341 (unsigned long)btrfs_stripe_dev_uuid(&chunk->stripe),
344 /* copy the key for the chunk to the system array */
345 ptr = super.sys_chunk_array;
346 array_size = sizeof(disk_key);
348 memcpy(ptr, &disk_key, sizeof(disk_key));
349 ptr += sizeof(disk_key);
351 /* copy the chunk to the system array */
352 read_extent_buffer(buf, ptr, (unsigned long)chunk, item_size);
353 array_size += item_size;
355 btrfs_set_super_sys_array_size(&super, array_size);
357 btrfs_set_header_bytenr(buf, cfg->blocks[3]);
358 btrfs_set_header_owner(buf, BTRFS_CHUNK_TREE_OBJECTID);
359 btrfs_set_header_nritems(buf, nritems);
360 csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
361 ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[3]);
362 if (ret != cfg->nodesize) {
363 ret = (ret < 0 ? -errno : -EIO);
367 /* create the device tree */
368 memset(buf->data + sizeof(struct btrfs_header), 0,
369 cfg->nodesize - sizeof(struct btrfs_header));
371 itemoff = __BTRFS_LEAF_DATA_SIZE(cfg->nodesize) -
372 sizeof(struct btrfs_dev_extent);
374 btrfs_set_disk_key_objectid(&disk_key, 1);
375 btrfs_set_disk_key_offset(&disk_key, 0);
376 btrfs_set_disk_key_type(&disk_key, BTRFS_DEV_EXTENT_KEY);
377 btrfs_set_item_key(buf, &disk_key, nritems);
378 btrfs_set_item_offset(buf, btrfs_item_nr(nritems), itemoff);
379 btrfs_set_item_size(buf, btrfs_item_nr(nritems),
380 sizeof(struct btrfs_dev_extent));
381 dev_extent = btrfs_item_ptr(buf, nritems, struct btrfs_dev_extent);
382 btrfs_set_dev_extent_chunk_tree(buf, dev_extent,
383 BTRFS_CHUNK_TREE_OBJECTID);
384 btrfs_set_dev_extent_chunk_objectid(buf, dev_extent,
385 BTRFS_FIRST_CHUNK_TREE_OBJECTID);
386 btrfs_set_dev_extent_chunk_offset(buf, dev_extent, 0);
388 write_extent_buffer(buf, chunk_tree_uuid,
389 (unsigned long)btrfs_dev_extent_chunk_tree_uuid(dev_extent),
392 btrfs_set_dev_extent_length(buf, dev_extent,
393 BTRFS_MKFS_SYSTEM_GROUP_SIZE);
396 btrfs_set_header_bytenr(buf, cfg->blocks[4]);
397 btrfs_set_header_owner(buf, BTRFS_DEV_TREE_OBJECTID);
398 btrfs_set_header_nritems(buf, nritems);
399 csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
400 ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[4]);
401 if (ret != cfg->nodesize) {
402 ret = (ret < 0 ? -errno : -EIO);
406 /* create the FS root */
407 memset(buf->data + sizeof(struct btrfs_header), 0,
408 cfg->nodesize - sizeof(struct btrfs_header));
409 btrfs_set_header_bytenr(buf, cfg->blocks[5]);
410 btrfs_set_header_owner(buf, BTRFS_FS_TREE_OBJECTID);
411 btrfs_set_header_nritems(buf, 0);
412 csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
413 ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[5]);
414 if (ret != cfg->nodesize) {
415 ret = (ret < 0 ? -errno : -EIO);
418 /* finally create the csum root */
419 memset(buf->data + sizeof(struct btrfs_header), 0,
420 cfg->nodesize - sizeof(struct btrfs_header));
421 btrfs_set_header_bytenr(buf, cfg->blocks[6]);
422 btrfs_set_header_owner(buf, BTRFS_CSUM_TREE_OBJECTID);
423 btrfs_set_header_nritems(buf, 0);
424 csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
425 ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[6]);
426 if (ret != cfg->nodesize) {
427 ret = (ret < 0 ? -errno : -EIO);
431 /* and write out the super block */
432 memset(buf->data, 0, BTRFS_SUPER_INFO_SIZE);
433 memcpy(buf->data, &super, sizeof(super));
434 buf->len = BTRFS_SUPER_INFO_SIZE;
435 csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
436 ret = pwrite(fd, buf->data, BTRFS_SUPER_INFO_SIZE, cfg->blocks[0]);
437 if (ret != BTRFS_SUPER_INFO_SIZE) {
438 ret = (ret < 0 ? -errno : -EIO);
449 u64 btrfs_min_dev_size(u32 nodesize)
451 return 2 * (BTRFS_MKFS_SYSTEM_GROUP_SIZE +
452 btrfs_min_global_blk_rsv_size(nodesize));
456 * Btrfs minimum size calculation is complicated, it should include at least:
457 * 1. system group size
458 * 2. minimum global block reserve
459 * 3. metadata used at mkfs
460 * 4. space reservation to create uuid for first mount.
461 * Also, raid factor should also be taken into consideration.
462 * To avoid the overkill calculation, (system group + global block rsv) * 2
463 * for *EACH* device should be good enough.
465 u64 btrfs_min_global_blk_rsv_size(u32 nodesize)
467 return (u64)nodesize << 10;
470 #define isoctal(c) (((c) & ~7) == '0')
472 static inline void translate(char *f, char *t)
476 isoctal(f[1]) && isoctal(f[2]) && isoctal(f[3])) {
477 *t++ = 64*(f[1] & 7) + 8*(f[2] & 7) + (f[3] & 7);
487 * Checks if the swap device.
488 * Returns 1 if swap device, < 0 on error or 0 if not swap device.
490 static int is_swap_device(const char *file)
501 if (stat(file, &st_buf) < 0)
503 if (S_ISBLK(st_buf.st_mode))
504 dev = st_buf.st_rdev;
505 else if (S_ISREG(st_buf.st_mode)) {
511 if ((f = fopen("/proc/swaps", "r")) == NULL)
514 /* skip the first line */
515 if (fgets(tmp, sizeof(tmp), f) == NULL)
518 while (fgets(tmp, sizeof(tmp), f) != NULL) {
519 if ((cp = strchr(tmp, ' ')) != NULL)
521 if ((cp = strchr(tmp, '\t')) != NULL)
524 if (stat(buf, &st_buf) != 0)
526 if (S_ISBLK(st_buf.st_mode)) {
527 if (dev == st_buf.st_rdev) {
531 } else if (S_ISREG(st_buf.st_mode)) {
532 if (dev == st_buf.st_dev && ino == st_buf.st_ino) {
546 * Check for existing filesystem or partition table on device.
548 * 1 for existing fs or partition
549 * 0 for nothing found
550 * -1 for internal error
552 static int check_overwrite(const char *device)
555 blkid_probe pr = NULL;
559 if (!device || !*device)
562 ret = -1; /* will reset on success of all setup calls */
564 pr = blkid_new_probe_from_filename(device);
568 size = blkid_probe_get_size(pr);
572 /* nothing to overwrite on a 0-length device */
578 ret = blkid_probe_enable_partitions(pr, 1);
582 ret = blkid_do_fullprobe(pr);
587 * Blkid returns 1 for nothing found and 0 when it finds a signature,
588 * but we want the exact opposite, so reverse the return value here.
590 * In addition print some useful diagnostics about what actually is
598 if (!blkid_probe_lookup_value(pr, "TYPE", &type, NULL)) {
600 "%s appears to contain an existing "
601 "filesystem (%s).\n", device, type);
602 } else if (!blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL)) {
604 "%s appears to contain a partition "
605 "table (%s).\n", device, type);
608 "%s appears to contain something weird "
609 "according to blkid\n", device);
615 blkid_free_probe(pr);
618 "probe of %s failed, cannot detect "
619 "existing filesystem.\n", device);
624 * Check if a device is suitable for btrfs
626 * 1: something is wrong, an error is printed
629 int test_dev_for_mkfs(const char *file, int force_overwrite)
634 ret = is_swap_device(file);
636 error("checking status of %s: %s", file, strerror(-ret));
640 error("%s is a swap device", file);
643 if (!force_overwrite) {
644 if (check_overwrite(file)) {
645 error("use the -f option to force overwrite of %s",
650 ret = check_mounted(file);
652 error("cannot check mount status of %s: %s", file,
657 error("%s is mounted", file);
660 /* check if the device is busy */
661 fd = open(file, O_RDWR|O_EXCL);
663 error("unable to open %s: %s", file, strerror(errno));
666 if (fstat(fd, &st)) {
667 error("unable to stat %s: %s", file, strerror(errno));
671 if (!S_ISBLK(st.st_mode)) {
672 error("%s is not a block device", file);
680 int is_vol_small(const char *file)
687 fd = open(file, O_RDONLY);
690 if (fstat(fd, &st) < 0) {
695 size = btrfs_device_size(fd, &st);
700 if (size < BTRFS_MKFS_SMALL_VOLUME_SIZE) {
709 int test_minimum_size(const char *file, u32 nodesize)
714 fd = open(file, O_RDONLY);
717 if (stat(file, &statbuf) < 0) {
721 if (btrfs_device_size(fd, &statbuf) < btrfs_min_dev_size(nodesize)) {