NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: kern/42573: DIRBLKSIZ in <ufs/ufs/dir.h> should not be DEV_BSIZE constant
The following reply was made to PR kern/42573; it has been noted by GNATS.
From: Izumi Tsutsui <tsutsui%ceres.dti.ne.jp@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: tsutsui%ceres.dti.ne.jp@localhost
Subject: Re: kern/42573: DIRBLKSIZ in <ufs/ufs/dir.h> should not be DEV_BSIZE
constant
Date: Mon, 4 Jan 2010 03:11:07 +0900
Here is a revised patch of makefs(8) for readability:
---
Index: ffs.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/makefs/ffs.c,v
retrieving revision 1.44
diff -u -r1.44 ffs.c
--- ffs.c 28 Apr 2009 22:49:26 -0000 1.44
+++ ffs.c 3 Jan 2010 17:54:15 -0000
@@ -134,8 +134,10 @@
static int ffs_create_image(const char *, fsinfo_t *);
static void ffs_dump_fsinfo(fsinfo_t *);
-static void ffs_dump_dirbuf(dirbuf_t *, const char *, int);
-static void ffs_make_dirbuf(dirbuf_t *, const char *, fsnode *,
int);
+static void ffs_dump_dirbuf(dirbuf_t *, const char *,
+ const fsinfo_t *);
+static void ffs_make_dirbuf(dirbuf_t *, const char *, fsnode *,
+ const fsinfo_t *);
static int ffs_populate_dir(const char *, fsnode *, fsinfo_t *);
static void ffs_size_dir(fsnode *, fsinfo_t *);
static void ffs_validate(const char *, fsnode *, fsinfo_t *);
@@ -550,12 +552,13 @@
{
struct direct tmpdir;
fsnode * node;
- int curdirsize, this;
+ int curdirsize, this, dirblksiz;
ffs_opt_t *ffs_opts = fsopts->fs_specific;
/* node may be NULL (empty directory) */
assert(fsopts != NULL);
assert(ffs_opts != NULL);
+ dirblksiz = fsopts->sectorsize;
if (debug & DEBUG_FS_SIZE_DIR)
printf("ffs_size_dir: entry: bytes %lld inodes %lld\n",
@@ -567,8 +570,8 @@
if (debug & DEBUG_FS_SIZE_DIR_ADD_DIRENT) \
printf("ADDDIRENT: was: %s (%d) this %d cur %d\n", \
e, tmpdir.d_namlen, this, curdirsize); \
- if (this + curdirsize > roundup(curdirsize, DIRBLKSIZ)) \
- curdirsize = roundup(curdirsize, DIRBLKSIZ); \
+ if (this + curdirsize > roundup(curdirsize, dirblksiz)) \
+ curdirsize = roundup(curdirsize, dirblksiz); \
curdirsize += this; \
if (debug & DEBUG_FS_SIZE_DIR_ADD_DIRENT) \
printf("ADDDIRENT: now: %s (%d) this %d cur %d\n", \
@@ -752,11 +755,11 @@
fsopts->curinode++;
}
}
- ffs_make_dirbuf(&dirbuf, cur->name, cur, fsopts->needswap);
+ ffs_make_dirbuf(&dirbuf, cur->name, cur, fsopts);
if (cur == root) { /* we're at "."; add ".." */
ffs_make_dirbuf(&dirbuf, "..",
cur->parent == NULL ? cur : cur->parent->first,
- fsopts->needswap);
+ fsopts);
root->inode->nlink++; /* count my parent's link */
} else if (cur->child != NULL)
root->inode->nlink++; /* count my child's link */
@@ -769,7 +772,7 @@
*/
}
if (debug & DEBUG_FS_POPULATE_DIRBUF)
- ffs_dump_dirbuf(&dirbuf, dir, fsopts->needswap);
+ ffs_dump_dirbuf(&dirbuf, dir, fsopts);
/*
* pass 2: write out dirbuf, then non-directories at this level
@@ -955,14 +958,16 @@
static void
-ffs_dump_dirbuf(dirbuf_t *dbuf, const char *dir, int needswap)
+ffs_dump_dirbuf(dirbuf_t *dbuf, const char *dir, const fsinfo_t *fsopts)
{
doff_t i;
struct direct *de;
+ int needswap;
uint16_t reclen;
assert (dbuf != NULL);
assert (dir != NULL);
+ needswap = fsopts->needswap;
printf("ffs_dump_dirbuf: dir %s size %d cur %d\n",
dir, dbuf->size, dbuf->cur);
@@ -980,15 +985,20 @@
}
static void
-ffs_make_dirbuf(dirbuf_t *dbuf, const char *name, fsnode *node, int needswap)
+ffs_make_dirbuf(dirbuf_t *dbuf, const char *name, fsnode *node,
+ const fsinfo_t *fsopts)
{
struct direct de, *dp;
+ int needswap;
+ int dirblksiz;
uint16_t llen, reclen;
u_char *newbuf;
assert (dbuf != NULL);
assert (name != NULL);
assert (node != NULL);
+ needswap = fsopts->needswap;
+ dirblksiz = fsopts->sectorsize;
/* create direct entry */
(void)memset(&de, 0, sizeof(de));
de.d_fileno = ufs_rw32(node->inode->ino, needswap);
@@ -1011,16 +1021,17 @@
ufs_rw32(de.d_fileno, needswap), de.d_type, reclen,
de.d_namlen, de.d_name);
- if (reclen + dbuf->cur + llen > roundup(dbuf->size, DIRBLKSIZ)) {
+ if (reclen + dbuf->cur + llen > roundup(dbuf->size, dirblksiz)) {
if (debug & DEBUG_FS_MAKE_DIRBUF)
printf("ffs_make_dirbuf: growing buf to %d\n",
- dbuf->size + DIRBLKSIZ);
- if ((newbuf = realloc(dbuf->buf, dbuf->size + DIRBLKSIZ)) ==
NULL)
+ dbuf->size + dirblksiz);
+ if ((newbuf = realloc(dbuf->buf,
+ dbuf->size + dirblksiz)) == NULL)
err(1, "Allocating memory for directory buffer");
dbuf->buf = newbuf;
- dbuf->size += DIRBLKSIZ;
- memset(dbuf->buf + dbuf->size - DIRBLKSIZ, 0, DIRBLKSIZ);
- dbuf->cur = dbuf->size - DIRBLKSIZ;
+ dbuf->size += dirblksiz;
+ memset(dbuf->buf + dbuf->size - dirblksiz, 0, dirblksiz);
+ dbuf->cur = dbuf->size - dirblksiz;
} else if (dp) { /* shrink end of previous */
dp->d_reclen = ufs_rw16(llen,needswap);
dbuf->cur += llen;
Home |
Main Index |
Thread Index |
Old Index