Module Name: src Committed By: hannken Date: Thu Nov 13 16:49:56 UTC 2014
Modified Files: src/sys/fs/ntfs: ntfs_inode.h ntfs_subr.c ntfs_subr.h ntfs_vfsops.c ntfs_vfsops.h ntfs_vnops.c Log Message: - 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. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/fs/ntfs/ntfs_inode.h \ src/sys/fs/ntfs/ntfs_vfsops.h cvs rdiff -u -r1.51 -r1.52 src/sys/fs/ntfs/ntfs_subr.c cvs rdiff -u -r1.6 -r1.7 src/sys/fs/ntfs/ntfs_subr.h cvs rdiff -u -r1.94 -r1.95 src/sys/fs/ntfs/ntfs_vfsops.c cvs rdiff -u -r1.57 -r1.58 src/sys/fs/ntfs/ntfs_vnops.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/fs/ntfs/ntfs_inode.h diff -u src/sys/fs/ntfs/ntfs_inode.h:1.7 src/sys/fs/ntfs/ntfs_inode.h:1.8 --- src/sys/fs/ntfs/ntfs_inode.h:1.7 Tue Jan 29 18:21:10 2008 +++ src/sys/fs/ntfs/ntfs_inode.h Thu Nov 13 16:49:56 2014 @@ -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; Index: src/sys/fs/ntfs/ntfs_vfsops.h diff -u src/sys/fs/ntfs/ntfs_vfsops.h:1.7 src/sys/fs/ntfs/ntfs_vfsops.h:1.8 --- src/sys/fs/ntfs/ntfs_vfsops.h:1.7 Sat Jun 28 01:34:05 2008 +++ src/sys/fs/ntfs/ntfs_vfsops.h Thu Nov 13 16:49:56 2014 @@ -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 (sem...@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 *); Index: src/sys/fs/ntfs/ntfs_subr.c diff -u src/sys/fs/ntfs/ntfs_subr.c:1.51 src/sys/fs/ntfs/ntfs_subr.c:1.52 --- src/sys/fs/ntfs/ntfs_subr.c:1.51 Fri Jun 28 17:13:34 2013 +++ src/sys/fs/ntfs/ntfs_subr.c Thu Nov 13 16:49:56 2014 @@ -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 (sem...@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; Index: src/sys/fs/ntfs/ntfs_subr.h diff -u src/sys/fs/ntfs/ntfs_subr.h:1.6 src/sys/fs/ntfs/ntfs_subr.h:1.7 --- src/sys/fs/ntfs/ntfs_subr.h:1.6 Sun Mar 4 06:03:00 2007 +++ src/sys/fs/ntfs/ntfs_subr.h Thu Nov 13 16:49:56 2014 @@ -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 ntfsmoun 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 *); Index: src/sys/fs/ntfs/ntfs_vfsops.c diff -u src/sys/fs/ntfs/ntfs_vfsops.c:1.94 src/sys/fs/ntfs/ntfs_vfsops.c:1.95 --- src/sys/fs/ntfs/ntfs_vfsops.c:1.94 Wed Apr 16 18:55:18 2014 +++ src/sys/fs/ntfs/ntfs_vfsops.c Thu Nov 13 16:49:56 2014 @@ -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; Index: src/sys/fs/ntfs/ntfs_vnops.c diff -u src/sys/fs/ntfs/ntfs_vnops.c:1.57 src/sys/fs/ntfs/ntfs_vnops.c:1.58 --- src/sys/fs/ntfs/ntfs_vnops.c:1.57 Fri Jul 25 08:20:52 2014 +++ src/sys/fs/ntfs/ntfs_vnops.c Thu Nov 13 16:49:56 2014 @@ -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);