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"
27 * Device topology information.
30 int dsunit
; /* stripe unit - data subvolume */
31 int dswidth
; /* stripe width - data subvolume */
32 int rtswidth
; /* stripe width - rt subvolume */
33 int lsectorsize
; /* logical sector size &*/
34 int psectorsize
; /* physical sector size */
38 * Prototypes for internal functions.
40 static void conflict(char opt
, char *tab
[], int oldidx
, int newidx
);
41 static void illegal(const char *value
, const char *opt
);
42 static __attribute__((noreturn
)) void usage (void);
43 static __attribute__((noreturn
)) void reqval(char opt
, char *tab
[], int idx
);
44 static void respec(char opt
, char *tab
[], int idx
);
45 static void unknown(char opt
, char *s
);
46 static int ispow2(unsigned int i
);
48 static long long cvtnum(unsigned int blocksize
,
49 unsigned int sectorsize
, const char *s
);
51 #define MAX_SUBOPTS 16
52 #define SUBOPT_NEEDS_VAL (-1LL)
54 * Table for parsing mkfs parameters.
56 * Description of the structure members follows:
59 * Name is a single char, e.g., for '-d file', name is 'd'.
62 * Subopts is a list of strings naming suboptions. In the example above,
63 * it would contain "file". The last entry of this list has to be NULL.
65 * subopt_params MANDATORY
66 * This is a list of structs tied with subopts. For each entry in subopts,
67 * a corresponding entry has to be defined:
69 * subopt_params struct:
71 * This number, starting from zero, denotes which item in subopt_params
72 * it is. The index has to be the same as is the order in subopts list,
73 * so we can access the right item both in subopt_param and subopts.
76 * Do not set this flag when definning a subopt. It is used to remeber that
77 * this subopt was already seen, for example for conflicts detection.
79 * minval, maxval OPTIONAL
80 * These options are used for automatic range check and they have to be
81 * always used together in pair. If you don't want to limit the max value,
82 * use something like UINT_MAX. If no value is given, then you must either
83 * supply your own validation, or refuse any value in the 'case
84 * X_SOMETHING' block. If you forget to define the min and max value, but
85 * call a standard function for validating user's value, it will cause an
86 * error message notifying you about this issue.
88 * (Said in another way, you can't have minval and maxval both equal
89 * to zero. But if one value is different: minval=0 and maxval=1,
92 * defaultval MANDATORY
93 * The value used if user specifies the subopt, but no value.
94 * If the subopt accepts some values (-d file=[1|0]), then this
95 * sets what is used with simple specifying the subopt (-d file).
96 * A special SUBOPT_NEEDS_VAL can be used to require a user-given
101 const char *subopts
[MAX_SUBOPTS
];
103 struct subopt_param
{
108 long long defaultval
;
109 } subopt_params
[MAX_SUBOPTS
];
112 struct opt_params bopts
= {
123 .minval
= XFS_MIN_BLOCKSIZE_LOG
,
124 .maxval
= XFS_MAX_BLOCKSIZE_LOG
,
125 .defaultval
= SUBOPT_NEEDS_VAL
,
128 .minval
= XFS_MIN_BLOCKSIZE
,
129 .maxval
= XFS_MAX_BLOCKSIZE
,
130 .defaultval
= SUBOPT_NEEDS_VAL
,
135 struct opt_params dopts
= {
158 #define D_SECTSIZE 10
162 #define D_RTINHERIT 12
164 #define D_PROJINHERIT 13
166 #define D_EXTSZINHERIT 14
171 { .index
= D_AGCOUNT
,
173 .maxval
= XFS_MAX_AGNUMBER
,
174 .defaultval
= SUBOPT_NEEDS_VAL
,
182 .defaultval
= SUBOPT_NEEDS_VAL
,
185 .defaultval
= SUBOPT_NEEDS_VAL
,
190 .defaultval
= SUBOPT_NEEDS_VAL
,
195 .defaultval
= SUBOPT_NEEDS_VAL
,
198 .minval
= XFS_AG_MIN_BYTES
,
199 .maxval
= XFS_AG_MAX_BYTES
,
200 .defaultval
= SUBOPT_NEEDS_VAL
,
203 .defaultval
= SUBOPT_NEEDS_VAL
,
208 .defaultval
= SUBOPT_NEEDS_VAL
,
210 { .index
= D_SECTLOG
,
211 .minval
= XFS_MIN_SECTORSIZE_LOG
,
212 .maxval
= XFS_MAX_SECTORSIZE_LOG
,
213 .defaultval
= SUBOPT_NEEDS_VAL
,
215 { .index
= D_SECTSIZE
,
216 .minval
= XFS_MIN_SECTORSIZE
,
217 .maxval
= XFS_MAX_SECTORSIZE
,
218 .defaultval
= SUBOPT_NEEDS_VAL
,
220 { .index
= D_NOALIGN
,
225 { .index
= D_RTINHERIT
,
230 { .index
= D_PROJINHERIT
,
233 .defaultval
= SUBOPT_NEEDS_VAL
,
235 { .index
= D_EXTSZINHERIT
,
238 .defaultval
= SUBOPT_NEEDS_VAL
,
244 struct opt_params iopts
= {
259 #define I_PROJID32BIT 6
272 .minval
= XFS_DINODE_MIN_LOG
,
273 .maxval
= XFS_DINODE_MAX_LOG
,
274 .defaultval
= SUBOPT_NEEDS_VAL
,
279 .defaultval
= SUBOPT_NEEDS_VAL
,
281 { .index
= I_PERBLOCK
,
282 .minval
= XFS_MIN_INODE_PERBLOCK
,
283 .maxval
= XFS_MAX_BLOCKSIZE
/ XFS_DINODE_MIN_SIZE
,
284 .defaultval
= SUBOPT_NEEDS_VAL
,
287 .minval
= XFS_DINODE_MIN_SIZE
,
288 .maxval
= XFS_DINODE_MAX_SIZE
,
289 .defaultval
= SUBOPT_NEEDS_VAL
,
294 .defaultval
= SUBOPT_NEEDS_VAL
,
296 { .index
= I_PROJID32BIT
,
301 { .index
= I_SPINODES
,
309 struct opt_params lopts
= {
334 #define L_LAZYSBCNTR 11
342 .defaultval
= SUBOPT_NEEDS_VAL
,
344 { .index
= L_INTERNAL
,
350 .defaultval
= SUBOPT_NEEDS_VAL
,
352 { .index
= L_VERSION
,
355 .defaultval
= SUBOPT_NEEDS_VAL
,
358 .minval
= BTOBB(XLOG_MIN_RECORD_BSIZE
),
359 .maxval
= BTOBB(XLOG_MAX_RECORD_BSIZE
),
360 .defaultval
= SUBOPT_NEEDS_VAL
,
363 .defaultval
= SUBOPT_NEEDS_VAL
,
366 .defaultval
= SUBOPT_NEEDS_VAL
,
368 { .index
= L_SECTLOG
,
369 .minval
= XFS_MIN_SECTORSIZE_LOG
,
370 .maxval
= XFS_MAX_SECTORSIZE_LOG
,
371 .defaultval
= SUBOPT_NEEDS_VAL
,
373 { .index
= L_SECTSIZE
,
374 .minval
= XFS_MIN_SECTORSIZE
,
375 .maxval
= XFS_MAX_SECTORSIZE
,
376 .defaultval
= SUBOPT_NEEDS_VAL
,
384 .defaultval
= SUBOPT_NEEDS_VAL
,
386 { .index
= L_LAZYSBCNTR
,
394 struct opt_params nopts
= {
409 .minval
= XFS_MIN_REC_DIRSIZE
,
410 .maxval
= XFS_MAX_BLOCKSIZE_LOG
,
411 .defaultval
= SUBOPT_NEEDS_VAL
,
414 .minval
= 1 << XFS_MIN_REC_DIRSIZE
,
415 .maxval
= XFS_MAX_BLOCKSIZE
,
416 .defaultval
= SUBOPT_NEEDS_VAL
,
418 { .index
= N_VERSION
,
421 .defaultval
= SUBOPT_NEEDS_VAL
,
431 struct opt_params ropts
= {
449 { .index
= R_EXTSIZE
,
450 .defaultval
= SUBOPT_NEEDS_VAL
,
453 .defaultval
= SUBOPT_NEEDS_VAL
,
456 .defaultval
= SUBOPT_NEEDS_VAL
,
464 .defaultval
= SUBOPT_NEEDS_VAL
,
466 { .index
= R_NOALIGN
,
474 struct opt_params sopts
= {
489 .minval
= XFS_MIN_SECTORSIZE_LOG
,
490 .maxval
= XFS_MAX_SECTORSIZE_LOG
,
491 .defaultval
= SUBOPT_NEEDS_VAL
,
493 { .index
= S_SECTLOG
,
494 .minval
= XFS_MIN_SECTORSIZE_LOG
,
495 .maxval
= XFS_MAX_SECTORSIZE_LOG
,
496 .defaultval
= SUBOPT_NEEDS_VAL
,
499 .minval
= XFS_MIN_SECTORSIZE
,
500 .maxval
= XFS_MAX_SECTORSIZE
,
501 .defaultval
= SUBOPT_NEEDS_VAL
,
503 { .index
= S_SECTSIZE
,
504 .minval
= XFS_MIN_SECTORSIZE
,
505 .maxval
= XFS_MAX_SECTORSIZE
,
506 .defaultval
= SUBOPT_NEEDS_VAL
,
511 struct opt_params mopts
= {
534 .defaultval
= SUBOPT_NEEDS_VAL
,
539 #define TERABYTES(count, blog) ((__uint64_t)(count) << (40 - (blog)))
540 #define GIGABYTES(count, blog) ((__uint64_t)(count) << (30 - (blog)))
541 #define MEGABYTES(count, blog) ((__uint64_t)(count) << (20 - (blog)))
544 * Use this macro before we have superblock and mount structure
546 #define DTOBT(d) ((xfs_rfsblock_t)((d) >> (blocklog - BBSHIFT)))
549 * Use this for block reservations needed for mkfs's conditions
550 * (basically no fragmentation).
552 #define MKFS_BLOCKRES_INODE \
553 ((uint)(mp->m_ialloc_blks + (mp->m_in_maxlevels - 1)))
554 #define MKFS_BLOCKRES(rb) \
555 ((uint)(MKFS_BLOCKRES_INODE + XFS_DA_NODE_MAXDEPTH + \
556 (XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1) + (rb)))
558 /* amount (in bytes) we zero at the beginning and end of the device to
559 * remove traces of other filesystems, raid superblocks, etc.
561 #define WHACK_SIZE (128 * 1024)
574 /* Handle data sunit/swidth options */
575 if (*dsunit
|| *dswidth
) {
578 _("data su/sw must not be used in "
579 "conjunction with data sunit/swidth\n"));
583 if ((*dsunit
&& !*dswidth
) || (!*dsunit
&& *dswidth
)) {
585 _("both data sunit and data swidth options "
586 "must be specified\n"));
592 if (*dsunit
|| *dswidth
) {
594 _("data sunit/swidth must not be used in "
595 "conjunction with data su/sw\n"));
599 if ((dsu
&& !dsw
) || (!dsu
&& dsw
)) {
601 _("both data su and data sw options "
602 "must be specified\n"));
608 _("data su must be a multiple of the "
609 "sector size (%d)\n"), dsectsz
);
613 *dsunit
= (int)BTOBBT(dsu
);
614 *dswidth
= *dsunit
* dsw
;
617 if (*dsunit
&& (*dswidth
% *dsunit
!= 0)) {
619 _("data stripe width (%d) must be a multiple of the "
620 "data stripe unit (%d)\n"), *dswidth
, *dsunit
);
624 /* Handle log sunit options */
629 _("log su should not be used in "
630 "conjunction with log sunit\n"));
638 _("log sunit should not be used in "
639 "conjunction with log su\n"));
642 *lsunit
= (int)BTOBBT(lsu
);
647 * Check for existing filesystem or partition table on device.
649 * 1 for existing fs or partition
650 * 0 for nothing found
651 * -1 for internal error
659 blkid_probe pr
= NULL
;
665 if (!device
|| !*device
)
668 ret
= -1; /* will reset on success of all setup calls */
670 fd
= open(device
, O_RDONLY
);
673 platform_findsizes(device
, fd
, &size
, &bsz
);
676 /* nothing to overwrite on a 0-length device */
682 pr
= blkid_new_probe_from_filename(device
);
686 ret
= blkid_probe_enable_partitions(pr
, 1);
690 ret
= blkid_do_fullprobe(pr
);
695 * Blkid returns 1 for nothing found and 0 when it finds a signature,
696 * but we want the exact opposite, so reverse the return value here.
698 * In addition print some useful diagnostics about what actually is
706 if (!blkid_probe_lookup_value(pr
, "TYPE", &type
, NULL
)) {
708 _("%s: %s appears to contain an existing "
709 "filesystem (%s).\n"), progname
, device
, type
);
710 } else if (!blkid_probe_lookup_value(pr
, "PTTYPE", &type
, NULL
)) {
712 _("%s: %s appears to contain a partition "
713 "table (%s).\n"), progname
, device
, type
);
716 _("%s: %s appears to contain something weird "
717 "according to blkid\n"), progname
, device
);
723 blkid_free_probe(pr
);
726 _("%s: probe of %s failed, cannot detect "
727 "existing filesystem.\n"), progname
, device
);
731 static void blkid_get_topology(
745 /* can't get topology info from a file */
746 if (!stat(device
, &statbuf
) && S_ISREG(statbuf
.st_mode
))
749 pr
= blkid_new_probe_from_filename(device
);
753 tp
= blkid_probe_get_topology(pr
);
757 val
= blkid_topology_get_logical_sector_size(tp
);
759 val
= blkid_topology_get_physical_sector_size(tp
);
761 val
= blkid_topology_get_minimum_io_size(tp
);
763 val
= blkid_topology_get_optimal_io_size(tp
);
767 * If the reported values are the same as the physical sector size
768 * do not bother to report anything. It will only cause warnings
769 * if people specify larger stripe units or widths manually.
771 if (*sunit
== *psectorsize
|| *swidth
== *psectorsize
) {
777 * Blkid reports the information in terms of bytes, but we want it in
778 * terms of 512 bytes blocks (only to convert it to bytes later..)
780 *sunit
= *sunit
>> 9;
781 *swidth
= *swidth
>> 9;
783 if (blkid_topology_get_alignment_offset(tp
) != 0) {
785 _("warning: device is not properly aligned %s\n"),
788 if (!force_overwrite
) {
790 _("Use -f to force usage of a misaligned device\n"));
794 /* Do not use physical sector size if the device is misaligned */
795 *psectorsize
= *lsectorsize
;
798 blkid_free_probe(pr
);
802 blkid_free_probe(pr
);
804 _("warning: unable to probe device topology for device %s\n"),
807 #else /* ifdef ENABLE_BLKID */
809 * Without blkid, we can't do a good check for signatures.
810 * So instead of some messy attempts, just disable any checks
811 * and always return 'nothing found'.
813 # warning BLKID is disabled, so signature detection and block device\
814 access are not working!
822 static void blkid_get_topology(
831 * Shouldn't make any difference (no blkid = no block device access),
832 * but make sure this dummy replacement returns with at least some
835 *lsectorsize
= *psectorsize
= 512;
838 #endif /* ENABLE_BLKID */
840 static void get_topology(
842 struct fs_topology
*ft
,
846 char *dfile
= xi
->volname
? xi
->volname
: xi
->dname
;
849 * If our target is a regular file, use platform_findsizes
850 * to try to obtain the underlying filesystem's requirements
851 * for direct IO; we'll set our sector size to that if possible.
854 (!stat(dfile
, &statbuf
) && S_ISREG(statbuf
.st_mode
))) {
856 int flags
= O_RDONLY
;
859 /* with xi->disfile we may not have the file yet! */
863 fd
= open(dfile
, flags
, 0666);
865 platform_findsizes(dfile
, fd
, &dummy
, &ft
->lsectorsize
);
867 ft
->psectorsize
= ft
->lsectorsize
;
869 ft
->psectorsize
= ft
->lsectorsize
= BBSIZE
;
871 blkid_get_topology(dfile
, &ft
->dsunit
, &ft
->dswidth
,
872 &ft
->lsectorsize
, &ft
->psectorsize
,
876 if (xi
->rtname
&& !xi
->risfile
) {
877 int sunit
, lsectorsize
, psectorsize
;
879 blkid_get_topology(xi
->rtname
, &sunit
, &ft
->rtswidth
,
880 &lsectorsize
, &psectorsize
, force_overwrite
);
885 fixup_log_stripe_unit(
888 xfs_rfsblock_t
*logblocks
,
891 __uint64_t tmp_logblocks
;
894 * Make sure that the log size is a multiple of the stripe unit
896 if ((*logblocks
% sunit
) != 0) {
898 tmp_logblocks
= ((*logblocks
+ (sunit
- 1))
901 * If the log is too large, round down
902 * instead of round up
904 if ((tmp_logblocks
> XFS_MAX_LOG_BLOCKS
) ||
905 ((tmp_logblocks
<< blocklog
) > XFS_MAX_LOG_BYTES
)) {
906 tmp_logblocks
= (*logblocks
/ sunit
) * sunit
;
908 *logblocks
= tmp_logblocks
;
910 fprintf(stderr
, _("log size %lld is not a multiple "
911 "of the log stripe unit %d\n"),
912 (long long) *logblocks
, sunit
);
919 fixup_internal_log_stripe(
922 xfs_fsblock_t logstart
,
925 xfs_rfsblock_t
*logblocks
,
929 if ((logstart
% sunit
) != 0) {
930 logstart
= ((logstart
+ (sunit
- 1))/sunit
) * sunit
;
934 fixup_log_stripe_unit(lsflag
, sunit
, logblocks
, blocklog
);
936 if (*logblocks
> agsize
- XFS_FSB_TO_AGBNO(mp
, logstart
)) {
938 _("Due to stripe alignment, the internal log size "
939 "(%lld) is too large.\n"), (long long) *logblocks
);
940 fprintf(stderr
, _("Must fit within an allocation group.\n"));
947 validate_log_size(__uint64_t logblocks
, int blocklog
, int min_logblocks
)
949 if (logblocks
< min_logblocks
) {
951 _("log size %lld blocks too small, minimum size is %d blocks\n"),
952 (long long)logblocks
, min_logblocks
);
955 if (logblocks
> XFS_MAX_LOG_BLOCKS
) {
957 _("log size %lld blocks too large, maximum size is %lld blocks\n"),
958 (long long)logblocks
, XFS_MAX_LOG_BLOCKS
);
961 if ((logblocks
<< blocklog
) > XFS_MAX_LOG_BYTES
) {
963 _("log size %lld bytes too large, maximum size is %lld bytes\n"),
964 (long long)(logblocks
<< blocklog
), XFS_MAX_LOG_BYTES
);
970 calc_default_imaxpct(
975 * This returns the % of the disk space that is used for
976 * inodes, it changes relatively to the FS size:
977 * - over 50 TB, use 1%,
978 * - 1TB - 50 TB, use 5%,
979 * - under 1 TB, use XFS_DFL_IMAXIMUM_PCT (25%).
982 if (dblocks
< TERABYTES(1, blocklog
)) {
983 return XFS_DFL_IMAXIMUM_PCT
;
984 } else if (dblocks
< TERABYTES(50, blocklog
)) {
993 calc_default_ag_geometry(
1000 __uint64_t blocks
= 0;
1004 * First handle the high extreme - the point at which we will
1005 * always use the maximum AG size.
1007 * This applies regardless of storage configuration.
1009 if (dblocks
>= TERABYTES(32, blocklog
)) {
1010 blocks
= XFS_AG_MAX_BLOCKS(blocklog
);
1015 * For a single underlying storage device over 4TB in size
1016 * use the maximum AG size. Between 128MB and 4TB, just use
1017 * 4 AGs and scale up smoothly between min/max AG sizes.
1020 if (dblocks
>= TERABYTES(4, blocklog
)) {
1021 blocks
= XFS_AG_MAX_BLOCKS(blocklog
);
1023 } else if (dblocks
>= MEGABYTES(128, blocklog
)) {
1024 shift
= XFS_NOMULTIDISK_AGLOG
;
1030 * For the multidisk configs we choose an AG count based on the number
1031 * of data blocks available, trying to keep the number of AGs higher
1032 * than the single disk configurations. This makes the assumption that
1033 * larger filesystems have more parallelism available to them.
1035 shift
= XFS_MULTIDISK_AGLOG
;
1036 if (dblocks
<= GIGABYTES(512, blocklog
))
1038 if (dblocks
<= GIGABYTES(8, blocklog
))
1040 if (dblocks
< MEGABYTES(128, blocklog
))
1042 if (dblocks
< MEGABYTES(64, blocklog
))
1044 if (dblocks
< MEGABYTES(32, blocklog
))
1048 * If dblocks is not evenly divisible by the number of
1049 * desired AGs, round "blocks" up so we don't lose the
1050 * last bit of the filesystem. The same principle applies
1051 * to the AG count, so we don't lose the last AG!
1054 ASSERT(shift
>= 0 && shift
<= XFS_MULTIDISK_AGLOG
);
1055 blocks
= dblocks
>> shift
;
1056 if (dblocks
& xfs_mask32lo(shift
)) {
1057 if (blocks
< XFS_AG_MAX_BLOCKS(blocklog
))
1062 *agcount
= dblocks
/ blocks
+ (dblocks
% blocks
!= 0);
1066 validate_ag_geometry(
1072 if (agsize
< XFS_AG_MIN_BLOCKS(blocklog
)) {
1074 _("agsize (%lld blocks) too small, need at least %lld blocks\n"),
1076 (long long)XFS_AG_MIN_BLOCKS(blocklog
));
1080 if (agsize
> XFS_AG_MAX_BLOCKS(blocklog
)) {
1082 _("agsize (%lld blocks) too big, maximum is %lld blocks\n"),
1084 (long long)XFS_AG_MAX_BLOCKS(blocklog
));
1088 if (agsize
> dblocks
) {
1090 _("agsize (%lld blocks) too big, data area is %lld blocks\n"),
1091 (long long)agsize
, (long long)dblocks
);
1095 if (agsize
< XFS_AG_MIN_BLOCKS(blocklog
)) {
1097 _("too many allocation groups for size = %lld\n"),
1099 fprintf(stderr
, _("need at most %lld allocation groups\n"),
1100 (long long)(dblocks
/ XFS_AG_MIN_BLOCKS(blocklog
) +
1101 (dblocks
% XFS_AG_MIN_BLOCKS(blocklog
) != 0)));
1105 if (agsize
> XFS_AG_MAX_BLOCKS(blocklog
)) {
1107 _("too few allocation groups for size = %lld\n"), (long long)agsize
);
1109 _("need at least %lld allocation groups\n"),
1110 (long long)(dblocks
/ XFS_AG_MAX_BLOCKS(blocklog
) +
1111 (dblocks
% XFS_AG_MAX_BLOCKS(blocklog
) != 0)));
1116 * If the last AG is too small, reduce the filesystem size
1117 * and drop the blocks.
1119 if ( dblocks
% agsize
!= 0 &&
1120 (dblocks
% agsize
< XFS_AG_MIN_BLOCKS(blocklog
))) {
1122 _("last AG size %lld blocks too small, minimum size is %lld blocks\n"),
1123 (long long)(dblocks
% agsize
),
1124 (long long)XFS_AG_MIN_BLOCKS(blocklog
));
1129 * If agcount is too large, make it smaller.
1131 if (agcount
> XFS_MAX_AGNUMBER
+ 1) {
1133 _("%lld allocation groups is too many, maximum is %lld\n"),
1134 (long long)agcount
, (long long)XFS_MAX_AGNUMBER
+ 1);
1140 zero_old_xfs_structures(
1152 * We open regular files with O_TRUNC|O_CREAT. Nothing to do here...
1154 if (xi
->disfile
&& xi
->dcreat
)
1158 * read in existing filesystem superblock, use its geometry
1159 * settings and zero the existing secondary superblocks.
1161 buf
= memalign(libxfs_device_alignment(), new_sb
->sb_sectsize
);
1164 _("error reading existing superblock -- failed to memalign buffer\n"));
1167 memset(buf
, 0, new_sb
->sb_sectsize
);
1169 tmp
= pread(xi
->dfd
, buf
, new_sb
->sb_sectsize
, 0);
1171 fprintf(stderr
, _("existing superblock read failed: %s\n"),
1175 if (tmp
!= new_sb
->sb_sectsize
) {
1177 _("warning: could not read existing superblock, skip zeroing\n"));
1180 libxfs_sb_from_disk(&sb
, buf
);
1183 * perform same basic superblock validation to make sure we
1184 * actually zero secondary blocks
1186 if (sb
.sb_magicnum
!= XFS_SB_MAGIC
|| sb
.sb_blocksize
== 0)
1189 for (bsize
= 1, i
= 0; bsize
< sb
.sb_blocksize
&&
1190 i
< sizeof(sb
.sb_blocksize
) * NBBY
; i
++)
1193 if (i
< XFS_MIN_BLOCKSIZE_LOG
|| i
> XFS_MAX_BLOCKSIZE_LOG
||
1194 i
!= sb
.sb_blocklog
)
1197 if (sb
.sb_dblocks
> ((__uint64_t
)sb
.sb_agcount
* sb
.sb_agblocks
) ||
1198 sb
.sb_dblocks
< ((__uint64_t
)(sb
.sb_agcount
- 1) *
1199 sb
.sb_agblocks
+ XFS_MIN_AG_BLOCKS
))
1203 * block size and basic geometry seems alright, zero the secondaries.
1205 memset(buf
, 0, new_sb
->sb_sectsize
);
1207 for (i
= 1; i
< sb
.sb_agcount
; i
++) {
1208 off
+= sb
.sb_agblocks
;
1209 if (pwrite64(xi
->dfd
, buf
, new_sb
->sb_sectsize
,
1210 off
<< sb
.sb_blocklog
) == -1)
1218 discard_blocks(dev_t dev
, __uint64_t nsectors
)
1223 * We intentionally ignore errors from the discard ioctl. It is
1224 * not necessary for the mkfs functionality but just an optimization.
1226 fd
= libxfs_device_to_fd(dev
);
1228 platform_discard_blocks(fd
, 0, nsectors
<< 9);
1231 struct sb_feat_args
{
1239 bool lazy_sb_counters
;
1243 bool parent_pointers
;
1249 struct sb_feat_args
*fp
,
1255 sbp
->sb_versionnum
= XFS_DFL_SB_VERSION_BITS
;
1256 if (fp
->crcs_enabled
)
1257 sbp
->sb_versionnum
|= XFS_SB_VERSION_5
;
1259 sbp
->sb_versionnum
|= XFS_SB_VERSION_4
;
1261 if (fp
->inode_align
)
1262 sbp
->sb_versionnum
|= XFS_SB_VERSION_ALIGNBIT
;
1264 sbp
->sb_versionnum
|= XFS_SB_VERSION_DALIGNBIT
;
1265 if (fp
->log_version
== 2)
1266 sbp
->sb_versionnum
|= XFS_SB_VERSION_LOGV2BIT
;
1267 if (fp
->attr_version
== 1)
1268 sbp
->sb_versionnum
|= XFS_SB_VERSION_ATTRBIT
;
1269 if (sectsize
> BBSIZE
|| lsectsize
> BBSIZE
)
1270 sbp
->sb_versionnum
|= XFS_SB_VERSION_SECTORBIT
;
1272 sbp
->sb_versionnum
|= XFS_SB_VERSION_BORGBIT
;
1275 sbp
->sb_features2
= 0;
1276 if (fp
->lazy_sb_counters
)
1277 sbp
->sb_features2
|= XFS_SB_VERSION2_LAZYSBCOUNTBIT
;
1278 if (!fp
->projid16bit
)
1279 sbp
->sb_features2
|= XFS_SB_VERSION2_PROJID32BIT
;
1280 if (fp
->parent_pointers
)
1281 sbp
->sb_features2
|= XFS_SB_VERSION2_PARENTBIT
;
1282 if (fp
->crcs_enabled
)
1283 sbp
->sb_features2
|= XFS_SB_VERSION2_CRCBIT
;
1284 if (fp
->attr_version
== 2)
1285 sbp
->sb_features2
|= XFS_SB_VERSION2_ATTR2BIT
;
1287 /* v5 superblocks have their own feature bit for dirftype */
1288 if (fp
->dirftype
&& !fp
->crcs_enabled
)
1289 sbp
->sb_features2
|= XFS_SB_VERSION2_FTYPE
;
1291 /* update whether extended features are in use */
1292 if (sbp
->sb_features2
!= 0)
1293 sbp
->sb_versionnum
|= XFS_SB_VERSION_MOREBITSBIT
;
1296 * Due to a structure alignment issue, sb_features2 ended up in one
1297 * of two locations, the second "incorrect" location represented by
1298 * the sb_bad_features2 field. To avoid older kernels mounting
1299 * filesystems they shouldn't, set both field to the same value.
1301 sbp
->sb_bad_features2
= sbp
->sb_features2
;
1303 if (!fp
->crcs_enabled
)
1306 /* default features for v5 filesystems */
1307 sbp
->sb_features_compat
= 0;
1308 sbp
->sb_features_ro_compat
= 0;
1309 sbp
->sb_features_incompat
= XFS_SB_FEAT_INCOMPAT_FTYPE
;
1310 sbp
->sb_features_log_incompat
= 0;
1313 sbp
->sb_features_ro_compat
= XFS_SB_FEAT_RO_COMPAT_FINOBT
;
1316 * Sparse inode chunk support has two main inode alignment requirements.
1317 * First, sparse chunk alignment must match the cluster size. Second,
1318 * full chunk alignment must match the inode chunk size.
1320 * Copy the already calculated/scaled inoalignmt to spino_align and
1321 * update the former to the full inode chunk size.
1324 sbp
->sb_spino_align
= sbp
->sb_inoalignmt
;
1325 sbp
->sb_inoalignmt
= XFS_INODES_PER_CHUNK
*
1326 sbp
->sb_inodesize
>> sbp
->sb_blocklog
;
1327 sbp
->sb_features_incompat
|= XFS_SB_FEAT_INCOMPAT_SPINODES
;
1335 unsigned int blocksize
,
1336 unsigned int sectorsize
,
1343 return cvtnum(blocksize
, sectorsize
, str
);
1345 i
= strtoll(str
, &sp
, 0);
1346 if (i
== 0 && sp
== str
)
1349 return -1LL; /* trailing garbage */
1353 static __attribute__((noreturn
)) void
1356 struct opt_params
*opts
,
1360 _("Illegal value %s for -%c %s option\n"),
1361 value
, opts
->name
, opts
->subopts
[index
]);
1368 struct opt_params
*opts
,
1371 struct subopt_param
*sp
= &opts
->subopt_params
[index
];
1374 if (sp
->index
!= index
) {
1376 ("Developer screwed up option parsing (%d/%d)! Please report!\n"),
1378 reqval(opts
->name
, (char **)opts
->subopts
, index
);
1381 /* check for respecification of the option */
1383 respec(opts
->name
, (char **)opts
->subopts
, index
);
1386 if (!str
|| *str
== '\0') {
1387 if (sp
->defaultval
== SUBOPT_NEEDS_VAL
)
1388 reqval(opts
->name
, (char **)opts
->subopts
, index
);
1389 return sp
->defaultval
;
1392 if (sp
->minval
== 0 && sp
->maxval
== 0) {
1394 _("Option -%c %s has undefined minval/maxval."
1395 "Can't verify value range. This is a bug.\n"),
1396 opts
->name
, opts
->subopts
[index
]);
1400 c
= getnum(str
, 0, 0, false);
1401 if (c
< sp
->minval
|| c
> sp
->maxval
)
1402 illegal_option(str
, opts
, index
);
1414 xfs_agnumber_t agno
;
1416 xfs_alloc_rec_t
*arec
;
1417 struct xfs_btree_block
*block
;
1420 unsigned int blocksize
;
1427 xfs_rfsblock_t dblocks
;
1436 int force_overwrite
;
1451 xfs_agnumber_t logagno
;
1452 xfs_rfsblock_t logblocks
;
1456 xfs_fsblock_t logstart
;
1470 xfs_extlen_t nbmblocks
;
1474 xfs_alloc_rec_t
*nrec
;
1483 xfs_rfsblock_t rtblocks
;
1484 xfs_extlen_t rtextblocks
;
1485 xfs_rtblock_t rtextents
;
1491 unsigned int sectorsize
;
1492 __uint64_t sector_mask
;
1495 __uint64_t tmp_agsize
;
1499 struct fs_topology ft
;
1500 struct sb_feat_args sb_feat
= {
1505 .dir_version
= XFS_DFL_DIR_VERSION
,
1506 .inode_align
= XFS_IFLAG_ALIGN
,
1508 .lazy_sb_counters
= true,
1509 .projid16bit
= false,
1510 .crcs_enabled
= true,
1512 .parent_pointers
= false,
1515 platform_uuid_generate(&uuid
);
1516 progname
= basename(argv
[0]);
1517 setlocale(LC_ALL
, "");
1518 bindtextdomain(PACKAGE
, LOCALEDIR
);
1519 textdomain(PACKAGE
);
1521 blflag
= bsflag
= slflag
= ssflag
= lslflag
= lssflag
= 0;
1522 blocklog
= blocksize
= 0;
1523 sectorlog
= lsectorlog
= 0;
1524 sectorsize
= lsectorsize
= 0;
1525 agsize
= daflag
= dasize
= dblocks
= 0;
1526 ilflag
= imflag
= ipflag
= isflag
= 0;
1527 liflag
= laflag
= lsflag
= lsuflag
= lsunitflag
= ldflag
= lvflag
= 0;
1529 logagno
= logblocks
= rtblocks
= rtextblocks
= 0;
1530 Nflag
= nlflag
= nsflag
= nvflag
= 0;
1531 dirblocklog
= dirblocksize
= 0;
1533 imaxpct
= inodelog
= inopblock
= isize
= 0;
1534 dfile
= logfile
= rtfile
= NULL
;
1535 dsize
= logsize
= rtsize
= rtextsize
= protofile
= NULL
;
1536 dsu
= dsw
= dsunit
= dswidth
= lalign
= lsu
= lsunit
= 0;
1537 nodsflag
= norsflag
= 0;
1538 force_overwrite
= 0;
1540 memset(&fsx
, 0, sizeof(fsx
));
1542 memset(&xi
, 0, sizeof(xi
));
1543 xi
.isdirect
= LIBXFS_DIRECT
;
1544 xi
.isreadonly
= LIBXFS_EXCLUSIVELY
;
1546 while ((c
= getopt(argc
, argv
, "b:d:i:l:L:m:n:KNp:qr:s:CfV")) != EOF
) {
1550 force_overwrite
= 1;
1554 while (*p
!= '\0') {
1555 char **subopts
= (char **)bopts
.subopts
;
1558 switch (getsubopt(&p
, (constpp
)subopts
,
1562 conflict('b', subopts
, B_SIZE
,
1564 blocklog
= getnum_checked(value
, &bopts
,
1566 blocksize
= 1 << blocklog
;
1570 if (!value
|| *value
== '\0')
1571 reqval('b', subopts
, B_SIZE
);
1573 respec('b', subopts
, B_SIZE
);
1575 conflict('b', subopts
, B_LOG
,
1577 blocksize
= getnum(value
, blocksize
,
1579 if (blocksize
<= 0 ||
1581 illegal(value
, "b size");
1582 blocklog
= libxfs_highbit32(blocksize
);
1586 unknown('b', value
);
1592 while (*p
!= '\0') {
1593 char **subopts
= (char **)dopts
.subopts
;
1596 switch (getsubopt(&p
, (constpp
)subopts
,
1599 agcount
= getnum_checked(value
, &dopts
,
1604 if (!value
|| *value
== '\0')
1605 reqval('d', subopts
, D_AGSIZE
);
1607 respec('d', subopts
, D_AGSIZE
);
1608 agsize
= getnum(value
, blocksize
,
1610 if ((__int64_t
)agsize
<= 0)
1611 illegal(value
, "d agsize");
1615 xi
.disfile
= getnum_checked(value
,
1617 if (xi
.disfile
&& !Nflag
)
1621 if (!value
|| *value
== '\0')
1622 reqval('d', subopts
, D_NAME
);
1624 respec('d', subopts
, D_NAME
);
1628 if (!value
|| *value
== '\0')
1629 reqval('d', subopts
, D_SIZE
);
1631 respec('d', subopts
, D_SIZE
);
1636 conflict('d', subopts
, D_NOALIGN
,
1638 dsunit
= getnum_checked(value
, &dopts
,
1643 conflict('d', subopts
, D_NOALIGN
,
1645 dswidth
= getnum_checked(value
, &dopts
,
1649 if (!value
|| *value
== '\0')
1650 reqval('d', subopts
, D_SU
);
1652 respec('d', subopts
, D_SU
);
1654 conflict('d', subopts
, D_NOALIGN
,
1656 dsu
= getnum(value
, blocksize
,
1659 illegal(value
, "d su");
1663 conflict('d', subopts
, D_NOALIGN
,
1665 dsw
= getnum_checked(value
, &dopts
,
1669 nodsflag
= getnum_checked(value
,
1673 conflict('d', subopts
, D_SU
,
1676 conflict('d', subopts
, D_SUNIT
,
1679 conflict('d', subopts
, D_SW
,
1682 conflict('d', subopts
, D_SWIDTH
,
1688 conflict('d', subopts
, D_SECTSIZE
,
1690 sectorlog
= getnum_checked(value
, &dopts
,
1692 sectorsize
= 1 << sectorlog
;
1696 if (!value
|| *value
== '\0')
1697 reqval('d', subopts
, D_SECTSIZE
);
1699 respec('d', subopts
, D_SECTSIZE
);
1701 conflict('d', subopts
, D_SECTLOG
,
1703 sectorsize
= getnum(value
, blocksize
,
1705 if (sectorsize
<= 0 ||
1706 !ispow2(sectorsize
))
1707 illegal(value
, "d sectsize");
1709 libxfs_highbit32(sectorsize
);
1713 c
= getnum_checked(value
, &dopts
,
1717 XFS_DIFLAG_RTINHERIT
;
1720 fsx
.fsx_projid
= getnum_checked(value
,
1721 &dopts
, D_PROJINHERIT
);
1723 XFS_DIFLAG_PROJINHERIT
;
1725 case D_EXTSZINHERIT
:
1726 fsx
.fsx_extsize
= getnum_checked(value
,
1727 &dopts
, D_EXTSZINHERIT
);
1729 XFS_DIFLAG_EXTSZINHERIT
;
1732 unknown('d', value
);
1738 while (*p
!= '\0') {
1739 char **subopts
= (char **)iopts
.subopts
;
1742 switch (getsubopt(&p
, (constpp
)subopts
,
1745 sb_feat
.inode_align
= getnum_checked(
1746 value
, &iopts
, I_ALIGN
);
1750 conflict('i', subopts
, I_PERBLOCK
,
1753 conflict('i', subopts
, I_SIZE
,
1755 inodelog
= getnum_checked(value
, &iopts
,
1757 isize
= 1 << inodelog
;
1761 imaxpct
= getnum_checked(value
, &iopts
,
1767 conflict('i', subopts
, I_LOG
,
1770 conflict('i', subopts
, I_SIZE
,
1772 inopblock
= getnum_checked(value
, &iopts
,
1774 if (!ispow2(inopblock
))
1775 illegal(value
, "i perblock");
1780 conflict('i', subopts
, I_LOG
,
1783 conflict('i', subopts
, I_PERBLOCK
,
1785 isize
= getnum_checked(value
, &iopts
,
1788 illegal(value
, "i size");
1789 inodelog
= libxfs_highbit32(isize
);
1793 sb_feat
.attr_version
= getnum_checked(
1794 value
, &iopts
, I_ATTR
);
1797 sb_feat
.projid16bit
=
1798 !getnum_checked(value
, &iopts
,
1803 getnum_checked(value
, &iopts
,
1807 unknown('i', value
);
1813 while (*p
!= '\0') {
1814 char **subopts
= (char **)lopts
.subopts
;
1817 switch (getsubopt(&p
, (constpp
)subopts
,
1821 conflict('l', subopts
, L_AGNUM
, L_DEV
);
1822 logagno
= getnum_checked(value
, &lopts
,
1827 xi
.lisfile
= getnum_checked(value
,
1829 if (xi
.lisfile
&& loginternal
)
1830 conflict('l', subopts
, L_INTERNAL
,
1837 conflict('l', subopts
, L_INTERNAL
, L_DEV
);
1839 conflict('l', subopts
, L_FILE
,
1842 loginternal
= getnum_checked(value
,
1843 &lopts
, L_INTERNAL
);
1847 if (!value
|| *value
== '\0')
1848 reqval('l', subopts
, L_SU
);
1850 respec('l', subopts
, L_SU
);
1851 lsu
= getnum(value
, blocksize
,
1854 illegal(value
, "l su");
1858 lsunit
= getnum_checked(value
, &lopts
,
1865 conflict('l', subopts
, L_AGNUM
, L_DEV
);
1867 conflict('l', subopts
, L_INTERNAL
, L_DEV
);
1868 if (!value
|| *value
== '\0')
1869 reqval('l', subopts
, L_NAME
);
1871 respec('l', subopts
, L_NAME
);
1878 sb_feat
.log_version
=
1879 getnum_checked(value
, &lopts
,
1884 if (!value
|| *value
== '\0')
1885 reqval('l', subopts
, L_SIZE
);
1887 respec('l', subopts
, L_SIZE
);
1893 conflict('l', subopts
, L_SECTSIZE
,
1895 lsectorlog
= getnum_checked(value
,
1897 lsectorsize
= 1 << lsectorlog
;
1901 if (!value
|| *value
== '\0')
1902 reqval('l', subopts
, L_SECTSIZE
);
1904 respec('l', subopts
, L_SECTSIZE
);
1906 conflict('l', subopts
, L_SECTLOG
,
1908 lsectorsize
= getnum(value
, blocksize
,
1910 if (lsectorsize
<= 0 ||
1911 !ispow2(lsectorsize
))
1912 illegal(value
, "l sectsize");
1914 libxfs_highbit32(lsectorsize
);
1918 sb_feat
.lazy_sb_counters
=
1919 getnum_checked(value
, &lopts
,
1923 unknown('l', value
);
1928 if (strlen(optarg
) > sizeof(sbp
->sb_fname
))
1929 illegal(optarg
, "L");
1934 while (*p
!= '\0') {
1935 char **subopts
= (char **)mopts
.subopts
;
1938 switch (getsubopt(&p
, (constpp
)subopts
,
1941 sb_feat
.crcs_enabled
=
1942 getnum_checked(value
, &mopts
,
1944 if (sb_feat
.crcs_enabled
)
1945 sb_feat
.dirftype
= true;
1948 sb_feat
.finobt
= getnum_checked(
1949 value
, &mopts
, M_FINOBT
);
1952 if (!value
|| *value
== '\0')
1953 reqval('m', subopts
, M_UUID
);
1954 if (platform_uuid_parse(value
, &uuid
))
1955 illegal(optarg
, "m uuid");
1958 unknown('m', value
);
1964 while (*p
!= '\0') {
1965 char **subopts
= (char **)nopts
.subopts
;
1968 switch (getsubopt(&p
, (constpp
)subopts
,
1972 conflict('n', subopts
, N_SIZE
,
1974 dirblocklog
= getnum_checked(value
,
1976 dirblocksize
= 1 << dirblocklog
;
1980 if (!value
|| *value
== '\0')
1981 reqval('n', subopts
, N_SIZE
);
1983 respec('n', subopts
, N_SIZE
);
1985 conflict('n', subopts
, N_LOG
,
1987 dirblocksize
= getnum(value
, blocksize
,
1989 if (dirblocksize
<= 0 ||
1990 !ispow2(dirblocksize
))
1991 illegal(value
, "n size");
1993 libxfs_highbit32(dirblocksize
);
1997 if (!value
|| *value
== '\0')
1998 reqval('n', subopts
, N_VERSION
);
2000 respec('n', subopts
, N_VERSION
);
2001 if (!strcasecmp(value
, "ci")) {
2005 sb_feat
.dir_version
=
2006 getnum_checked(value
,
2013 sb_feat
.dirftype
= getnum_checked(value
,
2017 unknown('n', value
);
2029 respec('p', NULL
, 0);
2037 while (*p
!= '\0') {
2038 char **subopts
= (char **)ropts
.subopts
;
2041 switch (getsubopt(&p
, (constpp
)subopts
,
2044 if (!value
|| *value
== '\0')
2045 reqval('r', subopts
, R_EXTSIZE
);
2047 respec('r', subopts
, R_EXTSIZE
);
2051 xi
.risfile
= getnum_checked(value
,
2058 if (!value
|| *value
== '\0')
2059 reqval('r', subopts
, R_NAME
);
2061 respec('r', subopts
, R_NAME
);
2065 if (!value
|| *value
== '\0')
2066 reqval('r', subopts
, R_SIZE
);
2068 respec('r', subopts
, R_SIZE
);
2072 norsflag
= getnum_checked(value
,
2076 unknown('r', value
);
2082 while (*p
!= '\0') {
2083 char **subopts
= (char **)sopts
.subopts
;
2086 switch (getsubopt(&p
, (constpp
)subopts
,
2090 if (ssflag
|| lssflag
)
2091 conflict('s', subopts
,
2092 S_SECTSIZE
, S_SECTLOG
);
2093 sectorlog
= getnum_checked(value
, &sopts
,
2095 lsectorlog
= sectorlog
;
2096 sectorsize
= 1 << sectorlog
;
2097 lsectorsize
= sectorsize
;
2098 lslflag
= slflag
= 1;
2102 if (!value
|| *value
== '\0')
2103 reqval('s', subopts
, S_SECTSIZE
);
2104 if (ssflag
|| lssflag
)
2105 respec('s', subopts
, S_SECTSIZE
);
2106 if (slflag
|| lslflag
)
2107 conflict('s', subopts
, S_SECTLOG
,
2109 sectorsize
= getnum(value
, blocksize
,
2111 if (sectorsize
<= 0 ||
2112 !ispow2(sectorsize
))
2113 illegal(value
, "s sectsize");
2114 lsectorsize
= sectorsize
;
2116 libxfs_highbit32(sectorsize
);
2117 lsectorlog
= sectorlog
;
2118 lssflag
= ssflag
= 1;
2121 unknown('s', value
);
2126 printf(_("%s version %s\n"), progname
, VERSION
);
2129 unknown(optopt
, "");
2132 if (argc
- optind
> 1) {
2133 fprintf(stderr
, _("extra arguments\n"));
2135 } else if (argc
- optind
== 1) {
2136 dfile
= xi
.volname
= argv
[optind
];
2139 _("cannot specify both %s and -d name=%s\n"),
2140 xi
.volname
, xi
.dname
);
2147 * Blocksize and sectorsize first, other things depend on them
2148 * For RAID4/5/6 we want to align sector size and block size,
2149 * so we need to start with the device geometry extraction too.
2151 if (!blflag
&& !bsflag
) {
2152 blocklog
= XFS_DFL_BLOCKSIZE_LOG
;
2153 blocksize
= 1 << XFS_DFL_BLOCKSIZE_LOG
;
2155 if (blocksize
< XFS_MIN_BLOCKSIZE
|| blocksize
> XFS_MAX_BLOCKSIZE
) {
2156 fprintf(stderr
, _("illegal block size %d\n"), blocksize
);
2159 if (sb_feat
.crcs_enabled
&& blocksize
< XFS_MIN_CRC_BLOCKSIZE
) {
2161 _("Minimum block size for CRC enabled filesystems is %d bytes.\n"),
2162 XFS_MIN_CRC_BLOCKSIZE
);
2165 if (sb_feat
.crcs_enabled
&& !sb_feat
.dirftype
) {
2166 fprintf(stderr
, _("cannot disable ftype with crcs enabled\n"));
2170 if (!slflag
&& !ssflag
) {
2171 sectorlog
= XFS_MIN_SECTORSIZE_LOG
;
2172 sectorsize
= XFS_MIN_SECTORSIZE
;
2174 if (!lslflag
&& !lssflag
) {
2175 lsectorlog
= sectorlog
;
2176 lsectorsize
= sectorsize
;
2179 memset(&ft
, 0, sizeof(ft
));
2180 get_topology(&xi
, &ft
, force_overwrite
);
2184 * Unless specified manually on the command line use the
2185 * advertised sector size of the device. We use the physical
2186 * sector size unless the requested block size is smaller
2187 * than that, then we can use logical, but warn about the
2191 /* Older kernels may not have physical/logical distinction */
2192 if (!ft
.psectorsize
)
2193 ft
.psectorsize
= ft
.lsectorsize
;
2195 sectorsize
= ft
.psectorsize
? ft
.psectorsize
:
2198 if ((blocksize
< sectorsize
) && (blocksize
>= ft
.lsectorsize
)) {
2200 _("specified blocksize %d is less than device physical sector size %d\n"),
2201 blocksize
, ft
.psectorsize
);
2203 _("switching to logical sector size %d\n"),
2205 sectorsize
= ft
.lsectorsize
? ft
.lsectorsize
:
2211 sectorlog
= libxfs_highbit32(sectorsize
);
2213 lsectorsize
= sectorsize
;
2214 lsectorlog
= sectorlog
;
2218 if (sectorsize
< XFS_MIN_SECTORSIZE
||
2219 sectorsize
> XFS_MAX_SECTORSIZE
|| sectorsize
> blocksize
) {
2221 fprintf(stderr
, _("illegal sector size %d\n"), sectorsize
);
2224 _("block size %d cannot be smaller than logical sector size %d\n"),
2225 blocksize
, ft
.lsectorsize
);
2228 if (sectorsize
< ft
.lsectorsize
) {
2229 fprintf(stderr
, _("illegal sector size %d; hw sector is %d\n"),
2230 sectorsize
, ft
.lsectorsize
);
2233 if (lsectorsize
< XFS_MIN_SECTORSIZE
||
2234 lsectorsize
> XFS_MAX_SECTORSIZE
|| lsectorsize
> blocksize
) {
2235 fprintf(stderr
, _("illegal log sector size %d\n"), lsectorsize
);
2237 } else if (lsectorsize
> XFS_MIN_SECTORSIZE
&& !lsu
&& !lsunit
) {
2239 sb_feat
.log_version
= 2;
2243 * Now we have blocks and sector sizes set up, check parameters that are
2244 * no longer optional for CRC enabled filesystems. Catch them up front
2245 * here before doing anything else.
2247 if (sb_feat
.crcs_enabled
) {
2248 /* minimum inode size is 512 bytes, ipflag checked later */
2249 if ((isflag
|| ilflag
) && inodelog
< XFS_DINODE_DFL_CRC_LOG
) {
2251 _("Minimum inode size for CRCs is %d bytes\n"),
2252 1 << XFS_DINODE_DFL_CRC_LOG
);
2256 /* inodes always aligned */
2257 if (!sb_feat
.inode_align
) {
2259 _("Inodes always aligned for CRC enabled filesytems\n"));
2263 /* lazy sb counters always on */
2264 if (!sb_feat
.lazy_sb_counters
) {
2266 _("Lazy superblock counted always enabled for CRC enabled filesytems\n"));
2270 /* version 2 logs always on */
2271 if (sb_feat
.log_version
!= 2) {
2273 _("V2 logs always enabled for CRC enabled filesytems\n"));
2277 /* attr2 always on */
2278 if (sb_feat
.attr_version
!= 2) {
2280 _("V2 attribute format always enabled on CRC enabled filesytems\n"));
2284 /* 32 bit project quota always on */
2285 /* attr2 always on */
2286 if (sb_feat
.projid16bit
) {
2288 _("32 bit Project IDs always enabled on CRC enabled filesytems\n"));
2293 * The kernel doesn't currently support crc=0,finobt=1
2294 * filesystems. If crcs are not enabled and the user has
2295 * explicitly turned them off then silently turn them off
2296 * to avoid an unnecessary warning. If the user explicitly
2297 * tried to use crc=0,finobt=1, then issue a warning before
2300 if (sb_feat
.finobt
&& mopts
.subopt_params
[M_FINOBT
].seen
) {
2302 _("warning: finobt not supported without CRC support, disabled.\n"));
2307 if (sb_feat
.spinodes
&& !sb_feat
.crcs_enabled
) {
2309 _("warning: sparse inodes not supported without CRC support, disabled.\n"));
2310 sb_feat
.spinodes
= 0;
2313 if (nsflag
|| nlflag
) {
2314 if (dirblocksize
< blocksize
||
2315 dirblocksize
> XFS_MAX_BLOCKSIZE
) {
2316 fprintf(stderr
, _("illegal directory block size %d\n"),
2321 if (blocksize
< (1 << XFS_MIN_REC_DIRSIZE
))
2322 dirblocklog
= XFS_MIN_REC_DIRSIZE
;
2324 dirblocklog
= blocklog
;
2325 dirblocksize
= 1 << dirblocklog
;
2328 if (daflag
&& dasize
) {
2330 _("both -d agcount= and agsize= specified, use one or the other\n"));
2334 if (xi
.disfile
&& (!dsize
|| !xi
.dname
)) {
2336 _("if -d file then -d name and -d size are required\n"));
2342 dbytes
= getnum(dsize
, blocksize
, sectorsize
, true);
2343 if ((__int64_t
)dbytes
< 0)
2344 illegal(dsize
, "d size");
2345 if (dbytes
% XFS_MIN_BLOCKSIZE
) {
2347 _("illegal data length %lld, not a multiple of %d\n"),
2348 (long long)dbytes
, XFS_MIN_BLOCKSIZE
);
2351 dblocks
= (xfs_rfsblock_t
)(dbytes
>> blocklog
);
2352 if (dbytes
% blocksize
)
2353 fprintf(stderr
, _("warning: "
2354 "data length %lld not a multiple of %d, truncated to %lld\n"),
2355 (long long)dbytes
, blocksize
,
2356 (long long)(dblocks
<< blocklog
));
2359 inodelog
= blocklog
- libxfs_highbit32(inopblock
);
2360 isize
= 1 << inodelog
;
2361 } else if (!ilflag
&& !isflag
) {
2362 inodelog
= sb_feat
.crcs_enabled
? XFS_DINODE_DFL_CRC_LOG
2363 : XFS_DINODE_DFL_LOG
;
2364 isize
= 1 << inodelog
;
2366 if (sb_feat
.crcs_enabled
&& inodelog
< XFS_DINODE_DFL_CRC_LOG
) {
2368 _("Minimum inode size for CRCs is %d bytes\n"),
2369 1 << XFS_DINODE_DFL_CRC_LOG
);
2373 if (xi
.lisfile
&& (!logsize
|| !xi
.logname
)) {
2375 _("if -l file then -l name and -l size are required\n"));
2379 __uint64_t logbytes
;
2381 logbytes
= getnum(logsize
, blocksize
, sectorsize
, true);
2382 if ((__int64_t
)logbytes
< 0)
2383 illegal(logsize
, "l size");
2384 if (logbytes
% XFS_MIN_BLOCKSIZE
) {
2386 _("illegal log length %lld, not a multiple of %d\n"),
2387 (long long)logbytes
, XFS_MIN_BLOCKSIZE
);
2390 logblocks
= (xfs_rfsblock_t
)(logbytes
>> blocklog
);
2391 if (logbytes
% blocksize
)
2393 _("warning: log length %lld not a multiple of %d, truncated to %lld\n"),
2394 (long long)logbytes
, blocksize
,
2395 (long long)(logblocks
<< blocklog
));
2397 if (xi
.risfile
&& (!rtsize
|| !xi
.rtname
)) {
2399 _("if -r file then -r name and -r size are required\n"));
2405 rtbytes
= getnum(rtsize
, blocksize
, sectorsize
, true);
2406 if ((__int64_t
)rtbytes
< 0)
2407 illegal(rtsize
, "r size");
2408 if (rtbytes
% XFS_MIN_BLOCKSIZE
) {
2410 _("illegal rt length %lld, not a multiple of %d\n"),
2411 (long long)rtbytes
, XFS_MIN_BLOCKSIZE
);
2414 rtblocks
= (xfs_rfsblock_t
)(rtbytes
>> blocklog
);
2415 if (rtbytes
% blocksize
)
2417 _("warning: rt length %lld not a multiple of %d, truncated to %lld\n"),
2418 (long long)rtbytes
, blocksize
,
2419 (long long)(rtblocks
<< blocklog
));
2422 * If specified, check rt extent size against its constraints.
2425 __uint64_t rtextbytes
;
2427 rtextbytes
= getnum(rtextsize
, blocksize
, sectorsize
, true);
2428 if ((__int64_t
)rtextbytes
< 0)
2429 illegal(rtsize
, "r extsize");
2430 if (rtextbytes
% blocksize
) {
2432 _("illegal rt extent size %lld, not a multiple of %d\n"),
2433 (long long)rtextbytes
, blocksize
);
2436 if (rtextbytes
> XFS_MAX_RTEXTSIZE
) {
2438 _("rt extent size %s too large, maximum %d\n"),
2439 rtextsize
, XFS_MAX_RTEXTSIZE
);
2442 if (rtextbytes
< XFS_MIN_RTEXTSIZE
) {
2444 _("rt extent size %s too small, minimum %d\n"),
2445 rtextsize
, XFS_MIN_RTEXTSIZE
);
2448 rtextblocks
= (xfs_extlen_t
)(rtextbytes
>> blocklog
);
2451 * If realtime extsize has not been specified by the user,
2452 * and the underlying volume is striped, then set rtextblocks
2453 * to the stripe width.
2456 __uint64_t rtextbytes
;
2458 if (!norsflag
&& !xi
.risfile
&& !(!rtsize
&& xi
.disfile
))
2459 rswidth
= ft
.rtswidth
;
2463 /* check that rswidth is a multiple of fs blocksize */
2464 if (!norsflag
&& rswidth
&& !(BBTOB(rswidth
) % blocksize
)) {
2465 rswidth
= DTOBT(rswidth
);
2466 rtextbytes
= rswidth
<< blocklog
;
2467 if (XFS_MIN_RTEXTSIZE
<= rtextbytes
&&
2468 (rtextbytes
<= XFS_MAX_RTEXTSIZE
)) {
2469 rtextblocks
= rswidth
;
2473 rtextblocks
= (blocksize
< XFS_MIN_RTEXTSIZE
) ?
2474 XFS_MIN_RTEXTSIZE
>> blocklog
: 1;
2477 ASSERT(rtextblocks
);
2480 * Check some argument sizes against mins, maxes.
2482 if (isize
> blocksize
/ XFS_MIN_INODE_PERBLOCK
||
2483 isize
< XFS_DINODE_MIN_SIZE
||
2484 isize
> XFS_DINODE_MAX_SIZE
) {
2487 fprintf(stderr
, _("illegal inode size %d\n"), isize
);
2488 maxsz
= MIN(blocksize
/ XFS_MIN_INODE_PERBLOCK
,
2489 XFS_DINODE_MAX_SIZE
);
2490 if (XFS_DINODE_MIN_SIZE
== maxsz
)
2492 _("allowable inode size with %d byte blocks is %d\n"),
2493 blocksize
, XFS_DINODE_MIN_SIZE
);
2496 _("allowable inode size with %d byte blocks is between %d and %d\n"),
2497 blocksize
, XFS_DINODE_MIN_SIZE
, maxsz
);
2501 /* if lsu or lsunit was specified, automatically use v2 logs */
2502 if ((lsu
|| lsunit
) && sb_feat
.log_version
== 1) {
2504 _("log stripe unit specified, using v2 logs\n"));
2505 sb_feat
.log_version
= 2;
2508 calc_stripe_factors(dsu
, dsw
, sectorsize
, lsu
, lsectorsize
,
2509 &dsunit
, &dswidth
, &lsunit
);
2511 xi
.setblksize
= sectorsize
;
2514 * Initialize. This will open the log and rt devices as well.
2516 if (!libxfs_init(&xi
))
2519 fprintf(stderr
, _("no device name given in argument list\n"));
2524 * Ok, Linux only has a 1024-byte resolution on device _size_,
2525 * and the sizes below are in basic 512-byte blocks,
2526 * so if we have (size % 2), on any partition, we can't get
2527 * to the last 512 bytes. The same issue exists for larger
2528 * sector sizes - we cannot write past the last sector.
2530 * So, we reduce the size (in basic blocks) to a perfect
2531 * multiple of the sector size, or 1024, whichever is larger.
2534 sector_mask
= (__uint64_t
)-1 << (MAX(sectorlog
, 10) - BBSHIFT
);
2535 xi
.dsize
&= sector_mask
;
2536 xi
.rtsize
&= sector_mask
;
2537 xi
.logBBsize
&= (__uint64_t
)-1 << (MAX(lsectorlog
, 10) - BBSHIFT
);
2539 if (!force_overwrite
) {
2540 if (check_overwrite(dfile
) ||
2541 check_overwrite(logfile
) ||
2542 check_overwrite(xi
.rtname
)) {
2544 _("%s: Use the -f option to force overwrite.\n"),
2550 if (discard
&& !Nflag
) {
2551 discard_blocks(xi
.ddev
, xi
.dsize
);
2553 discard_blocks(xi
.rtdev
, xi
.rtsize
);
2554 if (xi
.logdev
&& xi
.logdev
!= xi
.ddev
)
2555 discard_blocks(xi
.logdev
, xi
.logBBsize
);
2558 if (!liflag
&& !ldflag
)
2559 loginternal
= xi
.logdev
== 0;
2561 logfile
= xi
.logname
;
2562 else if (loginternal
)
2563 logfile
= _("internal log");
2564 else if (xi
.volname
&& xi
.logdev
)
2565 logfile
= _("volume log");
2567 fprintf(stderr
, _("no log subvolume or internal log\n"));
2573 if (xi
.volname
&& xi
.rtdev
)
2574 rtfile
= _("volume rt");
2577 if (dsize
&& xi
.dsize
> 0 && dblocks
> DTOBT(xi
.dsize
)) {
2579 _("size %s specified for data subvolume is too large, "
2580 "maximum is %lld blocks\n"),
2581 dsize
, (long long)DTOBT(xi
.dsize
));
2583 } else if (!dsize
&& xi
.dsize
> 0)
2584 dblocks
= DTOBT(xi
.dsize
);
2586 fprintf(stderr
, _("can't get size of data subvolume\n"));
2589 if (dblocks
< XFS_MIN_DATA_BLOCKS
) {
2591 _("size %lld of data subvolume is too small, minimum %d blocks\n"),
2592 (long long)dblocks
, XFS_MIN_DATA_BLOCKS
);
2596 if (loginternal
&& xi
.logdev
) {
2598 _("can't have both external and internal logs\n"));
2600 } else if (loginternal
&& sectorsize
!= lsectorsize
) {
2602 _("data and log sector sizes must be equal for internal logs\n"));
2606 if (xi
.dbsize
> sectorsize
) {
2608 "Warning: the data subvolume sector size %u is less than the sector size \n\
2609 reported by the device (%u).\n"),
2610 sectorsize
, xi
.dbsize
);
2612 if (!loginternal
&& xi
.lbsize
> lsectorsize
) {
2614 "Warning: the log subvolume sector size %u is less than the sector size\n\
2615 reported by the device (%u).\n"),
2616 lsectorsize
, xi
.lbsize
);
2618 if (rtsize
&& xi
.rtsize
> 0 && xi
.rtbsize
> sectorsize
) {
2620 "Warning: the realtime subvolume sector size %u is less than the sector size\n\
2621 reported by the device (%u).\n"),
2622 sectorsize
, xi
.rtbsize
);
2625 if (rtsize
&& xi
.rtsize
> 0 && rtblocks
> DTOBT(xi
.rtsize
)) {
2627 _("size %s specified for rt subvolume is too large, "
2628 "maximum is %lld blocks\n"),
2629 rtsize
, (long long)DTOBT(xi
.rtsize
));
2631 } else if (!rtsize
&& xi
.rtsize
> 0)
2632 rtblocks
= DTOBT(xi
.rtsize
);
2633 else if (rtsize
&& !xi
.rtdev
) {
2635 _("size specified for non-existent rt subvolume\n"));
2639 rtextents
= rtblocks
/ rtextblocks
;
2640 nbmblocks
= (xfs_extlen_t
)howmany(rtextents
, NBBY
* blocksize
);
2642 rtextents
= rtblocks
= 0;
2648 if (ft
.dsunit
&& ft
.dsunit
!= dsunit
) {
2650 _("%s: Specified data stripe unit %d "
2651 "is not the same as the volume stripe "
2653 progname
, dsunit
, ft
.dsunit
);
2655 if (ft
.dswidth
&& ft
.dswidth
!= dswidth
) {
2657 _("%s: Specified data stripe width %d "
2658 "is not the same as the volume stripe "
2660 progname
, dswidth
, ft
.dswidth
);
2664 dswidth
= ft
.dswidth
;
2667 } /* else dsunit & dswidth can't be set if nodsflag is set */
2669 if (dasize
) { /* User-specified AG size */
2671 * Check specified agsize is a multiple of blocksize.
2673 if (agsize
% blocksize
) {
2675 _("agsize (%lld) not a multiple of fs blk size (%d)\n"),
2676 (long long)agsize
, blocksize
);
2679 agsize
/= blocksize
;
2680 agcount
= dblocks
/ agsize
+ (dblocks
% agsize
!= 0);
2682 } else if (daflag
) { /* User-specified AG count */
2683 agsize
= dblocks
/ agcount
+ (dblocks
% agcount
!= 0);
2685 calc_default_ag_geometry(blocklog
, dblocks
,
2686 dsunit
| dswidth
, &agsize
, &agcount
);
2690 * If dsunit is a multiple of fs blocksize, then check that is a
2691 * multiple of the agsize too
2693 if (dsunit
&& !(BBTOB(dsunit
) % blocksize
) &&
2694 dswidth
&& !(BBTOB(dswidth
) % blocksize
)) {
2696 /* convert from 512 byte blocks to fs blocksize */
2697 dsunit
= DTOBT(dsunit
);
2698 dswidth
= DTOBT(dswidth
);
2701 * agsize is not a multiple of dsunit
2703 if ((agsize
% dsunit
) != 0) {
2705 * Round up to stripe unit boundary. Also make sure
2706 * that agsize is still larger than
2707 * XFS_AG_MIN_BLOCKS(blocklog)
2709 tmp_agsize
= ((agsize
+ (dsunit
- 1))/ dsunit
) * dsunit
;
2711 * Round down to stripe unit boundary if rounding up
2712 * created an AG size that is larger than the AG max.
2714 if (tmp_agsize
> XFS_AG_MAX_BLOCKS(blocklog
))
2715 tmp_agsize
= ((agsize
) / dsunit
) * dsunit
;
2717 if ((tmp_agsize
>= XFS_AG_MIN_BLOCKS(blocklog
)) &&
2718 (tmp_agsize
<= XFS_AG_MAX_BLOCKS(blocklog
))) {
2719 agsize
= tmp_agsize
;
2721 agcount
= dblocks
/agsize
+
2722 (dblocks
% agsize
!= 0);
2725 _("agsize rounded to %lld, swidth = %d\n"),
2726 (long long)agsize
, dswidth
);
2729 dsunit
= dswidth
= 0;
2732 * agsize is out of bounds, this will
2733 * print nice details & exit.
2735 validate_ag_geometry(blocklog
, dblocks
,
2741 if (dswidth
&& ((agsize
% dswidth
) == 0) && (agcount
> 1)) {
2742 /* This is a non-optimal configuration because all AGs
2743 * start on the same disk in the stripe. Changing
2744 * the AG size by one sunit will guarantee that this
2747 tmp_agsize
= agsize
- dsunit
;
2748 if (tmp_agsize
< XFS_AG_MIN_BLOCKS(blocklog
)) {
2749 tmp_agsize
= agsize
+ dsunit
;
2750 if (dblocks
< agsize
) {
2751 /* oh well, nothing to do */
2752 tmp_agsize
= agsize
;
2755 if (daflag
|| dasize
) {
2757 "Warning: AG size is a multiple of stripe width. This can cause performance\n\
2758 problems by aligning all AGs on the same disk. To avoid this, run mkfs with\n\
2759 an AG size that is one stripe unit smaller, for example %llu.\n"),
2760 (unsigned long long)tmp_agsize
);
2762 agsize
= tmp_agsize
;
2763 agcount
= dblocks
/agsize
+ (dblocks
% agsize
!= 0);
2765 * If the last AG is too small, reduce the
2766 * filesystem size and drop the blocks.
2768 if ( dblocks
% agsize
!= 0 &&
2770 XFS_AG_MIN_BLOCKS(blocklog
))) {
2771 dblocks
= (xfs_rfsblock_t
)((agcount
- 1) * agsize
);
2773 ASSERT(agcount
!= 0);
2779 dsunit
= dswidth
= 0;
2782 _("%s: Stripe unit(%d) or stripe width(%d) is "
2783 "not a multiple of the block size(%d)\n"),
2784 progname
, BBTOB(dsunit
), BBTOB(dswidth
),
2791 * If the last AG is too small, reduce the filesystem size
2792 * and drop the blocks.
2794 if ( dblocks
% agsize
!= 0 &&
2795 (dblocks
% agsize
< XFS_AG_MIN_BLOCKS(blocklog
))) {
2797 dblocks
= (xfs_rfsblock_t
)((agcount
- 1) * agsize
);
2799 ASSERT(agcount
!= 0);
2802 validate_ag_geometry(blocklog
, dblocks
, agsize
, agcount
);
2805 imaxpct
= calc_default_imaxpct(blocklog
, dblocks
);
2808 * check that log sunit is modulo fsblksize or default it to dsunit.
2812 if ((BBTOB(lsunit
) % blocksize
!= 0)) {
2814 _("log stripe unit (%d) must be a multiple of the block size (%d)\n"),
2815 BBTOB(lsunit
), blocksize
);
2818 /* convert from 512 byte blocks to fs blocks */
2819 lsunit
= DTOBT(lsunit
);
2820 } else if (sb_feat
.log_version
== 2 && loginternal
&& dsunit
) {
2821 /* lsunit and dsunit now in fs blocks */
2825 if (sb_feat
.log_version
== 2 && (lsunit
* blocksize
) > 256 * 1024) {
2826 /* Warn only if specified on commandline */
2827 if (lsuflag
|| lsunitflag
) {
2829 _("log stripe unit (%d bytes) is too large (maximum is 256KiB)\n"),
2830 (lsunit
* blocksize
));
2832 _("log stripe unit adjusted to 32KiB\n"));
2834 lsunit
= (32 * 1024) >> blocklog
;
2837 min_logblocks
= max_trans_res(sb_feat
.crcs_enabled
, sb_feat
.dir_version
,
2838 sectorlog
, blocklog
, inodelog
, dirblocklog
,
2839 sb_feat
.log_version
, lsunit
, sb_feat
.finobt
);
2840 ASSERT(min_logblocks
);
2841 min_logblocks
= MAX(XFS_MIN_LOG_BLOCKS
, min_logblocks
);
2842 if (!logsize
&& dblocks
>= (1024*1024*1024) >> blocklog
)
2843 min_logblocks
= MAX(min_logblocks
, XFS_MIN_LOG_BYTES
>>blocklog
);
2844 if (logsize
&& xi
.logBBsize
> 0 && logblocks
> DTOBT(xi
.logBBsize
)) {
2846 _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
2847 logsize
, (long long)DTOBT(xi
.logBBsize
));
2849 } else if (!logsize
&& xi
.logBBsize
> 0) {
2850 logblocks
= DTOBT(xi
.logBBsize
);
2851 } else if (logsize
&& !xi
.logdev
&& !loginternal
) {
2853 _("size specified for non-existent log subvolume\n"));
2855 } else if (loginternal
&& logsize
&& logblocks
>= dblocks
) {
2856 fprintf(stderr
, _("size %lld too large for internal log\n"),
2857 (long long)logblocks
);
2859 } else if (!loginternal
&& !xi
.logdev
) {
2861 } else if (loginternal
&& !logsize
) {
2863 if (dblocks
< GIGABYTES(1, blocklog
)) {
2864 /* tiny filesystems get minimum sized logs. */
2865 logblocks
= min_logblocks
;
2866 } else if (dblocks
< GIGABYTES(16, blocklog
)) {
2869 * For small filesystems, we want to use the
2870 * XFS_MIN_LOG_BYTES for filesystems smaller than 16G if
2871 * at all possible, ramping up to 128MB at 256GB.
2873 logblocks
= MIN(XFS_MIN_LOG_BYTES
>> blocklog
,
2874 min_logblocks
* XFS_DFL_LOG_FACTOR
);
2877 * With a 2GB max log size, default to maximum size
2878 * at 4TB. This keeps the same ratio from the older
2879 * max log size of 128M at 256GB fs size. IOWs,
2880 * the ratio of fs size to log size is 2048:1.
2882 logblocks
= (dblocks
<< blocklog
) / 2048;
2883 logblocks
= logblocks
>> blocklog
;
2886 /* Ensure the chosen size meets minimum log size requirements */
2887 logblocks
= MAX(min_logblocks
, logblocks
);
2889 /* make sure the log fits wholly within an AG */
2890 if (logblocks
>= agsize
)
2891 logblocks
= min_logblocks
;
2893 /* and now clamp the size to the maximum supported size */
2894 logblocks
= MIN(logblocks
, XFS_MAX_LOG_BLOCKS
);
2895 if ((logblocks
<< blocklog
) > XFS_MAX_LOG_BYTES
)
2896 logblocks
= XFS_MAX_LOG_BYTES
>> blocklog
;
2899 validate_log_size(logblocks
, blocklog
, min_logblocks
);
2901 protostring
= setup_proto(protofile
);
2902 bsize
= 1 << (blocklog
- BBSHIFT
);
2905 memset(mp
, 0, sizeof(xfs_mount_t
));
2906 sbp
->sb_blocklog
= (__uint8_t
)blocklog
;
2907 sbp
->sb_sectlog
= (__uint8_t
)sectorlog
;
2908 sbp
->sb_agblklog
= (__uint8_t
)libxfs_log2_roundup((unsigned int)agsize
);
2909 sbp
->sb_agblocks
= (xfs_agblock_t
)agsize
;
2910 mp
->m_blkbb_log
= sbp
->sb_blocklog
- BBSHIFT
;
2911 mp
->m_sectbb_log
= sbp
->sb_sectlog
- BBSHIFT
;
2914 * sb_versionnum and finobt flags must be set before we use
2915 * XFS_PREALLOC_BLOCKS().
2917 sb_set_features(&mp
->m_sb
, &sb_feat
, sectorsize
, lsectorsize
, dsunit
);
2922 * Readjust the log size to fit within an AG if it was sized
2926 logblocks
= MIN(logblocks
,
2927 XFS_ALLOC_AG_MAX_USABLE(mp
));
2929 /* revalidate the log size is valid if we changed it */
2930 validate_log_size(logblocks
, blocklog
, min_logblocks
);
2932 if (logblocks
> agsize
- XFS_PREALLOC_BLOCKS(mp
)) {
2934 _("internal log size %lld too large, must fit in allocation group\n"),
2935 (long long)logblocks
);
2940 if (logagno
>= agcount
) {
2942 _("log ag number %d too large, must be less than %lld\n"),
2943 logagno
, (long long)agcount
);
2947 logagno
= (xfs_agnumber_t
)(agcount
/ 2);
2949 logstart
= XFS_AGB_TO_FSB(mp
, logagno
, XFS_PREALLOC_BLOCKS(mp
));
2951 * Align the logstart at stripe unit boundary.
2954 logstart
= fixup_internal_log_stripe(mp
,
2955 lsflag
, logstart
, agsize
, lsunit
,
2956 &logblocks
, blocklog
, &lalign
);
2957 } else if (dsunit
) {
2958 logstart
= fixup_internal_log_stripe(mp
,
2959 lsflag
, logstart
, agsize
, dsunit
,
2960 &logblocks
, blocklog
, &lalign
);
2965 fixup_log_stripe_unit(lsflag
, lsunit
,
2966 &logblocks
, blocklog
);
2968 validate_log_size(logblocks
, blocklog
, min_logblocks
);
2970 if (!qflag
|| Nflag
) {
2972 "meta-data=%-22s isize=%-6d agcount=%lld, agsize=%lld blks\n"
2973 " =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n"
2974 " =%-22s crc=%-8u finobt=%u, sparse=%u\n"
2975 "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
2976 " =%-22s sunit=%-6u swidth=%u blks\n"
2977 "naming =version %-14u bsize=%-6u ascii-ci=%d ftype=%d\n"
2978 "log =%-22s bsize=%-6d blocks=%lld, version=%d\n"
2979 " =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n"
2980 "realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"),
2981 dfile
, isize
, (long long)agcount
, (long long)agsize
,
2982 "", sectorsize
, sb_feat
.attr_version
,
2983 !sb_feat
.projid16bit
,
2984 "", sb_feat
.crcs_enabled
, sb_feat
.finobt
, sb_feat
.spinodes
,
2985 "", blocksize
, (long long)dblocks
, imaxpct
,
2986 "", dsunit
, dswidth
,
2987 sb_feat
.dir_version
, dirblocksize
, sb_feat
.nci
,
2989 logfile
, 1 << blocklog
, (long long)logblocks
,
2990 sb_feat
.log_version
, "", lsectorsize
, lsunit
,
2991 sb_feat
.lazy_sb_counters
,
2992 rtfile
, rtextblocks
<< blocklog
,
2993 (long long)rtblocks
, (long long)rtextents
);
2999 strncpy(sbp
->sb_fname
, label
, sizeof(sbp
->sb_fname
));
3000 sbp
->sb_magicnum
= XFS_SB_MAGIC
;
3001 sbp
->sb_blocksize
= blocksize
;
3002 sbp
->sb_dblocks
= dblocks
;
3003 sbp
->sb_rblocks
= rtblocks
;
3004 sbp
->sb_rextents
= rtextents
;
3005 platform_uuid_copy(&sbp
->sb_uuid
, &uuid
);
3006 /* Only in memory; libxfs expects this as if read from disk */
3007 platform_uuid_copy(&sbp
->sb_meta_uuid
, &uuid
);
3008 sbp
->sb_logstart
= logstart
;
3009 sbp
->sb_rootino
= sbp
->sb_rbmino
= sbp
->sb_rsumino
= NULLFSINO
;
3010 sbp
->sb_rextsize
= rtextblocks
;
3011 sbp
->sb_agcount
= (xfs_agnumber_t
)agcount
;
3012 sbp
->sb_rbmblocks
= nbmblocks
;
3013 sbp
->sb_logblocks
= (xfs_extlen_t
)logblocks
;
3014 sbp
->sb_sectsize
= (__uint16_t
)sectorsize
;
3015 sbp
->sb_inodesize
= (__uint16_t
)isize
;
3016 sbp
->sb_inopblock
= (__uint16_t
)(blocksize
/ isize
);
3017 sbp
->sb_sectlog
= (__uint8_t
)sectorlog
;
3018 sbp
->sb_inodelog
= (__uint8_t
)inodelog
;
3019 sbp
->sb_inopblog
= (__uint8_t
)(blocklog
- inodelog
);
3021 (__uint8_t
)(rtextents
?
3022 libxfs_highbit32((unsigned int)rtextents
) : 0);
3023 sbp
->sb_inprogress
= 1; /* mkfs is in progress */
3024 sbp
->sb_imax_pct
= imaxpct
;
3027 sbp
->sb_fdblocks
= dblocks
- agcount
* XFS_PREALLOC_BLOCKS(mp
) -
3028 (loginternal
? logblocks
: 0);
3029 sbp
->sb_frextents
= 0; /* will do a free later */
3030 sbp
->sb_uquotino
= sbp
->sb_gquotino
= sbp
->sb_pquotino
= 0;
3032 sbp
->sb_unit
= dsunit
;
3033 sbp
->sb_width
= dswidth
;
3034 sbp
->sb_dirblklog
= dirblocklog
- blocklog
;
3035 if (sb_feat
.log_version
== 2) { /* This is stored in bytes */
3036 lsunit
= (lsunit
== 0) ? 1 : XFS_FSB_TO_B(mp
, lsunit
);
3037 sbp
->sb_logsunit
= lsunit
;
3039 sbp
->sb_logsunit
= 0;
3040 if (sb_feat
.inode_align
) {
3041 int cluster_size
= XFS_INODE_BIG_CLUSTER_SIZE
;
3042 if (sb_feat
.crcs_enabled
)
3043 cluster_size
*= isize
/ XFS_DINODE_MIN_SIZE
;
3044 sbp
->sb_inoalignmt
= cluster_size
>> blocklog
;
3045 sb_feat
.inode_align
= sbp
->sb_inoalignmt
!= 0;
3047 sbp
->sb_inoalignmt
= 0;
3048 if (lsectorsize
!= BBSIZE
|| sectorsize
!= BBSIZE
) {
3049 sbp
->sb_logsectlog
= (__uint8_t
)lsectorlog
;
3050 sbp
->sb_logsectsize
= (__uint16_t
)lsectorsize
;
3052 sbp
->sb_logsectlog
= 0;
3053 sbp
->sb_logsectsize
= 0;
3056 sb_set_features(&mp
->m_sb
, &sb_feat
, sectorsize
, lsectorsize
, dsunit
);
3058 if (force_overwrite
)
3059 zero_old_xfs_structures(&xi
, sbp
);
3062 * Zero out the beginning of the device, to obliterate any old
3063 * filesystem signatures out there. This should take care of
3064 * swap (somewhere around the page size), jfs (32k),
3065 * ext[2,3] and reiserfs (64k) - and hopefully all else.
3067 libxfs_buftarg_init(mp
, xi
.ddev
, xi
.logdev
, xi
.rtdev
);
3068 buf
= libxfs_getbuf(mp
->m_ddev_targp
, 0, BTOBB(WHACK_SIZE
));
3069 memset(XFS_BUF_PTR(buf
), 0, WHACK_SIZE
);
3070 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3071 libxfs_purgebuf(buf
);
3073 /* OK, now write the superblock */
3074 buf
= libxfs_getbuf(mp
->m_ddev_targp
, XFS_SB_DADDR
, XFS_FSS_TO_BB(mp
, 1));
3075 buf
->b_ops
= &xfs_sb_buf_ops
;
3076 memset(XFS_BUF_PTR(buf
), 0, sectorsize
);
3077 libxfs_sb_to_disk((void *)XFS_BUF_PTR(buf
), sbp
);
3078 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3079 libxfs_purgebuf(buf
);
3082 * If the data area is a file, then grow it out to its final size
3083 * so that the reads for the end of the device in the mount code
3086 if (xi
.disfile
&& ftruncate64(xi
.dfd
, dblocks
* blocksize
) < 0) {
3087 fprintf(stderr
, _("%s: Growing the data section failed\n"),
3093 * Zero out the end of the device, to obliterate any
3094 * old MD RAID (or other) metadata at the end of the device.
3095 * (MD sb is ~64k from the end, take out a wider swath to be sure)
3098 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3099 (xi
.dsize
- BTOBB(WHACK_SIZE
)),
3101 memset(XFS_BUF_PTR(buf
), 0, WHACK_SIZE
);
3102 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3103 libxfs_purgebuf(buf
);
3109 libxfs_log_clear(mp
->m_logdev_targp
, NULL
,
3110 XFS_FSB_TO_DADDR(mp
, logstart
),
3111 (xfs_extlen_t
)XFS_FSB_TO_BB(mp
, logblocks
),
3112 &sbp
->sb_uuid
, sb_feat
.log_version
, lsunit
, XLOG_FMT
, XLOG_INIT_CYCLE
, false);
3114 mp
= libxfs_mount(mp
, sbp
, xi
.ddev
, xi
.logdev
, xi
.rtdev
, 0);
3116 fprintf(stderr
, _("%s: filesystem failed to initialize\n"),
3122 * XXX: this code is effectively shared with the kernel growfs code.
3123 * These initialisations should be pulled into libxfs to keep the
3124 * kernel/userspace header initialisation code the same.
3126 for (agno
= 0; agno
< agcount
; agno
++) {
3127 struct xfs_agfl
*agfl
;
3129 struct xfs_perag
*pag
= xfs_perag_get(mp
, agno
);
3134 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3135 XFS_AG_DADDR(mp
, agno
, XFS_SB_DADDR
),
3136 XFS_FSS_TO_BB(mp
, 1));
3137 buf
->b_ops
= &xfs_sb_buf_ops
;
3138 memset(XFS_BUF_PTR(buf
), 0, sectorsize
);
3139 libxfs_sb_to_disk((void *)XFS_BUF_PTR(buf
), sbp
);
3140 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3143 * AG header block: freespace
3145 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3146 XFS_AG_DADDR(mp
, agno
, XFS_AGF_DADDR(mp
)),
3147 XFS_FSS_TO_BB(mp
, 1));
3148 buf
->b_ops
= &xfs_agf_buf_ops
;
3149 agf
= XFS_BUF_TO_AGF(buf
);
3150 memset(agf
, 0, sectorsize
);
3151 if (agno
== agcount
- 1)
3152 agsize
= dblocks
- (xfs_rfsblock_t
)(agno
* agsize
);
3153 agf
->agf_magicnum
= cpu_to_be32(XFS_AGF_MAGIC
);
3154 agf
->agf_versionnum
= cpu_to_be32(XFS_AGF_VERSION
);
3155 agf
->agf_seqno
= cpu_to_be32(agno
);
3156 agf
->agf_length
= cpu_to_be32(agsize
);
3157 agf
->agf_roots
[XFS_BTNUM_BNOi
] = cpu_to_be32(XFS_BNO_BLOCK(mp
));
3158 agf
->agf_roots
[XFS_BTNUM_CNTi
] = cpu_to_be32(XFS_CNT_BLOCK(mp
));
3159 agf
->agf_levels
[XFS_BTNUM_BNOi
] = cpu_to_be32(1);
3160 agf
->agf_levels
[XFS_BTNUM_CNTi
] = cpu_to_be32(1);
3161 pag
->pagf_levels
[XFS_BTNUM_BNOi
] = 1;
3162 pag
->pagf_levels
[XFS_BTNUM_CNTi
] = 1;
3163 agf
->agf_flfirst
= 0;
3164 agf
->agf_fllast
= cpu_to_be32(XFS_AGFL_SIZE(mp
) - 1);
3165 agf
->agf_flcount
= 0;
3166 nbmblocks
= (xfs_extlen_t
)(agsize
- XFS_PREALLOC_BLOCKS(mp
));
3167 agf
->agf_freeblks
= cpu_to_be32(nbmblocks
);
3168 agf
->agf_longest
= cpu_to_be32(nbmblocks
);
3169 if (xfs_sb_version_hascrc(&mp
->m_sb
))
3170 platform_uuid_copy(&agf
->agf_uuid
, &mp
->m_sb
.sb_uuid
);
3172 if (loginternal
&& agno
== logagno
) {
3173 be32_add_cpu(&agf
->agf_freeblks
, -logblocks
);
3174 agf
->agf_longest
= cpu_to_be32(agsize
-
3175 XFS_FSB_TO_AGBNO(mp
, logstart
) - logblocks
);
3177 if (xfs_alloc_min_freelist(mp
, pag
) > worst_freelist
)
3178 worst_freelist
= xfs_alloc_min_freelist(mp
, pag
);
3179 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3182 * AG freelist header block
3184 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3185 XFS_AG_DADDR(mp
, agno
, XFS_AGFL_DADDR(mp
)),
3186 XFS_FSS_TO_BB(mp
, 1));
3187 buf
->b_ops
= &xfs_agfl_buf_ops
;
3188 agfl
= XFS_BUF_TO_AGFL(buf
);
3189 /* setting to 0xff results in initialisation to NULLAGBLOCK */
3190 memset(agfl
, 0xff, sectorsize
);
3191 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
3192 agfl
->agfl_magicnum
= cpu_to_be32(XFS_AGFL_MAGIC
);
3193 agfl
->agfl_seqno
= cpu_to_be32(agno
);
3194 platform_uuid_copy(&agfl
->agfl_uuid
, &mp
->m_sb
.sb_uuid
);
3195 for (bucket
= 0; bucket
< XFS_AGFL_SIZE(mp
); bucket
++)
3196 agfl
->agfl_bno
[bucket
] = cpu_to_be32(NULLAGBLOCK
);
3199 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3202 * AG header block: inodes
3204 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3205 XFS_AG_DADDR(mp
, agno
, XFS_AGI_DADDR(mp
)),
3206 XFS_FSS_TO_BB(mp
, 1));
3207 agi
= XFS_BUF_TO_AGI(buf
);
3208 buf
->b_ops
= &xfs_agi_buf_ops
;
3209 memset(agi
, 0, sectorsize
);
3210 agi
->agi_magicnum
= cpu_to_be32(XFS_AGI_MAGIC
);
3211 agi
->agi_versionnum
= cpu_to_be32(XFS_AGI_VERSION
);
3212 agi
->agi_seqno
= cpu_to_be32(agno
);
3213 agi
->agi_length
= cpu_to_be32((xfs_agblock_t
)agsize
);
3215 agi
->agi_root
= cpu_to_be32(XFS_IBT_BLOCK(mp
));
3216 agi
->agi_level
= cpu_to_be32(1);
3217 if (sb_feat
.finobt
) {
3218 agi
->agi_free_root
= cpu_to_be32(XFS_FIBT_BLOCK(mp
));
3219 agi
->agi_free_level
= cpu_to_be32(1);
3221 agi
->agi_freecount
= 0;
3222 agi
->agi_newino
= cpu_to_be32(NULLAGINO
);
3223 agi
->agi_dirino
= cpu_to_be32(NULLAGINO
);
3224 if (xfs_sb_version_hascrc(&mp
->m_sb
))
3225 platform_uuid_copy(&agi
->agi_uuid
, &mp
->m_sb
.sb_uuid
);
3226 for (c
= 0; c
< XFS_AGI_UNLINKED_BUCKETS
; c
++)
3227 agi
->agi_unlinked
[c
] = cpu_to_be32(NULLAGINO
);
3228 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3231 * BNO btree root block
3233 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3234 XFS_AGB_TO_DADDR(mp
, agno
, XFS_BNO_BLOCK(mp
)),
3236 buf
->b_ops
= &xfs_allocbt_buf_ops
;
3237 block
= XFS_BUF_TO_BLOCK(buf
);
3238 memset(block
, 0, blocksize
);
3239 if (xfs_sb_version_hascrc(&mp
->m_sb
))
3240 xfs_btree_init_block(mp
, buf
, XFS_ABTB_CRC_MAGIC
, 0, 1,
3241 agno
, XFS_BTREE_CRC_BLOCKS
);
3243 xfs_btree_init_block(mp
, buf
, XFS_ABTB_MAGIC
, 0, 1,
3246 arec
= XFS_ALLOC_REC_ADDR(mp
, block
, 1);
3247 arec
->ar_startblock
= cpu_to_be32(XFS_PREALLOC_BLOCKS(mp
));
3248 if (loginternal
&& agno
== logagno
) {
3251 * Have to insert two records
3252 * Insert pad record for stripe align of log
3254 arec
->ar_blockcount
= cpu_to_be32(
3255 XFS_FSB_TO_AGBNO(mp
, logstart
) -
3256 be32_to_cpu(arec
->ar_startblock
));
3259 * Insert record at start of internal log
3261 nrec
->ar_startblock
= cpu_to_be32(
3262 be32_to_cpu(arec
->ar_startblock
) +
3263 be32_to_cpu(arec
->ar_blockcount
));
3265 be16_add_cpu(&block
->bb_numrecs
, 1);
3268 * Change record start to after the internal log
3270 be32_add_cpu(&arec
->ar_startblock
, logblocks
);
3273 * Calculate the record block count and check for the case where
3274 * the log might have consumed all available space in the AG. If
3275 * so, reset the record count to 0 to avoid exposure of an invalid
3276 * record start block.
3278 arec
->ar_blockcount
= cpu_to_be32(agsize
-
3279 be32_to_cpu(arec
->ar_startblock
));
3280 if (!arec
->ar_blockcount
)
3281 block
->bb_numrecs
= 0;
3283 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3286 * CNT btree root block
3288 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3289 XFS_AGB_TO_DADDR(mp
, agno
, XFS_CNT_BLOCK(mp
)),
3291 buf
->b_ops
= &xfs_allocbt_buf_ops
;
3292 block
= XFS_BUF_TO_BLOCK(buf
);
3293 memset(block
, 0, blocksize
);
3294 if (xfs_sb_version_hascrc(&mp
->m_sb
))
3295 xfs_btree_init_block(mp
, buf
, XFS_ABTC_CRC_MAGIC
, 0, 1,
3296 agno
, XFS_BTREE_CRC_BLOCKS
);
3298 xfs_btree_init_block(mp
, buf
, XFS_ABTC_MAGIC
, 0, 1,
3301 arec
= XFS_ALLOC_REC_ADDR(mp
, block
, 1);
3302 arec
->ar_startblock
= cpu_to_be32(XFS_PREALLOC_BLOCKS(mp
));
3303 if (loginternal
&& agno
== logagno
) {
3305 arec
->ar_blockcount
= cpu_to_be32(
3306 XFS_FSB_TO_AGBNO(mp
, logstart
) -
3307 be32_to_cpu(arec
->ar_startblock
));
3309 nrec
->ar_startblock
= cpu_to_be32(
3310 be32_to_cpu(arec
->ar_startblock
) +
3311 be32_to_cpu(arec
->ar_blockcount
));
3313 be16_add_cpu(&block
->bb_numrecs
, 1);
3315 be32_add_cpu(&arec
->ar_startblock
, logblocks
);
3318 * Calculate the record block count and check for the case where
3319 * the log might have consumed all available space in the AG. If
3320 * so, reset the record count to 0 to avoid exposure of an invalid
3321 * record start block.
3323 arec
->ar_blockcount
= cpu_to_be32(agsize
-
3324 be32_to_cpu(arec
->ar_startblock
));
3325 if (!arec
->ar_blockcount
)
3326 block
->bb_numrecs
= 0;
3328 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3331 * INO btree root block
3333 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3334 XFS_AGB_TO_DADDR(mp
, agno
, XFS_IBT_BLOCK(mp
)),
3336 buf
->b_ops
= &xfs_inobt_buf_ops
;
3337 block
= XFS_BUF_TO_BLOCK(buf
);
3338 memset(block
, 0, blocksize
);
3339 if (xfs_sb_version_hascrc(&mp
->m_sb
))
3340 xfs_btree_init_block(mp
, buf
, XFS_IBT_CRC_MAGIC
, 0, 0,
3341 agno
, XFS_BTREE_CRC_BLOCKS
);
3343 xfs_btree_init_block(mp
, buf
, XFS_IBT_MAGIC
, 0, 0,
3345 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3348 * Free INO btree root block
3350 if (!sb_feat
.finobt
) {
3355 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3356 XFS_AGB_TO_DADDR(mp
, agno
, XFS_FIBT_BLOCK(mp
)),
3358 buf
->b_ops
= &xfs_inobt_buf_ops
;
3359 block
= XFS_BUF_TO_BLOCK(buf
);
3360 memset(block
, 0, blocksize
);
3361 if (xfs_sb_version_hascrc(&mp
->m_sb
))
3362 xfs_btree_init_block(mp
, buf
, XFS_FIBT_CRC_MAGIC
, 0, 0,
3363 agno
, XFS_BTREE_CRC_BLOCKS
);
3365 xfs_btree_init_block(mp
, buf
, XFS_FIBT_MAGIC
, 0, 0,
3367 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3372 * Touch last block, make fs the right size if it's a file.
3374 buf
= libxfs_getbuf(mp
->m_ddev_targp
,
3375 (xfs_daddr_t
)XFS_FSB_TO_BB(mp
, dblocks
- 1LL), bsize
);
3376 memset(XFS_BUF_PTR(buf
), 0, blocksize
);
3377 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3380 * Make sure we can write the last block in the realtime area.
3382 if (mp
->m_rtdev_targp
->dev
&& rtblocks
> 0) {
3383 buf
= libxfs_getbuf(mp
->m_rtdev_targp
,
3384 XFS_FSB_TO_BB(mp
, rtblocks
- 1LL), bsize
);
3385 memset(XFS_BUF_PTR(buf
), 0, blocksize
);
3386 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3390 * BNO, CNT free block list
3392 for (agno
= 0; agno
< agcount
; agno
++) {
3393 xfs_alloc_arg_t args
;
3395 struct xfs_trans_res tres
= {0};
3397 memset(&args
, 0, sizeof(args
));
3398 args
.tp
= tp
= libxfs_trans_alloc(mp
, 0);
3402 args
.pag
= xfs_perag_get(mp
,agno
);
3403 c
= -libxfs_trans_reserve(tp
, &tres
, worst_freelist
, 0);
3407 libxfs_alloc_fix_freelist(&args
, 0);
3408 xfs_perag_put(args
.pag
);
3409 libxfs_trans_commit(tp
);
3413 * Allocate the root inode and anything else in the proto file.
3415 parse_proto(mp
, &fsx
, &protostring
);
3418 * Protect ourselves against possible stupidity
3420 if (XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
) != 0) {
3422 _("%s: root inode created in AG %u, not AG 0\n"),
3423 progname
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
));
3428 * Write out multiple secondary superblocks with rootinode field set
3430 if (mp
->m_sb
.sb_agcount
> 1) {
3432 * the last superblock
3434 buf
= libxfs_readbuf(mp
->m_dev
,
3435 XFS_AGB_TO_DADDR(mp
, mp
->m_sb
.sb_agcount
-1,
3437 XFS_FSS_TO_BB(mp
, 1),
3438 LIBXFS_EXIT_ON_FAILURE
, &xfs_sb_buf_ops
);
3439 XFS_BUF_TO_SBP(buf
)->sb_rootino
= cpu_to_be64(
3440 mp
->m_sb
.sb_rootino
);
3441 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3443 * and one in the middle for luck
3445 if (mp
->m_sb
.sb_agcount
> 2) {
3446 buf
= libxfs_readbuf(mp
->m_dev
,
3447 XFS_AGB_TO_DADDR(mp
, (mp
->m_sb
.sb_agcount
-1)/2,
3449 XFS_FSS_TO_BB(mp
, 1),
3450 LIBXFS_EXIT_ON_FAILURE
, &xfs_sb_buf_ops
);
3451 XFS_BUF_TO_SBP(buf
)->sb_rootino
= cpu_to_be64(
3452 mp
->m_sb
.sb_rootino
);
3453 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3458 * Dump all inodes and buffers before marking us all done.
3459 * Need to drop references to inodes we still hold, first.
3461 libxfs_rtmount_destroy(mp
);
3462 libxfs_bcache_purge();
3465 * Mark the filesystem ok.
3467 buf
= libxfs_getsb(mp
, LIBXFS_EXIT_ON_FAILURE
);
3468 (XFS_BUF_TO_SBP(buf
))->sb_inprogress
= 0;
3469 libxfs_writebuf(buf
, LIBXFS_EXIT_ON_FAILURE
);
3473 libxfs_device_close(xi
.rtdev
);
3474 if (xi
.logdev
&& xi
.logdev
!= xi
.ddev
)
3475 libxfs_device_close(xi
.logdev
);
3476 libxfs_device_close(xi
.ddev
);
3488 fprintf(stderr
, _("Cannot specify both -%c %s and -%c %s\n"),
3489 opt
, tab
[oldidx
], opt
, tab
[newidx
]);
3499 fprintf(stderr
, _("Illegal value %s for -%s option\n"), value
, opt
);
3507 return (i
& (i
- 1)) == 0;
3510 static void __attribute__((noreturn
))
3516 fprintf(stderr
, _("-%c %s option requires a value\n"), opt
, tab
[idx
]);
3526 fprintf(stderr
, "-%c ", opt
);
3528 fprintf(stderr
, "%s ", tab
[idx
]);
3529 fprintf(stderr
, _("option respecified\n"));
3538 fprintf(stderr
, _("unknown option -%c %s\n"), opt
, s
);
3544 unsigned int blocksize
,
3545 unsigned int sectorsize
,
3551 i
= strtoll(s
, &sp
, 0);
3552 if (i
== 0 && sp
== s
)
3557 if (*sp
== 'b' && sp
[1] == '\0')
3558 return i
* blocksize
;
3559 if (*sp
== 's' && sp
[1] == '\0')
3560 return i
* sectorsize
;
3562 if (*sp
== 'k' && sp
[1] == '\0')
3564 if (*sp
== 'm' && sp
[1] == '\0')
3565 return 1024LL * 1024LL * i
;
3566 if (*sp
== 'g' && sp
[1] == '\0')
3567 return 1024LL * 1024LL * 1024LL * i
;
3568 if (*sp
== 't' && sp
[1] == '\0')
3569 return 1024LL * 1024LL * 1024LL * 1024LL * i
;
3570 if (*sp
== 'p' && sp
[1] == '\0')
3571 return 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * i
;
3572 if (*sp
== 'e' && sp
[1] == '\0')
3573 return 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * i
;
3577 static void __attribute__((noreturn
))
3580 fprintf(stderr
, _("Usage: %s\n\
3581 /* blocksize */ [-b log=n|size=num]\n\
3582 /* metadata */ [-m crc=0|1,finobt=0|1,uuid=xxx]\n\
3583 /* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num,\n\
3584 (sunit=value,swidth=value|su=num,sw=num|noalign),\n\
3585 sectlog=n|sectsize=num\n\
3586 /* force overwrite */ [-f]\n\
3587 /* inode size */ [-i log=n|perblock=n|size=num,maxpct=n,attr=0|1|2,\n\
3588 projid32bit=0|1,sparse=0|1]\n\
3589 /* no discard */ [-K]\n\
3590 /* log subvol */ [-l agnum=n,internal,size=num,logdev=xxx,version=n\n\
3591 sunit=value|su=num,sectlog=n|sectsize=num,\n\
3593 /* label */ [-L label (maximum 12 characters)]\n\
3594 /* naming */ [-n log=n|size=num,version=2|ci,ftype=0|1]\n\
3595 /* no-op info only */ [-N]\n\
3596 /* prototype file */ [-p fname]\n\
3598 /* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx]\n\
3599 /* sectorsize */ [-s log=n|size=num]\n\
3600 /* version */ [-V]\n\
3602 <devicename> is required unless -d name=xxx is given.\n\
3603 <num> is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxx KiB),\n\
3604 xxxm (xxx MiB), xxxg (xxx GiB), xxxt (xxx TiB) or xxxp (xxx PiB).\n\
3605 <value> is xxx (512 byte blocks).\n"),