| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: mkfs.c,v 1.128 2017/02/08 16:11:40 rin Exp $ */ | | 1 | /* $NetBSD: mkfs.c,v 1.129 2020/04/17 09:33:37 jdolecek Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1980, 1989, 1993 | | 4 | * Copyright (c) 1980, 1989, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -63,27 +63,27 @@ | | | @@ -63,27 +63,27 @@ |
63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
64 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 64 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
68 | * SUCH DAMAGE. | | 68 | * SUCH DAMAGE. |
69 | */ | | 69 | */ |
70 | | | 70 | |
71 | #include <sys/cdefs.h> | | 71 | #include <sys/cdefs.h> |
72 | #ifndef lint | | 72 | #ifndef lint |
73 | #if 0 | | 73 | #if 0 |
74 | static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95"; | | 74 | static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95"; |
75 | #else | | 75 | #else |
76 | __RCSID("$NetBSD: mkfs.c,v 1.128 2017/02/08 16:11:40 rin Exp $"); | | 76 | __RCSID("$NetBSD: mkfs.c,v 1.129 2020/04/17 09:33:37 jdolecek Exp $"); |
77 | #endif | | 77 | #endif |
78 | #endif /* not lint */ | | 78 | #endif /* not lint */ |
79 | | | 79 | |
80 | #include <sys/param.h> | | 80 | #include <sys/param.h> |
81 | #include <sys/mman.h> | | 81 | #include <sys/mman.h> |
82 | #include <sys/time.h> | | 82 | #include <sys/time.h> |
83 | #include <sys/resource.h> | | 83 | #include <sys/resource.h> |
84 | #include <ufs/ufs/dinode.h> | | 84 | #include <ufs/ufs/dinode.h> |
85 | #include <ufs/ufs/dir.h> | | 85 | #include <ufs/ufs/dir.h> |
86 | #include <ufs/ufs/ufs_bswap.h> | | 86 | #include <ufs/ufs/ufs_bswap.h> |
87 | #include <ufs/ufs/quota2.h> | | 87 | #include <ufs/ufs/quota2.h> |
88 | #include <ufs/ffs/fs.h> | | 88 | #include <ufs/ffs/fs.h> |
89 | #include <ufs/ffs/ffs_extern.h> | | 89 | #include <ufs/ffs/ffs_extern.h> |
| @@ -190,30 +190,32 @@ mkfs(const char *fsys, int fi, int fo, | | | @@ -190,30 +190,32 @@ mkfs(const char *fsys, int fi, int fo, |
190 | long long sizepb; | | 190 | long long sizepb; |
191 | int len, col, delta, fld_width, max_cols; | | 191 | int len, col, delta, fld_width, max_cols; |
192 | struct winsize winsize; | | 192 | struct winsize winsize; |
193 | | | 193 | |
194 | #ifndef STANDALONE | | 194 | #ifndef STANDALONE |
195 | gettimeofday(&tv, NULL); | | 195 | gettimeofday(&tv, NULL); |
196 | #endif | | 196 | #endif |
197 | #ifdef MFS | | 197 | #ifdef MFS |
198 | if (mfs && !Nflag) { | | 198 | if (mfs && !Nflag) { |
199 | if ((membase = mkfs_malloc(fssize * sectorsize)) == NULL) | | 199 | if ((membase = mkfs_malloc(fssize * sectorsize)) == NULL) |
200 | exit(12); | | 200 | exit(12); |
201 | } | | 201 | } |
202 | #endif | | 202 | #endif |
203 | if ((fsun = calloc(1, sizeof(*fsun))) == NULL) | | 203 | if ((fsun = aligned_alloc(DEV_BSIZE, sizeof(*fsun))) == NULL) |
204 | exit(12); | | 204 | exit(12); |
205 | if ((cgun = calloc(1, sizeof(*cgun))) == NULL) | | 205 | memset(fsun, 0, sizeof(*fsun)); |
| | | 206 | if ((cgun = aligned_alloc(DEV_BSIZE, sizeof(*cgun))) == NULL) |
206 | exit(12); | | 207 | exit(12); |
| | | 208 | memset(cgun, 0, sizeof(*cgun)); |
207 | | | 209 | |
208 | fsi = fi; | | 210 | fsi = fi; |
209 | fso = fo; | | 211 | fso = fo; |
210 | if (Oflag == 0) { | | 212 | if (Oflag == 0) { |
211 | sblock.fs_old_inodefmt = FS_42INODEFMT; | | 213 | sblock.fs_old_inodefmt = FS_42INODEFMT; |
212 | sblock.fs_maxsymlinklen = 0; | | 214 | sblock.fs_maxsymlinklen = 0; |
213 | sblock.fs_old_flags = 0; | | 215 | sblock.fs_old_flags = 0; |
214 | } else { | | 216 | } else { |
215 | sblock.fs_old_inodefmt = FS_44INODEFMT; | | 217 | sblock.fs_old_inodefmt = FS_44INODEFMT; |
216 | sblock.fs_maxsymlinklen = (Oflag == 1 ? UFS1_MAXSYMLINKLEN : | | 218 | sblock.fs_maxsymlinklen = (Oflag == 1 ? UFS1_MAXSYMLINKLEN : |
217 | UFS2_MAXSYMLINKLEN); | | 219 | UFS2_MAXSYMLINKLEN); |
218 | sblock.fs_old_flags = FS_FLAGS_UPDATED; | | 220 | sblock.fs_old_flags = FS_FLAGS_UPDATED; |
219 | if (isappleufs) | | 221 | if (isappleufs) |
| @@ -623,27 +625,27 @@ mkfs(const char *fsys, int fi, int fo, | | | @@ -623,27 +625,27 @@ mkfs(const char *fsys, int fi, int fo, |
623 | sblkoff += SBLOCKSIZE; | | 625 | sblkoff += SBLOCKSIZE; |
624 | for (sz = SBLOCKSIZE; sz <= 0x10000; sz <<= 1) | | 626 | for (sz = SBLOCKSIZE; sz <= 0x10000; sz <<= 1) |
625 | zap_old_sblock(roundup(sblkoff, sz)); | | 627 | zap_old_sblock(roundup(sblkoff, sz)); |
626 | } | | 628 | } |
627 | /* | | 629 | /* |
628 | * Also zap possible Ext2fs magic leftover to prevent | | 630 | * Also zap possible Ext2fs magic leftover to prevent |
629 | * kernel vfs_mountroot() and bootloaders from mis-recognizing | | 631 | * kernel vfs_mountroot() and bootloaders from mis-recognizing |
630 | * this file system as Ext2fs. | | 632 | * this file system as Ext2fs. |
631 | */ | | 633 | */ |
632 | zap_old_sblock(EXT2FS_SBOFF); | | 634 | zap_old_sblock(EXT2FS_SBOFF); |
633 | | | 635 | |
634 | #ifndef NO_APPLE_UFS | | 636 | #ifndef NO_APPLE_UFS |
635 | if (isappleufs) { | | 637 | if (isappleufs) { |
636 | struct appleufslabel appleufs; | | 638 | struct appleufslabel appleufs __aligned(DEV_BSIZE); |
637 | ffs_appleufs_set(&appleufs, appleufs_volname, | | 639 | ffs_appleufs_set(&appleufs, appleufs_volname, |
638 | tv.tv_sec, 0); | | 640 | tv.tv_sec, 0); |
639 | wtfs(APPLEUFS_LABEL_OFFSET/sectorsize, | | 641 | wtfs(APPLEUFS_LABEL_OFFSET/sectorsize, |
640 | APPLEUFS_LABEL_SIZE, &appleufs); | | 642 | APPLEUFS_LABEL_SIZE, &appleufs); |
641 | } else if (APPLEUFS_LABEL_SIZE % sectorsize == 0) { | | 643 | } else if (APPLEUFS_LABEL_SIZE % sectorsize == 0) { |
642 | struct appleufslabel appleufs; | | 644 | struct appleufslabel appleufs; |
643 | /* Look for & zap any existing valid apple ufs labels */ | | 645 | /* Look for & zap any existing valid apple ufs labels */ |
644 | rdfs(APPLEUFS_LABEL_OFFSET/sectorsize, | | 646 | rdfs(APPLEUFS_LABEL_OFFSET/sectorsize, |
645 | APPLEUFS_LABEL_SIZE, &appleufs); | | 647 | APPLEUFS_LABEL_SIZE, &appleufs); |
646 | if (ffs_appleufs_validate(fsys, &appleufs, NULL) == 0) { | | 648 | if (ffs_appleufs_validate(fsys, &appleufs, NULL) == 0) { |
647 | memset(&appleufs, 0, sizeof(appleufs)); | | 649 | memset(&appleufs, 0, sizeof(appleufs)); |
648 | wtfs(APPLEUFS_LABEL_OFFSET/sectorsize, | | 650 | wtfs(APPLEUFS_LABEL_OFFSET/sectorsize, |
649 | APPLEUFS_LABEL_SIZE, &appleufs); | | 651 | APPLEUFS_LABEL_SIZE, &appleufs); |
| @@ -1024,27 +1026,27 @@ struct direct lost_found_dir[] = { | | | @@ -1024,27 +1026,27 @@ struct direct lost_found_dir[] = { |
1024 | struct odirect olost_found_dir[] = { | | 1026 | struct odirect olost_found_dir[] = { |
1025 | { LOSTFOUNDINO, sizeof(struct direct), 1, "." }, | | 1027 | { LOSTFOUNDINO, sizeof(struct direct), 1, "." }, |
1026 | { UFS_ROOTINO, sizeof(struct direct), 2, ".." }, | | 1028 | { UFS_ROOTINO, sizeof(struct direct), 2, ".." }, |
1027 | { 0, DIRBLKSIZ, 0, 0 }, | | 1029 | { 0, DIRBLKSIZ, 0, 0 }, |
1028 | }; | | 1030 | }; |
1029 | #endif | | 1031 | #endif |
1030 | | | 1032 | |
1031 | static void copy_dir(struct direct *, struct direct *); | | 1033 | static void copy_dir(struct direct *, struct direct *); |
1032 | | | 1034 | |
1033 | int | | 1035 | int |
1034 | fsinit(const struct timeval *tv, mode_t mfsmode, uid_t mfsuid, gid_t mfsgid) | | 1036 | fsinit(const struct timeval *tv, mode_t mfsmode, uid_t mfsuid, gid_t mfsgid) |
1035 | { | | 1037 | { |
1036 | union dinode node; | | 1038 | union dinode node; |
1037 | union Buffer buf; | | 1039 | union Buffer buf __aligned(DEV_BSIZE); |
1038 | int i; | | 1040 | int i; |
1039 | int qblocks = 0; | | 1041 | int qblocks = 0; |
1040 | int qinos = 0; | | 1042 | int qinos = 0; |
1041 | uint8_t q2h_hash_shift; | | 1043 | uint8_t q2h_hash_shift; |
1042 | uint16_t q2h_hash_mask; | | 1044 | uint16_t q2h_hash_mask; |
1043 | #ifdef LOSTDIR | | 1045 | #ifdef LOSTDIR |
1044 | int dirblksiz = DIRBLKSIZ; | | 1046 | int dirblksiz = DIRBLKSIZ; |
1045 | if (isappleufs) | | 1047 | if (isappleufs) |
1046 | dirblksiz = APPLEUFS_DIRBLKSIZ; | | 1048 | dirblksiz = APPLEUFS_DIRBLKSIZ; |
1047 | int nextino = LOSTFOUNDINO+1; | | 1049 | int nextino = LOSTFOUNDINO+1; |
1048 | #else | | 1050 | #else |
1049 | int nextino = UFS_ROOTINO+1; | | 1051 | int nextino = UFS_ROOTINO+1; |
1050 | #endif | | 1052 | #endif |
| @@ -1574,27 +1576,27 @@ ilog2(int val) | | | @@ -1574,27 +1576,27 @@ ilog2(int val) |
1574 | { | | 1576 | { |
1575 | u_int n; | | 1577 | u_int n; |
1576 | | | 1578 | |
1577 | for (n = 0; n < sizeof(n) * CHAR_BIT; n++) | | 1579 | for (n = 0; n < sizeof(n) * CHAR_BIT; n++) |
1578 | if (1 << n == val) | | 1580 | if (1 << n == val) |
1579 | return (n); | | 1581 | return (n); |
1580 | errx(1, "ilog2: %d is not a power of 2", val); | | 1582 | errx(1, "ilog2: %d is not a power of 2", val); |
1581 | } | | 1583 | } |
1582 | | | 1584 | |
1583 | static void | | 1585 | static void |
1584 | zap_old_sblock(int sblkoff) | | 1586 | zap_old_sblock(int sblkoff) |
1585 | { | | 1587 | { |
1586 | static int cg0_data; | | 1588 | static int cg0_data; |
1587 | uint32_t oldfs[SBLOCKSIZE / 4]; | | 1589 | uint32_t oldfs[SBLOCKSIZE / 4] __aligned(DEV_BSIZE); |
1588 | static const struct fsm { | | 1590 | static const struct fsm { |
1589 | uint32_t offset; | | 1591 | uint32_t offset; |
1590 | uint32_t magic; | | 1592 | uint32_t magic; |
1591 | uint32_t mask; | | 1593 | uint32_t mask; |
1592 | } fs_magics[] = { | | 1594 | } fs_magics[] = { |
1593 | {offsetof(struct fs, fs_magic)/4, FS_UFS1_MAGIC, ~0u}, | | 1595 | {offsetof(struct fs, fs_magic)/4, FS_UFS1_MAGIC, ~0u}, |
1594 | {offsetof(struct fs, fs_magic)/4, FS_UFS2_MAGIC, ~0u}, | | 1596 | {offsetof(struct fs, fs_magic)/4, FS_UFS2_MAGIC, ~0u}, |
1595 | {0, 0x70162, ~0u}, /* LFS_MAGIC */ | | 1597 | {0, 0x70162, ~0u}, /* LFS_MAGIC */ |
1596 | {14, 0xef53, 0xffff}, /* EXT2FS (little) */ | | 1598 | {14, 0xef53, 0xffff}, /* EXT2FS (little) */ |
1597 | {14, 0xef530000, 0xffff0000}, /* EXT2FS (big) */ | | 1599 | {14, 0xef530000, 0xffff0000}, /* EXT2FS (big) */ |
1598 | {.offset = ~0u}, | | 1600 | {.offset = ~0u}, |
1599 | }; | | 1601 | }; |
1600 | const struct fsm *fsm; | | 1602 | const struct fsm *fsm; |