2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "xfs_multidisk.h"
26 #define TERABYTES(count, blog) ((uint64_t)(count) << (40 - (blog)))
27 #define GIGABYTES(count, blog) ((uint64_t)(count) << (30 - (blog)))
28 #define MEGABYTES(count, blog) ((uint64_t)(count) << (20 - (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 unsigned int blocksize
;
47 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.
135 /* Just define the max options array size manually right now */
136 #define MAX_SUBOPTS D_MAX_OPTS
138 #define SUBOPT_NEEDS_VAL (-1LL)
139 #define MAX_CONFLICTS 8
140 #define LAST_CONFLICT (-1)
143 * Table for parsing mkfs parameters.
145 * Description of the structure members follows:
148 * Name is a single char, e.g., for '-d file', name is 'd'.
151 * Subopts is a list of strings naming suboptions. In the example above,
152 * it would contain "file". The last entry of this list has to be NULL.
154 * subopt_params MANDATORY
155 * This is a list of structs tied with subopts. For each entry in subopts,
156 * a corresponding entry has to be defined:
158 * subopt_params struct:
160 * This number, starting from zero, denotes which item in subopt_params
161 * it is. The index has to be the same as is the order in subopts list,
162 * so we can access the right item both in subopt_param and subopts.
165 * Do not set this flag when definning a subopt. It is used to remeber that
166 * this subopt was already seen, for example for conflicts detection.
169 * Do not set. It is used internally for respecification, when some options
170 * has to be parsed twice - at first as a string, then later as a number.
173 * A flag signalling whether the user-given value can use suffixes.
174 * If you want to allow the use of user-friendly values like 13k, 42G,
177 * is_power_2 OPTIONAL
178 * An optional flag for subopts where the given value has to be a power
181 * conflicts MANDATORY
182 * If your subopt is in a conflict with some other option, specify it.
183 * Accepts the .index values of the conflicting subopts and the last
184 * member of this list has to be LAST_CONFLICT.
186 * minval, maxval OPTIONAL
187 * These options are used for automatic range check and they have to be
188 * always used together in pair. If you don't want to limit the max value,
189 * use something like UINT_MAX. If no value is given, then you must either
190 * supply your own validation, or refuse any value in the 'case
191 * X_SOMETHING' block. If you forget to define the min and max value, but
192 * call a standard function for validating user's value, it will cause an
193 * error message notifying you about this issue.
195 * (Said in another way, you can't have minval and maxval both equal
196 * to zero. But if one value is different: minval=0 and maxval=1,
199 * defaultval MANDATORY
200 * The value used if user specifies the subopt, but no value.
201 * If the subopt accepts some values (-d file=[1|0]), then this
202 * sets what is used with simple specifying the subopt (-d file).
203 * A special SUBOPT_NEEDS_VAL can be used to require a user-given
208 const char *subopts
[MAX_SUBOPTS
];
210 struct subopt_param
{
217 struct opt_params
*opts
;
219 } conflicts
[MAX_CONFLICTS
];
222 long long defaultval
;
223 } subopt_params
[MAX_SUBOPTS
];
227 * The two dimensional conflict array requires some initialisations to know
228 * about tables that haven't yet been defined. Work around this ordering
229 * issue with extern definitions here.
231 extern struct opt_params sopts
;
233 struct opt_params bopts
= {
242 .conflicts
= { { NULL
, LAST_CONFLICT
} },
243 .minval
= XFS_MIN_BLOCKSIZE
,
244 .maxval
= XFS_MAX_BLOCKSIZE
,
245 .defaultval
= SUBOPT_NEEDS_VAL
,
250 struct opt_params dopts
= {
253 [D_AGCOUNT
] = "agcount",
258 [D_SWIDTH
] = "swidth",
259 [D_AGSIZE
] = "agsize",
262 [D_SECTSIZE
] = "sectsize",
263 [D_NOALIGN
] = "noalign",
264 [D_RTINHERIT
] = "rtinherit",
265 [D_PROJINHERIT
] = "projinherit",
266 [D_EXTSZINHERIT
] = "extszinherit",
267 [D_COWEXTSIZE
] = "cowextsize",
270 { .index
= D_AGCOUNT
,
271 .conflicts
= { { &dopts
, D_AGSIZE
},
272 { NULL
, LAST_CONFLICT
} },
274 .maxval
= XFS_MAX_AGNUMBER
,
275 .defaultval
= SUBOPT_NEEDS_VAL
,
278 .conflicts
= { { NULL
, LAST_CONFLICT
} },
284 .conflicts
= { { NULL
, LAST_CONFLICT
} },
285 .defaultval
= SUBOPT_NEEDS_VAL
,
288 .conflicts
= { { NULL
, LAST_CONFLICT
} },
290 .minval
= XFS_AG_MIN_BYTES
,
292 .defaultval
= SUBOPT_NEEDS_VAL
,
295 .conflicts
= { { &dopts
, D_NOALIGN
},
298 { NULL
, LAST_CONFLICT
} },
301 .defaultval
= SUBOPT_NEEDS_VAL
,
304 .conflicts
= { { &dopts
, D_NOALIGN
},
307 { NULL
, LAST_CONFLICT
} },
310 .defaultval
= SUBOPT_NEEDS_VAL
,
313 .conflicts
= { { &dopts
, D_AGCOUNT
},
314 { NULL
, LAST_CONFLICT
} },
316 .minval
= XFS_AG_MIN_BYTES
,
317 .maxval
= XFS_AG_MAX_BYTES
,
318 .defaultval
= SUBOPT_NEEDS_VAL
,
321 .conflicts
= { { &dopts
, D_NOALIGN
},
323 { &dopts
, D_SWIDTH
},
324 { NULL
, LAST_CONFLICT
} },
328 .defaultval
= SUBOPT_NEEDS_VAL
,
331 .conflicts
= { { &dopts
, D_NOALIGN
},
333 { &dopts
, D_SWIDTH
},
334 { NULL
, LAST_CONFLICT
} },
337 .defaultval
= SUBOPT_NEEDS_VAL
,
339 { .index
= D_SECTSIZE
,
340 .conflicts
= { { &sopts
, S_SIZE
},
341 { &sopts
, S_SECTSIZE
},
342 { NULL
, LAST_CONFLICT
} },
345 .minval
= XFS_MIN_SECTORSIZE
,
346 .maxval
= XFS_MAX_SECTORSIZE
,
347 .defaultval
= SUBOPT_NEEDS_VAL
,
349 { .index
= D_NOALIGN
,
350 .conflicts
= { { &dopts
, D_SU
},
353 { &dopts
, D_SWIDTH
},
354 { NULL
, LAST_CONFLICT
} },
359 { .index
= D_RTINHERIT
,
360 .conflicts
= { { NULL
, LAST_CONFLICT
} },
365 { .index
= D_PROJINHERIT
,
366 .conflicts
= { { NULL
, LAST_CONFLICT
} },
369 .defaultval
= SUBOPT_NEEDS_VAL
,
371 { .index
= D_EXTSZINHERIT
,
372 .conflicts
= { { NULL
, LAST_CONFLICT
} },
375 .defaultval
= SUBOPT_NEEDS_VAL
,
377 { .index
= D_COWEXTSIZE
,
378 .conflicts
= { { NULL
, LAST_CONFLICT
} },
381 .defaultval
= SUBOPT_NEEDS_VAL
,
387 struct opt_params iopts
= {
391 [I_MAXPCT
] = "maxpct",
392 [I_PERBLOCK
] = "perblock",
395 [I_PROJID32BIT
] = "projid32bit",
396 [I_SPINODES
] = "sparse",
400 .conflicts
= { { NULL
, LAST_CONFLICT
} },
406 .conflicts
= { { NULL
, LAST_CONFLICT
} },
409 .defaultval
= SUBOPT_NEEDS_VAL
,
411 { .index
= I_PERBLOCK
,
412 .conflicts
= { { &iopts
, I_SIZE
},
413 { NULL
, LAST_CONFLICT
} },
415 .minval
= XFS_MIN_INODE_PERBLOCK
,
416 .maxval
= XFS_MAX_BLOCKSIZE
/ XFS_DINODE_MIN_SIZE
,
417 .defaultval
= SUBOPT_NEEDS_VAL
,
420 .conflicts
= { { &iopts
, I_PERBLOCK
},
421 { NULL
, LAST_CONFLICT
} },
423 .minval
= XFS_DINODE_MIN_SIZE
,
424 .maxval
= XFS_DINODE_MAX_SIZE
,
425 .defaultval
= SUBOPT_NEEDS_VAL
,
428 .conflicts
= { { NULL
, LAST_CONFLICT
} },
431 .defaultval
= SUBOPT_NEEDS_VAL
,
433 { .index
= I_PROJID32BIT
,
434 .conflicts
= { { NULL
, LAST_CONFLICT
} },
439 { .index
= I_SPINODES
,
440 .conflicts
= { { NULL
, LAST_CONFLICT
} },
448 struct opt_params lopts
= {
452 [L_INTERNAL
] = "internal",
454 [L_VERSION
] = "version",
458 [L_SECTSIZE
] = "sectsize",
461 [L_LAZYSBCNTR
] = "lazy-count",
465 .conflicts
= { { &lopts
, L_DEV
},
466 { NULL
, LAST_CONFLICT
} },
469 .defaultval
= SUBOPT_NEEDS_VAL
,
471 { .index
= L_INTERNAL
,
472 .conflicts
= { { &lopts
, L_FILE
},
474 { &lopts
, L_SECTSIZE
},
475 { NULL
, LAST_CONFLICT
} },
481 .conflicts
= { { NULL
, LAST_CONFLICT
} },
483 .minval
= 2 * 1024 * 1024LL, /* XXX: XFS_MIN_LOG_BYTES */
484 .maxval
= XFS_MAX_LOG_BYTES
,
485 .defaultval
= SUBOPT_NEEDS_VAL
,
487 { .index
= L_VERSION
,
488 .conflicts
= { { NULL
, LAST_CONFLICT
} },
491 .defaultval
= SUBOPT_NEEDS_VAL
,
494 .conflicts
= { { &lopts
, L_SU
},
495 { NULL
, LAST_CONFLICT
} },
497 .maxval
= BTOBB(XLOG_MAX_RECORD_BSIZE
),
498 .defaultval
= SUBOPT_NEEDS_VAL
,
501 .conflicts
= { { &lopts
, L_SUNIT
},
502 { NULL
, LAST_CONFLICT
} },
505 .maxval
= XLOG_MAX_RECORD_BSIZE
,
506 .defaultval
= SUBOPT_NEEDS_VAL
,
509 .conflicts
= { { &lopts
, L_AGNUM
},
511 { &lopts
, L_INTERNAL
},
512 { NULL
, LAST_CONFLICT
} },
513 .defaultval
= SUBOPT_NEEDS_VAL
,
515 { .index
= L_SECTSIZE
,
516 .conflicts
= { { &lopts
, L_INTERNAL
},
517 { NULL
, LAST_CONFLICT
} },
520 .minval
= XFS_MIN_SECTORSIZE
,
521 .maxval
= XFS_MAX_SECTORSIZE
,
522 .defaultval
= SUBOPT_NEEDS_VAL
,
525 .conflicts
= { { &lopts
, L_INTERNAL
},
526 { NULL
, LAST_CONFLICT
} },
532 .conflicts
= { { &lopts
, L_AGNUM
},
534 { &lopts
, L_INTERNAL
},
535 { NULL
, LAST_CONFLICT
} },
536 .defaultval
= SUBOPT_NEEDS_VAL
,
538 { .index
= L_LAZYSBCNTR
,
539 .conflicts
= { { NULL
, LAST_CONFLICT
} },
547 struct opt_params nopts
= {
551 [N_VERSION
] = "version",
556 .conflicts
= { { NULL
, LAST_CONFLICT
} },
559 .minval
= 1 << XFS_MIN_REC_DIRSIZE
,
560 .maxval
= XFS_MAX_BLOCKSIZE
,
561 .defaultval
= SUBOPT_NEEDS_VAL
,
563 { .index
= N_VERSION
,
564 .conflicts
= { { NULL
, LAST_CONFLICT
} },
567 .defaultval
= SUBOPT_NEEDS_VAL
,
570 .conflicts
= { { NULL
, LAST_CONFLICT
} },
578 struct opt_params ropts
= {
581 [R_EXTSIZE
] = "extsize",
586 [R_NOALIGN
] = "noalign",
589 { .index
= R_EXTSIZE
,
590 .conflicts
= { { NULL
, LAST_CONFLICT
} },
592 .minval
= XFS_MIN_RTEXTSIZE
,
593 .maxval
= XFS_MAX_RTEXTSIZE
,
594 .defaultval
= SUBOPT_NEEDS_VAL
,
597 .conflicts
= { { NULL
, LAST_CONFLICT
} },
601 .defaultval
= SUBOPT_NEEDS_VAL
,
604 .conflicts
= { { &ropts
, R_NAME
},
605 { NULL
, LAST_CONFLICT
} },
606 .defaultval
= SUBOPT_NEEDS_VAL
,
612 .conflicts
= { { NULL
, LAST_CONFLICT
} },
615 .conflicts
= { { &ropts
, R_DEV
},
616 { NULL
, LAST_CONFLICT
} },
617 .defaultval
= SUBOPT_NEEDS_VAL
,
619 { .index
= R_NOALIGN
,
623 .conflicts
= { { NULL
, LAST_CONFLICT
} },
628 struct opt_params sopts
= {
632 [S_SECTSIZE
] = "sectsize",
636 .conflicts
= { { &sopts
, S_SECTSIZE
},
637 { &dopts
, D_SECTSIZE
},
638 { NULL
, LAST_CONFLICT
} },
641 .minval
= XFS_MIN_SECTORSIZE
,
642 .maxval
= XFS_MAX_SECTORSIZE
,
643 .defaultval
= SUBOPT_NEEDS_VAL
,
645 { .index
= S_SECTSIZE
,
646 .conflicts
= { { &sopts
, S_SIZE
},
647 { &dopts
, D_SECTSIZE
},
648 { NULL
, LAST_CONFLICT
} },
651 .minval
= XFS_MIN_SECTORSIZE
,
652 .maxval
= XFS_MAX_SECTORSIZE
,
653 .defaultval
= SUBOPT_NEEDS_VAL
,
658 struct opt_params mopts
= {
662 [M_FINOBT
] = "finobt",
664 [M_RMAPBT
] = "rmapbt",
665 [M_REFLINK
] = "reflink",
669 .conflicts
= { { NULL
, LAST_CONFLICT
} },
675 .conflicts
= { { NULL
, LAST_CONFLICT
} },
681 .conflicts
= { { NULL
, LAST_CONFLICT
} },
682 .defaultval
= SUBOPT_NEEDS_VAL
,
685 .conflicts
= { { NULL
, LAST_CONFLICT
} },
690 { .index
= M_REFLINK
,
691 .conflicts
= { { NULL
, LAST_CONFLICT
} },
699 /* quick way of checking if a parameter was set on the CLI */
702 struct opt_params
*opts
,
705 return opts
->subopt_params
[subopt
].seen
||
706 opts
->subopt_params
[subopt
].str_seen
;
710 * Options configured on the command line.
712 * This stores all the specific config parameters the user sets on the command
713 * line. We do not use these values directly - they are inputs to the mkfs
714 * geometry validation and override any default configuration value we have.
716 * We don't keep flags to indicate what parameters are set - if we need to check
717 * if an option was set on the command line, we check the relevant entry in the
718 * option table which records whether it was specified in the .seen and
719 * .str_seen variables in the table.
721 * Some parameters are stored as strings for post-parsing after their dependent
722 * options have been resolved (e.g. block size and sector size have been parsed
725 * This allows us to check that values have been set without needing separate
726 * flags for each value, and hence avoids needing to record and check for each
727 * specific option that can set the value later on in the code. In the cases
728 * where we don't have a cli_params structure around, the above cli_opt_set()
729 * function can be used.
731 struct sb_feat_args
{
735 bool inode_align
; /* XFS_SB_VERSION_ALIGNBIT */
736 bool nci
; /* XFS_SB_VERSION_BORGBIT */
737 bool lazy_sb_counters
; /* XFS_SB_VERSION2_LAZYSBCOUNTBIT */
738 bool parent_pointers
; /* XFS_SB_VERSION2_PARENTBIT */
739 bool projid32bit
; /* XFS_SB_VERSION2_PROJID32BIT */
740 bool crcs_enabled
; /* XFS_SB_VERSION2_CRCBIT */
741 bool dirftype
; /* XFS_SB_VERSION2_FTYPE */
742 bool finobt
; /* XFS_SB_FEAT_RO_COMPAT_FINOBT */
743 bool spinodes
; /* XFS_SB_FEAT_INCOMPAT_SPINODES */
744 bool rmapbt
; /* XFS_SB_FEAT_RO_COMPAT_RMAPBT */
745 bool reflink
; /* XFS_SB_FEAT_RO_COMPAT_REFLINK */
754 /* parameters that depend on sector/block size being validated. */
764 /* parameters where 0 is a valid CLI value */
772 /* parameters where 0 is not a valid value */
780 /* feature flags that are set */
781 struct sb_feat_args sb_feat
;
783 /* root inode characteristics */
786 /* libxfs device setup */
787 struct libxfs_xinit
*xi
;
791 * Calculated filesystem feature and geometry information.
793 * This structure contains the information we will use to create the on-disk
794 * filesystem from. The validation and calculation code uses it to store all the
795 * temporary and final config state for the filesystem.
797 * The information in this structure will contain a mix of validated CLI input
798 * variables, default feature state and calculated values that are needed to
799 * construct the superblock and other on disk features. These are all in one
800 * place so that we don't have to pass handfuls of seemingly arbitrary variables
801 * around to different functions to do the work we need to do.
819 uint64_t rtextblocks
;
821 uint64_t rtbmblocks
; /* rt bitmap blocks */
823 int dsunit
; /* in FSBs */
824 int dswidth
; /* in FSBs */
825 int lsunit
; /* in FSBs */
839 struct sb_feat_args sb_feat
;
843 * Default filesystem features and configuration values
845 * This structure contains the default mkfs values that are to be used when
846 * a user does not specify the option on the command line. We do not use these
847 * values directly - they are inputs to the mkfs geometry validation and
850 struct mkfs_default_params
{
851 char *source
; /* where the defaults came from */
856 /* feature flags that are set */
857 struct sb_feat_args sb_feat
;
859 /* root inode characteristics */
863 static void __attribute__((noreturn
))
866 fprintf(stderr
, _("Usage: %s\n\
867 /* blocksize */ [-b size=num]\n\
868 /* metadata */ [-m crc=0|1,finobt=0|1,uuid=xxx,rmapbt=0|1,reflink=0|1]\n\
869 /* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num,\n\
870 (sunit=value,swidth=value|su=num,sw=num|noalign),\n\
872 /* force overwrite */ [-f]\n\
873 /* inode size */ [-i log=n|perblock=n|size=num,maxpct=n,attr=0|1|2,\n\
874 projid32bit=0|1,sparse=0|1]\n\
875 /* no discard */ [-K]\n\
876 /* log subvol */ [-l agnum=n,internal,size=num,logdev=xxx,version=n\n\
877 sunit=value|su=num,sectsize=num,lazy-count=0|1]\n\
878 /* label */ [-L label (maximum 12 characters)]\n\
879 /* naming */ [-n size=num,version=2|ci,ftype=0|1]\n\
880 /* no-op info only */ [-N]\n\
881 /* prototype file */ [-p fname]\n\
883 /* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx]\n\
884 /* sectorsize */ [-s size=num]\n\
885 /* version */ [-V]\n\
887 <devicename> is required unless -d name=xxx is given.\n\
888 <num> is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxx KiB),\n\
889 xxxm (xxx MiB), xxxg (xxx GiB), xxxt (xxx TiB) or xxxp (xxx PiB).\n\
890 <value> is xxx (512 byte blocks).\n"),
897 struct opt_params
*opts
,
899 struct opt_params
*con_opts
,
902 fprintf(stderr
, _("Cannot specify both -%c %s and -%c %s\n"),
903 con_opts
->name
, con_opts
->subopts
[conflict
],
904 opts
->name
, opts
->subopts
[option
]);
914 fprintf(stderr
, _("Illegal value %s for -%s option\n"), value
, opt
);
922 return (i
& (i
- 1)) == 0;
925 static void __attribute__((noreturn
))
931 fprintf(stderr
, _("-%c %s option requires a value\n"), opt
, tab
[idx
]);
941 fprintf(stderr
, "-%c ", opt
);
943 fprintf(stderr
, "%s ", tab
[idx
]);
944 fprintf(stderr
, _("option respecified\n"));
953 fprintf(stderr
, _("unknown option -%c %s\n"), opt
, s
);
959 unsigned int blksize
,
960 unsigned int sectsize
,
967 i
= strtoll(s
, &sp
, 0);
968 if (i
== 0 && sp
== s
)
979 _("Blocksize must be provided prior to using 'b' suffix.\n"));
988 _("Sectorsize must be specified prior to using 's' suffix.\n"));
1027 bool force_overwrite
,
1028 const char *optname
)
1030 struct stat statbuf
;
1032 if (*isfile
&& (no_size
|| no_name
)) {
1034 _("if -%s file then -%s name and -%s size are required\n"),
1035 optname
, optname
, optname
);
1040 fprintf(stderr
, _("No device name specified\n"));
1044 if (stat(name
, &statbuf
)) {
1045 if (errno
== ENOENT
&& *isfile
) {
1052 _("Error accessing specified device %s: %s\n"),
1053 name
, strerror(errno
));
1058 if (!force_overwrite
&& check_overwrite(name
)) {
1060 _("%s: Use the -f option to force overwrite.\n"),
1066 * We only want to completely truncate and recreate an existing file if
1067 * we were specifically told it was a file. Set the create flag only in
1068 * this case to trigger that behaviour.
1070 if (S_ISREG(statbuf
.st_mode
)) {
1078 if (S_ISBLK(statbuf
.st_mode
)) {
1081 _("specified \"-%s file\" on a block device %s\n"),
1089 _("specified device %s not a file or block device\n"),
1095 validate_ag_geometry(
1101 if (agsize
< XFS_AG_MIN_BLOCKS(blocklog
)) {
1103 _("agsize (%lld blocks) too small, need at least %lld blocks\n"),
1105 (long long)XFS_AG_MIN_BLOCKS(blocklog
));
1109 if (agsize
> XFS_AG_MAX_BLOCKS(blocklog
)) {
1111 _("agsize (%lld blocks) too big, maximum is %lld blocks\n"),
1113 (long long)XFS_AG_MAX_BLOCKS(blocklog
));
1117 if (agsize
> dblocks
) {
1119 _("agsize (%lld blocks) too big, data area is %lld blocks\n"),
1120 (long long)agsize
, (long long)dblocks
);
1124 if (agsize
< XFS_AG_MIN_BLOCKS(blocklog
)) {
1126 _("too many allocation groups for size = %lld\n"),
1128 fprintf(stderr
, _("need at most %lld allocation groups\n"),
1129 (long long)(dblocks
/ XFS_AG_MIN_BLOCKS(blocklog
) +
1130 (dblocks
% XFS_AG_MIN_BLOCKS(blocklog
) != 0)));
1134 if (agsize
> XFS_AG_MAX_BLOCKS(blocklog
)) {
1136 _("too few allocation groups for size = %lld\n"), (long long)agsize
);
1138 _("need at least %lld allocation groups\n"),
1139 (long long)(dblocks
/ XFS_AG_MAX_BLOCKS(blocklog
) +
1140 (dblocks
% XFS_AG_MAX_BLOCKS(blocklog
) != 0)));
1145 * If the last AG is too small, reduce the filesystem size
1146 * and drop the blocks.
1148 if ( dblocks
% agsize
!= 0 &&
1149 (dblocks
% agsize
< XFS_AG_MIN_BLOCKS(blocklog
))) {
1151 _("last AG size %lld blocks too small, minimum size is %lld blocks\n"),
1152 (long long)(dblocks
% agsize
),
1153 (long long)XFS_AG_MIN_BLOCKS(blocklog
));
1158 * If agcount is too large, make it smaller.
1160 if (agcount
> XFS_MAX_AGNUMBER
+ 1) {
1162 _("%lld allocation groups is too many, maximum is %lld\n"),
1163 (long long)agcount
, (long long)XFS_MAX_AGNUMBER
+ 1);
1169 zero_old_xfs_structures(
1180 * We open regular files with O_TRUNC|O_CREAT. Nothing to do here...
1182 if (xi
->disfile
&& xi
->dcreat
)
1186 * read in existing filesystem superblock, use its geometry
1187 * settings and zero the existing secondary superblocks.
1189 buf
= memalign(libxfs_device_alignment(), new_sb
->sb_sectsize
);
1192 _("error reading existing superblock -- failed to memalign buffer\n"));
1195 memset(buf
, 0, new_sb
->sb_sectsize
);
1198 * If we are creating an image file, it might be of zero length at this
1199 * point in time. Hence reading the existing superblock is going to
1200 * return zero bytes. It's not a failure we need to warn about in this
1203 off
= pread(xi
->dfd
, buf
, new_sb
->sb_sectsize
, 0);
1204 if (off
!= new_sb
->sb_sectsize
) {
1207 _("error reading existing superblock: %s\n"),
1211 libxfs_sb_from_disk(&sb
, buf
);
1214 * perform same basic superblock validation to make sure we
1215 * actually zero secondary blocks
1217 if (sb
.sb_magicnum
!= XFS_SB_MAGIC
|| sb
.sb_blocksize
== 0)
1220 for (bsize
= 1, i
= 0; bsize
< sb
.sb_blocksize
&&
1221 i
< sizeof(sb
.sb_blocksize
) * NBBY
; i
++)
1224 if (i
< XFS_MIN_BLOCKSIZE_LOG
|| i
> XFS_MAX_BLOCKSIZE_LOG
||
1225 i
!= sb
.sb_blocklog
)
1228 if (sb
.sb_dblocks
> ((uint64_t)sb
.sb_agcount
* sb
.sb_agblocks
) ||
1229 sb
.sb_dblocks
< ((uint64_t)(sb
.sb_agcount
- 1) *
1230 sb
.sb_agblocks
+ XFS_MIN_AG_BLOCKS
))
1234 * block size and basic geometry seems alright, zero the secondaries.
1236 memset(buf
, 0, new_sb
->sb_sectsize
);
1238 for (i
= 1; i
< sb
.sb_agcount
; i
++) {
1239 off
+= sb
.sb_agblocks
;
1240 if (pwrite(xi
->dfd
, buf
, new_sb
->sb_sectsize
,
1241 off
<< sb
.sb_blocklog
) == -1)
1249 discard_blocks(dev_t dev
, uint64_t nsectors
)
1254 * We intentionally ignore errors from the discard ioctl. It is
1255 * not necessary for the mkfs functionality but just an optimization.
1257 fd
= libxfs_device_to_fd(dev
);
1259 platform_discard_blocks(fd
, 0, nsectors
<< 9);
1262 static __attribute__((noreturn
)) void
1265 struct opt_params
*opts
,
1270 _("Illegal value %s for -%c %s option. %s\n"),
1271 value
, opts
->name
, opts
->subopts
[index
],
1272 reason
? reason
: "");
1277 * Check for conflicts and option respecification.
1281 struct opt_params
*opts
,
1285 struct subopt_param
*sp
= &opts
->subopt_params
[index
];
1288 if (sp
->index
!= index
) {
1290 _("Developer screwed up option parsing (%d/%d)! Please report!\n"),
1292 reqval(opts
->name
, opts
->subopts
, index
);
1296 * Check for respecification of the option. This is more complex than it
1297 * seems because some options are parsed twice - once as a string during
1298 * input parsing, then later the string is passed to getnum for
1299 * conversion into a number and bounds checking. Hence the two variables
1300 * used to track the different uses based on the @str parameter passed
1305 respec(opts
->name
, opts
->subopts
, index
);
1309 respec(opts
->name
, opts
->subopts
, index
);
1310 sp
->str_seen
= true;
1313 /* check for conflicts with the option */
1314 for (i
= 0; i
< MAX_CONFLICTS
; i
++) {
1315 struct _conflict
*con
= &sp
->conflicts
[i
];
1317 if (con
->subopt
== LAST_CONFLICT
)
1319 if (con
->opts
->subopt_params
[con
->subopt
].seen
||
1320 con
->opts
->subopt_params
[con
->subopt
].str_seen
)
1321 conflict(opts
, index
, con
->opts
, con
->subopt
);
1328 struct opt_params
*opts
,
1331 struct subopt_param
*sp
= &opts
->subopt_params
[index
];
1334 check_opt(opts
, index
, false);
1335 /* empty strings might just return a default value */
1336 if (!str
|| *str
== '\0') {
1337 if (sp
->defaultval
== SUBOPT_NEEDS_VAL
)
1338 reqval(opts
->name
, opts
->subopts
, index
);
1339 return sp
->defaultval
;
1342 if (sp
->minval
== 0 && sp
->maxval
== 0) {
1344 _("Option -%c %s has undefined minval/maxval."
1345 "Can't verify value range. This is a bug.\n"),
1346 opts
->name
, opts
->subopts
[index
]);
1351 * Some values are pure numbers, others can have suffixes that define
1352 * the units of the number. Those get passed to cvtnum(), otherwise we
1353 * convert it ourselves to guarantee there is no trailing garbage in the
1357 c
= cvtnum(blocksize
, sectorsize
, str
);
1361 c
= strtoll(str
, &str_end
, 0);
1362 if (c
== 0 && str_end
== str
)
1363 illegal_option(str
, opts
, index
, NULL
);
1364 if (*str_end
!= '\0')
1365 illegal_option(str
, opts
, index
, NULL
);
1368 /* Validity check the result. */
1370 illegal_option(str
, opts
, index
, _("value is too small"));
1371 else if (c
> sp
->maxval
)
1372 illegal_option(str
, opts
, index
, _("value is too large"));
1373 if (sp
->is_power_2
&& !ispow2(c
))
1374 illegal_option(str
, opts
, index
, _("value must be a power of 2"));
1379 * Option is a string - do all the option table work, and check there
1380 * is actually an option string. Otherwise we don't do anything with the string
1381 * here - validation will be done later when the string is converted to a value
1382 * or used as a file/device path.
1387 struct opt_params
*opts
,
1390 check_opt(opts
, index
, true);
1392 /* empty strings for string options are not valid */
1393 if (!str
|| *str
== '\0')
1394 reqval(opts
->name
, opts
->subopts
, index
);
1400 struct opt_params
*opts
,
1403 struct cli_params
*cli
)
1407 cli
->blocksize
= getnum(value
, opts
, subopt
);
1417 struct opt_params
*opts
,
1420 struct cli_params
*cli
)
1424 cli
->agcount
= getnum(value
, opts
, subopt
);
1427 cli
->agsize
= getstr(value
, opts
, subopt
);
1430 cli
->xi
->disfile
= getnum(value
, opts
, subopt
);
1433 cli
->xi
->dname
= getstr(value
, opts
, subopt
);
1436 cli
->dsize
= getstr(value
, opts
, subopt
);
1439 cli
->dsunit
= getnum(value
, opts
, subopt
);
1442 cli
->dswidth
= getnum(value
, opts
, subopt
);
1445 cli
->dsu
= getstr(value
, opts
, subopt
);
1448 cli
->dsw
= getnum(value
, opts
, subopt
);
1451 cli
->sb_feat
.nodalign
= getnum(value
, opts
, subopt
);
1454 cli
->sectorsize
= getnum(value
, opts
, subopt
);
1457 if (getnum(value
, opts
, subopt
))
1458 cli
->fsx
.fsx_xflags
|= XFS_DIFLAG_RTINHERIT
;
1461 cli
->fsx
.fsx_projid
= getnum(value
, opts
, subopt
);
1462 cli
->fsx
.fsx_xflags
|= XFS_DIFLAG_PROJINHERIT
;
1464 case D_EXTSZINHERIT
:
1465 cli
->fsx
.fsx_extsize
= getnum(value
, opts
, subopt
);
1466 cli
->fsx
.fsx_xflags
|= XFS_DIFLAG_EXTSZINHERIT
;
1469 cli
->fsx
.fsx_cowextsize
= getnum(value
, opts
, subopt
);
1470 cli
->fsx
.fsx_xflags
|= FS_XFLAG_COWEXTSIZE
;
1480 struct opt_params
*opts
,
1483 struct cli_params
*cli
)
1487 cli
->sb_feat
.inode_align
= getnum(value
, opts
, subopt
);
1490 cli
->imaxpct
= getnum(value
, opts
, subopt
);
1493 cli
->inopblock
= getnum(value
, opts
, subopt
);
1496 cli
->inodesize
= getnum(value
, opts
, subopt
);
1499 cli
->sb_feat
.attr_version
= getnum(value
, opts
, subopt
);
1502 cli
->sb_feat
.projid32bit
= getnum(value
, opts
, subopt
);
1505 cli
->sb_feat
.spinodes
= getnum(value
, opts
, subopt
);
1515 struct opt_params
*opts
,
1518 struct cli_params
*cli
)
1522 cli
->logagno
= getnum(value
, opts
, subopt
);
1525 cli
->xi
->lisfile
= getnum(value
, opts
, subopt
);
1528 cli
->loginternal
= getnum(value
, opts
, subopt
);
1531 cli
->lsu
= getstr(value
, opts
, subopt
);
1534 cli
->lsunit
= getnum(value
, opts
, subopt
);
1538 cli
->xi
->logname
= getstr(value
, opts
, subopt
);
1539 cli
->loginternal
= 0;
1542 cli
->sb_feat
.log_version
= getnum(value
, opts
, subopt
);
1545 cli
->logsize
= getstr(value
, opts
, subopt
);
1548 cli
->lsectorsize
= getnum(value
, opts
, subopt
);
1551 cli
->sb_feat
.lazy_sb_counters
= getnum(value
, opts
, subopt
);
1561 struct opt_params
*opts
,
1564 struct cli_params
*cli
)
1568 cli
->sb_feat
.crcs_enabled
= getnum(value
, opts
, subopt
);
1569 if (cli
->sb_feat
.crcs_enabled
)
1570 cli
->sb_feat
.dirftype
= true;
1573 cli
->sb_feat
.finobt
= getnum(value
, opts
, subopt
);
1576 if (!value
|| *value
== '\0')
1577 reqval('m', opts
->subopts
, subopt
);
1578 if (platform_uuid_parse(value
, &cli
->uuid
))
1579 illegal(value
, "m uuid");
1582 cli
->sb_feat
.rmapbt
= getnum(value
, opts
, subopt
);
1585 cli
->sb_feat
.reflink
= getnum(value
, opts
, subopt
);
1595 struct opt_params
*opts
,
1598 struct cli_params
*cli
)
1602 cli
->dirblocksize
= getstr(value
, opts
, subopt
);
1605 value
= getstr(value
, &nopts
, subopt
);
1606 if (!strcasecmp(value
, "ci")) {
1608 cli
->sb_feat
.nci
= true;
1610 cli
->sb_feat
.dir_version
= getnum(value
, opts
, subopt
);
1614 cli
->sb_feat
.dirftype
= getnum(value
, opts
, subopt
);
1624 struct opt_params
*opts
,
1627 struct cli_params
*cli
)
1631 cli
->rtextsize
= getstr(value
, opts
, subopt
);
1634 cli
->xi
->risfile
= getnum(value
, opts
, subopt
);
1638 cli
->xi
->rtname
= getstr(value
, opts
, subopt
);
1641 cli
->rtsize
= getstr(value
, opts
, subopt
);
1644 cli
->sb_feat
.nortalign
= getnum(value
, opts
, subopt
);
1654 struct opt_params
*opts
,
1657 struct cli_params
*cli
)
1662 cli
->sectorsize
= getnum(value
, opts
, subopt
);
1663 cli
->lsectorsize
= cli
->sectorsize
;
1673 struct opt_params
*opts
;
1676 { 'b', &bopts
, block_opts_parser
},
1677 { 'd', &dopts
, data_opts_parser
},
1678 { 'i', &iopts
, inode_opts_parser
},
1679 { 'l', &lopts
, log_opts_parser
},
1680 { 'm', &mopts
, meta_opts_parser
},
1681 { 'n', &nopts
, naming_opts_parser
},
1682 { 'r', &ropts
, rtdev_opts_parser
},
1683 { 's', &sopts
, sector_opts_parser
},
1684 { '\0', NULL
, NULL
},
1691 struct cli_params
*cli
)
1693 struct subopts
*sop
= &subopt_tab
[0];
1698 if (sop
->opt
== opt
)
1703 /* should never happen */
1708 while (*p
!= '\0') {
1709 char **subopts
= (char **)sop
->opts
->subopts
;
1713 subopt
= getsubopt(&p
, subopts
, &value
);
1715 ret
= (sop
->parser
)(sop
->opts
, subopt
, value
, cli
);
1717 unknown(opt
, value
);
1722 validate_sectorsize(
1723 struct mkfs_params
*cfg
,
1724 struct cli_params
*cli
,
1725 struct mkfs_default_params
*dft
,
1726 struct fs_topology
*ft
,
1729 int force_overwrite
)
1731 /* set configured sector sizes in preparation for checks */
1732 if (!cli
->sectorsize
) {
1733 cfg
->sectorsize
= dft
->sectorsize
;
1735 cfg
->sectorsize
= cli
->sectorsize
;
1737 cfg
->sectorlog
= libxfs_highbit32(cfg
->sectorsize
);
1740 * Before anything else, verify that we are correctly operating on
1741 * files or block devices and set the control parameters correctly.
1743 check_device_type(dfile
, &cli
->xi
->disfile
, !cli
->dsize
, !dfile
,
1744 dry_run
? NULL
: &cli
->xi
->dcreat
,
1745 force_overwrite
, "d");
1746 if (!cli
->loginternal
)
1747 check_device_type(cli
->xi
->logname
, &cli
->xi
->lisfile
,
1748 !cli
->logsize
, !cli
->xi
->logname
,
1749 dry_run
? NULL
: &cli
->xi
->lcreat
,
1750 force_overwrite
, "l");
1751 if (cli
->xi
->rtname
)
1752 check_device_type(cli
->xi
->rtname
, &cli
->xi
->risfile
,
1753 !cli
->rtsize
, !cli
->xi
->rtname
,
1754 dry_run
? NULL
: &cli
->xi
->rcreat
,
1755 force_overwrite
, "r");
1758 * Explicitly disable direct IO for image files so we don't error out on
1759 * sector size mismatches between the new filesystem and the underlying
1762 if (cli
->xi
->disfile
|| cli
->xi
->lisfile
|| cli
->xi
->risfile
)
1763 cli
->xi
->isdirect
= 0;
1765 memset(ft
, 0, sizeof(*ft
));
1766 get_topology(cli
->xi
, ft
, force_overwrite
);
1768 if (!cli
->sectorsize
) {
1770 * Unless specified manually on the command line use the
1771 * advertised sector size of the device. We use the physical
1772 * sector size unless the requested block size is smaller
1773 * than that, then we can use logical, but warn about the
1776 * Set the topology sectors if they were not probed to the
1777 * minimum supported sector size.
1780 if (!ft
->lsectorsize
)
1781 ft
->lsectorsize
= XFS_MIN_SECTORSIZE
;
1783 /* Older kernels may not have physical/logical distinction */
1784 if (!ft
->psectorsize
)
1785 ft
->psectorsize
= ft
->lsectorsize
;
1787 cfg
->sectorsize
= ft
->psectorsize
;
1788 if (cfg
->blocksize
< cfg
->sectorsize
&&
1789 cfg
->blocksize
>= ft
->lsectorsize
) {
1791 _("specified blocksize %d is less than device physical sector size %d\n"
1792 "switching to logical sector size %d\n"),
1793 cfg
->blocksize
, ft
->psectorsize
,
1795 cfg
->sectorsize
= ft
->lsectorsize
;
1798 cfg
->sectorlog
= libxfs_highbit32(cfg
->sectorsize
);
1801 /* validate specified/probed sector size */
1802 if (cfg
->sectorsize
< XFS_MIN_SECTORSIZE
||
1803 cfg
->sectorsize
> XFS_MAX_SECTORSIZE
) {
1804 fprintf(stderr
, _("illegal sector size %d\n"), cfg
->sectorsize
);
1808 if (cfg
->blocksize
< cfg
->sectorsize
) {
1810 _("block size %d cannot be smaller than sector size %d\n"),
1811 cfg
->blocksize
, cfg
->sectorsize
);
1815 if (cfg
->sectorsize
< ft
->lsectorsize
) {
1816 fprintf(stderr
, _("illegal sector size %d; hw sector is %d\n"),
1817 cfg
->sectorsize
, ft
->lsectorsize
);
1824 struct mkfs_params
*cfg
,
1825 struct cli_params
*cli
,
1826 struct mkfs_default_params
*dft
)
1829 * Blocksize and sectorsize first, other things depend on them
1830 * For RAID4/5/6 we want to align sector size and block size,
1831 * so we need to start with the device geometry extraction too.
1833 if (!cli
->blocksize
)
1834 cfg
->blocksize
= dft
->blocksize
;
1836 cfg
->blocksize
= cli
->blocksize
;
1837 cfg
->blocklog
= libxfs_highbit32(cfg
->blocksize
);
1839 /* validate block sizes are in range */
1840 if (cfg
->blocksize
< XFS_MIN_BLOCKSIZE
||
1841 cfg
->blocksize
> XFS_MAX_BLOCKSIZE
) {
1842 fprintf(stderr
, _("illegal block size %d\n"), cfg
->blocksize
);
1846 if (cli
->sb_feat
.crcs_enabled
&&
1847 cfg
->blocksize
< XFS_MIN_CRC_BLOCKSIZE
) {
1849 _("Minimum block size for CRC enabled filesystems is %d bytes.\n"),
1850 XFS_MIN_CRC_BLOCKSIZE
);
1857 * Grab log sector size and validate.
1859 * XXX: should we probe sector size on external log device rather than using
1860 * the data device sector size?
1863 validate_log_sectorsize(
1864 struct mkfs_params
*cfg
,
1865 struct cli_params
*cli
,
1866 struct mkfs_default_params
*dft
)
1869 if (cli
->loginternal
&& cli
->lsectorsize
&&
1870 cli
->lsectorsize
!= cfg
->sectorsize
) {
1872 _("Can't change sector size on internal log!\n"));
1876 if (cli
->lsectorsize
)
1877 cfg
->lsectorsize
= cli
->lsectorsize
;
1878 else if (cli
->loginternal
)
1879 cfg
->lsectorsize
= cfg
->sectorsize
;
1881 cfg
->lsectorsize
= dft
->sectorsize
;
1882 cfg
->lsectorlog
= libxfs_highbit32(cfg
->lsectorsize
);
1884 if (cfg
->lsectorsize
< XFS_MIN_SECTORSIZE
||
1885 cfg
->lsectorsize
> XFS_MAX_SECTORSIZE
||
1886 cfg
->lsectorsize
> cfg
->blocksize
) {
1887 fprintf(stderr
, _("illegal log sector size %d\n"),
1891 if (cfg
->lsectorsize
> XFS_MIN_SECTORSIZE
) {
1892 if (cli
->sb_feat
.log_version
< 2) {
1893 /* user specified non-default log version */
1895 _("Version 1 logs do not support sector size %d\n"),
1901 /* if lsu or lsunit was specified, automatically use v2 logs */
1902 if ((cli_opt_set(&lopts
, L_SU
) || cli_opt_set(&lopts
, L_SUNIT
)) &&
1903 cli
->sb_feat
.log_version
== 1) {
1905 _("log stripe unit specified, using v2 logs\n"));
1906 cli
->sb_feat
.log_version
= 2;
1912 * Check that the incoming features make sense. The CLI structure was
1913 * initialised with the default values before parsing, so we can just
1914 * check it and copy it straight across to the cfg structure if it
1918 validate_sb_features(
1919 struct mkfs_params
*cfg
,
1920 struct cli_params
*cli
)
1923 * Now we have blocks and sector sizes set up, check parameters that are
1924 * no longer optional for CRC enabled filesystems. Catch them up front
1925 * here before doing anything else.
1927 if (cli
->sb_feat
.crcs_enabled
) {
1928 /* minimum inode size is 512 bytes, rest checked later */
1929 if (cli
->inodesize
&&
1930 cli
->inodesize
< (1 << XFS_DINODE_DFL_CRC_LOG
)) {
1932 _("Minimum inode size for CRCs is %d bytes\n"),
1933 1 << XFS_DINODE_DFL_CRC_LOG
);
1937 /* inodes always aligned */
1938 if (!cli
->sb_feat
.inode_align
) {
1940 _("Inodes always aligned for CRC enabled filesytems\n"));
1944 /* lazy sb counters always on */
1945 if (!cli
->sb_feat
.lazy_sb_counters
) {
1947 _("Lazy superblock counted always enabled for CRC enabled filesytems\n"));
1951 /* version 2 logs always on */
1952 if (cli
->sb_feat
.log_version
!= 2) {
1954 _("V2 logs always enabled for CRC enabled filesytems\n"));
1958 /* attr2 always on */
1959 if (cli
->sb_feat
.attr_version
!= 2) {
1961 _("V2 attribute format always enabled on CRC enabled filesytems\n"));
1965 /* 32 bit project quota always on */
1966 /* attr2 always on */
1967 if (!cli
->sb_feat
.projid32bit
) {
1969 _("32 bit Project IDs always enabled on CRC enabled filesytems\n"));
1973 /* ftype always on */
1974 if (!cli
->sb_feat
.dirftype
) {
1976 _("Directory ftype field always enabled on CRC enabled filesytems\n"));
1982 * The kernel doesn't currently support crc=0,finobt=1
1983 * filesystems. If crcs are not enabled and the user has not
1984 * explicitly turned finobt on, then silently turn it off to
1985 * avoid an unnecessary warning.
1986 * If the user explicitly tried to use crc=0,finobt=1,
1987 * then issue an error.
1988 * The same is also for sparse inodes.
1990 if (cli
->sb_feat
.finobt
&& cli_opt_set(&mopts
, M_FINOBT
)) {
1992 _("finobt not supported without CRC support\n"));
1995 cli
->sb_feat
.finobt
= false;
1997 if (cli
->sb_feat
.spinodes
) {
1999 _("sparse inodes not supported without CRC support\n"));
2002 cli
->sb_feat
.spinodes
= false;
2004 if (cli
->sb_feat
.rmapbt
) {
2006 _("rmapbt not supported without CRC support\n"));
2009 cli
->sb_feat
.rmapbt
= false;
2011 if (cli
->sb_feat
.reflink
) {
2013 _("reflink not supported without CRC support\n"));
2016 cli
->sb_feat
.reflink
= false;
2019 if ((cli
->fsx
.fsx_xflags
& FS_XFLAG_COWEXTSIZE
) &&
2020 !cli
->sb_feat
.reflink
) {
2022 _("cowextsize not supported without reflink support\n"));
2026 if (cli
->sb_feat
.rmapbt
&& cli
->xi
->rtname
) {
2028 _("rmapbt not supported with realtime devices\n"));
2030 cli
->sb_feat
.rmapbt
= false;
2034 * Copy features across to config structure now.
2036 cfg
->sb_feat
= cli
->sb_feat
;
2037 if (!platform_uuid_is_null(&cli
->uuid
))
2038 platform_uuid_copy(&cfg
->uuid
, &cli
->uuid
);
2042 validate_dirblocksize(
2043 struct mkfs_params
*cfg
,
2044 struct cli_params
*cli
)
2047 if (cli
->dirblocksize
)
2048 cfg
->dirblocksize
= getnum(cli
->dirblocksize
, &nopts
, N_SIZE
);
2050 if (cfg
->dirblocksize
) {
2051 if (cfg
->dirblocksize
< cfg
->blocksize
||
2052 cfg
->dirblocksize
> XFS_MAX_BLOCKSIZE
) {
2053 fprintf(stderr
, _("illegal directory block size %d\n"),
2057 cfg
->dirblocklog
= libxfs_highbit32(cfg
->dirblocksize
);
2061 /* use default size based on current block size */
2062 if (cfg
->blocksize
< (1 << XFS_MIN_REC_DIRSIZE
))
2063 cfg
->dirblocklog
= XFS_MIN_REC_DIRSIZE
;
2065 cfg
->dirblocklog
= cfg
->blocklog
;
2066 cfg
->dirblocksize
= 1 << cfg
->dirblocklog
;
2071 struct mkfs_params
*cfg
,
2072 struct cli_params
*cli
)
2076 cfg
->inodelog
= cfg
->blocklog
- libxfs_highbit32(cli
->inopblock
);
2077 else if (cli
->inodesize
)
2078 cfg
->inodelog
= libxfs_highbit32(cli
->inodesize
);
2079 else if (cfg
->sb_feat
.crcs_enabled
)
2080 cfg
->inodelog
= XFS_DINODE_DFL_CRC_LOG
;
2082 cfg
->inodelog
= XFS_DINODE_DFL_LOG
;
2084 cfg
->inodesize
= 1 << cfg
->inodelog
;
2085 cfg
->inopblock
= cfg
->blocksize
/ cfg
->inodesize
;
2087 /* input parsing has already validated non-crc inode size range */
2088 if (cfg
->sb_feat
.crcs_enabled
&&
2089 cfg
->inodelog
< XFS_DINODE_DFL_CRC_LOG
) {
2091 _("Minimum inode size for CRCs is %d bytes\n"),
2092 1 << XFS_DINODE_DFL_CRC_LOG
);
2096 if (cfg
->inodesize
> cfg
->blocksize
/ XFS_MIN_INODE_PERBLOCK
||
2097 cfg
->inopblock
< XFS_MIN_INODE_PERBLOCK
||
2098 cfg
->inodesize
< XFS_DINODE_MIN_SIZE
||
2099 cfg
->inodesize
> XFS_DINODE_MAX_SIZE
) {
2102 fprintf(stderr
, _("illegal inode size %d\n"), cfg
->inodesize
);
2103 maxsz
= MIN(cfg
->blocksize
/ XFS_MIN_INODE_PERBLOCK
,
2104 XFS_DINODE_MAX_SIZE
);
2105 if (XFS_DINODE_MIN_SIZE
== maxsz
)
2107 _("allowable inode size with %d byte blocks is %d\n"),
2108 cfg
->blocksize
, XFS_DINODE_MIN_SIZE
);
2111 _("allowable inode size with %d byte blocks is between %d and %d\n"),
2112 cfg
->blocksize
, XFS_DINODE_MIN_SIZE
, maxsz
);
2117 static xfs_rfsblock_t
2120 struct mkfs_params
*cfg
,
2121 struct opt_params
*opts
,
2126 xfs_rfsblock_t dblocks
;
2131 dbytes
= getnum(size
, opts
, sizeopt
);
2132 if (dbytes
% XFS_MIN_BLOCKSIZE
) {
2134 _("illegal %s length %lld, not a multiple of %d\n"),
2135 type
, (long long)dbytes
, XFS_MIN_BLOCKSIZE
);
2138 dblocks
= (xfs_rfsblock_t
)(dbytes
>> cfg
->blocklog
);
2139 if (dbytes
% cfg
->blocksize
) {
2141 _("warning: %s length %lld not a multiple of %d, truncated to %lld\n"),
2142 type
, (long long)dbytes
, cfg
->blocksize
,
2143 (long long)(dblocks
<< cfg
->blocklog
));
2150 struct mkfs_params
*cfg
,
2151 struct cli_params
*cli
,
2152 struct fs_topology
*ft
)
2154 uint64_t rtextbytes
;
2157 * If specified, check rt extent size against its constraints.
2159 if (cli
->rtextsize
) {
2161 rtextbytes
= getnum(cli
->rtextsize
, &ropts
, R_EXTSIZE
);
2162 if (rtextbytes
% cfg
->blocksize
) {
2164 _("illegal rt extent size %lld, not a multiple of %d\n"),
2165 (long long)rtextbytes
, cfg
->blocksize
);
2168 cfg
->rtextblocks
= (xfs_extlen_t
)(rtextbytes
>> cfg
->blocklog
);
2171 * If realtime extsize has not been specified by the user,
2172 * and the underlying volume is striped, then set rtextblocks
2173 * to the stripe width.
2177 if (!cfg
->sb_feat
.nortalign
&& !cli
->xi
->risfile
&&
2178 !(!cli
->rtsize
&& cli
->xi
->disfile
))
2179 rswidth
= ft
->rtswidth
;
2183 /* check that rswidth is a multiple of fs blocksize */
2184 if (!cfg
->sb_feat
.nortalign
&& rswidth
&&
2185 !(BBTOB(rswidth
) % cfg
->blocksize
)) {
2186 rswidth
= DTOBT(rswidth
, cfg
->blocklog
);
2187 rtextbytes
= rswidth
<< cfg
->blocklog
;
2188 if (rtextbytes
> XFS_MIN_RTEXTSIZE
&&
2189 rtextbytes
<= XFS_MAX_RTEXTSIZE
) {
2190 cfg
->rtextblocks
= rswidth
;
2193 if (!cfg
->rtextblocks
) {
2194 cfg
->rtextblocks
= (cfg
->blocksize
< XFS_MIN_RTEXTSIZE
)
2195 ? XFS_MIN_RTEXTSIZE
>> cfg
->blocklog
2199 ASSERT(cfg
->rtextblocks
);
2203 * Validate the configured stripe geometry, or is none is specified, pull
2204 * the configuration from the underlying device.
2206 * CLI parameters come in as different units, go out as filesystem blocks.
2209 calc_stripe_factors(
2210 struct mkfs_params
*cfg
,
2211 struct cli_params
*cli
,
2212 struct fs_topology
*ft
)
2214 long long int big_dswidth
;
2221 bool use_dev
= false;
2223 if (cli_opt_set(&dopts
, D_SUNIT
))
2224 dsunit
= cli
->dsunit
;
2225 if (cli_opt_set(&dopts
, D_SWIDTH
))
2226 dswidth
= cli
->dswidth
;
2228 if (cli_opt_set(&dopts
, D_SU
))
2229 dsu
= getnum(cli
->dsu
, &dopts
, D_SU
);
2230 if (cli_opt_set(&dopts
, D_SW
))
2233 /* data sunit/swidth options */
2234 if ((dsunit
&& !dswidth
) || (!dsunit
&& dswidth
)) {
2236 _("both data sunit and data swidth options must be specified\n"));
2240 /* convert dsu/dsw to dsunit/dswidth and use them from now on */
2242 if ((dsu
&& !dsw
) || (!dsu
&& dsw
)) {
2244 _("both data su and data sw options must be specified\n"));
2248 if (dsu
% cfg
->sectorsize
) {
2250 _("data su must be a multiple of the sector size (%d)\n"), cfg
->sectorsize
);
2254 dsunit
= (int)BTOBBT(dsu
);
2255 big_dswidth
= (long long int)dsunit
* dsw
;
2256 if (big_dswidth
> INT_MAX
) {
2258 _("data stripe width (%lld) is too large of a multiple of the data stripe unit (%d)\n"),
2259 big_dswidth
, dsunit
);
2262 dswidth
= big_dswidth
;
2265 if (dsunit
&& (dswidth
% dsunit
!= 0)) {
2267 _("data stripe width (%d) must be a multiple of the data stripe unit (%d)\n"),
2272 /* If sunit & swidth were manually specified as 0, same as noalign */
2273 if ((cli_opt_set(&dopts
, D_SUNIT
) || cli_opt_set(&dopts
, D_SU
)) &&
2274 !dsunit
&& !dswidth
)
2275 cfg
->sb_feat
.nodalign
= true;
2277 /* if we are not using alignment, don't apply device defaults */
2278 if (cfg
->sb_feat
.nodalign
) {
2284 /* if no stripe config set, use the device default */
2286 dsunit
= ft
->dsunit
;
2287 dswidth
= ft
->dswidth
;
2290 /* check and warn is alignment is sub-optimal */
2291 if (ft
->dsunit
&& ft
->dsunit
!= dsunit
) {
2293 _("%s: Specified data stripe unit %d is not the same as the volume stripe unit %d\n"),
2294 progname
, dsunit
, ft
->dsunit
);
2296 if (ft
->dswidth
&& ft
->dswidth
!= dswidth
) {
2298 _("%s: Specified data stripe width %d is not the same as the volume stripe width %d\n"),
2299 progname
, dswidth
, ft
->dswidth
);
2304 * now we have our stripe config, check it's a multiple of block
2307 if ((BBTOB(dsunit
) % cfg
->blocksize
) ||
2308 (BBTOB(dswidth
) % cfg
->blocksize
)) {
2310 * If we are using device defaults, just clear them and we're
2311 * good to go. Otherwise bail out with an error.
2315 _("%s: Stripe unit(%d) or stripe width(%d) is not a multiple of the block size(%d)\n"),
2316 progname
, BBTOB(dsunit
), BBTOB(dswidth
),
2322 cfg
->sb_feat
.nodalign
= true;
2325 /* convert from 512 byte blocks to fs blocksize */
2326 cfg
->dsunit
= DTOBT(dsunit
, cfg
->blocklog
);
2327 cfg
->dswidth
= DTOBT(dswidth
, cfg
->blocklog
);
2330 /* log sunit options */
2331 if (cli_opt_set(&lopts
, L_SUNIT
))
2332 lsunit
= cli
->lsunit
;
2333 else if (cli_opt_set(&lopts
, L_SU
))
2334 lsu
= getnum(cli
->lsu
, &lopts
, L_SU
);
2335 else if (cfg
->lsectorsize
> XLOG_HEADER_SIZE
)
2336 lsu
= cfg
->blocksize
; /* lsunit matches filesystem block size */
2339 /* verify if lsu is a multiple block size */
2340 if (lsu
% cfg
->blocksize
!= 0) {
2342 _("log stripe unit (%d) must be a multiple of the block size (%d)\n"),
2343 lsu
, cfg
->blocksize
);
2346 lsunit
= (int)BTOBBT(lsu
);
2348 if (BBTOB(lsunit
) % cfg
->blocksize
!= 0) {
2350 _("log stripe unit (%d) must be a multiple of the block size (%d)\n"),
2351 BBTOB(lsunit
), cfg
->blocksize
);
2356 * check that log sunit is modulo fsblksize or default it to dsunit.
2359 /* convert from 512 byte blocks to fs blocks */
2360 cfg
->lsunit
= DTOBT(lsunit
, cfg
->blocklog
);
2361 } else if (cfg
->sb_feat
.log_version
== 2 &&
2362 cfg
->loginternal
&& cfg
->dsunit
) {
2363 /* lsunit and dsunit now in fs blocks */
2364 cfg
->lsunit
= cfg
->dsunit
;
2367 if (cfg
->sb_feat
.log_version
== 2 &&
2368 cfg
->lsunit
* cfg
->blocksize
> 256 * 1024) {
2369 /* Warn only if specified on commandline */
2370 if (cli
->lsu
|| cli
->lsunit
!= -1) {
2372 _("log stripe unit (%d bytes) is too large (maximum is 256KiB)\n"
2373 "log stripe unit adjusted to 32KiB\n"),
2374 (cfg
->lsunit
* cfg
->blocksize
));
2376 /* XXX: 64k block size? */
2377 cfg
->lsunit
= (32 * 1024) / cfg
->blocksize
;
2384 struct mkfs_params
*cfg
,
2385 struct libxfs_xinit
*xi
,
2388 uint64_t sector_mask
;
2391 * Initialize. This will open the log and rt devices as well.
2393 xi
->setblksize
= cfg
->sectorsize
;
2394 if (!libxfs_init(xi
))
2397 fprintf(stderr
, _("no device name given in argument list\n"));
2402 * Ok, Linux only has a 1024-byte resolution on device _size_,
2403 * and the sizes below are in basic 512-byte blocks,
2404 * so if we have (size % 2), on any partition, we can't get
2405 * to the last 512 bytes. The same issue exists for larger
2406 * sector sizes - we cannot write past the last sector.
2408 * So, we reduce the size (in basic blocks) to a perfect
2409 * multiple of the sector size, or 1024, whichever is larger.
2411 sector_mask
= (uint64_t)-1 << (MAX(cfg
->sectorlog
, 10) - BBSHIFT
);
2412 xi
->dsize
&= sector_mask
;
2413 xi
->rtsize
&= sector_mask
;
2414 xi
->logBBsize
&= (uint64_t)-1 << (MAX(cfg
->lsectorlog
, 10) - BBSHIFT
);
2421 discard_blocks(xi
->ddev
, xi
->dsize
);
2422 if (xi
->rtdev
&& !xi
->risfile
)
2423 discard_blocks(xi
->rtdev
, xi
->rtsize
);
2424 if (xi
->logdev
&& xi
->logdev
!= xi
->ddev
&& !xi
->lisfile
)
2425 discard_blocks(xi
->logdev
, xi
->logBBsize
);
2430 struct mkfs_params
*cfg
,
2431 struct cli_params
*cli
)
2433 struct libxfs_xinit
*xi
= cli
->xi
;
2437 * if the device is a file, we can't validate the size here.
2438 * Instead, the file will be truncated to the correct length
2439 * later on. if it's not a file, we've got a dud device.
2442 fprintf(stderr
, _("can't get size of data subvolume\n"));
2445 ASSERT(cfg
->dblocks
);
2446 } else if (cfg
->dblocks
) {
2447 /* check the size fits into the underlying device */
2448 if (cfg
->dblocks
> DTOBT(xi
->dsize
, cfg
->blocklog
)) {
2450 _("size %s specified for data subvolume is too large, maximum is %lld blocks\n"),
2452 (long long)DTOBT(xi
->dsize
, cfg
->blocklog
));
2456 /* no user size, so use the full block device */
2457 cfg
->dblocks
= DTOBT(xi
->dsize
, cfg
->blocklog
);
2460 if (cfg
->dblocks
< XFS_MIN_DATA_BLOCKS
) {
2462 _("size %lld of data subvolume is too small, minimum %d blocks\n"),
2463 (long long)cfg
->dblocks
, XFS_MIN_DATA_BLOCKS
);
2467 if (xi
->dbsize
> cfg
->sectorsize
) {
2469 "Warning: the data subvolume sector size %u is less than the sector size \n\
2470 reported by the device (%u).\n"),
2471 cfg
->sectorsize
, xi
->dbsize
);
2476 * This is more complex than it needs to be because we still support volume
2477 * based external logs. They are only discovered *after* the devices have been
2478 * opened, hence the crazy "is this really an internal log" checks here.
2482 struct mkfs_params
*cfg
,
2483 struct cli_params
*cli
,
2486 struct libxfs_xinit
*xi
= cli
->xi
;
2490 /* check for volume log first */
2491 if (cli
->loginternal
&& xi
->volname
&& xi
->logdev
) {
2492 *devname
= _("volume log");
2493 cfg
->loginternal
= false;
2495 cfg
->loginternal
= cli
->loginternal
;
2497 /* now run device checks */
2498 if (cfg
->loginternal
) {
2501 _("can't have both external and internal logs\n"));
2506 * if no sector size has been specified on the command line,
2507 * use what has been configured and validated for the data
2510 if (!cli
->lsectorsize
) {
2511 cfg
->lsectorsize
= cfg
->sectorsize
;
2512 cfg
->lsectorlog
= cfg
->sectorlog
;
2515 if (cfg
->sectorsize
!= cfg
->lsectorsize
) {
2517 _("data and log sector sizes must be equal for internal logs\n"));
2520 if (cli
->logsize
&& cfg
->logblocks
>= cfg
->dblocks
) {
2522 _("log size %lld too large for internal log\n"),
2523 (long long)cfg
->logblocks
);
2526 *devname
= _("internal log");
2530 /* External/log subvolume checks */
2532 *devname
= xi
->logname
;
2533 if (!*devname
|| !xi
->logdev
) {
2534 fprintf(stderr
, _("no log subvolume or external log.\n"));
2538 if (!cfg
->logblocks
) {
2539 if (xi
->logBBsize
== 0) {
2541 _("unable to get size of the log subvolume.\n"));
2544 cfg
->logblocks
= DTOBT(xi
->logBBsize
, cfg
->blocklog
);
2545 } else if (cfg
->logblocks
> DTOBT(xi
->logBBsize
, cfg
->blocklog
)) {
2547 _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
2549 (long long)DTOBT(xi
->logBBsize
, cfg
->blocklog
));
2553 if (xi
->lbsize
> cfg
->lsectorsize
) {
2555 "Warning: the log subvolume sector size %u is less than the sector size\n\
2556 reported by the device (%u).\n"),
2557 cfg
->lsectorsize
, xi
->lbsize
);
2563 struct mkfs_params
*cfg
,
2564 struct cli_params
*cli
,
2567 struct libxfs_xinit
*xi
= cli
->xi
;
2574 _("size specified for non-existent rt subvolume\n"));
2578 *devname
= _("none");
2581 cfg
->rtbmblocks
= 0;
2585 fprintf(stderr
, _("Invalid zero length rt subvolume found\n"));
2591 *devname
= _("volume rt");
2593 *devname
= xi
->rtname
;
2596 if (cfg
->rtblocks
> DTOBT(xi
->rtsize
, cfg
->blocklog
)) {
2598 _("size %s specified for rt subvolume is too large, maxi->um is %lld blocks\n"),
2600 (long long)DTOBT(xi
->rtsize
, cfg
->blocklog
));
2603 if (xi
->rtbsize
> cfg
->sectorsize
) {
2605 "Warning: the realtime subvolume sector size %u is less than the sector size\n\
2606 reported by the device (%u).\n"),
2607 cfg
->sectorsize
, xi
->rtbsize
);
2610 /* grab volume size */
2611 cfg
->rtblocks
= DTOBT(xi
->rtsize
, cfg
->blocklog
);
2614 cfg
->rtextents
= cfg
->rtblocks
/ cfg
->rtextblocks
;
2615 cfg
->rtbmblocks
= (xfs_extlen_t
)howmany(cfg
->rtextents
,
2616 NBBY
* cfg
->blocksize
);
2620 calculate_initial_ag_geometry(
2621 struct mkfs_params
*cfg
,
2622 struct cli_params
*cli
)
2624 if (cli
->agsize
) { /* User-specified AG size */
2625 cfg
->agsize
= getnum(cli
->agsize
, &dopts
, D_AGSIZE
);
2628 * Check specified agsize is a multiple of blocksize.
2630 if (cfg
->agsize
% cfg
->blocksize
) {
2632 _("agsize (%s) not a multiple of fs blk size (%d)\n"),
2633 cli
->agsize
, cfg
->blocksize
);
2636 cfg
->agsize
/= cfg
->blocksize
;
2637 cfg
->agcount
= cfg
->dblocks
/ cfg
->agsize
+
2638 (cfg
->dblocks
% cfg
->agsize
!= 0);
2640 } else if (cli
->agcount
) { /* User-specified AG count */
2641 cfg
->agcount
= cli
->agcount
;
2642 cfg
->agsize
= cfg
->dblocks
/ cfg
->agcount
+
2643 (cfg
->dblocks
% cfg
->agcount
!= 0);
2645 calc_default_ag_geometry(cfg
->blocklog
, cfg
->dblocks
,
2646 cfg
->dsunit
, &cfg
->agsize
,
2652 * Align the AG size to stripe geometry. If this fails and we are using
2653 * discovered stripe geometry, tell the caller to clear the stripe geometry.
2654 * Otherwise, set the aligned geometry (valid or invalid!) so that the
2655 * validation call will fail and exit.
2659 struct mkfs_params
*cfg
)
2661 uint64_t tmp_agsize
;
2662 int dsunit
= cfg
->dsunit
;
2668 * agsize is not a multiple of dsunit
2670 if ((cfg
->agsize
% dsunit
) != 0) {
2672 * Round up to stripe unit boundary. Also make sure
2673 * that agsize is still larger than
2674 * XFS_AG_MIN_BLOCKS(blocklog)
2676 tmp_agsize
= ((cfg
->agsize
+ dsunit
- 1) / dsunit
) * dsunit
;
2678 * Round down to stripe unit boundary if rounding up
2679 * created an AG size that is larger than the AG max.
2681 if (tmp_agsize
> XFS_AG_MAX_BLOCKS(cfg
->blocklog
))
2682 tmp_agsize
= (cfg
->agsize
/ dsunit
) * dsunit
;
2684 if (tmp_agsize
< XFS_AG_MIN_BLOCKS(cfg
->blocklog
) &&
2685 tmp_agsize
> XFS_AG_MAX_BLOCKS(cfg
->blocklog
)) {
2688 * If the AG size is invalid and we are using device
2689 * probed stripe alignment, just clear the alignment
2692 if (!cli_opt_set(&dopts
, D_SUNIT
) &&
2693 !cli_opt_set(&dopts
, D_SU
)) {
2699 * set the agsize to the invalid value so the following
2700 * validation of the ag will fail and print a nice error
2703 cfg
->agsize
= tmp_agsize
;
2707 /* update geometry to be stripe unit aligned */
2708 cfg
->agsize
= tmp_agsize
;
2709 if (!cli_opt_set(&dopts
, D_AGCOUNT
))
2710 cfg
->agcount
= cfg
->dblocks
/ cfg
->agsize
+
2711 (cfg
->dblocks
% cfg
->agsize
!= 0);
2712 if (cli_opt_set(&dopts
, D_AGSIZE
))
2714 _("agsize rounded to %lld, sunit = %d\n"),
2715 (long long)cfg
->agsize
, dsunit
);
2718 if ((cfg
->agsize
% cfg
->dswidth
) == 0 &&
2719 cfg
->dswidth
!= cfg
->dsunit
&&
2722 if (cli_opt_set(&dopts
, D_AGCOUNT
) ||
2723 cli_opt_set(&dopts
, D_AGSIZE
)) {
2725 "Warning: AG size is a multiple of stripe width. This can cause performance\n\
2726 problems by aligning all AGs on the same disk. To avoid this, run mkfs with\n\
2727 an AG size that is one stripe unit smaller or larger, for example %llu.\n"),
2728 (unsigned long long)cfg
->agsize
- dsunit
);
2733 * This is a non-optimal configuration because all AGs start on
2734 * the same disk in the stripe. Changing the AG size by one
2735 * sunit will guarantee that this does not happen.
2737 tmp_agsize
= cfg
->agsize
- dsunit
;
2738 if (tmp_agsize
< XFS_AG_MIN_BLOCKS(cfg
->blocklog
)) {
2739 tmp_agsize
= cfg
->agsize
+ dsunit
;
2740 if (cfg
->dblocks
< cfg
->agsize
) {
2741 /* oh well, nothing to do */
2742 tmp_agsize
= cfg
->agsize
;
2746 cfg
->agsize
= tmp_agsize
;
2747 cfg
->agcount
= cfg
->dblocks
/ cfg
->agsize
+
2748 (cfg
->dblocks
% cfg
->agsize
!= 0);
2753 * If the last AG is too small, reduce the filesystem size
2754 * and drop the blocks.
2756 if (cfg
->dblocks
% cfg
->agsize
!= 0 &&
2757 (cfg
->dblocks
% cfg
->agsize
< XFS_AG_MIN_BLOCKS(cfg
->blocklog
))) {
2758 ASSERT(!cli_opt_set(&dopts
, D_AGCOUNT
));
2759 cfg
->dblocks
= (xfs_rfsblock_t
)((cfg
->agcount
- 1) * cfg
->agsize
);
2761 ASSERT(cfg
->agcount
!= 0);
2764 validate_ag_geometry(cfg
->blocklog
, cfg
->dblocks
,
2765 cfg
->agsize
, cfg
->agcount
);
2770 struct mkfs_params
*cfg
,
2771 struct cli_params
*cli
)
2773 cfg
->imaxpct
= cli
->imaxpct
;
2778 * This returns the % of the disk space that is used for
2779 * inodes, it changes relatively to the FS size:
2780 * - over 50 TB, use 1%,
2781 * - 1TB - 50 TB, use 5%,
2782 * - under 1 TB, use XFS_DFL_IMAXIMUM_PCT (25%).
2785 if (cfg
->dblocks
< TERABYTES(1, cfg
->blocklog
))
2786 cfg
->imaxpct
= XFS_DFL_IMAXIMUM_PCT
;
2787 else if (cfg
->dblocks
< TERABYTES(50, cfg
->blocklog
))
2794 * Set up the initial state of the superblock so we can start using the
2795 * libxfs geometry macros.
2799 struct mkfs_params
*cfg
,
2802 struct sb_feat_args
*fp
= &cfg
->sb_feat
;
2804 sbp
->sb_versionnum
= XFS_DFL_SB_VERSION_BITS
;
2805 if (fp
->crcs_enabled
)
2806 sbp
->sb_versionnum
|= XFS_SB_VERSION_5
;
2808 sbp
->sb_versionnum
|= XFS_SB_VERSION_4
;
2810 if (fp
->inode_align
) {
2811 int cluster_size
= XFS_INODE_BIG_CLUSTER_SIZE
;
2813 sbp
->sb_versionnum
|= XFS_SB_VERSION_ALIGNBIT
;
2814 if (cfg
->sb_feat
.crcs_enabled
)
2815 cluster_size
*= cfg
->inodesize
/ XFS_DINODE_MIN_SIZE
;
2816 sbp
->sb_inoalignmt
= cluster_size
>> cfg
->blocklog
;
2818 sbp
->sb_inoalignmt
= 0;
2821 sbp
->sb_versionnum
|= XFS_SB_VERSION_DALIGNBIT
;
2822 if (fp
->log_version
== 2)
2823 sbp
->sb_versionnum
|= XFS_SB_VERSION_LOGV2BIT
;
2824 if (fp
->attr_version
== 1)
2825 sbp
->sb_versionnum
|= XFS_SB_VERSION_ATTRBIT
;
2827 sbp
->sb_versionnum
|= XFS_SB_VERSION_BORGBIT
;
2829 if (cfg
->sectorsize
> BBSIZE
|| cfg
->lsectorsize
> BBSIZE
) {
2830 sbp
->sb_versionnum
|= XFS_SB_VERSION_SECTORBIT
;
2831 sbp
->sb_logsectlog
= (uint8_t)cfg
->lsectorlog
;
2832 sbp
->sb_logsectsize
= (uint16_t)cfg
->lsectorsize
;
2834 sbp
->sb_logsectlog
= 0;
2835 sbp
->sb_logsectsize
= 0;
2838 sbp
->sb_features2
= 0;
2839 if (fp
->lazy_sb_counters
)
2840 sbp
->sb_features2
|= XFS_SB_VERSION2_LAZYSBCOUNTBIT
;
2841 if (fp
->projid32bit
)
2842 sbp
->sb_features2
|= XFS_SB_VERSION2_PROJID32BIT
;
2843 if (fp
->parent_pointers
)
2844 sbp
->sb_features2
|= XFS_SB_VERSION2_PARENTBIT
;
2845 if (fp
->crcs_enabled
)
2846 sbp
->sb_features2
|= XFS_SB_VERSION2_CRCBIT
;
2847 if (fp
->attr_version
== 2)
2848 sbp
->sb_features2
|= XFS_SB_VERSION2_ATTR2BIT
;
2850 /* v5 superblocks have their own feature bit for dirftype */
2851 if (fp
->dirftype
&& !fp
->crcs_enabled
)
2852 sbp
->sb_features2
|= XFS_SB_VERSION2_FTYPE
;
2854 /* update whether extended features are in use */
2855 if (sbp
->sb_features2
!= 0)
2856 sbp
->sb_versionnum
|= XFS_SB_VERSION_MOREBITSBIT
;
2859 * Due to a structure alignment issue, sb_features2 ended up in one
2860 * of two locations, the second "incorrect" location represented by
2861 * the sb_bad_features2 field. To avoid older kernels mounting
2862 * filesystems they shouldn't, set both field to the same value.
2864 sbp
->sb_bad_features2
= sbp
->sb_features2
;
2866 if (!fp
->crcs_enabled
)
2869 /* default features for v5 filesystems */
2870 sbp
->sb_features_compat
= 0;
2871 sbp
->sb_features_ro_compat
= 0;
2872 sbp
->sb_features_incompat
= XFS_SB_FEAT_INCOMPAT_FTYPE
;
2873 sbp
->sb_features_log_incompat
= 0;
2876 sbp
->sb_features_ro_compat
= XFS_SB_FEAT_RO_COMPAT_FINOBT
;
2878 sbp
->sb_features_ro_compat
|= XFS_SB_FEAT_RO_COMPAT_RMAPBT
;
2880 sbp
->sb_features_ro_compat
|= XFS_SB_FEAT_RO_COMPAT_REFLINK
;
2883 * Sparse inode chunk support has two main inode alignment requirements.
2884 * First, sparse chunk alignment must match the cluster size. Second,
2885 * full chunk alignment must match the inode chunk size.
2887 * Copy the already calculated/scaled inoalignmt to spino_align and
2888 * update the former to the full inode chunk size.
2891 sbp
->sb_spino_align
= sbp
->sb_inoalignmt
;
2892 sbp
->sb_inoalignmt
= XFS_INODES_PER_CHUNK
*
2893 cfg
->inodesize
>> cfg
->blocklog
;
2894 sbp
->sb_features_incompat
|= XFS_SB_FEAT_INCOMPAT_SPINODES
;
2900 * Make sure that the log size is a multiple of the stripe unit
2904 struct mkfs_params
*cfg
,
2907 uint64_t tmp_logblocks
;
2909 /* nothing to do if it's already aligned. */
2910 if ((cfg
->logblocks
% sunit
) == 0)
2913 if (cli_opt_set(&lopts
, L_SIZE
)) {
2915 _("log size %lld is not a multiple of the log stripe unit %d\n"),
2916 (long long) cfg
->logblocks
, sunit
);
2920 tmp_logblocks
= ((cfg
->logblocks
+ (sunit
- 1)) / sunit
) * sunit
;
2922 /* If the log is too large, round down instead of round up */
2923 if ((tmp_logblocks
> XFS_MAX_LOG_BLOCKS
) ||
2924 ((tmp_logblocks
<< cfg
->blocklog
) > XFS_MAX_LOG_BYTES
)) {
2925 tmp_logblocks
= (cfg
->logblocks
/ sunit
) * sunit
;
2927 cfg
->logblocks
= tmp_logblocks
;
2931 * Make sure that the internal log is correctly aligned to the specified
2936 struct mkfs_params
*cfg
,
2937 struct xfs_mount
*mp
,
2940 /* round up log start if necessary */
2941 if ((cfg
->logstart
% sunit
) != 0)
2942 cfg
->logstart
= ((cfg
->logstart
+ (sunit
- 1)) / sunit
) * sunit
;
2944 /* round up/down the log size now */
2945 align_log_size(cfg
, sunit
);
2947 /* check the aligned log still fits in an AG. */
2948 if (cfg
->logblocks
> cfg
->agsize
- XFS_FSB_TO_AGBNO(mp
, cfg
->logstart
)) {
2950 _("Due to stripe alignment, the internal log size (%lld) is too large.\n"
2951 "Must fit within an allocation group.\n"),
2952 (long long) cfg
->logblocks
);
2958 validate_log_size(uint64_t logblocks
, int blocklog
, int min_logblocks
)
2960 if (logblocks
< min_logblocks
) {
2962 _("log size %lld blocks too small, minimum size is %d blocks\n"),
2963 (long long)logblocks
, min_logblocks
);
2966 if (logblocks
> XFS_MAX_LOG_BLOCKS
) {
2968 _("log size %lld blocks too large, maximum size is %lld blocks\n"),
2969 (long long)logblocks
, XFS_MAX_LOG_BLOCKS
);
2972 if ((logblocks
<< blocklog
) > XFS_MAX_LOG_BYTES
) {
2974 _("log size %lld bytes too large, maximum size is %lld bytes\n"),
2975 (long long)(logblocks
<< blocklog
), XFS_MAX_LOG_BYTES
);
2982 struct mkfs_params
*cfg
,
2983 struct cli_params
*cli
,
2984 struct xfs_mount
*mp
)
2986 struct xfs_sb
*sbp
= &mp
->m_sb
;
2988 struct xfs_mount mount
;
2990 /* we need a temporary mount to calculate the minimum log size. */
2991 memset(&mount
, 0, sizeof(mount
));
2993 libxfs_mount(&mount
, &mp
->m_sb
, 0, 0, 0, 0);
2994 min_logblocks
= libxfs_log_calc_minimum_size(&mount
);
2995 libxfs_umount(&mount
);
2997 ASSERT(min_logblocks
);
2998 min_logblocks
= MAX(XFS_MIN_LOG_BLOCKS
, min_logblocks
);
3000 /* if we have lots of blocks, check against XFS_MIN_LOG_BYTES, too */
3001 if (!cli
->logsize
&&
3002 cfg
->dblocks
>= (1024*1024*1024) >> cfg
->blocklog
)
3003 min_logblocks
= MAX(min_logblocks
,
3004 XFS_MIN_LOG_BYTES
>> cfg
->blocklog
);
3007 * external logs will have a device and size by now, so all we have
3008 * to do is validate it against minimum size and align it.
3010 if (!cfg
->loginternal
) {
3011 if (min_logblocks
> cfg
->logblocks
) {
3013 _("external log device %lld too small, must be at least %lld blocks\n"),
3014 (long long)cfg
->logblocks
,
3015 (long long)min_logblocks
);
3021 align_log_size(cfg
, cfg
->lsunit
);
3023 validate_log_size(cfg
->logblocks
, cfg
->blocklog
, min_logblocks
);
3027 /* internal log - if no size specified, calculate automatically */
3028 if (!cfg
->logblocks
) {
3029 if (cfg
->dblocks
< GIGABYTES(1, cfg
->blocklog
)) {
3030 /* tiny filesystems get minimum sized logs. */
3031 cfg
->logblocks
= min_logblocks
;
3032 } else if (cfg
->dblocks
< GIGABYTES(16, cfg
->blocklog
)) {
3035 * For small filesystems, we want to use the
3036 * XFS_MIN_LOG_BYTES for filesystems smaller than 16G if
3037 * at all possible, ramping up to 128MB at 256GB.
3039 cfg
->logblocks
= MIN(XFS_MIN_LOG_BYTES
>> cfg
->blocklog
,
3040 min_logblocks
* XFS_DFL_LOG_FACTOR
);
3043 * With a 2GB max log size, default to maximum size
3044 * at 4TB. This keeps the same ratio from the older
3045 * max log size of 128M at 256GB fs size. IOWs,
3046 * the ratio of fs size to log size is 2048:1.
3048 cfg
->logblocks
= (cfg
->dblocks
<< cfg
->blocklog
) / 2048;
3049 cfg
->logblocks
= cfg
->logblocks
>> cfg
->blocklog
;
3052 /* Ensure the chosen size meets minimum log size requirements */
3053 cfg
->logblocks
= MAX(min_logblocks
, cfg
->logblocks
);
3056 * Make sure the log fits wholly within an AG
3058 * XXX: If agf->freeblks ends up as 0 because the log uses all
3059 * the free space, it causes the kernel all sorts of problems
3060 * with per-ag reservations. Right now just back it off one
3061 * block, but there's a whole can of worms here that needs to be
3062 * opened to decide what is the valid maximum size of a log in
3065 cfg
->logblocks
= MIN(cfg
->logblocks
,
3066 libxfs_alloc_ag_max_usable(mp
) - 1);
3068 /* and now clamp the size to the maximum supported size */
3069 cfg
->logblocks
= MIN(cfg
->logblocks
, XFS_MAX_LOG_BLOCKS
);
3070 if ((cfg
->logblocks
<< cfg
->blocklog
) > XFS_MAX_LOG_BYTES
)
3071 cfg
->logblocks
= XFS_MAX_LOG_BYTES
>> cfg
->blocklog
;
3073 validate_log_size(cfg
->logblocks
, cfg
->blocklog
, min_logblocks
);
3076 if (cfg
->logblocks
> sbp
->sb_agblocks
- libxfs_prealloc_blocks(mp
)) {
3078 _("internal log size %lld too large, must fit in allocation group\n"),
3079 (long long)cfg
->logblocks
);
3083 if (cli_opt_set(&lopts
, L_AGNUM
)) {
3084 if (cli
->logagno
>= sbp
->sb_agcount
) {
3086 _("log ag number %lld too large, must be less than %lld\n"),
3087 (long long)cli
->logagno
,
3088 (long long)sbp
->sb_agcount
);
3091 cfg
->logagno
= cli
->logagno
;
3093 cfg
->logagno
= (xfs_agnumber_t
)(sbp
->sb_agcount
/ 2);
3095 cfg
->logstart
= XFS_AGB_TO_FSB(mp
, cfg
->logagno
,
3096 libxfs_prealloc_blocks(mp
));
3099 * Align the logstart at stripe unit boundary.
3102 align_internal_log(cfg
, mp
, cfg
->lsunit
);
3103 } else if (cfg
->dsunit
) {
3104 align_internal_log(cfg
, mp
, cfg
->dsunit
);
3106 validate_log_size(cfg
->logblocks
, cfg
->blocklog
, min_logblocks
);
3110 * Set up superblock with the minimum parameters required for
3111 * the libxfs macros needed by the log sizing code to run successfully.
3112 * This includes a minimum log size calculation, so we need everything
3113 * that goes into that calculation to be setup here including feature
3117 start_superblock_setup(
3118 struct mkfs_params
*cfg
,
3119 struct xfs_mount
*mp
,
3122 sbp
->sb_magicnum
= XFS_SB_MAGIC
;
3123 sbp
->sb_sectsize
= (uint16_t)cfg
->sectorsize
;
3124 sbp
->sb_sectlog
= (uint8_t)cfg
->sectorlog
;
3125 sbp
->sb_blocksize
= cfg
->blocksize
;
3126 sbp
->sb_blocklog
= (uint8_t)cfg
->blocklog
;
3128 sbp
->sb_agblocks
= (xfs_agblock_t
)cfg
->agsize
;
3129 sbp
->sb_agblklog
= (uint8_t)log2_roundup(cfg
->agsize
);
3130 sbp
->sb_agcount
= (xfs_agnumber_t
)cfg
->agcount
;
3132 sbp
->sb_inodesize
= (uint16_t)cfg
->inodesize
;
3133 sbp
->sb_inodelog
= (uint8_t)cfg
->inodelog
;
3134 sbp
->sb_inopblock
= (uint16_t)(cfg
->blocksize
/ cfg
->inodesize
);
3135 sbp
->sb_inopblog
= (uint8_t)(cfg
->blocklog
- cfg
->inodelog
);
3137 sbp
->sb_dirblklog
= cfg
->dirblocklog
- cfg
->blocklog
;
3139 sb_set_features(cfg
, sbp
);
3142 * log stripe unit is stored in bytes on disk and cannot be zero
3145 if (cfg
->sb_feat
.log_version
== 2) {
3147 sbp
->sb_logsunit
= XFS_FSB_TO_B(mp
, cfg
->lsunit
);
3149 sbp
->sb_logsunit
= 1;
3151 sbp
->sb_logsunit
= 0;
3157 struct mkfs_params
*cfg
,
3158 struct xfs_mount
*mp
,
3161 /* Minimum needed for libxfs_prealloc_blocks() */
3162 mp
->m_blkbb_log
= sbp
->sb_blocklog
- BBSHIFT
;
3163 mp
->m_sectbb_log
= sbp
->sb_sectlog
- BBSHIFT
;
3168 struct mkfs_params
*cfg
,
3173 struct sb_feat_args
*fp
= &cfg
->sb_feat
;
3176 "meta-data=%-22s isize=%-6d agcount=%lld, agsize=%lld blks\n"
3177 " =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n"
3178 " =%-22s crc=%-8u finobt=%u, sparse=%u, rmapbt=%u, reflink=%u\n"
3179 "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
3180 " =%-22s sunit=%-6u swidth=%u blks\n"
3181 "naming =version %-14u bsize=%-6u ascii-ci=%d ftype=%d\n"
3182 "log =%-22s bsize=%-6d blocks=%lld, version=%d\n"
3183 " =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n"
3184 "realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"),
3185 dfile
, cfg
->inodesize
, (long long)cfg
->agcount
,
3186 (long long)cfg
->agsize
,
3187 "", cfg
->sectorsize
, fp
->attr_version
, fp
->projid32bit
,
3188 "", fp
->crcs_enabled
, fp
->finobt
, fp
->spinodes
, fp
->rmapbt
,
3190 "", cfg
->blocksize
, (long long)cfg
->dblocks
, cfg
->imaxpct
,
3191 "", cfg
->dsunit
, cfg
->dswidth
,
3192 fp
->dir_version
, cfg
->dirblocksize
, fp
->nci
, fp
->dirftype
,
3193 logfile
, cfg
->blocksize
, (long long)cfg
->logblocks
,
3195 "", cfg
->lsectorsize
, cfg
->lsunit
, fp
->lazy_sb_counters
,
3196 rtfile
, (int)cfg
->rtextblocks
<< cfg
->blocklog
,
3197 (long long)cfg
->rtblocks
, (long long)cfg
->rtextents
);
3201 * Format everything from the generated config into the superblock that
3202 * will be used to initialise the on-disk superblock. This is the in-memory
3203 * copy, so no need to care about endian swapping here.
3206 finish_superblock_setup(
3207 struct mkfs_params
*cfg
,
3208 struct xfs_mount
*mp
,
3212 strncpy(sbp
->sb_fname
, cfg
->label
, sizeof(sbp
->sb_fname
));
3214 sbp
->sb_dblocks
= cfg
->dblocks
;
3215 sbp
->sb_rblocks
= cfg
->rtblocks
;
3216 sbp
->sb_rextents
= cfg
->rtextents
;
3217 platform_uuid_copy(&sbp
->sb_uuid
, &cfg
->uuid
);
3218 /* Only in memory; libxfs expects this as if read from disk */
3219 platform_uuid_copy(&sbp
->sb_meta_uuid
, &cfg
->uuid
);
3220 sbp
->sb_logstart
= cfg
->logstart
;
3221 sbp
->sb_rootino
= sbp
->sb_rbmino
= sbp
->sb_rsumino
= NULLFSINO
;
3222 sbp
->sb_rextsize
= cfg
->rtextblocks
;
3223 sbp
->sb_agcount
= (xfs_agnumber_t
)cfg
->agcount
;
3224 sbp
->sb_rbmblocks
= cfg
->rtbmblocks
;
3225 sbp
->sb_logblocks
= (xfs_extlen_t
)cfg
->logblocks
;
3226 sbp
->sb_rextslog
= (uint8_t)(cfg
->rtextents
?
3227 libxfs_highbit32((unsigned int)cfg
->rtextents
) : 0);
3228 sbp
->sb_inprogress
= 1; /* mkfs is in progress */
3229 sbp
->sb_imax_pct
= cfg
->imaxpct
;
3232 sbp
->sb_fdblocks
= cfg
->dblocks
-
3233 cfg
->agcount
* libxfs_prealloc_blocks(mp
) -
3234 (cfg
->loginternal
? cfg
->logblocks
: 0);
3235 sbp
->sb_frextents
= 0; /* will do a free later */
3236 sbp
->sb_uquotino
= sbp
->sb_gquotino
= sbp
->sb_pquotino
= 0;
3238 sbp
->sb_unit
= cfg
->dsunit
;
3239 sbp
->sb_width
= cfg
->dswidth
;
3244 * Sanitise the data and log devices and prepare them so libxfs can mount the
3245 * device successfully. Also check we can access the rt device if configured.
3249 struct mkfs_params
*cfg
,
3250 struct libxfs_xinit
*xi
,
3251 struct xfs_mount
*mp
,
3255 struct xfs_buf
*buf
;
3256 int whack_blks
= BTOBB(WHACK_SIZE
);
3260 * If there's an old XFS filesystem on the device with enough intact
3261 * information that we can parse the superblock, there's enough
3262 * information on disk to confuse a future xfs_repair call. To avoid
3263 * this, whack all the old secondary superblocks that we can find.
3266 zero_old_xfs_structures(xi
, sbp
);
3269 * If the data device is a file, grow out the file to its final size if
3270 * needed so that the reads for the end of the device in the mount code
3274 xi
->dsize
* xi
->dbsize
< cfg
->dblocks
* cfg
->blocksize
) {
3275 if (ftruncate(xi
->dfd
, cfg
->dblocks
* cfg
->blocksize
) < 0) {
3277 _("%s: Growing the data section failed\n"),
3282 /* update size to be able to whack blocks correctly */
3283 xi
->dsize
= BTOBB(cfg
->dblocks
* cfg
->blocksize
);
3287 * Zero out the end to obliterate any old MD RAID (or other) metadata at
3288 * the end of the device. (MD sb is ~64k from the end, take out a wider
3291 buf
= libxfs_getbuf(mp
->m_ddev_targp
, (xi
->dsize
- whack_blks
),
3293 memset(XFS_BUF_PTR(buf
), 0, WHACK_SIZE
);
3294 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3295 libxfs_purgebuf(buf
);
3298 * Now zero out the beginning of the device, to obliterate any old
3299 * filesystem signatures out there. This should take care of
3300 * swap (somewhere around the page size), jfs (32k),
3301 * ext[2,3] and reiserfs (64k) - and hopefully all else.
3303 buf
= libxfs_getbuf(mp
->m_ddev_targp
, 0, whack_blks
);
3304 memset(XFS_BUF_PTR(buf
), 0, WHACK_SIZE
);
3305 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3306 libxfs_purgebuf(buf
);
3308 /* OK, now write the superblock... */
3309 buf
= libxfs_getbuf(mp
->m_ddev_targp
, XFS_SB_DADDR
, XFS_FSS_TO_BB(mp
, 1));
3310 buf
->b_ops
= &xfs_sb_buf_ops
;
3311 memset(XFS_BUF_PTR(buf
), 0, cfg
->sectorsize
);
3312 libxfs_sb_to_disk((void *)XFS_BUF_PTR(buf
), sbp
);
3313 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3314 libxfs_purgebuf(buf
);
3316 /* ...and zero the log.... */
3317 lsunit
= sbp
->sb_logsunit
;
3319 lsunit
= sbp
->sb_logsectsize
;
3321 libxfs_log_clear(mp
->m_logdev_targp
, NULL
,
3322 XFS_FSB_TO_DADDR(mp
, cfg
->logstart
),
3323 (xfs_extlen_t
)XFS_FSB_TO_BB(mp
, cfg
->logblocks
),
3324 &sbp
->sb_uuid
, cfg
->sb_feat
.log_version
,
3325 lsunit
, XLOG_FMT
, XLOG_INIT_CYCLE
, false);
3327 /* finally, check we can write the last block in the realtime area */
3328 if (mp
->m_rtdev_targp
->dev
&& cfg
->rtblocks
> 0) {
3329 buf
= libxfs_getbuf(mp
->m_rtdev_targp
,
3330 XFS_FSB_TO_BB(mp
, cfg
->rtblocks
- 1LL),
3331 BTOBB(cfg
->blocksize
));
3332 memset(XFS_BUF_PTR(buf
), 0, cfg
->blocksize
);
3333 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3334 libxfs_purgebuf(buf
);
3340 * XXX: this code is mostly common with the kernel growfs code.
3341 * These initialisations should be pulled into libxfs to keep the
3342 * kernel/userspace header initialisation code the same.
3345 initialise_ag_headers(
3346 struct mkfs_params
*cfg
,
3347 struct xfs_mount
*mp
,
3349 xfs_agnumber_t agno
,
3350 int *worst_freelist
)
3352 struct xfs_perag
*pag
= libxfs_perag_get(mp
, agno
);
3353 struct xfs_agfl
*agfl
;
3354 struct xfs_agf
*agf
;
3355 struct xfs_agi
*agi
;
3356 struct xfs_buf
*buf
;
3357 struct xfs_btree_block
*block
;
3358 struct xfs_alloc_rec
*arec
;
3359 struct xfs_alloc_rec
*nrec
;
3361 uint64_t agsize
= cfg
->agsize
;
3362 xfs_agblock_t agblocks
;
3363 bool is_log_ag
= false;
3366 if (cfg
->loginternal
&& agno
== cfg
->logagno
)
3372 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3373 XFS_AG_DADDR(mp
, agno
, XFS_SB_DADDR
),
3374 XFS_FSS_TO_BB(mp
, 1));
3375 buf
->b_ops
= &xfs_sb_buf_ops
;
3376 memset(XFS_BUF_PTR(buf
), 0, cfg
->sectorsize
);
3377 libxfs_sb_to_disk((void *)XFS_BUF_PTR(buf
), sbp
);
3378 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3381 * AG header block: freespace
3383 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3384 XFS_AG_DADDR(mp
, agno
, XFS_AGF_DADDR(mp
)),
3385 XFS_FSS_TO_BB(mp
, 1));
3386 buf
->b_ops
= &xfs_agf_buf_ops
;
3387 agf
= XFS_BUF_TO_AGF(buf
);
3388 memset(agf
, 0, cfg
->sectorsize
);
3389 if (agno
== cfg
->agcount
- 1)
3390 agsize
= cfg
->dblocks
- (xfs_rfsblock_t
)(agno
* agsize
);
3391 agf
->agf_magicnum
= cpu_to_be32(XFS_AGF_MAGIC
);
3392 agf
->agf_versionnum
= cpu_to_be32(XFS_AGF_VERSION
);
3393 agf
->agf_seqno
= cpu_to_be32(agno
);
3394 agf
->agf_length
= cpu_to_be32(agsize
);
3395 agf
->agf_roots
[XFS_BTNUM_BNOi
] = cpu_to_be32(XFS_BNO_BLOCK(mp
));
3396 agf
->agf_roots
[XFS_BTNUM_CNTi
] = cpu_to_be32(XFS_CNT_BLOCK(mp
));
3397 agf
->agf_levels
[XFS_BTNUM_BNOi
] = cpu_to_be32(1);
3398 agf
->agf_levels
[XFS_BTNUM_CNTi
] = cpu_to_be32(1);
3399 pag
->pagf_levels
[XFS_BTNUM_BNOi
] = 1;
3400 pag
->pagf_levels
[XFS_BTNUM_CNTi
] = 1;
3402 if (xfs_sb_version_hasrmapbt(sbp
)) {
3403 agf
->agf_roots
[XFS_BTNUM_RMAPi
] = cpu_to_be32(XFS_RMAP_BLOCK(mp
));
3404 agf
->agf_levels
[XFS_BTNUM_RMAPi
] = cpu_to_be32(1);
3405 agf
->agf_rmap_blocks
= cpu_to_be32(1);
3408 if (xfs_sb_version_hasreflink(sbp
)) {
3409 agf
->agf_refcount_root
= cpu_to_be32(libxfs_refc_block(mp
));
3410 agf
->agf_refcount_level
= cpu_to_be32(1);
3411 agf
->agf_refcount_blocks
= cpu_to_be32(1);
3414 agf
->agf_flfirst
= 0;
3415 agf
->agf_fllast
= cpu_to_be32(XFS_AGFL_SIZE(mp
) - 1);
3416 agf
->agf_flcount
= 0;
3417 agblocks
= (xfs_agblock_t
)(agsize
- libxfs_prealloc_blocks(mp
));
3418 agf
->agf_freeblks
= cpu_to_be32(agblocks
);
3419 agf
->agf_longest
= cpu_to_be32(agblocks
);
3421 if (xfs_sb_version_hascrc(sbp
))
3422 platform_uuid_copy(&agf
->agf_uuid
, &sbp
->sb_uuid
);
3425 be32_add_cpu(&agf
->agf_freeblks
, -(int64_t)cfg
->logblocks
);
3426 agf
->agf_longest
= cpu_to_be32(agsize
-
3427 XFS_FSB_TO_AGBNO(mp
, cfg
->logstart
) - cfg
->logblocks
);
3429 if (libxfs_alloc_min_freelist(mp
, pag
) > *worst_freelist
)
3430 *worst_freelist
= libxfs_alloc_min_freelist(mp
, pag
);
3431 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3434 * AG freelist header block
3436 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3437 XFS_AG_DADDR(mp
, agno
, XFS_AGFL_DADDR(mp
)),
3438 XFS_FSS_TO_BB(mp
, 1));
3439 buf
->b_ops
= &xfs_agfl_buf_ops
;
3440 agfl
= XFS_BUF_TO_AGFL(buf
);
3441 /* setting to 0xff results in initialisation to NULLAGBLOCK */
3442 memset(agfl
, 0xff, cfg
->sectorsize
);
3443 if (xfs_sb_version_hascrc(sbp
)) {
3444 agfl
->agfl_magicnum
= cpu_to_be32(XFS_AGFL_MAGIC
);
3445 agfl
->agfl_seqno
= cpu_to_be32(agno
);
3446 platform_uuid_copy(&agfl
->agfl_uuid
, &sbp
->sb_uuid
);
3447 for (bucket
= 0; bucket
< XFS_AGFL_SIZE(mp
); bucket
++)
3448 agfl
->agfl_bno
[bucket
] = cpu_to_be32(NULLAGBLOCK
);
3451 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3454 * AG header block: inodes
3456 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3457 XFS_AG_DADDR(mp
, agno
, XFS_AGI_DADDR(mp
)),
3458 XFS_FSS_TO_BB(mp
, 1));
3459 agi
= XFS_BUF_TO_AGI(buf
);
3460 buf
->b_ops
= &xfs_agi_buf_ops
;
3461 memset(agi
, 0, cfg
->sectorsize
);
3462 agi
->agi_magicnum
= cpu_to_be32(XFS_AGI_MAGIC
);
3463 agi
->agi_versionnum
= cpu_to_be32(XFS_AGI_VERSION
);
3464 agi
->agi_seqno
= cpu_to_be32(agno
);
3465 agi
->agi_length
= cpu_to_be32(agsize
);
3467 agi
->agi_root
= cpu_to_be32(XFS_IBT_BLOCK(mp
));
3468 agi
->agi_level
= cpu_to_be32(1);
3469 if (xfs_sb_version_hasfinobt(sbp
)) {
3470 agi
->agi_free_root
= cpu_to_be32(XFS_FIBT_BLOCK(mp
));
3471 agi
->agi_free_level
= cpu_to_be32(1);
3473 agi
->agi_freecount
= 0;
3474 agi
->agi_newino
= cpu_to_be32(NULLAGINO
);
3475 agi
->agi_dirino
= cpu_to_be32(NULLAGINO
);
3476 if (xfs_sb_version_hascrc(sbp
))
3477 platform_uuid_copy(&agi
->agi_uuid
, &sbp
->sb_uuid
);
3478 for (c
= 0; c
< XFS_AGI_UNLINKED_BUCKETS
; c
++)
3479 agi
->agi_unlinked
[c
] = cpu_to_be32(NULLAGINO
);
3480 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3483 * BNO btree root block
3485 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3486 XFS_AGB_TO_DADDR(mp
, agno
, XFS_BNO_BLOCK(mp
)),
3487 BTOBB(cfg
->blocksize
));
3488 buf
->b_ops
= &xfs_allocbt_buf_ops
;
3489 block
= XFS_BUF_TO_BLOCK(buf
);
3490 memset(block
, 0, cfg
->blocksize
);
3491 libxfs_btree_init_block(mp
, buf
, XFS_BTNUM_BNO
, 0, 1, agno
, 0);
3493 arec
= XFS_ALLOC_REC_ADDR(mp
, block
, 1);
3494 arec
->ar_startblock
= cpu_to_be32(libxfs_prealloc_blocks(mp
));
3496 xfs_agblock_t start
= XFS_FSB_TO_AGBNO(mp
, cfg
->logstart
);
3498 ASSERT(start
>= libxfs_prealloc_blocks(mp
));
3499 if (start
!= libxfs_prealloc_blocks(mp
)) {
3501 * Modify first record to pad stripe align of log
3503 arec
->ar_blockcount
= cpu_to_be32(start
-
3504 libxfs_prealloc_blocks(mp
));
3507 * Insert second record at start of internal log
3508 * which then gets trimmed.
3510 nrec
->ar_startblock
= cpu_to_be32(
3511 be32_to_cpu(arec
->ar_startblock
) +
3512 be32_to_cpu(arec
->ar_blockcount
));
3514 be16_add_cpu(&block
->bb_numrecs
, 1);
3517 * Change record start to after the internal log
3519 be32_add_cpu(&arec
->ar_startblock
, cfg
->logblocks
);
3522 * Calculate the record block count and check for the case where
3523 * the log might have consumed all available space in the AG. If
3524 * so, reset the record count to 0 to avoid exposure of an invalid
3525 * record start block.
3527 arec
->ar_blockcount
= cpu_to_be32(agsize
-
3528 be32_to_cpu(arec
->ar_startblock
));
3529 if (!arec
->ar_blockcount
)
3530 block
->bb_numrecs
= 0;
3532 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3535 * CNT btree root block
3537 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3538 XFS_AGB_TO_DADDR(mp
, agno
, XFS_CNT_BLOCK(mp
)),
3539 BTOBB(cfg
->blocksize
));
3540 buf
->b_ops
= &xfs_allocbt_buf_ops
;
3541 block
= XFS_BUF_TO_BLOCK(buf
);
3542 memset(block
, 0, cfg
->blocksize
);
3543 libxfs_btree_init_block(mp
, buf
, XFS_BTNUM_CNT
, 0, 1, agno
, 0);
3545 arec
= XFS_ALLOC_REC_ADDR(mp
, block
, 1);
3546 arec
->ar_startblock
= cpu_to_be32(libxfs_prealloc_blocks(mp
));
3548 xfs_agblock_t start
= XFS_FSB_TO_AGBNO(mp
, cfg
->logstart
);
3550 ASSERT(start
>= libxfs_prealloc_blocks(mp
));
3551 if (start
!= libxfs_prealloc_blocks(mp
)) {
3552 arec
->ar_blockcount
= cpu_to_be32(start
-
3553 libxfs_prealloc_blocks(mp
));
3555 nrec
->ar_startblock
= cpu_to_be32(
3556 be32_to_cpu(arec
->ar_startblock
) +
3557 be32_to_cpu(arec
->ar_blockcount
));
3559 be16_add_cpu(&block
->bb_numrecs
, 1);
3561 be32_add_cpu(&arec
->ar_startblock
, cfg
->logblocks
);
3564 * Calculate the record block count and check for the case where
3565 * the log might have consumed all available space in the AG. If
3566 * so, reset the record count to 0 to avoid exposure of an invalid
3567 * record start block.
3569 arec
->ar_blockcount
= cpu_to_be32(agsize
-
3570 be32_to_cpu(arec
->ar_startblock
));
3571 if (!arec
->ar_blockcount
)
3572 block
->bb_numrecs
= 0;
3574 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3577 * refcount btree root block
3579 if (xfs_sb_version_hasreflink(sbp
)) {
3580 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3581 XFS_AGB_TO_DADDR(mp
, agno
, libxfs_refc_block(mp
)),
3582 BTOBB(cfg
->blocksize
));
3583 buf
->b_ops
= &xfs_refcountbt_buf_ops
;
3585 block
= XFS_BUF_TO_BLOCK(buf
);
3586 memset(block
, 0, cfg
->blocksize
);
3587 libxfs_btree_init_block(mp
, buf
, XFS_BTNUM_REFC
, 0, 0, agno
, 0);
3588 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3592 * INO btree root block
3594 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3595 XFS_AGB_TO_DADDR(mp
, agno
, XFS_IBT_BLOCK(mp
)),
3596 BTOBB(cfg
->blocksize
));
3597 buf
->b_ops
= &xfs_inobt_buf_ops
;
3598 block
= XFS_BUF_TO_BLOCK(buf
);
3599 memset(block
, 0, cfg
->blocksize
);
3600 libxfs_btree_init_block(mp
, buf
, XFS_BTNUM_INO
, 0, 0, agno
, 0);
3601 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3604 * Free INO btree root block
3606 if (xfs_sb_version_hasfinobt(sbp
)) {
3607 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3608 XFS_AGB_TO_DADDR(mp
, agno
, XFS_FIBT_BLOCK(mp
)),
3609 BTOBB(cfg
->blocksize
));
3610 buf
->b_ops
= &xfs_inobt_buf_ops
;
3611 block
= XFS_BUF_TO_BLOCK(buf
);
3612 memset(block
, 0, cfg
->blocksize
);
3613 libxfs_btree_init_block(mp
, buf
, XFS_BTNUM_FINO
, 0, 0, agno
, 0);
3614 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3617 /* RMAP btree root block */
3618 if (xfs_sb_version_hasrmapbt(sbp
)) {
3619 struct xfs_rmap_rec
*rrec
;
3621 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3622 XFS_AGB_TO_DADDR(mp
, agno
, XFS_RMAP_BLOCK(mp
)),
3623 BTOBB(cfg
->blocksize
));
3624 buf
->b_ops
= &xfs_rmapbt_buf_ops
;
3625 block
= XFS_BUF_TO_BLOCK(buf
);
3626 memset(block
, 0, cfg
->blocksize
);
3628 libxfs_btree_init_block(mp
, buf
, XFS_BTNUM_RMAP
, 0, 0, agno
, 0);
3631 * mark the AG header regions as static metadata
3632 * The BNO btree block is the first block after the
3633 * headers, so it's location defines the size of region
3634 * the static metadata consumes.
3636 rrec
= XFS_RMAP_REC_ADDR(block
, 1);
3637 rrec
->rm_startblock
= 0;
3638 rrec
->rm_blockcount
= cpu_to_be32(XFS_BNO_BLOCK(mp
));
3639 rrec
->rm_owner
= cpu_to_be64(XFS_RMAP_OWN_FS
);
3640 rrec
->rm_offset
= 0;
3641 be16_add_cpu(&block
->bb_numrecs
, 1);
3643 /* account freespace btree root blocks */
3644 rrec
= XFS_RMAP_REC_ADDR(block
, 2);
3645 rrec
->rm_startblock
= cpu_to_be32(XFS_BNO_BLOCK(mp
));
3646 rrec
->rm_blockcount
= cpu_to_be32(2);
3647 rrec
->rm_owner
= cpu_to_be64(XFS_RMAP_OWN_AG
);
3648 rrec
->rm_offset
= 0;
3649 be16_add_cpu(&block
->bb_numrecs
, 1);
3651 /* account inode btree root blocks */
3652 rrec
= XFS_RMAP_REC_ADDR(block
, 3);
3653 rrec
->rm_startblock
= cpu_to_be32(XFS_IBT_BLOCK(mp
));
3654 rrec
->rm_blockcount
= cpu_to_be32(XFS_RMAP_BLOCK(mp
) -
3656 rrec
->rm_owner
= cpu_to_be64(XFS_RMAP_OWN_INOBT
);
3657 rrec
->rm_offset
= 0;
3658 be16_add_cpu(&block
->bb_numrecs
, 1);
3660 /* account for rmap btree root */
3661 rrec
= XFS_RMAP_REC_ADDR(block
, 4);
3662 rrec
->rm_startblock
= cpu_to_be32(XFS_RMAP_BLOCK(mp
));
3663 rrec
->rm_blockcount
= cpu_to_be32(1);
3664 rrec
->rm_owner
= cpu_to_be64(XFS_RMAP_OWN_AG
);
3665 rrec
->rm_offset
= 0;
3666 be16_add_cpu(&block
->bb_numrecs
, 1);
3668 /* account for refcount btree root */
3669 if (xfs_sb_version_hasreflink(sbp
)) {
3670 rrec
= XFS_RMAP_REC_ADDR(block
, 5);
3671 rrec
->rm_startblock
= cpu_to_be32(libxfs_refc_block(mp
));
3672 rrec
->rm_blockcount
= cpu_to_be32(1);
3673 rrec
->rm_owner
= cpu_to_be64(XFS_RMAP_OWN_REFC
);
3674 rrec
->rm_offset
= 0;
3675 be16_add_cpu(&block
->bb_numrecs
, 1);
3678 /* account for the log space */
3680 rrec
= XFS_RMAP_REC_ADDR(block
,
3681 be16_to_cpu(block
->bb_numrecs
) + 1);
3682 rrec
->rm_startblock
= cpu_to_be32(
3683 XFS_FSB_TO_AGBNO(mp
, cfg
->logstart
));
3684 rrec
->rm_blockcount
= cpu_to_be32(cfg
->logblocks
);
3685 rrec
->rm_owner
= cpu_to_be64(XFS_RMAP_OWN_LOG
);
3686 rrec
->rm_offset
= 0;
3687 be16_add_cpu(&block
->bb_numrecs
, 1);
3690 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3693 libxfs_perag_put(pag
);
3697 initialise_ag_freespace(
3698 struct xfs_mount
*mp
,
3699 xfs_agnumber_t agno
,
3702 struct xfs_alloc_arg args
;
3703 struct xfs_trans
*tp
;
3704 struct xfs_trans_res tres
= {0};
3707 c
= libxfs_trans_alloc(mp
, &tres
, worst_freelist
, 0, 0, &tp
);
3711 memset(&args
, 0, sizeof(args
));
3716 args
.pag
= libxfs_perag_get(mp
, agno
);
3718 libxfs_alloc_fix_freelist(&args
, 0);
3719 libxfs_perag_put(args
.pag
);
3720 libxfs_trans_commit(tp
);
3724 * rewrite several secondary superblocks with the root inode number filled out.
3725 * This can help repair recovery from a trashed primary superblock without
3726 * losing the root inode.
3729 rewrite_secondary_superblocks(
3730 struct xfs_mount
*mp
)
3732 struct xfs_buf
*buf
;
3734 /* rewrite the last superblock */
3735 buf
= libxfs_readbuf(mp
->m_dev
,
3736 XFS_AGB_TO_DADDR(mp
, mp
->m_sb
.sb_agcount
- 1,
3738 XFS_FSS_TO_BB(mp
, 1),
3739 LIBXFS_EXIT_ON_FAILURE
, &xfs_sb_buf_ops
);
3740 XFS_BUF_TO_SBP(buf
)->sb_rootino
= cpu_to_be64(mp
->m_sb
.sb_rootino
);
3741 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3743 /* and one in the middle for luck if there's enough AGs for that */
3744 if (mp
->m_sb
.sb_agcount
<= 2)
3747 buf
= libxfs_readbuf(mp
->m_dev
,
3748 XFS_AGB_TO_DADDR(mp
, (mp
->m_sb
.sb_agcount
- 1) / 2,
3750 XFS_FSS_TO_BB(mp
, 1),
3751 LIBXFS_EXIT_ON_FAILURE
, &xfs_sb_buf_ops
);
3752 XFS_BUF_TO_SBP(buf
)->sb_rootino
= cpu_to_be64(mp
->m_sb
.sb_rootino
);
3753 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3761 xfs_agnumber_t agno
;
3765 char *logfile
= NULL
;
3766 char *rtfile
= NULL
;
3769 int force_overwrite
= 0;
3771 char *protofile
= NULL
;
3772 char *protostring
= NULL
;
3773 int worst_freelist
= 0;
3775 struct libxfs_xinit xi
= {
3776 .isdirect
= LIBXFS_DIRECT
,
3777 .isreadonly
= LIBXFS_EXCLUSIVELY
,
3779 struct xfs_mount mbuf
= {};
3780 struct xfs_mount
*mp
= &mbuf
;
3781 struct xfs_sb
*sbp
= &mp
->m_sb
;
3782 struct fs_topology ft
= {};
3783 struct cli_params cli
= {
3787 struct mkfs_params cfg
= {};
3789 /* build time defaults */
3790 struct mkfs_default_params dft
= {
3791 .source
= _("package build definitions"),
3792 .sectorsize
= XFS_MIN_SECTORSIZE
,
3793 .blocksize
= 1 << XFS_DFL_BLOCKSIZE_LOG
,
3798 .inode_align
= true,
3800 .lazy_sb_counters
= true,
3801 .projid32bit
= true,
3802 .crcs_enabled
= true,
3808 .parent_pointers
= false,
3814 platform_uuid_generate(&cli
.uuid
);
3815 progname
= basename(argv
[0]);
3816 setlocale(LC_ALL
, "");
3817 bindtextdomain(PACKAGE
, LOCALEDIR
);
3818 textdomain(PACKAGE
);
3821 * TODO: Sourcing defaults from a config file
3823 * Before anything else, see if there's a config file with different
3824 * defaults. If a file exists in <package location>, read in the new
3825 * default values and overwrite them in the &dft structure. This way the
3826 * new defaults will apply before we parse the CLI, and the CLI will
3827 * still be able to override them. When more than one source is
3828 * implemented, emit a message to indicate where the defaults being
3831 * printf(_("Default configuration sourced from %s\n"), dft.source);
3834 /* copy new defaults into CLI parsing structure */
3835 memcpy(&cli
.sb_feat
, &dft
.sb_feat
, sizeof(cli
.sb_feat
));
3836 memcpy(&cli
.fsx
, &dft
.fsx
, sizeof(cli
.fsx
));
3838 while ((c
= getopt(argc
, argv
, "b:d:i:l:L:m:n:KNp:qr:s:CfV")) != EOF
) {
3842 force_overwrite
= 1;
3852 parse_subopts(c
, optarg
, &cli
);
3855 if (strlen(optarg
) > sizeof(sbp
->sb_fname
))
3856 illegal(optarg
, "L");
3867 respec('p', NULL
, 0);
3874 printf(_("%s version %s\n"), progname
, VERSION
);
3877 unknown(optopt
, "");
3880 if (argc
- optind
> 1) {
3881 fprintf(stderr
, _("extra arguments\n"));
3883 } else if (argc
- optind
== 1) {
3884 dfile
= xi
.volname
= getstr(argv
[optind
], &dopts
, D_NAME
);
3888 protostring
= setup_proto(protofile
);
3891 * Extract as much of the valid config as we can from the CLI input
3892 * before opening the libxfs devices.
3894 validate_blocksize(&cfg
, &cli
, &dft
);
3895 validate_sectorsize(&cfg
, &cli
, &dft
, &ft
, dfile
, dry_run
,
3899 * XXX: we still need to set block size and sector size global variables
3900 * so that getnum/cvtnum works correctly
3902 blocksize
= cfg
.blocksize
;
3903 sectorsize
= cfg
.sectorsize
;
3905 validate_log_sectorsize(&cfg
, &cli
, &dft
);
3906 validate_sb_features(&cfg
, &cli
);
3909 * we've now completed basic validation of the features, sector and
3910 * block sizes, so from this point onwards we use the values found in
3911 * the cfg structure for them, not the command line structure.
3913 validate_dirblocksize(&cfg
, &cli
);
3914 validate_inodesize(&cfg
, &cli
);
3917 * if the device size was specified convert it to a block count
3918 * now we have a valid block size. These will be set to zero if
3919 * nothing was specified, indicating we should use the full device.
3921 cfg
.dblocks
= calc_dev_size(cli
.dsize
, &cfg
, &dopts
, D_SIZE
, "data");
3922 cfg
.logblocks
= calc_dev_size(cli
.logsize
, &cfg
, &lopts
, L_SIZE
, "log");
3923 cfg
.rtblocks
= calc_dev_size(cli
.rtsize
, &cfg
, &ropts
, R_SIZE
, "rt");
3925 validate_rtextsize(&cfg
, &cli
, &ft
);
3926 calc_stripe_factors(&cfg
, &cli
, &ft
);
3929 * Open and validate the device configurations
3931 open_devices(&cfg
, &xi
, (discard
&& !dry_run
));
3932 validate_datadev(&cfg
, &cli
);
3933 validate_logdev(&cfg
, &cli
, &logfile
);
3934 validate_rtdev(&cfg
, &cli
, &rtfile
);
3937 * At this point when know exactly what size all the devices are,
3938 * so we can start validating and calculating layout options that are
3939 * dependent on device sizes. Once calculated, make sure everything
3940 * aligns to device geometry correctly.
3942 calculate_initial_ag_geometry(&cfg
, &cli
);
3943 align_ag_geometry(&cfg
);
3945 calculate_imaxpct(&cfg
, &cli
);
3948 * Set up the basic superblock parameters now so that we can use
3949 * the geometry information we've already validated in libxfs
3950 * provided functions to determine on-disk format information.
3952 start_superblock_setup(&cfg
, mp
, sbp
);
3953 initialise_mount(&cfg
, mp
, sbp
);
3956 * With the mount set up, we can finally calculate the log size
3957 * constraints and do default size calculations and final validation
3959 calculate_log_size(&cfg
, &cli
, mp
);
3961 if (!quiet
|| dry_run
) {
3962 print_mkfs_cfg(&cfg
, dfile
, logfile
, rtfile
);
3966 finish_superblock_setup(&cfg
, mp
, sbp
);
3969 * we need the libxfs buffer cache from here on in.
3971 libxfs_buftarg_init(mp
, xi
.ddev
, xi
.logdev
, xi
.rtdev
);
3974 * Before we mount the filesystem we need to make sure the devices have
3975 * enough of the filesystem structure on them that allows libxfs to
3978 prepare_devices(&cfg
, &xi
, mp
, sbp
, force_overwrite
);
3979 mp
= libxfs_mount(mp
, sbp
, xi
.ddev
, xi
.logdev
, xi
.rtdev
, 0);
3981 fprintf(stderr
, _("%s: filesystem failed to initialize\n"),
3987 * Initialise all the static on disk metadata.
3989 for (agno
= 0; agno
< cfg
.agcount
; agno
++)
3990 initialise_ag_headers(&cfg
, mp
, sbp
, agno
, &worst_freelist
);
3993 * Initialise the freespace freelists (i.e. AGFLs) in each AG.
3995 for (agno
= 0; agno
< cfg
.agcount
; agno
++)
3996 initialise_ag_freespace(mp
, agno
, worst_freelist
);
3999 * Allocate the root inode and anything else in the proto file.
4001 parse_proto(mp
, &cli
.fsx
, &protostring
);
4004 * Protect ourselves against possible stupidity
4006 if (XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
) != 0) {
4008 _("%s: root inode created in AG %u, not AG 0\n"),
4009 progname
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
));
4014 * Re-write multiple secondary superblocks with rootinode field set
4016 if (mp
->m_sb
.sb_agcount
> 1)
4017 rewrite_secondary_superblocks(mp
);
4020 * Dump all inodes and buffers before marking us all done.
4021 * Need to drop references to inodes we still hold, first.
4023 libxfs_rtmount_destroy(mp
);
4024 libxfs_bcache_purge();
4027 * Mark the filesystem ok.
4029 buf
= libxfs_getsb(mp
, LIBXFS_EXIT_ON_FAILURE
);
4030 (XFS_BUF_TO_SBP(buf
))->sb_inprogress
= 0;
4031 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
4035 libxfs_device_close(xi
.rtdev
);
4036 if (xi
.logdev
&& xi
.logdev
!= xi
.ddev
)
4037 libxfs_device_close(xi
.logdev
);
4038 libxfs_device_close(xi
.ddev
);