2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 static const char copyright[] =
35 "@(#) Copyright (c) 1983, 1993\n\
36 The Regents of the University of California. All rights reserved.\n";
40 static char sccsid[] = "@(#)tunefs.c 8.2 (Berkeley) 4/19/94";
43 #include <sys/cdefs.h>
45 * tunefs: change layout parameters to an existing file system.
47 #include <sys/param.h>
48 #include <sys/mount.h>
49 #include <sys/disklabel.h>
52 #include <ufs/ufs/ufsmount.h>
53 #include <ufs/ufs/dinode.h>
54 #include <ufs/ffs/fs.h>
55 #include <ufs/ufs/dir.h>
71 /* the optimization warning string template */
72 #define OPTWARN "should optimize for %s with minfree %s %d%%"
75 static char clrbuf[MAXBSIZE];
76 static struct uufsd disk;
77 #define sblock disk.d_fs
79 static void usage(void);
80 static void printfs(void);
81 static int journal_alloc(int64_t size);
82 static void journal_clear(void);
83 static void sbdirty(void);
86 main(int argc, char *argv[])
88 const char *avalue, *jvalue, *Jvalue, *Lvalue, *lvalue, *Nvalue, *nvalue;
93 int Aflag, aflag, eflag, evalue, fflag, fvalue, jflag, Jflag, kflag;
94 int kvalue, Lflag, lflag, mflag, mvalue, Nflag, nflag, oflag, ovalue;
95 int pflag, sflag, svalue, Svalue, tflag;
101 Aflag = aflag = eflag = fflag = jflag = Jflag = kflag = Lflag = 0;
102 lflag = mflag = Nflag = nflag = oflag = pflag = sflag = tflag = 0;
103 avalue = jvalue = Jvalue = Lvalue = lvalue = Nvalue = nvalue = NULL;
104 evalue = fvalue = mvalue = ovalue = svalue = Svalue = 0;
105 found_arg = 0; /* At least one arg is required. */
106 while ((ch = getopt(argc, argv, "Aa:e:f:j:J:k:L:l:m:N:n:o:ps:S:t:"))
117 name = "POSIX.1e ACLs";
119 if (strcmp(avalue, "enable") &&
120 strcmp(avalue, "disable")) {
121 errx(10, "bad %s (options are %s)",
122 name, "`enable' or `disable'");
129 name = "maximum blocks per file in a cylinder group";
130 evalue = atoi(optarg);
132 errx(10, "%s must be >= 1 (was %s)",
139 name = "average file size";
140 fvalue = atoi(optarg);
142 errx(10, "%s must be >= 1 (was %s)",
149 name = "softdep journaled file system";
151 if (strcmp(jvalue, "enable") &&
152 strcmp(jvalue, "disable")) {
153 errx(10, "bad %s (options are %s)",
154 name, "`enable' or `disable'");
161 name = "gjournaled file system";
163 if (strcmp(Jvalue, "enable") &&
164 strcmp(Jvalue, "disable")) {
165 errx(10, "bad %s (options are %s)",
166 name, "`enable' or `disable'");
173 name = "space to hold for metadata blocks";
174 kvalue = atoi(optarg);
176 errx(10, "bad %s (%s)", name, optarg);
182 name = "volume label";
185 while (isalnum(Lvalue[++i]) || Lvalue[i] == '_' ||
188 if (Lvalue[i] != '\0') {
189 errx(10, "bad %s. Valid characters are "
190 "alphanumerics, dashes, and underscores.",
193 if (strlen(Lvalue) >= MAXVOLLEN) {
194 errx(10, "bad %s. Length is longer than %d.",
195 name, MAXVOLLEN - 1);
202 name = "multilabel MAC file system";
204 if (strcmp(lvalue, "enable") &&
205 strcmp(lvalue, "disable")) {
206 errx(10, "bad %s (options are %s)",
207 name, "`enable' or `disable'");
214 name = "minimum percentage of free space";
215 mvalue = atoi(optarg);
216 if (mvalue < 0 || mvalue > 99)
217 errx(10, "bad %s (%s)", name, optarg);
225 if (strcmp(Nvalue, "enable") &&
226 strcmp(Nvalue, "disable")) {
227 errx(10, "bad %s (options are %s)",
228 name, "`enable' or `disable'");
235 name = "soft updates";
237 if (strcmp(nvalue, "enable") != 0 &&
238 strcmp(nvalue, "disable") != 0) {
239 errx(10, "bad %s (options are %s)",
240 name, "`enable' or `disable'");
247 name = "optimization preference";
248 if (strcmp(optarg, "space") == 0)
249 ovalue = FS_OPTSPACE;
250 else if (strcmp(optarg, "time") == 0)
254 "bad %s (options are `space' or `time')",
266 name = "expected number of files per directory";
267 svalue = atoi(optarg);
269 errx(10, "%s must be >= 1 (was %s)",
276 name = "Softdep Journal Size";
277 Svalue = atoi(optarg);
278 if (Svalue < SUJ_MIN)
279 errx(10, "%s must be >= %d (was %s)",
280 name, SUJ_MIN, optarg);
287 if (strcmp(tvalue, "enable") != 0 &&
288 strcmp(tvalue, "disable") != 0) {
289 errx(10, "bad %s (options are %s)",
290 name, "`enable' or `disable'");
300 if (found_arg == 0 || argc != 1)
304 if (ufs_disk_fillout(&disk, special) == -1)
307 * Check for unclean filesystem.
309 if ((sblock.fs_clean == 0 ||
310 (sblock.fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) != 0) &&
311 (found_arg > 1 || !pflag))
312 errx(1, "%s is not clean - run fsck.\n", special);
318 name = "volume label";
319 strncpy(sblock.fs_volname, Lvalue, MAXVOLLEN);
322 name = "POSIX.1e ACLs";
323 if (strcmp(avalue, "enable") == 0) {
324 if (sblock.fs_flags & FS_ACLS) {
325 warnx("%s remains unchanged as enabled", name);
326 } else if (sblock.fs_flags & FS_NFS4ACLS) {
327 warnx("%s and NFSv4 ACLs are mutually "
330 sblock.fs_flags |= FS_ACLS;
331 warnx("%s set", name);
333 } else if (strcmp(avalue, "disable") == 0) {
334 if ((~sblock.fs_flags & FS_ACLS) ==
336 warnx("%s remains unchanged as disabled",
339 sblock.fs_flags &= ~FS_ACLS;
340 warnx("%s cleared", name);
345 name = "maximum blocks per file in a cylinder group";
346 if (sblock.fs_maxbpg == evalue)
347 warnx("%s remains unchanged as %d", name, evalue);
349 warnx("%s changes from %d to %d",
350 name, sblock.fs_maxbpg, evalue);
351 sblock.fs_maxbpg = evalue;
355 name = "average file size";
356 if (sblock.fs_avgfilesize == (unsigned)fvalue) {
357 warnx("%s remains unchanged as %d", name, fvalue);
360 warnx("%s changes from %d to %d",
361 name, sblock.fs_avgfilesize, fvalue);
362 sblock.fs_avgfilesize = fvalue;
366 name = "soft updates journaling";
367 if (strcmp(jvalue, "enable") == 0) {
368 if ((sblock.fs_flags & (FS_DOSOFTDEP | FS_SUJ)) ==
369 (FS_DOSOFTDEP | FS_SUJ)) {
370 warnx("%s remains unchanged as enabled", name);
371 } else if (sblock.fs_clean == 0) {
372 warnx("%s cannot be enabled until fsck is run",
374 } else if (journal_alloc(Svalue) != 0) {
375 warnx("%s cannot be enabled", name);
377 sblock.fs_flags |= FS_DOSOFTDEP | FS_SUJ;
378 warnx("%s set", name);
380 } else if (strcmp(jvalue, "disable") == 0) {
381 if ((~sblock.fs_flags & FS_SUJ) == FS_SUJ) {
382 warnx("%s remains unchanged as disabled", name);
385 sblock.fs_flags &= ~FS_SUJ;
386 sblock.fs_sujfree = 0;
387 warnx("%s cleared but soft updates still set.",
390 warnx("remove .sujournal to reclaim space");
396 if (strcmp(Jvalue, "enable") == 0) {
397 if (sblock.fs_flags & FS_GJOURNAL) {
398 warnx("%s remains unchanged as enabled", name);
400 sblock.fs_flags |= FS_GJOURNAL;
401 warnx("%s set", name);
403 } else if (strcmp(Jvalue, "disable") == 0) {
404 if ((~sblock.fs_flags & FS_GJOURNAL) ==
406 warnx("%s remains unchanged as disabled",
409 sblock.fs_flags &= ~FS_GJOURNAL;
410 warnx("%s cleared", name);
415 name = "space to hold for metadata blocks";
416 if (sblock.fs_metaspace == kvalue)
417 warnx("%s remains unchanged as %d", name, kvalue);
419 kvalue = blknum(&sblock, kvalue);
420 if (kvalue > sblock.fs_fpg / 2) {
421 kvalue = blknum(&sblock, sblock.fs_fpg / 2);
422 warnx("%s cannot exceed half the file system "
425 warnx("%s changes from %jd to %d",
426 name, sblock.fs_metaspace, kvalue);
427 sblock.fs_metaspace = kvalue;
432 if (strcmp(lvalue, "enable") == 0) {
433 if (sblock.fs_flags & FS_MULTILABEL) {
434 warnx("%s remains unchanged as enabled", name);
436 sblock.fs_flags |= FS_MULTILABEL;
437 warnx("%s set", name);
439 } else if (strcmp(lvalue, "disable") == 0) {
440 if ((~sblock.fs_flags & FS_MULTILABEL) ==
442 warnx("%s remains unchanged as disabled",
445 sblock.fs_flags &= ~FS_MULTILABEL;
446 warnx("%s cleared", name);
451 name = "minimum percentage of free space";
452 if (sblock.fs_minfree == mvalue)
453 warnx("%s remains unchanged as %d%%", name, mvalue);
455 warnx("%s changes from %d%% to %d%%",
456 name, sblock.fs_minfree, mvalue);
457 sblock.fs_minfree = mvalue;
458 if (mvalue >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
459 warnx(OPTWARN, "time", ">=", MINFREE);
460 if (mvalue < MINFREE && sblock.fs_optim == FS_OPTTIME)
461 warnx(OPTWARN, "space", "<", MINFREE);
466 if (strcmp(Nvalue, "enable") == 0) {
467 if (sblock.fs_flags & FS_NFS4ACLS) {
468 warnx("%s remains unchanged as enabled", name);
469 } else if (sblock.fs_flags & FS_ACLS) {
470 warnx("%s and POSIX.1e ACLs are mutually "
473 sblock.fs_flags |= FS_NFS4ACLS;
474 warnx("%s set", name);
476 } else if (strcmp(Nvalue, "disable") == 0) {
477 if ((~sblock.fs_flags & FS_NFS4ACLS) ==
479 warnx("%s remains unchanged as disabled",
482 sblock.fs_flags &= ~FS_NFS4ACLS;
483 warnx("%s cleared", name);
488 name = "soft updates";
489 if (strcmp(nvalue, "enable") == 0) {
490 if (sblock.fs_flags & FS_DOSOFTDEP)
491 warnx("%s remains unchanged as enabled", name);
492 else if (sblock.fs_clean == 0) {
493 warnx("%s cannot be enabled until fsck is run",
496 sblock.fs_flags |= FS_DOSOFTDEP;
497 warnx("%s set", name);
499 } else if (strcmp(nvalue, "disable") == 0) {
500 if ((~sblock.fs_flags & FS_DOSOFTDEP) == FS_DOSOFTDEP)
501 warnx("%s remains unchanged as disabled", name);
503 sblock.fs_flags &= ~FS_DOSOFTDEP;
504 warnx("%s cleared", name);
509 name = "optimization preference";
510 chg[FS_OPTSPACE] = "space";
511 chg[FS_OPTTIME] = "time";
512 if (sblock.fs_optim == ovalue)
513 warnx("%s remains unchanged as %s", name, chg[ovalue]);
515 warnx("%s changes from %s to %s",
516 name, chg[sblock.fs_optim], chg[ovalue]);
517 sblock.fs_optim = ovalue;
518 if (sblock.fs_minfree >= MINFREE &&
519 ovalue == FS_OPTSPACE)
520 warnx(OPTWARN, "time", ">=", MINFREE);
521 if (sblock.fs_minfree < MINFREE && ovalue == FS_OPTTIME)
522 warnx(OPTWARN, "space", "<", MINFREE);
526 name = "expected number of files per directory";
527 if (sblock.fs_avgfpdir == (unsigned)svalue) {
528 warnx("%s remains unchanged as %d", name, svalue);
531 warnx("%s changes from %d to %d",
532 name, sblock.fs_avgfpdir, svalue);
533 sblock.fs_avgfpdir = svalue;
537 name = "issue TRIM to the disk";
538 if (strcmp(tvalue, "enable") == 0) {
539 if (sblock.fs_flags & FS_TRIM)
540 warnx("%s remains unchanged as enabled", name);
542 sblock.fs_flags |= FS_TRIM;
543 warnx("%s set", name);
545 } else if (strcmp(tvalue, "disable") == 0) {
546 if ((~sblock.fs_flags & FS_TRIM) == FS_TRIM)
547 warnx("%s remains unchanged as disabled", name);
549 sblock.fs_flags &= ~FS_TRIM;
550 warnx("%s cleared", name);
555 if (sbwrite(&disk, Aflag) == -1)
557 diskname = strdup(disk.d_name);
558 ufs_disk_close(&disk);
559 chkdoreload(getmntpoint(diskname), warnx);
562 if (disk.d_error != NULL)
563 errx(11, "%s: %s", special, disk.d_error);
565 err(12, "%s", special);
571 disk.d_fs.fs_flags |= FS_UNCLEAN | FS_NEEDSFSCK;
572 disk.d_fs.fs_clean = 0;
581 static int contig = 1;
585 blk = cgballoc(&disk);
589 * If we failed to allocate a block from this cg, move to
592 if (cgwrite(&disk) < 0) {
593 warn("Failed to write updated cg");
596 while ((valid = cgread(&disk)) == 1) {
598 * Try to minimize fragmentation by requiring a minimum
599 * number of blocks present.
601 if (cgp->cg_cs.cs_nbfree > 256 * 1024)
603 if (contig == 0 && cgp->cg_cs.cs_nbfree)
609 * Try once through looking only for large contiguous regions
610 * and again taking any space we can find.
615 warnx("Journal file fragmented.");
618 warnx("Failed to find sufficient free blocks for the journal");
621 if (bwrite(&disk, fsbtodb(&sblock, blk), clrbuf,
622 sblock.fs_bsize) <= 0) {
623 warn("Failed to initialize new block");
630 * Search a directory block for the SUJ_FILE.
633 dir_search(ufs2_daddr_t blk, int bytes)
635 char block[MAXBSIZE];
639 if (bread(&disk, fsbtodb(&sblock, blk), block, bytes) <= 0) {
640 warn("Failed to read dir block");
643 for (off = 0; off < bytes; off += dp->d_reclen) {
644 dp = (struct direct *)&block[off];
645 if (dp->d_reclen == 0)
649 if (dp->d_namlen != strlen(SUJ_FILE))
651 if (bcmp(dp->d_name, SUJ_FILE, dp->d_namlen) != 0)
660 * Search in the UFS_ROOTINO for the SUJ_FILE. If it exists we can not enable
664 journal_findfile(void)
670 if (getinode(&disk, &dp, UFS_ROOTINO) != 0) {
671 warn("Failed to get root inode: %s", disk.d_error);
674 if (sblock.fs_magic == FS_UFS1_MAGIC) {
675 if ((off_t)dp.dp1->di_size >= lblktosize(&sblock, UFS_NDADDR)) {
676 warnx("UFS_ROOTINO extends beyond direct blocks.");
679 for (i = 0; i < UFS_NDADDR; i++) {
680 if (dp.dp1->di_db[i] == 0)
682 if ((ino = dir_search(dp.dp1->di_db[i],
683 sblksize(&sblock, (off_t)dp.dp1->di_size, i))) != 0)
687 if ((off_t)dp.dp2->di_size >= lblktosize(&sblock, UFS_NDADDR)) {
688 warnx("UFS_ROOTINO extends beyond direct blocks.");
691 for (i = 0; i < UFS_NDADDR; i++) {
692 if (dp.dp2->di_db[i] == 0)
694 if ((ino = dir_search(dp.dp2->di_db[i],
695 sblksize(&sblock, (off_t)dp.dp2->di_size, i))) != 0)
704 dir_clear_block(const char *block, off_t off)
708 for (; off < sblock.fs_bsize; off += DIRBLKSIZ) {
709 dp = (struct direct *)&block[off];
711 dp->d_reclen = DIRBLKSIZ;
712 dp->d_type = DT_UNKNOWN;
717 * Insert the journal at inode 'ino' into directory blk 'blk' at the first
718 * free offset of 'off'. DIRBLKSIZ blocks after off are initialized as
722 dir_insert(ufs2_daddr_t blk, off_t off, ino_t ino)
725 char block[MAXBSIZE];
727 if (bread(&disk, fsbtodb(&sblock, blk), block, sblock.fs_bsize) <= 0) {
728 warn("Failed to read dir block");
731 bzero(&block[off], sblock.fs_bsize - off);
732 dp = (struct direct *)&block[off];
734 dp->d_reclen = DIRBLKSIZ;
736 dp->d_namlen = strlen(SUJ_FILE);
737 bcopy(SUJ_FILE, &dp->d_name, strlen(SUJ_FILE));
738 dir_clear_block(block, off + DIRBLKSIZ);
739 if (bwrite(&disk, fsbtodb(&sblock, blk), block, sblock.fs_bsize) <= 0) {
740 warn("Failed to write dir block");
747 * Extend a directory block in 'blk' by copying it to a full size block
748 * and inserting the new journal inode into .sujournal.
751 dir_extend(ufs2_daddr_t blk, ufs2_daddr_t nblk, off_t size, ino_t ino)
753 char block[MAXBSIZE];
755 if (bread(&disk, fsbtodb(&sblock, blk), block,
756 roundup(size, sblock.fs_fsize)) <= 0) {
757 warn("Failed to read dir block");
760 dir_clear_block(block, size);
761 if (bwrite(&disk, fsbtodb(&sblock, nblk), block, sblock.fs_bsize)
763 warn("Failed to write dir block");
767 return (dir_insert(nblk, size, ino));
771 * Insert the journal file into the UFS_ROOTINO directory. We always extend the
775 journal_insertfile(ino_t ino)
784 if (getinode(&disk, &dp, UFS_ROOTINO) != 0) {
785 warn("Failed to get root inode: %s", disk.d_error);
791 nblk = journal_balloc();
795 * For simplicity sake we aways extend the UFS_ROOTINO into a new
796 * directory block rather than searching for space and inserting
797 * into an existing block. However, if the rootino has frags
798 * have to free them and extend the block.
800 if (sblock.fs_magic == FS_UFS1_MAGIC) {
801 lbn = lblkno(&sblock, dp.dp1->di_size);
802 off = blkoff(&sblock, dp.dp1->di_size);
803 blk = dp.dp1->di_db[lbn];
804 size = sblksize(&sblock, (off_t)dp.dp1->di_size, lbn);
806 lbn = lblkno(&sblock, dp.dp2->di_size);
807 off = blkoff(&sblock, dp.dp2->di_size);
808 blk = dp.dp2->di_db[lbn];
809 size = sblksize(&sblock, (off_t)dp.dp2->di_size, lbn);
812 if (dir_extend(blk, nblk, off, ino) == -1)
816 if (dir_insert(nblk, 0, ino) == -1)
819 if (sblock.fs_magic == FS_UFS1_MAGIC) {
820 dp.dp1->di_blocks += (sblock.fs_bsize - size) / DEV_BSIZE;
821 dp.dp1->di_db[lbn] = nblk;
822 dp.dp1->di_size = lblktosize(&sblock, lbn+1);
824 dp.dp2->di_blocks += (sblock.fs_bsize - size) / DEV_BSIZE;
825 dp.dp2->di_db[lbn] = nblk;
826 dp.dp2->di_size = lblktosize(&sblock, lbn+1);
828 if (putinode(&disk) < 0) {
829 warn("Failed to write root inode: %s", disk.d_error);
832 if (cgwrite(&disk) < 0) {
833 warn("Failed to write updated cg");
838 if (cgbfree(&disk, blk, size) < 0) {
839 warn("Failed to write cg");
848 indir_fill(ufs2_daddr_t blk, int level, int *resid)
850 char indirbuf[MAXBSIZE];
858 bzero(indirbuf, sizeof(indirbuf));
859 bap1 = (ufs1_daddr_t *)indirbuf;
862 for (i = 0; i < NINDIR(&sblock) && *resid != 0; i++) {
863 nblk = journal_balloc();
867 if (sblock.fs_magic == FS_UFS1_MAGIC)
872 ncnt = indir_fill(nblk, level - 1, resid);
879 if (bwrite(&disk, fsbtodb(&sblock, blk), indirbuf,
880 sblock.fs_bsize) <= 0) {
881 warn("Failed to write indirect");
888 * Clear the flag bits so the journal can be removed.
896 ino = journal_findfile();
897 if (ino == (ino_t)-1 || ino == 0) {
898 warnx("Journal file does not exist");
901 printf("Clearing journal flags from inode %ju\n", (uintmax_t)ino);
902 if (getinode(&disk, &dp, ino) != 0) {
903 warn("Failed to get journal inode: %s", disk.d_error);
906 if (sblock.fs_magic == FS_UFS1_MAGIC)
907 dp.dp1->di_flags = 0;
909 dp.dp2->di_flags = 0;
910 if (putinode(&disk) < 0) {
911 warn("Failed to write journal inode: %s", disk.d_error);
917 journal_alloc(int64_t size)
932 * If the journal file exists we can't allocate it.
934 ino = journal_findfile();
935 if (ino == (ino_t)-1) {
936 warnx("journal_findfile() failed.");
940 warnx("Journal file %s already exists, please remove.",
945 * If the user didn't supply a size pick one based on the filesystem
946 * size constrained with hardcoded MIN and MAX values. We opt for
947 * 1/1024th of the filesystem up to MAX but not exceeding one CG and
948 * not less than the MIN.
951 size = (sblock.fs_size * sblock.fs_bsize) / 1024;
952 if (size / sblock.fs_fsize > sblock.fs_fpg)
953 size = sblock.fs_fpg * sblock.fs_fsize;
954 size = MAX(SUJ_MIN, size);
956 /* fsck does not support fragments in journal files. */
957 size = roundup(size, sblock.fs_bsize);
958 resid = blocks = size / sblock.fs_bsize;
959 if (sblock.fs_cstotal.cs_nbfree < blocks) {
960 warn("Insufficient free space for %jd byte journal", size);
964 * Find a cg with enough blocks to satisfy the journal
965 * size. Presently the journal does not span cgs.
967 while (cgread(&disk) == 1) {
968 if (cgp->cg_cs.cs_nifree == 0)
970 ino = cgialloc(&disk);
973 printf("Using inode %ju in cg %d for %jd byte journal\n",
974 (uintmax_t)ino, cgp->cg_cgx, size);
975 if (getinode(&disk, &dp, ino) != 0) {
976 warn("Failed to get allocated inode: %s", disk.d_error);
981 * We leave fields unrelated to the number of allocated
982 * blocks and size uninitialized. This causes legacy
983 * fsck implementations to clear the inode.
986 if (sblock.fs_magic == FS_UFS1_MAGIC) {
987 bzero(dp.dp1, sizeof(*dp.dp1));
988 dp.dp1->di_size = size;
989 dp.dp1->di_mode = IFREG | IREAD;
990 dp.dp1->di_nlink = 1;
992 SF_IMMUTABLE | SF_NOUNLINK | UF_NODUMP;
993 dp.dp1->di_atime = utime;
994 dp.dp1->di_mtime = utime;
995 dp.dp1->di_ctime = utime;
997 bzero(dp.dp2, sizeof(*dp.dp2));
998 dp.dp2->di_size = size;
999 dp.dp2->di_mode = IFREG | IREAD;
1000 dp.dp2->di_nlink = 1;
1002 SF_IMMUTABLE | SF_NOUNLINK | UF_NODUMP;
1003 dp.dp2->di_atime = utime;
1004 dp.dp2->di_mtime = utime;
1005 dp.dp2->di_ctime = utime;
1006 dp.dp2->di_birthtime = utime;
1008 for (i = 0; i < UFS_NDADDR && resid; i++, resid--) {
1009 blk = journal_balloc();
1012 if (sblock.fs_magic == FS_UFS1_MAGIC) {
1013 dp.dp1->di_db[i] = blk;
1014 dp.dp1->di_blocks++;
1016 dp.dp2->di_db[i] = blk;
1017 dp.dp2->di_blocks++;
1020 for (i = 0; i < UFS_NIADDR && resid; i++) {
1021 blk = journal_balloc();
1024 blks = indir_fill(blk, i, &resid) + 1;
1029 if (sblock.fs_magic == FS_UFS1_MAGIC) {
1030 dp.dp1->di_ib[i] = blk;
1031 dp.dp1->di_blocks += blks;
1033 dp.dp2->di_ib[i] = blk;
1034 dp.dp2->di_blocks += blks;
1037 if (sblock.fs_magic == FS_UFS1_MAGIC)
1038 dp.dp1->di_blocks *= sblock.fs_bsize / disk.d_bsize;
1040 dp.dp2->di_blocks *= sblock.fs_bsize / disk.d_bsize;
1041 if (putinode(&disk) < 0) {
1042 warn("Failed to write allocated inode: %s",
1047 if (cgwrite(&disk) < 0) {
1048 warn("Failed to write updated cg");
1052 if (journal_insertfile(ino) < 0) {
1056 sblock.fs_sujfree = 0;
1059 warnx("Insufficient free space for the journal.");
1067 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n",
1068 "usage: tunefs [-A] [-a enable | disable] [-e maxbpg] [-f avgfilesize]",
1069 " [-J enable | disable] [-j enable | disable] [-k metaspace]",
1070 " [-L volname] [-l enable | disable] [-m minfree]",
1071 " [-N enable | disable] [-n enable | disable]",
1072 " [-o space | time] [-p] [-s avgfpdir] [-t enable | disable]",
1073 " special | filesystem");
1080 warnx("POSIX.1e ACLs: (-a) %s",
1081 (sblock.fs_flags & FS_ACLS)? "enabled" : "disabled");
1082 warnx("NFSv4 ACLs: (-N) %s",
1083 (sblock.fs_flags & FS_NFS4ACLS)? "enabled" : "disabled");
1084 warnx("MAC multilabel: (-l) %s",
1085 (sblock.fs_flags & FS_MULTILABEL)? "enabled" : "disabled");
1086 warnx("soft updates: (-n) %s",
1087 (sblock.fs_flags & FS_DOSOFTDEP)? "enabled" : "disabled");
1088 warnx("soft update journaling: (-j) %s",
1089 (sblock.fs_flags & FS_SUJ)? "enabled" : "disabled");
1090 warnx("gjournal: (-J) %s",
1091 (sblock.fs_flags & FS_GJOURNAL)? "enabled" : "disabled");
1092 warnx("trim: (-t) %s",
1093 (sblock.fs_flags & FS_TRIM)? "enabled" : "disabled");
1094 warnx("maximum blocks per file in a cylinder group: (-e) %d",
1096 warnx("average file size: (-f) %d",
1097 sblock.fs_avgfilesize);
1098 warnx("average number of files in a directory: (-s) %d",
1099 sblock.fs_avgfpdir);
1100 warnx("minimum percentage of free space: (-m) %d%%",
1102 warnx("space to hold for metadata blocks: (-k) %jd",
1103 sblock.fs_metaspace);
1104 warnx("optimization preference: (-o) %s",
1105 sblock.fs_optim == FS_OPTSPACE ? "space" : "time");
1106 if (sblock.fs_minfree >= MINFREE &&
1107 sblock.fs_optim == FS_OPTSPACE)
1108 warnx(OPTWARN, "time", ">=", MINFREE);
1109 if (sblock.fs_minfree < MINFREE &&
1110 sblock.fs_optim == FS_OPTTIME)
1111 warnx(OPTWARN, "space", "<", MINFREE);
1112 warnx("volume label: (-L) %s",