Allocate the struct dirent in ntfs_readdir() via MALLOC(), rather than
on stack.
This commit is contained in:
parent
65f0069f5b
commit
61c37aef21
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ntfs_vnops.c,v 1.33 2001/06/20 09:14:59 jdolecek Exp $ */
|
||||
/* $NetBSD: ntfs_vnops.c,v 1.34 2001/06/26 09:24:36 jdolecek Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -584,36 +584,41 @@ ntfs_readdir(ap)
|
|||
int i, error = 0;
|
||||
u_int32_t faked = 0, num;
|
||||
int ncookies = 0;
|
||||
struct dirent cde;
|
||||
struct dirent *cde;
|
||||
off_t off;
|
||||
|
||||
dprintf(("ntfs_readdir %d off: %d resid: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid));
|
||||
|
||||
off = uio->uio_offset;
|
||||
|
||||
/* Simulate . in every dir except ROOT */
|
||||
if( ip->i_number != NTFS_ROOTINO ) {
|
||||
struct dirent dot = { NTFS_ROOTINO,
|
||||
sizeof(struct dirent), DT_DIR, 1, "." };
|
||||
MALLOC(cde, struct dirent *, sizeof(struct dirent), M_TEMP, M_WAITOK);
|
||||
|
||||
if( uio->uio_offset < sizeof(struct dirent) ) {
|
||||
dot.d_fileno = ip->i_number;
|
||||
error = uiomove((char *)&dot,sizeof(struct dirent),uio);
|
||||
/* Simulate . in every dir except ROOT */
|
||||
if (ip->i_number != NTFS_ROOTINO
|
||||
&& uio->uio_offset < sizeof(struct dirent)) {
|
||||
cde->d_fileno = ip->i_number;
|
||||
cde->d_reclen = sizeof(struct dirent);
|
||||
cde->d_type = DT_DIR;
|
||||
cde->d_namlen = 1;
|
||||
strncpy(cde->d_name, ".", 2);
|
||||
error = uiomove((void *)cde, sizeof(struct dirent), uio);
|
||||
if (error)
|
||||
return (error);
|
||||
goto out;
|
||||
|
||||
ncookies++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Simulate .. in every dir including ROOT */
|
||||
if (uio->uio_offset < 2 * sizeof(struct dirent)) {
|
||||
struct dirent dotdot = { NTFS_ROOTINO,
|
||||
sizeof(struct dirent), DT_DIR, 2, ".." };
|
||||
cde->d_fileno = ip->i_number;
|
||||
cde->d_reclen = sizeof(struct dirent);
|
||||
cde->d_type = DT_DIR;
|
||||
cde->d_namlen = 2;
|
||||
strncpy(cde->d_name, "..", 3);
|
||||
|
||||
error = uiomove((char *)&dotdot,sizeof(struct dirent),uio);
|
||||
error = uiomove((void *) cde, sizeof(struct dirent), uio);
|
||||
if (error)
|
||||
return (error);
|
||||
goto out;
|
||||
|
||||
ncookies++;
|
||||
}
|
||||
|
@ -628,9 +633,8 @@ ntfs_readdir(ap)
|
|||
int sz;
|
||||
|
||||
error = ntfs_ntreaddir(ntmp, fp, num, &iep);
|
||||
|
||||
if (error)
|
||||
return (error);
|
||||
goto out;
|
||||
|
||||
if (NULL == iep)
|
||||
break;
|
||||
|
@ -641,8 +645,8 @@ ntfs_readdir(ap)
|
|||
if(!ntfs_isnamepermitted(ntmp,iep))
|
||||
continue;
|
||||
|
||||
remains = sizeof(cde.d_name) - 1;
|
||||
fname = cde.d_name;
|
||||
remains = sizeof(cde->d_name) - 1;
|
||||
fname = cde->d_name;
|
||||
for(i=0; i<iep->ie_fnamelen; i++) {
|
||||
sz = (*ntmp->ntm_wput)(fname, remains,
|
||||
iep->ie_fname[i]);
|
||||
|
@ -653,15 +657,15 @@ ntfs_readdir(ap)
|
|||
dprintf(("ntfs_readdir: elem: %d, fname:[%s] type: %d, flag: %d, ",
|
||||
num, cde.d_name, iep->ie_fnametype,
|
||||
iep->ie_flag));
|
||||
cde.d_namlen = fname - (char *) cde.d_name;
|
||||
cde.d_fileno = iep->ie_number;
|
||||
cde.d_type = (iep->ie_fflag & NTFS_FFLAG_DIR) ? DT_DIR : DT_REG;
|
||||
cde.d_reclen = sizeof(struct dirent);
|
||||
cde->d_namlen = fname - (char *) cde->d_name;
|
||||
cde->d_fileno = iep->ie_number;
|
||||
cde->d_type = (iep->ie_fflag & NTFS_FFLAG_DIR) ? DT_DIR : DT_REG;
|
||||
cde->d_reclen = sizeof(struct dirent);
|
||||
dprintf(("%s\n", (cde.d_type == DT_DIR) ? "dir":"reg"));
|
||||
|
||||
error = uiomove((char *)&cde, sizeof(struct dirent), uio);
|
||||
error = uiomove((void *)cde, sizeof(struct dirent), uio);
|
||||
if (error)
|
||||
return (error);
|
||||
goto out;
|
||||
|
||||
ncookies++;
|
||||
num++;
|
||||
|
@ -709,6 +713,8 @@ ntfs_readdir(ap)
|
|||
if (ap->a_eofflag)
|
||||
*ap->a_eofflag = VTONT(ap->a_vp)->i_size <= uio->uio_offset;
|
||||
*/
|
||||
out:
|
||||
FREE(cde, M_TEMP);
|
||||
return (error);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue