1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
6 #include "libfrog/util.h"
9 #include "xfs_multidisk.h"
11 #include "libfrog/fsgeom.h"
12 #include "libfrog/convert.h"
13 #include "libfrog/crc32cselftest.h"
14 #include "libfrog/dahashselftest.h"
18 #define TERABYTES(count, blog) ((uint64_t)(count) << (40 - (blog)))
19 #define GIGABYTES(count, blog) ((uint64_t)(count) << (30 - (blog)))
20 #define MEGABYTES(count, blog) ((uint64_t)(count) << (20 - (blog)))
23 * Realistically, the log should never be smaller than 64MB. Studies by the
24 * kernel maintainer in early 2022 have shown a dramatic reduction in long tail
25 * latency of the xlog grant head waitqueue when running a heavy metadata
26 * update workload when the log size is at least 64MB.
28 #define XFS_MIN_REALISTIC_LOG_BLOCKS(blog) (MEGABYTES(64, (blog)))
31 * Use this macro before we have superblock and mount structure to
32 * convert from basic blocks to filesystem blocks.
34 #define DTOBT(d, bl) ((xfs_rfsblock_t)((d) >> ((bl) - BBSHIFT)))
37 * amount (in bytes) we zero at the beginning and end of the device to
38 * remove traces of other filesystems, raid superblocks, etc.
40 #define WHACK_SIZE (128 * 1024)
43 * XXX: The configured block and sector sizes are defined as global variables so
44 * that they don't need to be passed to getnum/cvtnum().
46 static unsigned int blocksize
;
47 static unsigned int sectorsize
;
50 * Enums for each CLI parameter type are declared first so we can calculate the
51 * maximum array size needed to hold them automatically.
151 * Just define the max options array size manually to the largest
152 * enum right now, leaving room for a NULL terminator at the end
154 #define MAX_SUBOPTS (D_MAX_OPTS + 1)
156 #define SUBOPT_NEEDS_VAL (-1LL)
157 #define MAX_CONFLICTS 8
158 #define LAST_CONFLICT (-1)
161 * Table for parsing mkfs parameters.
163 * Description of the structure members follows:
166 * Name is a single char, e.g., for '-d file', name is 'd'.
168 * ini_section MANDATORY
169 * This field is required to connect each opt_params (that is to say, each
170 * option class) to a section in the config file. The only option class this
171 * is not required for is the config file specification class itself.
172 * The section name is a string, not longer than MAX_INI_NAME_LEN.
175 * Subopts is a list of strings naming suboptions. In the example above,
176 * it would contain "file". The last entry of this list has to be NULL.
178 * subopt_params MANDATORY
179 * This is a list of structs tied with subopts. For each entry in subopts,
180 * a corresponding entry has to be defined:
182 * subopt_params struct:
184 * This number, starting from zero, denotes which item in subopt_params
185 * it is. The index has to be the same as is the order in subopts list,
186 * so we can access the right item both in subopt_param and subopts.
189 * Do not set this flag when definning a subopt. It is used to remeber that
190 * this subopt was already seen, for example for conflicts detection.
193 * Do not set. It is used internally for respecification, when some options
194 * has to be parsed twice - at first as a string, then later as a number.
197 * A flag signalling whether the user-given value can use suffixes.
198 * If you want to allow the use of user-friendly values like 13k, 42G,
201 * is_power_2 OPTIONAL
202 * An optional flag for subopts where the given value has to be a power
205 * conflicts MANDATORY
206 * If your subopt is in a conflict with some other option, specify it.
207 * Accepts the .index values of the conflicting subopts and the last
208 * member of this list has to be LAST_CONFLICT.
210 * minval, maxval OPTIONAL
211 * These options are used for automatic range check and they have to be
212 * always used together in pair. If you don't want to limit the max value,
213 * use something like UINT_MAX. If no value is given, then you must either
214 * supply your own validation, or refuse any value in the 'case
215 * X_SOMETHING' block. If you forget to define the min and max value, but
216 * call a standard function for validating user's value, it will cause an
217 * error message notifying you about this issue.
219 * (Said in another way, you can't have minval and maxval both equal
220 * to zero. But if one value is different: minval=0 and maxval=1,
223 * defaultval MANDATORY
224 * The value used if user specifies the subopt, but no value.
225 * If the subopt accepts some values (-d file=[1|0]), then this
226 * sets what is used with simple specifying the subopt (-d file).
227 * A special SUBOPT_NEEDS_VAL can be used to require a user-given
232 #define MAX_INI_NAME_LEN 32
233 const char ini_section
[MAX_INI_NAME_LEN
];
234 const char *subopts
[MAX_SUBOPTS
];
236 struct subopt_param
{
243 struct opt_params
*opts
;
245 } conflicts
[MAX_CONFLICTS
];
248 long long defaultval
;
249 } subopt_params
[MAX_SUBOPTS
];
253 * The two dimensional conflict array requires some initialisations to know
254 * about tables that haven't yet been defined. Work around this ordering
255 * issue with extern definitions here.
257 static struct opt_params sopts
;
259 static struct opt_params bopts
= {
261 .ini_section
= "block",
270 .conflicts
= { { NULL
, LAST_CONFLICT
} },
271 .minval
= XFS_MIN_BLOCKSIZE
,
272 .maxval
= XFS_MAX_BLOCKSIZE
,
273 .defaultval
= SUBOPT_NEEDS_VAL
,
279 * Config file specification. Usage is:
281 * mkfs.xfs -c options=<name>
283 * A subopt is used for the filename so in future we can extend the behaviour
284 * of the config file (e.g. specified defaults rather than options) if we ever
285 * have a need to do that sort of thing.
287 static struct opt_params copts
= {
290 [C_OPTFILE
] = "options",
294 { .index
= C_OPTFILE
,
295 .conflicts
= { { NULL
, LAST_CONFLICT
} },
296 .defaultval
= SUBOPT_NEEDS_VAL
,
301 static struct opt_params dopts
= {
303 .ini_section
= "data",
305 [D_AGCOUNT
] = "agcount",
310 [D_SWIDTH
] = "swidth",
311 [D_AGSIZE
] = "agsize",
314 [D_SECTSIZE
] = "sectsize",
315 [D_NOALIGN
] = "noalign",
316 [D_RTINHERIT
] = "rtinherit",
317 [D_PROJINHERIT
] = "projinherit",
318 [D_EXTSZINHERIT
] = "extszinherit",
319 [D_COWEXTSIZE
] = "cowextsize",
320 [D_DAXINHERIT
] = "daxinherit",
324 { .index
= D_AGCOUNT
,
325 .conflicts
= { { &dopts
, D_AGSIZE
},
326 { NULL
, LAST_CONFLICT
} },
328 .maxval
= XFS_MAX_AGNUMBER
,
329 .defaultval
= SUBOPT_NEEDS_VAL
,
332 .conflicts
= { { NULL
, LAST_CONFLICT
} },
338 .conflicts
= { { NULL
, LAST_CONFLICT
} },
339 .defaultval
= SUBOPT_NEEDS_VAL
,
342 .conflicts
= { { NULL
, LAST_CONFLICT
} },
344 .minval
= XFS_AG_MIN_BYTES
,
346 .defaultval
= SUBOPT_NEEDS_VAL
,
349 .conflicts
= { { &dopts
, D_NOALIGN
},
352 { NULL
, LAST_CONFLICT
} },
355 .defaultval
= SUBOPT_NEEDS_VAL
,
358 .conflicts
= { { &dopts
, D_NOALIGN
},
361 { NULL
, LAST_CONFLICT
} },
364 .defaultval
= SUBOPT_NEEDS_VAL
,
367 .conflicts
= { { &dopts
, D_AGCOUNT
},
368 { NULL
, LAST_CONFLICT
} },
370 .minval
= XFS_AG_MIN_BYTES
,
371 .maxval
= XFS_AG_MAX_BYTES
,
372 .defaultval
= SUBOPT_NEEDS_VAL
,
375 .conflicts
= { { &dopts
, D_NOALIGN
},
377 { &dopts
, D_SWIDTH
},
378 { NULL
, LAST_CONFLICT
} },
382 .defaultval
= SUBOPT_NEEDS_VAL
,
385 .conflicts
= { { &dopts
, D_NOALIGN
},
387 { &dopts
, D_SWIDTH
},
388 { NULL
, LAST_CONFLICT
} },
391 .defaultval
= SUBOPT_NEEDS_VAL
,
393 { .index
= D_SECTSIZE
,
394 .conflicts
= { { &sopts
, S_SIZE
},
395 { &sopts
, S_SECTSIZE
},
396 { NULL
, LAST_CONFLICT
} },
399 .minval
= XFS_MIN_SECTORSIZE
,
400 .maxval
= XFS_MAX_SECTORSIZE
,
401 .defaultval
= SUBOPT_NEEDS_VAL
,
403 { .index
= D_NOALIGN
,
404 .conflicts
= { { &dopts
, D_SU
},
407 { &dopts
, D_SWIDTH
},
408 { NULL
, LAST_CONFLICT
} },
413 { .index
= D_RTINHERIT
,
414 .conflicts
= { { NULL
, LAST_CONFLICT
} },
419 { .index
= D_PROJINHERIT
,
420 .conflicts
= { { NULL
, LAST_CONFLICT
} },
423 .defaultval
= SUBOPT_NEEDS_VAL
,
425 { .index
= D_EXTSZINHERIT
,
426 .conflicts
= { { NULL
, LAST_CONFLICT
} },
429 .defaultval
= SUBOPT_NEEDS_VAL
,
431 { .index
= D_COWEXTSIZE
,
432 .conflicts
= { { NULL
, LAST_CONFLICT
} },
435 .defaultval
= SUBOPT_NEEDS_VAL
,
437 { .index
= D_DAXINHERIT
,
438 .conflicts
= { { NULL
, LAST_CONFLICT
} },
447 static struct opt_params iopts
= {
449 .ini_section
= "inode",
452 [I_MAXPCT
] = "maxpct",
453 [I_PERBLOCK
] = "perblock",
456 [I_PROJID32BIT
] = "projid32bit",
457 [I_SPINODES
] = "sparse",
458 [I_NREXT64
] = "nrext64",
463 .conflicts
= { { NULL
, LAST_CONFLICT
} },
469 .conflicts
= { { NULL
, LAST_CONFLICT
} },
472 .defaultval
= SUBOPT_NEEDS_VAL
,
474 { .index
= I_PERBLOCK
,
475 .conflicts
= { { &iopts
, I_SIZE
},
476 { NULL
, LAST_CONFLICT
} },
478 .minval
= XFS_MIN_INODE_PERBLOCK
,
479 .maxval
= XFS_MAX_BLOCKSIZE
/ XFS_DINODE_MIN_SIZE
,
480 .defaultval
= SUBOPT_NEEDS_VAL
,
483 .conflicts
= { { &iopts
, I_PERBLOCK
},
484 { NULL
, LAST_CONFLICT
} },
486 .minval
= XFS_DINODE_MIN_SIZE
,
487 .maxval
= XFS_DINODE_MAX_SIZE
,
488 .defaultval
= SUBOPT_NEEDS_VAL
,
491 .conflicts
= { { NULL
, LAST_CONFLICT
} },
494 .defaultval
= SUBOPT_NEEDS_VAL
,
496 { .index
= I_PROJID32BIT
,
497 .conflicts
= { { NULL
, LAST_CONFLICT
} },
502 { .index
= I_SPINODES
,
503 .conflicts
= { { NULL
, LAST_CONFLICT
} },
508 { .index
= I_NREXT64
,
509 .conflicts
= { { NULL
, LAST_CONFLICT
} },
517 static struct opt_params lopts
= {
519 .ini_section
= "log",
522 [L_INTERNAL
] = "internal",
524 [L_VERSION
] = "version",
528 [L_SECTSIZE
] = "sectsize",
531 [L_LAZYSBCNTR
] = "lazy-count",
536 .conflicts
= { { &lopts
, L_DEV
},
537 { NULL
, LAST_CONFLICT
} },
540 .defaultval
= SUBOPT_NEEDS_VAL
,
542 { .index
= L_INTERNAL
,
543 .conflicts
= { { &lopts
, L_FILE
},
545 { &lopts
, L_SECTSIZE
},
546 { NULL
, LAST_CONFLICT
} },
552 .conflicts
= { { NULL
, LAST_CONFLICT
} },
554 .minval
= 2 * 1024 * 1024LL, /* XXX: XFS_MIN_LOG_BYTES */
555 .maxval
= XFS_MAX_LOG_BYTES
,
556 .defaultval
= SUBOPT_NEEDS_VAL
,
558 { .index
= L_VERSION
,
559 .conflicts
= { { NULL
, LAST_CONFLICT
} },
562 .defaultval
= SUBOPT_NEEDS_VAL
,
565 .conflicts
= { { &lopts
, L_SU
},
566 { NULL
, LAST_CONFLICT
} },
568 .maxval
= BTOBB(XLOG_MAX_RECORD_BSIZE
),
569 .defaultval
= SUBOPT_NEEDS_VAL
,
572 .conflicts
= { { &lopts
, L_SUNIT
},
573 { NULL
, LAST_CONFLICT
} },
576 .maxval
= XLOG_MAX_RECORD_BSIZE
,
577 .defaultval
= SUBOPT_NEEDS_VAL
,
580 .conflicts
= { { &lopts
, L_AGNUM
},
582 { &lopts
, L_INTERNAL
},
583 { NULL
, LAST_CONFLICT
} },
584 .defaultval
= SUBOPT_NEEDS_VAL
,
586 { .index
= L_SECTSIZE
,
587 .conflicts
= { { &lopts
, L_INTERNAL
},
588 { NULL
, LAST_CONFLICT
} },
591 .minval
= XFS_MIN_SECTORSIZE
,
592 .maxval
= XFS_MAX_SECTORSIZE
,
593 .defaultval
= SUBOPT_NEEDS_VAL
,
596 .conflicts
= { { &lopts
, L_INTERNAL
},
597 { NULL
, LAST_CONFLICT
} },
603 .conflicts
= { { &lopts
, L_AGNUM
},
605 { &lopts
, L_INTERNAL
},
606 { NULL
, LAST_CONFLICT
} },
607 .defaultval
= SUBOPT_NEEDS_VAL
,
609 { .index
= L_LAZYSBCNTR
,
610 .conflicts
= { { NULL
, LAST_CONFLICT
} },
618 static struct opt_params nopts
= {
620 .ini_section
= "naming",
623 [N_VERSION
] = "version",
629 .conflicts
= { { NULL
, LAST_CONFLICT
} },
632 .minval
= 1 << XFS_MIN_REC_DIRSIZE
,
633 .maxval
= XFS_MAX_BLOCKSIZE
,
634 .defaultval
= SUBOPT_NEEDS_VAL
,
636 { .index
= N_VERSION
,
637 .conflicts
= { { NULL
, LAST_CONFLICT
} },
640 .defaultval
= SUBOPT_NEEDS_VAL
,
643 .conflicts
= { { NULL
, LAST_CONFLICT
} },
651 static struct opt_params popts
= {
653 .ini_section
= "proto",
656 [P_SLASHES
] = "slashes_are_spaces",
661 .conflicts
= { { NULL
, LAST_CONFLICT
} },
662 .defaultval
= SUBOPT_NEEDS_VAL
,
664 { .index
= P_SLASHES
,
665 .conflicts
= { { NULL
, LAST_CONFLICT
} },
673 static struct opt_params ropts
= {
675 .ini_section
= "realtime",
677 [R_EXTSIZE
] = "extsize",
682 [R_NOALIGN
] = "noalign",
686 { .index
= R_EXTSIZE
,
687 .conflicts
= { { NULL
, LAST_CONFLICT
} },
689 .minval
= XFS_MIN_RTEXTSIZE
,
690 .maxval
= XFS_MAX_RTEXTSIZE
,
691 .defaultval
= SUBOPT_NEEDS_VAL
,
694 .conflicts
= { { NULL
, LAST_CONFLICT
} },
698 .defaultval
= SUBOPT_NEEDS_VAL
,
701 .conflicts
= { { &ropts
, R_NAME
},
702 { NULL
, LAST_CONFLICT
} },
703 .defaultval
= SUBOPT_NEEDS_VAL
,
709 .conflicts
= { { NULL
, LAST_CONFLICT
} },
712 .conflicts
= { { &ropts
, R_DEV
},
713 { NULL
, LAST_CONFLICT
} },
714 .defaultval
= SUBOPT_NEEDS_VAL
,
716 { .index
= R_NOALIGN
,
720 .conflicts
= { { NULL
, LAST_CONFLICT
} },
725 static struct opt_params sopts
= {
727 .ini_section
= "sector",
730 [S_SECTSIZE
] = "sectsize",
735 .conflicts
= { { &sopts
, S_SECTSIZE
},
736 { &dopts
, D_SECTSIZE
},
737 { NULL
, LAST_CONFLICT
} },
740 .minval
= XFS_MIN_SECTORSIZE
,
741 .maxval
= XFS_MAX_SECTORSIZE
,
742 .defaultval
= SUBOPT_NEEDS_VAL
,
744 { .index
= S_SECTSIZE
,
745 .conflicts
= { { &sopts
, S_SIZE
},
746 { &dopts
, D_SECTSIZE
},
747 { NULL
, LAST_CONFLICT
} },
750 .minval
= XFS_MIN_SECTORSIZE
,
751 .maxval
= XFS_MAX_SECTORSIZE
,
752 .defaultval
= SUBOPT_NEEDS_VAL
,
757 static struct opt_params mopts
= {
759 .ini_section
= "metadata",
762 [M_FINOBT
] = "finobt",
764 [M_RMAPBT
] = "rmapbt",
765 [M_REFLINK
] = "reflink",
766 [M_INOBTCNT
] = "inobtcount",
767 [M_BIGTIME
] = "bigtime",
772 .conflicts
= { { NULL
, LAST_CONFLICT
} },
778 .conflicts
= { { NULL
, LAST_CONFLICT
} },
784 .conflicts
= { { NULL
, LAST_CONFLICT
} },
785 .defaultval
= SUBOPT_NEEDS_VAL
,
788 .conflicts
= { { NULL
, LAST_CONFLICT
} },
793 { .index
= M_REFLINK
,
794 .conflicts
= { { NULL
, LAST_CONFLICT
} },
799 { .index
= M_INOBTCNT
,
800 .conflicts
= { { NULL
, LAST_CONFLICT
} },
805 { .index
= M_BIGTIME
,
806 .conflicts
= { { NULL
, LAST_CONFLICT
} },
814 /* quick way of checking if a parameter was set on the CLI */
817 struct opt_params
*opts
,
820 return opts
->subopt_params
[subopt
].seen
||
821 opts
->subopt_params
[subopt
].str_seen
;
825 * Options configured on the command line.
827 * This stores all the specific config parameters the user sets on the command
828 * line. We do not use these values directly - they are inputs to the mkfs
829 * geometry validation and override any default configuration value we have.
831 * We don't keep flags to indicate what parameters are set - if we need to check
832 * if an option was set on the command line, we check the relevant entry in the
833 * option table which records whether it was specified in the .seen and
834 * .str_seen variables in the table.
836 * Some parameters are stored as strings for post-parsing after their dependent
837 * options have been resolved (e.g. block size and sector size have been parsed
840 * This allows us to check that values have been set without needing separate
841 * flags for each value, and hence avoids needing to record and check for each
842 * specific option that can set the value later on in the code. In the cases
843 * where we don't have a cli_params structure around, the above cli_opt_set()
844 * function can be used.
846 struct sb_feat_args
{
850 bool inode_align
; /* XFS_SB_VERSION_ALIGNBIT */
851 bool nci
; /* XFS_SB_VERSION_BORGBIT */
852 bool lazy_sb_counters
; /* XFS_SB_VERSION2_LAZYSBCOUNTBIT */
853 bool parent_pointers
; /* XFS_SB_VERSION2_PARENTBIT */
854 bool projid32bit
; /* XFS_SB_VERSION2_PROJID32BIT */
855 bool crcs_enabled
; /* XFS_SB_VERSION2_CRCBIT */
856 bool dirftype
; /* XFS_SB_VERSION2_FTYPE */
857 bool finobt
; /* XFS_SB_FEAT_RO_COMPAT_FINOBT */
858 bool spinodes
; /* XFS_SB_FEAT_INCOMPAT_SPINODES */
859 bool rmapbt
; /* XFS_SB_FEAT_RO_COMPAT_RMAPBT */
860 bool reflink
; /* XFS_SB_FEAT_RO_COMPAT_REFLINK */
861 bool inobtcnt
; /* XFS_SB_FEAT_RO_COMPAT_INOBTCNT */
862 bool bigtime
; /* XFS_SB_FEAT_INCOMPAT_BIGTIME */
875 /* parameters that depend on sector/block size being validated. */
885 /* parameters where 0 is a valid CLI value */
893 int proto_slashes_are_spaces
;
895 /* parameters where 0 is not a valid value */
903 /* feature flags that are set */
904 struct sb_feat_args sb_feat
;
906 /* root inode characteristics */
909 /* libxfs device setup */
910 struct libxfs_init
*xi
;
914 * Calculated filesystem feature and geometry information.
916 * This structure contains the information we will use to create the on-disk
917 * filesystem from. The validation and calculation code uses it to store all the
918 * temporary and final config state for the filesystem.
920 * The information in this structure will contain a mix of validated CLI input
921 * variables, default feature state and calculated values that are needed to
922 * construct the superblock and other on disk features. These are all in one
923 * place so that we don't have to pass handfuls of seemingly arbitrary variables
924 * around to different functions to do the work we need to do.
942 uint64_t rtextblocks
;
944 uint64_t rtbmblocks
; /* rt bitmap blocks */
946 int dsunit
; /* in FSBs */
947 int dswidth
; /* in FSBs */
948 int lsunit
; /* in FSBs */
962 struct sb_feat_args sb_feat
;
966 * Default filesystem features and configuration values
968 * This structure contains the default mkfs values that are to be used when
969 * a user does not specify the option on the command line. We do not use these
970 * values directly - they are inputs to the mkfs geometry validation and
973 struct mkfs_default_params
{
974 char *source
; /* where the defaults came from */
979 /* feature flags that are set */
980 struct sb_feat_args sb_feat
;
982 /* root inode characteristics */
986 static void __attribute__((noreturn
))
989 fprintf(stderr
, _("Usage: %s\n\
990 /* blocksize */ [-b size=num]\n\
991 /* config file */ [-c options=xxx]\n\
992 /* metadata */ [-m crc=0|1,finobt=0|1,uuid=xxx,rmapbt=0|1,reflink=0|1,\n\
993 inobtcount=0|1,bigtime=0|1]\n\
994 /* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num,\n\
995 (sunit=value,swidth=value|su=num,sw=num|noalign),\n\
997 /* force overwrite */ [-f]\n\
998 /* inode size */ [-i perblock=n|size=num,maxpct=n,attr=0|1|2,\n\
999 projid32bit=0|1,sparse=0|1,nrext64=0|1]\n\
1000 /* no discard */ [-K]\n\
1001 /* log subvol */ [-l agnum=n,internal,size=num,logdev=xxx,version=n\n\
1002 sunit=value|su=num,sectsize=num,lazy-count=0|1]\n\
1003 /* label */ [-L label (maximum 12 characters)]\n\
1004 /* naming */ [-n size=num,version=2|ci,ftype=0|1]\n\
1005 /* no-op info only */ [-N]\n\
1006 /* prototype file */ [-p fname]\n\
1008 /* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx]\n\
1009 /* sectorsize */ [-s size=num]\n\
1010 /* version */ [-V]\n\
1012 <devicename> is required unless -d name=xxx is given.\n\
1013 <num> is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxx KiB),\n\
1014 xxxm (xxx MiB), xxxg (xxx GiB), xxxt (xxx TiB) or xxxp (xxx PiB).\n\
1015 <value> is xxx (512 byte blocks).\n"),
1022 struct opt_params
*opts
,
1024 struct opt_params
*con_opts
,
1027 fprintf(stderr
, _("Cannot specify both -%c %s and -%c %s\n"),
1028 con_opts
->name
, con_opts
->subopts
[conflict
],
1029 opts
->name
, opts
->subopts
[option
]);
1039 fprintf(stderr
, _("Invalid value %s for -%s option\n"), value
, opt
);
1047 return (i
& (i
- 1)) == 0;
1050 static void __attribute__((noreturn
))
1056 fprintf(stderr
, _("-%c %s option requires a value\n"), opt
, tab
[idx
]);
1066 fprintf(stderr
, "-%c ", opt
);
1068 fprintf(stderr
, "%s ", tab
[idx
]);
1069 fprintf(stderr
, _("option respecified\n"));
1078 fprintf(stderr
, _("unknown option -%c %s\n"), opt
, s
);
1083 invalid_cfgfile_opt(
1084 const char *filename
,
1085 const char *section
,
1089 fprintf(stderr
, _("%s: invalid config file option: [%s]: %s=%s\n"),
1090 filename
, section
, name
, value
);
1100 const char *optname
)
1102 struct stat statbuf
;
1104 if (*isfile
&& (no_size
|| no_name
)) {
1106 _("if -%s file then -%s name and -%s size are required\n"),
1107 optname
, optname
, optname
);
1112 fprintf(stderr
, _("No device name specified\n"));
1116 if (stat(name
, &statbuf
)) {
1117 if (errno
== ENOENT
&& *isfile
) {
1124 _("Error accessing specified device %s: %s\n"),
1125 name
, strerror(errno
));
1131 * We only want to completely truncate and recreate an existing file if
1132 * we were specifically told it was a file. Set the create flag only in
1133 * this case to trigger that behaviour.
1135 if (S_ISREG(statbuf
.st_mode
)) {
1143 if (S_ISBLK(statbuf
.st_mode
)) {
1146 _("specified \"-%s file\" on a block device %s\n"),
1154 _("specified device %s not a file or block device\n"),
1162 bool force_overwrite
)
1164 if (!force_overwrite
&& check_overwrite(name
)) {
1166 _("%s: Use the -f option to force overwrite.\n"),
1174 validate_ag_geometry(
1180 if (agsize
< XFS_AG_MIN_BLOCKS(blocklog
)) {
1182 _("agsize (%lld blocks) too small, need at least %lld blocks\n"),
1184 (long long)XFS_AG_MIN_BLOCKS(blocklog
));
1188 if (agsize
> XFS_AG_MAX_BLOCKS(blocklog
)) {
1190 _("agsize (%lld blocks) too big, maximum is %lld blocks\n"),
1192 (long long)XFS_AG_MAX_BLOCKS(blocklog
));
1196 if (agsize
> dblocks
) {
1198 _("agsize (%lld blocks) too big, data area is %lld blocks\n"),
1199 (long long)agsize
, (long long)dblocks
);
1203 if (agsize
< XFS_AG_MIN_BLOCKS(blocklog
)) {
1205 _("too many allocation groups for size = %lld\n"),
1207 fprintf(stderr
, _("need at most %lld allocation groups\n"),
1208 (long long)(dblocks
/ XFS_AG_MIN_BLOCKS(blocklog
) +
1209 (dblocks
% XFS_AG_MIN_BLOCKS(blocklog
) != 0)));
1213 if (agsize
> XFS_AG_MAX_BLOCKS(blocklog
)) {
1215 _("too few allocation groups for size = %lld\n"), (long long)agsize
);
1217 _("need at least %lld allocation groups\n"),
1218 (long long)(dblocks
/ XFS_AG_MAX_BLOCKS(blocklog
) +
1219 (dblocks
% XFS_AG_MAX_BLOCKS(blocklog
) != 0)));
1224 * If the last AG is too small, reduce the filesystem size
1225 * and drop the blocks.
1227 if ( dblocks
% agsize
!= 0 &&
1228 (dblocks
% agsize
< XFS_AG_MIN_BLOCKS(blocklog
))) {
1230 _("last AG size %lld blocks too small, minimum size is %lld blocks\n"),
1231 (long long)(dblocks
% agsize
),
1232 (long long)XFS_AG_MIN_BLOCKS(blocklog
));
1237 * If agcount is too large, make it smaller.
1239 if (agcount
> XFS_MAX_AGNUMBER
+ 1) {
1241 _("%lld allocation groups is too many, maximum is %lld\n"),
1242 (long long)agcount
, (long long)XFS_MAX_AGNUMBER
+ 1);
1248 zero_old_xfs_structures(
1249 struct libxfs_init
*xi
,
1259 * We open regular files with O_TRUNC|O_CREAT. Nothing to do here...
1261 if (xi
->disfile
&& xi
->dcreat
)
1265 * read in existing filesystem superblock, use its geometry
1266 * settings and zero the existing secondary superblocks.
1268 buf
= memalign(libxfs_device_alignment(), new_sb
->sb_sectsize
);
1271 _("error reading existing superblock -- failed to memalign buffer\n"));
1274 memset(buf
, 0, new_sb
->sb_sectsize
);
1277 * If we are creating an image file, it might be of zero length at this
1278 * point in time. Hence reading the existing superblock is going to
1279 * return zero bytes. It's not a failure we need to warn about in this
1282 off
= pread(xi
->dfd
, buf
, new_sb
->sb_sectsize
, 0);
1283 if (off
!= new_sb
->sb_sectsize
) {
1286 _("error reading existing superblock: %s\n"),
1290 libxfs_sb_from_disk(&sb
, buf
);
1293 * perform same basic superblock validation to make sure we
1294 * actually zero secondary blocks
1296 if (sb
.sb_magicnum
!= XFS_SB_MAGIC
|| sb
.sb_blocksize
== 0)
1299 for (bsize
= 1, i
= 0; bsize
< sb
.sb_blocksize
&&
1300 i
< sizeof(sb
.sb_blocksize
) * NBBY
; i
++)
1303 if (i
< XFS_MIN_BLOCKSIZE_LOG
|| i
> XFS_MAX_BLOCKSIZE_LOG
||
1304 i
!= sb
.sb_blocklog
)
1307 if (sb
.sb_dblocks
> ((uint64_t)sb
.sb_agcount
* sb
.sb_agblocks
) ||
1308 sb
.sb_dblocks
< ((uint64_t)(sb
.sb_agcount
- 1) *
1309 sb
.sb_agblocks
+ XFS_MIN_AG_BLOCKS
))
1313 * block size and basic geometry seems alright, zero the secondaries.
1315 memset(buf
, 0, new_sb
->sb_sectsize
);
1317 for (i
= 1; i
< sb
.sb_agcount
; i
++) {
1318 off
+= sb
.sb_agblocks
;
1319 if (pwrite(xi
->dfd
, buf
, new_sb
->sb_sectsize
,
1320 off
<< sb
.sb_blocklog
) == -1)
1328 discard_blocks(dev_t dev
, uint64_t nsectors
, int quiet
)
1331 uint64_t offset
= 0;
1332 /* Discard the device 2G at a time */
1333 const uint64_t step
= 2ULL << 30;
1334 const uint64_t count
= BBTOB(nsectors
);
1336 fd
= libxfs_device_to_fd(dev
);
1340 /* The block discarding happens in smaller batches so it can be
1341 * interrupted prematurely
1343 while (offset
< count
) {
1344 uint64_t tmp_step
= min(step
, count
- offset
);
1347 * We intentionally ignore errors from the discard ioctl. It is
1348 * not necessary for the mkfs functionality but just an
1349 * optimization. However we should stop on error.
1351 if (platform_discard_blocks(fd
, offset
, tmp_step
) == 0) {
1352 if (offset
== 0 && !quiet
) {
1353 printf("Discarding blocks...");
1357 if (offset
> 0 && !quiet
)
1364 if (offset
> 0 && !quiet
)
1368 static __attribute__((noreturn
)) void
1371 struct opt_params
*opts
,
1376 _("Invalid value %s for -%c %s option. %s\n"),
1377 value
, opts
->name
, opts
->subopts
[index
],
1383 * Check for conflicts and option respecification.
1387 struct opt_params
*opts
,
1391 struct subopt_param
*sp
= &opts
->subopt_params
[index
];
1394 if (sp
->index
!= index
) {
1396 _("Developer screwed up option parsing (%d/%d)! Please report!\n"),
1398 reqval(opts
->name
, opts
->subopts
, index
);
1402 * Check for respecification of the option. This is more complex than it
1403 * seems because some options are parsed twice - once as a string during
1404 * input parsing, then later the string is passed to getnum for
1405 * conversion into a number and bounds checking. Hence the two variables
1406 * used to track the different uses based on the @str parameter passed
1411 respec(opts
->name
, opts
->subopts
, index
);
1415 respec(opts
->name
, opts
->subopts
, index
);
1416 sp
->str_seen
= true;
1419 /* check for conflicts with the option */
1420 for (i
= 0; i
< MAX_CONFLICTS
; i
++) {
1421 struct _conflict
*con
= &sp
->conflicts
[i
];
1423 if (con
->subopt
== LAST_CONFLICT
)
1425 if (con
->opts
->subopt_params
[con
->subopt
].seen
||
1426 con
->opts
->subopt_params
[con
->subopt
].str_seen
)
1427 conflict(opts
, index
, con
->opts
, con
->subopt
);
1434 struct opt_params
*opts
,
1437 struct subopt_param
*sp
= &opts
->subopt_params
[index
];
1440 check_opt(opts
, index
, false);
1441 /* empty strings might just return a default value */
1442 if (!str
|| *str
== '\0') {
1443 if (sp
->defaultval
== SUBOPT_NEEDS_VAL
)
1444 reqval(opts
->name
, opts
->subopts
, index
);
1445 return sp
->defaultval
;
1448 if (sp
->minval
== 0 && sp
->maxval
== 0) {
1450 _("Option -%c %s has undefined minval/maxval."
1451 "Can't verify value range. This is a bug.\n"),
1452 opts
->name
, opts
->subopts
[index
]);
1457 * Some values are pure numbers, others can have suffixes that define
1458 * the units of the number. Those get passed to cvtnum(), otherwise we
1459 * convert it ourselves to guarantee there is no trailing garbage in the
1463 c
= cvtnum(blocksize
, sectorsize
, str
);
1465 illegal_option(str
, opts
, index
,
1466 _("Not a valid value or illegal suffix"));
1471 c
= strtoll(str
, &str_end
, 0);
1472 if (c
== 0 && str_end
== str
)
1473 illegal_option(str
, opts
, index
,
1474 _("Value not recognized as number."));
1475 if (*str_end
!= '\0')
1476 illegal_option(str
, opts
, index
,
1477 _("Unit suffixes are not allowed."));
1480 /* Validity check the result. */
1482 illegal_option(str
, opts
, index
, _("Value is too small."));
1483 else if (c
> sp
->maxval
)
1484 illegal_option(str
, opts
, index
, _("Value is too large."));
1485 if (sp
->is_power_2
&& !ispow2(c
))
1486 illegal_option(str
, opts
, index
, _("Value must be a power of 2."));
1491 * Option is a string - do all the option table work, and check there
1492 * is actually an option string. Otherwise we don't do anything with the string
1493 * here - validation will be done later when the string is converted to a value
1494 * or used as a file/device path.
1499 struct opt_params
*opts
,
1504 check_opt(opts
, index
, true);
1506 /* empty strings for string options are not valid */
1507 if (!str
|| *str
== '\0')
1508 reqval(opts
->name
, opts
->subopts
, index
);
1512 fprintf(stderr
, _("Out of memory while saving suboptions.\n"));
1521 struct opt_params
*opts
,
1524 struct cli_params
*cli
)
1528 cli
->blocksize
= getnum(value
, opts
, subopt
);
1537 cfgfile_opts_parser(
1538 struct opt_params
*opts
,
1541 struct cli_params
*cli
)
1545 cli
->cfgfile
= getstr(value
, opts
, subopt
);
1555 struct opt_params
*opts
,
1558 struct cli_params
*cli
)
1562 cli
->agcount
= getnum(value
, opts
, subopt
);
1565 cli
->agsize
= getstr(value
, opts
, subopt
);
1568 cli
->xi
->disfile
= getnum(value
, opts
, subopt
);
1571 cli
->xi
->dname
= getstr(value
, opts
, subopt
);
1574 cli
->dsize
= getstr(value
, opts
, subopt
);
1577 cli
->dsunit
= getnum(value
, opts
, subopt
);
1580 cli
->dswidth
= getnum(value
, opts
, subopt
);
1583 cli
->dsu
= getstr(value
, opts
, subopt
);
1586 cli
->dsw
= getnum(value
, opts
, subopt
);
1589 cli
->sb_feat
.nodalign
= getnum(value
, opts
, subopt
);
1592 cli
->sectorsize
= getnum(value
, opts
, subopt
);
1595 if (getnum(value
, opts
, subopt
))
1596 cli
->fsx
.fsx_xflags
|= FS_XFLAG_RTINHERIT
;
1598 cli
->fsx
.fsx_xflags
&= ~FS_XFLAG_RTINHERIT
;
1601 cli
->fsx
.fsx_projid
= getnum(value
, opts
, subopt
);
1602 cli
->fsx
.fsx_xflags
|= FS_XFLAG_PROJINHERIT
;
1604 case D_EXTSZINHERIT
:
1605 cli
->fsx
.fsx_extsize
= getnum(value
, opts
, subopt
);
1606 if (cli
->fsx
.fsx_extsize
)
1607 cli
->fsx
.fsx_xflags
|= FS_XFLAG_EXTSZINHERIT
;
1609 cli
->fsx
.fsx_xflags
&= ~FS_XFLAG_EXTSZINHERIT
;
1612 cli
->fsx
.fsx_cowextsize
= getnum(value
, opts
, subopt
);
1613 if (cli
->fsx
.fsx_cowextsize
)
1614 cli
->fsx
.fsx_xflags
|= FS_XFLAG_COWEXTSIZE
;
1616 cli
->fsx
.fsx_xflags
&= ~FS_XFLAG_COWEXTSIZE
;
1619 if (getnum(value
, opts
, subopt
))
1620 cli
->fsx
.fsx_xflags
|= FS_XFLAG_DAX
;
1622 cli
->fsx
.fsx_xflags
&= ~FS_XFLAG_DAX
;
1632 struct opt_params
*opts
,
1635 struct cli_params
*cli
)
1639 cli
->sb_feat
.inode_align
= getnum(value
, opts
, subopt
);
1642 cli
->imaxpct
= getnum(value
, opts
, subopt
);
1645 cli
->inopblock
= getnum(value
, opts
, subopt
);
1648 cli
->inodesize
= getnum(value
, opts
, subopt
);
1651 cli
->sb_feat
.attr_version
= getnum(value
, opts
, subopt
);
1654 cli
->sb_feat
.projid32bit
= getnum(value
, opts
, subopt
);
1657 cli
->sb_feat
.spinodes
= getnum(value
, opts
, subopt
);
1660 cli
->sb_feat
.nrext64
= getnum(value
, opts
, subopt
);
1670 struct opt_params
*opts
,
1673 struct cli_params
*cli
)
1677 cli
->logagno
= getnum(value
, opts
, subopt
);
1680 cli
->xi
->lisfile
= getnum(value
, opts
, subopt
);
1683 cli
->loginternal
= getnum(value
, opts
, subopt
);
1686 cli
->lsu
= getstr(value
, opts
, subopt
);
1689 cli
->lsunit
= getnum(value
, opts
, subopt
);
1693 cli
->xi
->logname
= getstr(value
, opts
, subopt
);
1694 cli
->loginternal
= 0;
1697 cli
->sb_feat
.log_version
= getnum(value
, opts
, subopt
);
1700 cli
->logsize
= getstr(value
, opts
, subopt
);
1703 cli
->lsectorsize
= getnum(value
, opts
, subopt
);
1706 cli
->sb_feat
.lazy_sb_counters
= getnum(value
, opts
, subopt
);
1716 struct opt_params
*opts
,
1719 struct cli_params
*cli
)
1723 cli
->sb_feat
.crcs_enabled
= getnum(value
, opts
, subopt
);
1724 if (cli
->sb_feat
.crcs_enabled
)
1725 cli
->sb_feat
.dirftype
= true;
1728 cli
->sb_feat
.finobt
= getnum(value
, opts
, subopt
);
1731 if (!value
|| *value
== '\0')
1732 reqval('m', opts
->subopts
, subopt
);
1733 if (platform_uuid_parse(value
, &cli
->uuid
))
1734 illegal(value
, "m uuid");
1737 cli
->sb_feat
.rmapbt
= getnum(value
, opts
, subopt
);
1740 cli
->sb_feat
.reflink
= getnum(value
, opts
, subopt
);
1743 cli
->sb_feat
.inobtcnt
= getnum(value
, opts
, subopt
);
1746 cli
->sb_feat
.bigtime
= getnum(value
, opts
, subopt
);
1756 struct opt_params
*opts
,
1759 struct cli_params
*cli
)
1763 cli
->dirblocksize
= getstr(value
, opts
, subopt
);
1766 value
= getstr(value
, &nopts
, subopt
);
1767 if (!strcasecmp(value
, "ci")) {
1769 cli
->sb_feat
.nci
= true;
1771 cli
->sb_feat
.dir_version
= getnum(value
, opts
, subopt
);
1773 free((char *)value
);
1776 cli
->sb_feat
.dirftype
= getnum(value
, opts
, subopt
);
1786 struct opt_params
*opts
,
1789 struct cli_params
*cli
)
1793 cli
->proto_slashes_are_spaces
= getnum(value
, opts
, subopt
);
1798 if (cli
->protofile
) {
1801 respec(opts
->name
, opts
->subopts
, subopt
);
1803 cli
->protofile
= strdup(value
);
1804 if (!cli
->protofile
) {
1806 _("Out of memory while saving protofile option.\n"));
1816 struct opt_params
*opts
,
1819 struct cli_params
*cli
)
1823 cli
->rtextsize
= getstr(value
, opts
, subopt
);
1826 cli
->xi
->risfile
= getnum(value
, opts
, subopt
);
1830 cli
->xi
->rtname
= getstr(value
, opts
, subopt
);
1833 cli
->rtsize
= getstr(value
, opts
, subopt
);
1836 cli
->sb_feat
.nortalign
= getnum(value
, opts
, subopt
);
1846 struct opt_params
*opts
,
1849 struct cli_params
*cli
)
1854 cli
->sectorsize
= getnum(value
, opts
, subopt
);
1855 cli
->lsectorsize
= cli
->sectorsize
;
1863 static struct subopts
{
1864 struct opt_params
*opts
;
1865 int (*parser
)(struct opt_params
*opts
,
1868 struct cli_params
*cli
);
1870 { &bopts
, block_opts_parser
},
1871 { &copts
, cfgfile_opts_parser
},
1872 { &dopts
, data_opts_parser
},
1873 { &iopts
, inode_opts_parser
},
1874 { &lopts
, log_opts_parser
},
1875 { &mopts
, meta_opts_parser
},
1876 { &nopts
, naming_opts_parser
},
1877 { &popts
, proto_opts_parser
},
1878 { &ropts
, rtdev_opts_parser
},
1879 { &sopts
, sector_opts_parser
},
1887 struct cli_params
*cli
)
1889 struct subopts
*sop
= &subopt_tab
[0];
1894 if (sop
->opts
->name
== opt
)
1899 /* should never happen */
1904 while (*p
!= '\0') {
1905 char **subopts
= (char **)sop
->opts
->subopts
;
1909 subopt
= getsubopt(&p
, subopts
, &value
);
1911 ret
= (sop
->parser
)(sop
->opts
, subopt
, value
, cli
);
1913 unknown(opt
, value
);
1919 const char *section
,
1922 struct cli_params
*cli
)
1924 struct subopts
*sop
= &subopt_tab
[0];
1930 if (sop
->opts
->ini_section
[0] != '\0' &&
1931 strcasecmp(section
, sop
->opts
->ini_section
) == 0)
1936 /* Config files with unknown sections get caught here. */
1940 subopts
= (char **)sop
->opts
->subopts
;
1941 for (i
= 0; i
< MAX_SUBOPTS
; i
++) {
1944 if (strcasecmp(name
, subopts
[i
]) == 0) {
1945 ret
= (sop
->parser
)(sop
->opts
, i
, value
, cli
);
1952 invalid_cfgfile_opt(cli
->cfgfile
, section
, name
, value
);
1957 validate_sectorsize(
1958 struct mkfs_params
*cfg
,
1959 struct cli_params
*cli
,
1960 struct mkfs_default_params
*dft
,
1961 struct fs_topology
*ft
,
1963 int force_overwrite
)
1966 * Before anything else, verify that we are correctly operating on
1967 * files or block devices and set the control parameters correctly.
1969 check_device_type(cli
->xi
->dname
, &cli
->xi
->disfile
,
1970 !cli
->dsize
, !cli
->xi
->dname
,
1971 dry_run
? NULL
: &cli
->xi
->dcreat
, "d");
1972 if (!cli
->loginternal
)
1973 check_device_type(cli
->xi
->logname
, &cli
->xi
->lisfile
,
1974 !cli
->logsize
, !cli
->xi
->logname
,
1975 dry_run
? NULL
: &cli
->xi
->lcreat
, "l");
1976 if (cli
->xi
->rtname
)
1977 check_device_type(cli
->xi
->rtname
, &cli
->xi
->risfile
,
1978 !cli
->rtsize
, !cli
->xi
->rtname
,
1979 dry_run
? NULL
: &cli
->xi
->rcreat
, "r");
1982 * Explicitly disable direct IO for image files so we don't error out on
1983 * sector size mismatches between the new filesystem and the underlying
1986 if (cli
->xi
->disfile
|| cli
->xi
->lisfile
|| cli
->xi
->risfile
)
1987 cli
->xi
->isdirect
= 0;
1989 memset(ft
, 0, sizeof(*ft
));
1990 get_topology(cli
->xi
, ft
, force_overwrite
);
1992 /* set configured sector sizes in preparation for checks */
1993 if (!cli
->sectorsize
) {
1995 * Unless specified manually on the command line use the
1996 * advertised sector size of the device. We use the physical
1997 * sector size unless the requested block size is smaller
1998 * than that, then we can use logical, but warn about the
2001 * Set the topology sectors if they were not probed to the
2002 * minimum supported sector size.
2004 if (!ft
->lsectorsize
)
2005 ft
->lsectorsize
= dft
->sectorsize
;
2008 * Older kernels may not have physical/logical distinction.
2010 * Some architectures have a page size > XFS_MAX_SECTORSIZE.
2011 * In that case, a ramdisk or persistent memory device may
2012 * advertise a physical sector size that is too big to use.
2014 if (!ft
->psectorsize
|| ft
->psectorsize
> XFS_MAX_SECTORSIZE
)
2015 ft
->psectorsize
= ft
->lsectorsize
;
2017 cfg
->sectorsize
= ft
->psectorsize
;
2018 if (cfg
->blocksize
< cfg
->sectorsize
&&
2019 cfg
->blocksize
>= ft
->lsectorsize
) {
2021 _("specified blocksize %d is less than device physical sector size %d\n"
2022 "switching to logical sector size %d\n"),
2023 cfg
->blocksize
, ft
->psectorsize
,
2025 cfg
->sectorsize
= ft
->lsectorsize
;
2028 cfg
->sectorsize
= cli
->sectorsize
;
2030 cfg
->sectorlog
= libxfs_highbit32(cfg
->sectorsize
);
2032 /* validate specified/probed sector size */
2033 if (cfg
->sectorsize
< XFS_MIN_SECTORSIZE
||
2034 cfg
->sectorsize
> XFS_MAX_SECTORSIZE
) {
2035 fprintf(stderr
, _("illegal sector size %d\n"), cfg
->sectorsize
);
2039 if (cfg
->blocksize
< cfg
->sectorsize
) {
2041 _("block size %d cannot be smaller than sector size %d\n"),
2042 cfg
->blocksize
, cfg
->sectorsize
);
2046 if (cfg
->sectorsize
< ft
->lsectorsize
) {
2047 fprintf(stderr
, _("illegal sector size %d; hw sector is %d\n"),
2048 cfg
->sectorsize
, ft
->lsectorsize
);
2055 struct mkfs_params
*cfg
,
2056 struct cli_params
*cli
,
2057 struct mkfs_default_params
*dft
)
2060 * Blocksize and sectorsize first, other things depend on them
2061 * For RAID4/5/6 we want to align sector size and block size,
2062 * so we need to start with the device geometry extraction too.
2064 if (!cli
->blocksize
)
2065 cfg
->blocksize
= dft
->blocksize
;
2067 cfg
->blocksize
= cli
->blocksize
;
2068 cfg
->blocklog
= libxfs_highbit32(cfg
->blocksize
);
2070 /* validate block sizes are in range */
2071 if (cfg
->blocksize
< XFS_MIN_BLOCKSIZE
||
2072 cfg
->blocksize
> XFS_MAX_BLOCKSIZE
) {
2073 fprintf(stderr
, _("illegal block size %d\n"), cfg
->blocksize
);
2077 if (cli
->sb_feat
.crcs_enabled
&&
2078 cfg
->blocksize
< XFS_MIN_CRC_BLOCKSIZE
) {
2080 _("Minimum block size for CRC enabled filesystems is %d bytes.\n"),
2081 XFS_MIN_CRC_BLOCKSIZE
);
2088 * Grab log sector size and validate.
2090 * XXX: should we probe sector size on external log device rather than using
2091 * the data device sector size?
2094 validate_log_sectorsize(
2095 struct mkfs_params
*cfg
,
2096 struct cli_params
*cli
,
2097 struct mkfs_default_params
*dft
)
2100 if (cli
->loginternal
&& cli
->lsectorsize
&&
2101 cli
->lsectorsize
!= cfg
->sectorsize
) {
2103 _("Can't change sector size on internal log!\n"));
2107 if (cli
->lsectorsize
)
2108 cfg
->lsectorsize
= cli
->lsectorsize
;
2109 else if (cli
->loginternal
)
2110 cfg
->lsectorsize
= cfg
->sectorsize
;
2112 cfg
->lsectorsize
= dft
->sectorsize
;
2113 cfg
->lsectorlog
= libxfs_highbit32(cfg
->lsectorsize
);
2115 if (cfg
->lsectorsize
< XFS_MIN_SECTORSIZE
||
2116 cfg
->lsectorsize
> XFS_MAX_SECTORSIZE
||
2117 cfg
->lsectorsize
> cfg
->blocksize
) {
2118 fprintf(stderr
, _("illegal log sector size %d\n"),
2122 if (cfg
->lsectorsize
> XFS_MIN_SECTORSIZE
) {
2123 if (cli
->sb_feat
.log_version
< 2) {
2124 /* user specified non-default log version */
2126 _("Version 1 logs do not support sector size %d\n"),
2132 /* if lsu or lsunit was specified, automatically use v2 logs */
2133 if ((cli_opt_set(&lopts
, L_SU
) || cli_opt_set(&lopts
, L_SUNIT
)) &&
2134 cli
->sb_feat
.log_version
== 1) {
2136 _("log stripe unit specified, using v2 logs\n"));
2137 cli
->sb_feat
.log_version
= 2;
2143 * Check that the incoming features make sense. The CLI structure was
2144 * initialised with the default values before parsing, so we can just
2145 * check it and copy it straight across to the cfg structure if it
2149 validate_sb_features(
2150 struct mkfs_params
*cfg
,
2151 struct cli_params
*cli
)
2153 if (cli
->sb_feat
.nci
) {
2155 * The ascii-ci feature is deprecated in the upstream Linux
2156 * kernel. In September 2025 it will be turned off by default
2157 * in the kernel and in September 2030 support will be removed
2161 _("ascii-ci filesystems are deprecated and will not be supported by future versions.\n"));
2165 * Now we have blocks and sector sizes set up, check parameters that are
2166 * no longer optional for CRC enabled filesystems. Catch them up front
2167 * here before doing anything else.
2169 if (cli
->sb_feat
.crcs_enabled
) {
2170 /* minimum inode size is 512 bytes, rest checked later */
2171 if (cli
->inodesize
&&
2172 cli
->inodesize
< (1 << XFS_DINODE_DFL_CRC_LOG
)) {
2174 _("Minimum inode size for CRCs is %d bytes\n"),
2175 1 << XFS_DINODE_DFL_CRC_LOG
);
2179 /* inodes always aligned */
2180 if (!cli
->sb_feat
.inode_align
) {
2182 _("Inodes always aligned for CRC enabled filesystems\n"));
2186 /* lazy sb counters always on */
2187 if (!cli
->sb_feat
.lazy_sb_counters
) {
2189 _("Lazy superblock counters always enabled for CRC enabled filesystems\n"));
2193 /* version 2 logs always on */
2194 if (cli
->sb_feat
.log_version
!= 2) {
2196 _("V2 logs always enabled for CRC enabled filesystems\n"));
2200 /* attr2 always on */
2201 if (cli
->sb_feat
.attr_version
!= 2) {
2203 _("V2 attribute format always enabled on CRC enabled filesystems\n"));
2207 /* 32 bit project quota always on */
2208 /* attr2 always on */
2209 if (!cli
->sb_feat
.projid32bit
) {
2211 _("32 bit Project IDs always enabled on CRC enabled filesystems\n"));
2215 /* ftype always on */
2216 if (!cli
->sb_feat
.dirftype
) {
2218 _("Directory ftype field always enabled on CRC enabled filesystems\n"));
2222 } else { /* !crcs_enabled */
2224 * The V4 filesystem format is deprecated in the upstream Linux
2225 * kernel. In September 2025 it will be turned off by default
2226 * in the kernel and in September 2030 support will be removed
2230 _("V4 filesystems are deprecated and will not be supported by future versions.\n"));
2233 * The kernel doesn't support crc=0,finobt=1 filesystems.
2234 * If crcs are not enabled and the user has not explicitly
2235 * turned finobt on, then silently turn it off to avoid an
2236 * unnecessary warning.
2237 * If the user explicitly tried to use crc=0,finobt=1,
2238 * then issue an error.
2239 * The same is also true for sparse inodes and reflink.
2241 if (cli
->sb_feat
.finobt
&& cli_opt_set(&mopts
, M_FINOBT
)) {
2243 _("finobt not supported without CRC support\n"));
2246 cli
->sb_feat
.finobt
= false;
2248 if (cli
->sb_feat
.spinodes
&& cli_opt_set(&iopts
, I_SPINODES
)) {
2250 _("sparse inodes not supported without CRC support\n"));
2253 cli
->sb_feat
.spinodes
= false;
2255 if (cli
->sb_feat
.rmapbt
&& cli_opt_set(&mopts
, M_RMAPBT
)) {
2257 _("rmapbt not supported without CRC support\n"));
2260 cli
->sb_feat
.rmapbt
= false;
2262 if (cli
->sb_feat
.reflink
&& cli_opt_set(&mopts
, M_REFLINK
)) {
2264 _("reflink not supported without CRC support\n"));
2267 cli
->sb_feat
.reflink
= false;
2269 if (cli
->sb_feat
.inobtcnt
&& cli_opt_set(&mopts
, M_INOBTCNT
)) {
2271 _("inode btree counters not supported without CRC support\n"));
2274 cli
->sb_feat
.inobtcnt
= false;
2276 if (cli
->sb_feat
.bigtime
&& cli_opt_set(&mopts
, M_BIGTIME
)) {
2278 _("timestamps later than 2038 not supported without CRC support\n"));
2281 cli
->sb_feat
.bigtime
= false;
2283 if (cli
->sb_feat
.nrext64
&&
2284 cli_opt_set(&iopts
, I_NREXT64
)) {
2286 _("64 bit extent count not supported without CRC support\n"));
2289 cli
->sb_feat
.nrext64
= false;
2292 if (!cli
->sb_feat
.finobt
) {
2293 if (cli
->sb_feat
.inobtcnt
&& cli_opt_set(&mopts
, M_INOBTCNT
)) {
2295 _("inode btree counters not supported without finobt support\n"));
2298 cli
->sb_feat
.inobtcnt
= false;
2301 if (cli
->xi
->rtname
) {
2302 if (cli
->sb_feat
.reflink
&& cli_opt_set(&mopts
, M_REFLINK
)) {
2304 _("reflink not supported with realtime devices\n"));
2307 cli
->sb_feat
.reflink
= false;
2309 if (cli
->sb_feat
.rmapbt
&& cli_opt_set(&mopts
, M_RMAPBT
)) {
2311 _("rmapbt not supported with realtime devices\n"));
2314 cli
->sb_feat
.rmapbt
= false;
2317 if ((cli
->fsx
.fsx_xflags
& FS_XFLAG_COWEXTSIZE
) &&
2318 !cli
->sb_feat
.reflink
) {
2320 _("cowextsize not supported without reflink support\n"));
2325 * Copy features across to config structure now.
2327 cfg
->sb_feat
= cli
->sb_feat
;
2328 if (!platform_uuid_is_null(&cli
->uuid
))
2329 platform_uuid_copy(&cfg
->uuid
, &cli
->uuid
);
2333 validate_dirblocksize(
2334 struct mkfs_params
*cfg
,
2335 struct cli_params
*cli
)
2338 if (cli
->dirblocksize
)
2339 cfg
->dirblocksize
= getnum(cli
->dirblocksize
, &nopts
, N_SIZE
);
2341 if (cfg
->dirblocksize
) {
2342 if (cfg
->dirblocksize
< cfg
->blocksize
||
2343 cfg
->dirblocksize
> XFS_MAX_BLOCKSIZE
) {
2344 fprintf(stderr
, _("illegal directory block size %d\n"),
2348 cfg
->dirblocklog
= libxfs_highbit32(cfg
->dirblocksize
);
2352 /* use default size based on current block size */
2353 if (cfg
->blocksize
< (1 << XFS_MIN_REC_DIRSIZE
))
2354 cfg
->dirblocklog
= XFS_MIN_REC_DIRSIZE
;
2356 cfg
->dirblocklog
= cfg
->blocklog
;
2357 cfg
->dirblocksize
= 1 << cfg
->dirblocklog
;
2362 struct mkfs_params
*cfg
,
2363 struct cli_params
*cli
)
2367 cfg
->inodelog
= cfg
->blocklog
- libxfs_highbit32(cli
->inopblock
);
2368 else if (cli
->inodesize
)
2369 cfg
->inodelog
= libxfs_highbit32(cli
->inodesize
);
2370 else if (cfg
->sb_feat
.crcs_enabled
)
2371 cfg
->inodelog
= XFS_DINODE_DFL_CRC_LOG
;
2373 cfg
->inodelog
= XFS_DINODE_DFL_LOG
;
2375 cfg
->inodesize
= 1 << cfg
->inodelog
;
2376 cfg
->inopblock
= cfg
->blocksize
/ cfg
->inodesize
;
2378 /* input parsing has already validated non-crc inode size range */
2379 if (cfg
->sb_feat
.crcs_enabled
&&
2380 cfg
->inodelog
< XFS_DINODE_DFL_CRC_LOG
) {
2382 _("Minimum inode size for CRCs is %d bytes\n"),
2383 1 << XFS_DINODE_DFL_CRC_LOG
);
2387 if (cfg
->inodesize
> cfg
->blocksize
/ XFS_MIN_INODE_PERBLOCK
||
2388 cfg
->inopblock
< XFS_MIN_INODE_PERBLOCK
||
2389 cfg
->inodesize
< XFS_DINODE_MIN_SIZE
||
2390 cfg
->inodesize
> XFS_DINODE_MAX_SIZE
) {
2393 fprintf(stderr
, _("illegal inode size %d\n"), cfg
->inodesize
);
2394 maxsz
= min(cfg
->blocksize
/ XFS_MIN_INODE_PERBLOCK
,
2395 XFS_DINODE_MAX_SIZE
);
2396 if (XFS_DINODE_MIN_SIZE
== maxsz
)
2398 _("allowable inode size with %d byte blocks is %d\n"),
2399 cfg
->blocksize
, XFS_DINODE_MIN_SIZE
);
2402 _("allowable inode size with %d byte blocks is between %d and %d\n"),
2403 cfg
->blocksize
, XFS_DINODE_MIN_SIZE
, maxsz
);
2408 static xfs_rfsblock_t
2411 struct mkfs_params
*cfg
,
2412 struct opt_params
*opts
,
2417 xfs_rfsblock_t dblocks
;
2422 dbytes
= getnum(size
, opts
, sizeopt
);
2423 if (dbytes
% XFS_MIN_BLOCKSIZE
) {
2425 _("illegal %s length %lld, not a multiple of %d\n"),
2426 type
, (long long)dbytes
, XFS_MIN_BLOCKSIZE
);
2429 dblocks
= (xfs_rfsblock_t
)(dbytes
>> cfg
->blocklog
);
2430 if (dbytes
% cfg
->blocksize
) {
2432 _("warning: %s length %lld not a multiple of %d, truncated to %lld\n"),
2433 type
, (long long)dbytes
, cfg
->blocksize
,
2434 (long long)(dblocks
<< cfg
->blocklog
));
2441 struct mkfs_params
*cfg
,
2442 struct cli_params
*cli
,
2443 struct fs_topology
*ft
)
2445 uint64_t rtextbytes
;
2448 * If specified, check rt extent size against its constraints.
2450 if (cli
->rtextsize
) {
2452 rtextbytes
= getnum(cli
->rtextsize
, &ropts
, R_EXTSIZE
);
2453 if (rtextbytes
% cfg
->blocksize
) {
2455 _("illegal rt extent size %lld, not a multiple of %d\n"),
2456 (long long)rtextbytes
, cfg
->blocksize
);
2459 cfg
->rtextblocks
= (xfs_extlen_t
)(rtextbytes
>> cfg
->blocklog
);
2462 * If realtime extsize has not been specified by the user,
2463 * and the underlying volume is striped, then set rtextblocks
2464 * to the stripe width.
2468 if (!cfg
->sb_feat
.nortalign
&& !cli
->xi
->risfile
&&
2469 !(!cli
->rtsize
&& cli
->xi
->disfile
))
2470 rswidth
= ft
->rtswidth
;
2474 /* check that rswidth is a multiple of fs blocksize */
2475 if (!cfg
->sb_feat
.nortalign
&& rswidth
&&
2476 !(BBTOB(rswidth
) % cfg
->blocksize
)) {
2477 rswidth
= DTOBT(rswidth
, cfg
->blocklog
);
2478 rtextbytes
= rswidth
<< cfg
->blocklog
;
2479 if (rtextbytes
> XFS_MIN_RTEXTSIZE
&&
2480 rtextbytes
<= XFS_MAX_RTEXTSIZE
) {
2481 cfg
->rtextblocks
= rswidth
;
2484 if (!cfg
->rtextblocks
) {
2485 cfg
->rtextblocks
= (cfg
->blocksize
< XFS_MIN_RTEXTSIZE
)
2486 ? XFS_MIN_RTEXTSIZE
>> cfg
->blocklog
2490 ASSERT(cfg
->rtextblocks
);
2493 /* Validate the incoming extsize hint. */
2495 validate_extsize_hint(
2496 struct xfs_mount
*mp
,
2497 struct cli_params
*cli
)
2503 * First we validate the extent size inherit hint on a directory so
2504 * that we know that we'll be propagating a correct hint and flag to
2505 * new files on the data device.
2507 if (cli
->fsx
.fsx_xflags
& FS_XFLAG_EXTSZINHERIT
)
2508 flags
|= XFS_DIFLAG_EXTSZINHERIT
;
2510 fa
= libxfs_inode_validate_extsize(mp
, cli
->fsx
.fsx_extsize
, S_IFDIR
,
2514 _("illegal extent size hint %lld, must be less than %u.\n"),
2515 (long long)cli
->fsx
.fsx_extsize
,
2516 min(XFS_MAX_BMBT_EXTLEN
, mp
->m_sb
.sb_agblocks
/ 2));
2521 * If the value is to be passed on to realtime files, revalidate with
2522 * a realtime file so that we know the hint and flag that get passed on
2523 * to realtime files will be correct.
2525 if (!(cli
->fsx
.fsx_xflags
& FS_XFLAG_RTINHERIT
))
2528 flags
= XFS_DIFLAG_REALTIME
;
2529 if (cli
->fsx
.fsx_xflags
& FS_XFLAG_EXTSZINHERIT
)
2530 flags
|= XFS_DIFLAG_EXTSIZE
;
2532 fa
= libxfs_inode_validate_extsize(mp
, cli
->fsx
.fsx_extsize
, S_IFREG
,
2537 _("illegal extent size hint %lld, must be less than %u and a multiple of %u.\n"),
2538 (long long)cli
->fsx
.fsx_extsize
,
2539 min(XFS_MAX_BMBT_EXTLEN
, mp
->m_sb
.sb_agblocks
/ 2),
2540 mp
->m_sb
.sb_rextsize
);
2545 /* Validate the incoming CoW extsize hint. */
2547 validate_cowextsize_hint(
2548 struct xfs_mount
*mp
,
2549 struct cli_params
*cli
)
2552 uint64_t flags2
= 0;
2555 * Validate the copy on write extent size inherit hint on a directory
2556 * so that we know that we'll be propagating a correct hint and flag to
2557 * new files on the data device.
2559 if (cli
->fsx
.fsx_xflags
& FS_XFLAG_COWEXTSIZE
)
2560 flags2
|= XFS_DIFLAG2_COWEXTSIZE
;
2562 fa
= libxfs_inode_validate_cowextsize(mp
, cli
->fsx
.fsx_cowextsize
,
2563 S_IFDIR
, 0, flags2
);
2566 _("illegal CoW extent size hint %lld, must be less than %u.\n"),
2567 (long long)cli
->fsx
.fsx_cowextsize
,
2568 min(XFS_MAX_BMBT_EXTLEN
, mp
->m_sb
.sb_agblocks
/ 2));
2573 /* Complain if this filesystem is not a supported configuration. */
2576 struct xfs_mount
*mp
,
2577 struct cli_params
*cli
)
2579 /* Undocumented option to enable unsupported tiny filesystems. */
2580 if (!cli
->is_supported
) {
2582 _("Filesystems formatted with --unsupported are not supported!!\n"));
2587 * fstests has a large number of tests that create tiny filesystems to
2588 * perform specific regression and resource depletion tests in a
2589 * controlled environment. Avoid breaking fstests by allowing
2590 * unsupported configurations if TEST_DIR, TEST_DEV, and QA_CHECK_FS
2593 if (getenv("TEST_DIR") && getenv("TEST_DEV") && getenv("QA_CHECK_FS"))
2597 * We don't support filesystems smaller than 300MB anymore. Tiny
2598 * filesystems have never been XFS' design target. This limit has been
2599 * carefully calculated to prevent formatting with a log smaller than
2600 * the "realistic" size.
2602 * If the realistic log size is 64MB, there are four AGs, and the log
2603 * AG should be at least 1/8 free after formatting, this gives us:
2605 * 64MB * (8 / 7) * 4 = 293MB
2607 if (mp
->m_sb
.sb_dblocks
< MEGABYTES(300, mp
->m_sb
.sb_blocklog
)) {
2609 _("Filesystem must be larger than 300MB.\n"));
2614 * For best performance, we don't allow unrealistically small logs.
2615 * See the comment for XFS_MIN_REALISTIC_LOG_BLOCKS.
2617 if (mp
->m_sb
.sb_logblocks
<
2618 XFS_MIN_REALISTIC_LOG_BLOCKS(mp
->m_sb
.sb_blocklog
)) {
2620 _("Log size must be at least 64MB.\n"));
2625 * Filesystems should not have fewer than two AGs, because we need to
2626 * have redundant superblocks.
2628 if (mp
->m_sb
.sb_agcount
< 2) {
2630 _("Filesystem must have at least 2 superblocks for redundancy!\n"));
2636 * Validate the configured stripe geometry, or is none is specified, pull
2637 * the configuration from the underlying device.
2639 * CLI parameters come in as different units, go out as filesystem blocks.
2642 calc_stripe_factors(
2643 struct mkfs_params
*cfg
,
2644 struct cli_params
*cli
,
2645 struct fs_topology
*ft
)
2647 long long int big_dswidth
;
2654 bool use_dev
= false;
2656 if (cli_opt_set(&dopts
, D_SUNIT
))
2657 dsunit
= cli
->dsunit
;
2658 if (cli_opt_set(&dopts
, D_SWIDTH
))
2659 dswidth
= cli
->dswidth
;
2661 if (cli_opt_set(&dopts
, D_SU
))
2662 dsu
= getnum(cli
->dsu
, &dopts
, D_SU
);
2663 if (cli_opt_set(&dopts
, D_SW
))
2666 /* data sunit/swidth options */
2667 if (cli_opt_set(&dopts
, D_SUNIT
) != cli_opt_set(&dopts
, D_SWIDTH
)) {
2669 _("both data sunit and data swidth options must be specified\n"));
2673 /* convert dsu/dsw to dsunit/dswidth and use them from now on */
2675 if (cli_opt_set(&dopts
, D_SU
) != cli_opt_set(&dopts
, D_SW
)) {
2677 _("both data su and data sw options must be specified\n"));
2681 big_dswidth
= (long long int)dsu
* dsw
;
2682 if (BTOBBT(big_dswidth
) > INT_MAX
) {
2684 _("data stripe width (%lld) is too large of a multiple of the data stripe unit (%d)\n"),
2689 if (!libxfs_validate_stripe_geometry(NULL
, dsu
, big_dswidth
,
2690 cfg
->sectorsize
, false))
2693 dsunit
= BTOBBT(dsu
);
2694 dswidth
= BTOBBT(big_dswidth
);
2695 } else if (!libxfs_validate_stripe_geometry(NULL
, BBTOB(dsunit
),
2696 BBTOB(dswidth
), cfg
->sectorsize
, false)) {
2700 /* If sunit & swidth were manually specified as 0, same as noalign */
2701 if ((cli_opt_set(&dopts
, D_SUNIT
) || cli_opt_set(&dopts
, D_SU
)) &&
2702 !dsunit
&& !dswidth
)
2703 cfg
->sb_feat
.nodalign
= true;
2705 /* if we are not using alignment, don't apply device defaults */
2706 if (cfg
->sb_feat
.nodalign
) {
2712 /* if no stripe config set, use the device default */
2714 /* Ignore nonsense from device report. */
2715 if (!libxfs_validate_stripe_geometry(NULL
, BBTOB(ft
->dsunit
),
2716 BBTOB(ft
->dswidth
), 0, true)) {
2718 _("%s: Volume reports invalid stripe unit (%d) and stripe width (%d), ignoring.\n"),
2719 progname
, BBTOB(ft
->dsunit
), BBTOB(ft
->dswidth
));
2722 } else if (cfg
->dblocks
< GIGABYTES(1, cfg
->blocklog
)) {
2724 * Don't use automatic stripe detection if the device
2725 * size is less than 1GB because the performance gains
2726 * on such a small system are not worth the risk that
2727 * we'll end up with an undersized log.
2729 if (ft
->dsunit
|| ft
->dswidth
)
2731 _("%s: small data volume, ignoring data volume stripe unit %d and stripe width %d\n"),
2732 progname
, ft
->dsunit
,
2737 dsunit
= ft
->dsunit
;
2738 dswidth
= ft
->dswidth
;
2742 /* check and warn if user-specified alignment is sub-optimal */
2743 if (ft
->dsunit
&& ft
->dsunit
!= dsunit
) {
2745 _("%s: Specified data stripe unit %d is not the same as the volume stripe unit %d\n"),
2746 progname
, dsunit
, ft
->dsunit
);
2748 if (ft
->dswidth
&& ft
->dswidth
!= dswidth
) {
2750 _("%s: Specified data stripe width %d is not the same as the volume stripe width %d\n"),
2751 progname
, dswidth
, ft
->dswidth
);
2756 * now we have our stripe config, check it's a multiple of block
2759 if ((BBTOB(dsunit
) % cfg
->blocksize
) ||
2760 (BBTOB(dswidth
) % cfg
->blocksize
)) {
2762 * If we are using device defaults, just clear them and we're
2763 * good to go. Otherwise bail out with an error.
2767 _("%s: Stripe unit(%d) or stripe width(%d) is not a multiple of the block size(%d)\n"),
2768 progname
, BBTOB(dsunit
), BBTOB(dswidth
),
2774 cfg
->sb_feat
.nodalign
= true;
2777 /* convert from 512 byte blocks to fs blocksize */
2778 cfg
->dsunit
= DTOBT(dsunit
, cfg
->blocklog
);
2779 cfg
->dswidth
= DTOBT(dswidth
, cfg
->blocklog
);
2782 /* log sunit options */
2783 if (cli_opt_set(&lopts
, L_SUNIT
))
2784 lsunit
= cli
->lsunit
;
2785 else if (cli_opt_set(&lopts
, L_SU
))
2786 lsu
= getnum(cli
->lsu
, &lopts
, L_SU
);
2787 else if (cfg
->lsectorsize
> XLOG_HEADER_SIZE
)
2788 lsu
= cfg
->blocksize
; /* lsunit matches filesystem block size */
2791 /* verify if lsu is a multiple block size */
2792 if (lsu
% cfg
->blocksize
!= 0) {
2794 _("log stripe unit (%d) must be a multiple of the block size (%d)\n"),
2795 lsu
, cfg
->blocksize
);
2798 lsunit
= (int)BTOBBT(lsu
);
2800 if (BBTOB(lsunit
) % cfg
->blocksize
!= 0) {
2802 _("log stripe unit (%d) must be a multiple of the block size (%d)\n"),
2803 BBTOB(lsunit
), cfg
->blocksize
);
2808 * check that log sunit is modulo fsblksize or default it to dsunit.
2811 /* convert from 512 byte blocks to fs blocks */
2812 cfg
->lsunit
= DTOBT(lsunit
, cfg
->blocklog
);
2813 } else if (cfg
->sb_feat
.log_version
== 2 &&
2814 cfg
->loginternal
&& cfg
->dsunit
) {
2815 /* lsunit and dsunit now in fs blocks */
2816 cfg
->lsunit
= cfg
->dsunit
;
2819 if (cfg
->sb_feat
.log_version
== 2 &&
2820 cfg
->lsunit
* cfg
->blocksize
> 256 * 1024) {
2821 /* Warn only if specified on commandline */
2822 if (cli
->lsu
|| cli
->lsunit
!= -1) {
2824 _("log stripe unit (%d bytes) is too large (maximum is 256KiB)\n"
2825 "log stripe unit adjusted to 32KiB\n"),
2826 (cfg
->lsunit
* cfg
->blocksize
));
2828 /* XXX: 64k block size? */
2829 cfg
->lsunit
= (32 * 1024) / cfg
->blocksize
;
2836 struct mkfs_params
*cfg
,
2837 struct libxfs_init
*xi
)
2839 uint64_t sector_mask
;
2842 * Initialize. This will open the log and rt devices as well.
2844 xi
->setblksize
= cfg
->sectorsize
;
2845 if (!libxfs_init(xi
))
2848 fprintf(stderr
, _("no device name given in argument list\n"));
2853 * Ok, Linux only has a 1024-byte resolution on device _size_,
2854 * and the sizes below are in basic 512-byte blocks,
2855 * so if we have (size % 2), on any partition, we can't get
2856 * to the last 512 bytes. The same issue exists for larger
2857 * sector sizes - we cannot write past the last sector.
2859 * So, we reduce the size (in basic blocks) to a perfect
2860 * multiple of the sector size, or 1024, whichever is larger.
2862 sector_mask
= (uint64_t)-1 << (max(cfg
->sectorlog
, 10) - BBSHIFT
);
2863 xi
->dsize
&= sector_mask
;
2864 xi
->rtsize
&= sector_mask
;
2865 xi
->logBBsize
&= (uint64_t)-1 << (max(cfg
->lsectorlog
, 10) - BBSHIFT
);
2870 struct libxfs_init
*xi
,
2874 *Â This function has to be called after libxfs has been initialized.
2878 discard_blocks(xi
->ddev
, xi
->dsize
, quiet
);
2879 if (xi
->rtdev
&& !xi
->risfile
)
2880 discard_blocks(xi
->rtdev
, xi
->rtsize
, quiet
);
2881 if (xi
->logdev
&& xi
->logdev
!= xi
->ddev
&& !xi
->lisfile
)
2882 discard_blocks(xi
->logdev
, xi
->logBBsize
, quiet
);
2887 struct mkfs_params
*cfg
,
2888 struct cli_params
*cli
)
2890 struct libxfs_init
*xi
= cli
->xi
;
2894 * if the device is a file, we can't validate the size here.
2895 * Instead, the file will be truncated to the correct length
2896 * later on. if it's not a file, we've got a dud device.
2899 fprintf(stderr
, _("can't get size of data subvolume\n"));
2902 ASSERT(cfg
->dblocks
);
2903 } else if (cfg
->dblocks
) {
2904 /* check the size fits into the underlying device */
2905 if (cfg
->dblocks
> DTOBT(xi
->dsize
, cfg
->blocklog
)) {
2907 _("size %s specified for data subvolume is too large, maximum is %lld blocks\n"),
2909 (long long)DTOBT(xi
->dsize
, cfg
->blocklog
));
2913 /* no user size, so use the full block device */
2914 cfg
->dblocks
= DTOBT(xi
->dsize
, cfg
->blocklog
);
2917 if (cfg
->dblocks
< XFS_MIN_DATA_BLOCKS(cfg
)) {
2919 _("size %lld of data subvolume is too small, minimum %lld blocks\n"),
2920 (long long)cfg
->dblocks
, XFS_MIN_DATA_BLOCKS(cfg
));
2924 if (xi
->dbsize
> cfg
->sectorsize
) {
2926 "Warning: the data subvolume sector size %u is less than the sector size \n\
2927 reported by the device (%u).\n"),
2928 cfg
->sectorsize
, xi
->dbsize
);
2934 struct mkfs_params
*cfg
,
2935 struct cli_params
*cli
)
2937 struct libxfs_init
*xi
= cli
->xi
;
2939 cfg
->loginternal
= cli
->loginternal
;
2941 /* now run device checks */
2942 if (cfg
->loginternal
) {
2944 * if no sector size has been specified on the command line,
2945 * use what has been configured and validated for the data
2948 if (!cli
->lsectorsize
) {
2949 cfg
->lsectorsize
= cfg
->sectorsize
;
2950 cfg
->lsectorlog
= cfg
->sectorlog
;
2953 if (cfg
->sectorsize
!= cfg
->lsectorsize
) {
2955 _("data and log sector sizes must be equal for internal logs\n"));
2958 if (cli
->logsize
&& cfg
->logblocks
>= cfg
->dblocks
) {
2960 _("log size %lld too large for internal log\n"),
2961 (long long)cfg
->logblocks
);
2967 /* External/log subvolume checks */
2968 if (!*xi
->logname
|| !xi
->logdev
) {
2969 fprintf(stderr
, _("no log subvolume or external log.\n"));
2973 if (!cfg
->logblocks
) {
2974 if (xi
->logBBsize
== 0) {
2976 _("unable to get size of the log subvolume.\n"));
2979 cfg
->logblocks
= DTOBT(xi
->logBBsize
, cfg
->blocklog
);
2980 } else if (cfg
->logblocks
> DTOBT(xi
->logBBsize
, cfg
->blocklog
)) {
2982 _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
2984 (long long)DTOBT(xi
->logBBsize
, cfg
->blocklog
));
2988 if (xi
->lbsize
> cfg
->lsectorsize
) {
2990 "Warning: the log subvolume sector size %u is less than the sector size\n\
2991 reported by the device (%u).\n"),
2992 cfg
->lsectorsize
, xi
->lbsize
);
2998 struct mkfs_params
*cfg
,
2999 struct cli_params
*cli
)
3001 struct libxfs_init
*xi
= cli
->xi
;
3006 _("size specified for non-existent rt subvolume\n"));
3012 cfg
->rtbmblocks
= 0;
3016 fprintf(stderr
, _("Invalid zero length rt subvolume found\n"));
3021 if (cfg
->rtblocks
> DTOBT(xi
->rtsize
, cfg
->blocklog
)) {
3023 _("size %s specified for rt subvolume is too large, maxi->um is %lld blocks\n"),
3025 (long long)DTOBT(xi
->rtsize
, cfg
->blocklog
));
3028 if (xi
->rtbsize
> cfg
->sectorsize
) {
3030 "Warning: the realtime subvolume sector size %u is less than the sector size\n\
3031 reported by the device (%u).\n"),
3032 cfg
->sectorsize
, xi
->rtbsize
);
3035 /* grab volume size */
3036 cfg
->rtblocks
= DTOBT(xi
->rtsize
, cfg
->blocklog
);
3039 cfg
->rtextents
= cfg
->rtblocks
/ cfg
->rtextblocks
;
3040 cfg
->rtbmblocks
= (xfs_extlen_t
)howmany(cfg
->rtextents
,
3041 NBBY
* cfg
->blocksize
);
3045 calculate_initial_ag_geometry(
3046 struct mkfs_params
*cfg
,
3047 struct cli_params
*cli
)
3049 if (cli
->agsize
) { /* User-specified AG size */
3050 cfg
->agsize
= getnum(cli
->agsize
, &dopts
, D_AGSIZE
);
3053 * Check specified agsize is a multiple of blocksize.
3055 if (cfg
->agsize
% cfg
->blocksize
) {
3057 _("agsize (%s) not a multiple of fs blk size (%d)\n"),
3058 cli
->agsize
, cfg
->blocksize
);
3061 cfg
->agsize
/= cfg
->blocksize
;
3062 cfg
->agcount
= cfg
->dblocks
/ cfg
->agsize
+
3063 (cfg
->dblocks
% cfg
->agsize
!= 0);
3065 } else if (cli
->agcount
) { /* User-specified AG count */
3066 cfg
->agcount
= cli
->agcount
;
3067 cfg
->agsize
= cfg
->dblocks
/ cfg
->agcount
+
3068 (cfg
->dblocks
% cfg
->agcount
!= 0);
3070 calc_default_ag_geometry(cfg
->blocklog
, cfg
->dblocks
,
3071 cfg
->dsunit
, &cfg
->agsize
,
3077 * Align the AG size to stripe geometry. If this fails and we are using
3078 * discovered stripe geometry, tell the caller to clear the stripe geometry.
3079 * Otherwise, set the aligned geometry (valid or invalid!) so that the
3080 * validation call will fail and exit.
3084 struct mkfs_params
*cfg
)
3086 uint64_t tmp_agsize
;
3087 int dsunit
= cfg
->dsunit
;
3093 * agsize is not a multiple of dsunit
3095 if ((cfg
->agsize
% dsunit
) != 0) {
3097 * Round up to stripe unit boundary. Also make sure
3098 * that agsize is still larger than
3099 * XFS_AG_MIN_BLOCKS(blocklog)
3101 tmp_agsize
= ((cfg
->agsize
+ dsunit
- 1) / dsunit
) * dsunit
;
3103 * Round down to stripe unit boundary if rounding up
3104 * created an AG size that is larger than the AG max.
3106 if (tmp_agsize
> XFS_AG_MAX_BLOCKS(cfg
->blocklog
))
3107 tmp_agsize
= (cfg
->agsize
/ dsunit
) * dsunit
;
3109 if (tmp_agsize
< XFS_AG_MIN_BLOCKS(cfg
->blocklog
) &&
3110 tmp_agsize
> XFS_AG_MAX_BLOCKS(cfg
->blocklog
)) {
3113 * If the AG size is invalid and we are using device
3114 * probed stripe alignment, just clear the alignment
3117 if (!cli_opt_set(&dopts
, D_SUNIT
) &&
3118 !cli_opt_set(&dopts
, D_SU
)) {
3124 * set the agsize to the invalid value so the following
3125 * validation of the ag will fail and print a nice error
3128 cfg
->agsize
= tmp_agsize
;
3132 /* update geometry to be stripe unit aligned */
3133 cfg
->agsize
= tmp_agsize
;
3134 if (!cli_opt_set(&dopts
, D_AGCOUNT
))
3135 cfg
->agcount
= cfg
->dblocks
/ cfg
->agsize
+
3136 (cfg
->dblocks
% cfg
->agsize
!= 0);
3137 if (cli_opt_set(&dopts
, D_AGSIZE
))
3139 _("agsize rounded to %lld, sunit = %d\n"),
3140 (long long)cfg
->agsize
, dsunit
);
3143 if ((cfg
->agsize
% cfg
->dswidth
) == 0 &&
3144 cfg
->dswidth
!= cfg
->dsunit
&&
3147 if (cli_opt_set(&dopts
, D_AGCOUNT
) ||
3148 cli_opt_set(&dopts
, D_AGSIZE
)) {
3150 "Warning: AG size is a multiple of stripe width. This can cause performance\n\
3151 problems by aligning all AGs on the same disk. To avoid this, run mkfs with\n\
3152 an AG size that is one stripe unit smaller or larger, for example %llu.\n"),
3153 (unsigned long long)cfg
->agsize
- dsunit
);
3159 * This is a non-optimal configuration because all AGs start on
3160 * the same disk in the stripe. Changing the AG size by one
3161 * sunit will guarantee that this does not happen.
3163 tmp_agsize
= cfg
->agsize
- dsunit
;
3164 if (tmp_agsize
< XFS_AG_MIN_BLOCKS(cfg
->blocklog
)) {
3165 tmp_agsize
= cfg
->agsize
+ dsunit
;
3166 if (cfg
->dblocks
< cfg
->agsize
) {
3167 /* oh well, nothing to do */
3168 tmp_agsize
= cfg
->agsize
;
3172 cfg
->agsize
= tmp_agsize
;
3173 cfg
->agcount
= cfg
->dblocks
/ cfg
->agsize
+
3174 (cfg
->dblocks
% cfg
->agsize
!= 0);
3179 * If the last AG is too small, reduce the filesystem size
3180 * and drop the blocks.
3182 if (cfg
->dblocks
% cfg
->agsize
!= 0 &&
3183 (cfg
->dblocks
% cfg
->agsize
< XFS_AG_MIN_BLOCKS(cfg
->blocklog
))) {
3184 ASSERT(!cli_opt_set(&dopts
, D_AGCOUNT
));
3185 cfg
->dblocks
= (xfs_rfsblock_t
)((cfg
->agcount
- 1) * cfg
->agsize
);
3187 ASSERT(cfg
->agcount
!= 0);
3190 validate_ag_geometry(cfg
->blocklog
, cfg
->dblocks
,
3191 cfg
->agsize
, cfg
->agcount
);
3196 struct mkfs_params
*cfg
,
3197 struct cli_params
*cli
)
3199 cfg
->imaxpct
= cli
->imaxpct
;
3204 * This returns the % of the disk space that is used for
3205 * inodes, it changes relatively to the FS size:
3206 * - over 50 TB, use 1%,
3207 * - 1TB - 50 TB, use 5%,
3208 * - under 1 TB, use XFS_DFL_IMAXIMUM_PCT (25%).
3211 if (cfg
->dblocks
< TERABYTES(1, cfg
->blocklog
))
3212 cfg
->imaxpct
= XFS_DFL_IMAXIMUM_PCT
;
3213 else if (cfg
->dblocks
< TERABYTES(50, cfg
->blocklog
))
3220 * Set up the initial state of the superblock so we can start using the
3221 * libxfs geometry macros.
3225 struct mkfs_params
*cfg
,
3228 struct sb_feat_args
*fp
= &cfg
->sb_feat
;
3230 sbp
->sb_versionnum
= XFS_DFL_SB_VERSION_BITS
;
3231 if (fp
->crcs_enabled
)
3232 sbp
->sb_versionnum
|= XFS_SB_VERSION_5
;
3234 sbp
->sb_versionnum
|= XFS_SB_VERSION_4
;
3236 if (fp
->inode_align
) {
3237 int cluster_size
= XFS_INODE_BIG_CLUSTER_SIZE
;
3239 sbp
->sb_versionnum
|= XFS_SB_VERSION_ALIGNBIT
;
3240 if (cfg
->sb_feat
.crcs_enabled
)
3241 cluster_size
*= cfg
->inodesize
/ XFS_DINODE_MIN_SIZE
;
3242 sbp
->sb_inoalignmt
= cluster_size
>> cfg
->blocklog
;
3244 sbp
->sb_inoalignmt
= 0;
3247 sbp
->sb_versionnum
|= XFS_SB_VERSION_DALIGNBIT
;
3248 if (fp
->log_version
== 2)
3249 sbp
->sb_versionnum
|= XFS_SB_VERSION_LOGV2BIT
;
3250 if (fp
->attr_version
== 1)
3251 sbp
->sb_versionnum
|= XFS_SB_VERSION_ATTRBIT
;
3253 sbp
->sb_versionnum
|= XFS_SB_VERSION_BORGBIT
;
3255 if (cfg
->sectorsize
> BBSIZE
|| cfg
->lsectorsize
> BBSIZE
) {
3256 sbp
->sb_versionnum
|= XFS_SB_VERSION_SECTORBIT
;
3257 sbp
->sb_logsectlog
= (uint8_t)cfg
->lsectorlog
;
3258 sbp
->sb_logsectsize
= (uint16_t)cfg
->lsectorsize
;
3260 sbp
->sb_logsectlog
= 0;
3261 sbp
->sb_logsectsize
= 0;
3264 sbp
->sb_features2
= 0;
3265 if (fp
->lazy_sb_counters
)
3266 sbp
->sb_features2
|= XFS_SB_VERSION2_LAZYSBCOUNTBIT
;
3267 if (fp
->projid32bit
)
3268 sbp
->sb_features2
|= XFS_SB_VERSION2_PROJID32BIT
;
3269 if (fp
->parent_pointers
)
3270 sbp
->sb_features2
|= XFS_SB_VERSION2_PARENTBIT
;
3271 if (fp
->crcs_enabled
)
3272 sbp
->sb_features2
|= XFS_SB_VERSION2_CRCBIT
;
3273 if (fp
->attr_version
== 2)
3274 sbp
->sb_features2
|= XFS_SB_VERSION2_ATTR2BIT
;
3276 /* v5 superblocks have their own feature bit for dirftype */
3277 if (fp
->dirftype
&& !fp
->crcs_enabled
)
3278 sbp
->sb_features2
|= XFS_SB_VERSION2_FTYPE
;
3280 /* update whether extended features are in use */
3281 if (sbp
->sb_features2
!= 0)
3282 sbp
->sb_versionnum
|= XFS_SB_VERSION_MOREBITSBIT
;
3285 * Due to a structure alignment issue, sb_features2 ended up in one
3286 * of two locations, the second "incorrect" location represented by
3287 * the sb_bad_features2 field. To avoid older kernels mounting
3288 * filesystems they shouldn't, set both field to the same value.
3290 sbp
->sb_bad_features2
= sbp
->sb_features2
;
3292 if (!fp
->crcs_enabled
)
3295 /* default features for v5 filesystems */
3296 sbp
->sb_features_compat
= 0;
3297 sbp
->sb_features_ro_compat
= 0;
3298 sbp
->sb_features_incompat
= XFS_SB_FEAT_INCOMPAT_FTYPE
;
3299 sbp
->sb_features_log_incompat
= 0;
3302 sbp
->sb_features_ro_compat
= XFS_SB_FEAT_RO_COMPAT_FINOBT
;
3304 sbp
->sb_features_ro_compat
|= XFS_SB_FEAT_RO_COMPAT_RMAPBT
;
3306 sbp
->sb_features_ro_compat
|= XFS_SB_FEAT_RO_COMPAT_REFLINK
;
3308 sbp
->sb_features_ro_compat
|= XFS_SB_FEAT_RO_COMPAT_INOBTCNT
;
3310 sbp
->sb_features_incompat
|= XFS_SB_FEAT_INCOMPAT_BIGTIME
;
3313 * Sparse inode chunk support has two main inode alignment requirements.
3314 * First, sparse chunk alignment must match the cluster size. Second,
3315 * full chunk alignment must match the inode chunk size.
3317 * Copy the already calculated/scaled inoalignmt to spino_align and
3318 * update the former to the full inode chunk size.
3321 sbp
->sb_spino_align
= sbp
->sb_inoalignmt
;
3322 sbp
->sb_inoalignmt
= XFS_INODES_PER_CHUNK
*
3323 cfg
->inodesize
>> cfg
->blocklog
;
3324 sbp
->sb_features_incompat
|= XFS_SB_FEAT_INCOMPAT_SPINODES
;
3328 sbp
->sb_features_incompat
|= XFS_SB_FEAT_INCOMPAT_NREXT64
;
3332 * Make sure that the log size is a multiple of the stripe unit
3336 struct mkfs_params
*cfg
,
3340 uint64_t tmp_logblocks
;
3342 /* nothing to do if it's already aligned. */
3343 if ((cfg
->logblocks
% sunit
) == 0)
3346 if (cli_opt_set(&lopts
, L_SIZE
)) {
3348 _("log size %lld is not a multiple of the log stripe unit %d\n"),
3349 (long long) cfg
->logblocks
, sunit
);
3353 tmp_logblocks
= ((cfg
->logblocks
+ (sunit
- 1)) / sunit
) * sunit
;
3355 /* If the log is too large, round down instead of round up */
3356 if ((tmp_logblocks
> XFS_MAX_LOG_BLOCKS
) ||
3357 ((tmp_logblocks
<< cfg
->blocklog
) > XFS_MAX_LOG_BYTES
) ||
3358 tmp_logblocks
> max_logblocks
) {
3359 tmp_logblocks
= (cfg
->logblocks
/ sunit
) * sunit
;
3361 cfg
->logblocks
= tmp_logblocks
;
3365 * Make sure that the internal log is correctly aligned to the specified
3370 struct mkfs_params
*cfg
,
3371 struct xfs_mount
*mp
,
3375 /* round up log start if necessary */
3376 if ((cfg
->logstart
% sunit
) != 0)
3377 cfg
->logstart
= ((cfg
->logstart
+ (sunit
- 1)) / sunit
) * sunit
;
3379 /* If our log start overlaps the next AG's metadata, fail. */
3380 if (!libxfs_verify_fsbno(mp
, cfg
->logstart
)) {
3382 _("Due to stripe alignment, the internal log start (%lld) cannot be aligned\n"
3383 "within an allocation group.\n"),
3384 (long long) cfg
->logstart
);
3388 /* round up/down the log size now */
3389 align_log_size(cfg
, sunit
, max_logblocks
);
3392 * If the end of the log has been rounded past the end of the AG,
3393 * reduce logblocks by a stripe unit to try to get it back under EOAG.
3395 if (!libxfs_verify_fsbext(mp
, cfg
->logstart
, cfg
->logblocks
) &&
3396 cfg
->logblocks
> sunit
) {
3397 cfg
->logblocks
-= sunit
;
3400 /* check the aligned log still starts and ends in the same AG. */
3401 if (!libxfs_verify_fsbext(mp
, cfg
->logstart
, cfg
->logblocks
)) {
3403 _("Due to stripe alignment, the internal log size (%lld) is too large.\n"
3404 "Must fit within an allocation group.\n"),
3405 (long long) cfg
->logblocks
);
3411 validate_log_size(uint64_t logblocks
, int blocklog
, int min_logblocks
)
3413 if (logblocks
< min_logblocks
) {
3415 _("log size %lld blocks too small, minimum size is %d blocks\n"),
3416 (long long)logblocks
, min_logblocks
);
3419 if (logblocks
> XFS_MAX_LOG_BLOCKS
) {
3421 _("log size %lld blocks too large, maximum size is %lld blocks\n"),
3422 (long long)logblocks
, XFS_MAX_LOG_BLOCKS
);
3425 if ((logblocks
<< blocklog
) > XFS_MAX_LOG_BYTES
) {
3427 _("log size %lld bytes too large, maximum size is %lld bytes\n"),
3428 (long long)(logblocks
<< blocklog
), XFS_MAX_LOG_BYTES
);
3434 adjust_ag0_internal_logblocks(
3435 struct mkfs_params
*cfg
,
3436 struct xfs_mount
*mp
,
3444 * mkfs will trip over the write verifiers if the log is allocated in
3445 * AG 0 and consumes enough space that we cannot allocate a non-sparse
3446 * inode chunk for the root directory. The inode allocator requires
3447 * that the AG have enough free space for the chunk itself plus enough
3448 * to fix up the freelist with aligned blocks if we need to fill the
3449 * allocation from the AGFL.
3451 ichunk_blocks
= XFS_INODES_PER_CHUNK
* cfg
->inodesize
>> cfg
->blocklog
;
3452 backoff
= ichunk_blocks
* 4;
3455 * We try to align inode allocations to the data device stripe unit,
3456 * so ensure there's enough space to perform an aligned allocation.
3457 * The inode geometry structure isn't set up yet, so compute this by
3460 backoff
= max(backoff
, cfg
->dsunit
* 2);
3462 *max_logblocks
-= backoff
;
3464 /* If the specified log size is too big, complain. */
3465 if (cli_opt_set(&lopts
, L_SIZE
) && cfg
->logblocks
> *max_logblocks
) {
3467 _("internal log size %lld too large, must be less than %d\n"),
3468 (long long)cfg
->logblocks
,
3473 cfg
->logblocks
= min(cfg
->logblocks
, *max_logblocks
);
3478 struct mkfs_params
*cfg
,
3479 struct cli_params
*cli
,
3480 struct xfs_mount
*mp
)
3482 struct xfs_sb
*sbp
= &mp
->m_sb
;
3483 int min_logblocks
; /* absolute minimum */
3484 int max_logblocks
; /* absolute max for this AG */
3485 struct xfs_mount mount
;
3486 struct libxfs_init dummy_init
= { };
3488 /* we need a temporary mount to calculate the minimum log size. */
3489 memset(&mount
, 0, sizeof(mount
));
3491 libxfs_mount(&mount
, &mp
->m_sb
, &dummy_init
, 0);
3492 min_logblocks
= libxfs_log_calc_minimum_size(&mount
);
3493 libxfs_umount(&mount
);
3495 ASSERT(min_logblocks
);
3496 min_logblocks
= max(XFS_MIN_LOG_BLOCKS
, min_logblocks
);
3498 /* if we have lots of blocks, check against XFS_MIN_LOG_BYTES, too */
3499 if (!cli
->logsize
&&
3500 cfg
->dblocks
>= (1024*1024*1024) >> cfg
->blocklog
)
3501 min_logblocks
= max(min_logblocks
,
3502 XFS_MIN_LOG_BYTES
>> cfg
->blocklog
);
3505 * external logs will have a device and size by now, so all we have
3506 * to do is validate it against minimum size and align it.
3508 if (!cfg
->loginternal
) {
3509 if (min_logblocks
> cfg
->logblocks
) {
3511 _("external log device size %lld blocks too small, must be at least %lld blocks\n"),
3512 (long long)cfg
->logblocks
,
3513 (long long)min_logblocks
);
3519 align_log_size(cfg
, cfg
->lsunit
, XFS_MAX_LOG_BLOCKS
);
3521 validate_log_size(cfg
->logblocks
, cfg
->blocklog
, min_logblocks
);
3526 * Make sure the log fits wholly within an AG
3528 * XXX: If agf->freeblks ends up as 0 because the log uses all
3529 * the free space, it causes the kernel all sorts of problems
3530 * with per-ag reservations. Right now just back it off one
3531 * block, but there's a whole can of worms here that needs to be
3532 * opened to decide what is the valid maximum size of a log in
3535 max_logblocks
= libxfs_alloc_ag_max_usable(mp
) - 1;
3536 if (max_logblocks
< min_logblocks
) {
3538 _("max log size %d smaller than min log size %d, filesystem is too small\n"),
3544 /* internal log - if no size specified, calculate automatically */
3545 if (!cfg
->logblocks
) {
3546 /* Use a 2048:1 fs:log ratio for most filesystems */
3547 cfg
->logblocks
= (cfg
->dblocks
<< cfg
->blocklog
) / 2048;
3548 cfg
->logblocks
= cfg
->logblocks
>> cfg
->blocklog
;
3550 /* But don't go below a reasonable size */
3551 cfg
->logblocks
= max(cfg
->logblocks
,
3552 XFS_MIN_REALISTIC_LOG_BLOCKS(cfg
->blocklog
));
3554 /* And for a tiny filesystem, use the absolute minimum size */
3555 if (cfg
->dblocks
< MEGABYTES(300, cfg
->blocklog
))
3556 cfg
->logblocks
= min_logblocks
;
3558 /* Ensure the chosen size fits within log size requirements */
3559 cfg
->logblocks
= max(min_logblocks
, cfg
->logblocks
);
3560 cfg
->logblocks
= min(cfg
->logblocks
, max_logblocks
);
3562 /* and now clamp the size to the maximum supported size */
3563 cfg
->logblocks
= min(cfg
->logblocks
, XFS_MAX_LOG_BLOCKS
);
3564 if ((cfg
->logblocks
<< cfg
->blocklog
) > XFS_MAX_LOG_BYTES
)
3565 cfg
->logblocks
= XFS_MAX_LOG_BYTES
>> cfg
->blocklog
;
3567 validate_log_size(cfg
->logblocks
, cfg
->blocklog
, min_logblocks
);
3568 } else if (cfg
->logblocks
> max_logblocks
) {
3569 /* check specified log size */
3571 _("internal log size %lld too large, must be less than %d\n"),
3572 (long long)cfg
->logblocks
,
3577 if (cfg
->logblocks
> sbp
->sb_agblocks
- libxfs_prealloc_blocks(mp
)) {
3579 _("internal log size %lld too large, must fit in allocation group\n"),
3580 (long long)cfg
->logblocks
);
3584 if (cli_opt_set(&lopts
, L_AGNUM
)) {
3585 if (cli
->logagno
>= sbp
->sb_agcount
) {
3587 _("log ag number %lld too large, must be less than %lld\n"),
3588 (long long)cli
->logagno
,
3589 (long long)sbp
->sb_agcount
);
3592 cfg
->logagno
= cli
->logagno
;
3594 cfg
->logagno
= (xfs_agnumber_t
)(sbp
->sb_agcount
/ 2);
3596 if (cfg
->logagno
== 0)
3597 adjust_ag0_internal_logblocks(cfg
, mp
, min_logblocks
,
3600 cfg
->logstart
= XFS_AGB_TO_FSB(mp
, cfg
->logagno
,
3601 libxfs_prealloc_blocks(mp
));
3604 * Align the logstart at stripe unit boundary.
3607 align_internal_log(cfg
, mp
, cfg
->lsunit
, max_logblocks
);
3608 } else if (cfg
->dsunit
) {
3609 align_internal_log(cfg
, mp
, cfg
->dsunit
, max_logblocks
);
3611 validate_log_size(cfg
->logblocks
, cfg
->blocklog
, min_logblocks
);
3615 * Set up superblock with the minimum parameters required for
3616 * the libxfs macros needed by the log sizing code to run successfully.
3617 * This includes a minimum log size calculation, so we need everything
3618 * that goes into that calculation to be setup here including feature
3622 start_superblock_setup(
3623 struct mkfs_params
*cfg
,
3624 struct xfs_mount
*mp
,
3627 sbp
->sb_magicnum
= XFS_SB_MAGIC
;
3628 sbp
->sb_sectsize
= (uint16_t)cfg
->sectorsize
;
3629 sbp
->sb_sectlog
= (uint8_t)cfg
->sectorlog
;
3630 sbp
->sb_blocksize
= cfg
->blocksize
;
3631 sbp
->sb_blocklog
= (uint8_t)cfg
->blocklog
;
3633 sbp
->sb_agblocks
= (xfs_agblock_t
)cfg
->agsize
;
3634 sbp
->sb_agblklog
= (uint8_t)log2_roundup(cfg
->agsize
);
3635 sbp
->sb_agcount
= (xfs_agnumber_t
)cfg
->agcount
;
3636 sbp
->sb_dblocks
= (xfs_rfsblock_t
)cfg
->dblocks
;
3638 sbp
->sb_inodesize
= (uint16_t)cfg
->inodesize
;
3639 sbp
->sb_inodelog
= (uint8_t)cfg
->inodelog
;
3640 sbp
->sb_inopblock
= (uint16_t)(cfg
->blocksize
/ cfg
->inodesize
);
3641 sbp
->sb_inopblog
= (uint8_t)(cfg
->blocklog
- cfg
->inodelog
);
3643 sbp
->sb_dirblklog
= cfg
->dirblocklog
- cfg
->blocklog
;
3645 sb_set_features(cfg
, sbp
);
3648 * log stripe unit is stored in bytes on disk and cannot be zero
3651 if (cfg
->sb_feat
.log_version
== 2) {
3653 sbp
->sb_logsunit
= XFS_FSB_TO_B(mp
, cfg
->lsunit
);
3655 sbp
->sb_logsunit
= 1;
3657 sbp
->sb_logsunit
= 0;
3659 /* log reservation calculations depend on rt geometry */
3660 sbp
->sb_rblocks
= cfg
->rtblocks
;
3661 sbp
->sb_rextsize
= cfg
->rtextblocks
;
3662 mp
->m_features
|= libxfs_sb_version_to_features(sbp
);
3667 struct xfs_mount
*mp
,
3670 /* Minimum needed for libxfs_prealloc_blocks() */
3671 mp
->m_blkbb_log
= sbp
->sb_blocklog
- BBSHIFT
;
3672 mp
->m_sectbb_log
= sbp
->sb_sectlog
- BBSHIFT
;
3676 * Format everything from the generated config into the superblock that
3677 * will be used to initialise the on-disk superblock. This is the in-memory
3678 * copy, so no need to care about endian swapping here.
3681 finish_superblock_setup(
3682 struct mkfs_params
*cfg
,
3683 struct xfs_mount
*mp
,
3690 * Labels are null terminated unless the string fits exactly
3691 * in the label field, so assume sb_fname is zeroed and then
3692 * do a memcpy because the destination isn't a normal C string.
3694 label_len
= min(sizeof(sbp
->sb_fname
), strlen(cfg
->label
));
3695 memcpy(sbp
->sb_fname
, cfg
->label
, label_len
);
3698 sbp
->sb_dblocks
= cfg
->dblocks
;
3699 sbp
->sb_rextents
= cfg
->rtextents
;
3700 platform_uuid_copy(&sbp
->sb_uuid
, &cfg
->uuid
);
3701 /* Only in memory; libxfs expects this as if read from disk */
3702 platform_uuid_copy(&sbp
->sb_meta_uuid
, &cfg
->uuid
);
3703 sbp
->sb_logstart
= cfg
->logstart
;
3704 sbp
->sb_rootino
= sbp
->sb_rbmino
= sbp
->sb_rsumino
= NULLFSINO
;
3705 sbp
->sb_agcount
= (xfs_agnumber_t
)cfg
->agcount
;
3706 sbp
->sb_rbmblocks
= cfg
->rtbmblocks
;
3707 sbp
->sb_logblocks
= (xfs_extlen_t
)cfg
->logblocks
;
3708 sbp
->sb_rextslog
= (uint8_t)(cfg
->rtextents
?
3709 libxfs_highbit32((unsigned int)cfg
->rtextents
) : 0);
3710 sbp
->sb_inprogress
= 1; /* mkfs is in progress */
3711 sbp
->sb_imax_pct
= cfg
->imaxpct
;
3714 sbp
->sb_fdblocks
= cfg
->dblocks
-
3715 cfg
->agcount
* libxfs_prealloc_blocks(mp
) -
3716 (cfg
->loginternal
? cfg
->logblocks
: 0);
3717 sbp
->sb_frextents
= 0; /* will do a free later */
3718 sbp
->sb_uquotino
= sbp
->sb_gquotino
= sbp
->sb_pquotino
= 0;
3720 sbp
->sb_unit
= cfg
->dsunit
;
3721 sbp
->sb_width
= cfg
->dswidth
;
3722 mp
->m_features
|= libxfs_sb_version_to_features(sbp
);
3726 /* Prepare an uncached buffer, ready to write something out. */
3727 static inline struct xfs_buf
*
3729 struct xfs_buftarg
*btp
,
3736 error
= -libxfs_buf_get_uncached(btp
, bblen
, 0, &bp
);
3738 fprintf(stderr
, _("Could not get memory for buffer, err=%d\n"),
3743 xfs_buf_set_daddr(bp
, daddr
);
3748 * Sanitise the data and log devices and prepare them so libxfs can mount the
3749 * device successfully. Also check we can access the rt device if configured.
3753 struct mkfs_params
*cfg
,
3754 struct libxfs_init
*xi
,
3755 struct xfs_mount
*mp
,
3759 struct xfs_buf
*buf
;
3760 int whack_blks
= BTOBB(WHACK_SIZE
);
3764 * If there's an old XFS filesystem on the device with enough intact
3765 * information that we can parse the superblock, there's enough
3766 * information on disk to confuse a future xfs_repair call. To avoid
3767 * this, whack all the old secondary superblocks that we can find.
3770 zero_old_xfs_structures(xi
, sbp
);
3773 * If the data device is a file, grow out the file to its final size if
3774 * needed so that the reads for the end of the device in the mount code
3778 xi
->dsize
* xi
->dbsize
< cfg
->dblocks
* cfg
->blocksize
) {
3779 if (ftruncate(xi
->dfd
, cfg
->dblocks
* cfg
->blocksize
) < 0) {
3781 _("%s: Growing the data section failed\n"),
3786 /* update size to be able to whack blocks correctly */
3787 xi
->dsize
= BTOBB(cfg
->dblocks
* cfg
->blocksize
);
3791 * Zero out the end to obliterate any old MD RAID (or other) metadata at
3792 * the end of the device. (MD sb is ~64k from the end, take out a wider
3795 buf
= alloc_write_buf(mp
->m_ddev_targp
, (xi
->dsize
- whack_blks
),
3797 memset(buf
->b_addr
, 0, WHACK_SIZE
);
3798 libxfs_buf_mark_dirty(buf
);
3799 libxfs_buf_relse(buf
);
3802 * Now zero out the beginning of the device, to obliterate any old
3803 * filesystem signatures out there. This should take care of
3804 * swap (somewhere around the page size), jfs (32k),
3805 * ext[2,3] and reiserfs (64k) - and hopefully all else.
3807 buf
= alloc_write_buf(mp
->m_ddev_targp
, 0, whack_blks
);
3808 memset(buf
->b_addr
, 0, WHACK_SIZE
);
3809 libxfs_buf_mark_dirty(buf
);
3810 libxfs_buf_relse(buf
);
3812 /* OK, now write the superblock... */
3813 buf
= alloc_write_buf(mp
->m_ddev_targp
, XFS_SB_DADDR
,
3814 XFS_FSS_TO_BB(mp
, 1));
3815 buf
->b_ops
= &xfs_sb_buf_ops
;
3816 memset(buf
->b_addr
, 0, cfg
->sectorsize
);
3817 libxfs_sb_to_disk(buf
->b_addr
, sbp
);
3818 libxfs_buf_mark_dirty(buf
);
3819 libxfs_buf_relse(buf
);
3821 /* ...and zero the log.... */
3822 lsunit
= sbp
->sb_logsunit
;
3824 lsunit
= sbp
->sb_logsectsize
;
3826 libxfs_log_clear(mp
->m_logdev_targp
, NULL
,
3827 XFS_FSB_TO_DADDR(mp
, cfg
->logstart
),
3828 (xfs_extlen_t
)XFS_FSB_TO_BB(mp
, cfg
->logblocks
),
3829 &sbp
->sb_uuid
, cfg
->sb_feat
.log_version
,
3830 lsunit
, XLOG_FMT
, XLOG_INIT_CYCLE
, false);
3832 /* finally, check we can write the last block in the realtime area */
3833 if (mp
->m_rtdev_targp
->bt_bdev
&& cfg
->rtblocks
> 0) {
3834 buf
= alloc_write_buf(mp
->m_rtdev_targp
,
3835 XFS_FSB_TO_BB(mp
, cfg
->rtblocks
- 1LL),
3836 BTOBB(cfg
->blocksize
));
3837 memset(buf
->b_addr
, 0, cfg
->blocksize
);
3838 libxfs_buf_mark_dirty(buf
);
3839 libxfs_buf_relse(buf
);
3845 initialise_ag_headers(
3846 struct mkfs_params
*cfg
,
3847 struct xfs_mount
*mp
,
3848 xfs_agnumber_t agno
,
3849 int *worst_freelist
,
3850 struct list_head
*buffer_list
)
3852 struct aghdr_init_data id
= {
3854 .agsize
= cfg
->agsize
,
3856 struct xfs_perag
*pag
= libxfs_perag_get(mp
, agno
);
3859 if (agno
== cfg
->agcount
- 1)
3860 id
.agsize
= cfg
->dblocks
- (xfs_rfsblock_t
)(agno
* cfg
->agsize
);
3862 INIT_LIST_HEAD(&id
.buffer_list
);
3863 error
= -libxfs_ag_init_headers(mp
, &id
);
3865 fprintf(stderr
, _("AG header init failed, error %d\n"), error
);
3869 list_splice_tail_init(&id
.buffer_list
, buffer_list
);
3871 if (libxfs_alloc_min_freelist(mp
, pag
) > *worst_freelist
)
3872 *worst_freelist
= libxfs_alloc_min_freelist(mp
, pag
);
3873 libxfs_perag_put(pag
);
3877 initialise_ag_freespace(
3878 struct xfs_mount
*mp
,
3879 xfs_agnumber_t agno
,
3882 struct xfs_alloc_arg args
;
3883 struct xfs_trans
*tp
;
3886 c
= -libxfs_trans_alloc_rollable(mp
, worst_freelist
, &tp
);
3890 memset(&args
, 0, sizeof(args
));
3895 args
.pag
= libxfs_perag_get(mp
, agno
);
3897 libxfs_alloc_fix_freelist(&args
, 0);
3898 libxfs_perag_put(args
.pag
);
3899 c
= -libxfs_trans_commit(tp
);
3902 perror(_("initializing AG free space list"));
3908 * rewrite several secondary superblocks with the root inode number filled out.
3909 * This can help repair recovery from a trashed primary superblock without
3910 * losing the root inode.
3913 rewrite_secondary_superblocks(
3914 struct xfs_mount
*mp
)
3916 struct xfs_buf
*buf
;
3917 struct xfs_dsb
*dsb
;
3920 /* rewrite the last superblock */
3921 error
= -libxfs_buf_read(mp
->m_dev
,
3922 XFS_AGB_TO_DADDR(mp
, mp
->m_sb
.sb_agcount
- 1,
3924 XFS_FSS_TO_BB(mp
, 1), 0, &buf
, &xfs_sb_buf_ops
);
3926 fprintf(stderr
, _("%s: could not re-read AG %u superblock\n"),
3927 progname
, mp
->m_sb
.sb_agcount
- 1);
3931 dsb
->sb_rootino
= cpu_to_be64(mp
->m_sb
.sb_rootino
);
3932 libxfs_buf_mark_dirty(buf
);
3933 libxfs_buf_relse(buf
);
3935 /* and one in the middle for luck if there's enough AGs for that */
3936 if (mp
->m_sb
.sb_agcount
<= 2)
3939 error
= -libxfs_buf_read(mp
->m_dev
,
3940 XFS_AGB_TO_DADDR(mp
, (mp
->m_sb
.sb_agcount
- 1) / 2,
3942 XFS_FSS_TO_BB(mp
, 1), 0, &buf
, &xfs_sb_buf_ops
);
3944 fprintf(stderr
, _("%s: could not re-read AG %u superblock\n"),
3945 progname
, (mp
->m_sb
.sb_agcount
- 1) / 2);
3949 dsb
->sb_rootino
= cpu_to_be64(mp
->m_sb
.sb_rootino
);
3950 libxfs_buf_mark_dirty(buf
);
3951 libxfs_buf_relse(buf
);
3956 struct xfs_mount
*mp
)
3960 if (XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
) != 0) {
3962 _("%s: root inode created in AG %u, not AG 0\n"),
3963 progname
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
));
3968 * The superblock points to the root directory inode, but xfs_repair
3969 * expects to find the root inode in a very specific location computed
3970 * from the filesystem geometry for an extra level of verification.
3972 * Fail the format immediately if those assumptions ever break, because
3973 * repair will toss the root directory.
3975 ino
= libxfs_ialloc_calc_rootino(mp
, mp
->m_sb
.sb_unit
);
3976 if (mp
->m_sb
.sb_rootino
!= ino
) {
3978 _("%s: root inode (%llu) not allocated in expected location (%llu)\n"),
3980 (unsigned long long)mp
->m_sb
.sb_rootino
,
3981 (unsigned long long)ino
);
3987 * INI file format option parser.
3989 * This is called by the file parser library for every valid option it finds in
3990 * the config file. The option is already broken down into a
3991 * {section,name,value} tuple, so all we need to do is feed it to the correct
3992 * suboption parser function and translate the return value.
3994 * Returns 0 on failure, 1 for success.
3999 const char *section
,
4003 struct cli_params
*cli
= user
;
4005 if (!parse_cfgopt(section
, name
, value
, cli
))
4012 struct cli_params
*cli
)
4019 error
= ini_parse(cli
->cfgfile
, cfgfile_parse_ini
, cli
);
4023 _("%s: Unrecognised input on line %d. Aborting.\n"),
4024 cli
->cfgfile
, error
);
4025 } else if (error
== -1) {
4027 _("Unable to open config file %s. Aborting.\n"),
4029 } else if (error
== -2) {
4031 _("Memory allocation failure parsing %s. Aborting.\n"),
4035 _("Unknown error %d opening config file %s. Aborting.\n"),
4036 error
, cli
->cfgfile
);
4040 printf(_("Parameters parsed from config file %s successfully\n"),
4049 xfs_agnumber_t agno
;
4050 struct xfs_buf
*buf
;
4054 int force_overwrite
= 0;
4056 char *protostring
= NULL
;
4057 int worst_freelist
= 0;
4059 struct libxfs_init xi
= {
4060 .isdirect
= LIBXFS_DIRECT
,
4061 .isreadonly
= LIBXFS_EXCLUSIVELY
,
4063 struct xfs_mount mbuf
= {};
4064 struct xfs_mount
*mp
= &mbuf
;
4065 struct xfs_sb
*sbp
= &mp
->m_sb
;
4066 struct xfs_dsb
*dsb
;
4067 struct fs_topology ft
= {};
4068 struct cli_params cli
= {
4073 struct mkfs_params cfg
= {};
4075 struct option long_options
[] = {
4077 .name
= "unsupported",
4078 .has_arg
= no_argument
,
4079 .flag
= &cli
.is_supported
,
4082 {NULL
, 0, NULL
, 0 },
4084 int option_index
= 0;
4086 /* build time defaults */
4087 struct mkfs_default_params dft
= {
4088 .source
= _("package build definitions"),
4089 .sectorsize
= XFS_MIN_SECTORSIZE
,
4090 .blocksize
= 1 << XFS_DFL_BLOCKSIZE_LOG
,
4095 .inode_align
= true,
4097 .lazy_sb_counters
= true,
4098 .projid32bit
= true,
4099 .crcs_enabled
= true,
4106 .parent_pointers
= false,
4112 * When we decide to enable a new feature by default,
4113 * please remember to update the mkfs conf files.
4118 struct list_head buffer_list
;
4121 platform_uuid_generate(&cli
.uuid
);
4122 progname
= basename(argv
[0]);
4123 setlocale(LC_ALL
, "");
4124 bindtextdomain(PACKAGE
, LOCALEDIR
);
4125 textdomain(PACKAGE
);
4128 * TODO: Sourcing defaults from a config file
4130 * Before anything else, see if there's a config file with different
4131 * defaults. If a file exists in <package location>, read in the new
4132 * default values and overwrite them in the &dft structure. This way the
4133 * new defaults will apply before we parse the CLI, and the CLI will
4134 * still be able to override them. When more than one source is
4135 * implemented, emit a message to indicate where the defaults being
4138 * printf(_("Default configuration sourced from %s\n"), dft.source);
4141 /* copy new defaults into CLI parsing structure */
4142 memcpy(&cli
.sb_feat
, &dft
.sb_feat
, sizeof(cli
.sb_feat
));
4143 memcpy(&cli
.fsx
, &dft
.fsx
, sizeof(cli
.fsx
));
4145 while ((c
= getopt_long(argc
, argv
, "b:c:d:i:l:L:m:n:KNp:qr:s:CfV",
4146 long_options
, &option_index
)) != EOF
) {
4152 force_overwrite
= 1;
4164 parse_subopts(c
, optarg
, &cli
);
4167 if (strlen(optarg
) > sizeof(sbp
->sb_fname
))
4168 illegal(optarg
, "L");
4181 printf(_("%s version %s\n"), progname
, VERSION
);
4184 unknown(optopt
, "");
4187 if (argc
- optind
> 1) {
4188 fprintf(stderr
, _("extra arguments\n"));
4190 } else if (argc
- optind
== 1) {
4191 xi
.dname
= getstr(argv
[optind
], &dopts
, D_NAME
);
4195 * Now we have all the options parsed, we can read in the option file
4196 * specified on the command line via "-c options=xxx". Once we have all
4197 * the options from this file parsed, we can then proceed with parameter
4198 * and bounds checking and making the filesystem.
4200 cfgfile_parse(&cli
);
4202 protostring
= setup_proto(cli
.protofile
);
4205 * Extract as much of the valid config as we can from the CLI input
4206 * before opening the libxfs devices.
4208 validate_blocksize(&cfg
, &cli
, &dft
);
4209 validate_sectorsize(&cfg
, &cli
, &dft
, &ft
, dry_run
, force_overwrite
);
4212 * XXX: we still need to set block size and sector size global variables
4213 * so that getnum/cvtnum works correctly
4215 blocksize
= cfg
.blocksize
;
4216 sectorsize
= cfg
.sectorsize
;
4218 validate_log_sectorsize(&cfg
, &cli
, &dft
);
4219 validate_sb_features(&cfg
, &cli
);
4222 * we've now completed basic validation of the features, sector and
4223 * block sizes, so from this point onwards we use the values found in
4224 * the cfg structure for them, not the command line structure.
4226 validate_dirblocksize(&cfg
, &cli
);
4227 validate_inodesize(&cfg
, &cli
);
4230 * if the device size was specified convert it to a block count
4231 * now we have a valid block size. These will be set to zero if
4232 * nothing was specified, indicating we should use the full device.
4234 cfg
.dblocks
= calc_dev_size(cli
.dsize
, &cfg
, &dopts
, D_SIZE
, "data");
4235 cfg
.logblocks
= calc_dev_size(cli
.logsize
, &cfg
, &lopts
, L_SIZE
, "log");
4236 cfg
.rtblocks
= calc_dev_size(cli
.rtsize
, &cfg
, &ropts
, R_SIZE
, "rt");
4238 validate_rtextsize(&cfg
, &cli
, &ft
);
4241 * Open and validate the device configurations
4243 open_devices(&cfg
, &xi
);
4244 validate_overwrite(xi
.dname
, force_overwrite
);
4245 validate_datadev(&cfg
, &cli
);
4246 validate_logdev(&cfg
, &cli
);
4247 validate_rtdev(&cfg
, &cli
);
4248 calc_stripe_factors(&cfg
, &cli
, &ft
);
4251 * At this point when know exactly what size all the devices are,
4252 * so we can start validating and calculating layout options that are
4253 * dependent on device sizes. Once calculated, make sure everything
4254 * aligns to device geometry correctly.
4256 calculate_initial_ag_geometry(&cfg
, &cli
);
4257 align_ag_geometry(&cfg
);
4259 calculate_imaxpct(&cfg
, &cli
);
4262 * Set up the basic superblock parameters now so that we can use
4263 * the geometry information we've already validated in libxfs
4264 * provided functions to determine on-disk format information.
4266 start_superblock_setup(&cfg
, mp
, sbp
);
4267 initialise_mount(mp
, sbp
);
4270 * With the mount set up, we can finally calculate the log size
4271 * constraints and do default size calculations and final validation
4273 calculate_log_size(&cfg
, &cli
, mp
);
4275 finish_superblock_setup(&cfg
, mp
, sbp
);
4277 /* Validate the extent size hints now that @mp is fully set up. */
4278 validate_extsize_hint(mp
, &cli
);
4279 validate_cowextsize_hint(mp
, &cli
);
4281 validate_supported(mp
, &cli
);
4283 /* Print the intended geometry of the fs. */
4284 if (!quiet
|| dry_run
) {
4285 struct xfs_fsop_geom geo
;
4287 libxfs_fs_geometry(mp
, &geo
, XFS_FS_GEOM_MAX_STRUCT_VER
);
4288 xfs_report_geom(&geo
, xi
.dname
, xi
.logname
, xi
.rtname
);
4293 /* Make sure our checksum algorithm really works. */
4294 if (crc32c_test(CRC32CTEST_QUIET
) != 0) {
4296 _("crc32c self-test failed, will not create a filesystem here.\n"));
4300 /* Make sure our dir/attr hash algorithm really works. */
4301 if (dahash_test(DAHASHTEST_QUIET
) != 0) {
4303 _("xfs dir/attr self-test failed, will not create a filesystem here.\n"));
4308 * All values have been validated, discard the old device layout.
4310 if (discard
&& !dry_run
)
4311 discard_devices(&xi
, quiet
);
4314 * we need the libxfs buffer cache from here on in.
4316 libxfs_buftarg_init(mp
, &xi
);
4319 * Before we mount the filesystem we need to make sure the devices have
4320 * enough of the filesystem structure on them that allows libxfs to
4323 prepare_devices(&cfg
, &xi
, mp
, sbp
, force_overwrite
);
4324 mp
= libxfs_mount(mp
, sbp
, &xi
, 0);
4326 fprintf(stderr
, _("%s: filesystem failed to initialize\n"),
4332 * Initialise all the static on disk metadata.
4334 INIT_LIST_HEAD(&buffer_list
);
4335 for (agno
= 0; agno
< cfg
.agcount
; agno
++) {
4336 initialise_ag_headers(&cfg
, mp
, agno
, &worst_freelist
,
4342 error
= -libxfs_buf_delwri_submit(&buffer_list
);
4345 _("%s: writing AG headers failed, err=%d\n"),
4351 error
= -libxfs_buf_delwri_submit(&buffer_list
);
4353 fprintf(stderr
, _("%s: writing AG headers failed, err=%d\n"),
4359 * Initialise the freespace freelists (i.e. AGFLs) in each AG.
4361 for (agno
= 0; agno
< cfg
.agcount
; agno
++)
4362 initialise_ag_freespace(mp
, agno
, worst_freelist
);
4365 * Allocate the root inode and anything else in the proto file.
4367 parse_proto(mp
, &cli
.fsx
, &protostring
, cli
.proto_slashes_are_spaces
);
4370 * Protect ourselves against possible stupidity
4375 * Re-write multiple secondary superblocks with rootinode field set
4377 if (mp
->m_sb
.sb_agcount
> 1)
4378 rewrite_secondary_superblocks(mp
);
4381 * Dump all inodes and buffers before marking us all done.
4382 * Need to drop references to inodes we still hold, first.
4384 libxfs_rtmount_destroy(mp
);
4385 libxfs_bcache_purge();
4388 * Mark the filesystem ok.
4390 buf
= libxfs_getsb(mp
);
4391 if (!buf
|| buf
->b_error
)
4394 dsb
->sb_inprogress
= 0;
4395 libxfs_buf_mark_dirty(buf
);
4396 libxfs_buf_relse(buf
);
4398 /* Exit w/ failure if anything failed to get written to our new fs. */
4399 error
= -libxfs_umount(mp
);
4403 libxfs_destroy(&xi
);