Source-Changes-HG archive

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

[src/trunk]: src Factor out the lookup results from struct denode.



details:   https://anonhg.NetBSD.org/src/rev/1567675e9a2e
branches:  trunk
changeset: 1024424:1567675e9a2e
user:      hannken <hannken%NetBSD.org@localhost>
date:      Sat Oct 23 07:38:33 2021 +0000

description:
Factor out the lookup results from struct denode.

No functional change.

diffstat:

 sys/fs/msdosfs/denode.h               |  18 +++++++++---
 sys/fs/msdosfs/msdosfs_lookup.c       |  46 +++++++++++++++++++---------------
 sys/fs/msdosfs/msdosfs_vnops.c        |  35 +++++++++++++------------
 usr.sbin/makefs/msdos/msdosfs_vnops.c |  20 +++++++-------
 4 files changed, 66 insertions(+), 53 deletions(-)

diffs (truncated from 413 to 300 lines):

diff -r 57821ddfaf34 -r 1567675e9a2e sys/fs/msdosfs/denode.h
--- a/sys/fs/msdosfs/denode.h   Sat Oct 23 06:49:46 2021 +0000
+++ b/sys/fs/msdosfs/denode.h   Sat Oct 23 07:38:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: denode.h,v 1.26 2021/07/18 23:57:14 dholland Exp $     */
+/*     $NetBSD: denode.h,v 1.27 2021/10/23 07:38:33 hannken Exp $      */
 
 /*-
  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -147,7 +147,14 @@
                (dep)->de_fc[FC_NEXTTOLASTFC].fc_frcn = (dep)->de_fc[FC_LASTFC].fc_frcn; \
                (dep)->de_fc[FC_NEXTTOLASTFC].fc_fsrcn = (dep)->de_fc[FC_LASTFC].fc_fsrcn; \
        } while (0)
-        
+
+/*
+ * Auxiliary results from an msdosfs_lookup operation
+ */
+struct msdosfs_lookup_results {
+       u_long mlr_fndoffset;   /* offset of found dir entry */
+       int mlr_fndcnt;         /* number of slots before de_fndoffset */
+};
 
 /*
  * This is the in memory variant of a dos directory entry.  It is usually
@@ -168,8 +175,7 @@
 #define de_dirclust de_key.dk_dirclust
 #define de_diroffset de_key.dk_diroffset
 #define de_dirgen de_key.dk_dirgen
-       u_long de_fndoffset;    /* offset of found dir entry */
-       int de_fndcnt;          /* number of slots before de_fndoffset */
+       struct msdosfs_lookup_results de_crap;  /* results from lookup */
        long de_refcnt;         /* reference count */
        struct msdosfsmount *de_pmp;    /* addr of our mount struct */
        struct lockf *de_lockf; /* byte level lock list */
@@ -302,6 +308,7 @@
 int msdosfs_update(struct vnode *, const struct timespec *,
            const struct timespec *, int);
 int createde(struct denode *, struct denode *,
+               const struct msdosfs_lookup_results *,
                struct denode **, struct componentname *);
 int deextend(struct denode *, u_long, struct kauth_cred *);
 #ifdef MAKEFS
@@ -316,7 +323,8 @@
 int readde(struct denode *, struct buf **, struct direntry **);
 int readep(struct msdosfsmount *, u_long, u_long,
                struct buf **, struct direntry **);
-int removede(struct denode *, struct denode *);
+int removede(struct denode *, struct denode *,
+               const struct msdosfs_lookup_results *);
 int uniqdosname(struct denode *, struct componentname *, u_char *);
 int findwin95(struct denode *);
 int msdosfs_gop_alloc(struct vnode *, off_t, off_t, int, struct kauth_cred *);
diff -r 57821ddfaf34 -r 1567675e9a2e sys/fs/msdosfs/msdosfs_lookup.c
--- a/sys/fs/msdosfs/msdosfs_lookup.c   Sat Oct 23 06:49:46 2021 +0000
+++ b/sys/fs/msdosfs/msdosfs_lookup.c   Sat Oct 23 07:38:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msdosfs_lookup.c,v 1.37 2021/07/24 21:31:38 andvar Exp $       */
+/*     $NetBSD: msdosfs_lookup.c,v 1.38 2021/10/23 07:38:33 hannken Exp $      */
 
 /*-
  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -52,7 +52,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: msdosfs_lookup.c,v 1.37 2021/07/24 21:31:38 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_lookup.c,v 1.38 2021/10/23 07:38:33 hannken Exp $");
 
 #include <sys/param.h>
 
@@ -320,21 +320,21 @@
                                 * entry came from for whoever did
                                 * this lookup.
                                 */
