Source-Changes-HG archive

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

[src/trunk]: src/sys/ntfs change ntfs_read*attr*() and ntfs_write*attr*() to ...



details:   https://anonhg.NetBSD.org/src/rev/b431f0c13bb7
branches:  trunk
changeset: 476041:b431f0c13bb7
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sat Sep 04 18:56:01 1999 +0000

description:
change ntfs_read*attr*() and ntfs_write*attr*() to accept struct
        uio parameter; if it's not null, the data are copied directly
        into/from the user buffer via uiomove()
new macro NTFS_U28() and function ntfs_u28() to convert between Unicode
        and 8bit encoding; all it does currently is getting lower 8bit
        of the Unicode char and subtituting '_' for it if the result would be 0;
        use the macro within NTFS_TOUPPER() macro and in ntfs_uastrcmp()
g/c the (ntfsmount *) parametr to ntfs_u*astr[i]cmp() functions, it's no
        longer needed
avoid excessive intendation

diffstat:

 sys/ntfs/ntfs_subr.c |  525 ++++++++++++++++++++++++++------------------------
 sys/ntfs/ntfs_subr.h |   23 +-
 2 files changed, 284 insertions(+), 264 deletions(-)

diffs (truncated from 835 to 300 lines):

diff -r c1b74f1bb38a -r b431f0c13bb7 sys/ntfs/ntfs_subr.c
--- a/sys/ntfs/ntfs_subr.c      Sat Sep 04 18:38:28 1999 +0000
+++ b/sys/ntfs/ntfs_subr.c      Sat Sep 04 18:56:01 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntfs_subr.c,v 1.9 1999/08/18 16:25:52 augustss Exp $   */
+/*     $NetBSD: ntfs_subr.c,v 1.10 1999/09/04 18:56:01 jdolecek Exp $  */
 
 /*-
  * Copyright (c) 1998, 1999 Semen Ustimenko (semenu%FreeBSD.org@localhost)
@@ -66,7 +66,8 @@
 /* table for mapping Unicode chars into uppercase; it's filled upon first
  * ntfs mount, freed upon last ntfs umount */
 static wchar *ntfs_toupper_tab;
-#define NTFS_TOUPPER(ch)       (ntfs_toupper_tab[ch & 0xFF])
+#define NTFS_U28(ch)           (((ch & 0xFF) == 0) ? '_' : (ch) & 0xFF)
+#define NTFS_TOUPPER(ch)       (ntfs_toupper_tab[NTFS_U28(ch)])
 static struct lock ntfs_toupper_lock;
 static signed int ntfs_toupper_usecount;
 
@@ -161,7 +162,8 @@
        /* Scan $ATTRIBUTE_LIST for requested attribute */
        len = lvap->va_datalen;
        MALLOC(alpool, caddr_t, len, M_TEMP, M_WAITOK);
-       error = ntfs_readntvattr_plain(ntmp, ip, lvap, 0, len, alpool, &len);
+       error = ntfs_readntvattr_plain(ntmp, ip, lvap, 0, len, alpool, &len,
+                       NULL);
        if (error)
                goto out;
 
@@ -183,7 +185,7 @@
 
 #define AALPCMP(aalp,type,name,namelen) (                              \
   (aalp->al_type == type) && (aalp->al_namelen == namelen) &&          \
