Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add an accessor function for directory names.
details: https://anonhg.NetBSD.org/src/rev/79dfbeaddbb9
branches: trunk
changeset: 340591:79dfbeaddbb9
user: dholland <dholland%NetBSD.org@localhost>
date: Tue Sep 15 15:02:01 2015 +0000
description:
Add an accessor function for directory names.
diffstat:
sbin/fsck_lfs/dir.c | 12 ++++++------
sbin/fsck_lfs/inode.c | 6 +++---
sbin/fsck_lfs/pass2.c | 24 ++++++++++++------------
sbin/newfs_lfs/make_lfs.c | 6 +++---
sys/ufs/lfs/lfs.h | 12 +-----------
sys/ufs/lfs/lfs_accessors.h | 8 +++++++-
sys/ufs/lfs/lfs_rename.c | 6 +++---
sys/ufs/lfs/ulfs_dirhash.c | 18 ++++++++++--------
sys/ufs/lfs/ulfs_lookup.c | 16 ++++++++--------
sys/ufs/lfs/ulfs_vnops.c | 7 ++++---
10 files changed, 57 insertions(+), 58 deletions(-)
diffs (truncated from 439 to 300 lines):
diff -r 937ce769ee6c -r 79dfbeaddbb9 sbin/fsck_lfs/dir.c
--- a/sbin/fsck_lfs/dir.c Tue Sep 15 15:01:38 2015 +0000
+++ b/sbin/fsck_lfs/dir.c Tue Sep 15 15:02:01 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.c,v 1.41 2015/09/15 15:01:38 dholland Exp $ */
+/* $NetBSD: dir.c,v 1.42 2015/09/15 15:02:01 dholland Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -198,8 +198,8 @@
lfs_dir_setnamlen(fs, dp, 0);
lfs_dir_setreclen(fs, dp, LFS_DIRBLKSIZ);
/* for now at least, don't zero the old contents */
- /*lfs_copydirname(fs, dp->d_name, "", 0, LFS_DIRBLKSIZ);*/
- dp->d_name[0] = '\0';
+ /*lfs_copydirname(fs, lfs_dir_nameptr(fs, dp), "", 0, LFS_DIRBLKSIZ);*/
+ lfs_dir_nameptr(fs, dp)[0] = '\0';
if (fix)
VOP_BWRITE(bp);
else
@@ -281,7 +281,7 @@
printf("reclen<size, filesize<size, namlen too large, or type>15\n");
return (0);
}
- cp = dp->d_name;
+ cp = lfs_dir_nameptr(fs, dp);
for (size = 0; size < namlen; size++)
if (*cp == '\0' || (*cp++ == '/')) {
printf("name contains NUL or /\n");
@@ -400,7 +400,7 @@
lfs_dir_setreclen(fs, dirp, newreclen);
lfs_dir_settype(fs, dirp, typemap[idesc->id_parent]);
lfs_dir_setnamlen(fs, dirp, namlen);
- lfs_copydirname(fs, dirp->d_name, idesc->id_name,
+ lfs_copydirname(fs, lfs_dir_nameptr(fs, dirp), idesc->id_name,
namlen, newreclen);
return (ALTERED | STOP);
@@ -413,7 +413,7 @@
int namlen;
namlen = lfs_dir_getnamlen(fs, dirp);
- if (memcmp(dirp->d_name, idesc->id_name, namlen + 1))
+ if (memcmp(lfs_dir_nameptr(fs, dirp), idesc->id_name, namlen + 1))
return (KEEPON);
lfs_dir_setino(fs, dirp, idesc->id_parent);
lfs_dir_settype(fs, dirp, typemap[idesc->id_parent]);
diff -r 937ce769ee6c -r 79dfbeaddbb9 sbin/fsck_lfs/inode.c
--- a/sbin/fsck_lfs/inode.c Tue Sep 15 15:01:38 2015 +0000
+++ b/sbin/fsck_lfs/inode.c Tue Sep 15 15:02:01 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: inode.c,v 1.65 2015/09/15 15:01:22 dholland Exp $ */
+/* $NetBSD: inode.c,v 1.66 2015/09/15 15:02:01 dholland Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -515,7 +515,7 @@
}
/* this is namebuf with utils.h */
buf = __UNCONST(idesc->id_name);
- (void)memcpy(buf, dirp->d_name, len);
+ (void)memcpy(buf, lfs_dir_nameptr(fs, dirp), len);
return (STOP | FOUND);
}
@@ -528,7 +528,7 @@
ino = lfs_dir_getino(fs, dirp);
if (ino == 0)
return (KEEPON);
- if (strcmp(dirp->d_name, idesc->id_name) == 0 &&
+ if (strcmp(lfs_dir_nameptr(fs, dirp), idesc->id_name) == 0 &&
ino >= ULFS_ROOTINO && ino < maxino) {
idesc->id_parent = ino;
return (STOP | FOUND);
diff -r 937ce769ee6c -r 79dfbeaddbb9 sbin/fsck_lfs/pass2.c
--- a/sbin/fsck_lfs/pass2.c Tue Sep 15 15:01:38 2015 +0000
+++ b/sbin/fsck_lfs/pass2.c Tue Sep 15 15:02:01 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pass2.c,v 1.30 2015/09/15 15:01:38 dholland Exp $ */
+/* $NetBSD: pass2.c,v 1.31 2015/09/15 15:02:01 dholland Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -226,7 +226,7 @@
*/
if (idesc->id_entryno != 0)
goto chk1;
- if (lfs_dir_getino(fs, dirp) != 0 && strcmp(dirp->d_name, ".") == 0) {
+ if (lfs_dir_getino(fs, dirp) != 0 && strcmp(lfs_dir_nameptr(fs, dirp), ".") == 0) {
if (lfs_dir_getino(fs, dirp) != idesc->id_number) {
direrror(idesc->id_number, "BAD INODE NUMBER FOR '.'");
if (reply("FIX") == 1) {
@@ -249,16 +249,16 @@
lfs_dir_setnamlen(fs, &proto, 1);
entrysize = LFS_DIRECTSIZ(1);
lfs_dir_setreclen(fs, &proto, entrysize);
- if (lfs_dir_getino(fs, dirp) != 0 && strcmp(dirp->d_name, "..") != 0) {
+ if (lfs_dir_getino(fs, dirp) != 0 && strcmp(lfs_dir_nameptr(fs, dirp), "..") != 0) {
pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n",
- dirp->d_name);
+ lfs_dir_nameptr(fs, dirp));
} else if (lfs_dir_getreclen(fs, dirp) < entrysize) {
pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n");
} else if (lfs_dir_getreclen(fs, dirp) < 2 * entrysize) {
/* convert this entry to a . entry */
lfs_dir_setreclen(fs, &proto, lfs_dir_getreclen(fs, dirp));
memcpy(dirp, &proto, sizeof(proto));
- lfs_copydirname(fs, dirp->d_name, ".", 1,
+ lfs_copydirname(fs, lfs_dir_nameptr(fs, dirp), ".", 1,
lfs_dir_getreclen(fs, dirp));
if (reply("FIX") == 1)
ret |= ALTERED;
@@ -266,7 +266,7 @@
/* split this entry and use the beginning for the . entry */
n = lfs_dir_getreclen(fs, dirp) - entrysize;
memcpy(dirp, &proto, sizeof(proto));
- lfs_copydirname(fs, dirp->d_name, ".", 1,
+ lfs_copydirname(fs, lfs_dir_nameptr(fs, dirp), ".", 1,
lfs_dir_getreclen(fs, dirp));
idesc->id_entryno++;
lncntp[lfs_dir_getino(fs, dirp)]--;
@@ -297,7 +297,7 @@
memset(dirp, 0, lfs_dir_getreclen(fs, &proto));
lfs_dir_setreclen(fs, dirp, lfs_dir_getreclen(fs, &proto));
}
- if (lfs_dir_getino(fs, dirp) != 0 && strcmp(dirp->d_name, "..") == 0) {
+ if (lfs_dir_getino(fs, dirp) != 0 && strcmp(lfs_dir_nameptr(fs, dirp), "..") == 0) {
inp->i_dotdot = lfs_dir_getino(fs, dirp);
if (lfs_dir_gettype(fs, dirp) != LFS_DT_DIR) {
direrror(idesc->id_number, "BAD TYPE VALUE FOR '..'");
@@ -307,10 +307,10 @@
}
goto chk2;
}
- if (lfs_dir_getino(fs, dirp) != 0 && strcmp(dirp->d_name, ".") != 0) {
+ if (lfs_dir_getino(fs, dirp) != 0 && strcmp(lfs_dir_nameptr(fs, dirp), ".") != 0) {
fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
pfatal("CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS %s\n",
- dirp->d_name);
+ lfs_dir_nameptr(fs, dirp));
inp->i_dotdot = (ino_t) - 1;
} else if (lfs_dir_getreclen(fs, dirp) < entrysize) {
fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
@@ -324,7 +324,7 @@
fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
lfs_dir_setreclen(fs, &proto, lfs_dir_getreclen(fs, dirp));
memcpy(dirp, &proto, (size_t) entrysize);
- lfs_copydirname(fs, dirp->d_name, "..", 2,
+ lfs_copydirname(fs, lfs_dir_nameptr(fs, dirp), "..", 2,
lfs_dir_getreclen(fs, dirp));
if (reply("FIX") == 1)
ret |= ALTERED;
@@ -337,7 +337,7 @@
if (lfs_dir_getino(fs, dirp) == 0)
return (ret | KEEPON);
if (lfs_dir_getnamlen(fs, dirp) <= 2 &&
- dirp->d_name[0] == '.' &&
+ lfs_dir_nameptr(fs, dirp)[0] == '.' &&
idesc->id_entryno >= 2) {
if (lfs_dir_getnamlen(fs, dirp) == 1) {
direrror(idesc->id_number, "EXTRA '.' ENTRY");
@@ -347,7 +347,7 @@
}
return (KEEPON | ret);
}
- if (dirp->d_name[1] == '.') {
+ if (lfs_dir_nameptr(fs, dirp)[1] == '.') {
direrror(idesc->id_number, "EXTRA '..' ENTRY");
if (reply("FIX") == 1) {
lfs_dir_setino(fs, dirp, 0);
diff -r 937ce769ee6c -r 79dfbeaddbb9 sbin/newfs_lfs/make_lfs.c
--- a/sbin/newfs_lfs/make_lfs.c Tue Sep 15 15:01:38 2015 +0000
+++ b/sbin/newfs_lfs/make_lfs.c Tue Sep 15 15:02:01 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: make_lfs.c,v 1.52 2015/09/15 15:01:38 dholland Exp $ */
+/* $NetBSD: make_lfs.c,v 1.53 2015/09/15 15:02:01 dholland Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
#if 0
static char sccsid[] = "@(#)lfs.c 8.5 (Berkeley) 5/24/95";
#else
-__RCSID("$NetBSD: make_lfs.c,v 1.52 2015/09/15 15:01:38 dholland Exp $");
+__RCSID("$NetBSD: make_lfs.c,v 1.53 2015/09/15 15:02:01 dholland Exp $");
#endif
#endif /* not lint */
@@ -380,7 +380,7 @@
lfs_dir_setreclen(fs, ep, reclen);
lfs_dir_settype(fs, ep, protodir[i].dp_type);
lfs_dir_setnamlen(fs, ep, namlen);
- lfs_copydirname(fs, ep->d_name, protodir[i].dp_name,
+ lfs_copydirname(fs, lfs_dir_nameptr(fs, ep), protodir[i].dp_name,
namlen, reclen);
ep = LFS_NEXTDIR(fs, ep);
}
diff -r 937ce769ee6c -r 79dfbeaddbb9 sys/ufs/lfs/lfs.h
--- a/sys/ufs/lfs/lfs.h Tue Sep 15 15:01:38 2015 +0000
+++ b/sys/ufs/lfs/lfs.h Tue Sep 15 15:02:01 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs.h,v 1.187 2015/09/15 14:59:58 dholland Exp $ */
+/* $NetBSD: lfs.h,v 1.188 2015/09/15 15:02:01 dholland Exp $ */
/* from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp */
/* from NetBSD: dir.h,v 1.21 2009/07/22 04:49:19 dholland Exp */
@@ -376,16 +376,6 @@
char d_name[LFS_MAXNAMLEN + 1];/* name with length <= LFS_MAXNAMLEN */
};
-/* Note that this does *not* byteswap and should probably be phased out */
-#define LFS_DIRECT_INITIALIZER(ino, type, namlen, name) \
- { \
- .d_ino = (ino), \
- .d_reclen = LFS_DIRECTSIZE(namlen), \
- .d_type = (type), \
- .d_namlen = (namlen), \
- .d_name = (name) \
- }
-
/*
* Template for manipulating directories. Should use struct lfs_direct's,
* but the name field is LFS_MAXNAMLEN - 1, and this just won't do.
diff -r 937ce769ee6c -r 79dfbeaddbb9 sys/ufs/lfs/lfs_accessors.h
--- a/sys/ufs/lfs/lfs_accessors.h Tue Sep 15 15:01:38 2015 +0000
+++ b/sys/ufs/lfs/lfs_accessors.h Tue Sep 15 15:02:01 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_accessors.h,v 1.25 2015/09/15 15:01:38 dholland Exp $ */
+/* $NetBSD: lfs_accessors.h,v 1.26 2015/09/15 15:02:01 dholland Exp $ */
/* from NetBSD: lfs.h,v 1.165 2015/07/24 06:59:32 dholland Exp */
/* from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp */
@@ -244,6 +244,12 @@
#define LFS_NEXTDIR(fs, dp) \
((struct lfs_direct *)((char *)(dp) + lfs_dir_getreclen(fs, dp)))
+static __unused inline char *
+lfs_dir_nameptr(const STRUCT_LFS *fs, struct lfs_direct *dp)
+{
+ return (char *)(&dp->d_header + 1);
+}
+
static __unused inline uint32_t
lfs_dir_getino(const STRUCT_LFS *fs, const struct lfs_direct *dp)
{
diff -r 937ce769ee6c -r 79dfbeaddbb9 sys/ufs/lfs/lfs_rename.c
--- a/sys/ufs/lfs/lfs_rename.c Tue Sep 15 15:01:38 2015 +0000
+++ b/sys/ufs/lfs/lfs_rename.c Tue Sep 15 15:02:01 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_rename.c,v 1.11 2015/09/15 15:00:32 dholland Exp $ */
+/* $NetBSD: lfs_rename.c,v 1.12 2015/09/15 15:02:01 dholland Exp $ */
/* from NetBSD: ufs_rename.c,v 1.6 2013/01/22 09:39:18 dholland Exp */
/*-
@@ -89,7 +89,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_rename.c,v 1.11 2015/09/15 15:00:32 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_rename.c,v 1.12 2015/09/15 15:02:01 dholland Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -442,7 +442,7 @@
if (fcnp->cn_namelen != ulfs_direct_namlen(ep, dvp))
goto next; /* Wrong name length. */
- if (memcmp(ep->d_name, fcnp->cn_nameptr, fcnp->cn_namelen))
+ if (memcmp(lfs_dir_nameptr(fs, ep), fcnp->cn_nameptr, fcnp->cn_namelen))
goto next; /* Wrong name. */
/* Got it! */
diff -r 937ce769ee6c -r 79dfbeaddbb9 sys/ufs/lfs/ulfs_dirhash.c
--- a/sys/ufs/lfs/ulfs_dirhash.c Tue Sep 15 15:01:38 2015 +0000
+++ b/sys/ufs/lfs/ulfs_dirhash.c Tue Sep 15 15:02:01 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ulfs_dirhash.c,v 1.10 2015/09/15 14:58:06 dholland Exp $ */
+/* $NetBSD: ulfs_dirhash.c,v 1.11 2015/09/15 15:02:01 dholland Exp $ */
/* from NetBSD: ufs_dirhash.c,v 1.34 2009/10/05 23:48:08 rmind Exp */
/*
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ulfs_dirhash.c,v 1.10 2015/09/15 14:58:06 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ulfs_dirhash.c,v 1.11 2015/09/15 15:02:01 dholland Exp $");
/*
* This implements a hash-based lookup scheme for ULFS directories.
@@ -236,7 +236,7 @@
}
if (lfs_dir_getino(fs, ep) != 0) {
/* Add the entry (simplified ulfsdirhash_add). */
- slot = ulfsdirhash_hash(dh, ep->d_name,
+ slot = ulfsdirhash_hash(dh, lfs_dir_nameptr(fs, ep),
lfs_dir_getnamlen(fs, ep));
while (DH_ENTRY(dh, slot) != DIRHASH_EMPTY)
slot = WRAPINCR(slot, dh->dh_hlen);
@@ -433,7 +433,7 @@
Home |
Main Index |
Thread Index |
Old Index