-                               dp->de_fndoffset = diroff;
+                               dp->de_crap.mlr_fndoffset = diroff;
                                if (chksum_ok && nameiop == RENAME) {
                                        /*
                                         * Target had correct long name
                                         * directory entries, reuse them
                                         * as needed.
                                         */
-                                       dp->de_fndcnt = wincnt - 1;
+                                       dp->de_crap.mlr_fndcnt = wincnt - 1;
                                } else {
                                        /*
                                         * Long name directory entries
                                         * not present or corrupt, can only
                                         * reuse dos directory entry.
                                         */
-                                       dp->de_fndcnt = 0;
+                                       dp->de_crap.mlr_fndcnt = 0;
                                }
 
                                goto found;
@@ -389,8 +389,8 @@
                 * Return an indication of where the new directory
                 * entry should be put.
                 */
-               dp->de_fndoffset = slotoffset;
-               dp->de_fndcnt = wincnt - 1;
+               dp->de_crap.mlr_fndoffset = slotoffset;
+               dp->de_crap.mlr_fndcnt = wincnt - 1;
 
                /*
                 * We return with the directory locked, so that
@@ -552,7 +552,9 @@
  * cnp  - componentname needed for Win95 long filenames
  */
 int
-createde(struct denode *dep, struct denode *ddep, struct denode **depp, struct componentname *cnp)
+createde(struct denode *dep, struct denode *ddep,
+    const struct msdosfs_lookup_results *mlr,
+    struct denode **depp, struct componentname *cnp)
 {
        int error, rberror;
        u_long dirclust, clusoffset;
@@ -581,9 +583,9 @@
         * to extend the root directory.  We just return an error in that
         * case.
         */
-       if (ddep->de_fndoffset >= ddep->de_FileSize) {
-               u_long needlen = ddep->de_fndoffset + sizeof(struct direntry)
-                   - ddep->de_FileSize;
+       if (mlr->mlr_fndoffset >= ddep->de_FileSize) {
+               u_long needlen = ddep->de_crap.mlr_fndoffset
+                   + sizeof(struct direntry) - ddep->de_FileSize;
                dirclust = de_clcount(pmp, needlen);
                if ((error = extendfile(ddep, dirclust, 0, 0, DE_CLEAR)) != 0) {
                        (void)detrunc(ddep, ddep->de_FileSize, 0, NOCRED);
@@ -601,11 +603,11 @@
         * entry in.  Then write it to disk. NOTE:  DOS directories
         * do not get smaller as clusters are emptied.
         */
-       error = pcbmap(ddep, de_cluster(pmp, ddep->de_fndoffset),
+       error = pcbmap(ddep, de_cluster(pmp, mlr->mlr_fndoffset),
                       &bn, &dirclust, &blsize);
        if (error)
                goto err_norollback;
-       clusoffset = ddep->de_fndoffset;
+       clusoffset = mlr->mlr_fndoffset;
        if (dirclust != MSDOSFSROOT)
                clusoffset &= pmp->pm_crbomask;
        if ((error = bread(pmp->pm_devvp, de_bn2kb(pmp, bn), blsize,
@@ -619,14 +621,14 @@
        /*
         * Now write the Win95 long name
         */
-       if (ddep->de_fndcnt > 0) {
+       if (mlr->mlr_fndcnt > 0) {
                u_int8_t chksum = winChksum(ndep->deName);
                const u_char *un = (const u_char *)cnp->cn_nameptr;
                int unlen = cnp->cn_namelen;
                u_long xhavecnt;
 
-               fndoffset = ddep->de_fndoffset;
-               xhavecnt = ddep->de_fndcnt + 1;
+               fndoffset = mlr->mlr_fndoffset;
+               xhavecnt = mlr->mlr_fndcnt + 1;
 
                for(; wcnt < xhavecnt; wcnt++) {
                        if ((fndoffset & pmp->pm_crbomask) == 0) {
@@ -705,7 +707,7 @@
         * can't just call removede(), since directory is not in
         * consistent state.
         */
-       fndoffset = ddep->de_fndoffset;
+       fndoffset = mlr->mlr_fndoffset;
        rberror = pcbmap(ddep, de_cluster(pmp, fndoffset),
               &bn, NULL, &blsize);
        if (rberror)
@@ -716,7 +718,7 @@
        }
        ndep = bptoep(pmp, bp, clusoffset);
 
-       havecnt = ddep->de_fndcnt + 1;
+       havecnt = mlr->mlr_fndcnt + 1;
        for(i = wcnt; i <= havecnt; i++) {
                /* mark entry as deleted */
                ndep->deName[0] = SLOT_DELETED;
@@ -985,9 +987,11 @@
  * msdosfs_reclaim() which will remove the denode from the denode cache.
  */
 int
-removede(struct denode *pdep, struct denode *dep)
+removede(struct denode *pdep, struct denode *dep,
+    const struct msdosfs_lookup_results *mlr)
        /* pdep:         directory where the entry is removed */
        /* dep:  file to be removed */
+       /* mlr:  position of dep in pdep from lookup */
 {
        int error;
        struct direntry *ep;
@@ -995,7 +999,7 @@
        daddr_t bn;
        int blsize;
        struct msdosfsmount *pmp = pdep->de_pmp;
-       u_long offset = pdep->de_fndoffset;
+       u_long offset = mlr->mlr_fndoffset;
 #ifdef _KERNEL
        int async = pdep->de_pmp->pm_mountp->mnt_flag & MNT_ASYNC;
 #else
@@ -1039,7 +1043,7 @@
                 * entry in this block is a longfilename entry, too.
                 */
                if (ep->deAttributes != ATTR_WIN95
-                   && offset != pdep->de_fndoffset) {
+                   && offset != mlr->mlr_fndoffset) {
                        brelse(bp, 0);
                        break;
                }
diff -r 57821ddfaf34 -r 1567675e9a2e sys/fs/msdosfs/msdosfs_vnops.c
--- a/sys/fs/msdosfs/msdosfs_vnops.c    Sat Oct 23 06:49:46 2021 +0000
+++ b/sys/fs/msdosfs/msdosfs_vnops.c    Sat Oct 23 07:38:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msdosfs_vnops.c,v 1.107 2021/10/20 03:08:17 thorpej Exp $      */
+/*     $NetBSD: msdosfs_vnops.c,v 1.108 2021/10/23 07:38:33 hannken 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.107 2021/10/20 03:08:17 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.108 2021/10/23 07:38:33 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -125,7 +125,7 @@
         * change size.
         */
        if (pdep->de_StartCluster == MSDOSFSROOT
-           && pdep->de_fndoffset >= pdep->de_FileSize) {
+           && pdep->de_crap.mlr_fndoffset >= pdep->de_FileSize) {
                error = ENOSPC;
                goto bad;
        }
@@ -149,7 +149,7 @@
        ndirent.de_pmp = pdep->de_pmp;
        ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
        DETIMES(&ndirent, NULL, NULL, NULL, pdep->de_pmp->pm_gmtoff);
-       if ((error = createde(&ndirent, pdep, &dep, cnp)) != 0)
+       if ((error = createde(&ndirent, pdep, &pdep->de_crap, &dep, cnp)) != 0)
                goto bad;
        *ap->a_vpp = DETOV(dep);
        cache_enter(ap->a_dvp, *ap->a_vpp, cnp->cn_nameptr, cnp->cn_namelen,
@@ -725,7 +725,7 @@
        if (ap->a_vp->v_type == VDIR)
                error = EPERM;
        else
-               error = removede(ddep, dep);
+               error = removede(ddep, dep, &ddep->de_crap);
 #ifdef MSDOSFS_DEBUG
        printf("msdosfs_remove(), dep %p, usecount %d\n",
                dep, vrefcnt(ap->a_vp));
@@ -896,8 +896,8 @@
        /*
         * Remember direntry place to use for destination
         */
-       to_diroffset = dp->de_fndoffset;
-       to_count = dp->de_fndcnt;
+       to_diroffset = dp->de_crap.mlr_fndoffset;
+       to_count = dp->de_crap.mlr_fndcnt;
 
        /*
         * If ".." must be changed (ie the directory gets a new
@@ -957,7 +957,7 @@
                        error = EISDIR;
                        goto tdvpbad;
                }
-               if ((error = removede(dp, xp)) != 0)
+               if ((error = removede(dp, xp, &dp->de_crap)) != 0)
                        goto tdvpbad;
                VN_KNOTE(tdvp, NOTE_WRITE);
                VN_KNOTE(tvp, NOTE_DELETE);
@@ -1004,7 +1004,7 @@
        VOP_UNLOCK(fdvp);
        xp = VTODE(fvp);
        zp = VTODE(fdvp);
-       from_diroffset = zp->de_fndoffset;
+       from_diroffset = zp->de_crap.mlr_fndoffset;
 
        /*
         * Ensure that the directory entry still exists and has not
@@ -1033,17 +1033,18 @@
                 */
                memcpy(oldname, ip->de_Name, 11);
                memcpy(ip->de_Name, toname, 11);        /* update denode */
-               dp->de_fndoffset = to_diroffset;
-               dp->de_fndcnt = to_count;
-               error = createde(ip, dp, (struct denode **)0, tcnp);
+               dp->de_crap.mlr_fndoffset = to_diroffset;
+               dp->de_crap.mlr_fndcnt = to_count;
+               error = createde(ip, dp, &dp->de_crap, (struct denode **)0,
+                   tcnp);
                if (error) {
                        memcpy(ip->de_Name, oldname, 11);
                        VOP_UNLOCK(fvp);



Home | Main Index | Thread Index | Old Index