Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/ufs/ufs misc cleanups, no functional change
details: https://anonhg.NetBSD.org/src/rev/5c2f4fde2987
branches: trunk
changeset: 344702:5c2f4fde2987
user: christos <christos%NetBSD.org@localhost>
date: Mon Apr 11 23:41:15 2016 +0000
description:
misc cleanups, no functional change
diffstat:
sys/ufs/ufs/ufs_extern.h | 4 +-
sys/ufs/ufs/ufs_lookup.c | 195 +++++++++++++++++++++-------------------------
2 files changed, 92 insertions(+), 107 deletions(-)
diffs (truncated from 421 to 300 lines):
diff -r 60f7b5e8e18b -r 5c2f4fde2987 sys/ufs/ufs/ufs_extern.h
--- a/sys/ufs/ufs/ufs_extern.h Mon Apr 11 22:30:14 2016 +0000
+++ b/sys/ufs/ufs/ufs_extern.h Mon Apr 11 23:41:15 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_extern.h,v 1.79 2015/03/27 17:27:56 riastradh Exp $ */
+/* $NetBSD: ufs_extern.h,v 1.80 2016/04/11 23:41:15 christos Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@@ -126,7 +126,7 @@
int ufs_dirrewrite(struct inode *, off_t,
struct inode *, ino_t, int, int, int);
int ufs_dirempty(struct inode *, ino_t, kauth_cred_t);
-int ufs_blkatoff(struct vnode *, off_t, char **, struct buf **, bool);
+int ufs_blkatoff(struct vnode *, off_t, void *, struct buf **, bool);
/* ufs_rename.c -- for lfs */
bool ufs_gro_directory_empty_p(struct mount *, kauth_cred_t,
diff -r 60f7b5e8e18b -r 5c2f4fde2987 sys/ufs/ufs/ufs_lookup.c
--- a/sys/ufs/ufs/ufs_lookup.c Mon Apr 11 22:30:14 2016 +0000
+++ b/sys/ufs/ufs/ufs_lookup.c Mon Apr 11 23:41:15 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_lookup.c,v 1.135 2015/07/11 11:04:48 mlelstv Exp $ */
+/* $NetBSD: ufs_lookup.c,v 1.136 2016/04/11 23:41:15 christos Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.135 2015/07/11 11:04:48 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.136 2016/04/11 23:41:15 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_ffs.h"
@@ -76,6 +76,23 @@
int dirchk = 0;
#endif
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define ENDIANSWAP 0
+#else
+#define ENDIANSWAP UFS_NEEDSWAP
+#endif
+
+#define NAMLEN(fsfmt, needswap, dp) \
+ ((fsfmt) && (needswap) == ENDIANSWAP ? (dp)->d_type : dp->d_namlen)
+
+static void
+ufs_dirswap(struct direct *dirp)
+{
+ u_char tmp = dirp->d_namlen;
+ dirp->d_namlen = dirp->d_type;
+ dirp->d_type = tmp;
+}
+
/*
* Convert a component of a pathname into a pointer to a locked inode.
* This is a very central and rather complicated routine.
@@ -153,6 +170,7 @@
ino_t foundino;
struct ufs_lookup_results *results;
int iswhiteout; /* temp result from cache_lookup() */
+ const int fsfmt = FSFMT(vdp);
flags = cnp->cn_flags;
@@ -261,7 +279,7 @@
switch (ufsdirhash_lookup(dp, cnp->cn_nameptr, cnp->cn_namelen,
&results->ulr_offset, &bp, nameiop == DELETE ? &prevoff : NULL)) {
case 0:
- ep = (struct direct *)((char *)bp->b_data +
+ ep = (void *)((char *)bp->b_data +
(results->ulr_offset & bmask));
goto foundentry;
case ENOENT:
@@ -325,12 +343,13 @@
* "dirchk" to be true.
*/
KASSERT(bp != NULL);
- ep = (struct direct *)((char *)bp->b_data + entryoffsetinblock);
+ ep = (void *)((char *)bp->b_data + entryoffsetinblock);
if (ep->d_reclen == 0 ||
(dirchk && ufs_dirbadentry(vdp, ep, entryoffsetinblock))) {
int i;
- ufs_dirbad(dp, results->ulr_offset, "mangled entry");
+ ufs_dirbad(dp, results->ulr_offset, ep->d_reclen == 0 ?
+ "null entry" : "mangled entry");
i = dirblksiz - (entryoffsetinblock & (dirblksiz - 1));
results->ulr_offset += i;
entryoffsetinblock += i;
@@ -347,7 +366,7 @@
int size = ufs_rw16(ep->d_reclen, needswap);
if (ep->d_ino != 0)
- size -= UFS_DIRSIZ(FSFMT(vdp), ep, needswap);
+ size -= UFS_DIRSIZ(fsfmt, ep, needswap);
if (size > 0) {
if (size >= slotneeded) {
slotstatus = FOUND;
@@ -373,19 +392,7 @@
* Check for a name match.
*/
if (ep->d_ino) {
- int namlen;
-
-#if (BYTE_ORDER == LITTLE_ENDIAN)
- if (FSFMT(vdp) && needswap == 0)
- namlen = ep->d_type;
- else
- namlen = ep->d_namlen;
-#else
- if (FSFMT(vdp) && needswap != 0)
- namlen = ep->d_type;
- else
- namlen = ep->d_namlen;
-#endif
+ const int namlen = NAMLEN(fsfmt, needswap, ep);
if (namlen == cnp->cn_namelen &&
!memcmp(cnp->cn_nameptr, ep->d_name,
(unsigned)namlen)) {
@@ -396,7 +403,7 @@
* Save directory entry's inode number and
* reclen, and release directory buffer.
*/
- if (!FSFMT(vdp) && ep->d_type == DT_WHT) {
+ if (!fsfmt && ep->d_type == DT_WHT) {
slotstatus = FOUND;
slotoffset = results->ulr_offset;
slotsize = ufs_rw16(ep->d_reclen,
@@ -527,10 +534,11 @@
* Check that directory length properly reflects presence
* of this entry.
*/
- if (results->ulr_offset + UFS_DIRSIZ(FSFMT(vdp), ep, needswap) > dp->i_size) {
+ const uint64_t newisize =
+ results->ulr_offset + UFS_DIRSIZ(fsfmt, ep, needswap);
+ if (newisize > dp->i_size) {
ufs_dirbad(dp, results->ulr_offset, "i_size too small");
- dp->i_size =
- results->ulr_offset + UFS_DIRSIZ(FSFMT(vdp), ep, needswap);
+ dp->i_size = newisize;
DIP_ASSIGN(dp, size, dp->i_size);
dp->i_flag |= IN_CHANGE | IN_UPDATE;
UFS_WAPBL_UPDATE(vdp, NULL, NULL, UPDATE_DIROP);
@@ -672,51 +680,53 @@
int
ufs_dirbadentry(struct vnode *dp, struct direct *ep, int entryoffsetinblock)
{
- int i;
- int namlen;
- struct ufsmount *ump = VFSTOUFS(dp->v_mount);
+ const struct ufsmount *ump = VFSTOUFS(dp->v_mount);
const int needswap = UFS_MPNEEDSWAP(ump);
- int dirblksiz = ump->um_dirblksiz;
+ const int dirblksiz = ump->um_dirblksiz;
+ const int maxsize = dirblksiz - (entryoffsetinblock & (dirblksiz - 1));
+ const int fsfmt = FSFMT(dp);
+ const int namlen = NAMLEN(fsfmt, needswap, ep);
+ const int reclen = ufs_rw16(ep->d_reclen, needswap);
+ const int dirsiz = (int)UFS_DIRSIZ(fsfmt, ep, needswap);
-#if (BYTE_ORDER == LITTLE_ENDIAN)
- if (FSFMT(dp) && needswap == 0)
- namlen = ep->d_type;
- else
- namlen = ep->d_namlen;
-#else
- if (FSFMT(dp) && needswap != 0)
- namlen = ep->d_type;
+ const char *str;
+ if ((reclen & 0x3) != 0)
+ str = "not rounded";
+ else if (reclen > maxsize)
+ str = "too big";
+ else if (reclen < dirsiz)
+ str = "too small";
+ else if (namlen > FFS_MAXNAMLEN)
+ str = "long name";
else
- namlen = ep->d_namlen;
-#endif
- if ((ufs_rw16(ep->d_reclen, needswap) & 0x3) != 0 ||
- ufs_rw16(ep->d_reclen, needswap) >
- dirblksiz - (entryoffsetinblock & (dirblksiz - 1)) ||
- ufs_rw16(ep->d_reclen, needswap) <
- UFS_DIRSIZ(FSFMT(dp), ep, needswap) ||
- namlen > FFS_MAXNAMLEN) {
- /*return (1); */
- printf("First bad, reclen=%#x, DIRSIZ=%lu, namlen=%d, "
- "flags=%#x, entryoffsetinblock=%d, dirblksiz = %d\n",
- ufs_rw16(ep->d_reclen, needswap),
- (u_long)UFS_DIRSIZ(FSFMT(dp), ep, needswap),
- namlen, dp->v_mount->mnt_flag, entryoffsetinblock,
- dirblksiz);
+ str = NULL;
+
+ if (str) {
+ printf("%s: Bad dir (%s), reclen=%#x, namlen=%d, "
+ "dirsiz=%d <= reclen=%d <= maxsize=%d, "
+ "flags=%#x, entryoffsetinblock=%d, dirblksiz=%d\n",
+ __func__, str, reclen, namlen, dirsiz, reclen, maxsize,
+ dp->v_mount->mnt_flag, entryoffsetinblock, dirblksiz);
goto bad;
}
+
if (ep->d_ino == 0)
- return (0);
+ return 0;
+
+ int i;
for (i = 0; i < namlen; i++)
if (ep->d_name[i] == '\0') {
- /*return (1); */
- printf("Second bad\n");
+ printf("%s: NUL in name i=%d, namlen=%d\n", __func__,
+ i, namlen);
goto bad;
}
- if (ep->d_name[i])
+ if (ep->d_name[i]) {
+ printf("%s: missing NUL in name namlen=%d\n", __func__, i);
goto bad;
- return (0);
+ }
+ return 0;
bad:
- return (1);
+ return 1;
}
/*
@@ -784,6 +794,7 @@
struct ufsmount *ump = VFSTOUFS(dvp->v_mount);
const int needswap = UFS_MPNEEDSWAP(ump);
int dirblksiz = ump->um_dirblksiz;
+ const int fsfmt = FSFMT(dvp);
UFS_WAPBL_JLOCK_ASSERT(dvp->v_mount);
@@ -812,17 +823,8 @@
uvm_vnp_setsize(dvp, dp->i_size);
dirp->d_reclen = ufs_rw16(dirblksiz, needswap);
dirp->d_ino = ufs_rw32(dirp->d_ino, needswap);
- if (FSFMT(dvp)) {
-#if (BYTE_ORDER == LITTLE_ENDIAN)
- if (needswap == 0) {
-#else
- if (needswap != 0) {
-#endif
- u_char tmp = dirp->d_namlen;
- dirp->d_namlen = dirp->d_type;
- dirp->d_type = tmp;
- }
- }
+ if (fsfmt && needswap == ENDIANSWAP)
+ ufs_dirswap(dirp);
blkoff = ulr->ulr_offset & (ump->um_mountp->mnt_stat.f_iosize - 1);
memcpy((char *)bp->b_data + blkoff, dirp, newentrysize);
#ifdef UFS_DIRHASH
@@ -880,17 +882,17 @@
* arranged that compacting the region ulr_offset to
* ulr_offset + ulr_count would yield the space.
*/
- ep = (struct direct *)dirbuf;
- dsize = (ep->d_ino != 0) ? UFS_DIRSIZ(FSFMT(dvp), ep, needswap) : 0;
+ ep = (void *)dirbuf;
+ dsize = (ep->d_ino != 0) ? UFS_DIRSIZ(fsfmt, ep, needswap) : 0;
spacefree = ufs_rw16(ep->d_reclen, needswap) - dsize;
for (loc = ufs_rw16(ep->d_reclen, needswap); loc < ulr->ulr_count; ) {
uint16_t reclen;
- nep = (struct direct *)(dirbuf + loc);
+ nep = (void *)(dirbuf + loc);
/* Trim the existing slot (NB: dsize may be zero). */
ep->d_reclen = ufs_rw16(dsize, needswap);
- ep = (struct direct *)((char *)ep + dsize);
+ ep = (void *)((char *)ep + dsize);
reclen = ufs_rw16(nep->d_reclen, needswap);
loc += reclen;
@@ -908,7 +910,7 @@
dsize = 0;
continue;
}
- dsize = UFS_DIRSIZ(FSFMT(dvp), nep, needswap);
+ dsize = UFS_DIRSIZ(fsfmt, nep, needswap);
spacefree += reclen - dsize;
#ifdef UFS_DIRHASH
if (dp->i_dirhash != NULL)
@@ -916,7 +918,7 @@
ulr->ulr_offset + ((char *)nep - dirbuf),
ulr->ulr_offset + ((char *)ep - dirbuf));
#endif
- memcpy((void *)ep, (void *)nep, dsize);
+ memcpy(ep, nep, dsize);
}
Home |
Main Index |
Thread Index |
Old Index