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
22 # include <blkid/blkid.h>
23 #endif /* ENABLE_BLKID */
24 #include "xfs_multidisk.h"
28 * Prototypes for internal functions.
30 static void conflict(char opt
, char *tab
[], int oldidx
, int newidx
);
31 static void illegal(const char *value
, const char *opt
);
32 static __attribute__((noreturn
)) void usage (void);
33 static __attribute__((noreturn
)) void reqval(char opt
, char *tab
[], int idx
);
34 static void respec(char opt
, char *tab
[], int idx
);
35 static void unknown(char opt
, char *s
);
36 static int ispow2(unsigned int i
);
39 * The configured block and sector sizes are defined as global variables so
40 * that they don't need to be passed to functions that require them.
42 unsigned int blocksize
;
43 unsigned int sectorsize
;
45 #define MAX_SUBOPTS 16
46 #define SUBOPT_NEEDS_VAL (-1LL)
47 #define MAX_CONFLICTS 8
48 #define LAST_CONFLICT (-1)
51 * Table for parsing mkfs parameters.
53 * Description of the structure members follows:
56 * Name is a single char, e.g., for '-d file', name is 'd'.
59 * Subopts is a list of strings naming suboptions. In the example above,
60 * it would contain "file". The last entry of this list has to be NULL.
62 * subopt_params MANDATORY
63 * This is a list of structs tied with subopts. For each entry in subopts,
64 * a corresponding entry has to be defined:
66 * subopt_params struct:
68 * This number, starting from zero, denotes which item in subopt_params
69 * it is. The index has to be the same as is the order in subopts list,
70 * so we can access the right item both in subopt_param and subopts.
73 * Do not set this flag when definning a subopt. It is used to remeber that
74 * this subopt was already seen, for example for conflicts detection.
77 * Do not set. It is used internally for respecification, when some options
78 * has to be parsed twice - at first as a string, then later as a number.
81 * A flag signalling whether the user-given value can use suffixes.
82 * If you want to allow the use of user-friendly values like 13k, 42G,
86 * An optional flag for subopts where the given value has to be a power
90 * If your subopt is in a conflict with some other option, specify it.
91 * Accepts the .index values of the conflicting subopts and the last
92 * member of this list has to be LAST_CONFLICT.
94 * minval, maxval OPTIONAL
95 * These options are used for automatic range check and they have to be
96 * always used together in pair. If you don't want to limit the max value,
97 * use something like UINT_MAX. If no value is given, then you must either
98 * supply your own validation, or refuse any value in the 'case
99 * X_SOMETHING' block. If you forget to define the min and max value, but
100 * call a standard function for validating user's value, it will cause an
101 * error message notifying you about this issue.
103 * (Said in another way, you can't have minval and maxval both equal
104 * to zero. But if one value is different: minval=0 and maxval=1,
107 * defaultval MANDATORY
108 * The value used if user specifies the subopt, but no value.
109 * If the subopt accepts some values (-d file=[1|0]), then this
110 * sets what is used with simple specifying the subopt (-d file).
111 * A special SUBOPT_NEEDS_VAL can be used to require a user-given
116 const char *subopts
[MAX_SUBOPTS
];
118 struct subopt_param
{
124 int conflicts
[MAX_CONFLICTS
];
127 long long defaultval
;
128 } subopt_params
[MAX_SUBOPTS
];
131 struct opt_params bopts
= {
142 .conflicts
= { B_SIZE
,
144 .minval
= XFS_MIN_BLOCKSIZE_LOG
,
145 .maxval
= XFS_MAX_BLOCKSIZE_LOG
,
146 .defaultval
= SUBOPT_NEEDS_VAL
,
151 .conflicts
= { B_LOG
,
153 .minval
= XFS_MIN_BLOCKSIZE
,
154 .maxval
= XFS_MAX_BLOCKSIZE
,
155 .defaultval
= SUBOPT_NEEDS_VAL
,
160 struct opt_params dopts
= {
183 #define D_SECTSIZE 10
187 #define D_RTINHERIT 12
189 #define D_PROJINHERIT 13
191 #define D_EXTSZINHERIT 14
196 { .index
= D_AGCOUNT
,
197 .conflicts
= { D_AGSIZE
,
200 .maxval
= XFS_MAX_AGNUMBER
,
201 .defaultval
= SUBOPT_NEEDS_VAL
,
204 .conflicts
= { LAST_CONFLICT
},
210 .conflicts
= { LAST_CONFLICT
},
211 .defaultval
= SUBOPT_NEEDS_VAL
,
214 .conflicts
= { LAST_CONFLICT
},
216 .minval
= XFS_AG_MIN_BYTES
,
218 .defaultval
= SUBOPT_NEEDS_VAL
,
221 .conflicts
= { D_NOALIGN
,
227 .defaultval
= SUBOPT_NEEDS_VAL
,
230 .conflicts
= { D_NOALIGN
,
236 .defaultval
= SUBOPT_NEEDS_VAL
,
239 .conflicts
= { D_AGCOUNT
,
242 .minval
= XFS_AG_MIN_BYTES
,
243 .maxval
= XFS_AG_MAX_BYTES
,
244 .defaultval
= SUBOPT_NEEDS_VAL
,
247 .conflicts
= { D_NOALIGN
,
254 .defaultval
= SUBOPT_NEEDS_VAL
,
257 .conflicts
= { D_NOALIGN
,
263 .defaultval
= SUBOPT_NEEDS_VAL
,
265 { .index
= D_SECTLOG
,
266 .conflicts
= { D_SECTSIZE
,
268 .minval
= XFS_MIN_SECTORSIZE_LOG
,
269 .maxval
= XFS_MAX_SECTORSIZE_LOG
,
270 .defaultval
= SUBOPT_NEEDS_VAL
,
272 { .index
= D_SECTSIZE
,
273 .conflicts
= { D_SECTLOG
,
277 .minval
= XFS_MIN_SECTORSIZE
,
278 .maxval
= XFS_MAX_SECTORSIZE
,
279 .defaultval
= SUBOPT_NEEDS_VAL
,
281 { .index
= D_NOALIGN
,
291 { .index
= D_RTINHERIT
,
292 .conflicts
= { LAST_CONFLICT
},
297 { .index
= D_PROJINHERIT
,
298 .conflicts
= { LAST_CONFLICT
},
301 .defaultval
= SUBOPT_NEEDS_VAL
,
303 { .index
= D_EXTSZINHERIT
,
304 .conflicts
= { LAST_CONFLICT
},
307 .defaultval
= SUBOPT_NEEDS_VAL
,
313 struct opt_params iopts
= {
328 #define I_PROJID32BIT 6
336 .conflicts
= { LAST_CONFLICT
},
342 .conflicts
= { I_PERBLOCK
,
345 .minval
= XFS_DINODE_MIN_LOG
,
346 .maxval
= XFS_DINODE_MAX_LOG
,
347 .defaultval
= SUBOPT_NEEDS_VAL
,
350 .conflicts
= { LAST_CONFLICT
},
353 .defaultval
= SUBOPT_NEEDS_VAL
,
355 { .index
= I_PERBLOCK
,
356 .conflicts
= { I_LOG
,
360 .minval
= XFS_MIN_INODE_PERBLOCK
,
361 .maxval
= XFS_MAX_BLOCKSIZE
/ XFS_DINODE_MIN_SIZE
,
362 .defaultval
= SUBOPT_NEEDS_VAL
,
365 .conflicts
= { I_PERBLOCK
,
369 .minval
= XFS_DINODE_MIN_SIZE
,
370 .maxval
= XFS_DINODE_MAX_SIZE
,
371 .defaultval
= SUBOPT_NEEDS_VAL
,
374 .conflicts
= { LAST_CONFLICT
},
377 .defaultval
= SUBOPT_NEEDS_VAL
,
379 { .index
= I_PROJID32BIT
,
380 .conflicts
= { LAST_CONFLICT
},
385 { .index
= I_SPINODES
,
386 .conflicts
= { LAST_CONFLICT
},
394 struct opt_params lopts
= {
419 #define L_LAZYSBCNTR 11
425 .conflicts
= { L_DEV
,
429 .defaultval
= SUBOPT_NEEDS_VAL
,
431 { .index
= L_INTERNAL
,
432 .conflicts
= { L_FILE
,
440 .conflicts
= { LAST_CONFLICT
},
442 .minval
= 2 * 1024 * 1024LL, /* XXX: XFS_MIN_LOG_BYTES */
443 .maxval
= XFS_MAX_LOG_BYTES
,
444 .defaultval
= SUBOPT_NEEDS_VAL
,
446 { .index
= L_VERSION
,
447 .conflicts
= { LAST_CONFLICT
},
450 .defaultval
= SUBOPT_NEEDS_VAL
,
455 .minval
= BTOBB(XLOG_MIN_RECORD_BSIZE
),
456 .maxval
= BTOBB(XLOG_MAX_RECORD_BSIZE
),
457 .defaultval
= SUBOPT_NEEDS_VAL
,
460 .conflicts
= { L_SUNIT
,
463 .minval
= XLOG_MIN_RECORD_BSIZE
,
464 .maxval
= XLOG_MAX_RECORD_BSIZE
,
465 .defaultval
= SUBOPT_NEEDS_VAL
,
468 .conflicts
= { L_AGNUM
,
471 .defaultval
= SUBOPT_NEEDS_VAL
,
473 { .index
= L_SECTLOG
,
474 .conflicts
= { L_SECTSIZE
,
476 .minval
= XFS_MIN_SECTORSIZE_LOG
,
477 .maxval
= XFS_MAX_SECTORSIZE_LOG
,
478 .defaultval
= SUBOPT_NEEDS_VAL
,
480 { .index
= L_SECTSIZE
,
481 .conflicts
= { L_SECTLOG
,
485 .minval
= XFS_MIN_SECTORSIZE
,
486 .maxval
= XFS_MAX_SECTORSIZE
,
487 .defaultval
= SUBOPT_NEEDS_VAL
,
490 .conflicts
= { L_INTERNAL
,
497 .conflicts
= { L_AGNUM
,
500 .defaultval
= SUBOPT_NEEDS_VAL
,
502 { .index
= L_LAZYSBCNTR
,
503 .conflicts
= { LAST_CONFLICT
},
511 struct opt_params nopts
= {
526 .conflicts
= { N_SIZE
,
528 .minval
= XFS_MIN_REC_DIRSIZE
,
529 .maxval
= XFS_MAX_BLOCKSIZE_LOG
,
530 .defaultval
= SUBOPT_NEEDS_VAL
,
533 .conflicts
= { N_LOG
,
537 .minval
= 1 << XFS_MIN_REC_DIRSIZE
,
538 .maxval
= XFS_MAX_BLOCKSIZE
,
539 .defaultval
= SUBOPT_NEEDS_VAL
,
541 { .index
= N_VERSION
,
542 .conflicts
= { LAST_CONFLICT
},
545 .defaultval
= SUBOPT_NEEDS_VAL
,
548 .conflicts
= { LAST_CONFLICT
},
556 struct opt_params ropts
= {
574 { .index
= R_EXTSIZE
,
575 .conflicts
= { LAST_CONFLICT
},
577 .minval
= XFS_MIN_RTEXTSIZE
,
578 .maxval
= XFS_MAX_RTEXTSIZE
,
579 .defaultval
= SUBOPT_NEEDS_VAL
,
582 .conflicts
= { LAST_CONFLICT
},
586 .defaultval
= SUBOPT_NEEDS_VAL
,
589 .conflicts
= { LAST_CONFLICT
},
590 .defaultval
= SUBOPT_NEEDS_VAL
,
596 .conflicts
= { LAST_CONFLICT
},
599 .conflicts
= { LAST_CONFLICT
},
600 .defaultval
= SUBOPT_NEEDS_VAL
,
602 { .index
= R_NOALIGN
,
606 .conflicts
= { LAST_CONFLICT
},
611 struct opt_params sopts
= {
626 .conflicts
= { S_SIZE
,
629 .minval
= XFS_MIN_SECTORSIZE_LOG
,
630 .maxval
= XFS_MAX_SECTORSIZE_LOG
,
631 .defaultval
= SUBOPT_NEEDS_VAL
,
633 { .index
= S_SECTLOG
,
634 .conflicts
= { S_SIZE
,
637 .minval
= XFS_MIN_SECTORSIZE_LOG
,
638 .maxval
= XFS_MAX_SECTORSIZE_LOG
,
639 .defaultval
= SUBOPT_NEEDS_VAL
,
642 .conflicts
= { S_LOG
,
647 .minval
= XFS_MIN_SECTORSIZE
,
648 .maxval
= XFS_MAX_SECTORSIZE
,
649 .defaultval
= SUBOPT_NEEDS_VAL
,
651 { .index
= S_SECTSIZE
,
652 .conflicts
= { S_LOG
,
657 .minval
= XFS_MIN_SECTORSIZE
,
658 .maxval
= XFS_MAX_SECTORSIZE
,
659 .defaultval
= SUBOPT_NEEDS_VAL
,
664 struct opt_params mopts
= {
677 .conflicts
= { LAST_CONFLICT
},
683 .conflicts
= { LAST_CONFLICT
},
689 .conflicts
= { LAST_CONFLICT
},
690 .defaultval
= SUBOPT_NEEDS_VAL
,
695 #define TERABYTES(count, blog) ((__uint64_t)(count) << (40 - (blog)))
696 #define GIGABYTES(count, blog) ((__uint64_t)(count) << (30 - (blog)))
697 #define MEGABYTES(count, blog) ((__uint64_t)(count) << (20 - (blog)))
700 * Use this macro before we have superblock and mount structure
702 #define DTOBT(d) ((xfs_rfsblock_t)((d) >> (blocklog - BBSHIFT)))
705 * Use this for block reservations needed for mkfs's conditions
706 * (basically no fragmentation).
708 #define MKFS_BLOCKRES_INODE \
709 ((uint)(mp->m_ialloc_blks + (mp->m_in_maxlevels - 1)))
710 #define MKFS_BLOCKRES(rb) \
711 ((uint)(MKFS_BLOCKRES_INODE + XFS_DA_NODE_MAXDEPTH + \
712 (XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1) + (rb)))
714 /* amount (in bytes) we zero at the beginning and end of the device to
715 * remove traces of other filesystems, raid superblocks, etc.
717 #define WHACK_SIZE (128 * 1024)
730 /* Handle data sunit/swidth options */
731 if ((*dsunit
&& !*dswidth
) || (!*dsunit
&& *dswidth
)) {
733 _("both data sunit and data swidth options "
734 "must be specified\n"));
739 if ((dsu
&& !dsw
) || (!dsu
&& dsw
)) {
741 _("both data su and data sw options "
742 "must be specified\n"));
748 _("data su must be a multiple of the "
749 "sector size (%d)\n"), dsectsz
);
753 *dsunit
= (int)BTOBBT(dsu
);
754 *dswidth
= *dsunit
* dsw
;
757 if (*dsunit
&& (*dswidth
% *dsunit
!= 0)) {
759 _("data stripe width (%d) must be a multiple of the "
760 "data stripe unit (%d)\n"), *dswidth
, *dsunit
);
764 /* Handle log sunit options */
767 *lsunit
= (int)BTOBBT(lsu
);
777 bool force_overwrite
,
780 struct stat64 statbuf
;
782 if (*isfile
&& (no_size
|| no_name
)) {
784 _("if -%s file then -%s name and -%s size are required\n"),
785 optname
, optname
, optname
);
790 fprintf(stderr
, _("No device name specified\n"));
794 if (stat64(name
, &statbuf
)) {
795 if (errno
== ENOENT
&& *isfile
) {
802 _("Error accessing specified device %s: %s\n"),
803 name
, strerror(errno
));
808 if (!force_overwrite
&& check_overwrite(name
)) {
810 _("%s: Use the -f option to force overwrite.\n"),
816 * We only want to completely truncate and recreate an existing file if
817 * we were specifically told it was a file. Set the create flag only in
818 * this case to trigger that behaviour.
820 if (S_ISREG(statbuf
.st_mode
)) {
828 if (S_ISBLK(statbuf
.st_mode
)) {
831 _("specified \"-%s file\" on a block device %s\n"),
839 _("specified device %s not a file or block device\n"),
845 fixup_log_stripe_unit(
848 xfs_rfsblock_t
*logblocks
,
851 __uint64_t tmp_logblocks
;
854 * Make sure that the log size is a multiple of the stripe unit
856 if ((*logblocks
% sunit
) != 0) {
858 tmp_logblocks
= ((*logblocks
+ (sunit
- 1))
861 * If the log is too large, round down
862 * instead of round up
864 if ((tmp_logblocks
> XFS_MAX_LOG_BLOCKS
) ||
865 ((tmp_logblocks
<< blocklog
) > XFS_MAX_LOG_BYTES
)) {
866 tmp_logblocks
= (*logblocks
/ sunit
) * sunit
;
868 *logblocks
= tmp_logblocks
;
870 fprintf(stderr
, _("log size %lld is not a multiple "
871 "of the log stripe unit %d\n"),
872 (long long) *logblocks
, sunit
);
879 fixup_internal_log_stripe(
882 xfs_fsblock_t logstart
,
885 xfs_rfsblock_t
*logblocks
,
889 if ((logstart
% sunit
) != 0) {
890 logstart
= ((logstart
+ (sunit
- 1))/sunit
) * sunit
;
894 fixup_log_stripe_unit(lsflag
, sunit
, logblocks
, blocklog
);
896 if (*logblocks
> agsize
- XFS_FSB_TO_AGBNO(mp
, logstart
)) {
898 _("Due to stripe alignment, the internal log size "
899 "(%lld) is too large.\n"), (long long) *logblocks
);
900 fprintf(stderr
, _("Must fit within an allocation group.\n"));
907 validate_log_size(__uint64_t logblocks
, int blocklog
, int min_logblocks
)
909 if (logblocks
< min_logblocks
) {
911 _("log size %lld blocks too small, minimum size is %d blocks\n"),
912 (long long)logblocks
, min_logblocks
);
915 if (logblocks
> XFS_MAX_LOG_BLOCKS
) {
917 _("log size %lld blocks too large, maximum size is %lld blocks\n"),
918 (long long)logblocks
, XFS_MAX_LOG_BLOCKS
);
921 if ((logblocks
<< blocklog
) > XFS_MAX_LOG_BYTES
) {
923 _("log size %lld bytes too large, maximum size is %lld bytes\n"),
924 (long long)(logblocks
<< blocklog
), XFS_MAX_LOG_BYTES
);
930 calc_default_imaxpct(
935 * This returns the % of the disk space that is used for
936 * inodes, it changes relatively to the FS size:
937 * - over 50 TB, use 1%,
938 * - 1TB - 50 TB, use 5%,
939 * - under 1 TB, use XFS_DFL_IMAXIMUM_PCT (25%).
942 if (dblocks
< TERABYTES(1, blocklog
)) {
943 return XFS_DFL_IMAXIMUM_PCT
;
944 } else if (dblocks
< TERABYTES(50, blocklog
)) {
952 validate_ag_geometry(
958 if (agsize
< XFS_AG_MIN_BLOCKS(blocklog
)) {
960 _("agsize (%lld blocks) too small, need at least %lld blocks\n"),
962 (long long)XFS_AG_MIN_BLOCKS(blocklog
));
966 if (agsize
> XFS_AG_MAX_BLOCKS(blocklog
)) {
968 _("agsize (%lld blocks) too big, maximum is %lld blocks\n"),
970 (long long)XFS_AG_MAX_BLOCKS(blocklog
));
974 if (agsize
> dblocks
) {
976 _("agsize (%lld blocks) too big, data area is %lld blocks\n"),
977 (long long)agsize
, (long long)dblocks
);
981 if (agsize
< XFS_AG_MIN_BLOCKS(blocklog
)) {
983 _("too many allocation groups for size = %lld\n"),
985 fprintf(stderr
, _("need at most %lld allocation groups\n"),
986 (long long)(dblocks
/ XFS_AG_MIN_BLOCKS(blocklog
) +
987 (dblocks
% XFS_AG_MIN_BLOCKS(blocklog
) != 0)));
991 if (agsize
> XFS_AG_MAX_BLOCKS(blocklog
)) {
993 _("too few allocation groups for size = %lld\n"), (long long)agsize
);
995 _("need at least %lld allocation groups\n"),
996 (long long)(dblocks
/ XFS_AG_MAX_BLOCKS(blocklog
) +
997 (dblocks
% XFS_AG_MAX_BLOCKS(blocklog
) != 0)));
1002 * If the last AG is too small, reduce the filesystem size
1003 * and drop the blocks.
1005 if ( dblocks
% agsize
!= 0 &&
1006 (dblocks
% agsize
< XFS_AG_MIN_BLOCKS(blocklog
))) {
1008 _("last AG size %lld blocks too small, minimum size is %lld blocks\n"),
1009 (long long)(dblocks
% agsize
),
1010 (long long)XFS_AG_MIN_BLOCKS(blocklog
));
1015 * If agcount is too large, make it smaller.
1017 if (agcount
> XFS_MAX_AGNUMBER
+ 1) {
1019 _("%lld allocation groups is too many, maximum is %lld\n"),
1020 (long long)agcount
, (long long)XFS_MAX_AGNUMBER
+ 1);
1026 zero_old_xfs_structures(
1037 * We open regular files with O_TRUNC|O_CREAT. Nothing to do here...
1039 if (xi
->disfile
&& xi
->dcreat
)
1043 * read in existing filesystem superblock, use its geometry
1044 * settings and zero the existing secondary superblocks.
1046 buf
= memalign(libxfs_device_alignment(), new_sb
->sb_sectsize
);
1049 _("error reading existing superblock -- failed to memalign buffer\n"));
1052 memset(buf
, 0, new_sb
->sb_sectsize
);
1055 * If we are creating an image file, it might be of zero length at this
1056 * point in time. Hence reading the existing superblock is going to
1057 * return zero bytes. It's not a failure we need to warn about in this
1060 off
= pread(xi
->dfd
, buf
, new_sb
->sb_sectsize
, 0);
1061 if (off
!= new_sb
->sb_sectsize
) {
1064 _("error reading existing superblock: %s\n"),
1068 libxfs_sb_from_disk(&sb
, buf
);
1071 * perform same basic superblock validation to make sure we
1072 * actually zero secondary blocks
1074 if (sb
.sb_magicnum
!= XFS_SB_MAGIC
|| sb
.sb_blocksize
== 0)
1077 for (bsize
= 1, i
= 0; bsize
< sb
.sb_blocksize
&&
1078 i
< sizeof(sb
.sb_blocksize
) * NBBY
; i
++)
1081 if (i
< XFS_MIN_BLOCKSIZE_LOG
|| i
> XFS_MAX_BLOCKSIZE_LOG
||
1082 i
!= sb
.sb_blocklog
)
1085 if (sb
.sb_dblocks
> ((__uint64_t
)sb
.sb_agcount
* sb
.sb_agblocks
) ||
1086 sb
.sb_dblocks
< ((__uint64_t
)(sb
.sb_agcount
- 1) *
1087 sb
.sb_agblocks
+ XFS_MIN_AG_BLOCKS
))
1091 * block size and basic geometry seems alright, zero the secondaries.
1093 memset(buf
, 0, new_sb
->sb_sectsize
);
1095 for (i
= 1; i
< sb
.sb_agcount
; i
++) {
1096 off
+= sb
.sb_agblocks
;
1097 if (pwrite64(xi
->dfd
, buf
, new_sb
->sb_sectsize
,
1098 off
<< sb
.sb_blocklog
) == -1)
1106 discard_blocks(dev_t dev
, __uint64_t nsectors
)
1111 * We intentionally ignore errors from the discard ioctl. It is
1112 * not necessary for the mkfs functionality but just an optimization.
1114 fd
= libxfs_device_to_fd(dev
);
1116 platform_discard_blocks(fd
, 0, nsectors
<< 9);
1119 struct sb_feat_args
{
1127 bool lazy_sb_counters
;
1131 bool parent_pointers
;
1137 struct sb_feat_args
*fp
,
1143 sbp
->sb_versionnum
= XFS_DFL_SB_VERSION_BITS
;
1144 if (fp
->crcs_enabled
)
1145 sbp
->sb_versionnum
|= XFS_SB_VERSION_5
;
1147 sbp
->sb_versionnum
|= XFS_SB_VERSION_4
;
1149 if (fp
->inode_align
)
1150 sbp
->sb_versionnum
|= XFS_SB_VERSION_ALIGNBIT
;
1152 sbp
->sb_versionnum
|= XFS_SB_VERSION_DALIGNBIT
;
1153 if (fp
->log_version
== 2)
1154 sbp
->sb_versionnum
|= XFS_SB_VERSION_LOGV2BIT
;
1155 if (fp
->attr_version
== 1)
1156 sbp
->sb_versionnum
|= XFS_SB_VERSION_ATTRBIT
;
1157 if (sectsize
> BBSIZE
|| lsectsize
> BBSIZE
)
1158 sbp
->sb_versionnum
|= XFS_SB_VERSION_SECTORBIT
;
1160 sbp
->sb_versionnum
|= XFS_SB_VERSION_BORGBIT
;
1163 sbp
->sb_features2
= 0;
1164 if (fp
->lazy_sb_counters
)
1165 sbp
->sb_features2
|= XFS_SB_VERSION2_LAZYSBCOUNTBIT
;
1166 if (!fp
->projid16bit
)
1167 sbp
->sb_features2
|= XFS_SB_VERSION2_PROJID32BIT
;
1168 if (fp
->parent_pointers
)
1169 sbp
->sb_features2
|= XFS_SB_VERSION2_PARENTBIT
;
1170 if (fp
->crcs_enabled
)
1171 sbp
->sb_features2
|= XFS_SB_VERSION2_CRCBIT
;
1172 if (fp
->attr_version
== 2)
1173 sbp
->sb_features2
|= XFS_SB_VERSION2_ATTR2BIT
;
1175 /* v5 superblocks have their own feature bit for dirftype */
1176 if (fp
->dirftype
&& !fp
->crcs_enabled
)
1177 sbp
->sb_features2
|= XFS_SB_VERSION2_FTYPE
;
1179 /* update whether extended features are in use */
1180 if (sbp
->sb_features2
!= 0)
1181 sbp
->sb_versionnum
|= XFS_SB_VERSION_MOREBITSBIT
;
1184 * Due to a structure alignment issue, sb_features2 ended up in one
1185 * of two locations, the second "incorrect" location represented by
1186 * the sb_bad_features2 field. To avoid older kernels mounting
1187 * filesystems they shouldn't, set both field to the same value.
1189 sbp
->sb_bad_features2
= sbp
->sb_features2
;
1191 if (!fp
->crcs_enabled
)
1194 /* default features for v5 filesystems */
1195 sbp
->sb_features_compat
= 0;
1196 sbp
->sb_features_ro_compat
= 0;
1197 sbp
->sb_features_incompat
= XFS_SB_FEAT_INCOMPAT_FTYPE
;
1198 sbp
->sb_features_log_incompat
= 0;
1201 sbp
->sb_features_ro_compat
= XFS_SB_FEAT_RO_COMPAT_FINOBT
;
1204 * Sparse inode chunk support has two main inode alignment requirements.
1205 * First, sparse chunk alignment must match the cluster size. Second,
1206 * full chunk alignment must match the inode chunk size.
1208 * Copy the already calculated/scaled inoalignmt to spino_align and
1209 * update the former to the full inode chunk size.
1212 sbp
->sb_spino_align
= sbp
->sb_inoalignmt
;
1213 sbp
->sb_inoalignmt
= XFS_INODES_PER_CHUNK
*
1214 sbp
->sb_inodesize
>> sbp
->sb_blocklog
;
1215 sbp
->sb_features_incompat
|= XFS_SB_FEAT_INCOMPAT_SPINODES
;
1220 static __attribute__((noreturn
)) void
1223 struct opt_params
*opts
,
1228 _("Illegal value %s for -%c %s option. %s\n"),
1229 value
, opts
->name
, opts
->subopts
[index
],
1230 reason
? reason
: "");
1235 * Check for conflicts and option respecification.
1239 struct opt_params
*opts
,
1243 struct subopt_param
*sp
= &opts
->subopt_params
[index
];
1246 if (sp
->index
!= index
) {
1248 ("Developer screwed up option parsing (%d/%d)! Please report!\n"),
1250 reqval(opts
->name
, (char **)opts
->subopts
, index
);
1254 * Check for respecification of the option. This is more complex than it
1255 * seems because some options are parsed twice - once as a string during
1256 * input parsing, then later the string is passed to getnum for
1257 * conversion into a number and bounds checking. Hence the two variables
1258 * used to track the different uses based on the @str parameter passed
1263 respec(opts
->name
, (char **)opts
->subopts
, index
);
1267 respec(opts
->name
, (char **)opts
->subopts
, index
);
1268 sp
->str_seen
= true;
1271 /* check for conflicts with the option */
1272 for (i
= 0; i
< MAX_CONFLICTS
; i
++) {
1273 int conflict_opt
= sp
->conflicts
[i
];
1275 if (conflict_opt
== LAST_CONFLICT
)
1277 if (opts
->subopt_params
[conflict_opt
].seen
||
1278 opts
->subopt_params
[conflict_opt
].str_seen
)
1279 conflict(opts
->name
, (char **)opts
->subopts
,
1280 conflict_opt
, index
);
1287 struct opt_params
*opts
,
1290 struct subopt_param
*sp
= &opts
->subopt_params
[index
];
1293 check_opt(opts
, index
, false);
1294 /* empty strings might just return a default value */
1295 if (!str
|| *str
== '\0') {
1296 if (sp
->defaultval
== SUBOPT_NEEDS_VAL
)
1297 reqval(opts
->name
, (char **)opts
->subopts
, index
);
1298 return sp
->defaultval
;
1301 if (sp
->minval
== 0 && sp
->maxval
== 0) {
1303 _("Option -%c %s has undefined minval/maxval."
1304 "Can't verify value range. This is a bug.\n"),
1305 opts
->name
, opts
->subopts
[index
]);
1310 * Some values are pure numbers, others can have suffixes that define
1311 * the units of the number. Those get passed to cvtnum(), otherwise we
1312 * convert it ourselves to guarantee there is no trailing garbage in the
1316 c
= cvtnum(blocksize
, sectorsize
, str
);
1320 c
= strtoll(str
, &str_end
, 0);
1321 if (c
== 0 && str_end
== str
)
1322 illegal_option(str
, opts
, index
, NULL
);
1323 if (*str_end
!= '\0')
1324 illegal_option(str
, opts
, index
, NULL
);
1327 /* Validity check the result. */
1329 illegal_option(str
, opts
, index
, _("value is too small"));
1330 else if (c
> sp
->maxval
)
1331 illegal_option(str
, opts
, index
, _("value is too large"));
1332 if (sp
->is_power_2
&& !ispow2(c
))
1333 illegal_option(str
, opts
, index
, _("value must be a power of 2"));
1338 * Option is a string - do all the option table work, and check there
1339 * is actually an option string. Otherwise we don't do anything with the string
1340 * here - validation will be done later when the string is converted to a value
1341 * or used as a file/device path.
1346 struct opt_params
*opts
,
1349 check_opt(opts
, index
, true);
1351 /* empty strings for string options are not valid */
1352 if (!str
|| *str
== '\0')
1353 reqval(opts
->name
, (char **)opts
->subopts
, index
);
1365 xfs_agnumber_t agno
;
1367 xfs_alloc_rec_t
*arec
;
1368 struct xfs_btree_block
*block
;
1377 xfs_rfsblock_t dblocks
;
1386 int force_overwrite
;
1401 xfs_agnumber_t logagno
;
1402 xfs_rfsblock_t logblocks
;
1406 xfs_fsblock_t logstart
;
1420 xfs_extlen_t nbmblocks
;
1424 xfs_alloc_rec_t
*nrec
;
1433 xfs_rfsblock_t rtblocks
;
1434 xfs_extlen_t rtextblocks
;
1435 xfs_rtblock_t rtextents
;
1441 __uint64_t sector_mask
;
1444 __uint64_t tmp_agsize
;
1448 struct fs_topology ft
;
1449 struct sb_feat_args sb_feat
= {
1454 .dir_version
= XFS_DFL_DIR_VERSION
,
1455 .inode_align
= XFS_IFLAG_ALIGN
,
1457 .lazy_sb_counters
= true,
1458 .projid16bit
= false,
1459 .crcs_enabled
= true,
1461 .parent_pointers
= false,
1464 platform_uuid_generate(&uuid
);
1465 progname
= basename(argv
[0]);
1466 setlocale(LC_ALL
, "");
1467 bindtextdomain(PACKAGE
, LOCALEDIR
);
1468 textdomain(PACKAGE
);
1470 blflag
= bsflag
= slflag
= ssflag
= lslflag
= lssflag
= 0;
1471 blocklog
= blocksize
= 0;
1472 sectorlog
= lsectorlog
= 0;
1473 sectorsize
= lsectorsize
= 0;
1474 agsize
= daflag
= dasize
= dblocks
= 0;
1475 ilflag
= imflag
= ipflag
= isflag
= 0;
1476 liflag
= laflag
= lsflag
= lsuflag
= lsunitflag
= ldflag
= lvflag
= 0;
1478 logagno
= logblocks
= rtblocks
= rtextblocks
= 0;
1479 Nflag
= nlflag
= nsflag
= nvflag
= 0;
1480 dirblocklog
= dirblocksize
= 0;
1482 imaxpct
= inodelog
= inopblock
= isize
= 0;
1483 dfile
= logfile
= rtfile
= NULL
;
1484 dsize
= logsize
= rtsize
= rtextsize
= protofile
= NULL
;
1485 dsu
= dsw
= dsunit
= dswidth
= lalign
= lsu
= lsunit
= 0;
1486 nodsflag
= norsflag
= 0;
1487 force_overwrite
= 0;
1489 memset(&fsx
, 0, sizeof(fsx
));
1491 memset(&xi
, 0, sizeof(xi
));
1492 xi
.isdirect
= LIBXFS_DIRECT
;
1493 xi
.isreadonly
= LIBXFS_EXCLUSIVELY
;
1495 while ((c
= getopt(argc
, argv
, "b:d:i:l:L:m:n:KNp:qr:s:CfV")) != EOF
) {
1499 force_overwrite
= 1;
1503 while (*p
!= '\0') {
1504 char **subopts
= (char **)bopts
.subopts
;
1507 switch (getsubopt(&p
, (constpp
)subopts
,
1510 blocklog
= getnum(value
, &bopts
, B_LOG
);
1511 blocksize
= 1 << blocklog
;
1515 blocksize
= getnum(value
, &bopts
,
1517 blocklog
= libxfs_highbit32(blocksize
);
1521 unknown('b', value
);
1527 while (*p
!= '\0') {
1528 char **subopts
= (char **)dopts
.subopts
;
1531 switch (getsubopt(&p
, (constpp
)subopts
,
1534 agcount
= getnum(value
, &dopts
,
1539 agsize
= getnum(value
, &dopts
, D_AGSIZE
);
1543 xi
.disfile
= getnum(value
, &dopts
,
1547 xi
.dname
= getstr(value
, &dopts
, D_NAME
);
1550 dsize
= getstr(value
, &dopts
, D_SIZE
);
1553 dsunit
= getnum(value
, &dopts
, D_SUNIT
);
1556 dswidth
= getnum(value
, &dopts
,
1560 dsu
= getnum(value
, &dopts
, D_SU
);
1563 dsw
= getnum(value
, &dopts
, D_SW
);
1566 nodsflag
= getnum(value
, &dopts
,
1570 sectorlog
= getnum(value
, &dopts
,
1572 sectorsize
= 1 << sectorlog
;
1576 sectorsize
= getnum(value
, &dopts
,
1579 libxfs_highbit32(sectorsize
);
1583 c
= getnum(value
, &dopts
, D_RTINHERIT
);
1586 XFS_DIFLAG_RTINHERIT
;
1589 fsx
.fsx_projid
= getnum(value
, &dopts
,
1592 XFS_DIFLAG_PROJINHERIT
;
1594 case D_EXTSZINHERIT
:
1595 fsx
.fsx_extsize
= getnum(value
, &dopts
,
1598 XFS_DIFLAG_EXTSZINHERIT
;
1601 unknown('d', value
);
1607 while (*p
!= '\0') {
1608 char **subopts
= (char **)iopts
.subopts
;
1611 switch (getsubopt(&p
, (constpp
)subopts
,
1614 sb_feat
.inode_align
= getnum(value
,
1618 inodelog
= getnum(value
, &iopts
, I_LOG
);
1619 isize
= 1 << inodelog
;
1623 imaxpct
= getnum(value
, &iopts
,
1628 inopblock
= getnum(value
, &iopts
,
1633 isize
= getnum(value
, &iopts
, I_SIZE
);
1634 inodelog
= libxfs_highbit32(isize
);
1638 sb_feat
.attr_version
=
1639 getnum(value
, &iopts
, I_ATTR
);
1642 sb_feat
.projid16bit
=
1643 !getnum(value
, &iopts
,
1647 sb_feat
.spinodes
= getnum(value
,
1648 &iopts
, I_SPINODES
);
1651 unknown('i', value
);
1657 while (*p
!= '\0') {
1658 char **subopts
= (char **)lopts
.subopts
;
1661 switch (getsubopt(&p
, (constpp
)subopts
,
1664 logagno
= getnum(value
, &lopts
, L_AGNUM
);
1668 xi
.lisfile
= getnum(value
, &lopts
,
1672 loginternal
= getnum(value
, &lopts
,
1677 lsu
= getnum(value
, &lopts
, L_SU
);
1681 lsunit
= getnum(value
, &lopts
, L_SUNIT
);
1686 logfile
= getstr(value
, &lopts
, L_NAME
);
1687 xi
.logname
= logfile
;
1692 sb_feat
.log_version
=
1693 getnum(value
, &lopts
, L_VERSION
);
1697 logsize
= getstr(value
, &lopts
, L_SIZE
);
1700 lsectorlog
= getnum(value
, &lopts
,
1702 lsectorsize
= 1 << lsectorlog
;
1706 lsectorsize
= getnum(value
, &lopts
,
1709 libxfs_highbit32(lsectorsize
);
1713 sb_feat
.lazy_sb_counters
=
1714 getnum(value
, &lopts
,
1718 unknown('l', value
);
1723 if (strlen(optarg
) > sizeof(sbp
->sb_fname
))
1724 illegal(optarg
, "L");
1729 while (*p
!= '\0') {
1730 char **subopts
= (char **)mopts
.subopts
;
1733 switch (getsubopt(&p
, (constpp
)subopts
,
1736 sb_feat
.crcs_enabled
=
1737 getnum(value
, &mopts
, M_CRC
);
1738 if (sb_feat
.crcs_enabled
)
1739 sb_feat
.dirftype
= true;
1742 sb_feat
.finobt
= getnum(
1743 value
, &mopts
, M_FINOBT
);
1746 if (!value
|| *value
== '\0')
1747 reqval('m', subopts
, M_UUID
);
1748 if (platform_uuid_parse(value
, &uuid
))
1749 illegal(optarg
, "m uuid");
1752 unknown('m', value
);
1758 while (*p
!= '\0') {
1759 char **subopts
= (char **)nopts
.subopts
;
1762 switch (getsubopt(&p
, (constpp
)subopts
,
1765 dirblocklog
= getnum(value
, &nopts
,
1767 dirblocksize
= 1 << dirblocklog
;
1771 dirblocksize
= getnum(value
, &nopts
,
1774 libxfs_highbit32(dirblocksize
);
1778 value
= getstr(value
, &nopts
, N_VERSION
);
1779 if (!strcasecmp(value
, "ci")) {
1783 sb_feat
.dir_version
=
1784 getnum(value
, &nopts
,
1790 sb_feat
.dirftype
= getnum(value
, &nopts
,
1794 unknown('n', value
);
1806 respec('p', NULL
, 0);
1814 while (*p
!= '\0') {
1815 char **subopts
= (char **)ropts
.subopts
;
1818 switch (getsubopt(&p
, (constpp
)subopts
,
1821 rtextsize
= getstr(value
, &ropts
,
1825 xi
.risfile
= getnum(value
, &ropts
,
1830 xi
.rtname
= getstr(value
, &ropts
,
1834 rtsize
= getstr(value
, &ropts
, R_SIZE
);
1837 norsflag
= getnum(value
, &ropts
,
1841 unknown('r', value
);
1847 while (*p
!= '\0') {
1848 char **subopts
= (char **)sopts
.subopts
;
1851 switch (getsubopt(&p
, (constpp
)subopts
,
1856 conflict('s', subopts
,
1857 S_SECTSIZE
, S_SECTLOG
);
1858 sectorlog
= getnum(value
, &sopts
,
1860 lsectorlog
= sectorlog
;
1861 sectorsize
= 1 << sectorlog
;
1862 lsectorsize
= sectorsize
;
1863 lslflag
= slflag
= 1;
1868 conflict('s', subopts
, S_SECTLOG
,
1870 sectorsize
= getnum(value
, &sopts
,
1872 lsectorsize
= sectorsize
;
1874 libxfs_highbit32(sectorsize
);
1875 lsectorlog
= sectorlog
;
1876 lssflag
= ssflag
= 1;
1879 unknown('s', value
);
1884 printf(_("%s version %s\n"), progname
, VERSION
);
1887 unknown(optopt
, "");
1890 if (argc
- optind
> 1) {
1891 fprintf(stderr
, _("extra arguments\n"));
1893 } else if (argc
- optind
== 1) {
1894 dfile
= xi
.volname
= getstr(argv
[optind
], &dopts
, D_NAME
);
1899 * Blocksize and sectorsize first, other things depend on them
1900 * For RAID4/5/6 we want to align sector size and block size,
1901 * so we need to start with the device geometry extraction too.
1903 if (!blflag
&& !bsflag
) {
1904 blocklog
= XFS_DFL_BLOCKSIZE_LOG
;
1905 blocksize
= 1 << XFS_DFL_BLOCKSIZE_LOG
;
1907 if (blocksize
< XFS_MIN_BLOCKSIZE
|| blocksize
> XFS_MAX_BLOCKSIZE
) {
1908 fprintf(stderr
, _("illegal block size %d\n"), blocksize
);
1911 if (sb_feat
.crcs_enabled
&& blocksize
< XFS_MIN_CRC_BLOCKSIZE
) {
1913 _("Minimum block size for CRC enabled filesystems is %d bytes.\n"),
1914 XFS_MIN_CRC_BLOCKSIZE
);
1917 if (sb_feat
.crcs_enabled
&& !sb_feat
.dirftype
) {
1918 fprintf(stderr
, _("cannot disable ftype with crcs enabled\n"));
1922 if (!slflag
&& !ssflag
) {
1923 sectorlog
= XFS_MIN_SECTORSIZE_LOG
;
1924 sectorsize
= XFS_MIN_SECTORSIZE
;
1926 if (!lslflag
&& !lssflag
) {
1927 lsectorlog
= sectorlog
;
1928 lsectorsize
= sectorsize
;
1932 * Before anything else, verify that we are correctly operating on
1933 * files or block devices and set the control parameters correctly.
1934 * Explicitly disable direct IO for image files so we don't error out on
1935 * sector size mismatches between the new filesystem and the underlying
1938 check_device_type(dfile
, &xi
.disfile
, !dsize
, !dfile
,
1939 Nflag
? NULL
: &xi
.dcreat
, force_overwrite
, "d");
1941 check_device_type(xi
.logname
, &xi
.lisfile
, !logsize
, !xi
.logname
,
1942 Nflag
? NULL
: &xi
.lcreat
,
1943 force_overwrite
, "l");
1945 check_device_type(xi
.rtname
, &xi
.risfile
, !rtsize
, !xi
.rtname
,
1946 Nflag
? NULL
: &xi
.rcreat
,
1947 force_overwrite
, "r");
1948 if (xi
.disfile
|| xi
.lisfile
|| xi
.risfile
)
1951 memset(&ft
, 0, sizeof(ft
));
1952 get_topology(&xi
, &ft
, force_overwrite
);
1956 * Unless specified manually on the command line use the
1957 * advertised sector size of the device. We use the physical
1958 * sector size unless the requested block size is smaller
1959 * than that, then we can use logical, but warn about the
1963 /* Older kernels may not have physical/logical distinction */
1964 if (!ft
.psectorsize
)
1965 ft
.psectorsize
= ft
.lsectorsize
;
1967 sectorsize
= ft
.psectorsize
? ft
.psectorsize
:
1970 if ((blocksize
< sectorsize
) && (blocksize
>= ft
.lsectorsize
)) {
1972 _("specified blocksize %d is less than device physical sector size %d\n"),
1973 blocksize
, ft
.psectorsize
);
1975 _("switching to logical sector size %d\n"),
1977 sectorsize
= ft
.lsectorsize
? ft
.lsectorsize
:
1983 sectorlog
= libxfs_highbit32(sectorsize
);
1985 lsectorsize
= sectorsize
;
1986 lsectorlog
= sectorlog
;
1990 if (sectorsize
< XFS_MIN_SECTORSIZE
||
1991 sectorsize
> XFS_MAX_SECTORSIZE
|| sectorsize
> blocksize
) {
1993 fprintf(stderr
, _("illegal sector size %d\n"), sectorsize
);
1996 _("block size %d cannot be smaller than logical sector size %d\n"),
1997 blocksize
, ft
.lsectorsize
);
2000 if (sectorsize
< ft
.lsectorsize
) {
2001 fprintf(stderr
, _("illegal sector size %d; hw sector is %d\n"),
2002 sectorsize
, ft
.lsectorsize
);
2005 if (lsectorsize
< XFS_MIN_SECTORSIZE
||
2006 lsectorsize
> XFS_MAX_SECTORSIZE
|| lsectorsize
> blocksize
) {
2007 fprintf(stderr
, _("illegal log sector size %d\n"), lsectorsize
);
2009 } else if (lsectorsize
> XFS_MIN_SECTORSIZE
&& !lsu
&& !lsunit
) {
2011 sb_feat
.log_version
= 2;
2015 * Now we have blocks and sector sizes set up, check parameters that are
2016 * no longer optional for CRC enabled filesystems. Catch them up front
2017 * here before doing anything else.
2019 if (sb_feat
.crcs_enabled
) {
2020 /* minimum inode size is 512 bytes, ipflag checked later */
2021 if ((isflag
|| ilflag
) && inodelog
< XFS_DINODE_DFL_CRC_LOG
) {
2023 _("Minimum inode size for CRCs is %d bytes\n"),
2024 1 << XFS_DINODE_DFL_CRC_LOG
);
2028 /* inodes always aligned */
2029 if (!sb_feat
.inode_align
) {
2031 _("Inodes always aligned for CRC enabled filesytems\n"));
2035 /* lazy sb counters always on */
2036 if (!sb_feat
.lazy_sb_counters
) {
2038 _("Lazy superblock counted always enabled for CRC enabled filesytems\n"));
2042 /* version 2 logs always on */
2043 if (sb_feat
.log_version
!= 2) {
2045 _("V2 logs always enabled for CRC enabled filesytems\n"));
2049 /* attr2 always on */
2050 if (sb_feat
.attr_version
!= 2) {
2052 _("V2 attribute format always enabled on CRC enabled filesytems\n"));
2056 /* 32 bit project quota always on */
2057 /* attr2 always on */
2058 if (sb_feat
.projid16bit
) {
2060 _("32 bit Project IDs always enabled on CRC enabled filesytems\n"));
2065 * The kernel doesn't currently support crc=0,finobt=1
2066 * filesystems. If crcs are not enabled and the user has not
2067 * explicitly turned finobt on, then silently turn it off to
2068 * avoid an unnecessary warning.
2069 * If the user explicitly tried to use crc=0,finobt=1,
2070 * then issue an error.
2071 * The same is also for sparse inodes.
2073 if (sb_feat
.finobt
&& mopts
.subopt_params
[M_FINOBT
].seen
) {
2075 _("finobt not supported without CRC support\n"));
2080 if (sb_feat
.spinodes
) {
2082 _("sparse inodes not supported without CRC support\n"));
2085 sb_feat
.spinodes
= 0;
2089 if (nsflag
|| nlflag
) {
2090 if (dirblocksize
< blocksize
||
2091 dirblocksize
> XFS_MAX_BLOCKSIZE
) {
2092 fprintf(stderr
, _("illegal directory block size %d\n"),
2097 if (blocksize
< (1 << XFS_MIN_REC_DIRSIZE
))
2098 dirblocklog
= XFS_MIN_REC_DIRSIZE
;
2100 dirblocklog
= blocklog
;
2101 dirblocksize
= 1 << dirblocklog
;
2108 dbytes
= getnum(dsize
, &dopts
, D_SIZE
);
2109 if (dbytes
% XFS_MIN_BLOCKSIZE
) {
2111 _("illegal data length %lld, not a multiple of %d\n"),
2112 (long long)dbytes
, XFS_MIN_BLOCKSIZE
);
2115 dblocks
= (xfs_rfsblock_t
)(dbytes
>> blocklog
);
2116 if (dbytes
% blocksize
)
2117 fprintf(stderr
, _("warning: "
2118 "data length %lld not a multiple of %d, truncated to %lld\n"),
2119 (long long)dbytes
, blocksize
,
2120 (long long)(dblocks
<< blocklog
));
2123 inodelog
= blocklog
- libxfs_highbit32(inopblock
);
2124 isize
= 1 << inodelog
;
2125 } else if (!ilflag
&& !isflag
) {
2126 inodelog
= sb_feat
.crcs_enabled
? XFS_DINODE_DFL_CRC_LOG
2127 : XFS_DINODE_DFL_LOG
;
2128 isize
= 1 << inodelog
;
2130 if (sb_feat
.crcs_enabled
&& inodelog
< XFS_DINODE_DFL_CRC_LOG
) {
2132 _("Minimum inode size for CRCs is %d bytes\n"),
2133 1 << XFS_DINODE_DFL_CRC_LOG
);
2138 __uint64_t logbytes
;
2140 logbytes
= getnum(logsize
, &lopts
, L_SIZE
);
2141 if (logbytes
% XFS_MIN_BLOCKSIZE
) {
2143 _("illegal log length %lld, not a multiple of %d\n"),
2144 (long long)logbytes
, XFS_MIN_BLOCKSIZE
);
2147 logblocks
= (xfs_rfsblock_t
)(logbytes
>> blocklog
);
2148 if (logbytes
% blocksize
)
2150 _("warning: log length %lld not a multiple of %d, truncated to %lld\n"),
2151 (long long)logbytes
, blocksize
,
2152 (long long)(logblocks
<< blocklog
));
2157 rtbytes
= getnum(rtsize
, &ropts
, R_SIZE
);
2158 if (rtbytes
% XFS_MIN_BLOCKSIZE
) {
2160 _("illegal rt length %lld, not a multiple of %d\n"),
2161 (long long)rtbytes
, XFS_MIN_BLOCKSIZE
);
2164 rtblocks
= (xfs_rfsblock_t
)(rtbytes
>> blocklog
);
2165 if (rtbytes
% blocksize
)
2167 _("warning: rt length %lld not a multiple of %d, truncated to %lld\n"),
2168 (long long)rtbytes
, blocksize
,
2169 (long long)(rtblocks
<< blocklog
));
2172 * If specified, check rt extent size against its constraints.
2175 __uint64_t rtextbytes
;
2177 rtextbytes
= getnum(rtextsize
, &ropts
, R_EXTSIZE
);
2178 if (rtextbytes
% blocksize
) {
2180 _("illegal rt extent size %lld, not a multiple of %d\n"),
2181 (long long)rtextbytes
, blocksize
);
2184 rtextblocks
= (xfs_extlen_t
)(rtextbytes
>> blocklog
);
2187 * If realtime extsize has not been specified by the user,
2188 * and the underlying volume is striped, then set rtextblocks
2189 * to the stripe width.
2192 __uint64_t rtextbytes
;
2194 if (!norsflag
&& !xi
.risfile
&& !(!rtsize
&& xi
.disfile
))
2195 rswidth
= ft
.rtswidth
;
2199 /* check that rswidth is a multiple of fs blocksize */
2200 if (!norsflag
&& rswidth
&& !(BBTOB(rswidth
) % blocksize
)) {
2201 rswidth
= DTOBT(rswidth
);
2202 rtextbytes
= rswidth
<< blocklog
;
2203 if (XFS_MIN_RTEXTSIZE
<= rtextbytes
&&
2204 (rtextbytes
<= XFS_MAX_RTEXTSIZE
)) {
2205 rtextblocks
= rswidth
;
2209 rtextblocks
= (blocksize
< XFS_MIN_RTEXTSIZE
) ?
2210 XFS_MIN_RTEXTSIZE
>> blocklog
: 1;
2213 ASSERT(rtextblocks
);
2216 * Check some argument sizes against mins, maxes.
2218 if (isize
> blocksize
/ XFS_MIN_INODE_PERBLOCK
||
2219 isize
< XFS_DINODE_MIN_SIZE
||
2220 isize
> XFS_DINODE_MAX_SIZE
) {
2223 fprintf(stderr
, _("illegal inode size %d\n"), isize
);
2224 maxsz
= MIN(blocksize
/ XFS_MIN_INODE_PERBLOCK
,
2225 XFS_DINODE_MAX_SIZE
);
2226 if (XFS_DINODE_MIN_SIZE
== maxsz
)
2228 _("allowable inode size with %d byte blocks is %d\n"),
2229 blocksize
, XFS_DINODE_MIN_SIZE
);
2232 _("allowable inode size with %d byte blocks is between %d and %d\n"),
2233 blocksize
, XFS_DINODE_MIN_SIZE
, maxsz
);
2237 /* if lsu or lsunit was specified, automatically use v2 logs */
2238 if ((lsu
|| lsunit
) && sb_feat
.log_version
== 1) {
2240 _("log stripe unit specified, using v2 logs\n"));
2241 sb_feat
.log_version
= 2;
2244 calc_stripe_factors(dsu
, dsw
, sectorsize
, lsu
, lsectorsize
,
2245 &dsunit
, &dswidth
, &lsunit
);
2247 xi
.setblksize
= sectorsize
;
2250 * Initialize. This will open the log and rt devices as well.
2252 if (!libxfs_init(&xi
))
2255 fprintf(stderr
, _("no device name given in argument list\n"));
2260 * Ok, Linux only has a 1024-byte resolution on device _size_,
2261 * and the sizes below are in basic 512-byte blocks,
2262 * so if we have (size % 2), on any partition, we can't get
2263 * to the last 512 bytes. The same issue exists for larger
2264 * sector sizes - we cannot write past the last sector.
2266 * So, we reduce the size (in basic blocks) to a perfect
2267 * multiple of the sector size, or 1024, whichever is larger.
2270 sector_mask
= (__uint64_t
)-1 << (MAX(sectorlog
, 10) - BBSHIFT
);
2271 xi
.dsize
&= sector_mask
;
2272 xi
.rtsize
&= sector_mask
;
2273 xi
.logBBsize
&= (__uint64_t
)-1 << (MAX(lsectorlog
, 10) - BBSHIFT
);
2276 /* don't do discards on print-only runs or on files */
2277 if (discard
&& !Nflag
) {
2279 discard_blocks(xi
.ddev
, xi
.dsize
);
2280 if (xi
.rtdev
&& !xi
.risfile
)
2281 discard_blocks(xi
.rtdev
, xi
.rtsize
);
2282 if (xi
.logdev
&& xi
.logdev
!= xi
.ddev
&& !xi
.lisfile
)
2283 discard_blocks(xi
.logdev
, xi
.logBBsize
);
2286 if (!liflag
&& !ldflag
)
2287 loginternal
= xi
.logdev
== 0;
2289 logfile
= xi
.logname
;
2290 else if (loginternal
)
2291 logfile
= _("internal log");
2292 else if (xi
.volname
&& xi
.logdev
)
2293 logfile
= _("volume log");
2295 fprintf(stderr
, _("no log subvolume or internal log\n"));
2301 if (xi
.volname
&& xi
.rtdev
)
2302 rtfile
= _("volume rt");
2305 if (dsize
&& xi
.dsize
> 0 && dblocks
> DTOBT(xi
.dsize
)) {
2307 _("size %s specified for data subvolume is too large, "
2308 "maximum is %lld blocks\n"),
2309 dsize
, (long long)DTOBT(xi
.dsize
));
2311 } else if (!dsize
&& xi
.dsize
> 0)
2312 dblocks
= DTOBT(xi
.dsize
);
2314 fprintf(stderr
, _("can't get size of data subvolume\n"));
2317 if (dblocks
< XFS_MIN_DATA_BLOCKS
) {
2319 _("size %lld of data subvolume is too small, minimum %d blocks\n"),
2320 (long long)dblocks
, XFS_MIN_DATA_BLOCKS
);
2324 if (loginternal
&& xi
.logdev
) {
2326 _("can't have both external and internal logs\n"));
2328 } else if (loginternal
&& sectorsize
!= lsectorsize
) {
2330 _("data and log sector sizes must be equal for internal logs\n"));
2334 if (xi
.dbsize
> sectorsize
) {
2336 "Warning: the data subvolume sector size %u is less than the sector size \n\
2337 reported by the device (%u).\n"),
2338 sectorsize
, xi
.dbsize
);
2340 if (!loginternal
&& xi
.lbsize
> lsectorsize
) {
2342 "Warning: the log subvolume sector size %u is less than the sector size\n\
2343 reported by the device (%u).\n"),
2344 lsectorsize
, xi
.lbsize
);
2346 if (rtsize
&& xi
.rtsize
> 0 && xi
.rtbsize
> sectorsize
) {
2348 "Warning: the realtime subvolume sector size %u is less than the sector size\n\
2349 reported by the device (%u).\n"),
2350 sectorsize
, xi
.rtbsize
);
2353 if (rtsize
&& xi
.rtsize
> 0 && rtblocks
> DTOBT(xi
.rtsize
)) {
2355 _("size %s specified for rt subvolume is too large, "
2356 "maximum is %lld blocks\n"),
2357 rtsize
, (long long)DTOBT(xi
.rtsize
));
2359 } else if (!rtsize
&& xi
.rtsize
> 0)
2360 rtblocks
= DTOBT(xi
.rtsize
);
2361 else if (rtsize
&& !xi
.rtdev
) {
2363 _("size specified for non-existent rt subvolume\n"));
2367 rtextents
= rtblocks
/ rtextblocks
;
2368 nbmblocks
= (xfs_extlen_t
)howmany(rtextents
, NBBY
* blocksize
);
2370 rtextents
= rtblocks
= 0;
2376 if (ft
.dsunit
&& ft
.dsunit
!= dsunit
) {
2378 _("%s: Specified data stripe unit %d "
2379 "is not the same as the volume stripe "
2381 progname
, dsunit
, ft
.dsunit
);
2383 if (ft
.dswidth
&& ft
.dswidth
!= dswidth
) {
2385 _("%s: Specified data stripe width %d "
2386 "is not the same as the volume stripe "
2388 progname
, dswidth
, ft
.dswidth
);
2392 dswidth
= ft
.dswidth
;
2395 } /* else dsunit & dswidth can't be set if nodsflag is set */
2397 if (dasize
) { /* User-specified AG size */
2399 * Check specified agsize is a multiple of blocksize.
2401 if (agsize
% blocksize
) {
2403 _("agsize (%lld) not a multiple of fs blk size (%d)\n"),
2404 (long long)agsize
, blocksize
);
2407 agsize
/= blocksize
;
2408 agcount
= dblocks
/ agsize
+ (dblocks
% agsize
!= 0);
2410 } else if (daflag
) { /* User-specified AG count */
2411 agsize
= dblocks
/ agcount
+ (dblocks
% agcount
!= 0);
2413 calc_default_ag_geometry(blocklog
, dblocks
,
2414 dsunit
| dswidth
, &agsize
, &agcount
);
2418 * If dsunit is a multiple of fs blocksize, then check that is a
2419 * multiple of the agsize too
2421 if (dsunit
&& !(BBTOB(dsunit
) % blocksize
) &&
2422 dswidth
&& !(BBTOB(dswidth
) % blocksize
)) {
2424 /* convert from 512 byte blocks to fs blocksize */
2425 dsunit
= DTOBT(dsunit
);
2426 dswidth
= DTOBT(dswidth
);
2429 * agsize is not a multiple of dsunit
2431 if ((agsize
% dsunit
) != 0) {
2433 * Round up to stripe unit boundary. Also make sure
2434 * that agsize is still larger than
2435 * XFS_AG_MIN_BLOCKS(blocklog)
2437 tmp_agsize
= ((agsize
+ (dsunit
- 1))/ dsunit
) * dsunit
;
2439 * Round down to stripe unit boundary if rounding up
2440 * created an AG size that is larger than the AG max.
2442 if (tmp_agsize
> XFS_AG_MAX_BLOCKS(blocklog
))
2443 tmp_agsize
= ((agsize
) / dsunit
) * dsunit
;
2445 if ((tmp_agsize
>= XFS_AG_MIN_BLOCKS(blocklog
)) &&
2446 (tmp_agsize
<= XFS_AG_MAX_BLOCKS(blocklog
))) {
2447 agsize
= tmp_agsize
;
2449 agcount
= dblocks
/agsize
+
2450 (dblocks
% agsize
!= 0);
2453 _("agsize rounded to %lld, swidth = %d\n"),
2454 (long long)agsize
, dswidth
);
2457 dsunit
= dswidth
= 0;
2460 * agsize is out of bounds, this will
2461 * print nice details & exit.
2463 validate_ag_geometry(blocklog
, dblocks
,
2469 if (dswidth
&& ((agsize
% dswidth
) == 0) && (agcount
> 1)) {
2470 /* This is a non-optimal configuration because all AGs
2471 * start on the same disk in the stripe. Changing
2472 * the AG size by one sunit will guarantee that this
2475 tmp_agsize
= agsize
- dsunit
;
2476 if (tmp_agsize
< XFS_AG_MIN_BLOCKS(blocklog
)) {
2477 tmp_agsize
= agsize
+ dsunit
;
2478 if (dblocks
< agsize
) {
2479 /* oh well, nothing to do */
2480 tmp_agsize
= agsize
;
2483 if (daflag
|| dasize
) {
2485 "Warning: AG size is a multiple of stripe width. This can cause performance\n\
2486 problems by aligning all AGs on the same disk. To avoid this, run mkfs with\n\
2487 an AG size that is one stripe unit smaller, for example %llu.\n"),
2488 (unsigned long long)tmp_agsize
);
2490 agsize
= tmp_agsize
;
2491 agcount
= dblocks
/agsize
+ (dblocks
% agsize
!= 0);
2493 * If the last AG is too small, reduce the
2494 * filesystem size and drop the blocks.
2496 if ( dblocks
% agsize
!= 0 &&
2498 XFS_AG_MIN_BLOCKS(blocklog
))) {
2499 dblocks
= (xfs_rfsblock_t
)((agcount
- 1) * agsize
);
2501 ASSERT(agcount
!= 0);
2507 dsunit
= dswidth
= 0;
2510 _("%s: Stripe unit(%d) or stripe width(%d) is "
2511 "not a multiple of the block size(%d)\n"),
2512 progname
, BBTOB(dsunit
), BBTOB(dswidth
),
2519 * If the last AG is too small, reduce the filesystem size
2520 * and drop the blocks.
2522 if ( dblocks
% agsize
!= 0 &&
2523 (dblocks
% agsize
< XFS_AG_MIN_BLOCKS(blocklog
))) {
2525 dblocks
= (xfs_rfsblock_t
)((agcount
- 1) * agsize
);
2527 ASSERT(agcount
!= 0);
2530 validate_ag_geometry(blocklog
, dblocks
, agsize
, agcount
);
2533 imaxpct
= calc_default_imaxpct(blocklog
, dblocks
);
2536 * check that log sunit is modulo fsblksize or default it to dsunit.
2540 if ((BBTOB(lsunit
) % blocksize
!= 0)) {
2542 _("log stripe unit (%d) must be a multiple of the block size (%d)\n"),
2543 BBTOB(lsunit
), blocksize
);
2546 /* convert from 512 byte blocks to fs blocks */
2547 lsunit
= DTOBT(lsunit
);
2548 } else if (sb_feat
.log_version
== 2 && loginternal
&& dsunit
) {
2549 /* lsunit and dsunit now in fs blocks */
2553 if (sb_feat
.log_version
== 2 && (lsunit
* blocksize
) > 256 * 1024) {
2554 /* Warn only if specified on commandline */
2555 if (lsuflag
|| lsunitflag
) {
2557 _("log stripe unit (%d bytes) is too large (maximum is 256KiB)\n"),
2558 (lsunit
* blocksize
));
2560 _("log stripe unit adjusted to 32KiB\n"));
2562 lsunit
= (32 * 1024) >> blocklog
;
2565 min_logblocks
= max_trans_res(sb_feat
.crcs_enabled
, sb_feat
.dir_version
,
2566 sectorlog
, blocklog
, inodelog
, dirblocklog
,
2567 sb_feat
.log_version
, lsunit
, sb_feat
.finobt
);
2568 ASSERT(min_logblocks
);
2569 min_logblocks
= MAX(XFS_MIN_LOG_BLOCKS
, min_logblocks
);
2570 if (!logsize
&& dblocks
>= (1024*1024*1024) >> blocklog
)
2571 min_logblocks
= MAX(min_logblocks
, XFS_MIN_LOG_BYTES
>>blocklog
);
2572 if (logsize
&& xi
.logBBsize
> 0 && logblocks
> DTOBT(xi
.logBBsize
)) {
2574 _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
2575 logsize
, (long long)DTOBT(xi
.logBBsize
));
2577 } else if (!logsize
&& xi
.logBBsize
> 0) {
2578 logblocks
= DTOBT(xi
.logBBsize
);
2579 } else if (logsize
&& !xi
.logdev
&& !loginternal
) {
2581 _("size specified for non-existent log subvolume\n"));
2583 } else if (loginternal
&& logsize
&& logblocks
>= dblocks
) {
2584 fprintf(stderr
, _("size %lld too large for internal log\n"),
2585 (long long)logblocks
);
2587 } else if (!loginternal
&& !xi
.logdev
) {
2589 } else if (loginternal
&& !logsize
) {
2591 if (dblocks
< GIGABYTES(1, blocklog
)) {
2592 /* tiny filesystems get minimum sized logs. */
2593 logblocks
= min_logblocks
;
2594 } else if (dblocks
< GIGABYTES(16, blocklog
)) {
2597 * For small filesystems, we want to use the
2598 * XFS_MIN_LOG_BYTES for filesystems smaller than 16G if
2599 * at all possible, ramping up to 128MB at 256GB.
2601 logblocks
= MIN(XFS_MIN_LOG_BYTES
>> blocklog
,
2602 min_logblocks
* XFS_DFL_LOG_FACTOR
);
2605 * With a 2GB max log size, default to maximum size
2606 * at 4TB. This keeps the same ratio from the older
2607 * max log size of 128M at 256GB fs size. IOWs,
2608 * the ratio of fs size to log size is 2048:1.
2610 logblocks
= (dblocks
<< blocklog
) / 2048;
2611 logblocks
= logblocks
>> blocklog
;
2614 /* Ensure the chosen size meets minimum log size requirements */
2615 logblocks
= MAX(min_logblocks
, logblocks
);
2617 /* make sure the log fits wholly within an AG */
2618 if (logblocks
>= agsize
)
2619 logblocks
= min_logblocks
;
2621 /* and now clamp the size to the maximum supported size */
2622 logblocks
= MIN(logblocks
, XFS_MAX_LOG_BLOCKS
);
2623 if ((logblocks
<< blocklog
) > XFS_MAX_LOG_BYTES
)
2624 logblocks
= XFS_MAX_LOG_BYTES
>> blocklog
;
2627 validate_log_size(logblocks
, blocklog
, min_logblocks
);
2629 protostring
= setup_proto(protofile
);
2630 bsize
= 1 << (blocklog
- BBSHIFT
);
2633 memset(mp
, 0, sizeof(xfs_mount_t
));
2634 sbp
->sb_blocklog
= (__uint8_t
)blocklog
;
2635 sbp
->sb_sectlog
= (__uint8_t
)sectorlog
;
2636 sbp
->sb_agblklog
= (__uint8_t
)libxfs_log2_roundup((unsigned int)agsize
);
2637 sbp
->sb_agblocks
= (xfs_agblock_t
)agsize
;
2638 mp
->m_blkbb_log
= sbp
->sb_blocklog
- BBSHIFT
;
2639 mp
->m_sectbb_log
= sbp
->sb_sectlog
- BBSHIFT
;
2642 * sb_versionnum and finobt flags must be set before we use
2643 * XFS_PREALLOC_BLOCKS().
2645 sb_set_features(&mp
->m_sb
, &sb_feat
, sectorsize
, lsectorsize
, dsunit
);
2650 * Readjust the log size to fit within an AG if it was sized
2654 logblocks
= MIN(logblocks
,
2655 XFS_ALLOC_AG_MAX_USABLE(mp
));
2657 /* revalidate the log size is valid if we changed it */
2658 validate_log_size(logblocks
, blocklog
, min_logblocks
);
2660 if (logblocks
> agsize
- XFS_PREALLOC_BLOCKS(mp
)) {
2662 _("internal log size %lld too large, must fit in allocation group\n"),
2663 (long long)logblocks
);
2668 if (logagno
>= agcount
) {
2670 _("log ag number %d too large, must be less than %lld\n"),
2671 logagno
, (long long)agcount
);
2675 logagno
= (xfs_agnumber_t
)(agcount
/ 2);
2677 logstart
= XFS_AGB_TO_FSB(mp
, logagno
, XFS_PREALLOC_BLOCKS(mp
));
2679 * Align the logstart at stripe unit boundary.
2682 logstart
= fixup_internal_log_stripe(mp
,
2683 lsflag
, logstart
, agsize
, lsunit
,
2684 &logblocks
, blocklog
, &lalign
);
2685 } else if (dsunit
) {
2686 logstart
= fixup_internal_log_stripe(mp
,
2687 lsflag
, logstart
, agsize
, dsunit
,
2688 &logblocks
, blocklog
, &lalign
);
2693 fixup_log_stripe_unit(lsflag
, lsunit
,
2694 &logblocks
, blocklog
);
2696 validate_log_size(logblocks
, blocklog
, min_logblocks
);
2698 if (!qflag
|| Nflag
) {
2700 "meta-data=%-22s isize=%-6d agcount=%lld, agsize=%lld blks\n"
2701 " =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n"
2702 " =%-22s crc=%-8u finobt=%u, sparse=%u\n"
2703 "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
2704 " =%-22s sunit=%-6u swidth=%u blks\n"
2705 "naming =version %-14u bsize=%-6u ascii-ci=%d ftype=%d\n"
2706 "log =%-22s bsize=%-6d blocks=%lld, version=%d\n"
2707 " =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n"
2708 "realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"),
2709 dfile
, isize
, (long long)agcount
, (long long)agsize
,
2710 "", sectorsize
, sb_feat
.attr_version
,
2711 !sb_feat
.projid16bit
,
2712 "", sb_feat
.crcs_enabled
, sb_feat
.finobt
, sb_feat
.spinodes
,
2713 "", blocksize
, (long long)dblocks
, imaxpct
,
2714 "", dsunit
, dswidth
,
2715 sb_feat
.dir_version
, dirblocksize
, sb_feat
.nci
,
2717 logfile
, 1 << blocklog
, (long long)logblocks
,
2718 sb_feat
.log_version
, "", lsectorsize
, lsunit
,
2719 sb_feat
.lazy_sb_counters
,
2720 rtfile
, rtextblocks
<< blocklog
,
2721 (long long)rtblocks
, (long long)rtextents
);
2727 strncpy(sbp
->sb_fname
, label
, sizeof(sbp
->sb_fname
));
2728 sbp
->sb_magicnum
= XFS_SB_MAGIC
;
2729 sbp
->sb_blocksize
= blocksize
;
2730 sbp
->sb_dblocks
= dblocks
;
2731 sbp
->sb_rblocks
= rtblocks
;
2732 sbp
->sb_rextents
= rtextents
;
2733 platform_uuid_copy(&sbp
->sb_uuid
, &uuid
);
2734 /* Only in memory; libxfs expects this as if read from disk */
2735 platform_uuid_copy(&sbp
->sb_meta_uuid
, &uuid
);
2736 sbp
->sb_logstart
= logstart
;
2737 sbp
->sb_rootino
= sbp
->sb_rbmino
= sbp
->sb_rsumino
= NULLFSINO
;
2738 sbp
->sb_rextsize
= rtextblocks
;
2739 sbp
->sb_agcount
= (xfs_agnumber_t
)agcount
;
2740 sbp
->sb_rbmblocks
= nbmblocks
;
2741 sbp
->sb_logblocks
= (xfs_extlen_t
)logblocks
;
2742 sbp
->sb_sectsize
= (__uint16_t
)sectorsize
;
2743 sbp
->sb_inodesize
= (__uint16_t
)isize
;
2744 sbp
->sb_inopblock
= (__uint16_t
)(blocksize
/ isize
);
2745 sbp
->sb_sectlog
= (__uint8_t
)sectorlog
;
2746 sbp
->sb_inodelog
= (__uint8_t
)inodelog
;
2747 sbp
->sb_inopblog
= (__uint8_t
)(blocklog
- inodelog
);
2749 (__uint8_t
)(rtextents
?
2750 libxfs_highbit32((unsigned int)rtextents
) : 0);
2751 sbp
->sb_inprogress
= 1; /* mkfs is in progress */
2752 sbp
->sb_imax_pct
= imaxpct
;
2755 sbp
->sb_fdblocks
= dblocks
- agcount
* XFS_PREALLOC_BLOCKS(mp
) -
2756 (loginternal
? logblocks
: 0);
2757 sbp
->sb_frextents
= 0; /* will do a free later */
2758 sbp
->sb_uquotino
= sbp
->sb_gquotino
= sbp
->sb_pquotino
= 0;
2760 sbp
->sb_unit
= dsunit
;
2761 sbp
->sb_width
= dswidth
;
2762 sbp
->sb_dirblklog
= dirblocklog
- blocklog
;
2763 if (sb_feat
.log_version
== 2) { /* This is stored in bytes */
2764 lsunit
= (lsunit
== 0) ? 1 : XFS_FSB_TO_B(mp
, lsunit
);
2765 sbp
->sb_logsunit
= lsunit
;
2767 sbp
->sb_logsunit
= 0;
2768 if (sb_feat
.inode_align
) {
2769 int cluster_size
= XFS_INODE_BIG_CLUSTER_SIZE
;
2770 if (sb_feat
.crcs_enabled
)
2771 cluster_size
*= isize
/ XFS_DINODE_MIN_SIZE
;
2772 sbp
->sb_inoalignmt
= cluster_size
>> blocklog
;
2773 sb_feat
.inode_align
= sbp
->sb_inoalignmt
!= 0;
2775 sbp
->sb_inoalignmt
= 0;
2776 if (lsectorsize
!= BBSIZE
|| sectorsize
!= BBSIZE
) {
2777 sbp
->sb_logsectlog
= (__uint8_t
)lsectorlog
;
2778 sbp
->sb_logsectsize
= (__uint16_t
)lsectorsize
;
2780 sbp
->sb_logsectlog
= 0;
2781 sbp
->sb_logsectsize
= 0;
2784 sb_set_features(&mp
->m_sb
, &sb_feat
, sectorsize
, lsectorsize
, dsunit
);
2786 if (force_overwrite
)
2787 zero_old_xfs_structures(&xi
, sbp
);
2790 * Zero out the beginning of the device, to obliterate any old
2791 * filesystem signatures out there. This should take care of
2792 * swap (somewhere around the page size), jfs (32k),
2793 * ext[2,3] and reiserfs (64k) - and hopefully all else.
2795 libxfs_buftarg_init(mp
, xi
.ddev
, xi
.logdev
, xi
.rtdev
);
2796 buf
= libxfs_getbuf(mp
->m_ddev_targp
, 0, BTOBB(WHACK_SIZE
));
2797 memset(XFS_BUF_PTR(buf
), 0, WHACK_SIZE
);
2798 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2799 libxfs_purgebuf(buf
);
2801 /* OK, now write the superblock */
2802 buf
= libxfs_getbuf(mp
->m_ddev_targp
, XFS_SB_DADDR
, XFS_FSS_TO_BB(mp
, 1));
2803 buf
->b_ops
= &xfs_sb_buf_ops
;
2804 memset(XFS_BUF_PTR(buf
), 0, sectorsize
);
2805 libxfs_sb_to_disk((void *)XFS_BUF_PTR(buf
), sbp
);
2806 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2807 libxfs_purgebuf(buf
);
2810 * If the data area is a file, then grow it out to its final size
2811 * if needed so that the reads for the end of the device in the mount
2812 * code will succeed.
2814 if (xi
.disfile
&& xi
.dsize
* xi
.dbsize
< dblocks
* blocksize
) {
2815 if (ftruncate64(xi
.dfd
, dblocks
* blocksize
) < 0) {
2817 _("%s: Growing the data section failed\n"),
2824 * Zero out the end of the device, to obliterate any
2825 * old MD RAID (or other) metadata at the end of the device.
2826 * (MD sb is ~64k from the end, take out a wider swath to be sure)
2829 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2830 (xi
.dsize
- BTOBB(WHACK_SIZE
)),
2832 memset(XFS_BUF_PTR(buf
), 0, WHACK_SIZE
);
2833 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2834 libxfs_purgebuf(buf
);
2840 libxfs_log_clear(mp
->m_logdev_targp
, NULL
,
2841 XFS_FSB_TO_DADDR(mp
, logstart
),
2842 (xfs_extlen_t
)XFS_FSB_TO_BB(mp
, logblocks
),
2843 &sbp
->sb_uuid
, sb_feat
.log_version
, lsunit
, XLOG_FMT
, XLOG_INIT_CYCLE
, false);
2845 mp
= libxfs_mount(mp
, sbp
, xi
.ddev
, xi
.logdev
, xi
.rtdev
, 0);
2847 fprintf(stderr
, _("%s: filesystem failed to initialize\n"),
2853 * XXX: this code is effectively shared with the kernel growfs code.
2854 * These initialisations should be pulled into libxfs to keep the
2855 * kernel/userspace header initialisation code the same.
2857 for (agno
= 0; agno
< agcount
; agno
++) {
2858 struct xfs_agfl
*agfl
;
2860 struct xfs_perag
*pag
= xfs_perag_get(mp
, agno
);
2865 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2866 XFS_AG_DADDR(mp
, agno
, XFS_SB_DADDR
),
2867 XFS_FSS_TO_BB(mp
, 1));
2868 buf
->b_ops
= &xfs_sb_buf_ops
;
2869 memset(XFS_BUF_PTR(buf
), 0, sectorsize
);
2870 libxfs_sb_to_disk((void *)XFS_BUF_PTR(buf
), sbp
);
2871 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2874 * AG header block: freespace
2876 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2877 XFS_AG_DADDR(mp
, agno
, XFS_AGF_DADDR(mp
)),
2878 XFS_FSS_TO_BB(mp
, 1));
2879 buf
->b_ops
= &xfs_agf_buf_ops
;
2880 agf
= XFS_BUF_TO_AGF(buf
);
2881 memset(agf
, 0, sectorsize
);
2882 if (agno
== agcount
- 1)
2883 agsize
= dblocks
- (xfs_rfsblock_t
)(agno
* agsize
);
2884 agf
->agf_magicnum
= cpu_to_be32(XFS_AGF_MAGIC
);
2885 agf
->agf_versionnum
= cpu_to_be32(XFS_AGF_VERSION
);
2886 agf
->agf_seqno
= cpu_to_be32(agno
);
2887 agf
->agf_length
= cpu_to_be32(agsize
);
2888 agf
->agf_roots
[XFS_BTNUM_BNOi
] = cpu_to_be32(XFS_BNO_BLOCK(mp
));
2889 agf
->agf_roots
[XFS_BTNUM_CNTi
] = cpu_to_be32(XFS_CNT_BLOCK(mp
));
2890 agf
->agf_levels
[XFS_BTNUM_BNOi
] = cpu_to_be32(1);
2891 agf
->agf_levels
[XFS_BTNUM_CNTi
] = cpu_to_be32(1);
2892 pag
->pagf_levels
[XFS_BTNUM_BNOi
] = 1;
2893 pag
->pagf_levels
[XFS_BTNUM_CNTi
] = 1;
2894 agf
->agf_flfirst
= 0;
2895 agf
->agf_fllast
= cpu_to_be32(XFS_AGFL_SIZE(mp
) - 1);
2896 agf
->agf_flcount
= 0;
2897 nbmblocks
= (xfs_extlen_t
)(agsize
- XFS_PREALLOC_BLOCKS(mp
));
2898 agf
->agf_freeblks
= cpu_to_be32(nbmblocks
);
2899 agf
->agf_longest
= cpu_to_be32(nbmblocks
);
2900 if (xfs_sb_version_hascrc(&mp
->m_sb
))
2901 platform_uuid_copy(&agf
->agf_uuid
, &mp
->m_sb
.sb_uuid
);
2903 if (loginternal
&& agno
== logagno
) {
2904 be32_add_cpu(&agf
->agf_freeblks
, -logblocks
);
2905 agf
->agf_longest
= cpu_to_be32(agsize
-
2906 XFS_FSB_TO_AGBNO(mp
, logstart
) - logblocks
);
2908 if (xfs_alloc_min_freelist(mp
, pag
) > worst_freelist
)
2909 worst_freelist
= xfs_alloc_min_freelist(mp
, pag
);
2910 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2913 * AG freelist header block
2915 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2916 XFS_AG_DADDR(mp
, agno
, XFS_AGFL_DADDR(mp
)),
2917 XFS_FSS_TO_BB(mp
, 1));
2918 buf
->b_ops
= &xfs_agfl_buf_ops
;
2919 agfl
= XFS_BUF_TO_AGFL(buf
);
2920 /* setting to 0xff results in initialisation to NULLAGBLOCK */
2921 memset(agfl
, 0xff, sectorsize
);
2922 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
2923 agfl
->agfl_magicnum
= cpu_to_be32(XFS_AGFL_MAGIC
);
2924 agfl
->agfl_seqno
= cpu_to_be32(agno
);
2925 platform_uuid_copy(&agfl
->agfl_uuid
, &mp
->m_sb
.sb_uuid
);
2926 for (bucket
= 0; bucket
< XFS_AGFL_SIZE(mp
); bucket
++)
2927 agfl
->agfl_bno
[bucket
] = cpu_to_be32(NULLAGBLOCK
);
2930 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2933 * AG header block: inodes
2935 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2936 XFS_AG_DADDR(mp
, agno
, XFS_AGI_DADDR(mp
)),
2937 XFS_FSS_TO_BB(mp
, 1));
2938 agi
= XFS_BUF_TO_AGI(buf
);
2939 buf
->b_ops
= &xfs_agi_buf_ops
;
2940 memset(agi
, 0, sectorsize
);
2941 agi
->agi_magicnum
= cpu_to_be32(XFS_AGI_MAGIC
);
2942 agi
->agi_versionnum
= cpu_to_be32(XFS_AGI_VERSION
);
2943 agi
->agi_seqno
= cpu_to_be32(agno
);
2944 agi
->agi_length
= cpu_to_be32((xfs_agblock_t
)agsize
);
2946 agi
->agi_root
= cpu_to_be32(XFS_IBT_BLOCK(mp
));
2947 agi
->agi_level
= cpu_to_be32(1);
2948 if (sb_feat
.finobt
) {
2949 agi
->agi_free_root
= cpu_to_be32(XFS_FIBT_BLOCK(mp
));
2950 agi
->agi_free_level
= cpu_to_be32(1);
2952 agi
->agi_freecount
= 0;
2953 agi
->agi_newino
= cpu_to_be32(NULLAGINO
);
2954 agi
->agi_dirino
= cpu_to_be32(NULLAGINO
);
2955 if (xfs_sb_version_hascrc(&mp
->m_sb
))
2956 platform_uuid_copy(&agi
->agi_uuid
, &mp
->m_sb
.sb_uuid
);
2957 for (c
= 0; c
< XFS_AGI_UNLINKED_BUCKETS
; c
++)
2958 agi
->agi_unlinked
[c
] = cpu_to_be32(NULLAGINO
);
2959 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
2962 * BNO btree root block
2964 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
2965 XFS_AGB_TO_DADDR(mp
, agno
, XFS_BNO_BLOCK(mp
)),
2967 buf
->b_ops
= &xfs_allocbt_buf_ops
;
2968 block
= XFS_BUF_TO_BLOCK(buf
);
2969 memset(block
, 0, blocksize
);
2970 if (xfs_sb_version_hascrc(&mp
->m_sb
))
2971 xfs_btree_init_block(mp
, buf
, XFS_ABTB_CRC_MAGIC
, 0, 1,
2972 agno
, XFS_BTREE_CRC_BLOCKS
);
2974 xfs_btree_init_block(mp
, buf
, XFS_ABTB_MAGIC
, 0, 1,
2977 arec
= XFS_ALLOC_REC_ADDR(mp
, block
, 1);
2978 arec
->ar_startblock
= cpu_to_be32(XFS_PREALLOC_BLOCKS(mp
));
2979 if (loginternal
&& agno
== logagno
) {
2982 * Have to insert two records
2983 * Insert pad record for stripe align of log
2985 arec
->ar_blockcount
= cpu_to_be32(
2986 XFS_FSB_TO_AGBNO(mp
, logstart
) -
2987 be32_to_cpu(arec
->ar_startblock
));
2990 * Insert record at start of internal log
2992 nrec
->ar_startblock
= cpu_to_be32(
2993 be32_to_cpu(arec
->ar_startblock
) +
2994 be32_to_cpu(arec
->ar_blockcount
));
2996 be16_add_cpu(&block
->bb_numrecs
, 1);
2999 * Change record start to after the internal log
3001 be32_add_cpu(&arec
->ar_startblock
, logblocks
);
3004 * Calculate the record block count and check for the case where
3005 * the log might have consumed all available space in the AG. If
3006 * so, reset the record count to 0 to avoid exposure of an invalid
3007 * record start block.
3009 arec
->ar_blockcount
= cpu_to_be32(agsize
-
3010 be32_to_cpu(arec
->ar_startblock
));
3011 if (!arec
->ar_blockcount
)
3012 block
->bb_numrecs
= 0;
3014 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3017 * CNT btree root block
3019 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3020 XFS_AGB_TO_DADDR(mp
, agno
, XFS_CNT_BLOCK(mp
)),
3022 buf
->b_ops
= &xfs_allocbt_buf_ops
;
3023 block
= XFS_BUF_TO_BLOCK(buf
);
3024 memset(block
, 0, blocksize
);
3025 if (xfs_sb_version_hascrc(&mp
->m_sb
))
3026 xfs_btree_init_block(mp
, buf
, XFS_ABTC_CRC_MAGIC
, 0, 1,
3027 agno
, XFS_BTREE_CRC_BLOCKS
);
3029 xfs_btree_init_block(mp
, buf
, XFS_ABTC_MAGIC
, 0, 1,
3032 arec
= XFS_ALLOC_REC_ADDR(mp
, block
, 1);
3033 arec
->ar_startblock
= cpu_to_be32(XFS_PREALLOC_BLOCKS(mp
));
3034 if (loginternal
&& agno
== logagno
) {
3036 arec
->ar_blockcount
= cpu_to_be32(
3037 XFS_FSB_TO_AGBNO(mp
, logstart
) -
3038 be32_to_cpu(arec
->ar_startblock
));
3040 nrec
->ar_startblock
= cpu_to_be32(
3041 be32_to_cpu(arec
->ar_startblock
) +
3042 be32_to_cpu(arec
->ar_blockcount
));
3044 be16_add_cpu(&block
->bb_numrecs
, 1);
3046 be32_add_cpu(&arec
->ar_startblock
, logblocks
);
3049 * Calculate the record block count and check for the case where
3050 * the log might have consumed all available space in the AG. If
3051 * so, reset the record count to 0 to avoid exposure of an invalid
3052 * record start block.
3054 arec
->ar_blockcount
= cpu_to_be32(agsize
-
3055 be32_to_cpu(arec
->ar_startblock
));
3056 if (!arec
->ar_blockcount
)
3057 block
->bb_numrecs
= 0;
3059 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3062 * INO btree root block
3064 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3065 XFS_AGB_TO_DADDR(mp
, agno
, XFS_IBT_BLOCK(mp
)),
3067 buf
->b_ops
= &xfs_inobt_buf_ops
;
3068 block
= XFS_BUF_TO_BLOCK(buf
);
3069 memset(block
, 0, blocksize
);
3070 if (xfs_sb_version_hascrc(&mp
->m_sb
))
3071 xfs_btree_init_block(mp
, buf
, XFS_IBT_CRC_MAGIC
, 0, 0,
3072 agno
, XFS_BTREE_CRC_BLOCKS
);
3074 xfs_btree_init_block(mp
, buf
, XFS_IBT_MAGIC
, 0, 0,
3076 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3079 * Free INO btree root block
3081 if (!sb_feat
.finobt
) {
3086 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3087 XFS_AGB_TO_DADDR(mp
, agno
, XFS_FIBT_BLOCK(mp
)),
3089 buf
->b_ops
= &xfs_inobt_buf_ops
;
3090 block
= XFS_BUF_TO_BLOCK(buf
);
3091 memset(block
, 0, blocksize
);
3092 if (xfs_sb_version_hascrc(&mp
->m_sb
))
3093 xfs_btree_init_block(mp
, buf
, XFS_FIBT_CRC_MAGIC
, 0, 0,
3094 agno
, XFS_BTREE_CRC_BLOCKS
);
3096 xfs_btree_init_block(mp
, buf
, XFS_FIBT_MAGIC
, 0, 0,
3098 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3103 * Touch last block, make fs the right size if it's a file.
3105 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3106 (xfs_daddr_t
)XFS_FSB_TO_BB(mp
, dblocks
- 1LL), bsize
);
3107 memset(XFS_BUF_PTR(buf
), 0, blocksize
);
3108 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3111 * Make sure we can write the last block in the realtime area.
3113 if (mp
->m_rtdev_targp
->dev
&& rtblocks
> 0) {
3114 buf
= libxfs_getbuf(mp
->m_rtdev_targp
,
3115 XFS_FSB_TO_BB(mp
, rtblocks
- 1LL), bsize
);
3116 memset(XFS_BUF_PTR(buf
), 0, blocksize
);
3117 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3121 * BNO, CNT free block list
3123 for (agno
= 0; agno
< agcount
; agno
++) {
3124 xfs_alloc_arg_t args
;
3126 struct xfs_trans_res tres
= {0};
3128 memset(&args
, 0, sizeof(args
));
3129 args
.tp
= tp
= libxfs_trans_alloc(mp
, 0);
3133 args
.pag
= xfs_perag_get(mp
,agno
);
3134 c
= -libxfs_trans_reserve(tp
, &tres
, worst_freelist
, 0);
3138 libxfs_alloc_fix_freelist(&args
, 0);
3139 xfs_perag_put(args
.pag
);
3140 libxfs_trans_commit(tp
);
3144 * Allocate the root inode and anything else in the proto file.
3146 parse_proto(mp
, &fsx
, &protostring
);
3149 * Protect ourselves against possible stupidity
3151 if (XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
) != 0) {
3153 _("%s: root inode created in AG %u, not AG 0\n"),
3154 progname
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
));
3159 * Write out multiple secondary superblocks with rootinode field set
3161 if (mp
->m_sb
.sb_agcount
> 1) {
3163 * the last superblock
3165 buf
= libxfs_readbuf(mp
->m_dev
,
3166 XFS_AGB_TO_DADDR(mp
, mp
->m_sb
.sb_agcount
-1,
3168 XFS_FSS_TO_BB(mp
, 1),
3169 LIBXFS_EXIT_ON_FAILURE
, &xfs_sb_buf_ops
);
3170 XFS_BUF_TO_SBP(buf
)->sb_rootino
= cpu_to_be64(
3171 mp
->m_sb
.sb_rootino
);
3172 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3174 * and one in the middle for luck
3176 if (mp
->m_sb
.sb_agcount
> 2) {
3177 buf
= libxfs_readbuf(mp
->m_dev
,
3178 XFS_AGB_TO_DADDR(mp
, (mp
->m_sb
.sb_agcount
-1)/2,
3180 XFS_FSS_TO_BB(mp
, 1),
3181 LIBXFS_EXIT_ON_FAILURE
, &xfs_sb_buf_ops
);
3182 XFS_BUF_TO_SBP(buf
)->sb_rootino
= cpu_to_be64(
3183 mp
->m_sb
.sb_rootino
);
3184 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3189 * Dump all inodes and buffers before marking us all done.
3190 * Need to drop references to inodes we still hold, first.
3192 libxfs_rtmount_destroy(mp
);
3193 libxfs_bcache_purge();
3196 * Mark the filesystem ok.
3198 buf
= libxfs_getsb(mp
, LIBXFS_EXIT_ON_FAILURE
);
3199 (XFS_BUF_TO_SBP(buf
))->sb_inprogress
= 0;
3200 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3204 libxfs_device_close(xi
.rtdev
);
3205 if (xi
.logdev
&& xi
.logdev
!= xi
.ddev
)
3206 libxfs_device_close(xi
.logdev
);
3207 libxfs_device_close(xi
.ddev
);
3219 fprintf(stderr
, _("Cannot specify both -%c %s and -%c %s\n"),
3220 opt
, tab
[oldidx
], opt
, tab
[newidx
]);
3230 fprintf(stderr
, _("Illegal value %s for -%s option\n"), value
, opt
);
3238 return (i
& (i
- 1)) == 0;
3241 static void __attribute__((noreturn
))
3247 fprintf(stderr
, _("-%c %s option requires a value\n"), opt
, tab
[idx
]);
3257 fprintf(stderr
, "-%c ", opt
);
3259 fprintf(stderr
, "%s ", tab
[idx
]);
3260 fprintf(stderr
, _("option respecified\n"));
3269 fprintf(stderr
, _("unknown option -%c %s\n"), opt
, s
);
3275 unsigned int blksize
,
3276 unsigned int sectsize
,
3283 i
= strtoll(s
, &sp
, 0);
3284 if (i
== 0 && sp
== s
)
3295 return i
* sectsize
;
3322 static void __attribute__((noreturn
))
3325 fprintf(stderr
, _("Usage: %s\n\
3326 /* blocksize */ [-b log=n|size=num]\n\
3327 /* metadata */ [-m crc=0|1,finobt=0|1,uuid=xxx]\n\
3328 /* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num,\n\
3329 (sunit=value,swidth=value|su=num,sw=num|noalign),\n\
3330 sectlog=n|sectsize=num\n\
3331 /* force overwrite */ [-f]\n\
3332 /* inode size */ [-i log=n|perblock=n|size=num,maxpct=n,attr=0|1|2,\n\
3333 projid32bit=0|1,sparse=0|1]\n\
3334 /* no discard */ [-K]\n\
3335 /* log subvol */ [-l agnum=n,internal,size=num,logdev=xxx,version=n\n\
3336 sunit=value|su=num,sectlog=n|sectsize=num,\n\
3338 /* label */ [-L label (maximum 12 characters)]\n\
3339 /* naming */ [-n log=n|size=num,version=2|ci,ftype=0|1]\n\
3340 /* no-op info only */ [-N]\n\
3341 /* prototype file */ [-p fname]\n\
3343 /* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx]\n\
3344 /* sectorsize */ [-s log=n|size=num]\n\
3345 /* version */ [-V]\n\
3347 <devicename> is required unless -d name=xxx is given.\n\
3348 <num> is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxx KiB),\n\
3349 xxxm (xxx MiB), xxxg (xxx GiB), xxxt (xxx TiB) or xxxp (xxx PiB).\n\
3350 <value> is xxx (512 byte blocks).\n"),