- Fix ntfs_ntlookupattr() to make the examples from the man page work.

- Fix ntfs_loadntnode() to always read full cluster to prevent buffer
  cache inconsistency.
- Change ntfs_vgetex() and ntfs_fget() to take a const attrname and
  always pass a possibly empty string.
- Change printf to dprintf.
- Get rid of dead fields i_next, i_prev of struct ntnode.
This commit is contained in:
hannken 2014-11-13 16:49:56 +00:00
parent 44867f9155
commit 6f8e2ffe40
6 changed files with 52 additions and 51 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ntfs_inode.h,v 1.7 2008/01/29 18:21:10 pooka Exp $ */
/* $NetBSD: ntfs_inode.h,v 1.8 2014/11/13 16:49:56 hannken Exp $ */
/*-
* Copyright (c) 1998, 1999 Semen Ustimenko
@ -54,8 +54,6 @@ struct ntnode {
dev_t i_dev; /* Device associated with the inode. */
LIST_ENTRY(ntnode) i_hash;
struct ntnode *i_next;
struct ntnode **i_prev;
struct ntfsmount *i_mp;
ino_t i_number;
u_int32_t i_flag;
@ -76,7 +74,6 @@ struct ntnode {
#define FN_PRELOADED 0x0001
#define FN_VALID 0x0002
#define FN_AATTRNAME 0x0004 /* space allocated for f_attrname */
struct fnode {
struct genfs_node f_gnode;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ntfs_subr.c,v 1.51 2013/06/28 17:13:34 matt Exp $ */
/* $NetBSD: ntfs_subr.c,v 1.52 2014/11/13 16:49:56 hannken Exp $ */
/*-
* Copyright (c) 1998, 1999 Semen Ustimenko (semenu@FreeBSD.org)
@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ntfs_subr.c,v 1.51 2013/06/28 17:13:34 matt Exp $");
__KERNEL_RCSID(0, "$NetBSD: ntfs_subr.c,v 1.52 2014/11/13 16:49:56 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -235,7 +235,7 @@ ntfs_ntvattrget(
/* this is not a main record, so we can't use just plain
vget() */
error = ntfs_vgetex(ntmp->ntm_mountp, aalp->al_inumber,
NTFS_A_DATA, NULL, LK_EXCLUSIVE,
NTFS_A_DATA, "", LK_EXCLUSIVE,
VG_EXT, &newvp);
if (error) {
printf("%s: CAN'T VGET INO: %d\n", __func__,
@ -274,7 +274,6 @@ ntfs_loadntnode(
struct ntnode * ip)
{
struct filerec *mfrp;
daddr_t bn;
int error,off;
struct attr *ap;
struct ntvattr *nvap;
@ -286,20 +285,28 @@ ntfs_loadntnode(
if (ip->i_number < NTFS_SYSNODESNUM) {
struct buf *bp;
daddr_t bn;
off_t boff;
dprintf(("%s: read system node\n", __func__));
bn = ntfs_cntobn(ntmp->ntm_mftcn) +
ntmp->ntm_bpmftrec * ip->i_number;
/*
* Make sure we always read full cluster to
* prevent buffer cache inconsistency.
*/
boff = ntfs_cntob(ntmp->ntm_mftcn) +
ntfs_bntob(ntmp->ntm_bpmftrec) * ip->i_number;
bn = ntfs_cntobn(ntfs_btocn(boff));
off = ntfs_btocnoff(boff);
error = bread(ntmp->ntm_devvp,
bn, ntfs_bntob(ntmp->ntm_bpmftrec),
error = bread(ntmp->ntm_devvp, bn, ntfs_cntob(1),
NOCRED, 0, &bp);
if (error) {
printf("%s: BREAD FAILED\n", __func__);
goto out;
}
memcpy(mfrp, bp->b_data, ntfs_bntob(ntmp->ntm_bpmftrec));
memcpy(mfrp, (char *)bp->b_data + off,
ntfs_bntob(ntmp->ntm_bpmftrec));
bqrelse(bp);
} else {
struct vnode *vp;
@ -731,23 +738,21 @@ ntfs_fget(
struct ntfsmount *ntmp,
struct ntnode *ip,
int attrtype,
char *attrname,
const char *attrname,
struct fnode **fpp
)
{
struct fnode *fp;
dprintf(("%s: ino: %llu, attrtype: 0x%x, attrname: %s\n", __func__,
(unsigned long long)ip->i_number, attrtype, attrname?attrname:""));
(unsigned long long)ip->i_number, attrtype, attrname));
*fpp = NULL;
for (fp = ip->i_fnlist.lh_first; fp != NULL; fp = fp->f_fnlist.le_next){
dprintf(("%s: fnode: attrtype: %d, attrname: %s\n", __func__,
fp->f_attrtype, fp->f_attrname?fp->f_attrname:""));
fp->f_attrtype, fp->f_attrname));
if ((attrtype == fp->f_attrtype) &&
((!attrname && !fp->f_attrname) ||
(attrname && fp->f_attrname &&
!strcmp(attrname,fp->f_attrname)))){
strcmp(attrname, fp->f_attrname) == 0) {
dprintf(("%s: found existed: %p\n", __func__, fp));
*fpp = fp;
}
@ -760,8 +765,8 @@ ntfs_fget(
dprintf(("%s: allocating fnode: %p\n", __func__, fp));
fp->f_ip = ip;
fp->f_attrname = attrname;
if (fp->f_attrname) fp->f_flag |= FN_AATTRNAME;
fp->f_attrname = malloc(strlen(attrname)+1, M_TEMP, M_WAITOK);
strcpy(fp->f_attrname, attrname);
fp->f_attrtype = attrtype;
ntfs_ntref(ip);
@ -789,8 +794,7 @@ ntfs_frele(
dprintf(("%s: deallocating fnode\n", __func__));
LIST_REMOVE(fp,f_fnlist);
if (fp->f_flag & FN_AATTRNAME)
free(fp->f_attrname, M_TEMP);
free(fp->f_attrname, M_TEMP);
if (fp->f_dirblbuf)
free(fp->f_dirblbuf, M_NTFSDIR);
free(fp, M_NTFSFNODE);
@ -839,14 +843,14 @@ ntfs_ntlookupattr(
goto out;
}
return (ENOENT);
}
} else
*attrtype = NTFS_A_DATA;
out:
if (namelen) {
*attrname = malloc(namelen, M_TEMP, M_WAITOK);
*attrname = malloc(namelen+1, M_TEMP, M_WAITOK);
memcpy((*attrname), name, namelen);
(*attrname)[namelen] = '\0';
*attrtype = NTFS_A_DATA;
}
return (0);
@ -977,9 +981,7 @@ ntfs_ntlookupfile(
/* Check if we've found ourselves */
if ((iep->ie_number == ip->i_number) &&
(attrtype == fp->f_attrtype) &&
((!attrname && !fp->f_attrname) ||
(attrname && fp->f_attrname &&
!strcmp(attrname, fp->f_attrname))))
!strcmp(attrname ? attrname : "", fp->f_attrname))
{
vref(vp);
*vpp = vp;
@ -987,17 +989,18 @@ ntfs_ntlookupfile(
goto fail;
}
/* vget node, but don't load it */
error = ntfs_vgetex(ntmp->ntm_mountp, iep->ie_number,
attrtype, attrname ? attrname : "",
LK_EXCLUSIVE, VG_DONTLOADIN | VG_DONTVALIDFN,
&nvp);
/* free the buffer returned by ntfs_ntlookupattr() */
if (attrname) {
free(attrname, M_TEMP);
attrname = NULL;
}
/* vget node, but don't load it */
error = ntfs_vgetex(ntmp->ntm_mountp,
iep->ie_number, attrtype, attrname,
LK_EXCLUSIVE, VG_DONTLOADIN | VG_DONTVALIDFN,
&nvp);
if (error)
goto fail;
@ -1014,7 +1017,7 @@ ntfs_ntlookupfile(
if((nfp->f_fflag & NTFS_FFLAG_DIR) &&
(nfp->f_attrtype == NTFS_A_DATA) &&
(nfp->f_attrname == NULL))
strcmp(nfp->f_attrname, "") == 0)
f_type = VDIR;
else
f_type = VREG;
@ -1022,7 +1025,7 @@ ntfs_ntlookupfile(
nvp->v_type = f_type;
if ((nfp->f_attrtype == NTFS_A_DATA) &&
(nfp->f_attrname == NULL))
strcmp(nfp->f_attrname, "") == 0)
{
/* Opening default attribute */
nfp->f_size = iep->ie_fsize;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ntfs_subr.h,v 1.6 2007/03/04 06:03:00 christos Exp $ */
/* $NetBSD: ntfs_subr.h,v 1.7 2014/11/13 16:49:56 hannken Exp $ */
/*-
* Copyright (c) 1998, 1999 Semen Ustimenko
@ -114,7 +114,7 @@ int ntfs_writeattr_plain(struct ntfsmount *, struct ntnode *, u_int32_t,
void ntfs_toupper_init(void);
int ntfs_toupper_use(struct mount *, struct ntfsmount *);
void ntfs_toupper_unuse(void);
int ntfs_fget(struct ntfsmount *, struct ntnode *, int, char *,
int ntfs_fget(struct ntfsmount *, struct ntnode *, int, const char *,
struct fnode **);
void ntfs_frele(struct fnode *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ntfs_vfsops.c,v 1.94 2014/04/16 18:55:18 maxv Exp $ */
/* $NetBSD: ntfs_vfsops.c,v 1.95 2014/11/13 16:49:56 hannken Exp $ */
/*-
* Copyright (c) 1998, 1999 Semen Ustimenko
@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.94 2014/04/16 18:55:18 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.95 2014/11/13 16:49:56 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -659,7 +659,7 @@ ntfs_fhtovp(
ddprintf(("ntfs_fhtovp(): %s: %llu\n", mp->mnt_stat.f_mntonname,
(unsigned long long)ntfh.ntfid_ino));
error = ntfs_vgetex(mp, ntfh.ntfid_ino, ntfh.ntfid_attr, NULL,
error = ntfs_vgetex(mp, ntfh.ntfid_ino, ntfh.ntfid_attr, "",
LK_EXCLUSIVE, 0, vpp);
if (error != 0) {
*vpp = NULLVP;
@ -708,7 +708,7 @@ ntfs_vgetex(
struct mount *mp,
ino_t ino,
u_int32_t attrtype,
char *attrname,
const char *attrname,
u_long lkflags,
u_long flags,
struct vnode **vpp)
@ -722,7 +722,7 @@ ntfs_vgetex(
dprintf(("ntfs_vgetex: ino: %llu, attr: 0x%x:%s, lkf: 0x%lx, f:"
" 0x%lx\n", (unsigned long long)ino, attrtype,
attrname ? attrname : "", (u_long)lkflags, (u_long)flags));
attrname, (u_long)lkflags, (u_long)flags));
ntmp = VFSTONTFS(mp);
*vpp = NULL;
@ -755,7 +755,8 @@ loop:
if (!(flags & VG_DONTVALIDFN) && !(fp->f_flag & FN_VALID)) {
if ((ip->i_frflag & NTFS_FRFLAG_DIR) &&
(fp->f_attrtype == NTFS_A_DATA && fp->f_attrname == NULL)) {
(fp->f_attrtype == NTFS_A_DATA &&
strcmp(fp->f_attrname, "") == 0)) {
f_type = VDIR;
} else if (flags & VG_EXT) {
f_type = VNON;
@ -849,7 +850,7 @@ ntfs_vget(
ino_t ino,
struct vnode **vpp)
{
return ntfs_vgetex(mp, ino, NTFS_A_DATA, NULL, LK_EXCLUSIVE, 0, vpp);
return ntfs_vgetex(mp, ino, NTFS_A_DATA, "", LK_EXCLUSIVE, 0, vpp);
}
extern const struct vnodeopv_desc ntfs_vnodeop_opv_desc;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ntfs_vfsops.h,v 1.7 2008/06/28 01:34:05 rumble Exp $ */
/* $NetBSD: ntfs_vfsops.h,v 1.8 2014/11/13 16:49:56 hannken Exp $ */
/*-
* Copyright (c) 1998, 1999 Semen Ustimenko (semenu@FreeBSD.org)
@ -38,6 +38,6 @@
/* fnode */
#define VG_EXT 0x0004 /* This is not main record */
int ntfs_vgetex(struct mount *, ino_t, u_int32_t, char *, u_long, u_long,
int ntfs_vgetex(struct mount *, ino_t, u_int32_t, const char *, u_long, u_long,
struct vnode **);
int ntfs_calccfree(struct ntfsmount *, cn_t *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ntfs_vnops.c,v 1.57 2014/07/25 08:20:52 dholland Exp $ */
/* $NetBSD: ntfs_vnops.c,v 1.58 2014/11/13 16:49:56 hannken Exp $ */
/*
* Copyright (c) 1992, 1993
@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ntfs_vnops.c,v 1.57 2014/07/25 08:20:52 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: ntfs_vnops.c,v 1.58 2014/11/13 16:49:56 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -470,7 +470,7 @@ ntfs_open(void *v)
struct vnode *vp = ap->a_vp;
struct ntnode *ip = VTONT(vp);
printf("ntfs_open: %llu\n", (unsigned long long)ip->i_number);
dprintf(("ntfs_open: %llu\n", (unsigned long long)ip->i_number));
#endif
/*
@ -498,7 +498,7 @@ ntfs_close(void *v)
struct vnode *vp = ap->a_vp;
struct ntnode *ip = VTONT(vp);
printf("ntfs_close: %llu\n", (unsigned long long)ip->i_number);
dprintf(("ntfs_close: %llu\n", (unsigned long long)ip->i_number));
#endif
return (0);