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"
25 * Prototypes for internal functions.
27 static void conflict(char opt
, const char *tab
[], int oldidx
, int newidx
);
28 static void illegal(const char *value
, const char *opt
);
29 static __attribute__((noreturn
)) void usage (void);
30 static __attribute__((noreturn
)) void reqval(char opt
, const char *tab
[], int idx
);
31 static void respec(char opt
, const char *tab
[], int idx
);
32 static void unknown(char opt
, char *s
);
33 static int ispow2(unsigned int i
);
36 * The configured block and sector sizes are defined as global variables so
37 * that they don't need to be passed to functions that require them.
39 unsigned int blocksize
;
40 unsigned int sectorsize
;
42 #define MAX_SUBOPTS 17
43 #define SUBOPT_NEEDS_VAL (-1LL)
44 #define MAX_CONFLICTS 8
45 #define LAST_CONFLICT (-1)
48 * Table for parsing mkfs parameters.
50 * Description of the structure members follows:
53 * Name is a single char, e.g., for '-d file', name is 'd'.
56 * Subopts is a list of strings naming suboptions. In the example above,
57 * it would contain "file". The last entry of this list has to be NULL.
59 * subopt_params MANDATORY
60 * This is a list of structs tied with subopts. For each entry in subopts,
61 * a corresponding entry has to be defined:
63 * subopt_params struct:
65 * This number, starting from zero, denotes which item in subopt_params
66 * it is. The index has to be the same as is the order in subopts list,
67 * so we can access the right item both in subopt_param and subopts.
70 * Do not set this flag when definning a subopt. It is used to remeber that
71 * this subopt was already seen, for example for conflicts detection.
74 * Do not set. It is used internally for respecification, when some options
75 * has to be parsed twice - at first as a string, then later as a number.
78 * A flag signalling whether the user-given value can use suffixes.
79 * If you want to allow the use of user-friendly values like 13k, 42G,
83 * An optional flag for subopts where the given value has to be a power
87 * If your subopt is in a conflict with some other option, specify it.
88 * Accepts the .index values of the conflicting subopts and the last
89 * member of this list has to be LAST_CONFLICT.
91 * minval, maxval OPTIONAL
92 * These options are used for automatic range check and they have to be
93 * always used together in pair. If you don't want to limit the max value,
94 * use something like UINT_MAX. If no value is given, then you must either
95 * supply your own validation, or refuse any value in the 'case
96 * X_SOMETHING' block. If you forget to define the min and max value, but
97 * call a standard function for validating user's value, it will cause an
98 * error message notifying you about this issue.
100 * (Said in another way, you can't have minval and maxval both equal
101 * to zero. But if one value is different: minval=0 and maxval=1,
104 * defaultval MANDATORY
105 * The value used if user specifies the subopt, but no value.
106 * If the subopt accepts some values (-d file=[1|0]), then this
107 * sets what is used with simple specifying the subopt (-d file).
108 * A special SUBOPT_NEEDS_VAL can be used to require a user-given
113 const char *subopts
[MAX_SUBOPTS
];
115 struct subopt_param
{
121 int conflicts
[MAX_CONFLICTS
];
124 long long defaultval
;
125 } subopt_params
[MAX_SUBOPTS
];
128 struct opt_params bopts
= {
139 .conflicts
= { B_SIZE
,
141 .minval
= XFS_MIN_BLOCKSIZE_LOG
,
142 .maxval
= XFS_MAX_BLOCKSIZE_LOG
,
143 .defaultval
= SUBOPT_NEEDS_VAL
,
148 .conflicts
= { B_LOG
,
150 .minval
= XFS_MIN_BLOCKSIZE
,
151 .maxval
= XFS_MAX_BLOCKSIZE
,
152 .defaultval
= SUBOPT_NEEDS_VAL
,
157 struct opt_params dopts
= {
180 #define D_SECTSIZE 10
184 #define D_RTINHERIT 12
186 #define D_PROJINHERIT 13
188 #define D_EXTSZINHERIT 14
190 #define D_COWEXTSIZE 15
195 { .index
= D_AGCOUNT
,
196 .conflicts
= { D_AGSIZE
,
199 .maxval
= XFS_MAX_AGNUMBER
,
200 .defaultval
= SUBOPT_NEEDS_VAL
,
203 .conflicts
= { LAST_CONFLICT
},
209 .conflicts
= { LAST_CONFLICT
},
210 .defaultval
= SUBOPT_NEEDS_VAL
,
213 .conflicts
= { LAST_CONFLICT
},
215 .minval
= XFS_AG_MIN_BYTES
,
217 .defaultval
= SUBOPT_NEEDS_VAL
,
220 .conflicts
= { D_NOALIGN
,
226 .defaultval
= SUBOPT_NEEDS_VAL
,
229 .conflicts
= { D_NOALIGN
,
235 .defaultval
= SUBOPT_NEEDS_VAL
,
238 .conflicts
= { D_AGCOUNT
,
241 .minval
= XFS_AG_MIN_BYTES
,
242 .maxval
= XFS_AG_MAX_BYTES
,
243 .defaultval
= SUBOPT_NEEDS_VAL
,
246 .conflicts
= { D_NOALIGN
,
253 .defaultval
= SUBOPT_NEEDS_VAL
,
256 .conflicts
= { D_NOALIGN
,
262 .defaultval
= SUBOPT_NEEDS_VAL
,
264 { .index
= D_SECTLOG
,
265 .conflicts
= { D_SECTSIZE
,
267 .minval
= XFS_MIN_SECTORSIZE_LOG
,
268 .maxval
= XFS_MAX_SECTORSIZE_LOG
,
269 .defaultval
= SUBOPT_NEEDS_VAL
,
271 { .index
= D_SECTSIZE
,
272 .conflicts
= { D_SECTLOG
,
276 .minval
= XFS_MIN_SECTORSIZE
,
277 .maxval
= XFS_MAX_SECTORSIZE
,
278 .defaultval
= SUBOPT_NEEDS_VAL
,
280 { .index
= D_NOALIGN
,
290 { .index
= D_RTINHERIT
,
291 .conflicts
= { LAST_CONFLICT
},
296 { .index
= D_PROJINHERIT
,
297 .conflicts
= { LAST_CONFLICT
},
300 .defaultval
= SUBOPT_NEEDS_VAL
,
302 { .index
= D_EXTSZINHERIT
,
303 .conflicts
= { LAST_CONFLICT
},
306 .defaultval
= SUBOPT_NEEDS_VAL
,
308 { .index
= D_COWEXTSIZE
,
309 .conflicts
= { LAST_CONFLICT
},
312 .defaultval
= SUBOPT_NEEDS_VAL
,
318 struct opt_params iopts
= {
333 #define I_PROJID32BIT 6
341 .conflicts
= { LAST_CONFLICT
},
347 .conflicts
= { I_PERBLOCK
,
350 .minval
= XFS_DINODE_MIN_LOG
,
351 .maxval
= XFS_DINODE_MAX_LOG
,
352 .defaultval
= SUBOPT_NEEDS_VAL
,
355 .conflicts
= { LAST_CONFLICT
},
358 .defaultval
= SUBOPT_NEEDS_VAL
,
360 { .index
= I_PERBLOCK
,
361 .conflicts
= { I_LOG
,
365 .minval
= XFS_MIN_INODE_PERBLOCK
,
366 .maxval
= XFS_MAX_BLOCKSIZE
/ XFS_DINODE_MIN_SIZE
,
367 .defaultval
= SUBOPT_NEEDS_VAL
,
370 .conflicts
= { I_PERBLOCK
,
374 .minval
= XFS_DINODE_MIN_SIZE
,
375 .maxval
= XFS_DINODE_MAX_SIZE
,
376 .defaultval
= SUBOPT_NEEDS_VAL
,
379 .conflicts
= { LAST_CONFLICT
},
382 .defaultval
= SUBOPT_NEEDS_VAL
,
384 { .index
= I_PROJID32BIT
,
385 .conflicts
= { LAST_CONFLICT
},
390 { .index
= I_SPINODES
,
391 .conflicts
= { LAST_CONFLICT
},
399 struct opt_params lopts
= {
424 #define L_LAZYSBCNTR 11
430 .conflicts
= { L_DEV
,
434 .defaultval
= SUBOPT_NEEDS_VAL
,
436 { .index
= L_INTERNAL
,
437 .conflicts
= { L_FILE
,
447 .conflicts
= { LAST_CONFLICT
},
449 .minval
= 2 * 1024 * 1024LL, /* XXX: XFS_MIN_LOG_BYTES */
450 .maxval
= XFS_MAX_LOG_BYTES
,
451 .defaultval
= SUBOPT_NEEDS_VAL
,
453 { .index
= L_VERSION
,
454 .conflicts
= { LAST_CONFLICT
},
457 .defaultval
= SUBOPT_NEEDS_VAL
,
463 .maxval
= BTOBB(XLOG_MAX_RECORD_BSIZE
),
464 .defaultval
= SUBOPT_NEEDS_VAL
,
467 .conflicts
= { L_SUNIT
,
471 .maxval
= XLOG_MAX_RECORD_BSIZE
,
472 .defaultval
= SUBOPT_NEEDS_VAL
,
475 .conflicts
= { L_AGNUM
,
478 .defaultval
= SUBOPT_NEEDS_VAL
,
480 { .index
= L_SECTLOG
,
481 .conflicts
= { L_SECTSIZE
,
484 .minval
= XFS_MIN_SECTORSIZE_LOG
,
485 .maxval
= XFS_MAX_SECTORSIZE_LOG
,
486 .defaultval
= SUBOPT_NEEDS_VAL
,
488 { .index
= L_SECTSIZE
,
489 .conflicts
= { L_SECTLOG
,
494 .minval
= XFS_MIN_SECTORSIZE
,
495 .maxval
= XFS_MAX_SECTORSIZE
,
496 .defaultval
= SUBOPT_NEEDS_VAL
,
499 .conflicts
= { L_INTERNAL
,
506 .conflicts
= { L_AGNUM
,
509 .defaultval
= SUBOPT_NEEDS_VAL
,
511 { .index
= L_LAZYSBCNTR
,
512 .conflicts
= { LAST_CONFLICT
},
520 struct opt_params nopts
= {
535 .conflicts
= { N_SIZE
,
537 .minval
= XFS_MIN_REC_DIRSIZE
,
538 .maxval
= XFS_MAX_BLOCKSIZE_LOG
,
539 .defaultval
= SUBOPT_NEEDS_VAL
,
542 .conflicts
= { N_LOG
,
546 .minval
= 1 << XFS_MIN_REC_DIRSIZE
,
547 .maxval
= XFS_MAX_BLOCKSIZE
,
548 .defaultval
= SUBOPT_NEEDS_VAL
,
550 { .index
= N_VERSION
,
551 .conflicts
= { LAST_CONFLICT
},
554 .defaultval
= SUBOPT_NEEDS_VAL
,
557 .conflicts
= { LAST_CONFLICT
},
565 struct opt_params ropts
= {
583 { .index
= R_EXTSIZE
,
584 .conflicts
= { LAST_CONFLICT
},
586 .minval
= XFS_MIN_RTEXTSIZE
,
587 .maxval
= XFS_MAX_RTEXTSIZE
,
588 .defaultval
= SUBOPT_NEEDS_VAL
,
591 .conflicts
= { LAST_CONFLICT
},
595 .defaultval
= SUBOPT_NEEDS_VAL
,
598 .conflicts
= { LAST_CONFLICT
},
599 .defaultval
= SUBOPT_NEEDS_VAL
,
605 .conflicts
= { LAST_CONFLICT
},
608 .conflicts
= { LAST_CONFLICT
},
609 .defaultval
= SUBOPT_NEEDS_VAL
,
611 { .index
= R_NOALIGN
,
615 .conflicts
= { LAST_CONFLICT
},
620 struct opt_params sopts
= {
635 .conflicts
= { S_SIZE
,
638 .minval
= XFS_MIN_SECTORSIZE_LOG
,
639 .maxval
= XFS_MAX_SECTORSIZE_LOG
,
640 .defaultval
= SUBOPT_NEEDS_VAL
,
642 { .index
= S_SECTLOG
,
643 .conflicts
= { S_SIZE
,
646 .minval
= XFS_MIN_SECTORSIZE_LOG
,
647 .maxval
= XFS_MAX_SECTORSIZE_LOG
,
648 .defaultval
= SUBOPT_NEEDS_VAL
,
651 .conflicts
= { S_LOG
,
656 .minval
= XFS_MIN_SECTORSIZE
,
657 .maxval
= XFS_MAX_SECTORSIZE
,
658 .defaultval
= SUBOPT_NEEDS_VAL
,
660 { .index
= S_SECTSIZE
,
661 .conflicts
= { S_LOG
,
666 .minval
= XFS_MIN_SECTORSIZE
,
667 .maxval
= XFS_MAX_SECTORSIZE
,
668 .defaultval
= SUBOPT_NEEDS_VAL
,
673 struct opt_params mopts
= {
690 .conflicts
= { LAST_CONFLICT
},
696 .conflicts
= { LAST_CONFLICT
},
702 .conflicts
= { LAST_CONFLICT
},
703 .defaultval
= SUBOPT_NEEDS_VAL
,
706 .conflicts
= { LAST_CONFLICT
},
711 { .index
= M_REFLINK
,
712 .conflicts
= { LAST_CONFLICT
},
720 /* quick way of checking if a parameter was set on the CLI */
723 struct opt_params
*opts
,
726 return opts
->subopt_params
[subopt
].seen
||
727 opts
->subopt_params
[subopt
].str_seen
;
731 * Options configured on the command line.
733 * This stores all the specific config parameters the user sets on the command
734 * line. We do not use these values directly - they are inputs to the mkfs
735 * geometry validation and override any default configuration value we have.
737 * We don't keep flags to indicate what parameters are set - if we need to check
738 * if an option was set on the command line, we check the relevant entry in the
739 * option table which records whether it was specified in the .seen and
740 * .str_seen variables in the table.
742 * Some parameters are stored as strings for post-parsing after their dependent
743 * options have been resolved (e.g. block size and sector size have been parsed
746 * This allows us to check that values have been set without needing separate
747 * flags for each value, and hence avoids needing to record and check for each
748 * specific option that can set the value later on in the code. In the cases
749 * where we don't have a cli_params structure around, the above cli_opt_set()
750 * function can be used.
752 struct sb_feat_args
{
758 bool lazy_sb_counters
;
766 bool parent_pointers
;
776 /* parameters that depend on sector/block size being validated. */
786 /* parameters where 0 is a valid CLI value */
794 /* parameters where 0 is not a valid value */
803 /* feature flags that are set */
804 struct sb_feat_args sb_feat
;
806 /* root inode characteristics */
809 /* libxfs device setup */
810 struct libxfs_xinit
*xi
;
814 * Calculated filesystem feature and geometry information.
816 * This structure contains the information we will use to create the on-disk
817 * filesystem from. The validation and calculation code uses it to store all the
818 * temporary and final config state for the filesystem.
820 * The information in this structure will contain a mix of validated CLI input
821 * variables, default feature state and calculated values that are needed to
822 * construct the superblock and other on disk features. These are all in one
823 * place so that we don't have to pass handfuls of seemingly arbitrary variables
824 * around to different functions to do the work we need to do.
842 uint64_t rtextblocks
;
844 uint64_t rtbmblocks
; /* rt bitmap blocks */
846 int dsunit
; /* in FSBs */
847 int dswidth
; /* in FSBs */
848 int lsunit
; /* in FSBs */
862 struct sb_feat_args sb_feat
;
866 * Default filesystem features and configuration values
868 * This structure contains the default mkfs values that are to be used when
869 * a user does not specify the option on the command line. We do not use these
870 * values directly - they are inputs to the mkfs geometry validation and
873 struct mkfs_default_params
{
874 char *source
; /* where the defaults came from */
879 /* feature flags that are set */
880 struct sb_feat_args sb_feat
;
882 /* root inode characteristics */
886 #define TERABYTES(count, blog) ((uint64_t)(count) << (40 - (blog)))
887 #define GIGABYTES(count, blog) ((uint64_t)(count) << (30 - (blog)))
888 #define MEGABYTES(count, blog) ((uint64_t)(count) << (20 - (blog)))
891 * Use this macro before we have superblock and mount structure
893 #define DTOBT(d) ((xfs_rfsblock_t)((d) >> (blocklog - BBSHIFT)))
896 * Use this for block reservations needed for mkfs's conditions
897 * (basically no fragmentation).
899 #define MKFS_BLOCKRES_INODE \
900 ((uint)(mp->m_ialloc_blks + (mp->m_in_maxlevels - 1)))
901 #define MKFS_BLOCKRES(rb) \
902 ((uint)(MKFS_BLOCKRES_INODE + XFS_DA_NODE_MAXDEPTH + \
903 (XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1) + (rb)))
905 /* amount (in bytes) we zero at the beginning and end of the device to
906 * remove traces of other filesystems, raid superblocks, etc.
908 #define WHACK_SIZE (128 * 1024)
911 * Convert lsu to lsunit for 512 bytes blocks and check validity of the values.
924 /* Handle data sunit/swidth options */
925 if ((*dsunit
&& !*dswidth
) || (!*dsunit
&& *dswidth
)) {
927 _("both data sunit and data swidth options "
928 "must be specified\n"));
933 if ((dsu
&& !dsw
) || (!dsu
&& dsw
)) {
935 _("both data su and data sw options "
936 "must be specified\n"));
942 _("data su must be a multiple of the "
943 "sector size (%d)\n"), dsectsz
);
947 *dsunit
= (int)BTOBBT(dsu
);
948 *dswidth
= *dsunit
* dsw
;
951 if (*dsunit
&& (*dswidth
% *dsunit
!= 0)) {
953 _("data stripe width (%d) must be a multiple of the "
954 "data stripe unit (%d)\n"), *dswidth
, *dsunit
);
958 /* Handle log sunit options */
961 *lsunit
= (int)BTOBBT(lsu
);
963 /* verify if lsu/lsunit is a multiple block size */
964 if (lsu
% blocksize
!= 0) {
966 _("log stripe unit (%d) must be a multiple of the block size (%d)\n"),
970 if ((BBTOB(*lsunit
) % blocksize
!= 0)) {
972 _("log stripe unit (%d) must be a multiple of the block size (%d)\n"),
973 BBTOB(*lsunit
), blocksize
);
985 bool force_overwrite
,
990 if (*isfile
&& (no_size
|| no_name
)) {
992 _("if -%s file then -%s name and -%s size are required\n"),
993 optname
, optname
, optname
);
998 fprintf(stderr
, _("No device name specified\n"));
1002 if (stat(name
, &statbuf
)) {
1003 if (errno
== ENOENT
&& *isfile
) {
1010 _("Error accessing specified device %s: %s\n"),
1011 name
, strerror(errno
));
1016 if (!force_overwrite
&& check_overwrite(name
)) {
1018 _("%s: Use the -f option to force overwrite.\n"),
1024 * We only want to completely truncate and recreate an existing file if
1025 * we were specifically told it was a file. Set the create flag only in
1026 * this case to trigger that behaviour.
1028 if (S_ISREG(statbuf
.st_mode
)) {
1036 if (S_ISBLK(statbuf
.st_mode
)) {
1039 _("specified \"-%s file\" on a block device %s\n"),
1047 _("specified device %s not a file or block device\n"),
1053 fixup_log_stripe_unit(
1056 xfs_rfsblock_t
*logblocks
,
1059 uint64_t tmp_logblocks
;
1062 * Make sure that the log size is a multiple of the stripe unit
1064 if ((*logblocks
% sunit
) != 0) {
1066 tmp_logblocks
= ((*logblocks
+ (sunit
- 1))
1069 * If the log is too large, round down
1070 * instead of round up
1072 if ((tmp_logblocks
> XFS_MAX_LOG_BLOCKS
) ||
1073 ((tmp_logblocks
<< blocklog
) > XFS_MAX_LOG_BYTES
)) {
1074 tmp_logblocks
= (*logblocks
/ sunit
) * sunit
;
1076 *logblocks
= tmp_logblocks
;
1078 fprintf(stderr
, _("log size %lld is not a multiple "
1079 "of the log stripe unit %d\n"),
1080 (long long) *logblocks
, sunit
);
1086 static xfs_fsblock_t
1087 fixup_internal_log_stripe(
1090 xfs_fsblock_t logstart
,
1093 xfs_rfsblock_t
*logblocks
,
1097 if ((logstart
% sunit
) != 0) {
1098 logstart
= ((logstart
+ (sunit
- 1))/sunit
) * sunit
;
1102 fixup_log_stripe_unit(lsflag
, sunit
, logblocks
, blocklog
);
1104 if (*logblocks
> agsize
- XFS_FSB_TO_AGBNO(mp
, logstart
)) {
1106 _("Due to stripe alignment, the internal log size "
1107 "(%lld) is too large.\n"), (long long) *logblocks
);
1108 fprintf(stderr
, _("Must fit within an allocation group.\n"));
1115 validate_log_size(uint64_t logblocks
, int blocklog
, int min_logblocks
)
1117 if (logblocks
< min_logblocks
) {
1119 _("log size %lld blocks too small, minimum size is %d blocks\n"),
1120 (long long)logblocks
, min_logblocks
);
1123 if (logblocks
> XFS_MAX_LOG_BLOCKS
) {
1125 _("log size %lld blocks too large, maximum size is %lld blocks\n"),
1126 (long long)logblocks
, XFS_MAX_LOG_BLOCKS
);
1129 if ((logblocks
<< blocklog
) > XFS_MAX_LOG_BYTES
) {
1131 _("log size %lld bytes too large, maximum size is %lld bytes\n"),
1132 (long long)(logblocks
<< blocklog
), XFS_MAX_LOG_BYTES
);
1138 calc_default_imaxpct(
1143 * This returns the % of the disk space that is used for
1144 * inodes, it changes relatively to the FS size:
1145 * - over 50 TB, use 1%,
1146 * - 1TB - 50 TB, use 5%,
1147 * - under 1 TB, use XFS_DFL_IMAXIMUM_PCT (25%).
1150 if (dblocks
< TERABYTES(1, blocklog
)) {
1151 return XFS_DFL_IMAXIMUM_PCT
;
1152 } else if (dblocks
< TERABYTES(50, blocklog
)) {
1160 validate_ag_geometry(
1166 if (agsize
< XFS_AG_MIN_BLOCKS(blocklog
)) {
1168 _("agsize (%lld blocks) too small, need at least %lld blocks\n"),
1170 (long long)XFS_AG_MIN_BLOCKS(blocklog
));
1174 if (agsize
> XFS_AG_MAX_BLOCKS(blocklog
)) {
1176 _("agsize (%lld blocks) too big, maximum is %lld blocks\n"),
1178 (long long)XFS_AG_MAX_BLOCKS(blocklog
));
1182 if (agsize
> dblocks
) {
1184 _("agsize (%lld blocks) too big, data area is %lld blocks\n"),
1185 (long long)agsize
, (long long)dblocks
);
1189 if (agsize
< XFS_AG_MIN_BLOCKS(blocklog
)) {
1191 _("too many allocation groups for size = %lld\n"),
1193 fprintf(stderr
, _("need at most %lld allocation groups\n"),
1194 (long long)(dblocks
/ XFS_AG_MIN_BLOCKS(blocklog
) +
1195 (dblocks
% XFS_AG_MIN_BLOCKS(blocklog
) != 0)));
1199 if (agsize
> XFS_AG_MAX_BLOCKS(blocklog
)) {
1201 _("too few allocation groups for size = %lld\n"), (long long)agsize
);
1203 _("need at least %lld allocation groups\n"),
1204 (long long)(dblocks
/ XFS_AG_MAX_BLOCKS(blocklog
) +
1205 (dblocks
% XFS_AG_MAX_BLOCKS(blocklog
) != 0)));
1210 * If the last AG is too small, reduce the filesystem size
1211 * and drop the blocks.
1213 if ( dblocks
% agsize
!= 0 &&
1214 (dblocks
% agsize
< XFS_AG_MIN_BLOCKS(blocklog
))) {
1216 _("last AG size %lld blocks too small, minimum size is %lld blocks\n"),
1217 (long long)(dblocks
% agsize
),
1218 (long long)XFS_AG_MIN_BLOCKS(blocklog
));
1223 * If agcount is too large, make it smaller.
1225 if (agcount
> XFS_MAX_AGNUMBER
+ 1) {
1227 _("%lld allocation groups is too many, maximum is %lld\n"),
1228 (long long)agcount
, (long long)XFS_MAX_AGNUMBER
+ 1);
1234 zero_old_xfs_structures(
1245 * We open regular files with O_TRUNC|O_CREAT. Nothing to do here...
1247 if (xi
->disfile
&& xi
->dcreat
)
1251 * read in existing filesystem superblock, use its geometry
1252 * settings and zero the existing secondary superblocks.
1254 buf
= memalign(libxfs_device_alignment(), new_sb
->sb_sectsize
);
1257 _("error reading existing superblock -- failed to memalign buffer\n"));
1260 memset(buf
, 0, new_sb
->sb_sectsize
);
1263 * If we are creating an image file, it might be of zero length at this
1264 * point in time. Hence reading the existing superblock is going to
1265 * return zero bytes. It's not a failure we need to warn about in this
1268 off
= pread(xi
->dfd
, buf
, new_sb
->sb_sectsize
, 0);
1269 if (off
!= new_sb
->sb_sectsize
) {
1272 _("error reading existing superblock: %s\n"),
1276 libxfs_sb_from_disk(&sb
, buf
);
1279 * perform same basic superblock validation to make sure we
1280 * actually zero secondary blocks
1282 if (sb
.sb_magicnum
!= XFS_SB_MAGIC
|| sb
.sb_blocksize
== 0)
1285 for (bsize
= 1, i
= 0; bsize
< sb
.sb_blocksize
&&
1286 i
< sizeof(sb
.sb_blocksize
) * NBBY
; i
++)
1289 if (i
< XFS_MIN_BLOCKSIZE_LOG
|| i
> XFS_MAX_BLOCKSIZE_LOG
||
1290 i
!= sb
.sb_blocklog
)
1293 if (sb
.sb_dblocks
> ((uint64_t)sb
.sb_agcount
* sb
.sb_agblocks
) ||
1294 sb
.sb_dblocks
< ((uint64_t)(sb
.sb_agcount
- 1) *
1295 sb
.sb_agblocks
+ XFS_MIN_AG_BLOCKS
))
1299 * block size and basic geometry seems alright, zero the secondaries.
1301 memset(buf
, 0, new_sb
->sb_sectsize
);
1303 for (i
= 1; i
< sb
.sb_agcount
; i
++) {
1304 off
+= sb
.sb_agblocks
;
1305 if (pwrite(xi
->dfd
, buf
, new_sb
->sb_sectsize
,
1306 off
<< sb
.sb_blocklog
) == -1)
1314 discard_blocks(dev_t dev
, uint64_t nsectors
)
1319 * We intentionally ignore errors from the discard ioctl. It is
1320 * not necessary for the mkfs functionality but just an optimization.
1322 fd
= libxfs_device_to_fd(dev
);
1324 platform_discard_blocks(fd
, 0, nsectors
<< 9);
1330 struct sb_feat_args
*fp
,
1336 sbp
->sb_versionnum
= XFS_DFL_SB_VERSION_BITS
;
1337 if (fp
->crcs_enabled
)
1338 sbp
->sb_versionnum
|= XFS_SB_VERSION_5
;
1340 sbp
->sb_versionnum
|= XFS_SB_VERSION_4
;
1342 if (fp
->inode_align
)
1343 sbp
->sb_versionnum
|= XFS_SB_VERSION_ALIGNBIT
;
1345 sbp
->sb_versionnum
|= XFS_SB_VERSION_DALIGNBIT
;
1346 if (fp
->log_version
== 2)
1347 sbp
->sb_versionnum
|= XFS_SB_VERSION_LOGV2BIT
;
1348 if (fp
->attr_version
== 1)
1349 sbp
->sb_versionnum
|= XFS_SB_VERSION_ATTRBIT
;
1350 if (sectsize
> BBSIZE
|| lsectsize
> BBSIZE
)
1351 sbp
->sb_versionnum
|= XFS_SB_VERSION_SECTORBIT
;
1353 sbp
->sb_versionnum
|= XFS_SB_VERSION_BORGBIT
;
1356 sbp
->sb_features2
= 0;
1357 if (fp
->lazy_sb_counters
)
1358 sbp
->sb_features2
|= XFS_SB_VERSION2_LAZYSBCOUNTBIT
;
1359 if (!fp
->projid16bit
)
1360 sbp
->sb_features2
|= XFS_SB_VERSION2_PROJID32BIT
;
1361 if (fp
->parent_pointers
)
1362 sbp
->sb_features2
|= XFS_SB_VERSION2_PARENTBIT
;
1363 if (fp
->crcs_enabled
)
1364 sbp
->sb_features2
|= XFS_SB_VERSION2_CRCBIT
;
1365 if (fp
->attr_version
== 2)
1366 sbp
->sb_features2
|= XFS_SB_VERSION2_ATTR2BIT
;
1368 /* v5 superblocks have their own feature bit for dirftype */
1369 if (fp
->dirftype
&& !fp
->crcs_enabled
)
1370 sbp
->sb_features2
|= XFS_SB_VERSION2_FTYPE
;
1372 /* update whether extended features are in use */
1373 if (sbp
->sb_features2
!= 0)
1374 sbp
->sb_versionnum
|= XFS_SB_VERSION_MOREBITSBIT
;
1377 * Due to a structure alignment issue, sb_features2 ended up in one
1378 * of two locations, the second "incorrect" location represented by
1379 * the sb_bad_features2 field. To avoid older kernels mounting
1380 * filesystems they shouldn't, set both field to the same value.
1382 sbp
->sb_bad_features2
= sbp
->sb_features2
;
1384 if (!fp
->crcs_enabled
)
1387 /* default features for v5 filesystems */
1388 sbp
->sb_features_compat
= 0;
1389 sbp
->sb_features_ro_compat
= 0;
1390 sbp
->sb_features_incompat
= XFS_SB_FEAT_INCOMPAT_FTYPE
;
1391 sbp
->sb_features_log_incompat
= 0;
1394 sbp
->sb_features_ro_compat
= XFS_SB_FEAT_RO_COMPAT_FINOBT
;
1396 sbp
->sb_features_ro_compat
|= XFS_SB_FEAT_RO_COMPAT_RMAPBT
;
1398 sbp
->sb_features_ro_compat
|= XFS_SB_FEAT_RO_COMPAT_REFLINK
;
1401 * Sparse inode chunk support has two main inode alignment requirements.
1402 * First, sparse chunk alignment must match the cluster size. Second,
1403 * full chunk alignment must match the inode chunk size.
1405 * Copy the already calculated/scaled inoalignmt to spino_align and
1406 * update the former to the full inode chunk size.
1409 sbp
->sb_spino_align
= sbp
->sb_inoalignmt
;
1410 sbp
->sb_inoalignmt
= XFS_INODES_PER_CHUNK
*
1411 sbp
->sb_inodesize
>> sbp
->sb_blocklog
;
1412 sbp
->sb_features_incompat
|= XFS_SB_FEAT_INCOMPAT_SPINODES
;
1417 static __attribute__((noreturn
)) void
1420 struct opt_params
*opts
,
1425 _("Illegal value %s for -%c %s option. %s\n"),
1426 value
, opts
->name
, opts
->subopts
[index
],
1427 reason
? reason
: "");
1432 * Check for conflicts and option respecification.
1436 struct opt_params
*opts
,
1440 struct subopt_param
*sp
= &opts
->subopt_params
[index
];
1443 if (sp
->index
!= index
) {
1445 _("Developer screwed up option parsing (%d/%d)! Please report!\n"),
1447 reqval(opts
->name
, opts
->subopts
, index
);
1451 * Check for respecification of the option. This is more complex than it
1452 * seems because some options are parsed twice - once as a string during
1453 * input parsing, then later the string is passed to getnum for
1454 * conversion into a number and bounds checking. Hence the two variables
1455 * used to track the different uses based on the @str parameter passed
1460 respec(opts
->name
, opts
->subopts
, index
);
1464 respec(opts
->name
, opts
->subopts
, index
);
1465 sp
->str_seen
= true;
1468 /* check for conflicts with the option */
1469 for (i
= 0; i
< MAX_CONFLICTS
; i
++) {
1470 int conflict_opt
= sp
->conflicts
[i
];
1472 if (conflict_opt
== LAST_CONFLICT
)
1474 if (opts
->subopt_params
[conflict_opt
].seen
||
1475 opts
->subopt_params
[conflict_opt
].str_seen
)
1476 conflict(opts
->name
, opts
->subopts
,
1477 conflict_opt
, index
);
1484 struct opt_params
*opts
,
1487 struct subopt_param
*sp
= &opts
->subopt_params
[index
];
1490 check_opt(opts
, index
, false);
1491 /* empty strings might just return a default value */
1492 if (!str
|| *str
== '\0') {
1493 if (sp
->defaultval
== SUBOPT_NEEDS_VAL
)
1494 reqval(opts
->name
, opts
->subopts
, index
);
1495 return sp
->defaultval
;
1498 if (sp
->minval
== 0 && sp
->maxval
== 0) {
1500 _("Option -%c %s has undefined minval/maxval."
1501 "Can't verify value range. This is a bug.\n"),
1502 opts
->name
, opts
->subopts
[index
]);
1507 * Some values are pure numbers, others can have suffixes that define
1508 * the units of the number. Those get passed to cvtnum(), otherwise we
1509 * convert it ourselves to guarantee there is no trailing garbage in the
1513 c
= cvtnum(blocksize
, sectorsize
, str
);
1517 c
= strtoll(str
, &str_end
, 0);
1518 if (c
== 0 && str_end
== str
)
1519 illegal_option(str
, opts
, index
, NULL
);
1520 if (*str_end
!= '\0')
1521 illegal_option(str
, opts
, index
, NULL
);
1524 /* Validity check the result. */
1526 illegal_option(str
, opts
, index
, _("value is too small"));
1527 else if (c
> sp
->maxval
)
1528 illegal_option(str
, opts
, index
, _("value is too large"));
1529 if (sp
->is_power_2
&& !ispow2(c
))
1530 illegal_option(str
, opts
, index
, _("value must be a power of 2"));
1535 * Option is a string - do all the option table work, and check there
1536 * is actually an option string. Otherwise we don't do anything with the string
1537 * here - validation will be done later when the string is converted to a value
1538 * or used as a file/device path.
1543 struct opt_params
*opts
,
1546 check_opt(opts
, index
, true);
1548 /* empty strings for string options are not valid */
1549 if (!str
|| *str
== '\0')
1550 reqval(opts
->name
, opts
->subopts
, index
);
1556 struct opt_params
*opts
,
1559 struct cli_params
*cli
)
1565 blocklog
= getnum(value
, opts
, B_LOG
);
1566 cli
->blocksize
= 1 << blocklog
;
1569 cli
->blocksize
= getnum(value
, opts
, B_SIZE
);
1579 struct opt_params
*opts
,
1582 struct cli_params
*cli
)
1588 cli
->agcount
= getnum(value
, opts
, D_AGCOUNT
);
1591 cli
->agsize
= getstr(value
, opts
, D_AGSIZE
);
1594 cli
->xi
->disfile
= getnum(value
, opts
, D_FILE
);
1597 cli
->xi
->dname
= getstr(value
, opts
, D_NAME
);
1600 cli
->dsize
= getstr(value
, opts
, D_SIZE
);
1603 cli
->dsunit
= getnum(value
, opts
, D_SUNIT
);
1606 cli
->dswidth
= getnum(value
, opts
, D_SWIDTH
);
1609 cli
->dsu
= getstr(value
, opts
, D_SU
);
1612 cli
->dsw
= getnum(value
, opts
, D_SW
);
1615 cli
->sb_feat
.nodalign
= getnum(value
, opts
, D_NOALIGN
);
1618 if (cli
->sectorsize
)
1619 conflict('d', opts
->subopts
, D_SECTSIZE
, D_SECTLOG
);
1620 sectorlog
= getnum(value
, opts
, D_SECTLOG
);
1621 cli
->sectorsize
= 1 << sectorlog
;
1624 if (cli
->sectorsize
)
1625 conflict('d', opts
->subopts
, D_SECTSIZE
, D_SECTLOG
);
1626 cli
->sectorsize
= getnum(value
, opts
, D_SECTSIZE
);
1629 if (getnum(value
, opts
, D_RTINHERIT
))
1630 cli
->fsx
.fsx_xflags
|= XFS_DIFLAG_RTINHERIT
;
1633 cli
->fsx
.fsx_projid
= getnum(value
, opts
, D_PROJINHERIT
);
1634 cli
->fsx
.fsx_xflags
|= XFS_DIFLAG_PROJINHERIT
;
1636 case D_EXTSZINHERIT
:
1637 cli
->fsx
.fsx_extsize
= getnum(value
, opts
, D_EXTSZINHERIT
);
1638 cli
->fsx
.fsx_xflags
|= XFS_DIFLAG_EXTSZINHERIT
;
1641 cli
->fsx
.fsx_cowextsize
= getnum(value
, opts
, D_COWEXTSIZE
);
1642 cli
->fsx
.fsx_xflags
|= FS_XFLAG_COWEXTSIZE
;
1652 struct opt_params
*opts
,
1655 struct cli_params
*cli
)
1661 cli
->sb_feat
.inode_align
= getnum(value
, &iopts
, I_ALIGN
);
1664 inodelog
= getnum(value
, &iopts
, I_LOG
);
1665 cli
->inodesize
= 1 << inodelog
;
1668 cli
->imaxpct
= getnum(value
, &iopts
, I_MAXPCT
);
1671 cli
->inopblock
= getnum(value
, &iopts
, I_PERBLOCK
);
1674 cli
->inodesize
= getnum(value
, &iopts
, I_SIZE
);
1677 cli
->sb_feat
.attr_version
= getnum(value
, &iopts
, I_ATTR
);
1680 cli
->sb_feat
.projid16bit
= !getnum(value
, &iopts
, I_PROJID32BIT
);
1683 cli
->sb_feat
.spinodes
= getnum(value
, &iopts
, I_SPINODES
);
1693 struct opt_params
*opts
,
1696 struct cli_params
*cli
)
1702 cli
->logagno
= getnum(value
, &lopts
, L_AGNUM
);
1705 cli
->xi
->lisfile
= getnum(value
, &lopts
, L_FILE
);
1708 cli
->loginternal
= getnum(value
, &lopts
, L_INTERNAL
);
1711 cli
->lsu
= getstr(value
, &lopts
, L_SU
);
1714 cli
->lsunit
= getnum(value
, &lopts
, L_SUNIT
);
1718 cli
->xi
->logname
= getstr(value
, &lopts
, L_NAME
);
1719 cli
->loginternal
= 0;
1722 cli
->sb_feat
.log_version
= getnum(value
, &lopts
, L_VERSION
);
1725 cli
->logsize
= getstr(value
, &lopts
, L_SIZE
);
1728 lsectorlog
= getnum(value
, &lopts
, L_SECTLOG
);
1729 cli
->lsectorsize
= 1 << lsectorlog
;
1732 cli
->lsectorsize
= getnum(value
, &lopts
, L_SECTSIZE
);
1735 cli
->sb_feat
.lazy_sb_counters
= getnum(value
, &lopts
, L_LAZYSBCNTR
);
1745 struct opt_params
*opts
,
1748 struct cli_params
*cli
)
1752 cli
->sb_feat
.crcs_enabled
= getnum(value
, &mopts
, M_CRC
);
1753 if (cli
->sb_feat
.crcs_enabled
)
1754 cli
->sb_feat
.dirftype
= true;
1757 cli
->sb_feat
.finobt
= getnum(value
, &mopts
, M_FINOBT
);
1760 if (!value
|| *value
== '\0')
1761 reqval('m', opts
->subopts
, M_UUID
);
1762 if (platform_uuid_parse(value
, &cli
->uuid
))
1763 illegal(value
, "m uuid");
1766 cli
->sb_feat
.rmapbt
= getnum(value
, &mopts
, M_RMAPBT
);
1769 cli
->sb_feat
.reflink
= getnum(value
, &mopts
, M_REFLINK
);
1779 struct opt_params
*opts
,
1782 struct cli_params
*cli
)
1786 cli
->dirblocklog
= getnum(value
, opts
, N_LOG
);
1789 cli
->dirblocksize
= getstr(value
, opts
, N_SIZE
);
1792 value
= getstr(value
, &nopts
, N_VERSION
);
1793 if (!strcasecmp(value
, "ci")) {
1795 cli
->sb_feat
.nci
= true;
1797 cli
->sb_feat
.dir_version
= getnum(value
, opts
, N_VERSION
);
1801 cli
->sb_feat
.dirftype
= getnum(value
, opts
, N_FTYPE
);
1811 struct opt_params
*opts
,
1814 struct cli_params
*cli
)
1818 cli
->rtextsize
= getstr(value
, &ropts
, R_EXTSIZE
);
1821 cli
->xi
->risfile
= getnum(value
, &ropts
, R_FILE
);
1825 cli
->xi
->rtname
= getstr(value
, &ropts
, R_NAME
);
1828 cli
->rtsize
= getstr(value
, &ropts
, R_SIZE
);
1831 cli
->sb_feat
.nortalign
= getnum(value
, &ropts
, R_NOALIGN
);
1841 struct opt_params
*opts
,
1844 struct cli_params
*cli
)
1851 if (cli
->sectorsize
)
1852 conflict('s', opts
->subopts
, S_SECTSIZE
, S_SECTLOG
);
1853 sectorlog
= getnum(value
, &sopts
, S_SECTLOG
);
1854 cli
->sectorsize
= 1 << sectorlog
;
1855 cli
->lsectorsize
= cli
->sectorsize
;
1859 if (cli
->sectorsize
)
1860 conflict('s', opts
->subopts
, S_SECTLOG
, S_SECTSIZE
);
1861 cli
->sectorsize
= getnum(value
, &sopts
, S_SECTSIZE
);
1862 cli
->lsectorsize
= cli
->sectorsize
;
1872 struct opt_params
*opts
;
1875 { 'b', &bopts
, block_opts_parser
},
1876 { 'd', &dopts
, data_opts_parser
},
1877 { 'i', &iopts
, inode_opts_parser
},
1878 { 'l', &lopts
, log_opts_parser
},
1879 { 'm', &mopts
, meta_opts_parser
},
1880 { 'n', &nopts
, naming_opts_parser
},
1881 { 'r', &ropts
, rtdev_opts_parser
},
1882 { 's', &sopts
, sector_opts_parser
},
1883 { '\0', NULL
, NULL
},
1890 struct cli_params
*cli
)
1892 struct subopts
*sop
= &subopt_tab
[0];
1897 if (sop
->opt
== opt
)
1902 /* should never happen */
1907 while (*p
!= '\0') {
1908 char **subopts
= (char **)sop
->opts
->subopts
;
1912 subopt
= getsubopt(&p
, subopts
, &value
);
1914 ret
= (sop
->parser
)(sop
->opts
, subopt
, value
, cli
);
1916 unknown(opt
, value
);
1921 validate_sectorsize(
1922 struct mkfs_params
*cfg
,
1923 struct cli_params
*cli
,
1924 struct mkfs_default_params
*dft
,
1925 struct fs_topology
*ft
,
1928 int force_overwrite
)
1930 /* set configured sector sizes in preparation for checks */
1931 if (!cli
->sectorsize
) {
1932 cfg
->sectorsize
= dft
->sectorsize
;
1934 cfg
->sectorsize
= cli
->sectorsize
;
1936 cfg
->sectorlog
= libxfs_highbit32(cfg
->sectorsize
);
1939 * Before anything else, verify that we are correctly operating on
1940 * files or block devices and set the control parameters correctly.
1942 check_device_type(dfile
, &cli
->xi
->disfile
, !cli
->dsize
, !dfile
,
1943 dry_run
? NULL
: &cli
->xi
->dcreat
,
1944 force_overwrite
, "d");
1945 if (!cli
->loginternal
)
1946 check_device_type(cli
->xi
->logname
, &cli
->xi
->lisfile
,
1947 !cli
->logsize
, !cli
->xi
->logname
,
1948 dry_run
? NULL
: &cli
->xi
->lcreat
,
1949 force_overwrite
, "l");
1950 if (cli
->xi
->rtname
)
1951 check_device_type(cli
->xi
->rtname
, &cli
->xi
->risfile
,
1952 !cli
->rtsize
, !cli
->xi
->rtname
,
1953 dry_run
? NULL
: &cli
->xi
->rcreat
,
1954 force_overwrite
, "r");
1957 * Explicitly disable direct IO for image files so we don't error out on
1958 * sector size mismatches between the new filesystem and the underlying
1961 if (cli
->xi
->disfile
|| cli
->xi
->lisfile
|| cli
->xi
->risfile
)
1962 cli
->xi
->isdirect
= 0;
1964 memset(ft
, 0, sizeof(*ft
));
1965 get_topology(cli
->xi
, ft
, force_overwrite
);
1967 if (!cli
->sectorsize
) {
1969 * Unless specified manually on the command line use the
1970 * advertised sector size of the device. We use the physical
1971 * sector size unless the requested block size is smaller
1972 * than that, then we can use logical, but warn about the
1975 * Set the topology sectors if they were not probed to the
1976 * minimum supported sector size.
1979 if (!ft
->lsectorsize
)
1980 ft
->lsectorsize
= XFS_MIN_SECTORSIZE
;
1982 /* Older kernels may not have physical/logical distinction */
1983 if (!ft
->psectorsize
)
1984 ft
->psectorsize
= ft
->lsectorsize
;
1986 cfg
->sectorsize
= ft
->psectorsize
;
1987 if (cfg
->blocksize
< cfg
->sectorsize
&&
1988 cfg
->blocksize
>= ft
->lsectorsize
) {
1990 _("specified blocksize %d is less than device physical sector size %d\n"
1991 "switching to logical sector size %d\n"),
1992 cfg
->blocksize
, ft
->psectorsize
,
1994 cfg
->sectorsize
= ft
->lsectorsize
;
1997 cfg
->sectorlog
= libxfs_highbit32(cfg
->sectorsize
);
2000 /* validate specified/probed sector size */
2001 if (cfg
->sectorsize
< XFS_MIN_SECTORSIZE
||
2002 cfg
->sectorsize
> XFS_MAX_SECTORSIZE
) {
2003 fprintf(stderr
, _("illegal sector size %d\n"), cfg
->sectorsize
);
2007 if (cfg
->blocksize
< cfg
->sectorsize
) {
2009 _("block size %d cannot be smaller than sector size %d\n"),
2010 cfg
->blocksize
, cfg
->sectorsize
);
2014 if (cfg
->sectorsize
< ft
->lsectorsize
) {
2015 fprintf(stderr
, _("illegal sector size %d; hw sector is %d\n"),
2016 cfg
->sectorsize
, ft
->lsectorsize
);
2023 struct mkfs_params
*cfg
,
2024 struct cli_params
*cli
,
2025 struct mkfs_default_params
*dft
)
2028 * Blocksize and sectorsize first, other things depend on them
2029 * For RAID4/5/6 we want to align sector size and block size,
2030 * so we need to start with the device geometry extraction too.
2032 if (!cli
->blocksize
)
2033 cfg
->blocksize
= dft
->blocksize
;
2035 cfg
->blocksize
= cli
->blocksize
;
2036 cfg
->blocklog
= libxfs_highbit32(cfg
->blocksize
);
2038 /* validate block sizes are in range */
2039 if (cfg
->blocksize
< XFS_MIN_BLOCKSIZE
||
2040 cfg
->blocksize
> XFS_MAX_BLOCKSIZE
) {
2041 fprintf(stderr
, _("illegal block size %d\n"), cfg
->blocksize
);
2045 if (cli
->sb_feat
.crcs_enabled
&&
2046 cfg
->blocksize
< XFS_MIN_CRC_BLOCKSIZE
) {
2048 _("Minimum block size for CRC enabled filesystems is %d bytes.\n"),
2049 XFS_MIN_CRC_BLOCKSIZE
);
2056 * Grab log sector size and validate.
2058 * XXX: should we probe sector size on external log device rather than using
2059 * the data device sector size?
2062 validate_log_sectorsize(
2063 struct mkfs_params
*cfg
,
2064 struct cli_params
*cli
,
2065 struct mkfs_default_params
*dft
)
2068 if (cli
->loginternal
&& cli
->lsectorsize
&&
2069 cli
->lsectorsize
!= cfg
->sectorsize
) {
2071 _("Can't change sector size on internal log!\n"));
2075 if (cli
->lsectorsize
)
2076 cfg
->lsectorsize
= cli
->lsectorsize
;
2077 else if (cli
->loginternal
)
2078 cfg
->lsectorsize
= cfg
->sectorsize
;
2080 cfg
->lsectorsize
= dft
->sectorsize
;
2081 cfg
->lsectorlog
= libxfs_highbit32(cfg
->lsectorsize
);
2083 if (cfg
->lsectorsize
< XFS_MIN_SECTORSIZE
||
2084 cfg
->lsectorsize
> XFS_MAX_SECTORSIZE
||
2085 cfg
->lsectorsize
> cfg
->blocksize
) {
2086 fprintf(stderr
, _("illegal log sector size %d\n"),
2090 if (cfg
->lsectorsize
> XFS_MIN_SECTORSIZE
) {
2091 if (cli
->sb_feat
.log_version
< 2) {
2092 /* user specified non-default log version */
2094 _("Version 1 logs do not support sector size %d\n"),
2100 /* if lsu or lsunit was specified, automatically use v2 logs */
2101 if ((cli_opt_set(&lopts
, L_SU
) || cli_opt_set(&lopts
, L_SUNIT
)) &&
2102 cli
->sb_feat
.log_version
== 1) {
2104 _("log stripe unit specified, using v2 logs\n"));
2105 cli
->sb_feat
.log_version
= 2;
2111 * Check that the incoming features make sense. The CLI structure was
2112 * initialised with the default values before parsing, so we can just
2113 * check it and copy it straight across to the cfg structure if it
2117 validate_sb_features(
2118 struct mkfs_params
*cfg
,
2119 struct cli_params
*cli
)
2122 * Now we have blocks and sector sizes set up, check parameters that are
2123 * no longer optional for CRC enabled filesystems. Catch them up front
2124 * here before doing anything else.
2126 if (cli
->sb_feat
.crcs_enabled
) {
2127 /* minimum inode size is 512 bytes, rest checked later */
2128 if (cli
->inodesize
&&
2129 cli
->inodesize
< (1 << XFS_DINODE_DFL_CRC_LOG
)) {
2131 _("Minimum inode size for CRCs is %d bytes\n"),
2132 1 << XFS_DINODE_DFL_CRC_LOG
);
2136 /* inodes always aligned */
2137 if (!cli
->sb_feat
.inode_align
) {
2139 _("Inodes always aligned for CRC enabled filesytems\n"));
2143 /* lazy sb counters always on */
2144 if (!cli
->sb_feat
.lazy_sb_counters
) {
2146 _("Lazy superblock counted always enabled for CRC enabled filesytems\n"));
2150 /* version 2 logs always on */
2151 if (cli
->sb_feat
.log_version
!= 2) {
2153 _("V2 logs always enabled for CRC enabled filesytems\n"));
2157 /* attr2 always on */
2158 if (cli
->sb_feat
.attr_version
!= 2) {
2160 _("V2 attribute format always enabled on CRC enabled filesytems\n"));
2164 /* 32 bit project quota always on */
2165 /* attr2 always on */
2166 if (cli
->sb_feat
.projid16bit
) {
2168 _("32 bit Project IDs always enabled on CRC enabled filesytems\n"));
2172 /* ftype always on */
2173 if (!cli
->sb_feat
.dirftype
) {
2175 _("Directory ftype field always enabled on CRC enabled filesytems\n"));
2181 * The kernel doesn't currently support crc=0,finobt=1
2182 * filesystems. If crcs are not enabled and the user has not
2183 * explicitly turned finobt on, then silently turn it off to
2184 * avoid an unnecessary warning.
2185 * If the user explicitly tried to use crc=0,finobt=1,
2186 * then issue an error.
2187 * The same is also for sparse inodes.
2189 if (cli
->sb_feat
.finobt
&& cli_opt_set(&mopts
, M_FINOBT
)) {
2191 _("finobt not supported without CRC support\n"));
2194 cli
->sb_feat
.finobt
= false;
2196 if (cli
->sb_feat
.spinodes
) {
2198 _("sparse inodes not supported without CRC support\n"));
2201 cli
->sb_feat
.spinodes
= false;
2203 if (cli
->sb_feat
.rmapbt
) {
2205 _("rmapbt not supported without CRC support\n"));
2208 cli
->sb_feat
.rmapbt
= false;
2210 if (cli
->sb_feat
.reflink
) {
2212 _("reflink not supported without CRC support\n"));
2215 cli
->sb_feat
.reflink
= false;
2218 if ((cli
->fsx
.fsx_xflags
& FS_XFLAG_COWEXTSIZE
) &&
2219 !cli
->sb_feat
.reflink
) {
2221 _("cowextsize not supported without reflink support\n"));
2225 if (cli
->sb_feat
.rmapbt
&& cli
->xi
->rtname
) {
2227 _("rmapbt not supported with realtime devices\n"));
2229 cli
->sb_feat
.rmapbt
= false;
2233 * Copy features across to config structure now.
2235 cfg
->sb_feat
= cli
->sb_feat
;
2236 if (!platform_uuid_is_null(&cli
->uuid
))
2237 platform_uuid_copy(&cfg
->uuid
, &cli
->uuid
);
2242 struct mkfs_params
*cfg
,
2247 struct sb_feat_args
*fp
= &cfg
->sb_feat
;
2250 "meta-data=%-22s isize=%-6d agcount=%lld, agsize=%lld blks\n"
2251 " =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n"
2252 " =%-22s crc=%-8u finobt=%u, sparse=%u, rmapbt=%u, reflink=%u\n"
2253 "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
2254 " =%-22s sunit=%-6u swidth=%u blks\n"
2255 "naming =version %-14u bsize=%-6u ascii-ci=%d ftype=%d\n"
2256 "log =%-22s bsize=%-6d blocks=%lld, version=%d\n"
2257 " =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n"
2258 "realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"),
2259 dfile
, cfg
->inodesize
, (long long)cfg
->agcount
,
2260 (long long)cfg
->agsize
,
2261 "", cfg
->sectorsize
, fp
->attr_version
, !fp
->projid16bit
,
2262 "", fp
->crcs_enabled
, fp
->finobt
, fp
->spinodes
, fp
->rmapbt
,
2264 "", cfg
->blocksize
, (long long)cfg
->dblocks
, cfg
->imaxpct
,
2265 "", cfg
->dsunit
, cfg
->dswidth
,
2266 fp
->dir_version
, cfg
->dirblocksize
, fp
->nci
, fp
->dirftype
,
2267 logfile
, cfg
->blocksize
, (long long)cfg
->logblocks
,
2269 "", cfg
->lsectorsize
, cfg
->lsunit
, fp
->lazy_sb_counters
,
2270 rtfile
, (int)cfg
->rtextblocks
<< cfg
->blocklog
,
2271 (long long)cfg
->rtblocks
, (long long)cfg
->rtextents
);
2275 * Format everything from the generated config into the superblock that
2276 * will be used to initialise the on-disk superblock. This is the in-memory
2277 * copy, so no need to care about endian swapping here.
2281 struct mkfs_params
*cfg
,
2282 struct xfs_mount
*mp
,
2286 strncpy(sbp
->sb_fname
, cfg
->label
, sizeof(sbp
->sb_fname
));
2288 sbp
->sb_magicnum
= XFS_SB_MAGIC
;
2289 sbp
->sb_blocksize
= cfg
->blocksize
;
2290 sbp
->sb_dblocks
= cfg
->dblocks
;
2291 sbp
->sb_rblocks
= cfg
->rtblocks
;
2292 sbp
->sb_rextents
= cfg
->rtextents
;
2293 platform_uuid_copy(&sbp
->sb_uuid
, &cfg
->uuid
);
2294 /* Only in memory; libxfs expects this as if read from disk */
2295 platform_uuid_copy(&sbp
->sb_meta_uuid
, &cfg
->uuid
);
2296 sbp
->sb_logstart
= cfg
->logstart
;
2297 sbp
->sb_rootino
= sbp
->sb_rbmino
= sbp
->sb_rsumino
= NULLFSINO
;
2298 sbp
->sb_rextsize
= cfg
->rtextblocks
;
2299 sbp
->sb_agcount
= (xfs_agnumber_t
)cfg
->agcount
;
2300 sbp
->sb_rbmblocks
= cfg
->rtbmblocks
;
2301 sbp
->sb_logblocks
= (xfs_extlen_t
)cfg
->logblocks
;
2302 sbp
->sb_sectsize
= (uint16_t)cfg
->sectorsize
;
2303 sbp
->sb_inodesize
= (uint16_t)cfg
->inodesize
;
2304 sbp
->sb_inopblock
= (uint16_t)(cfg
->blocksize
/ cfg
->inodesize
);
2305 sbp
->sb_sectlog
= (uint8_t)cfg
->sectorlog
;
2306 sbp
->sb_inodelog
= (uint8_t)cfg
->inodelog
;
2307 sbp
->sb_inopblog
= (uint8_t)(cfg
->blocklog
- cfg
->inodelog
);
2308 sbp
->sb_rextslog
= (uint8_t)(cfg
->rtextents
?
2309 libxfs_highbit32((unsigned int)cfg
->rtextents
) : 0);
2310 sbp
->sb_inprogress
= 1; /* mkfs is in progress */
2311 sbp
->sb_imax_pct
= cfg
->imaxpct
;
2314 sbp
->sb_fdblocks
= cfg
->dblocks
-
2315 cfg
->agcount
* libxfs_prealloc_blocks(mp
) -
2316 (cfg
->loginternal
? cfg
->logblocks
: 0);
2317 sbp
->sb_frextents
= 0; /* will do a free later */
2318 sbp
->sb_uquotino
= sbp
->sb_gquotino
= sbp
->sb_pquotino
= 0;
2320 sbp
->sb_unit
= cfg
->dsunit
;
2321 sbp
->sb_width
= cfg
->dswidth
;
2322 sbp
->sb_dirblklog
= cfg
->dirblocklog
- cfg
->blocklog
;
2325 * log stripe unit is stored in bytes on disk and cannot be zero
2328 if (cfg
->sb_feat
.log_version
== 2) {
2330 sbp
->sb_logsunit
= XFS_FSB_TO_B(mp
, cfg
->lsunit
);
2332 sbp
->sb_logsunit
= 1;
2334 sbp
->sb_logsunit
= 0;
2336 if (cfg
->sb_feat
.inode_align
) {
2337 int cluster_size
= XFS_INODE_BIG_CLUSTER_SIZE
;
2338 if (cfg
->sb_feat
.crcs_enabled
)
2339 cluster_size
*= cfg
->inodesize
/ XFS_DINODE_MIN_SIZE
;
2340 sbp
->sb_inoalignmt
= cluster_size
>> cfg
->blocklog
;
2342 sbp
->sb_inoalignmt
= 0;
2344 if (cfg
->lsectorsize
!= BBSIZE
|| cfg
->sectorsize
!= BBSIZE
) {
2345 sbp
->sb_logsectlog
= (uint8_t)cfg
->lsectorlog
;
2346 sbp
->sb_logsectsize
= (uint16_t)cfg
->lsectorsize
;
2348 sbp
->sb_logsectlog
= 0;
2349 sbp
->sb_logsectsize
= 0;
2354 * Sanitise the data and log devices and prepare them so libxfs can mount the
2355 * device successfully. Also check we can access the rt device if configured.
2359 struct mkfs_params
*cfg
,
2360 struct libxfs_xinit
*xi
,
2361 struct xfs_mount
*mp
,
2365 struct xfs_buf
*buf
;
2366 int whack_blks
= BTOBB(WHACK_SIZE
);
2370 * If there's an old XFS filesystem on the device with enough intact
2371 * information that we can parse the superblock, there's enough
2372 * information on disk to confuse a future xfs_repair call. To avoid
2373 * this, whack all the old secondary superblocks that we can find.
2376 zero_old_xfs_structures(xi
, sbp
);
2379 * If the data device is a file, grow out the file to its final size if
2380 * needed so that the reads for the end of the device in the mount code
2384 xi
->dsize
* xi
->dbsize
< cfg
->dblocks
* cfg
->blocksize
) {
2385 if (ftruncate(xi
->dfd
, cfg
->dblocks
* cfg
->blocksize
) < 0) {
2387 _("%s: Growing the data section failed\n"),
2392 /* update size to be able to whack blocks correctly */
2393 xi
->dsize
= BTOBB(cfg
->dblocks
* cfg
->blocksize
);
2397 * Zero out the end to obliterate any old MD RAID (or other) metadata at
2398 * the end of the device. (MD sb is ~64k from the end, take out a wider
2401 buf
= libxfs_getbuf(mp
->m_ddev_targp
, (xi
->dsize
- whack_blks
),
2403 memset(XFS_BUF_PTR(buf
), 0, WHACK_SIZE
);
2404 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2405 libxfs_purgebuf(buf
);
2408 * Now zero out the beginning of the device, to obliterate any old
2409 * filesystem signatures out there. This should take care of
2410 * swap (somewhere around the page size), jfs (32k),
2411 * ext[2,3] and reiserfs (64k) - and hopefully all else.
2413 buf
= libxfs_getbuf(mp
->m_ddev_targp
, 0, whack_blks
);
2414 memset(XFS_BUF_PTR(buf
), 0, WHACK_SIZE
);
2415 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2416 libxfs_purgebuf(buf
);
2418 /* OK, now write the superblock... */
2419 buf
= libxfs_getbuf(mp
->m_ddev_targp
, XFS_SB_DADDR
, XFS_FSS_TO_BB(mp
, 1));
2420 buf
->b_ops
= &xfs_sb_buf_ops
;
2421 memset(XFS_BUF_PTR(buf
), 0, cfg
->sectorsize
);
2422 libxfs_sb_to_disk((void *)XFS_BUF_PTR(buf
), sbp
);
2423 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2424 libxfs_purgebuf(buf
);
2426 /* ...and zero the log.... */
2427 lsunit
= sbp
->sb_logsunit
;
2429 lsunit
= sbp
->sb_logsectsize
;
2431 libxfs_log_clear(mp
->m_logdev_targp
, NULL
,
2432 XFS_FSB_TO_DADDR(mp
, cfg
->logstart
),
2433 (xfs_extlen_t
)XFS_FSB_TO_BB(mp
, cfg
->logblocks
),
2434 &sbp
->sb_uuid
, cfg
->sb_feat
.log_version
,
2435 lsunit
, XLOG_FMT
, XLOG_INIT_CYCLE
, false);
2437 /* finally, check we can write the last block in the realtime area */
2438 if (mp
->m_rtdev_targp
->dev
&& cfg
->rtblocks
> 0) {
2439 buf
= libxfs_getbuf(mp
->m_rtdev_targp
,
2440 XFS_FSB_TO_BB(mp
, cfg
->rtblocks
- 1LL),
2441 BTOBB(cfg
->blocksize
));
2442 memset(XFS_BUF_PTR(buf
), 0, cfg
->blocksize
);
2443 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2444 libxfs_purgebuf(buf
);
2450 * XXX: this code is mostly common with the kernel growfs code.
2451 * These initialisations should be pulled into libxfs to keep the
2452 * kernel/userspace header initialisation code the same.
2455 initialise_ag_headers(
2456 struct mkfs_params
*cfg
,
2457 struct xfs_mount
*mp
,
2459 xfs_agnumber_t agno
,
2460 int *worst_freelist
)
2462 struct xfs_perag
*pag
= libxfs_perag_get(mp
, agno
);
2463 struct xfs_agfl
*agfl
;
2464 struct xfs_agf
*agf
;
2465 struct xfs_agi
*agi
;
2466 struct xfs_buf
*buf
;
2467 struct xfs_btree_block
*block
;
2468 struct xfs_alloc_rec
*arec
;
2469 struct xfs_alloc_rec
*nrec
;
2471 uint64_t agsize
= cfg
->agsize
;
2472 xfs_agblock_t agblocks
;
2473 bool is_log_ag
= false;
2476 if (cfg
->loginternal
&& agno
== cfg
->logagno
)
2482 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2483 XFS_AG_DADDR(mp
, agno
, XFS_SB_DADDR
),
2484 XFS_FSS_TO_BB(mp
, 1));
2485 buf
->b_ops
= &xfs_sb_buf_ops
;
2486 memset(XFS_BUF_PTR(buf
), 0, cfg
->sectorsize
);
2487 libxfs_sb_to_disk((void *)XFS_BUF_PTR(buf
), sbp
);
2488 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2491 * AG header block: freespace
2493 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2494 XFS_AG_DADDR(mp
, agno
, XFS_AGF_DADDR(mp
)),
2495 XFS_FSS_TO_BB(mp
, 1));
2496 buf
->b_ops
= &xfs_agf_buf_ops
;
2497 agf
= XFS_BUF_TO_AGF(buf
);
2498 memset(agf
, 0, cfg
->sectorsize
);
2499 if (agno
== cfg
->agcount
- 1)
2500 agsize
= cfg
->dblocks
- (xfs_rfsblock_t
)(agno
* agsize
);
2501 agf
->agf_magicnum
= cpu_to_be32(XFS_AGF_MAGIC
);
2502 agf
->agf_versionnum
= cpu_to_be32(XFS_AGF_VERSION
);
2503 agf
->agf_seqno
= cpu_to_be32(agno
);
2504 agf
->agf_length
= cpu_to_be32(agsize
);
2505 agf
->agf_roots
[XFS_BTNUM_BNOi
] = cpu_to_be32(XFS_BNO_BLOCK(mp
));
2506 agf
->agf_roots
[XFS_BTNUM_CNTi
] = cpu_to_be32(XFS_CNT_BLOCK(mp
));
2507 agf
->agf_levels
[XFS_BTNUM_BNOi
] = cpu_to_be32(1);
2508 agf
->agf_levels
[XFS_BTNUM_CNTi
] = cpu_to_be32(1);
2509 pag
->pagf_levels
[XFS_BTNUM_BNOi
] = 1;
2510 pag
->pagf_levels
[XFS_BTNUM_CNTi
] = 1;
2512 if (xfs_sb_version_hasrmapbt(sbp
)) {
2513 agf
->agf_roots
[XFS_BTNUM_RMAPi
] = cpu_to_be32(XFS_RMAP_BLOCK(mp
));
2514 agf
->agf_levels
[XFS_BTNUM_RMAPi
] = cpu_to_be32(1);
2515 agf
->agf_rmap_blocks
= cpu_to_be32(1);
2518 if (xfs_sb_version_hasreflink(sbp
)) {
2519 agf
->agf_refcount_root
= cpu_to_be32(libxfs_refc_block(mp
));
2520 agf
->agf_refcount_level
= cpu_to_be32(1);
2521 agf
->agf_refcount_blocks
= cpu_to_be32(1);
2524 agf
->agf_flfirst
= 0;
2525 agf
->agf_fllast
= cpu_to_be32(XFS_AGFL_SIZE(mp
) - 1);
2526 agf
->agf_flcount
= 0;
2527 agblocks
= (xfs_agblock_t
)(agsize
- libxfs_prealloc_blocks(mp
));
2528 agf
->agf_freeblks
= cpu_to_be32(agblocks
);
2529 agf
->agf_longest
= cpu_to_be32(agblocks
);
2531 if (xfs_sb_version_hascrc(sbp
))
2532 platform_uuid_copy(&agf
->agf_uuid
, &sbp
->sb_uuid
);
2535 be32_add_cpu(&agf
->agf_freeblks
, -(int64_t)cfg
->logblocks
);
2536 agf
->agf_longest
= cpu_to_be32(agsize
-
2537 XFS_FSB_TO_AGBNO(mp
, cfg
->logstart
) - cfg
->logblocks
);
2539 if (libxfs_alloc_min_freelist(mp
, pag
) > *worst_freelist
)
2540 *worst_freelist
= libxfs_alloc_min_freelist(mp
, pag
);
2541 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2544 * AG freelist header block
2546 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2547 XFS_AG_DADDR(mp
, agno
, XFS_AGFL_DADDR(mp
)),
2548 XFS_FSS_TO_BB(mp
, 1));
2549 buf
->b_ops
= &xfs_agfl_buf_ops
;
2550 agfl
= XFS_BUF_TO_AGFL(buf
);
2551 /* setting to 0xff results in initialisation to NULLAGBLOCK */
2552 memset(agfl
, 0xff, cfg
->sectorsize
);
2553 if (xfs_sb_version_hascrc(sbp
)) {
2554 agfl
->agfl_magicnum
= cpu_to_be32(XFS_AGFL_MAGIC
);
2555 agfl
->agfl_seqno
= cpu_to_be32(agno
);
2556 platform_uuid_copy(&agfl
->agfl_uuid
, &sbp
->sb_uuid
);
2557 for (bucket
= 0; bucket
< XFS_AGFL_SIZE(mp
); bucket
++)
2558 agfl
->agfl_bno
[bucket
] = cpu_to_be32(NULLAGBLOCK
);
2561 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2564 * AG header block: inodes
2566 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2567 XFS_AG_DADDR(mp
, agno
, XFS_AGI_DADDR(mp
)),
2568 XFS_FSS_TO_BB(mp
, 1));
2569 agi
= XFS_BUF_TO_AGI(buf
);
2570 buf
->b_ops
= &xfs_agi_buf_ops
;
2571 memset(agi
, 0, cfg
->sectorsize
);
2572 agi
->agi_magicnum
= cpu_to_be32(XFS_AGI_MAGIC
);
2573 agi
->agi_versionnum
= cpu_to_be32(XFS_AGI_VERSION
);
2574 agi
->agi_seqno
= cpu_to_be32(agno
);
2575 agi
->agi_length
= cpu_to_be32(agsize
);
2577 agi
->agi_root
= cpu_to_be32(XFS_IBT_BLOCK(mp
));
2578 agi
->agi_level
= cpu_to_be32(1);
2579 if (xfs_sb_version_hasfinobt(sbp
)) {
2580 agi
->agi_free_root
= cpu_to_be32(XFS_FIBT_BLOCK(mp
));
2581 agi
->agi_free_level
= cpu_to_be32(1);
2583 agi
->agi_freecount
= 0;
2584 agi
->agi_newino
= cpu_to_be32(NULLAGINO
);
2585 agi
->agi_dirino
= cpu_to_be32(NULLAGINO
);
2586 if (xfs_sb_version_hascrc(sbp
))
2587 platform_uuid_copy(&agi
->agi_uuid
, &sbp
->sb_uuid
);
2588 for (c
= 0; c
< XFS_AGI_UNLINKED_BUCKETS
; c
++)
2589 agi
->agi_unlinked
[c
] = cpu_to_be32(NULLAGINO
);
2590 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2593 * BNO btree root block
2595 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2596 XFS_AGB_TO_DADDR(mp
, agno
, XFS_BNO_BLOCK(mp
)),
2597 BTOBB(cfg
->blocksize
));
2598 buf
->b_ops
= &xfs_allocbt_buf_ops
;
2599 block
= XFS_BUF_TO_BLOCK(buf
);
2600 memset(block
, 0, cfg
->blocksize
);
2601 libxfs_btree_init_block(mp
, buf
, XFS_BTNUM_BNO
, 0, 1, agno
, 0);
2603 arec
= XFS_ALLOC_REC_ADDR(mp
, block
, 1);
2604 arec
->ar_startblock
= cpu_to_be32(libxfs_prealloc_blocks(mp
));
2606 xfs_agblock_t start
= XFS_FSB_TO_AGBNO(mp
, cfg
->logstart
);
2608 ASSERT(start
>= libxfs_prealloc_blocks(mp
));
2609 if (start
!= libxfs_prealloc_blocks(mp
)) {
2611 * Modify first record to pad stripe align of log
2613 arec
->ar_blockcount
= cpu_to_be32(start
-
2614 libxfs_prealloc_blocks(mp
));
2617 * Insert second record at start of internal log
2618 * which then gets trimmed.
2620 nrec
->ar_startblock
= cpu_to_be32(
2621 be32_to_cpu(arec
->ar_startblock
) +
2622 be32_to_cpu(arec
->ar_blockcount
));
2624 be16_add_cpu(&block
->bb_numrecs
, 1);
2627 * Change record start to after the internal log
2629 be32_add_cpu(&arec
->ar_startblock
, cfg
->logblocks
);
2632 * Calculate the record block count and check for the case where
2633 * the log might have consumed all available space in the AG. If
2634 * so, reset the record count to 0 to avoid exposure of an invalid
2635 * record start block.
2637 arec
->ar_blockcount
= cpu_to_be32(agsize
-
2638 be32_to_cpu(arec
->ar_startblock
));
2639 if (!arec
->ar_blockcount
)
2640 block
->bb_numrecs
= 0;
2642 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2645 * CNT btree root block
2647 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2648 XFS_AGB_TO_DADDR(mp
, agno
, XFS_CNT_BLOCK(mp
)),
2649 BTOBB(cfg
->blocksize
));
2650 buf
->b_ops
= &xfs_allocbt_buf_ops
;
2651 block
= XFS_BUF_TO_BLOCK(buf
);
2652 memset(block
, 0, cfg
->blocksize
);
2653 libxfs_btree_init_block(mp
, buf
, XFS_BTNUM_CNT
, 0, 1, agno
, 0);
2655 arec
= XFS_ALLOC_REC_ADDR(mp
, block
, 1);
2656 arec
->ar_startblock
= cpu_to_be32(libxfs_prealloc_blocks(mp
));
2658 xfs_agblock_t start
= XFS_FSB_TO_AGBNO(mp
, cfg
->logstart
);
2660 ASSERT(start
>= libxfs_prealloc_blocks(mp
));
2661 if (start
!= libxfs_prealloc_blocks(mp
)) {
2662 arec
->ar_blockcount
= cpu_to_be32(start
-
2663 libxfs_prealloc_blocks(mp
));
2665 nrec
->ar_startblock
= cpu_to_be32(
2666 be32_to_cpu(arec
->ar_startblock
) +
2667 be32_to_cpu(arec
->ar_blockcount
));
2669 be16_add_cpu(&block
->bb_numrecs
, 1);
2671 be32_add_cpu(&arec
->ar_startblock
, cfg
->logblocks
);
2674 * Calculate the record block count and check for the case where
2675 * the log might have consumed all available space in the AG. If
2676 * so, reset the record count to 0 to avoid exposure of an invalid
2677 * record start block.
2679 arec
->ar_blockcount
= cpu_to_be32(agsize
-
2680 be32_to_cpu(arec
->ar_startblock
));
2681 if (!arec
->ar_blockcount
)
2682 block
->bb_numrecs
= 0;
2684 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2687 * refcount btree root block
2689 if (xfs_sb_version_hasreflink(sbp
)) {
2690 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2691 XFS_AGB_TO_DADDR(mp
, agno
, libxfs_refc_block(mp
)),
2692 BTOBB(cfg
->blocksize
));
2693 buf
->b_ops
= &xfs_refcountbt_buf_ops
;
2695 block
= XFS_BUF_TO_BLOCK(buf
);
2696 memset(block
, 0, cfg
->blocksize
);
2697 libxfs_btree_init_block(mp
, buf
, XFS_BTNUM_REFC
, 0, 0, agno
, 0);
2698 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2702 * INO btree root block
2704 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2705 XFS_AGB_TO_DADDR(mp
, agno
, XFS_IBT_BLOCK(mp
)),
2706 BTOBB(cfg
->blocksize
));
2707 buf
->b_ops
= &xfs_inobt_buf_ops
;
2708 block
= XFS_BUF_TO_BLOCK(buf
);
2709 memset(block
, 0, cfg
->blocksize
);
2710 libxfs_btree_init_block(mp
, buf
, XFS_BTNUM_INO
, 0, 0, agno
, 0);
2711 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2714 * Free INO btree root block
2716 if (xfs_sb_version_hasfinobt(sbp
)) {
2717 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2718 XFS_AGB_TO_DADDR(mp
, agno
, XFS_FIBT_BLOCK(mp
)),
2719 BTOBB(cfg
->blocksize
));
2720 buf
->b_ops
= &xfs_inobt_buf_ops
;
2721 block
= XFS_BUF_TO_BLOCK(buf
);
2722 memset(block
, 0, cfg
->blocksize
);
2723 libxfs_btree_init_block(mp
, buf
, XFS_BTNUM_FINO
, 0, 0, agno
, 0);
2724 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2727 /* RMAP btree root block */
2728 if (xfs_sb_version_hasrmapbt(sbp
)) {
2729 struct xfs_rmap_rec
*rrec
;
2731 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2732 XFS_AGB_TO_DADDR(mp
, agno
, XFS_RMAP_BLOCK(mp
)),
2733 BTOBB(cfg
->blocksize
));
2734 buf
->b_ops
= &xfs_rmapbt_buf_ops
;
2735 block
= XFS_BUF_TO_BLOCK(buf
);
2736 memset(block
, 0, cfg
->blocksize
);
2738 libxfs_btree_init_block(mp
, buf
, XFS_BTNUM_RMAP
, 0, 0, agno
, 0);
2741 * mark the AG header regions as static metadata
2742 * The BNO btree block is the first block after the
2743 * headers, so it's location defines the size of region
2744 * the static metadata consumes.
2746 rrec
= XFS_RMAP_REC_ADDR(block
, 1);
2747 rrec
->rm_startblock
= 0;
2748 rrec
->rm_blockcount
= cpu_to_be32(XFS_BNO_BLOCK(mp
));
2749 rrec
->rm_owner
= cpu_to_be64(XFS_RMAP_OWN_FS
);
2750 rrec
->rm_offset
= 0;
2751 be16_add_cpu(&block
->bb_numrecs
, 1);
2753 /* account freespace btree root blocks */
2754 rrec
= XFS_RMAP_REC_ADDR(block
, 2);
2755 rrec
->rm_startblock
= cpu_to_be32(XFS_BNO_BLOCK(mp
));
2756 rrec
->rm_blockcount
= cpu_to_be32(2);
2757 rrec
->rm_owner
= cpu_to_be64(XFS_RMAP_OWN_AG
);
2758 rrec
->rm_offset
= 0;
2759 be16_add_cpu(&block
->bb_numrecs
, 1);
2761 /* account inode btree root blocks */
2762 rrec
= XFS_RMAP_REC_ADDR(block
, 3);
2763 rrec
->rm_startblock
= cpu_to_be32(XFS_IBT_BLOCK(mp
));
2764 rrec
->rm_blockcount
= cpu_to_be32(XFS_RMAP_BLOCK(mp
) -
2766 rrec
->rm_owner
= cpu_to_be64(XFS_RMAP_OWN_INOBT
);
2767 rrec
->rm_offset
= 0;
2768 be16_add_cpu(&block
->bb_numrecs
, 1);
2770 /* account for rmap btree root */
2771 rrec
= XFS_RMAP_REC_ADDR(block
, 4);
2772 rrec
->rm_startblock
= cpu_to_be32(XFS_RMAP_BLOCK(mp
));
2773 rrec
->rm_blockcount
= cpu_to_be32(1);
2774 rrec
->rm_owner
= cpu_to_be64(XFS_RMAP_OWN_AG
);
2775 rrec
->rm_offset
= 0;
2776 be16_add_cpu(&block
->bb_numrecs
, 1);
2778 /* account for refcount btree root */
2779 if (xfs_sb_version_hasreflink(sbp
)) {
2780 rrec
= XFS_RMAP_REC_ADDR(block
, 5);
2781 rrec
->rm_startblock
= cpu_to_be32(libxfs_refc_block(mp
));
2782 rrec
->rm_blockcount
= cpu_to_be32(1);
2783 rrec
->rm_owner
= cpu_to_be64(XFS_RMAP_OWN_REFC
);
2784 rrec
->rm_offset
= 0;
2785 be16_add_cpu(&block
->bb_numrecs
, 1);
2788 /* account for the log space */
2790 rrec
= XFS_RMAP_REC_ADDR(block
,
2791 be16_to_cpu(block
->bb_numrecs
) + 1);
2792 rrec
->rm_startblock
= cpu_to_be32(
2793 XFS_FSB_TO_AGBNO(mp
, cfg
->logstart
));
2794 rrec
->rm_blockcount
= cpu_to_be32(cfg
->logblocks
);
2795 rrec
->rm_owner
= cpu_to_be64(XFS_RMAP_OWN_LOG
);
2796 rrec
->rm_offset
= 0;
2797 be16_add_cpu(&block
->bb_numrecs
, 1);
2800 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2803 libxfs_perag_put(pag
);
2807 initialise_ag_freespace(
2808 struct xfs_mount
*mp
,
2809 xfs_agnumber_t agno
,
2812 struct xfs_alloc_arg args
;
2813 struct xfs_trans
*tp
;
2814 struct xfs_trans_res tres
= {0};
2817 c
= libxfs_trans_alloc(mp
, &tres
, worst_freelist
, 0, 0, &tp
);
2821 memset(&args
, 0, sizeof(args
));
2826 args
.pag
= libxfs_perag_get(mp
, agno
);
2828 libxfs_alloc_fix_freelist(&args
, 0);
2829 libxfs_perag_put(args
.pag
);
2830 libxfs_trans_commit(tp
);
2834 * rewrite several secondary superblocks with the root inode number filled out.
2835 * This can help repair recovery from a trashed primary superblock without
2836 * losing the root inode.
2839 rewrite_secondary_superblocks(
2840 struct xfs_mount
*mp
)
2842 struct xfs_buf
*buf
;
2844 /* rewrite the last superblock */
2845 buf
= libxfs_readbuf(mp
->m_dev
,
2846 XFS_AGB_TO_DADDR(mp
, mp
->m_sb
.sb_agcount
- 1,
2848 XFS_FSS_TO_BB(mp
, 1),
2849 LIBXFS_EXIT_ON_FAILURE
, &xfs_sb_buf_ops
);
2850 XFS_BUF_TO_SBP(buf
)->sb_rootino
= cpu_to_be64(mp
->m_sb
.sb_rootino
);
2851 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2853 /* and one in the middle for luck if there's enough AGs for that */
2854 if (mp
->m_sb
.sb_agcount
<= 2)
2857 buf
= libxfs_readbuf(mp
->m_dev
,
2858 XFS_AGB_TO_DADDR(mp
, (mp
->m_sb
.sb_agcount
- 1) / 2,
2860 XFS_FSS_TO_BB(mp
, 1),
2861 LIBXFS_EXIT_ON_FAILURE
, &xfs_sb_buf_ops
);
2862 XFS_BUF_TO_SBP(buf
)->sb_rootino
= cpu_to_be64(mp
->m_sb
.sb_rootino
);
2863 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2872 xfs_agnumber_t agno
;
2879 xfs_rfsblock_t dblocks
;
2889 int force_overwrite
;
2904 xfs_agnumber_t logagno
;
2905 xfs_rfsblock_t logblocks
;
2909 xfs_fsblock_t logstart
;
2921 xfs_extlen_t nbmblocks
;
2932 xfs_rfsblock_t rtblocks
;
2933 xfs_extlen_t rtextblocks
;
2934 xfs_rtblock_t rtextents
;
2940 uint64_t sector_mask
;
2941 uint64_t tmp_agsize
;
2945 struct fs_topology ft
;
2946 struct sb_feat_args sb_feat
;
2947 /* build time defaults */
2948 struct mkfs_default_params dft
= {
2949 .source
= "package build definitions",
2950 .sectorsize
= XFS_MIN_SECTORSIZE
,
2951 .blocksize
= 1 << XFS_DFL_BLOCKSIZE_LOG
,
2955 .dir_version
= XFS_DFL_DIR_VERSION
,
2956 .inode_align
= XFS_IFLAG_ALIGN
,
2958 .lazy_sb_counters
= true,
2959 .projid16bit
= false,
2960 .crcs_enabled
= true,
2966 .parent_pointers
= false,
2971 struct cli_params cli
= {
2974 struct mkfs_params cfg
= {};
2976 platform_uuid_generate(&cli
.uuid
);
2977 progname
= basename(argv
[0]);
2978 setlocale(LC_ALL
, "");
2979 bindtextdomain(PACKAGE
, LOCALEDIR
);
2980 textdomain(PACKAGE
);
2983 * TODO: Sourcing defaults from a config file
2985 * Before anything else, see if there's a config file with different
2986 * defaults. If a file exists in <package location>, read in the new
2987 * default values and overwrite them in the &dft structure. This way the
2988 * new defaults will apply before we parse the CLI, and the CLI will
2989 * still be able to override them. Emit a message to indicate where the
2990 * defaults being used came from.
2992 printf(_("Default configuration sourced from %s\n"), dft
.source
);
2994 /* copy new defaults into CLI parsing structure */
2995 memcpy(&cli
.sb_feat
, &dft
.sb_feat
, sizeof(cli
.sb_feat
));
2996 memcpy(&cli
.fsx
, &dft
.fsx
, sizeof(cli
.fsx
));
2999 * Initialise cli parameters that can be set to zero to an appropriate
3000 * value so we can tell if they have been set or or changed from the
3003 cli
.loginternal
= 1; /* internal by default */
3005 agsize
= daflag
= dasize
= dblocks
= 0;
3006 ilflag
= imflag
= ipflag
= isflag
= 0;
3007 liflag
= laflag
= lsflag
= lsuflag
= lsunitflag
= ldflag
= lvflag
= 0;
3009 logagno
= logblocks
= rtblocks
= rtextblocks
= 0;
3010 dry_run
= nlflag
= nsflag
= nvflag
= 0;
3011 dirblocklog
= dirblocksize
= 0;
3013 imaxpct
= inodelog
= inopblock
= isize
= 0;
3014 dfile
= logfile
= rtfile
= NULL
;
3015 dsize
= logsize
= rtsize
= rtextsize
= protofile
= NULL
;
3016 dsu
= dsw
= dsunit
= dswidth
= lalign
= lsu
= lsunit
= 0;
3017 dsflag
= nodsflag
= norsflag
= 0;
3018 force_overwrite
= 0;
3020 memset(&fsx
, 0, sizeof(fsx
));
3022 memset(&xi
, 0, sizeof(xi
));
3023 xi
.isdirect
= LIBXFS_DIRECT
;
3024 xi
.isreadonly
= LIBXFS_EXCLUSIVELY
;
3026 while ((c
= getopt(argc
, argv
, "b:d:i:l:L:m:n:KNp:qr:s:CfV")) != EOF
) {
3030 force_overwrite
= 1;
3034 parse_subopts(c
, optarg
, &cli
);
3037 parse_subopts(c
, optarg
, &cli
);
3039 /* temp don't break code */
3040 agcount
= cli
.agcount
;
3041 if (cli_opt_set(&dopts
, D_AGSIZE
)) {
3042 agsize
= getnum(cli
.agsize
, &dopts
, D_AGSIZE
);
3045 daflag
= cli_opt_set(&dopts
, D_AGCOUNT
);
3047 dsunit
= cli
.dsunit
;
3048 dswidth
= cli
.dswidth
;
3050 if (cli_opt_set(&dopts
, D_SU
)) {
3051 dsu
= getnum(cli
.dsu
, &dopts
, D_SU
);
3054 dsflag
|= cli_opt_set(&dopts
, D_SW
) ||
3055 cli_opt_set(&dopts
, D_SUNIT
) ||
3056 cli_opt_set(&dopts
, D_SWIDTH
);
3057 nodsflag
= cli_opt_set(&dopts
, D_NOALIGN
);
3059 fsx
.fsx_xflags
|= cli
.fsx
.fsx_xflags
;
3060 fsx
.fsx_projid
= cli
.fsx
.fsx_projid
;
3061 fsx
.fsx_extsize
= cli
.fsx
.fsx_extsize
;
3062 /* end temp don't break code */
3065 parse_subopts(c
, optarg
, &cli
);
3067 /* temp don't break code */
3068 isize
= cli
.inodesize
;
3069 inodelog
= libxfs_highbit32(isize
);
3070 inopblock
= cli
.inopblock
;
3071 ilflag
= cli_opt_set(&iopts
, I_LOG
);
3072 isflag
= cli_opt_set(&iopts
, I_SIZE
);
3073 ipflag
= cli_opt_set(&iopts
, I_PERBLOCK
);
3075 imaxpct
= cli
.imaxpct
;
3076 imflag
= cli_opt_set(&iopts
, I_MAXPCT
);
3077 /* end temp don't break code */
3080 parse_subopts(c
, optarg
, &cli
);
3082 /* temp don't break code */
3083 logagno
= cli
.logagno
;
3084 loginternal
= cli
.loginternal
;
3085 logfile
= xi
.logname
;
3086 logsize
= cli
.logsize
;
3088 lsunit
= cli
.lsunit
;
3089 lsunitflag
= cli_opt_set(&lopts
, L_SUNIT
);
3090 if (cli_opt_set(&lopts
, L_SU
)) {
3091 lsu
= getnum(cli
.lsu
, &lopts
, L_SU
);
3095 laflag
= cli_opt_set(&lopts
, L_AGNUM
);
3096 liflag
= cli_opt_set(&lopts
, L_INTERNAL
);
3097 ldflag
= cli_opt_set(&lopts
, L_NAME
) ||
3098 cli_opt_set(&lopts
, L_DEV
);
3099 lvflag
= cli_opt_set(&lopts
, L_VERSION
);
3100 /* end temp don't break code */
3103 if (strlen(optarg
) > sizeof(sbp
->sb_fname
))
3104 illegal(optarg
, "L");
3108 parse_subopts(c
, optarg
, &cli
);
3110 /* temp don't break code */
3111 platform_uuid_copy(&uuid
, &cli
.uuid
);
3112 /* end temp don't break code */
3115 parse_subopts(c
, optarg
, &cli
);
3117 /* temp don't break code */
3118 if ((nsflag
= cli_opt_set(&nopts
, N_SIZE
)))
3119 dirblocksize
= getnum(cli
.dirblocksize
, &nopts
, N_SIZE
);
3120 dirblocklog
= cli
.dirblocklog
;
3122 nlflag
= cli_opt_set(&nopts
, N_LOG
);
3123 /* end temp don't break code */
3133 respec('p', NULL
, 0);
3140 parse_subopts(c
, optarg
, &cli
);
3142 /* temp don't break code */
3143 rtextsize
= cli
.rtextsize
;
3144 rtsize
= cli
.rtsize
;
3145 norsflag
= cli
.sb_feat
.nortalign
;
3146 /* end temp don't break code */
3150 printf(_("%s version %s\n"), progname
, VERSION
);
3153 unknown(optopt
, "");
3156 if (argc
- optind
> 1) {
3157 fprintf(stderr
, _("extra arguments\n"));
3159 } else if (argc
- optind
== 1) {
3160 dfile
= xi
.volname
= getstr(argv
[optind
], &dopts
, D_NAME
);
3164 /* temp don't break code */
3165 sb_feat
= cli
.sb_feat
;
3166 /* end temp don't break code */
3169 * Extract as much of the valid config as we can from the CLI input
3170 * before opening the libxfs devices.
3172 validate_blocksize(&cfg
, &cli
, &dft
);
3173 validate_sectorsize(&cfg
, &cli
, &dft
, &ft
, dfile
, dry_run
,
3175 validate_log_sectorsize(&cfg
, &cli
, &dft
);
3176 validate_sb_features(&cfg
, &cli
);
3178 /* temp don't break code */
3179 sectorsize
= cfg
.sectorsize
;
3180 sectorlog
= cfg
.sectorlog
;
3181 blocksize
= cfg
.blocksize
;
3182 blocklog
= cfg
.blocklog
;
3183 lsectorsize
= cfg
.lsectorsize
;
3184 lsectorlog
= cfg
.lsectorlog
;
3185 platform_uuid_copy(&uuid
, &cfg
.uuid
);
3186 sb_feat
= cfg
.sb_feat
;
3187 /* end temp don't break code */
3189 if (nsflag
|| nlflag
) {
3190 if (dirblocksize
< blocksize
||
3191 dirblocksize
> XFS_MAX_BLOCKSIZE
) {
3192 fprintf(stderr
, _("illegal directory block size %d\n"),
3197 if (blocksize
< (1 << XFS_MIN_REC_DIRSIZE
))
3198 dirblocklog
= XFS_MIN_REC_DIRSIZE
;
3200 dirblocklog
= blocklog
;
3201 dirblocksize
= 1 << dirblocklog
;
3208 dbytes
= getnum(dsize
, &dopts
, D_SIZE
);
3209 if (dbytes
% XFS_MIN_BLOCKSIZE
) {
3211 _("illegal data length %lld, not a multiple of %d\n"),
3212 (long long)dbytes
, XFS_MIN_BLOCKSIZE
);
3215 dblocks
= (xfs_rfsblock_t
)(dbytes
>> blocklog
);
3216 if (dbytes
% blocksize
)
3217 fprintf(stderr
, _("warning: "
3218 "data length %lld not a multiple of %d, truncated to %lld\n"),
3219 (long long)dbytes
, blocksize
,
3220 (long long)(dblocks
<< blocklog
));
3223 inodelog
= blocklog
- libxfs_highbit32(inopblock
);
3224 isize
= 1 << inodelog
;
3225 } else if (!ilflag
&& !isflag
) {
3226 inodelog
= sb_feat
.crcs_enabled
? XFS_DINODE_DFL_CRC_LOG
3227 : XFS_DINODE_DFL_LOG
;
3228 isize
= 1 << inodelog
;
3230 if (sb_feat
.crcs_enabled
&& inodelog
< XFS_DINODE_DFL_CRC_LOG
) {
3232 _("Minimum inode size for CRCs is %d bytes\n"),
3233 1 << XFS_DINODE_DFL_CRC_LOG
);
3240 logbytes
= getnum(logsize
, &lopts
, L_SIZE
);
3241 if (logbytes
% XFS_MIN_BLOCKSIZE
) {
3243 _("illegal log length %lld, not a multiple of %d\n"),
3244 (long long)logbytes
, XFS_MIN_BLOCKSIZE
);
3247 logblocks
= (xfs_rfsblock_t
)(logbytes
>> blocklog
);
3248 if (logbytes
% blocksize
)
3250 _("warning: log length %lld not a multiple of %d, truncated to %lld\n"),
3251 (long long)logbytes
, blocksize
,
3252 (long long)(logblocks
<< blocklog
));
3257 rtbytes
= getnum(rtsize
, &ropts
, R_SIZE
);
3258 if (rtbytes
% XFS_MIN_BLOCKSIZE
) {
3260 _("illegal rt length %lld, not a multiple of %d\n"),
3261 (long long)rtbytes
, XFS_MIN_BLOCKSIZE
);
3264 rtblocks
= (xfs_rfsblock_t
)(rtbytes
>> blocklog
);
3265 if (rtbytes
% blocksize
)
3267 _("warning: rt length %lld not a multiple of %d, truncated to %lld\n"),
3268 (long long)rtbytes
, blocksize
,
3269 (long long)(rtblocks
<< blocklog
));
3272 * If specified, check rt extent size against its constraints.
3275 uint64_t rtextbytes
;
3277 rtextbytes
= getnum(rtextsize
, &ropts
, R_EXTSIZE
);
3278 if (rtextbytes
% blocksize
) {
3280 _("illegal rt extent size %lld, not a multiple of %d\n"),
3281 (long long)rtextbytes
, blocksize
);
3284 rtextblocks
= (xfs_extlen_t
)(rtextbytes
>> blocklog
);
3287 * If realtime extsize has not been specified by the user,
3288 * and the underlying volume is striped, then set rtextblocks
3289 * to the stripe width.
3292 uint64_t rtextbytes
;
3294 if (!norsflag
&& !xi
.risfile
&& !(!rtsize
&& xi
.disfile
))
3295 rswidth
= ft
.rtswidth
;
3299 /* check that rswidth is a multiple of fs blocksize */
3300 if (!norsflag
&& rswidth
&& !(BBTOB(rswidth
) % blocksize
)) {
3301 rswidth
= DTOBT(rswidth
);
3302 rtextbytes
= rswidth
<< blocklog
;
3303 if (XFS_MIN_RTEXTSIZE
<= rtextbytes
&&
3304 (rtextbytes
<= XFS_MAX_RTEXTSIZE
)) {
3305 rtextblocks
= rswidth
;
3309 rtextblocks
= (blocksize
< XFS_MIN_RTEXTSIZE
) ?
3310 XFS_MIN_RTEXTSIZE
>> blocklog
: 1;
3313 ASSERT(rtextblocks
);
3316 * Check some argument sizes against mins, maxes.
3318 if (isize
> blocksize
/ XFS_MIN_INODE_PERBLOCK
||
3319 isize
< XFS_DINODE_MIN_SIZE
||
3320 isize
> XFS_DINODE_MAX_SIZE
) {
3323 fprintf(stderr
, _("illegal inode size %d\n"), isize
);
3324 maxsz
= MIN(blocksize
/ XFS_MIN_INODE_PERBLOCK
,
3325 XFS_DINODE_MAX_SIZE
);
3326 if (XFS_DINODE_MIN_SIZE
== maxsz
)
3328 _("allowable inode size with %d byte blocks is %d\n"),
3329 blocksize
, XFS_DINODE_MIN_SIZE
);
3332 _("allowable inode size with %d byte blocks is between %d and %d\n"),
3333 blocksize
, XFS_DINODE_MIN_SIZE
, maxsz
);
3337 calc_stripe_factors(dsu
, dsw
, sectorsize
, lsu
, lsectorsize
,
3338 &dsunit
, &dswidth
, &lsunit
);
3340 /* If sunit & swidth were manually specified as 0, same as noalign */
3341 if (dsflag
&& !dsunit
&& !dswidth
)
3344 xi
.setblksize
= sectorsize
;
3347 * Initialize. This will open the log and rt devices as well.
3349 if (!libxfs_init(&xi
))
3352 fprintf(stderr
, _("no device name given in argument list\n"));
3357 * Ok, Linux only has a 1024-byte resolution on device _size_,
3358 * and the sizes below are in basic 512-byte blocks,
3359 * so if we have (size % 2), on any partition, we can't get
3360 * to the last 512 bytes. The same issue exists for larger
3361 * sector sizes - we cannot write past the last sector.
3363 * So, we reduce the size (in basic blocks) to a perfect
3364 * multiple of the sector size, or 1024, whichever is larger.
3367 sector_mask
= (uint64_t)-1 << (MAX(sectorlog
, 10) - BBSHIFT
);
3368 xi
.dsize
&= sector_mask
;
3369 xi
.rtsize
&= sector_mask
;
3370 xi
.logBBsize
&= (uint64_t)-1 << (MAX(lsectorlog
, 10) - BBSHIFT
);
3373 /* don't do discards on print-only runs or on files */
3374 if (discard
&& !dry_run
) {
3376 discard_blocks(xi
.ddev
, xi
.dsize
);
3377 if (xi
.rtdev
&& !xi
.risfile
)
3378 discard_blocks(xi
.rtdev
, xi
.rtsize
);
3379 if (xi
.logdev
&& xi
.logdev
!= xi
.ddev
&& !xi
.lisfile
)
3380 discard_blocks(xi
.logdev
, xi
.logBBsize
);
3383 if (!liflag
&& !ldflag
)
3384 loginternal
= xi
.logdev
== 0;
3386 logfile
= xi
.logname
;
3387 else if (loginternal
)
3388 logfile
= _("internal log");
3389 else if (xi
.volname
&& xi
.logdev
)
3390 logfile
= _("volume log");
3392 fprintf(stderr
, _("no log subvolume or internal log\n"));
3398 if (xi
.volname
&& xi
.rtdev
)
3399 rtfile
= _("volume rt");
3402 if (dsize
&& xi
.dsize
> 0 && dblocks
> DTOBT(xi
.dsize
)) {
3404 _("size %s specified for data subvolume is too large, "
3405 "maximum is %lld blocks\n"),
3406 dsize
, (long long)DTOBT(xi
.dsize
));
3408 } else if (!dsize
&& xi
.dsize
> 0)
3409 dblocks
= DTOBT(xi
.dsize
);
3411 fprintf(stderr
, _("can't get size of data subvolume\n"));
3414 if (dblocks
< XFS_MIN_DATA_BLOCKS
) {
3416 _("size %lld of data subvolume is too small, minimum %d blocks\n"),
3417 (long long)dblocks
, XFS_MIN_DATA_BLOCKS
);
3421 if (loginternal
&& xi
.logdev
) {
3423 _("can't have both external and internal logs\n"));
3425 } else if (loginternal
&& sectorsize
!= lsectorsize
) {
3427 _("data and log sector sizes must be equal for internal logs\n"));
3431 if (xi
.dbsize
> sectorsize
) {
3433 "Warning: the data subvolume sector size %u is less than the sector size \n\
3434 reported by the device (%u).\n"),
3435 sectorsize
, xi
.dbsize
);
3437 if (!loginternal
&& xi
.lbsize
> lsectorsize
) {
3439 "Warning: the log subvolume sector size %u is less than the sector size\n\
3440 reported by the device (%u).\n"),
3441 lsectorsize
, xi
.lbsize
);
3443 if (rtsize
&& xi
.rtsize
> 0 && xi
.rtbsize
> sectorsize
) {
3445 "Warning: the realtime subvolume sector size %u is less than the sector size\n\
3446 reported by the device (%u).\n"),
3447 sectorsize
, xi
.rtbsize
);
3450 if (rtsize
&& xi
.rtsize
> 0 && rtblocks
> DTOBT(xi
.rtsize
)) {
3452 _("size %s specified for rt subvolume is too large, "
3453 "maximum is %lld blocks\n"),
3454 rtsize
, (long long)DTOBT(xi
.rtsize
));
3456 } else if (!rtsize
&& xi
.rtsize
> 0)
3457 rtblocks
= DTOBT(xi
.rtsize
);
3458 else if (rtsize
&& !xi
.rtdev
) {
3460 _("size specified for non-existent rt subvolume\n"));
3464 rtextents
= rtblocks
/ rtextblocks
;
3465 nbmblocks
= (xfs_extlen_t
)howmany(rtextents
, NBBY
* blocksize
);
3467 rtextents
= rtblocks
= 0;
3473 if (ft
.dsunit
&& ft
.dsunit
!= dsunit
) {
3475 _("%s: Specified data stripe unit %d "
3476 "is not the same as the volume stripe "
3478 progname
, dsunit
, ft
.dsunit
);
3480 if (ft
.dswidth
&& ft
.dswidth
!= dswidth
) {
3482 _("%s: Specified data stripe width %d "
3483 "is not the same as the volume stripe "
3485 progname
, dswidth
, ft
.dswidth
);
3489 dswidth
= ft
.dswidth
;
3492 } /* else dsunit & dswidth can't be set if nodsflag is set */
3494 if (dasize
) { /* User-specified AG size */
3496 * Check specified agsize is a multiple of blocksize.
3498 if (agsize
% blocksize
) {
3500 _("agsize (%lld) not a multiple of fs blk size (%d)\n"),
3501 (long long)agsize
, blocksize
);
3504 agsize
/= blocksize
;
3505 agcount
= dblocks
/ agsize
+ (dblocks
% agsize
!= 0);
3507 } else if (daflag
) { /* User-specified AG count */
3508 agsize
= dblocks
/ agcount
+ (dblocks
% agcount
!= 0);
3510 calc_default_ag_geometry(blocklog
, dblocks
,
3511 dsunit
| dswidth
, &agsize
, &agcount
);
3515 * If dsunit is a multiple of fs blocksize, then check that is a
3516 * multiple of the agsize too
3518 if (dsunit
&& !(BBTOB(dsunit
) % blocksize
) &&
3519 dswidth
&& !(BBTOB(dswidth
) % blocksize
)) {
3521 /* convert from 512 byte blocks to fs blocksize */
3522 dsunit
= DTOBT(dsunit
);
3523 dswidth
= DTOBT(dswidth
);
3526 * agsize is not a multiple of dsunit
3528 if ((agsize
% dsunit
) != 0) {
3530 * Round up to stripe unit boundary. Also make sure
3531 * that agsize is still larger than
3532 * XFS_AG_MIN_BLOCKS(blocklog)
3534 tmp_agsize
= ((agsize
+ (dsunit
- 1))/ dsunit
) * dsunit
;
3536 * Round down to stripe unit boundary if rounding up
3537 * created an AG size that is larger than the AG max.
3539 if (tmp_agsize
> XFS_AG_MAX_BLOCKS(blocklog
))
3540 tmp_agsize
= ((agsize
) / dsunit
) * dsunit
;
3542 if ((tmp_agsize
>= XFS_AG_MIN_BLOCKS(blocklog
)) &&
3543 (tmp_agsize
<= XFS_AG_MAX_BLOCKS(blocklog
))) {
3544 agsize
= tmp_agsize
;
3546 agcount
= dblocks
/agsize
+
3547 (dblocks
% agsize
!= 0);
3550 _("agsize rounded to %lld, swidth = %d\n"),
3551 (long long)agsize
, dswidth
);
3554 dsunit
= dswidth
= 0;
3557 * agsize is out of bounds, this will
3558 * print nice details & exit.
3560 validate_ag_geometry(blocklog
, dblocks
,
3566 if (dswidth
&& ((agsize
% dswidth
) == 0)
3567 && (dswidth
!= dsunit
)
3569 /* This is a non-optimal configuration because all AGs
3570 * start on the same disk in the stripe. Changing
3571 * the AG size by one sunit will guarantee that this
3574 tmp_agsize
= agsize
- dsunit
;
3575 if (tmp_agsize
< XFS_AG_MIN_BLOCKS(blocklog
)) {
3576 tmp_agsize
= agsize
+ dsunit
;
3577 if (dblocks
< agsize
) {
3578 /* oh well, nothing to do */
3579 tmp_agsize
= agsize
;
3582 if (daflag
|| dasize
) {
3584 "Warning: AG size is a multiple of stripe width. This can cause performance\n\
3585 problems by aligning all AGs on the same disk. To avoid this, run mkfs with\n\
3586 an AG size that is one stripe unit smaller, for example %llu.\n"),
3587 (unsigned long long)tmp_agsize
);
3589 agsize
= tmp_agsize
;
3590 agcount
= dblocks
/agsize
+ (dblocks
% agsize
!= 0);
3592 * If the last AG is too small, reduce the
3593 * filesystem size and drop the blocks.
3595 if ( dblocks
% agsize
!= 0 &&
3597 XFS_AG_MIN_BLOCKS(blocklog
))) {
3598 dblocks
= (xfs_rfsblock_t
)((agcount
- 1) * agsize
);
3600 ASSERT(agcount
!= 0);
3606 dsunit
= dswidth
= 0;
3609 _("%s: Stripe unit(%d) or stripe width(%d) is "
3610 "not a multiple of the block size(%d)\n"),
3611 progname
, BBTOB(dsunit
), BBTOB(dswidth
),
3618 * If the last AG is too small, reduce the filesystem size
3619 * and drop the blocks.
3621 if ( dblocks
% agsize
!= 0 &&
3622 (dblocks
% agsize
< XFS_AG_MIN_BLOCKS(blocklog
))) {
3624 dblocks
= (xfs_rfsblock_t
)((agcount
- 1) * agsize
);
3626 ASSERT(agcount
!= 0);
3629 validate_ag_geometry(blocklog
, dblocks
, agsize
, agcount
);
3632 imaxpct
= calc_default_imaxpct(blocklog
, dblocks
);
3635 * check that log sunit is modulo fsblksize or default it to dsunit.
3639 /* convert from 512 byte blocks to fs blocks */
3640 lsunit
= DTOBT(lsunit
);
3641 } else if (sb_feat
.log_version
== 2 && loginternal
&& dsunit
) {
3642 /* lsunit and dsunit now in fs blocks */
3646 if (sb_feat
.log_version
== 2 && (lsunit
* blocksize
) > 256 * 1024) {
3647 /* Warn only if specified on commandline */
3648 if (lsuflag
|| lsunitflag
) {
3650 _("log stripe unit (%d bytes) is too large (maximum is 256KiB)\n"),
3651 (lsunit
* blocksize
));
3653 _("log stripe unit adjusted to 32KiB\n"));
3655 lsunit
= (32 * 1024) >> blocklog
;
3658 min_logblocks
= max_trans_res(agsize
,
3659 sb_feat
.crcs_enabled
, sb_feat
.dir_version
,
3660 sectorlog
, blocklog
, inodelog
, dirblocklog
,
3661 sb_feat
.log_version
, lsunit
, sb_feat
.finobt
,
3662 sb_feat
.rmapbt
, sb_feat
.reflink
,
3663 sb_feat
.inode_align
);
3664 ASSERT(min_logblocks
);
3665 min_logblocks
= MAX(XFS_MIN_LOG_BLOCKS
, min_logblocks
);
3666 if (!logsize
&& dblocks
>= (1024*1024*1024) >> blocklog
)
3667 min_logblocks
= MAX(min_logblocks
, XFS_MIN_LOG_BYTES
>>blocklog
);
3668 if (logsize
&& xi
.logBBsize
> 0 && logblocks
> DTOBT(xi
.logBBsize
)) {
3670 _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
3671 logsize
, (long long)DTOBT(xi
.logBBsize
));
3673 } else if (!logsize
&& xi
.logBBsize
> 0) {
3674 logblocks
= DTOBT(xi
.logBBsize
);
3675 } else if (logsize
&& !xi
.logdev
&& !loginternal
) {
3677 _("size specified for non-existent log subvolume\n"));
3679 } else if (loginternal
&& logsize
&& logblocks
>= dblocks
) {
3680 fprintf(stderr
, _("size %lld too large for internal log\n"),
3681 (long long)logblocks
);
3683 } else if (!loginternal
&& !xi
.logdev
) {
3685 } else if (loginternal
&& !logsize
) {
3687 if (dblocks
< GIGABYTES(1, blocklog
)) {
3688 /* tiny filesystems get minimum sized logs. */
3689 logblocks
= min_logblocks
;
3690 } else if (dblocks
< GIGABYTES(16, blocklog
)) {
3693 * For small filesystems, we want to use the
3694 * XFS_MIN_LOG_BYTES for filesystems smaller than 16G if
3695 * at all possible, ramping up to 128MB at 256GB.
3697 logblocks
= MIN(XFS_MIN_LOG_BYTES
>> blocklog
,
3698 min_logblocks
* XFS_DFL_LOG_FACTOR
);
3701 * With a 2GB max log size, default to maximum size
3702 * at 4TB. This keeps the same ratio from the older
3703 * max log size of 128M at 256GB fs size. IOWs,
3704 * the ratio of fs size to log size is 2048:1.
3706 logblocks
= (dblocks
<< blocklog
) / 2048;
3707 logblocks
= logblocks
>> blocklog
;
3710 /* Ensure the chosen size meets minimum log size requirements */
3711 logblocks
= MAX(min_logblocks
, logblocks
);
3713 /* make sure the log fits wholly within an AG */
3714 if (logblocks
>= agsize
)
3715 logblocks
= min_logblocks
;
3717 /* and now clamp the size to the maximum supported size */
3718 logblocks
= MIN(logblocks
, XFS_MAX_LOG_BLOCKS
);
3719 if ((logblocks
<< blocklog
) > XFS_MAX_LOG_BYTES
)
3720 logblocks
= XFS_MAX_LOG_BYTES
>> blocklog
;
3723 validate_log_size(logblocks
, blocklog
, min_logblocks
);
3725 protostring
= setup_proto(protofile
);
3728 memset(mp
, 0, sizeof(xfs_mount_t
));
3729 sbp
->sb_blocklog
= (uint8_t)blocklog
;
3730 sbp
->sb_sectlog
= (uint8_t)sectorlog
;
3731 sbp
->sb_agblklog
= (uint8_t)log2_roundup((unsigned int)agsize
);
3732 sbp
->sb_agblocks
= (xfs_agblock_t
)agsize
;
3733 mp
->m_blkbb_log
= sbp
->sb_blocklog
- BBSHIFT
;
3734 mp
->m_sectbb_log
= sbp
->sb_sectlog
- BBSHIFT
;
3737 * sb_versionnum, finobt and rmapbt flags must be set before we use
3738 * libxfs_prealloc_blocks().
3740 sb_set_features(&mp
->m_sb
, &sb_feat
, sectorsize
, lsectorsize
, dsunit
);
3745 * Readjust the log size to fit within an AG if it was sized
3749 logblocks
= MIN(logblocks
,
3750 libxfs_alloc_ag_max_usable(mp
));
3752 /* revalidate the log size is valid if we changed it */
3753 validate_log_size(logblocks
, blocklog
, min_logblocks
);
3755 if (logblocks
> agsize
- libxfs_prealloc_blocks(mp
)) {
3757 _("internal log size %lld too large, must fit in allocation group\n"),
3758 (long long)logblocks
);
3763 if (logagno
>= agcount
) {
3765 _("log ag number %d too large, must be less than %lld\n"),
3766 logagno
, (long long)agcount
);
3770 logagno
= (xfs_agnumber_t
)(agcount
/ 2);
3772 logstart
= XFS_AGB_TO_FSB(mp
, logagno
, libxfs_prealloc_blocks(mp
));
3774 * Align the logstart at stripe unit boundary.
3777 logstart
= fixup_internal_log_stripe(mp
,
3778 lsflag
, logstart
, agsize
, lsunit
,
3779 &logblocks
, blocklog
, &lalign
);
3780 } else if (dsunit
) {
3781 logstart
= fixup_internal_log_stripe(mp
,
3782 lsflag
, logstart
, agsize
, dsunit
,
3783 &logblocks
, blocklog
, &lalign
);
3788 fixup_log_stripe_unit(lsflag
, lsunit
,
3789 &logblocks
, blocklog
);
3791 validate_log_size(logblocks
, blocklog
, min_logblocks
);
3793 /* Temp support code to set up mkfs cfg parameters */
3794 cfg
.blocksize
= blocksize
;
3795 cfg
.blocklog
= blocklog
;
3796 cfg
.sectorsize
= sectorsize
;
3797 cfg
.sectorlog
= sectorlog
;
3798 cfg
.lsectorsize
= lsectorsize
;
3799 cfg
.lsectorlog
= lsectorlog
;
3800 cfg
.dirblocksize
= dirblocksize
;
3801 cfg
.dirblocklog
= dirblocklog
;
3802 cfg
.inodesize
= isize
;
3803 cfg
.inodelog
= inodelog
;
3804 cfg
.inopblock
= inopblock
;
3806 cfg
.dblocks
= dblocks
;
3807 cfg
.logblocks
= logblocks
;
3808 cfg
.rtblocks
= rtblocks
;
3809 cfg
.rtextblocks
= rtextblocks
;
3810 cfg
.rtextents
= rtextents
;
3811 cfg
.rtbmblocks
= nbmblocks
;
3812 cfg
.dsunit
= dsunit
;
3813 cfg
.dswidth
= dswidth
;
3814 cfg
.lsunit
= lsunit
;
3815 cfg
.agsize
= agsize
;
3816 cfg
.agcount
= agcount
;
3817 cfg
.imaxpct
= imaxpct
;
3818 cfg
.loginternal
= loginternal
;
3819 cfg
.logstart
= logstart
;
3820 cfg
.logagno
= logagno
;
3822 platform_uuid_copy(&cfg
.uuid
, &uuid
);
3823 memcpy(&cfg
.sb_feat
, &sb_feat
, sizeof(sb_feat
));
3824 /* end temp support code */
3826 if (!quiet
|| dry_run
) {
3827 print_mkfs_cfg(&cfg
, dfile
, logfile
, rtfile
);
3833 * Finish setting up the superblock state ready for formatting.
3835 setup_superblock(&cfg
, mp
, sbp
);
3838 * we need the libxfs buffer cache from here on in.
3840 libxfs_buftarg_init(mp
, xi
.ddev
, xi
.logdev
, xi
.rtdev
);
3843 * Before we mount the filesystem we need to make sure the devices have
3844 * enough of the filesystem structure on them that allows libxfs to
3847 prepare_devices(&cfg
, &xi
, mp
, sbp
, force_overwrite
);
3848 mp
= libxfs_mount(mp
, sbp
, xi
.ddev
, xi
.logdev
, xi
.rtdev
, 0);
3850 fprintf(stderr
, _("%s: filesystem failed to initialize\n"),
3856 * Initialise all the static on disk metadata.
3858 for (agno
= 0; agno
< cfg
.agcount
; agno
++)
3859 initialise_ag_headers(&cfg
, mp
, sbp
, agno
, &worst_freelist
);
3862 * Initialise the freespace freelists (i.e. AGFLs) in each AG.
3864 for (agno
= 0; agno
< cfg
.agcount
; agno
++)
3865 initialise_ag_freespace(mp
, agno
, worst_freelist
);
3868 * Allocate the root inode and anything else in the proto file.
3870 parse_proto(mp
, &fsx
, &protostring
);
3873 * Protect ourselves against possible stupidity
3875 if (XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
) != 0) {
3877 _("%s: root inode created in AG %u, not AG 0\n"),
3878 progname
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
));
3883 * Re-write multiple secondary superblocks with rootinode field set
3885 if (mp
->m_sb
.sb_agcount
> 1)
3886 rewrite_secondary_superblocks(mp
);
3889 * Dump all inodes and buffers before marking us all done.
3890 * Need to drop references to inodes we still hold, first.
3892 libxfs_rtmount_destroy(mp
);
3893 libxfs_bcache_purge();
3896 * Mark the filesystem ok.
3898 buf
= libxfs_getsb(mp
, LIBXFS_EXIT_ON_FAILURE
);
3899 (XFS_BUF_TO_SBP(buf
))->sb_inprogress
= 0;
3900 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3904 libxfs_device_close(xi
.rtdev
);
3905 if (xi
.logdev
&& xi
.logdev
!= xi
.ddev
)
3906 libxfs_device_close(xi
.logdev
);
3907 libxfs_device_close(xi
.ddev
);
3919 fprintf(stderr
, _("Cannot specify both -%c %s and -%c %s\n"),
3920 opt
, tab
[oldidx
], opt
, tab
[newidx
]);
3930 fprintf(stderr
, _("Illegal value %s for -%s option\n"), value
, opt
);
3938 return (i
& (i
- 1)) == 0;
3941 static void __attribute__((noreturn
))
3947 fprintf(stderr
, _("-%c %s option requires a value\n"), opt
, tab
[idx
]);
3957 fprintf(stderr
, "-%c ", opt
);
3959 fprintf(stderr
, "%s ", tab
[idx
]);
3960 fprintf(stderr
, _("option respecified\n"));
3969 fprintf(stderr
, _("unknown option -%c %s\n"), opt
, s
);
3975 unsigned int blksize
,
3976 unsigned int sectsize
,
3983 i
= strtoll(s
, &sp
, 0);
3984 if (i
== 0 && sp
== s
)
3995 _("Blocksize must be provided prior to using 'b' suffix.\n"));
4004 _("Sectorsize must be specified prior to using 's' suffix.\n"));
4007 return i
* sectsize
;
4036 static void __attribute__((noreturn
))
4039 fprintf(stderr
, _("Usage: %s\n\
4040 /* blocksize */ [-b log=n|size=num]\n\
4041 /* metadata */ [-m crc=0|1,finobt=0|1,uuid=xxx,rmapbt=0|1,reflink=0|1]\n\
4042 /* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num,\n\
4043 (sunit=value,swidth=value|su=num,sw=num|noalign),\n\
4044 sectlog=n|sectsize=num\n\
4045 /* force overwrite */ [-f]\n\
4046 /* inode size */ [-i log=n|perblock=n|size=num,maxpct=n,attr=0|1|2,\n\
4047 projid32bit=0|1,sparse=0|1]\n\
4048 /* no discard */ [-K]\n\
4049 /* log subvol */ [-l agnum=n,internal,size=num,logdev=xxx,version=n\n\
4050 sunit=value|su=num,sectlog=n|sectsize=num,\n\
4052 /* label */ [-L label (maximum 12 characters)]\n\
4053 /* naming */ [-n log=n|size=num,version=2|ci,ftype=0|1]\n\
4054 /* no-op info only */ [-N]\n\
4055 /* prototype file */ [-p fname]\n\
4057 /* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx]\n\
4058 /* sectorsize */ [-s log=n|size=num]\n\
4059 /* version */ [-V]\n\
4061 <devicename> is required unless -d name=xxx is given.\n\
4062 <num> is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxx KiB),\n\
4063 xxxm (xxx MiB), xxxg (xxx GiB), xxxt (xxx TiB) or xxxp (xxx PiB).\n\
4064 <value> is xxx (512 byte blocks).\n"),