Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/fs/ntfs - Fix ntfs_ntlookupattr() to make the examples f...



details:   https://anonhg.NetBSD.org/src/rev/886a7f265fca
branches:  trunk
changeset: 333680:886a7f265fca
user:      hannken <hannken%NetBSD.org@localhost>
date:      Thu Nov 13 16:49:56 2014 +0000

description:
- 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.

diffstat:

 sys/fs/ntfs/ntfs_inode.h  |   5 +--
 sys/fs/ntfs/ntfs_subr.c   |  67 ++++++++++++++++++++++++----------------------
 sys/fs/ntfs/ntfs_subr.h   |   4 +-
 sys/fs/ntfs/ntfs_vfsops.c |  15 +++++----
 sys/fs/ntfs/ntfs_vfsops.h |   4 +-
 sys/fs/ntfs/ntfs_vnops.c  |   8 ++--
 6 files changed, 52 insertions(+), 51 deletions(-)

diffs (truncated from 350 to 300 lines):

diff -r 8c9c7acc4b17 -r 886a7f265fca sys/fs/ntfs/ntfs_inode.h
--- a/sys/fs/ntfs/ntfs_inode.h  Thu Nov 13 16:37:39 2014 +0000
+++ b/sys/fs/ntfs/ntfs_inode.h  Thu Nov 13 16:49:56 2014 +0000
@@ -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 @@
        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 @@
 
 #define        FN_PRELOADED    0x0001
 #define        FN_VALID        0x0002
-#define        FN_AATTRNAME    0x0004  /* space allocated for f_attrname */
 struct fnode {
        struct genfs_node f_gnode;
 
diff -r 8c9c7acc4b17 -r 886a7f265fca sys/fs/ntfs/ntfs_subr.c
--- a/sys/fs/ntfs/ntfs_subr.c   Thu Nov 13 16:37:39 2014 +0000
+++ b/sys/fs/ntfs/ntfs_subr.c   Thu Nov 13 16:49:56 2014 +0000
@@ -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@localhost)
@@ -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 @@
                /* 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 @@
              struct ntnode * ip)
 {
        struct filerec  *mfrp;
-       daddr_t         bn;
        int             error,off;
        struct attr    *ap;
        struct ntvattr *nvap;
@@ -286,20 +285,28 @@
 
        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 @@
     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 @@
        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 @@
 
        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 @@
                        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 @@
                        /* 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 @@
                                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 @@
 
                        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 @@
                        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;
diff -r 8c9c7acc4b17 -r 886a7f265fca sys/fs/ntfs/ntfs_subr.h
--- a/sys/fs/ntfs/ntfs_subr.h   Thu Nov 13 16:37:39 2014 +0000
+++ b/sys/fs/ntfs/ntfs_subr.h   Thu Nov 13 16:49:56 2014 +0000
@@ -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 @@
 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 *);
 
diff -r 8c9c7acc4b17 -r 886a7f265fca sys/fs/ntfs/ntfs_vfsops.c
--- a/sys/fs/ntfs/ntfs_vfsops.c Thu Nov 13 16:37:39 2014 +0000
+++ b/sys/fs/ntfs/ntfs_vfsops.c Thu Nov 13 16:49:56 2014 +0000
@@ -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 @@
        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 @@
        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 @@
 
        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 @@
 
        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 @@
        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;
diff -r 8c9c7acc4b17 -r 886a7f265fca sys/fs/ntfs/ntfs_vfsops.h
--- a/sys/fs/ntfs/ntfs_vfsops.h Thu Nov 13 16:37:39 2014 +0000
+++ b/sys/fs/ntfs/ntfs_vfsops.h Thu Nov 13 16:49:56 2014 +0000



Home | Main Index | Thread Index | Old Index