Avoid stack allocation of large dirent structures in foo_readdir().

This commit is contained in:
rumble 2007-09-24 00:42:12 +00:00
parent 12e401bc1a
commit 0ae0a486c7
18 changed files with 274 additions and 214 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: efs_vnops.c,v 1.8 2007/09/08 18:17:59 rumble Exp $ */
/* $NetBSD: efs_vnops.c,v 1.9 2007/09/24 00:42:12 rumble Exp $ */
/*
* Copyright (c) 2006 Stephen M. Rumble <rumble@ephemeral.org>
@ -17,7 +17,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: efs_vnops.c,v 1.8 2007/09/08 18:17:59 rumble Exp $");
__KERNEL_RCSID(0, "$NetBSD: efs_vnops.c,v 1.9 2007/09/24 00:42:12 rumble Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -296,7 +296,7 @@ efs_readdir(void *v)
off_t **a_cookies;
int *a_ncookies;
} */ *ap = v;
struct dirent d;
struct dirent *dp;
struct efs_dinode edi;
struct efs_extent ex;
struct efs_extent_iterator exi;
@ -322,6 +322,8 @@ efs_readdir(void *v)
cookies = malloc(maxcookies * sizeof(off_t), M_TEMP, M_WAITOK);
}
dp = malloc(sizeof(struct dirent), M_EFSTMP, M_WAITOK | M_ZERO);
offset = 0;
efs_extent_iterator_init(&exi, ei, 0);
while ((ret = efs_extent_iterator_next(&exi, &ex)) == 0) {
@ -352,7 +354,7 @@ efs_readdir(void *v)
}
de = EFS_DIRBLK_TO_DIRENT(db, slot);
s = _DIRENT_RECLEN(&d, de->de_namelen);
s = _DIRENT_RECLEN(dp, de->de_namelen);
if (offset < uio->uio_offset) {
offset += s;
@ -367,18 +369,18 @@ efs_readdir(void *v)
}
/* de_namelen is uint8_t, d.d_name is 512b */
KASSERT(sizeof(d.d_name) - de->de_namelen > 0);
d.d_fileno = be32toh(de->de_inumber);
d.d_reclen = s;
d.d_namlen = de->de_namelen;
memcpy(d.d_name, de->de_name,
KASSERT(sizeof(dp->d_name)-de->de_namelen > 0);
dp->d_fileno = be32toh(de->de_inumber);
dp->d_reclen = s;
dp->d_namlen = de->de_namelen;
memcpy(dp->d_name, de->de_name,
de->de_namelen);
d.d_name[de->de_namelen] = '\0';
dp->d_name[de->de_namelen] = '\0';
/* look up inode to get type */
err = efs_read_inode(
VFSTOEFS(ap->a_vp->v_mount),
d.d_fileno, NULL, &edi);
dp->d_fileno, NULL, &edi);
if (err) {
brelse(bp);
goto exit_err;
@ -386,32 +388,32 @@ efs_readdir(void *v)
switch (be16toh(edi.di_mode) & EFS_IFMT) {
case EFS_IFIFO:
d.d_type = DT_FIFO;
dp->d_type = DT_FIFO;
break;
case EFS_IFCHR:
d.d_type = DT_CHR;
dp->d_type = DT_CHR;
break;
case EFS_IFDIR:
d.d_type = DT_DIR;
dp->d_type = DT_DIR;
break;
case EFS_IFBLK:
d.d_type = DT_BLK;
dp->d_type = DT_BLK;
break;
case EFS_IFREG:
d.d_type = DT_REG;
dp->d_type = DT_REG;
break;
case EFS_IFLNK:
d.d_type = DT_LNK;
dp->d_type = DT_LNK;
break;
case EFS_IFSOCK:
d.d_type = DT_SOCK;
dp->d_type = DT_SOCK;
break;
default:
d.d_type = DT_UNKNOWN;
dp->d_type = DT_UNKNOWN;
break;
}
err = uiomove(&d, s, uio);
err = uiomove(dp, s, uio);
if (err) {
brelse(bp);
goto exit_err;
@ -448,11 +450,15 @@ efs_readdir(void *v)
uio->uio_offset = offset;
free(dp, M_EFSTMP);
return (0);
exit_err:
if (cookies != NULL)
free(cookies, M_TEMP);
free(dp, M_EFSTMP);
return (err);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: filecore_extern.h,v 1.16 2007/07/31 21:14:17 pooka Exp $ */
/* $NetBSD: filecore_extern.h,v 1.17 2007/09/24 00:42:12 rumble Exp $ */
/*-
* Copyright (c) 1994 The Regents of the University of California.
@ -79,6 +79,7 @@
#include <sys/mallocvar.h>
MALLOC_DECLARE(M_FILECOREMNT);
MALLOC_DECLARE(M_FILECORETMP);
struct filecore_mnt {
struct mount *fc_mountp;

View File

@ -1,4 +1,4 @@
/* $NetBSD: filecore_node.c,v 1.10 2007/06/30 09:37:55 pooka Exp $ */
/* $NetBSD: filecore_node.c,v 1.11 2007/09/24 00:42:12 rumble Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1994
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: filecore_node.c,v 1.10 2007/06/30 09:37:55 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: filecore_node.c,v 1.11 2007/09/24 00:42:12 rumble Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -107,6 +107,7 @@ filecore_init()
{
malloc_type_attach(M_FILECOREMNT);
malloc_type_attach(M_FILECORETMP);
pool_init(&filecore_node_pool, sizeof(struct filecore_node), 0, 0, 0,
"filecrnopl", &pool_allocator_nointr, IPL_NONE);
filecorehashtbl = hashinit(desiredvnodes, HASH_LIST, M_FILECOREMNT,
@ -152,6 +153,7 @@ filecore_done()
{
hashdone(filecorehashtbl, M_FILECOREMNT);
pool_destroy(&filecore_node_pool);
malloc_type_detach(M_FILECORETMP);
malloc_type_detach(M_FILECOREMNT);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: filecore_vfsops.c,v 1.40 2007/07/31 21:14:17 pooka Exp $ */
/* $NetBSD: filecore_vfsops.c,v 1.41 2007/09/24 00:42:13 rumble Exp $ */
/*-
* Copyright (c) 1994 The Regents of the University of California.
@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.40 2007/07/31 21:14:17 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.41 2007/09/24 00:42:13 rumble Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@ -96,6 +96,8 @@ __KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.40 2007/07/31 21:14:17 pooka E
MALLOC_JUSTDEFINE(M_FILECOREMNT,
"filecore mount", "Filecore FS mount structures");
MALLOC_JUSTDEFINE(M_FILECORETMP,
"filecore temp", "Filecore FS temporary structures");
extern const struct vnodeopv_desc filecore_vnodeop_opv_desc;

View File

@ -1,4 +1,4 @@
/* $NetBSD: filecore_vnops.c,v 1.21 2007/07/29 21:17:41 rumble Exp $ */
/* $NetBSD: filecore_vnops.c,v 1.22 2007/09/24 00:42:13 rumble Exp $ */
/*-
* Copyright (c) 1994 The Regents of the University of California.
@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: filecore_vnops.c,v 1.21 2007/07/29 21:17:41 rumble Exp $");
__KERNEL_RCSID(0, "$NetBSD: filecore_vnops.c,v 1.22 2007/09/24 00:42:13 rumble Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -286,7 +286,7 @@ filecore_readdir(v)
struct filecore_node *dp;
struct filecore_mnt *fcmp;
struct buf *bp = NULL;
struct dirent de;
struct dirent *de;
struct filecore_direntry *dep = NULL;
int error = 0;
off_t *cookies = NULL;
@ -321,42 +321,44 @@ filecore_readdir(v)
cookies = malloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK);
}
de = malloc(sizeof(struct dirent), M_FILECORETMP, M_WAITOK | M_ZERO);
for (; ; i++) {
switch (i) {
case 0:
/* Fake the '.' entry */
de.d_fileno = dp->i_number;
de.d_type = DT_DIR;
de.d_namlen = 1;
strlcpy(de.d_name, ".", sizeof(de.d_name));
de->d_fileno = dp->i_number;
de->d_type = DT_DIR;
de->d_namlen = 1;
strlcpy(de->d_name, ".", sizeof(de->d_name));
break;
case 1:
/* Fake the '..' entry */
de.d_fileno = filecore_getparent(dp);
de.d_type = DT_DIR;
de.d_namlen = 2;
strlcpy(de.d_name, "..", sizeof(de.d_name));
de->d_fileno = filecore_getparent(dp);
de->d_type = DT_DIR;
de->d_namlen = 2;
strlcpy(de->d_name, "..", sizeof(de->d_name));
break;
default:
de.d_fileno = dp->i_dirent.addr +
de->d_fileno = dp->i_dirent.addr +
((i - 2) << FILECORE_INO_INDEX);
dep = fcdirentry(bp->b_data, i - 2);
if (dep->attr & FILECORE_ATTR_DIR)
de.d_type = DT_DIR;
de->d_type = DT_DIR;
else
de.d_type = DT_REG;
if (filecore_fn2unix(dep->name, de.d_name,
de->d_type = DT_REG;
if (filecore_fn2unix(dep->name, de->d_name,
/*###346 [cc] warning: passing arg 3 of `filecore_fn2unix' from incompatible pointer type%%%*/
&de.d_namlen)) {
&de->d_namlen)) {
*ap->a_eofflag = 1;
goto out;
}
break;
}
de.d_reclen = _DIRENT_SIZE(&de);
if (uio->uio_resid < de.d_reclen)
de->d_reclen = _DIRENT_SIZE(de);
if (uio->uio_resid < de->d_reclen)
goto out;
error = uiomove(&de, de.d_reclen, uio);
error = uiomove(de, de->d_reclen, uio);
if (error)
goto out;
uiooff += FILECORE_DIRENT_SIZE;
@ -383,6 +385,8 @@ out:
#endif
brelse (bp);
free(de, M_FILECORETMP);
return (error);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfs_denode.c,v 1.22 2007/07/23 11:05:47 pooka Exp $ */
/* $NetBSD: msdosfs_denode.c,v 1.23 2007/09/24 00:42:13 rumble Exp $ */
/*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: msdosfs_denode.c,v 1.22 2007/07/23 11:05:47 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: msdosfs_denode.c,v 1.23 2007/09/24 00:42:13 rumble Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -101,6 +101,7 @@ msdosfs_init()
malloc_type_attach(M_MSDOSFSMNT);
malloc_type_attach(M_MSDOSFSFAT);
malloc_type_attach(M_MSDOSFSTMP);
pool_init(&msdosfs_denode_pool, sizeof(struct denode), 0, 0, 0,
"msdosnopl", &pool_allocator_nointr, IPL_NONE);
dehashtbl = hashinit(desiredvnodes / 2, HASH_LIST, M_MSDOSFSMNT,
@ -145,6 +146,7 @@ msdosfs_done()
{
hashdone(dehashtbl, M_MSDOSFSMNT);
pool_destroy(&msdosfs_denode_pool);
malloc_type_detach(M_MSDOSFSTMP);
malloc_type_detach(M_MSDOSFSFAT);
malloc_type_detach(M_MSDOSFSMNT);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfs_vfsops.c,v 1.50 2007/07/31 21:14:17 pooka Exp $ */
/* $NetBSD: msdosfs_vfsops.c,v 1.51 2007/09/24 00:42:13 rumble Exp $ */
/*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.50 2007/07/31 21:14:17 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.51 2007/09/24 00:42:13 rumble Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@ -101,6 +101,7 @@ static int update_mp(struct mount *, struct msdosfs_args *);
MALLOC_JUSTDEFINE(M_MSDOSFSMNT, "MSDOSFS mount", "MSDOS FS mount structure");
MALLOC_JUSTDEFINE(M_MSDOSFSFAT, "MSDOSFS fat", "MSDOS FS fat table");
MALLOC_JUSTDEFINE(M_MSDOSFSTMP, "MSDOSFS temp", "MSDOS FS temp. structures");
#define ROOTNAME "root_device"

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfs_vnops.c,v 1.40 2007/07/29 21:17:41 rumble Exp $ */
/* $NetBSD: msdosfs_vnops.c,v 1.41 2007/09/24 00:42:13 rumble Exp $ */
/*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.40 2007/07/29 21:17:41 rumble Exp $");
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.41 2007/09/24 00:42:13 rumble Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -1428,7 +1428,7 @@ msdosfs_readdir(v)
struct denode *dep = VTODE(ap->a_vp);
struct msdosfsmount *pmp = dep->de_pmp;
struct direntry *dentp;
struct dirent dirbuf;
struct dirent *dirbuf;
struct uio *uio = ap->a_uio;
off_t *cookies = NULL;
int ncookies = 0, nc = 0;
@ -1449,11 +1449,6 @@ msdosfs_readdir(v)
if ((dep->de_Attributes & ATTR_DIRECTORY) == 0)
return (ENOTDIR);
/*
* To be safe, initialize dirbuf
*/
memset(dirbuf.d_name, 0, sizeof(dirbuf.d_name));
/*
* If the user buffer is smaller than the size of one dos directory
* entry or the file offset is not a multiple of the size of a
@ -1467,6 +1462,9 @@ msdosfs_readdir(v)
lost = uio->uio_resid - count;
uio->uio_resid = count;
uio_off = uio->uio_offset;
/* Allocate a temporary dirent buffer. */
dirbuf = malloc(sizeof(struct dirent), M_MSDOSFSTMP, M_WAITOK | M_ZERO);
if (ap->a_ncookies) {
nc = uio->uio_resid / _DIRENT_MINSIZE((struct dirent *)0);
@ -1494,29 +1492,28 @@ msdosfs_readdir(v)
for (n = (int)offset / sizeof(struct direntry);
n < 2; n++) {
if (FAT32(pmp))
dirbuf.d_fileno = cntobn(pmp,
dirbuf->d_fileno = cntobn(pmp,
(ino_t)pmp->pm_rootdirblk)
* dirsperblk;
else
dirbuf.d_fileno = 1;
dirbuf.d_type = DT_DIR;
dirbuf->d_fileno = 1;
dirbuf->d_type = DT_DIR;
switch (n) {
case 0:
dirbuf.d_namlen = 1;
strlcpy(dirbuf.d_name, ".",
sizeof(dirbuf.d_name));
dirbuf->d_namlen = 1;
strlcpy(dirbuf->d_name, ".",
sizeof(dirbuf->d_name));
break;
case 1:
dirbuf.d_namlen = 2;
strlcpy(dirbuf.d_name, "..",
sizeof(dirbuf.d_name));
dirbuf->d_namlen = 2;
strlcpy(dirbuf->d_name, "..",
sizeof(dirbuf->d_name));
break;
}
dirbuf.d_reclen = _DIRENT_SIZE(&dirbuf);
if (uio->uio_resid < dirbuf.d_reclen)
dirbuf->d_reclen = _DIRENT_SIZE(dirbuf);
if (uio->uio_resid < dirbuf->d_reclen)
goto out;
error = uiomove(&dirbuf,
dirbuf.d_reclen, uio);
error = uiomove(dirbuf, dirbuf->d_reclen, uio);
if (error)
goto out;
offset += sizeof(struct direntry);
@ -1545,6 +1542,7 @@ msdosfs_readdir(v)
NOCRED, &bp);
if (error) {
brelse(bp);
free(dirbuf, M_MSDOSFSTMP);
return (error);
}
n = MIN(n, blsize - bp->b_resid);
@ -1582,7 +1580,8 @@ msdosfs_readdir(v)
if (dentp->deAttributes == ATTR_WIN95) {
if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
continue;
chksum = win2unixfn((struct winentry *)dentp, &dirbuf, chksum);
chksum = win2unixfn((struct winentry *)dentp,
dirbuf, chksum);
continue;
}
@ -1612,26 +1611,26 @@ msdosfs_readdir(v)
fileno = 1;
else
fileno = cntobn(pmp, fileno) * dirsperblk;
dirbuf.d_fileno = fileno;
dirbuf.d_type = DT_DIR;
dirbuf->d_fileno = fileno;
dirbuf->d_type = DT_DIR;
} else {
dirbuf.d_fileno = offset / sizeof(struct direntry);
dirbuf.d_type = DT_REG;
dirbuf->d_fileno =
offset / sizeof(struct direntry);
dirbuf->d_type = DT_REG;
}
if (chksum != winChksum(dentp->deName))
dirbuf.d_namlen = dos2unixfn(dentp->deName,
(u_char *)dirbuf.d_name,
dirbuf->d_namlen = dos2unixfn(dentp->deName,
(u_char *)dirbuf->d_name,
pmp->pm_flags & MSDOSFSMNT_SHORTNAME);
else
dirbuf.d_name[dirbuf.d_namlen] = 0;
dirbuf->d_name[dirbuf->d_namlen] = 0;
chksum = -1;
dirbuf.d_reclen = _DIRENT_SIZE(&dirbuf);
if (uio->uio_resid < dirbuf.d_reclen) {
dirbuf->d_reclen = _DIRENT_SIZE(dirbuf);
if (uio->uio_resid < dirbuf->d_reclen) {
brelse(bp);
goto out;
}
error = uiomove(&dirbuf,
dirbuf.d_reclen, uio);
error = uiomove(dirbuf, dirbuf->d_reclen, uio);
if (error) {
brelse(bp);
goto out;
@ -1665,6 +1664,7 @@ out:
} else
*ap->a_ncookies = ncookies;
}
free(dirbuf, M_MSDOSFSTMP);
return (error);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfsmount.h,v 1.13 2007/03/04 06:03:00 christos Exp $ */
/* $NetBSD: msdosfsmount.h,v 1.14 2007/09/24 00:42:14 rumble Exp $ */
/*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@ -93,6 +93,7 @@ struct msdosfs_args {
#ifdef _KERNEL
#include <sys/mallocvar.h>
MALLOC_DECLARE(M_MSDOSFSMNT);
MALLOC_DECLARE(M_MSDOSFSTMP);
/*
* Layout of the mount control block for a msdos file system.

View File

@ -1,4 +1,4 @@
/* $NetBSD: ptyfs_vfsops.c,v 1.28 2007/07/31 21:14:18 pooka Exp $ */
/* $NetBSD: ptyfs_vfsops.c,v 1.29 2007/09/24 00:42:14 rumble Exp $ */
/*
* Copyright (c) 1992, 1993, 1995
@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ptyfs_vfsops.c,v 1.28 2007/07/31 21:14:18 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: ptyfs_vfsops.c,v 1.29 2007/09/24 00:42:14 rumble Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -62,6 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: ptyfs_vfsops.c,v 1.28 2007/07/31 21:14:18 pooka Exp
#include <miscfs/specfs/specdev.h>
MALLOC_JUSTDEFINE(M_PTYFSMNT, "ptyfs mount", "ptyfs mount structures");
MALLOC_JUSTDEFINE(M_PTYFSTMP, "ptyfs temp", "ptyfs temporary structures");
VFS_PROTOS(ptyfs);
@ -180,6 +181,7 @@ ptyfs_init(void)
{
malloc_type_attach(M_PTYFSMNT);
malloc_type_attach(M_PTYFSTMP);
ptyfs_hashinit();
}
@ -194,6 +196,7 @@ ptyfs_done(void)
{
ptyfs_hashdone();
malloc_type_detach(M_PTYFSTMP);
malloc_type_detach(M_PTYFSMNT);
}
@ -237,7 +240,7 @@ ptyfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len,
if (args->version != PTYFS_ARGSVERSION)
return EINVAL;
pmnt = malloc(sizeof(struct ptyfsmount), M_UFSMNT, M_WAITOK);
pmnt = malloc(sizeof(struct ptyfsmount), M_PTYFSMNT, M_WAITOK);
mp->mnt_data = pmnt;
pmnt->pmnt_gid = args->gid;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ptyfs_vnops.c,v 1.23 2007/07/09 21:10:48 ad Exp $ */
/* $NetBSD: ptyfs_vnops.c,v 1.24 2007/09/24 00:42:14 rumble Exp $ */
/*
* Copyright (c) 1993, 1995
@ -76,7 +76,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ptyfs_vnops.c,v 1.23 2007/07/09 21:10:48 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: ptyfs_vnops.c,v 1.24 2007/09/24 00:42:14 rumble Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -106,6 +106,8 @@ __KERNEL_RCSID(0, "$NetBSD: ptyfs_vnops.c,v 1.23 2007/07/09 21:10:48 ad Exp $");
#include <miscfs/genfs/genfs.h>
#include <miscfs/specfs/specdev.h>
MALLOC_DECLARE(M_PTYFSTMP);
/*
* Vnode Operations.
*
@ -626,7 +628,7 @@ ptyfs_readdir(void *v)
int *a_ncookies;
} */ *ap = v;
struct uio *uio = ap->a_uio;
struct dirent d;
struct dirent *dp;
struct ptyfsnode *ptyfs;
off_t i;
int error;
@ -643,10 +645,11 @@ ptyfs_readdir(void *v)
if (uio->uio_offset < 0)
return EINVAL;
dp = malloc(sizeof(struct dirent), M_PTYFSTMP, M_WAITOK | M_ZERO);
error = 0;
i = uio->uio_offset;
(void)memset(&d, 0, sizeof(d));
d.d_reclen = UIO_MX;
dp->d_reclen = UIO_MX;
ncookies = uio->uio_resid / UIO_MX;
switch (ptyfs->ptyfs_type) {
@ -666,14 +669,14 @@ ptyfs_readdir(void *v)
switch (i) {
case 0: /* `.' */
case 1: /* `..' */
d.d_fileno = PTYFS_FILENO(0, PTYFSroot);
d.d_namlen = i + 1;
(void)memcpy(d.d_name, "..", d.d_namlen);
d.d_name[i + 1] = '\0';
d.d_type = DT_DIR;
dp->d_fileno = PTYFS_FILENO(0, PTYFSroot);
dp->d_namlen = i + 1;
(void)memcpy(dp->d_name, "..", dp->d_namlen);
dp->d_name[i + 1] = '\0';
dp->d_type = DT_DIR;
break;
}
if ((error = uiomove(&d, UIO_MX, uio)) != 0)
if ((error = uiomove(dp, UIO_MX, uio)) != 0)
break;
if (cookies)
*cookies++ = i + 1;
@ -688,11 +691,11 @@ ptyfs_readdir(void *v)
if (pty_isfree(i - 2, 1))
continue;
d.d_fileno = PTYFS_FILENO(i - 2, PTYFSpts);
d.d_namlen = snprintf(d.d_name, sizeof(d.d_name),
dp->d_fileno = PTYFS_FILENO(i - 2, PTYFSpts);
dp->d_namlen = snprintf(dp->d_name, sizeof(dp->d_name),
"%lld", (long long)(i - 2));
d.d_type = DT_CHR;
if ((error = uiomove(&d, UIO_MX, uio)) != 0)
dp->d_type = DT_CHR;
if ((error = uiomove(dp, UIO_MX, uio)) != 0)
break;
if (cookies)
*cookies++ = i + 1;
@ -716,6 +719,7 @@ ptyfs_readdir(void *v)
*ap->a_ncookies = ncookies;
}
uio->uio_offset = i;
free(dp, M_PTYFSTMP);
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: smbfs_io.c,v 1.26 2007/07/29 13:31:10 ad Exp $ */
/* $NetBSD: smbfs_io.c,v 1.27 2007/09/24 00:42:14 rumble Exp $ */
/*
* Copyright (c) 2000-2001, Boris Popov
@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: smbfs_io.c,v 1.26 2007/07/29 13:31:10 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: smbfs_io.c,v 1.27 2007/09/24 00:42:14 rumble Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -46,6 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: smbfs_io.c,v 1.26 2007/07/29 13:31:10 ad Exp $");
#include <sys/fcntl.h>
#include <sys/buf.h>
#include <sys/mount.h>
#include <sys/malloc.h>
#include <sys/namei.h>
#include <sys/vnode.h>
#include <sys/dirent.h>
@ -87,7 +88,7 @@ __KERNEL_RCSID(0, "$NetBSD: smbfs_io.c,v 1.26 2007/07/29 13:31:10 ad Exp $");
static int
smbfs_readvdir(struct vnode *vp, struct uio *uio, kauth_cred_t cred)
{
struct dirent de;
struct dirent *de;
struct smb_cred scred;
struct smbfs_fctx *ctx;
struct smbnode *np = VTOSMB(vp);
@ -99,6 +100,8 @@ smbfs_readvdir(struct vnode *vp, struct uio *uio, kauth_cred_t cred)
if (uio->uio_resid < DE_SIZE || uio->uio_offset < 0)
return EINVAL;
de = malloc(DE_SIZE, M_SMBFSDATA, M_WAITOK | M_ZERO);
SMBVDEBUG("dirname='%.*s'\n", (int) np->n_nmlen, np->n_name);
smb_makescred(&scred, curlwp, cred);
offset = uio->uio_offset / DE_SIZE; /* offset in the directory */
@ -106,35 +109,35 @@ smbfs_readvdir(struct vnode *vp, struct uio *uio, kauth_cred_t cred)
/* Simulate . */
if (offset < 1) {
memset(&de, 0, sizeof(de));
de.d_fileno = np->n_ino;
de.d_reclen = DE_SIZE;
de.d_type = DT_DIR;
de.d_namlen = 1;
strncpy(de.d_name, ".", 2);
error = uiomove(&de, sizeof(struct dirent), uio);
memset(de, 0, DE_SIZE);
de->d_fileno = np->n_ino;
de->d_reclen = DE_SIZE;
de->d_type = DT_DIR;
de->d_namlen = 1;
strncpy(de->d_name, ".", 2);
error = uiomove(de, DE_SIZE, uio);
if (error)
return error;
goto out;
limit--;
offset++;
}
/* Simulate .. */
if (limit > 0 && offset < 2) {
memset(&de, 0, sizeof(de));
de.d_fileno = (np->n_parent ? VTOSMB(np->n_parent)->n_ino : 2);
de.d_reclen = DE_SIZE;
de.d_type = DT_DIR;
de.d_namlen = 2;
strncpy(de.d_name, "..", 3);
error = uiomove(&de, sizeof(struct dirent), uio);
memset(de, 0, DE_SIZE);
de->d_fileno = (np->n_parent ? VTOSMB(np->n_parent)->n_ino : 2);
de->d_reclen = DE_SIZE;
de->d_type = DT_DIR;
de->d_namlen = 2;
strncpy(de->d_name, "..", 3);
error = uiomove(de, DE_SIZE, uio);
if (error)
return error;
goto out;
limit--;
offset++;
}
if (limit == 0)
return (0);
goto out;
if (offset != np->n_dirofs || np->n_dirseq == NULL) {
SMBVDEBUG("Reopening search %ld:%ld\n", offset, np->n_dirofs);
@ -148,7 +151,7 @@ smbfs_readvdir(struct vnode *vp, struct uio *uio, kauth_cred_t cred)
&scred, &ctx);
if (error) {
SMBVDEBUG("can not open search, error = %d", error);
return error;
goto out;
}
np->n_dirseq = ctx;
} else
@ -160,7 +163,8 @@ smbfs_readvdir(struct vnode *vp, struct uio *uio, kauth_cred_t cred)
if (error) {
smbfs_findclose(np->n_dirseq, &scred);
np->n_dirseq = NULL;
return (error == ENOENT) ? 0 : error;
error = (error == ENOENT) ? 0 : error;
goto out;
}
}
@ -172,18 +176,21 @@ smbfs_readvdir(struct vnode *vp, struct uio *uio, kauth_cred_t cred)
break;
}
np->n_dirofs++;
memset(&de, 0, DE_SIZE);
de.d_reclen = DE_SIZE;
de.d_fileno = ctx->f_attr.fa_ino;
de.d_type = (ctx->f_attr.fa_attr & SMB_FA_DIR) ? DT_DIR : DT_REG;
de.d_namlen = ctx->f_nmlen;
memcpy(de.d_name, ctx->f_name, de.d_namlen);
de.d_name[de.d_namlen] = '\0';
error = uiomove(&de, DE_SIZE, uio);
memset(de, 0, DE_SIZE);
de->d_reclen = DE_SIZE;
de->d_fileno = ctx->f_attr.fa_ino;
de->d_type = (ctx->f_attr.fa_attr & SMB_FA_DIR) ?
DT_DIR : DT_REG;
de->d_namlen = ctx->f_nmlen;
memcpy(de->d_name, ctx->f_name, de->d_namlen);
de->d_name[de->d_namlen] = '\0';
error = uiomove(de, DE_SIZE, uio);
if (error)
break;
}
out:
free(de, M_SMBFSDATA);
return (error);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysvbfs_vnops.c,v 1.13 2007/07/29 13:31:10 ad Exp $ */
/* $NetBSD: sysvbfs_vnops.c,v 1.14 2007/09/24 00:42:14 rumble Exp $ */
/*-
* Copyright (c) 2004 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sysvbfs_vnops.c,v 1.13 2007/07/29 13:31:10 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: sysvbfs_vnops.c,v 1.14 2007/09/24 00:42:14 rumble Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -62,6 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: sysvbfs_vnops.c,v 1.13 2007/07/29 13:31:10 ad Exp $"
#define ROUND_SECTOR(x) (((x) + 511) & ~511)
MALLOC_JUSTDEFINE(M_SYSVBFS_VNODE, "sysvbfs vnode", "sysvbfs vnode structures");
MALLOC_DECLARE(M_BFS);
int
sysvbfs_lookup(void *arg)
@ -527,7 +528,7 @@ sysvbfs_readdir(void *v)
struct vnode *vp = ap->a_vp;
struct sysvbfs_node *bnode = vp->v_data;
struct bfs *bfs = bnode->bmp->bfs;
struct dirent d;
struct dirent *dp;
struct bfs_dirent *file;
int i, n, error;
@ -537,6 +538,8 @@ sysvbfs_readdir(void *v)
KDASSERT(vp->v_type == VDIR);
KDASSERT(uio->uio_offset >= 0);
dp = malloc(sizeof(struct dirent), M_BFS, M_WAITOK | M_ZERO);
i = uio->uio_offset / sizeof(struct dirent);
n = uio->uio_resid / sizeof(struct dirent);
if ((i + n) > bfs->n_dirent)
@ -551,20 +554,22 @@ sysvbfs_readdir(void *v)
break;
}
i++;
memset(&d, 0, sizeof d);
d.d_fileno = file->inode;
d.d_type = file->inode == BFS_ROOT_INODE ? DT_DIR : DT_REG;
d.d_namlen = strlen(file->name);
strncpy(d.d_name, file->name, BFS_FILENAME_MAXLEN);
d.d_reclen = sizeof(struct dirent);
if ((error = uiomove(&d, d.d_reclen, uio)) != 0) {
memset(dp, 0, sizeof(struct dirent));
dp->d_fileno = file->inode;
dp->d_type = file->inode == BFS_ROOT_INODE ? DT_DIR : DT_REG;
dp->d_namlen = strlen(file->name);
strncpy(dp->d_name, file->name, BFS_FILENAME_MAXLEN);
dp->d_reclen = sizeof(struct dirent);
if ((error = uiomove(dp, dp->d_reclen, uio)) != 0) {
DPRINTF("%s: uiomove failed.\n", __FUNCTION__);
free(dp, M_BFS);
return error;
}
}
DPRINTF("%s: %d %d %d\n", __FUNCTION__, i, n, bfs->n_dirent);
*ap->a_eofflag = i == bfs->n_dirent;
*ap->a_eofflag = (i == bfs->n_dirent);
free(dp, M_BFS);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs_subr.c,v 1.36 2007/08/06 16:08:55 pooka Exp $ */
/* $NetBSD: tmpfs_subr.c,v 1.37 2007/09/24 00:42:15 rumble Exp $ */
/*
* Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.36 2007/08/06 16:08:55 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.37 2007/09/24 00:42:15 rumble Exp $");
#include <sys/param.h>
#include <sys/dirent.h>
@ -66,6 +66,8 @@ __KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.36 2007/08/06 16:08:55 pooka Exp $"
#include <fs/tmpfs/tmpfs_specops.h>
#include <fs/tmpfs/tmpfs_vnops.h>
MALLOC_DECLARE(M_TMPFSTMP);
/* --------------------------------------------------------------------- */
/*
@ -660,28 +662,31 @@ int
tmpfs_dir_getdotdent(struct tmpfs_node *node, struct uio *uio)
{
int error;
struct dirent dent;
struct dirent *dentp;
TMPFS_VALIDATE_DIR(node);
KASSERT(uio->uio_offset == TMPFS_DIRCOOKIE_DOT);
dent.d_fileno = node->tn_id;
dent.d_type = DT_DIR;
dent.d_namlen = 1;
dent.d_name[0] = '.';
dent.d_name[1] = '\0';
dent.d_reclen = _DIRENT_SIZE(&dent);
dentp = malloc(sizeof(struct dirent), M_TMPFSTMP, M_WAITOK | M_ZERO);
if (dent.d_reclen > uio->uio_resid)
dentp->d_fileno = node->tn_id;
dentp->d_type = DT_DIR;
dentp->d_namlen = 1;
dentp->d_name[0] = '.';
dentp->d_name[1] = '\0';
dentp->d_reclen = _DIRENT_SIZE(dentp);
if (dentp->d_reclen > uio->uio_resid)
error = -1;
else {
error = uiomove(&dent, dent.d_reclen, uio);
error = uiomove(dentp, dentp->d_reclen, uio);
if (error == 0)
uio->uio_offset = TMPFS_DIRCOOKIE_DOTDOT;
}
node->tn_status |= TMPFS_NODE_ACCESSED;
free(dentp, M_TMPFSTMP);
return error;
}
@ -698,23 +703,25 @@ int
tmpfs_dir_getdotdotdent(struct tmpfs_node *node, struct uio *uio)
{
int error;
struct dirent dent;
struct dirent *dentp;
TMPFS_VALIDATE_DIR(node);
KASSERT(uio->uio_offset == TMPFS_DIRCOOKIE_DOTDOT);
dent.d_fileno = node->tn_spec.tn_dir.tn_parent->tn_id;
dent.d_type = DT_DIR;
dent.d_namlen = 2;
dent.d_name[0] = '.';
dent.d_name[1] = '.';
dent.d_name[2] = '\0';
dent.d_reclen = _DIRENT_SIZE(&dent);
dentp = malloc(sizeof(struct dirent), M_TMPFSTMP, M_WAITOK | M_ZERO);
if (dent.d_reclen > uio->uio_resid)
dentp->d_fileno = node->tn_spec.tn_dir.tn_parent->tn_id;
dentp->d_type = DT_DIR;
dentp->d_namlen = 2;
dentp->d_name[0] = '.';
dentp->d_name[1] = '.';
dentp->d_name[2] = '\0';
dentp->d_reclen = _DIRENT_SIZE(dentp);
if (dentp->d_reclen > uio->uio_resid)
error = -1;
else {
error = uiomove(&dent, dent.d_reclen, uio);
error = uiomove(dentp, dentp->d_reclen, uio);
if (error == 0) {
struct tmpfs_dirent *de;
@ -728,6 +735,7 @@ tmpfs_dir_getdotdotdent(struct tmpfs_node *node, struct uio *uio)
node->tn_status |= TMPFS_NODE_ACCESSED;
free(dentp, M_TMPFSTMP);
return error;
}
@ -769,6 +777,7 @@ tmpfs_dir_getdents(struct tmpfs_node *node, struct uio *uio, off_t *cntp)
{
int error;
off_t startcookie;
struct dirent *dentp;
struct tmpfs_dirent *de;
TMPFS_VALIDATE_DIR(node);
@ -788,62 +797,62 @@ tmpfs_dir_getdents(struct tmpfs_node *node, struct uio *uio, off_t *cntp)
return EINVAL;
}
dentp = malloc(sizeof(struct dirent), M_TMPFSTMP, M_WAITOK | M_ZERO);
/* Read as much entries as possible; i.e., until we reach the end of
* the directory or we exhaust uio space. */
do {
struct dirent d;
/* Create a dirent structure representing the current
* tmpfs_node and fill it. */
d.d_fileno = de->td_node->tn_id;
dentp->d_fileno = de->td_node->tn_id;
switch (de->td_node->tn_type) {
case VBLK:
d.d_type = DT_BLK;
dentp->d_type = DT_BLK;
break;
case VCHR:
d.d_type = DT_CHR;
dentp->d_type = DT_CHR;
break;
case VDIR:
d.d_type = DT_DIR;
dentp->d_type = DT_DIR;
break;
case VFIFO:
d.d_type = DT_FIFO;
dentp->d_type = DT_FIFO;
break;
case VLNK:
d.d_type = DT_LNK;
dentp->d_type = DT_LNK;
break;
case VREG:
d.d_type = DT_REG;
dentp->d_type = DT_REG;
break;
case VSOCK:
d.d_type = DT_SOCK;
dentp->d_type = DT_SOCK;
break;
default:
KASSERT(0);
}
d.d_namlen = de->td_namelen;
KASSERT(de->td_namelen < sizeof(d.d_name));
(void)memcpy(d.d_name, de->td_name, de->td_namelen);
d.d_name[de->td_namelen] = '\0';
d.d_reclen = _DIRENT_SIZE(&d);
dentp->d_namlen = de->td_namelen;
KASSERT(de->td_namelen < sizeof(dentp->d_name));
(void)memcpy(dentp->d_name, de->td_name, de->td_namelen);
dentp->d_name[de->td_namelen] = '\0';
dentp->d_reclen = _DIRENT_SIZE(dentp);
/* Stop reading if the directory entry we are treating is
* bigger than the amount of data that can be returned. */
if (d.d_reclen > uio->uio_resid) {
if (dentp->d_reclen > uio->uio_resid) {
error = -1;
break;
}
/* Copy the new dirent structure into the output buffer and
* advance pointers. */
error = uiomove(&d, d.d_reclen, uio);
error = uiomove(dentp, dentp->d_reclen, uio);
(*cntp)++;
de = TAILQ_NEXT(de, td_entries);
@ -862,6 +871,7 @@ tmpfs_dir_getdents(struct tmpfs_node *node, struct uio *uio, off_t *cntp)
node->tn_status |= TMPFS_NODE_ACCESSED;
free(dentp, M_TMPFSTMP);
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs_vfsops.c,v 1.27 2007/08/03 13:00:19 pooka Exp $ */
/* $NetBSD: tmpfs_vfsops.c,v 1.28 2007/09/24 00:42:15 rumble Exp $ */
/*
* Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
@ -49,7 +49,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.27 2007/08/03 13:00:19 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.28 2007/09/24 00:42:15 rumble Exp $");
#include <sys/param.h>
#include <sys/types.h>
@ -63,6 +63,7 @@ __KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.27 2007/08/03 13:00:19 pooka Exp
#include <fs/tmpfs/tmpfs.h>
MALLOC_JUSTDEFINE(M_TMPFSMNT, "tmpfs mount", "tmpfs mount structures");
MALLOC_JUSTDEFINE(M_TMPFSTMP, "tmpfs temp", "tmpfs temporary structures");
/* --------------------------------------------------------------------- */
@ -410,6 +411,7 @@ tmpfs_init(void)
{
malloc_type_attach(M_TMPFSMNT);
malloc_type_attach(M_TMPFSTMP);
}
/* --------------------------------------------------------------------- */
@ -418,6 +420,7 @@ static void
tmpfs_done(void)
{
malloc_type_attach(M_TMPFSTMP);
malloc_type_detach(M_TMPFSMNT);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: udf_subr.c,v 1.36 2007/07/29 13:31:11 ad Exp $ */
/* $NetBSD: udf_subr.c,v 1.37 2007/09/24 00:42:15 rumble Exp $ */
/*
* Copyright (c) 2006 Reinoud Zandijk
@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: udf_subr.c,v 1.36 2007/07/29 13:31:11 ad Exp $");
__RCSID("$NetBSD: udf_subr.c,v 1.37 2007/09/24 00:42:15 rumble Exp $");
#endif /* not lint */
@ -2443,7 +2443,7 @@ udf_lookup_name_in_dir(struct vnode *vp, const char *name, int namelen,
struct file_entry *fe;
struct extfile_entry *efe;
struct fileid_desc *fid;
struct dirent dirent;
struct dirent *dirent;
uint64_t file_size, diroffset;
uint32_t lb_size;
int found, error;
@ -2460,7 +2460,7 @@ udf_lookup_name_in_dir(struct vnode *vp, const char *name, int namelen,
/* allocate temporary space for fid */
lb_size = udf_rw32(dir_node->ump->logical_vol->lb_size);
fid = malloc(lb_size, M_TEMP, M_WAITOK);
fid = malloc(lb_size, M_UDFTEMP, M_WAITOK);
found = 0;
diroffset = dir_node->last_diroffset;
@ -2473,20 +2473,22 @@ udf_lookup_name_in_dir(struct vnode *vp, const char *name, int namelen,
diroffset = dir_node->last_diroffset = file_size;
}
dirent = malloc(sizeof(struct dirent), M_UDFTEMP, M_WAITOK);
while (!found) {
/* if at the end, go trough zero */
if (diroffset >= file_size)
diroffset = 0;
/* transfer a new fid/dirent */
error = udf_read_fid_stream(vp, &diroffset, fid, &dirent);
error = udf_read_fid_stream(vp, &diroffset, fid, dirent);
if (error)
break;
/* skip deleted entries */
if ((fid->file_char & UDF_FILE_CHAR_DEL) == 0) {
if ((strlen(dirent.d_name) == namelen) &&
(strncmp(dirent.d_name, name, namelen) == 0)) {
if ((strlen(dirent->d_name) == namelen) &&
(strncmp(dirent->d_name, name, namelen) == 0)) {
found = 1;
*icb_loc = fid->icb;
}
@ -2497,7 +2499,8 @@ udf_lookup_name_in_dir(struct vnode *vp, const char *name, int namelen,
break;
}
}
free(fid, M_TEMP);
free(fid, M_UDFTEMP);
free(dirent, M_UDFTEMP);
dir_node->last_diroffset = diroffset;
return found;
@ -2777,7 +2780,7 @@ udf_read_filebuf(struct udf_node *node, struct buf *buf)
return;
}
mapping = malloc(sizeof(*mapping) * FILEBUFSECT, M_TEMP, M_WAITOK);
mapping = malloc(sizeof(*mapping) * FILEBUFSECT, M_UDFTEMP, M_WAITOK);
error = 0;
DPRINTF(READ, ("\ttranslate %d-%d\n", from, sectors));
@ -2850,7 +2853,7 @@ udf_read_filebuf(struct udf_node *node, struct buf *buf)
}
out:
DPRINTF(READ, ("\tend of read_filebuf\n"));
free(mapping, M_TEMP);
free(mapping, M_UDFTEMP);
return;
}
#undef FILEBUFSECT

View File

@ -1,4 +1,4 @@
/* $NetBSD: udf_vnops.c,v 1.10 2007/04/29 20:23:36 msaitoh Exp $ */
/* $NetBSD: udf_vnops.c,v 1.11 2007/09/24 00:42:15 rumble Exp $ */
/*
* Copyright (c) 2006 Reinoud Zandijk
@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: udf_vnops.c,v 1.10 2007/04/29 20:23:36 msaitoh Exp $");
__RCSID("$NetBSD: udf_vnops.c,v 1.11 2007/09/24 00:42:15 rumble Exp $");
#endif /* not lint */
@ -349,7 +349,7 @@ udf_readdir(void *v)
struct file_entry *fe;
struct extfile_entry *efe;
struct fileid_desc *fid;
struct dirent dirent;
struct dirent *dirent;
uint64_t file_size, diroffset, transoffset;
uint32_t lb_size;
int error;
@ -370,19 +370,20 @@ udf_readdir(void *v)
file_size = udf_rw64(efe->inf_len);
}
dirent = malloc(sizeof(struct dirent), M_UDFTEMP, M_WAITOK | M_ZERO);
/*
* Add `.' pseudo entry if at offset zero since its not in the fid
* stream
*/
if (uio->uio_offset == 0) {
DPRINTF(READDIR, ("\t'.' inserted\n"));
memset(&dirent, 0, sizeof(struct dirent));
strcpy(dirent.d_name, ".");
dirent.d_fileno = udf_calchash(&udf_node->loc);
dirent.d_type = DT_DIR;
dirent.d_namlen = strlen(dirent.d_name);
dirent.d_reclen = _DIRENT_SIZE(&dirent);
uiomove(&dirent, _DIRENT_SIZE(&dirent), uio);
strcpy(dirent->d_name, ".");
dirent->d_fileno = udf_calchash(&udf_node->loc);
dirent->d_type = DT_DIR;
dirent->d_namlen = strlen(dirent->d_name);
dirent->d_reclen = _DIRENT_SIZE(dirent);
uiomove(dirent, _DIRENT_SIZE(dirent), uio);
/* mark with magic value that we have done the dummy */
uio->uio_offset = UDF_DIRCOOKIE_DOT;
@ -394,7 +395,7 @@ udf_readdir(void *v)
(uio->uio_resid >= sizeof(struct dirent))) {
/* allocate temporary space for fid */
lb_size = udf_rw32(udf_node->ump->logical_vol->lb_size);
fid = malloc(lb_size, M_TEMP, M_WAITOK);
fid = malloc(lb_size, M_UDFTEMP, M_WAITOK);
if (uio->uio_offset == UDF_DIRCOOKIE_DOT)
uio->uio_offset = 0;
@ -405,7 +406,7 @@ udf_readdir(void *v)
DPRINTF(READDIR, ("\tread in fid stream\n"));
/* transfer a new fid/dirent */
error = udf_read_fid_stream(vp, &diroffset,
fid, &dirent);
fid, dirent);
DPRINTFIF(READDIR, error, ("read error in read fid "
"stream : %d\n", error));
if (error)
@ -415,7 +416,7 @@ udf_readdir(void *v)
* If there isn't enough space in the uio to return a
* whole dirent, break off read
*/
if (uio->uio_resid < _DIRENT_SIZE(&dirent))
if (uio->uio_resid < _DIRENT_SIZE(dirent))
break;
/* remember the last entry we transfered */
@ -431,13 +432,13 @@ udf_readdir(void *v)
/* copy dirent to the caller */
DPRINTF(READDIR, ("\tread dirent `%s', type %d\n",
dirent.d_name, dirent.d_type));
uiomove(&dirent, _DIRENT_SIZE(&dirent), uio);
dirent->d_name, dirent->d_type));
uiomove(dirent, _DIRENT_SIZE(dirent), uio);
}
/* pass on last transfered offset */
uio->uio_offset = transoffset;
free(fid, M_TEMP);
free(fid, M_UDFTEMP);
}
if (ap->a_eofflag)
@ -453,6 +454,7 @@ udf_readdir(void *v)
}
#endif
free(dirent, M_UDFTEMP);
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ext2fs_lookup.c,v 1.51 2007/07/21 19:06:22 ad Exp $ */
/* $NetBSD: ext2fs_lookup.c,v 1.52 2007/09/24 00:42:15 rumble Exp $ */
/*
* Modified for NetBSD 1.2E
@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ext2fs_lookup.c,v 1.51 2007/07/21 19:06:22 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: ext2fs_lookup.c,v 1.52 2007/09/24 00:42:15 rumble Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -143,7 +143,7 @@ ext2fs_readdir(void *v)
struct m_ext2fs *fs = VTOI(vp)->i_e2fs;
struct ext2fs_direct *dp;
struct dirent dstd;
struct dirent *dstd;
struct uio auio;
struct iovec aiov;
void *dirbuf;
@ -168,8 +168,10 @@ ext2fs_readdir(void *v)
auio.uio_resid = e2fs_count;
UIO_SETUP_SYSSPACE(&auio);
dirbuf = malloc(e2fs_count, M_TEMP, M_WAITOK);
dstd = malloc(sizeof(struct dirent), M_TEMP, M_WAITOK | M_ZERO);
if (ap->a_ncookies) {
nc = ncookies = e2fs_count / 16;
nc = e2fs_count / _DIRENT_MINSIZE((struct dirent *)0);
ncookies = nc;
cookies = malloc(sizeof (off_t) * ncookies, M_TEMP, M_WAITOK);
*ap->a_cookies = cookies;
}
@ -186,11 +188,12 @@ ext2fs_readdir(void *v)
error = EIO;
break;
}
ext2fs_dirconv2ffs(dp, &dstd);
if(dstd.d_reclen > uio->uio_resid) {
ext2fs_dirconv2ffs(dp, dstd);
if(dstd->d_reclen > uio->uio_resid) {
break;
}
if ((error = uiomove((void *)&dstd, dstd.d_reclen, uio)) != 0) {
error = uiomove(dstd, dstd->d_reclen, uio);
if (error != 0) {
break;
}
off = off + e2d_reclen;
@ -207,6 +210,7 @@ ext2fs_readdir(void *v)
uio->uio_offset = off;
}
FREE(dirbuf, M_TEMP);
FREE(dstd, M_TEMP);
*ap->a_eofflag = ext2fs_size(VTOI(ap->a_vp)) <= uio->uio_offset;
if (ap->a_ncookies) {
if (error) {