-  !uastrcmp(aalp->al_name,aalp->al_namelen,name,namelen) )
+  !ntfs_uastrcmp(aalp->al_name,aalp->al_namelen,name,namelen) )
 
                if (AALPCMP(aalp, type, name, namelen) &&
                    (!nextaalp || (nextaalp->al_vcnstart > vcn) ||
@@ -296,7 +298,7 @@
                vp = ntmp->ntm_sysvn[NTFS_MFTINO];
                error = ntfs_readattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL,
                               ip->i_number * ntfs_bntob(ntmp->ntm_bpmftrec),
-                              ntfs_bntob(ntmp->ntm_bpmftrec), mfrp);
+                              ntfs_bntob(ntmp->ntm_bpmftrec), mfrp, NULL);
                if (error) {
                        printf("ntfs_loadnode: ntfs_readattr failed\n");
                        goto out;
@@ -662,7 +664,6 @@
  */
 int
 ntfs_uustricmp(
-              struct ntfsmount * ntmp,
               wchar * str1,
               int str1len,
               wchar * str2,
@@ -685,7 +686,6 @@
  */
 int
 ntfs_uastricmp(
-              struct ntfsmount * ntmp,
               const wchar *str1,
               int str1len,
               const char *str2,
@@ -708,7 +708,6 @@
  */
 int
 ntfs_uastrcmp(
-             struct ntfsmount *ntmp,
              const wchar *str1,
              int str1len,
              const char *str2,
@@ -718,7 +717,7 @@
        int             res;
 
        for (i = 0; (i < str1len) && (i < str2len); i++) {
-               res = ((int) str1[i]) - ((int) str2[i]);
+               res = ((int) NTFS_U28(str1[i])) - ((int) str2[i]);
                if (res)
                        return res;
        }
@@ -837,19 +836,19 @@
                namelen -= syslen;
 
                adp = ntmp->ntm_ad;
-               for (i = 0; i < ntmp->ntm_adnum; i++){
-                       if((syslen == adp->ad_namelen) && 
-                          (!strncmp(sys,adp->ad_name,syslen))) {
-                               *attrtype = adp->ad_type;
-                               if(namelen) {
-                                       MALLOC((*attrname), char *, namelen,
-                                               M_TEMP, M_WAITOK);
-                                       memcpy((*attrname), name, namelen);
-                                       (*attrname)[namelen] = '\0';
-                               }
-                               return (0);
+               for (i = 0; i < ntmp->ntm_adnum; i++, adp++){
+                       if (syslen != adp->ad_namelen || 
+                          strncmp(sys, adp->ad_name, syslen) != 0)
+                               continue;
+
+                       *attrtype = adp->ad_type;
+                       if (namelen) {
+                               MALLOC((*attrname), char *, namelen,
+                                       M_TEMP, M_WAITOK);
+                               memcpy((*attrname), name, namelen);
+                               (*attrname)[namelen] = '\0';
                        }
-                       adp++;
+                       return (0);
                }
                return (ENOENT);
        }
@@ -886,6 +885,11 @@
        int             error, res, anamelen, fnamelen;
        const char     *fname,*aname;
        u_int32_t       aoff;
+       int attrtype = NTFS_A_DATA;
+       char *attrname = NULL;
+       struct fnode   *nfp;
+       struct vnode   *nvp;
+
 
        error = ntfs_ntget(ip);
        if (error)
@@ -919,7 +923,7 @@
        MALLOC(rdbuf, caddr_t, blsize, M_TEMP, M_WAITOK);
 
        error = ntfs_readattr(ntmp, ip, NTFS_A_INDXROOT, "$I30",
-                              0, rdsize, rdbuf);
+                              0, rdsize, rdbuf, NULL);
        if (error)
                goto fail;
 
@@ -928,105 +932,97 @@
        do {
                iep = (struct attr_indexentry *) (rdbuf + aoff);
 
-               while (!(iep->ie_flag & NTFS_IEFLAG_LAST) && (rdsize > aoff)) {
+               for (; !(iep->ie_flag & NTFS_IEFLAG_LAST) && (rdsize > aoff);
+                       aoff += iep->reclen,
+                       iep = (struct attr_indexentry *) (rdbuf + aoff))
+               {
                        ddprintf(("scan: %d, %d\n",
                                  (u_int32_t) iep->ie_number,
                                  (u_int32_t) iep->ie_fnametype));
-                       res = ntfs_uastricmp(ntmp, iep->ie_fname,
-                                            iep->ie_fnamelen, fname,
-                                            fnamelen);
-                       if (res == 0) {
-                               /* Matched something (case ins.) */
-                               if (iep->ie_fnametype == 0 ||
-                                   !(ntmp->ntm_flag & NTFS_MFLAG_CASEINS))
-                                       res = ntfs_uastrcmp(ntmp,
-                                                           iep->ie_fname,
-                                                           iep->ie_fnamelen,
-                                                           fname,
-                                                           fnamelen);
-                               if (res == 0) {
-                                       int attrtype = NTFS_A_DATA;
-                                       char *attrname = NULL;
-                                       struct fnode   *nfp;
-                                       struct vnode   *nvp;
+
+                       /* check the name - the case-insensitible check
+                        * has to come first, to break from this for loop
+                        * if needed, so we can dive correctly */
+                       res = ntfs_uastricmp(iep->ie_fname, iep->ie_fnamelen,
+                                       fname, fnamelen);
+                       if (res > 0) break;
+                       if (res < 0) continue;
+
+                       if (iep->ie_fnametype == 0 ||
+                           !(ntmp->ntm_flag & NTFS_MFLAG_CASEINS))
+                       {
+                               res = ntfs_uastrcmp(iep->ie_fname,
+                                       iep->ie_fnamelen, fname, fnamelen);
+                               if (res != 0) continue;
+                       }
 
-                                       if (aname) {
-                                               error = ntfs_ntlookupattr(ntmp,
-                                                       aname, anamelen,
-                                                       &attrtype, &attrname);
-                                               if (error)
-                                                       goto fail;
-                                       }
+                       if (aname) {
+                               error = ntfs_ntlookupattr(ntmp,
+                                       aname, anamelen,
+                                       &attrtype, &attrname);
+                               if (error)
+                                       goto fail;
+                       }
 
-                                       /* Check if we've found ourself */
-                                       if ((iep->ie_number == ip->i_number) &&
-                                           (attrtype == fp->f_attrtype) &&
-                                           ((!attrname && !fp->f_attrname) ||
-                                            (attrname && fp->f_attrname &&
-                                             !strcmp(attrname, fp->f_attrname)))) {
-                                               VREF(vp);
-                                               *vpp = vp;
-                                               goto fail;
-                                       }
+                       /* Check if we've found ourself */
+                       if ((iep->ie_number == ip->i_number) &&
+                           (attrtype == fp->f_attrtype) &&
+                           ((!attrname && !fp->f_attrname) ||
+                            (attrname && fp->f_attrname &&
+                             !strcmp(attrname, fp->f_attrname))))
+                       {
+                               VREF(vp);
+                               *vpp = vp;
+                               goto fail;
+                       }
 
-                                       /* vget node, but don't load it */
-                                       error = ntfs_vgetex(ntmp->ntm_mountp,
-                                                          iep->ie_number,
-                                                          attrtype,
-                                                          attrname,
-                                                          LK_EXCLUSIVE,
-                                                          VG_DONTLOADIN | 
-                                                           VG_DONTVALIDFN,
-                                                          curproc,
-                                                          &nvp);
-                                       if(error)
-                                               goto fail;
+                       /* vget node, but don't load it */
+                       error = ntfs_vgetex(ntmp->ntm_mountp,
+                                  iep->ie_number, attrtype, attrname,
+                                  LK_EXCLUSIVE, VG_DONTLOADIN | VG_DONTVALIDFN,
+                                  curproc, &nvp);
+                       if (error)
+                               goto fail;
 
-                                       nfp = VTOF(nvp);
+                       nfp = VTOF(nvp);
 
-                                       if (nfp->f_flag & FN_VALID) {
-                                               *vpp = nvp;
-                                               goto fail;
-                                       }
+                       if (nfp->f_flag & FN_VALID) {
+                               *vpp = nvp;
+                               goto fail;
+                       }
 
-                                       nfp->f_fflag = iep->ie_fflag;
-                                       nfp->f_pnumber = iep->ie_fpnumber;
-                                       nfp->f_times = iep->ie_ftimes;
+                       nfp->f_fflag = iep->ie_fflag;
+                       nfp->f_pnumber = iep->ie_fpnumber;
+                       nfp->f_times = iep->ie_ftimes;
 
-                                       if((nfp->f_fflag & NTFS_FFLAG_DIR) &&
-                                          (nfp->f_attrtype == NTFS_A_DATA) &&
-                                          (nfp->f_attrname == NULL))
-                                               nfp->f_type = VDIR;     
-                                       else
-                                               nfp->f_type = VREG;     
+                       if((nfp->f_fflag & NTFS_FFLAG_DIR) &&
+                          (nfp->f_attrtype == NTFS_A_DATA) &&
+                          (nfp->f_attrname == NULL))
+                               nfp->f_type = VDIR;     
+                       else
+                               nfp->f_type = VREG;     
 
-                                       nvp->v_type = nfp->f_type;
+                       nvp->v_type = nfp->f_type;
 
-                                       if ((nfp->f_attrtype == NTFS_A_DATA) &&
-                                           (nfp->f_attrname == NULL)) {
-                                               /* Opening default attribute */
-                                               nfp->f_size = iep->ie_fsize;
-                                               nfp->f_allocated = iep->ie_fallocated;
-                                               nfp->f_flag |= FN_PRELOADED;
-                                       } else {
-                                               error = ntfs_filesize(ntmp, nfp,
-                                                           &nfp->f_size,
-                                                           &nfp->f_allocated);
-                                               if (error) {
-                                                       vput(nvp);
-                                                       goto fail;
-                                               }
-                                       }
-
-                                       nfp->f_flag &= ~FN_VALID;
-                                       *vpp = nvp;
+                       if ((nfp->f_attrtype == NTFS_A_DATA) &&
+                           (nfp->f_attrname == NULL))
+                       {
+                               /* Opening default attribute */
+                               nfp->f_size = iep->ie_fsize;
+                               nfp->f_allocated = iep->ie_fallocated;
+                               nfp->f_flag |= FN_PRELOADED;
+                       } else {
+                               error = ntfs_filesize(ntmp, nfp,
+                                           &nfp->f_size, &nfp->f_allocated);
+                               if (error) {



Home | Main Index | Thread Index | Old Index