git: aa90fbed151d - main - Standardize the definition of a UFS dinode.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 28 Jan 2025 01:41:15 UTC
The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=aa90fbed151de512ab6e59f75df009533a15751f commit aa90fbed151de512ab6e59f75df009533a15751f Author: Kirk McKusick <mckusick@FreeBSD.org> AuthorDate: 2025-01-28 01:39:45 +0000 Commit: Kirk McKusick <mckusick@FreeBSD.org> CommitDate: 2025-01-28 01:39:45 +0000 Standardize the definition of a UFS dinode. Each program that operates on UFS on-disk inodes defines its own version of a dinode. They all (of necessity) define the same layout but use different names. This change adds a definition of a dinode (a union of a UFS1 on-disk inode and a UFS2 on-disk inode) as well as a dinodep (a union of a pointer to a UFS1 on-disk inode and a pointer to a UFS2 on-disk inode) in sys/ufs/ufs/dinode.h. It then deletes the definitions of dinode and dinodep in all the programs that operate on them and instead uses these standard definitions. No functional change intended. MFC-after: 1 week --- lib/libufs/libufs.h | 8 ---- sbin/dump/traverse.c | 4 -- sbin/fsck_ffs/fsck.h | 4 -- sbin/fsck_ffs/inode.c | 12 ++++-- sbin/newfs/mkfs.c | 4 -- sbin/quotacheck/quotacheck.c | 4 -- stand/libsa/ufs.c | 11 ++---- sys/ufs/ufs/dinode.h | 20 ++++++++-- sys/ufs/ufs/inode.h | 9 ++--- usr.sbin/makefs/ffs.c | 22 +++++------ usr.sbin/makefs/ffs/ufs_inode.h | 81 +++++++++++++++++++---------------------- usr.sbin/quot/quot.c | 4 -- 12 files changed, 82 insertions(+), 101 deletions(-) diff --git a/lib/libufs/libufs.h b/lib/libufs/libufs.h index 45ac97f43c06..b91866164e64 100644 --- a/lib/libufs/libufs.h +++ b/lib/libufs/libufs.h @@ -37,14 +37,6 @@ */ #define LIBUFS_BUFALIGN 128 -/* - * libufs structures. - */ -union dinodep { - struct ufs1_dinode *dp1; - struct ufs2_dinode *dp2; -}; - /* * userland ufs disk. */ diff --git a/sbin/dump/traverse.c b/sbin/dump/traverse.c index ccc2d0a625e9..d3bb671644e3 100644 --- a/sbin/dump/traverse.c +++ b/sbin/dump/traverse.c @@ -51,10 +51,6 @@ #include "dump.h" -union dinode { - struct ufs1_dinode dp1; - struct ufs2_dinode dp2; -}; #define DIP(dp, field) \ ((sblock->fs_magic == FS_UFS1_MAGIC) ? \ (dp)->dp1.field : (dp)->dp2.field) diff --git a/sbin/fsck_ffs/fsck.h b/sbin/fsck_ffs/fsck.h index 312142eab9a7..32d1d93e05c8 100644 --- a/sbin/fsck_ffs/fsck.h +++ b/sbin/fsck_ffs/fsck.h @@ -75,10 +75,6 @@ #define INOBUFSIZE 64*1024 /* size of buffer to read inodes in pass1 */ #define ZEROBUFSIZE (dev_bsize * 128) /* size of zero buffer used by -Z */ -union dinode { - struct ufs1_dinode dp1; - struct ufs2_dinode dp2; -}; #define DIP(dp, field) \ ((sblock.fs_magic == FS_UFS1_MAGIC) ? \ (dp)->dp1.field : (dp)->dp2.field) diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c index 5b004cd29c90..dca479f43831 100644 --- a/sbin/fsck_ffs/inode.c +++ b/sbin/fsck_ffs/inode.c @@ -429,6 +429,7 @@ void ginode(ino_t inumber, struct inode *ip) { ufs2_daddr_t iblk; + union dinodep dpp; struct ufs2_dinode *dp; if (inumber < UFS_ROOTINO || inumber >= maxino) @@ -466,11 +467,12 @@ ginode(ino_t inumber, struct inode *ip) if (sblock.fs_magic == FS_UFS1_MAGIC) { ip->i_dp = (union dinode *) &ip->i_bp->b_un.b_dinode1[inumber - ip->i_bp->b_index]; + dpp.dp1 = (struct ufs1_dinode *)ip->i_dp; return; } ip->i_dp = (union dinode *) &ip->i_bp->b_un.b_dinode2[inumber - ip->i_bp->b_index]; - dp = (struct ufs2_dinode *)ip->i_dp; + dpp.dp2 = dp = (struct ufs2_dinode *)ip->i_dp; /* Do not check hash of inodes being created */ if (dp->di_mode != 0 && ffs_verify_dinode_ckhash(&sblock, dp)) { pwarn("INODE CHECK-HASH FAILED"); @@ -520,6 +522,7 @@ getnextinode(ino_t inumber, int rebuiltcg) mode_t mode; ufs2_daddr_t ndb, blk; union dinode *dp; + union dinodep dpp; struct inode ip; static caddr_t nextinop; @@ -550,10 +553,13 @@ getnextinode(ino_t inumber, int rebuiltcg) nextinop = inobuf.b_un.b_buf; } dp = (union dinode *)nextinop; - if (sblock.fs_magic == FS_UFS1_MAGIC) + if (sblock.fs_magic == FS_UFS1_MAGIC) { nextinop += sizeof(struct ufs1_dinode); - else + dpp.dp1 = (struct ufs1_dinode *)dp; + } else { nextinop += sizeof(struct ufs2_dinode); + dpp.dp2 = (struct ufs2_dinode *)dp; + } if ((ckhashadd & CK_INODE) != 0) { ffs_update_dinode_ckhash(&sblock, (struct ufs2_dinode *)dp); dirty(&inobuf); diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index db1fe2991f6d..3715ef58ad0f 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -89,10 +89,6 @@ static struct csum *fscs; #define sblock disk.d_fs #define acg disk.d_cg -union dinode { - struct ufs1_dinode dp1; - struct ufs2_dinode dp2; -}; #define DIP(dp, field) \ ((sblock.fs_magic == FS_UFS1_MAGIC) ? \ (dp)->dp1.field : (dp)->dp2.field) diff --git a/sbin/quotacheck/quotacheck.c b/sbin/quotacheck/quotacheck.c index 1fb4789ae348..1871d2efc25a 100644 --- a/sbin/quotacheck/quotacheck.c +++ b/sbin/quotacheck/quotacheck.c @@ -77,10 +77,6 @@ union { long dev_bsize = 1; ino_t maxino; -union dinode { - struct ufs1_dinode dp1; - struct ufs2_dinode dp2; -}; #define DIP(dp, field) \ ((sblock.fs_magic == FS_UFS1_MAGIC) ? \ (dp)->dp1.field : (dp)->dp2.field) diff --git a/stand/libsa/ufs.c b/stand/libsa/ufs.c index 2c3b3764bd74..e1d540ed2321 100644 --- a/stand/libsa/ufs.c +++ b/stand/libsa/ufs.c @@ -110,10 +110,7 @@ struct fs_ops ufs_fsops = { struct file { off_t f_seekp; /* seek pointer */ struct fs *f_fs; /* pointer to super-block */ - union dinode { - struct ufs1_dinode di1; - struct ufs2_dinode di2; - } f_di; /* copy of on-disk inode */ + union dinode f_dp; /* copy of on-disk inode */ int f_nindir[UFS_NIADDR]; /* number of blocks mapped by indirect block at level i */ @@ -129,7 +126,7 @@ struct file { }; #define DIP(fp, field) \ ((fp)->f_fs->fs_magic == FS_UFS1_MAGIC ? \ - (fp)->f_di.di1.field : (fp)->f_di.di2.field) + (fp)->f_dp.dp1.field : (fp)->f_dp.dp2.field) typedef struct ufs_mnt { char *um_dev; @@ -185,10 +182,10 @@ read_inode(ino_t inumber, struct open_file *f) } if (fp->f_fs->fs_magic == FS_UFS1_MAGIC) - fp->f_di.di1 = ((struct ufs1_dinode *)buf) + fp->f_dp.dp1 = ((struct ufs1_dinode *)buf) [ino_to_fsbo(fs, inumber)]; else - fp->f_di.di2 = ((struct ufs2_dinode *)buf) + fp->f_dp.dp2 = ((struct ufs2_dinode *)buf) [ino_to_fsbo(fs, inumber)]; /* diff --git a/sys/ufs/ufs/dinode.h b/sys/ufs/ufs/dinode.h index 673e6f2555f1..5265326b0b5b 100644 --- a/sys/ufs/ufs/dinode.h +++ b/sys/ufs/ufs/dinode.h @@ -111,12 +111,13 @@ typedef int64_t ufs_time_t; #define IFWHT 0160000 /* Whiteout. */ /* - * A dinode contains all the meta-data associated with a UFS2 file. - * This structure defines the on-disk format of a dinode. Since + * Each UFS filesystem version defines the on-disk format of its dinode. + * + * A UFS2 dinode contains all the meta-data associated with a UFS2 file. + * This structure defines the on-disk format of a UFS2 dinode. Since * this structure describes an on-disk structure, all its fields * are defined by types with precise widths. */ - #define UFS_NXADDR 2 /* External addresses in inode. */ #define UFS_NDADDR 12 /* Direct addresses in inode. */ #define UFS_NIADDR 3 /* Indirect addresses in inode. */ @@ -210,4 +211,17 @@ struct ufs1_dinode { #define UFS_LINK_MAX 65500 /* leave a few spare for special values */ +/* + * These structures hold or reference an on-disk dinode. + */ +union dinode { + struct ufs1_dinode dp1; + struct ufs2_dinode dp2; +}; + +union dinodep { + struct ufs1_dinode *dp1; + struct ufs2_dinode *dp2; +}; + #endif /* _UFS_UFS_DINODE_H_ */ diff --git a/sys/ufs/ufs/inode.h b/sys/ufs/ufs/inode.h index 85d3c4898318..a8a91e67b34a 100644 --- a/sys/ufs/ufs/inode.h +++ b/sys/ufs/ufs/inode.h @@ -88,10 +88,7 @@ struct inode { /* * The real copy of the on-disk inode. */ - union { - struct ufs1_dinode *din1; /* UFS1 on-disk dinode. */ - struct ufs2_dinode *din2; /* UFS2 on-disk dinode. */ - } dinode_u; + union dinodep i_dp; /* On-disk dinode */ ino_t i_number; /* The identity of the inode. */ uint32_t i_flag; /* flags, see below */ @@ -204,8 +201,8 @@ struct inode { #define i_dirhash i_un.dirhash #define i_snapblklist i_un.snapblklist -#define i_din1 dinode_u.din1 -#define i_din2 dinode_u.din2 +#define i_din1 i_dp.dp1 +#define i_din2 i_dp.dp2 #define ITOUMP(ip) ((ip)->i_ump) #define ITODEV(ip) (ITOUMP(ip)->um_dev) diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c index ebfda7f929e4..aa5574c5201f 100644 --- a/usr.sbin/makefs/ffs.c +++ b/usr.sbin/makefs/ffs.c @@ -106,7 +106,7 @@ #undef DIP #define DIP(dp, field) \ ((ffs_opts->version == 1) ? \ - (dp)->ffs1_din.di_##field : (dp)->ffs2_din.di_##field) + (dp)->dp1.di_##field : (dp)->dp2.di_##field) /* * Various file system defaults (cribbed from newfs(8)). @@ -853,10 +853,10 @@ ffs_populate_dir(const char *dir, fsnode *root, fsinfo_t *fsopts) /* build on-disk inode */ if (ffs_opts->version == 1) - membuf = ffs_build_dinode1(&din.ffs1_din, &dirbuf, cur, + membuf = ffs_build_dinode1(&din.dp1, &dirbuf, cur, root, fsopts); else - membuf = ffs_build_dinode2(&din.ffs2_din, &dirbuf, cur, + membuf = ffs_build_dinode2(&din.dp2, &dirbuf, cur, root, fsopts); if (debug & DEBUG_FS_POPULATE_NODE) { @@ -942,11 +942,11 @@ ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts) in.i_number = ino; in.i_size = DIP(din, size); if (ffs_opts->version == 1) - memcpy(&in.i_din.ffs1_din, &din->ffs1_din, - sizeof(in.i_din.ffs1_din)); + memcpy(&in.i_din.dp1, &din->dp1, + sizeof(in.i_din.dp1)); else - memcpy(&in.i_din.ffs2_din, &din->ffs2_din, - sizeof(in.i_din.ffs2_din)); + memcpy(&in.i_din.dp2, &din->dp2, + sizeof(in.i_din.dp2)); if (DIP(din, size) == 0) goto write_inode_and_leave; /* mmm, cheating */ @@ -1176,16 +1176,16 @@ ffs_write_inode(union dinode *dp, uint32_t ino, const fsinfo_t *fsopts) ffs_rdfs(d, fs->fs_bsize, buf, fsopts); if (fsopts->needswap) { if (ffs_opts->version == 1) - ffs_dinode1_swap(&dp->ffs1_din, + ffs_dinode1_swap(&dp->dp1, &dp1[ino_to_fsbo(fs, ino)]); else - ffs_dinode2_swap(&dp->ffs2_din, + ffs_dinode2_swap(&dp->dp2, &dp2[ino_to_fsbo(fs, ino)]); } else { if (ffs_opts->version == 1) - dp1[ino_to_fsbo(fs, ino)] = dp->ffs1_din; + dp1[ino_to_fsbo(fs, ino)] = dp->dp1; else - dp2[ino_to_fsbo(fs, ino)] = dp->ffs2_din; + dp2[ino_to_fsbo(fs, ino)] = dp->dp2; } ffs_wtfs(d, fs->fs_bsize, buf, fsopts); free(buf); diff --git a/usr.sbin/makefs/ffs/ufs_inode.h b/usr.sbin/makefs/ffs/ufs_inode.h index 050392624739..c960caea5c1e 100644 --- a/usr.sbin/makefs/ffs/ufs_inode.h +++ b/usr.sbin/makefs/ffs/ufs_inode.h @@ -37,11 +37,6 @@ * SUCH DAMAGE. */ -union dinode { - struct ufs1_dinode ffs1_din; - struct ufs2_dinode ffs2_din; -}; - struct inode { ino_t i_number; /* The identity of the inode. */ struct vnode *i_devvp; /* vnode pointer (contains fsopts) */ @@ -50,45 +45,45 @@ struct inode { uint64_t i_size; }; -#define i_ffs1_atime i_din.ffs1_din.di_atime -#define i_ffs1_atimensec i_din.ffs1_din.di_atimensec -#define i_ffs1_blocks i_din.ffs1_din.di_blocks -#define i_ffs1_ctime i_din.ffs1_din.di_ctime -#define i_ffs1_ctimensec i_din.ffs1_din.di_ctimensec -#define i_ffs1_db i_din.ffs1_din.di_db -#define i_ffs1_flags i_din.ffs1_din.di_flags -#define i_ffs1_gen i_din.ffs1_din.di_gen -#define i_ffs11_gid i_din.ffs1_din.di_gid -#define i_ffs1_ib i_din.ffs1_din.di_ib -#define i_ffs1_mode i_din.ffs1_din.di_mode -#define i_ffs1_mtime i_din.ffs1_din.di_mtime -#define i_ffs1_mtimensec i_din.ffs1_din.di_mtimensec -#define i_ffs1_nlink i_din.ffs1_din.di_nlink -#define i_ffs1_rdev i_din.ffs1_din.di_rdev -#define i_ffs1_shortlink i_din.ffs1_din.di_shortlink -#define i_ffs1_size i_din.ffs1_din.di_size -#define i_ffs1_uid i_din.ffs1_din.di_uid +#define i_ffs1_atime i_din.dp1.di_atime +#define i_ffs1_atimensec i_din.dp1.di_atimensec +#define i_ffs1_blocks i_din.dp1.di_blocks +#define i_ffs1_ctime i_din.dp1.di_ctime +#define i_ffs1_ctimensec i_din.dp1.di_ctimensec +#define i_ffs1_db i_din.dp1.di_db +#define i_ffs1_flags i_din.dp1.di_flags +#define i_ffs1_gen i_din.dp1.di_gen +#define i_ffs11_gid i_din.dp1.di_gid +#define i_ffs1_ib i_din.dp1.di_ib +#define i_ffs1_mode i_din.dp1.di_mode +#define i_ffs1_mtime i_din.dp1.di_mtime +#define i_ffs1_mtimensec i_din.dp1.di_mtimensec +#define i_ffs1_nlink i_din.dp1.di_nlink +#define i_ffs1_rdev i_din.dp1.di_rdev +#define i_ffs1_shortlink i_din.dp1.di_shortlink +#define i_ffs1_size i_din.dp1.di_size +#define i_ffs1_uid i_din.dp1.di_uid -#define i_ffs2_atime i_din.ffs2_din.di_atime -#define i_ffs2_atimensec i_din.ffs2_din.di_atimensec -#define i_ffs2_blocks i_din.ffs2_din.di_blocks -#define i_ffs2_ctime i_din.ffs2_din.di_ctime -#define i_ffs2_ctimensec i_din.ffs2_din.di_ctimensec -#define i_ffs2_birthtime i_din.ffs2_din.di_birthtime -#define i_ffs2_birthnsec i_din.ffs2_din.di_birthnsec -#define i_ffs2_db i_din.ffs2_din.di_db -#define i_ffs2_flags i_din.ffs2_din.di_flags -#define i_ffs2_gen i_din.ffs2_din.di_gen -#define i_ffs21_gid i_din.ffs2_din.di_gid -#define i_ffs2_ib i_din.ffs2_din.di_ib -#define i_ffs2_mode i_din.ffs2_din.di_mode -#define i_ffs2_mtime i_din.ffs2_din.di_mtime -#define i_ffs2_mtimensec i_din.ffs2_din.di_mtimensec -#define i_ffs2_nlink i_din.ffs2_din.di_nlink -#define i_ffs2_rdev i_din.ffs2_din.di_rdev -#define i_ffs2_shortlink i_din.ffs2_din.di_shortlink -#define i_ffs2_size i_din.ffs2_din.di_size -#define i_ffs2_uid i_din.ffs2_din.di_uid +#define i_ffs2_atime i_din.dp2.di_atime +#define i_ffs2_atimensec i_din.dp2.di_atimensec +#define i_ffs2_blocks i_din.dp2.di_blocks +#define i_ffs2_ctime i_din.dp2.di_ctime +#define i_ffs2_ctimensec i_din.dp2.di_ctimensec +#define i_ffs2_birthtime i_din.dp2.di_birthtime +#define i_ffs2_birthnsec i_din.dp2.di_birthnsec +#define i_ffs2_db i_din.dp2.di_db +#define i_ffs2_flags i_din.dp2.di_flags +#define i_ffs2_gen i_din.dp2.di_gen +#define i_ffs21_gid i_din.dp2.di_gid +#define i_ffs2_ib i_din.dp2.di_ib +#define i_ffs2_mode i_din.dp2.di_mode +#define i_ffs2_mtime i_din.dp2.di_mtime +#define i_ffs2_mtimensec i_din.dp2.di_mtimensec +#define i_ffs2_nlink i_din.dp2.di_nlink +#define i_ffs2_rdev i_din.dp2.di_rdev +#define i_ffs2_shortlink i_din.dp2.di_shortlink +#define i_ffs2_size i_din.dp2.di_size +#define i_ffs2_uid i_din.dp2.di_uid #undef DIP #define DIP(ip, field) \ diff --git a/usr.sbin/quot/quot.c b/usr.sbin/quot/quot.c index 7ca8110bef76..4152c498371a 100644 --- a/usr.sbin/quot/quot.c +++ b/usr.sbin/quot/quot.c @@ -97,10 +97,6 @@ static void quot(char *, char *); (((fs)->fs_magic == FS_UFS1_MAGIC ? sizeof(struct ufs1_dinode) : \ sizeof(struct ufs2_dinode)) * INOCNT(fs)) -union dinode { - struct ufs1_dinode dp1; - struct ufs2_dinode dp2; -}; #define DIP(fs, dp, field) \ (((fs)->fs_magic == FS_UFS1_MAGIC) ? \ (dp)->dp1.field : (dp)->dp2.field)