From da5362d567d5bc29ee9e27984ebc5dd0bad1b0e2 Mon Sep 17 00:00:00 2001 From: guenther Date: Tue, 9 Jan 2024 03:15:59 +0000 Subject: [PATCH] Delete support for FFS filesystems before the in-inode symlink optimization. As observed by ali_farzanrad(at)riseup.net, support for these was broken in the 5.5 release in early 2014 by the time_t changes. No one noticed before now, so clearly this isn't something we need to continue to support; rejecting in ffs_validate() is an improvement. Also: simplify DIRSIZ(), drop OLDDIRFMT and NEWDIRFMT, tests of fs_maxsymlinklen against zero, #ifdef tests of FS_44INODEFMT, and remove support for newfs -O0, last used in 2016. ok miod@ --- sbin/dump/main.c | 4 +-- sbin/dump/traverse.c | 10 ++---- sbin/fsck_ffs/dir.c | 12 +++---- sbin/fsck_ffs/inode.c | 5 ++- sbin/fsck_ffs/pass1.c | 5 ++- sbin/fsck_ffs/pass2.c | 8 ++--- sbin/fsdb/fsdb.c | 4 +-- sbin/newfs/mkfs.c | 30 ++++------------- sbin/newfs/newfs.8 | 9 ++--- sbin/newfs/newfs.c | 6 ++-- sbin/restore/dirs.c | 14 ++++---- sys/ufs/ext2fs/ext2fs_dir.h | 6 ++-- sys/ufs/ffs/ffs_inode.c | 6 ++-- sys/ufs/ffs/ffs_vfsops.c | 6 ++-- sys/ufs/ffs/ffs_vnops.c | 5 ++- sys/ufs/ufs/dir.h | 31 +++-------------- sys/ufs/ufs/ufs_dirhash.c | 19 +++++------ sys/ufs/ufs/ufs_lookup.c | 67 ++++++++----------------------------- sys/ufs/ufs/ufs_vnops.c | 35 ++++--------------- usr.sbin/makefs/ffs.c | 12 +++---- 20 files changed, 85 insertions(+), 209 deletions(-) diff --git a/sbin/dump/main.c b/sbin/dump/main.c index b23c408cd96..a5071abedd3 100644 --- a/sbin/dump/main.c +++ b/sbin/dump/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.64 2023/12/18 13:23:52 otto Exp $ */ +/* $OpenBSD: main.c,v 1.65 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: main.c,v 1.14 1997/06/05 11:13:24 lukem Exp $ */ /*- @@ -455,11 +455,9 @@ main(int argc, char *argv[]) tp_bshift = ffs(TP_BSIZE) - 1; if (TP_BSIZE != (1 << tp_bshift)) quit("TP_BSIZE (%d) is not a power of 2\n", TP_BSIZE); -#ifdef FS_44INODEFMT if (sblock->fs_magic == FS_UFS2_MAGIC || sblock->fs_inodefmt >= FS_44INODEFMT) spcl.c_flags |= DR_NEWINODEFMT; -#endif maxino = (ino_t)sblock->fs_ipg * sblock->fs_ncg; mapsize = roundup(howmany(maxino, NBBY), TP_BSIZE); usedinomap = calloc((unsigned) mapsize, sizeof(char)); diff --git a/sbin/dump/traverse.c b/sbin/dump/traverse.c index 16d783cd750..5d3225d613f 100644 --- a/sbin/dump/traverse.c +++ b/sbin/dump/traverse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: traverse.c,v 1.40 2023/02/08 08:25:44 tb Exp $ */ +/* $OpenBSD: traverse.c,v 1.41 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: traverse.c,v 1.17 1997/06/05 11:13:27 lukem Exp $ */ /*- @@ -547,13 +547,7 @@ dumpino(union dinode *dp, ino_t ino) * Check for short symbolic link. */ if (DIP(dp, di_size) > 0 && -#ifdef FS_44INODEFMT - (DIP(dp, di_size) < sblock->fs_maxsymlinklen || - (sblock->fs_maxsymlinklen == 0 && - DIP(dp, di_blocks) == 0))) { -#else - DIP(dp, di_blocks) == 0) { -#endif + DIP(dp, di_size) < sblock->fs_maxsymlinklen) { void *shortlink; spcl.c_addr[0] = 1; diff --git a/sbin/fsck_ffs/dir.c b/sbin/fsck_ffs/dir.c index be627ffbec9..150987a22ae 100644 --- a/sbin/fsck_ffs/dir.c +++ b/sbin/fsck_ffs/dir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dir.c,v 1.33 2023/02/08 08:25:44 tb Exp $ */ +/* $OpenBSD: dir.c,v 1.34 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: dir.c,v 1.20 1996/09/27 22:45:11 christos Exp $ */ /* @@ -52,10 +52,6 @@ struct dirtemplate dirhead = { 0, 12, DT_DIR, 1, ".", 0, DIRBLKSIZ - 12, DT_DIR, 2, ".." }; -struct odirtemplate odirhead = { - 0, 12, 1, ".", - 0, DIRBLKSIZ - 12, 2, ".." -}; static int expanddir(union dinode *, char *); static void freedir(ino_t, ino_t); @@ -210,7 +206,7 @@ dircheck(struct inodesc *idesc, struct direct *dp) return (0); if (dp->d_ino == 0) return (1); - size = DIRSIZ(0, dp); + size = DIRSIZ(dp); namlen = dp->d_namlen; type = dp->d_type; if (dp->d_reclen < size || @@ -292,9 +288,9 @@ mkentry(struct inodesc *idesc) int newlen, oldlen; newent.d_namlen = strlen(idesc->id_name); - newlen = DIRSIZ(0, &newent); + newlen = DIRSIZ(&newent); if (dirp->d_ino != 0) - oldlen = DIRSIZ(0, dirp); + oldlen = DIRSIZ(dirp); else oldlen = 0; if (dirp->d_reclen - oldlen < newlen) diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c index a1c583e4657..ebda1d4a10d 100644 --- a/sbin/fsck_ffs/inode.c +++ b/sbin/fsck_ffs/inode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inode.c,v 1.50 2020/07/13 06:52:53 otto Exp $ */ +/* $OpenBSD: inode.c,v 1.51 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: inode.c,v 1.23 1996/10/11 20:15:47 thorpej Exp $ */ /* @@ -71,8 +71,7 @@ ckinode(union dinode *dp, struct inodesc *idesc) idesc->id_filesize = DIP(dp, di_size); mode = DIP(dp, di_mode) & IFMT; if (mode == IFBLK || mode == IFCHR || (mode == IFLNK && - (DIP(dp, di_size) < sblock.fs_maxsymlinklen || - (sblock.fs_maxsymlinklen == 0 && DIP(dp, di_blocks) == 0)))) + DIP(dp, di_size) < sblock.fs_maxsymlinklen)) return (KEEPON); if (sblock.fs_magic == FS_UFS1_MAGIC) dino.dp1 = dp->dp1; diff --git a/sbin/fsck_ffs/pass1.c b/sbin/fsck_ffs/pass1.c index 7da7087be71..edeb370c713 100644 --- a/sbin/fsck_ffs/pass1.c +++ b/sbin/fsck_ffs/pass1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pass1.c,v 1.47 2020/07/13 06:52:53 otto Exp $ */ +/* $OpenBSD: pass1.c,v 1.48 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: pass1.c,v 1.16 1996/09/27 22:45:15 christos Exp $ */ /* @@ -266,8 +266,7 @@ checkinode(ino_t inumber, struct inodesc *idesc) * Fake ndb value so direct/indirect block checks below * will detect any garbage after symlink string. */ - if (DIP(dp, di_size) < sblock.fs_maxsymlinklen || - (sblock.fs_maxsymlinklen == 0 && DIP(dp, di_blocks) == 0)) { + if (DIP(dp, di_size) < sblock.fs_maxsymlinklen) { if (sblock.fs_magic == FS_UFS1_MAGIC) ndb = howmany(DIP(dp, di_size), sizeof(int32_t)); diff --git a/sbin/fsck_ffs/pass2.c b/sbin/fsck_ffs/pass2.c index 0d244c957a0..c048ba86f3b 100644 --- a/sbin/fsck_ffs/pass2.c +++ b/sbin/fsck_ffs/pass2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pass2.c,v 1.37 2015/01/20 18:22:21 deraadt Exp $ */ +/* $OpenBSD: pass2.c,v 1.38 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: pass2.c,v 1.17 1996/09/27 22:45:15 christos Exp $ */ /* @@ -283,7 +283,7 @@ pass2check(struct inodesc *idesc) proto.d_type = DT_DIR; proto.d_namlen = 1; (void)strlcpy(proto.d_name, ".", sizeof proto.d_name); - entrysize = DIRSIZ(0, &proto); + entrysize = DIRSIZ(&proto); if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") != 0) { pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n", dirp->d_name); @@ -314,9 +314,9 @@ chk1: proto.d_type = DT_DIR; proto.d_namlen = 2; (void)strlcpy(proto.d_name, "..", sizeof proto.d_name); - entrysize = DIRSIZ(0, &proto); + entrysize = DIRSIZ(&proto); if (idesc->id_entryno == 0) { - n = DIRSIZ(0, dirp); + n = DIRSIZ(dirp); if (dirp->d_reclen < n + entrysize) goto chk2; proto.d_reclen = dirp->d_reclen - n; diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c index 2699dd9ae1a..4cd9f65e464 100644 --- a/sbin/fsdb/fsdb.c +++ b/sbin/fsdb/fsdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fsdb.c,v 1.35 2022/07/22 09:04:44 jsg Exp $ */ +/* $OpenBSD: fsdb.c,v 1.36 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: fsdb.c,v 1.7 1997/01/11 06:50:53 lukem Exp $ */ /*- @@ -601,7 +601,7 @@ chnamefunc(struct inodesc *idesc) if (slotcount++ == desired) { /* will name fit? */ testdir.d_namlen = strlen(idesc->id_name); - if (DIRSIZ(NEWDIRFMT, &testdir) <= dirp->d_reclen) { + if (DIRSIZ(&testdir) <= dirp->d_reclen) { dirp->d_namlen = testdir.d_namlen; strlcpy(dirp->d_name, idesc->id_name, sizeof dirp->d_name); return STOP|ALTERED|FOUND; diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index 266ab9538ee..321b83c8557 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkfs.c,v 1.101 2020/06/20 07:49:04 otto Exp $ */ +/* $OpenBSD: mkfs.c,v 1.102 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: mkfs.c,v 1.25 1995/06/18 21:35:38 cgd Exp $ */ /* @@ -279,13 +279,8 @@ mkfs(struct partition *pp, char *fsys, int fi, int fo, mode_t mfsmode, sblock.fs_sblockloc = SBLOCK_UFS1; sblock.fs_nindir = sblock.fs_bsize / sizeof(int32_t); sblock.fs_inopb = sblock.fs_bsize / sizeof(struct ufs1_dinode); - if (Oflag == 0) { - sblock.fs_maxsymlinklen = 0; - sblock.fs_inodefmt = FS_42INODEFMT; - } else { - sblock.fs_maxsymlinklen = MAXSYMLINKLEN_UFS1; - sblock.fs_inodefmt = FS_44INODEFMT; - } + sblock.fs_maxsymlinklen = MAXSYMLINKLEN_UFS1; + sblock.fs_inodefmt = FS_44INODEFMT; sblock.fs_cgoffset = 0; sblock.fs_cgmask = 0xffffffff; sblock.fs_ffs1_size = sblock.fs_size; @@ -778,15 +773,6 @@ struct direct root_dir[] = { { ROOTINO, sizeof(struct direct), DT_DIR, 1, "." }, { ROOTINO, sizeof(struct direct), DT_DIR, 2, ".." }, }; -struct odirect { - u_int32_t d_ino; - u_int16_t d_reclen; - u_int16_t d_namlen; - u_char d_name[MAXNAMLEN + 1]; -} oroot_dir[] = { - { ROOTINO, sizeof(struct direct), 1, "." }, - { ROOTINO, sizeof(struct direct), 2, ".." }, -}; int fsinit1(time_t utime, mode_t mfsmode, uid_t mfsuid, gid_t mfsgid) @@ -814,11 +800,7 @@ fsinit1(time_t utime, mode_t mfsmode, uid_t mfsuid, gid_t mfsgid) node.dp1.di_gid = getegid(); } node.dp1.di_nlink = PREDEFDIR; - if (Oflag == 0) - node.dp1.di_size = makedir((struct direct *)oroot_dir, - PREDEFDIR); - else - node.dp1.di_size = makedir(root_dir, PREDEFDIR); + node.dp1.di_size = makedir(root_dir, PREDEFDIR); node.dp1.di_db[0] = alloc(sblock.fs_fsize, node.dp1.di_mode); if (node.dp1.di_db[0] == 0) return (1); @@ -919,13 +901,13 @@ makedir(struct direct *protodir, int entries) spcleft = DIRBLKSIZ; for (cp = iobuf, i = 0; i < entries - 1; i++) { - protodir[i].d_reclen = DIRSIZ(0, &protodir[i]); + protodir[i].d_reclen = DIRSIZ(&protodir[i]); memcpy(cp, &protodir[i], protodir[i].d_reclen); cp += protodir[i].d_reclen; spcleft -= protodir[i].d_reclen; } protodir[i].d_reclen = spcleft; - memcpy(cp, &protodir[i], DIRSIZ(0, &protodir[i])); + memcpy(cp, &protodir[i], DIRSIZ(&protodir[i])); return (DIRBLKSIZ); } diff --git a/sbin/newfs/newfs.8 b/sbin/newfs/newfs.8 index 2bf932ea0cb..2c509f205bd 100644 --- a/sbin/newfs/newfs.8 +++ b/sbin/newfs/newfs.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: newfs.8,v 1.79 2022/11/19 08:02:11 sthen Exp $ +.\" $OpenBSD: newfs.8,v 1.80 2024/01/09 03:16:00 guenther Exp $ .\" $NetBSD: newfs.8,v 1.12 1995/03/18 14:58:41 cgd Exp $ .\" .\" Copyright (c) 1983, 1987, 1991, 1993, 1994 @@ -30,7 +30,7 @@ .\" .\" @(#)newfs.8 8.3 (Berkeley) 3/27/94 .\" -.Dd $Mdocdate: November 19 2022 $ +.Dd $Mdocdate: January 9 2024 $ .Dt NEWFS 8 .Os .Sh NAME @@ -186,11 +186,6 @@ without really creating the file system. Select the filesystem format: .Pp .Bl -tag -width 3n -offset indent -compact -.It 0 -.Bx 4.3 -format file system. -This option is primarily used to build root file systems that can -be understood by older boot ROMs. .It 1 Fast File System (FFS), the default for .Nm mount_mfs . diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c index 7ab691d78f0..4e07e6d790e 100644 --- a/sbin/newfs/newfs.c +++ b/sbin/newfs/newfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: newfs.c,v 1.117 2022/12/04 23:50:47 cheloha Exp $ */ +/* $OpenBSD: newfs.c,v 1.118 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: newfs.c,v 1.20 1996/05/16 07:13:03 thorpej Exp $ */ /* @@ -121,7 +121,7 @@ u_short dkcksum(struct disklabel *); int mfs; /* run as the memory based filesystem */ int Nflag; /* run without writing file system */ -int Oflag = 2; /* 0 = 4.3BSD ffs, 1 = 4.4BSD ffs, 2 = ffs2 */ +int Oflag = 2; /* 1 = 4.4BSD ffs, 2 = ffs2 */ daddr_t fssize; /* file system size in 512-byte blocks */ long long sectorsize; /* bytes/sector */ int fsize = 0; /* fragment size */ @@ -211,7 +211,7 @@ main(int argc, char *argv[]) Nflag = 1; break; case 'O': - Oflag = strtonum(optarg, 0, 2, &errstr); + Oflag = strtonum(optarg, 1, 2, &errstr); if (errstr) fatal("%s: invalid ffs version", optarg); oflagset = 1; diff --git a/sbin/restore/dirs.c b/sbin/restore/dirs.c index 1a25e7342c1..baebb2c49bc 100644 --- a/sbin/restore/dirs.c +++ b/sbin/restore/dirs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dirs.c,v 1.42 2019/06/28 13:32:46 deraadt Exp $ */ +/* $OpenBSD: dirs.c,v 1.43 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: dirs.c,v 1.26 1997/07/01 05:37:49 lukem Exp $ */ /* @@ -175,7 +175,7 @@ extractdirs(int genmode) nulldir.d_namlen = 1; nulldir.d_name[0] = '/'; nulldir.d_name[1] = '\0'; - nulldir.d_reclen = DIRSIZ(0, &nulldir); + nulldir.d_reclen = DIRSIZ(&nulldir); for (;;) { curfile.name = ""; curfile.action = USING; @@ -364,17 +364,17 @@ putdir(char *buf, size_t size) i = DIRBLKSIZ - (loc & (DIRBLKSIZ - 1)); if ((dp->d_reclen & 0x3) != 0 || dp->d_reclen > i || - dp->d_reclen < DIRSIZ(0, dp) || + dp->d_reclen < DIRSIZ(dp) || dp->d_namlen > NAME_MAX) { Vprintf(stdout, "Mangled directory: "); if ((dp->d_reclen & 0x3) != 0) Vprintf(stdout, "reclen not multiple of 4 "); - if (dp->d_reclen < DIRSIZ(0, dp)) + if (dp->d_reclen < DIRSIZ(dp)) Vprintf(stdout, "reclen less than DIRSIZ (%u < %u) ", (unsigned)dp->d_reclen, - (unsigned)DIRSIZ(0, dp)); + (unsigned)DIRSIZ(dp)); if (dp->d_namlen > NAME_MAX) Vprintf(stdout, "reclen name too big (%u > %u) ", @@ -404,7 +404,7 @@ long prev = 0; static void putent(struct direct *dp) { - dp->d_reclen = DIRSIZ(0, dp); + dp->d_reclen = DIRSIZ(dp); if (dirloc + dp->d_reclen > DIRBLKSIZ) { ((struct direct *)(dirbuf + prev))->d_reclen = DIRBLKSIZ - prev; @@ -440,7 +440,7 @@ dcvt(struct odirect *odp, struct direct *ndp) ndp->d_type = DT_UNKNOWN; (void)strncpy(ndp->d_name, odp->d_name, ODIRSIZ); ndp->d_namlen = strlen(ndp->d_name); - ndp->d_reclen = DIRSIZ(0, ndp); + ndp->d_reclen = DIRSIZ(ndp); } /* diff --git a/sys/ufs/ext2fs/ext2fs_dir.h b/sys/ufs/ext2fs/ext2fs_dir.h index a45cca86bd8..bb1b8ece4b8 100644 --- a/sys/ufs/ext2fs/ext2fs_dir.h +++ b/sys/ufs/ext2fs/ext2fs_dir.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ext2fs_dir.h,v 1.11 2014/07/11 07:59:04 pelikan Exp $ */ +/* $OpenBSD: ext2fs_dir.h,v 1.12 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: ext2fs_dir.h,v 1.4 2000/01/28 16:00:23 bouyer Exp $ */ /* @@ -61,9 +61,9 @@ * with null bytes. All names are guaranteed null terminated. * The maximum length of a name in a directory is EXT2FS_MAXNAMLEN. * - * The macro EXT2FS_DIRSIZ(fmt, dp) gives the amount of space required to + * The macro EXT2FS_DIRSIZ(dp) gives the amount of space required to * represent a directory entry. Free space in a directory is represented by - * entries which have dp->e2d_reclen > DIRSIZ(fmt, dp). All d2fs_bsize bytes + * entries which have dp->e2d_reclen > DIRSIZ(dp). All d2fs_bsize bytes * in a directory block are claimed by the directory entries. This * usually results in the last entry in a directory having a large * dp->e2d_reclen. When entries are deleted from a directory, the diff --git a/sys/ufs/ffs/ffs_inode.c b/sys/ufs/ffs/ffs_inode.c index 4ef913f4450..79f7c188dbe 100644 --- a/sys/ufs/ffs/ffs_inode.c +++ b/sys/ufs/ffs/ffs_inode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_inode.c,v 1.81 2021/12/12 09:14:59 visa Exp $ */ +/* $OpenBSD: ffs_inode.c,v 1.82 2024/01/09 03:15:59 guenther Exp $ */ /* $NetBSD: ffs_inode.c,v 1.10 1996/05/11 18:27:19 mycroft Exp $ */ /* @@ -152,9 +152,7 @@ ffs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred) return (0); if (ovp->v_type == VLNK && - (DIP(oip, size) < oip->i_ump->um_maxsymlinklen || - (oip->i_ump->um_maxsymlinklen == 0 && - oip->i_din1->di_blocks == 0))) { + DIP(oip, size) < oip->i_ump->um_maxsymlinklen) { #ifdef DIAGNOSTIC if (length != 0) panic("ffs_truncate: partial truncate of symlink"); diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index 8c780d5340b..941a5cbd4e0 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_vfsops.c,v 1.195 2023/07/05 15:13:28 beck Exp $ */ +/* $OpenBSD: ffs_vfsops.c,v 1.196 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: ffs_vfsops.c,v 1.19 1996/02/09 22:22:26 christos Exp $ */ /* @@ -675,8 +675,8 @@ ffs_validate(struct fs *fsp) return (0); /* Invalid number of fragments */ if (fsp->fs_inodefmt == FS_42INODEFMT) - fsp->fs_maxsymlinklen = 0; - else if (fsp->fs_maxsymlinklen < 0) + return (0); /* Obsolete format, support broken in 2014 */ + if (fsp->fs_maxsymlinklen <= 0) return (0); /* Invalid max size of short symlink */ return (1); /* Super block is okay */ diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c index 668586b9fbf..24066cd54c5 100644 --- a/sys/ufs/ffs/ffs_vnops.c +++ b/sys/ufs/ffs/ffs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_vnops.c,v 1.100 2022/06/26 05:20:43 visa Exp $ */ +/* $OpenBSD: ffs_vnops.c,v 1.101 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: ffs_vnops.c,v 1.7 1996/05/11 18:27:24 mycroft Exp $ */ /* @@ -202,8 +202,7 @@ ffs_read(void *v) panic("ffs_read: mode"); if (vp->v_type == VLNK) { - if (DIP(ip, size) < ip->i_ump->um_maxsymlinklen || - (ip->i_ump->um_maxsymlinklen == 0 && DIP(ip, blocks) == 0)) + if (DIP(ip, size) < ip->i_ump->um_maxsymlinklen) panic("ffs_read: short symlink"); } else if (vp->v_type != VREG && vp->v_type != VDIR) panic("ffs_read: type %d", vp->v_type); diff --git a/sys/ufs/ufs/dir.h b/sys/ufs/ufs/dir.h index d9d94e7e17f..3f5b39e1289 100644 --- a/sys/ufs/ufs/dir.h +++ b/sys/ufs/ufs/dir.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dir.h,v 1.12 2019/05/04 15:38:12 deraadt Exp $ */ +/* $OpenBSD: dir.h,v 1.13 2024/01/09 03:15:59 guenther Exp $ */ /* $NetBSD: dir.h,v 1.8 1996/03/09 19:42:41 scottr Exp $ */ /* @@ -61,9 +61,9 @@ * with null bytes. All names are guaranteed null terminated. * The maximum length of a name in a directory is MAXNAMLEN. * - * The macro DIRSIZ(fmt, dp) gives the amount of space required to represent + * The macro DIRSIZ(dp) gives the amount of space required to represent * a directory entry. Free space in a directory is represented by - * entries which have dp->d_reclen > DIRSIZ(fmt, dp). All DIRBLKSIZ bytes + * entries which have dp->d_reclen > DIRSIZ(dp). All DIRBLKSIZ bytes * in a directory block are claimed by the directory entries. This * usually results in the last entry in a directory having a large * dp->d_reclen. When entries are deleted from a directory, the @@ -112,17 +112,8 @@ struct direct { #define DIRECTSIZ(namlen) \ ((offsetof(struct direct, d_name) + \ ((namlen)+1)*sizeof(((struct direct *)0)->d_name[0]) + 3) & ~3) -#if (BYTE_ORDER == LITTLE_ENDIAN) -#define DIRSIZ(oldfmt, dp) \ - ((oldfmt) ? \ - ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_type+1 + 3) &~ 3)) : \ - ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))) -#else -#define DIRSIZ(oldfmt, dp) \ +#define DIRSIZ(dp) \ ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) -#endif -#define OLDDIRFMT 1 -#define NEWDIRFMT 0 /* * Template for manipulating directories. Should use struct direct's, @@ -140,18 +131,4 @@ struct dirtemplate { u_int8_t dotdot_namlen; char dotdot_name[4]; /* ditto */ }; - -/* - * This is the old format of directories, sanz type element. - */ -struct odirtemplate { - u_int32_t dot_ino; - int16_t dot_reclen; - u_int16_t dot_namlen; - char dot_name[4]; /* must be multiple of 4 */ - u_int32_t dotdot_ino; - int16_t dotdot_reclen; - u_int16_t dotdot_namlen; - char dotdot_name[4]; /* ditto */ -}; #endif /* !_DIR_H_ */ diff --git a/sys/ufs/ufs/ufs_dirhash.c b/sys/ufs/ufs/ufs_dirhash.c index 664e61fe0d5..81c27c14f7a 100644 --- a/sys/ufs/ufs/ufs_dirhash.c +++ b/sys/ufs/ufs/ufs_dirhash.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufs_dirhash.c,v 1.42 2019/03/15 05:42:38 kevlo Exp $ */ +/* $OpenBSD: ufs_dirhash.c,v 1.43 2024/01/09 03:15:59 guenther Exp $ */ /* * Copyright (c) 2001, 2002 Ian Dowse. All rights reserved. * @@ -50,7 +50,6 @@ #define WRAPINCR(val, limit) (((val) + 1 == (limit)) ? 0 : ((val) + 1)) #define WRAPDECR(val, limit) (((val) == 0) ? ((limit) - 1) : ((val) - 1)) -#define OFSFMT(ip) ((ip)->i_ump->um_maxsymlinklen == 0) #define BLKFREE2IDX(n) ((n) > DH_NFSTATS ? DH_NFSTATS : (n)) int ufs_mindirhashsize; @@ -112,7 +111,7 @@ ufsdirhash_build(struct inode *ip) /* Check if we can/should use dirhash. */ if (ip->i_dirhash == NULL) { - if (DIP(ip, size) < ufs_mindirhashsize || OFSFMT(ip)) + if (DIP(ip, size) < ufs_mindirhashsize) return (-1); } else { /* Hash exists, but sysctls could have changed. */ @@ -224,7 +223,7 @@ ufsdirhash_build(struct inode *ip) slot = WRAPINCR(slot, dh->dh_hlen); dh->dh_hused++; DH_ENTRY(dh, slot) = pos; - ufsdirhash_adjfree(dh, pos, -DIRSIZ(0, ep)); + ufsdirhash_adjfree(dh, pos, -DIRSIZ(ep)); } pos += ep->d_reclen; } @@ -430,7 +429,7 @@ restart: /* Check for sequential access, and update offset. */ if (dh->dh_seqopt == 0 && dh->dh_seqoff == offset) dh->dh_seqopt = 1; - dh->dh_seqoff = offset + DIRSIZ(0, dp); + dh->dh_seqoff = offset + DIRSIZ(dp); *bpp = bp; *offp = offset; @@ -519,7 +518,7 @@ ufsdirhash_findfree(struct inode *ip, int slotneeded, int *slotsize) brelse(bp); return (-1); } - if (dp->d_ino == 0 || dp->d_reclen > DIRSIZ(0, dp)) + if (dp->d_ino == 0 || dp->d_reclen > DIRSIZ(dp)) break; i += dp->d_reclen; dp = (struct direct *)((char *)dp + dp->d_reclen); @@ -535,7 +534,7 @@ ufsdirhash_findfree(struct inode *ip, int slotneeded, int *slotsize) while (i < DIRBLKSIZ && freebytes < slotneeded) { freebytes += dp->d_reclen; if (dp->d_ino != 0) - freebytes -= DIRSIZ(0, dp); + freebytes -= DIRSIZ(dp); if (dp->d_reclen == 0) { brelse(bp); return (-1); @@ -627,7 +626,7 @@ ufsdirhash_add(struct inode *ip, struct direct *dirp, doff_t offset) DH_ENTRY(dh, slot) = offset; /* Update the per-block summary info. */ - ufsdirhash_adjfree(dh, offset, -DIRSIZ(0, dirp)); + ufsdirhash_adjfree(dh, offset, -DIRSIZ(dirp)); DIRHASH_UNLOCK(dh); } @@ -660,7 +659,7 @@ ufsdirhash_remove(struct inode *ip, struct direct *dirp, doff_t offset) ufsdirhash_delslot(dh, slot); /* Update the per-block summary info. */ - ufsdirhash_adjfree(dh, offset, DIRSIZ(0, dirp)); + ufsdirhash_adjfree(dh, offset, DIRSIZ(dirp)); DIRHASH_UNLOCK(dh); } @@ -835,7 +834,7 @@ ufsdirhash_checkblock(struct inode *ip, char *buf, doff_t offset) /* Check that the entry exists (will panic if it doesn't). */ ufsdirhash_findslot(dh, dp->d_name, dp->d_namlen, offset + i); - nfree += dp->d_reclen - DIRSIZ(0, dp); + nfree += dp->d_reclen - DIRSIZ(dp); } if (i != DIRBLKSIZ) panic("ufsdirhash_checkblock: bad dir end"); diff --git a/sys/ufs/ufs/ufs_lookup.c b/sys/ufs/ufs/ufs_lookup.c index 3cf88f30152..a2816f6694d 100644 --- a/sys/ufs/ufs/ufs_lookup.c +++ b/sys/ufs/ufs/ufs_lookup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufs_lookup.c,v 1.59 2022/01/11 03:13:59 jsg Exp $ */ +/* $OpenBSD: ufs_lookup.c,v 1.60 2024/01/09 03:15:59 guenther Exp $ */ /* $NetBSD: ufs_lookup.c,v 1.7 1996/02/09 22:36:06 christos Exp $ */ /* @@ -64,8 +64,6 @@ int dirchk = 1; int dirchk = 0; #endif -#define OFSFMT(ip) ((ip)->i_ump->um_maxsymlinklen == 0) - /* * Convert a component of a pathname into a pointer to a locked inode. * This is a very central and rather complicated routine. @@ -299,7 +297,7 @@ searchloop: int size = ep->d_reclen; if (ep->d_ino != 0) - size -= DIRSIZ(OFSFMT(dp), ep); + size -= DIRSIZ(ep); if (size > 0) { if (size >= slotneeded) { slotstatus = FOUND; @@ -322,14 +320,7 @@ searchloop: * Check for a name match. */ if (ep->d_ino) { -# if (BYTE_ORDER == LITTLE_ENDIAN) - if (OFSFMT(dp)) - namlen = ep->d_type; - else - namlen = ep->d_namlen; -# else - namlen = ep->d_namlen; -# endif + namlen = ep->d_namlen; if (namlen == cnp->cn_namelen && !memcmp(cnp->cn_nameptr, ep->d_name, namlen)) { #ifdef UFS_DIRHASH @@ -440,9 +431,9 @@ found: * Check that directory length properly reflects presence * of this entry. */ - if (dp->i_offset + DIRSIZ(OFSFMT(dp), ep) > DIP(dp, size)) { + if (dp->i_offset + DIRSIZ(ep) > DIP(dp, size)) { ufs_dirbad(dp, dp->i_offset, "i_ffs_size too small"); - DIP_ASSIGN(dp, size, dp->i_offset + DIRSIZ(OFSFMT(dp), ep)); + DIP_ASSIGN(dp, size, dp->i_offset + DIRSIZ(ep)); dp->i_flag |= IN_CHANGE | IN_UPDATE; } brelse(bp); @@ -626,17 +617,10 @@ ufs_dirbadentry(struct vnode *vdp, struct direct *ep, int entryoffsetinblock) dp = VTOI(vdp); -# if (BYTE_ORDER == LITTLE_ENDIAN) - if (OFSFMT(dp)) - namlen = ep->d_type; - else - namlen = ep->d_namlen; -# else - namlen = ep->d_namlen; -# endif + namlen = ep->d_namlen; if ((ep->d_reclen & 0x3) != 0 || ep->d_reclen > DIRBLKSIZ - (entryoffsetinblock & (DIRBLKSIZ - 1)) || - ep->d_reclen < DIRSIZ(OFSFMT(dp), ep) || namlen > MAXNAMLEN) { + ep->d_reclen < DIRSIZ(ep) || namlen > MAXNAMLEN) { /*return (1); */ printf("First bad\n"); goto bad; @@ -674,15 +658,7 @@ ufs_makedirentry(struct inode *ip, struct componentname *cnp, memset(newdirp->d_name + (cnp->cn_namelen & ~(DIR_ROUNDUP-1)), 0, DIR_ROUNDUP); memcpy(newdirp->d_name, cnp->cn_nameptr, cnp->cn_namelen); - if (OFSFMT(ip)) { - newdirp->d_type = 0; -# if (BYTE_ORDER == LITTLE_ENDIAN) - { u_char tmp = newdirp->d_namlen; - newdirp->d_namlen = newdirp->d_type; - newdirp->d_type = tmp; } -# endif - } else - newdirp->d_type = IFTODT(DIP(ip, mode)); + newdirp->d_type = IFTODT(DIP(ip, mode)); } /* @@ -712,7 +688,7 @@ ufs_direnter(struct vnode *dvp, struct vnode *tvp, struct direct *dirp, cr = cnp->cn_cred; p = cnp->cn_proc; dp = VTOI(dvp); - newentrysize = DIRSIZ(OFSFMT(dp), dirp); + newentrysize = DIRSIZ(dirp); if (dp->i_count == 0) { /* @@ -827,7 +803,7 @@ ufs_direnter(struct vnode *dvp, struct vnode *tvp, struct direct *dirp, * dp->i_offset + dp->i_count would yield the space. */ ep = (struct direct *)dirbuf; - dsize = ep->d_ino ? DIRSIZ(OFSFMT(dp), ep) : 0; + dsize = ep->d_ino ? DIRSIZ(ep) : 0; spacefree = ep->d_reclen - dsize; for (loc = ep->d_reclen; loc < dp->i_count; ) { nep = (struct direct *)(dirbuf + loc); @@ -852,7 +828,7 @@ ufs_direnter(struct vnode *dvp, struct vnode *tvp, struct direct *dirp, dsize = 0; continue; } - dsize = DIRSIZ(OFSFMT(dp), nep); + dsize = DIRSIZ(nep); spacefree += nep->d_reclen - dsize; #ifdef UFS_DIRHASH if (dp->i_dirhash != NULL) @@ -1030,8 +1006,7 @@ ufs_dirrewrite(struct inode *dp, struct inode *oip, ufsino_t newinum, if (error) return (error); ep->d_ino = newinum; - if (!OFSFMT(dp)) - ep->d_type = newtype; + ep->d_type = newtype; oip->i_effnlink--; if (DOINGSOFTDEP(vdp)) { softdep_change_linkcnt(oip, 0); @@ -1087,14 +1062,7 @@ ufs_dirempty(struct inode *ip, ufsino_t parentino, struct ucred *cred) if (dp->d_ino == 0) continue; /* accept only "." and ".." */ -# if (BYTE_ORDER == LITTLE_ENDIAN) - if (OFSFMT(ip)) - namlen = dp->d_type; - else - namlen = dp->d_namlen; -# else - namlen = dp->d_namlen; -# endif + namlen = dp->d_namlen; if (namlen > 2) return (0); if (dp->d_name[0] != '.') @@ -1145,14 +1113,7 @@ ufs_checkpath(struct inode *source, struct inode *target, struct ucred *cred) IO_NODELOCKED, cred, NULL, curproc); if (error != 0) break; -# if (BYTE_ORDER == LITTLE_ENDIAN) - if (OFSFMT(VTOI(vp))) - namlen = dirbuf.dotdot_type; - else - namlen = dirbuf.dotdot_namlen; -# else - namlen = dirbuf.dotdot_namlen; -# endif + namlen = dirbuf.dotdot_namlen; if (namlen != 2 || dirbuf.dotdot_name[0] != '.' || dirbuf.dotdot_name[1] != '.') { diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c index 6276475cda8..67cfb12405e 100644 --- a/sys/ufs/ufs/ufs_vnops.c +++ b/sys/ufs/ufs/ufs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufs_vnops.c,v 1.158 2023/09/08 20:00:28 mvs Exp $ */ +/* $OpenBSD: ufs_vnops.c,v 1.159 2024/01/09 03:15:59 guenther Exp $ */ /* $NetBSD: ufs_vnops.c,v 1.18 1996/05/11 18:28:04 mycroft Exp $ */ /* @@ -81,14 +81,10 @@ void filt_ufsdetach(struct knote *); /* * A virgin directory (no blushing please). */ -static struct dirtemplate mastertemplate = { +static const struct dirtemplate mastertemplate = { 0, 12, DT_DIR, 1, ".", 0, DIRBLKSIZ - 12, DT_DIR, 2, ".." }; -static struct odirtemplate omastertemplate = { - 0, 12, 1, ".", - 0, DIRBLKSIZ - 12, 2, ".." -}; /* * Update the times in the inode @@ -1127,7 +1123,7 @@ ufs_mkdir(void *v) struct vnode *tvp; struct buf *bp; struct direct newdir; - struct dirtemplate dirtemplate, *dtp; + struct dirtemplate dirtemplate; int error, dmode, blkoff; #ifdef DIAGNOSTIC @@ -1187,11 +1183,7 @@ ufs_mkdir(void *v) /* * Initialize directory with "." and ".." from static template. */ - if (dp->i_ump->um_maxsymlinklen > 0) - dtp = &mastertemplate; - else - dtp = (struct dirtemplate *)&omastertemplate; - dirtemplate = *dtp; + dirtemplate = mastertemplate; dirtemplate.dot_ino = ip->i_number; dirtemplate.dotdot_ino = dp->i_number; @@ -1411,9 +1403,6 @@ ufs_readdir(void *v) caddr_t diskbuf; size_t count, entries; int bufsize, readcnt, error; -#if (BYTE_ORDER == LITTLE_ENDIAN) - int ofmt = VTOI(ap->a_vp)->i_ump->um_maxsymlinklen == 0; -#endif if (uio->uio_rw != UIO_READ) return (EINVAL); @@ -1468,16 +1457,8 @@ ufs_readdir(void *v) off += dp->d_reclen; u.dn.d_off = off; u.dn.d_fileno = dp->d_ino; -#if (BYTE_ORDER == LITTLE_ENDIAN) - if (ofmt) { - u.dn.d_type = dp->d_namlen; - u.dn.d_namlen = dp->d_type; - } else -#endif - { - u.dn.d_type = dp->d_type; - u.dn.d_namlen = dp->d_namlen; - } + u.dn.d_type = dp->d_type; + u.dn.d_namlen = dp->d_namlen; memcpy(u.dn.d_name, dp->d_name, u.dn.d_namlen); memset(u.dn.d_name + u.dn.d_namlen, 0, u.dn.d_reclen - u.dn.d_namlen - offsetof(struct dirent, d_name)); @@ -1513,10 +1494,8 @@ ufs_readlink(void *v) u_int64_t isize; isize = DIP(ip, size); - if (isize < ip->i_ump->um_maxsymlinklen || - (ip->i_ump->um_maxsymlinklen == 0 && DIP(ip, blocks) == 0)) { + if (isize < ip->i_ump->um_maxsymlinklen) return (uiomove((char *)SHORTLINK(ip), isize, ap->a_uio)); - } return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred)); } diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c index fe203a40f21..b055c62a598 100644 --- a/usr.sbin/makefs/ffs.c +++ b/usr.sbin/makefs/ffs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs.c,v 1.38 2023/08/08 04:45:44 guenther Exp $ */ +/* $OpenBSD: ffs.c,v 1.39 2024/01/09 03:16:00 guenther Exp $ */ /* $NetBSD: ffs.c,v 1.66 2015/12/21 00:58:08 christos Exp $ */ /* @@ -550,9 +550,9 @@ ffs_size_dir(fsnode *root, fsinfo_t *fsopts) #define ADDDIRENT(e) do { \ tmpdir.d_namlen = strlen((e)); \ - this = DIRSIZ(NEWDIRFMT, &tmpdir); \ - if (this + curdirsize > roundup(curdirsize, DIRBLKSIZ)) \ - curdirsize = roundup(curdirsize, DIRBLKSIZ); \ + this = DIRSIZ(&tmpdir); \ + if (this + curdirsize > roundup(curdirsize, DIRBLKSIZ)) \ + curdirsize = roundup(curdirsize, DIRBLKSIZ); \ curdirsize += this; \ } while (0); @@ -887,12 +887,12 @@ ffs_make_dirbuf(dirbuf_t *dbuf, const char *name, fsnode *node) de.d_type = IFTODT(node->type); de.d_namlen = (uint8_t)strlen(name); strlcpy(de.d_name, name, sizeof de.d_name); - de.d_reclen = DIRSIZ(NEWDIRFMT, &de); + de.d_reclen = DIRSIZ(&de); dp = (struct direct *)(dbuf->buf + dbuf->cur); llen = 0; if (dp != NULL) - llen = DIRSIZ(NEWDIRFMT, dp); + llen = DIRSIZ(dp); if (de.d_reclen + dbuf->cur + llen > roundup(dbuf->size, DIRBLKSIZ)) { newbuf = erealloc(dbuf->buf, dbuf->size + DIRBLKSIZ); -- 2.20.1