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 some mallocs not to have casts and specify...



details:   https://anonhg.NetBSD.org/src/rev/fb76768daf19
branches:  trunk
changeset: 779544:fb76768daf19
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jun 02 16:26:24 2012 +0000

description:
- fix some mallocs not to have casts and specify sizeof(*var)
- if the index magic is 0, don't complain, just return an error.
- make dprintfs use __func__

diffstat:

 sys/fs/ntfs/ntfs_subr.c |  297 +++++++++++++++++++++++------------------------
 1 files changed, 143 insertions(+), 154 deletions(-)

diffs (truncated from 893 to 300 lines):

diff -r bc1a4d199c00 -r fb76768daf19 sys/fs/ntfs/ntfs_subr.c
--- a/sys/fs/ntfs/ntfs_subr.c   Sat Jun 02 16:16:16 2012 +0000
+++ b/sys/fs/ntfs/ntfs_subr.c   Sat Jun 02 16:26:24 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntfs_subr.c,v 1.46 2011/08/31 18:31:02 plunky Exp $    */
+/*     $NetBSD: ntfs_subr.c,v 1.47 2012/06/02 16:26:24 christos 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.46 2011/08/31 18:31:02 plunky Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ntfs_subr.c,v 1.47 2012/06/02 16:26:24 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -101,7 +101,7 @@
 int
 ntfs_ntvattrrele(struct ntvattr * vap)
 {
-       dprintf(("ntfs_ntvattrrele: ino: %llu, type: 0x%x\n",
+       dprintf(("%s: ino: %llu, type: 0x%x\n", __func__,
            (unsigned long long)vap->va_ip->i_number, vap->va_type));
 
        ntfs_ntrele(vap->va_ip);
@@ -119,11 +119,11 @@
        struct ntvattr *vap;
 
        if((ip->i_flag & IN_LOADED) == 0) {
-               dprintf(("ntfs_findvattr: node not loaded, ino: %llu\n",
+               dprintf(("%s: node not loaded, ino: %llu\n", __func__,
                    (unsigned long long)ip->i_number));
                error = ntfs_loadntnode(ntmp,ip);
                if (error) {
-                       printf("ntfs_findvattr: FAILED TO LOAD INO: %llu\n",
+                       printf("%s: FAILED TO LOAD INO: %llu\n", __func__,
                            (unsigned long long)ip->i_number);
                        return (error);
                }
@@ -132,7 +132,7 @@
        *lvapp = NULL;
        *vapp = NULL;
        for (vap = ip->i_valist.lh_first; vap; vap = vap->va_list.le_next) {
-               ddprintf(("ntfs_findvattr: type: 0x%x, vcn: %qu - %qu\n",
+               ddprintf(("%s: type: 0x%x, vcn: %qu - %qu\n", __func__,
                          vap->va_type, (long long) vap->va_vcnstart,
                          (long long) vap->va_vcnend));
                if ((vap->va_type == type) &&
@@ -178,14 +178,12 @@
        *vapp = NULL;
 
        if (name) {
-               dprintf(("ntfs_ntvattrget: "
-                   "ino: %llu, type: 0x%x, name: %s, vcn: %qu\n",
-                   (unsigned long long)ip->i_number, type, name,
+               dprintf(("%s: ino: %llu, type: 0x%x, name: %s, vcn: %qu\n",
+                   __func__, (unsigned long long)ip->i_number, type, name,
                    (long long)vcn));
                namelen = strlen(name);
        } else {
-               dprintf(("ntfs_ntvattrget: "
-                   "ino: %llu, type: 0x%x, vcn: %qu\n",
+               dprintf(("%s: ino: %llu, type: 0x%x, vcn: %qu\n", __func__,
                    (unsigned long long)ip->i_number, type, (long long)vcn));
                name = "";
                namelen = 0;
@@ -196,15 +194,15 @@
                return (error);
 
        if (!lvap) {
-               dprintf(("ntfs_ntvattrget: UNEXISTED ATTRIBUTE: "
-                   "ino: %llu, type: 0x%x, name: %s, vcn: %qu\n",
+               dprintf(("%s: UNEXISTED ATTRIBUTE: "
+                   "ino: %llu, type: 0x%x, name: %s, vcn: %qu\n", __func__,
                    (unsigned long long)ip->i_number, type, name,
                    (long long)vcn));
                return (ENOENT);
        }
        /* Scan $ATTRIBUTE_LIST for requested attribute */
        len = lvap->va_datalen;
-       alpool = (void *) malloc(len, M_TEMP, M_WAITOK);
+       alpool = malloc(len, M_TEMP, M_WAITOK);
        error = ntfs_readntvattr_plain(ntmp, ip, lvap, 0, len, alpool, &len,
                        NULL);
        if (error)
@@ -215,10 +213,9 @@
 
        for(; len > 0; aalp = nextaalp) {
                KASSERT(aalp != NULL);
-               dprintf(("ntfs_ntvattrget: "
-                   "attrlist: ino: %d, attr: 0x%x, vcn: %qu\n",
-                   aalp->al_inumber, aalp->al_type,
-                        (long long) aalp->al_vcnstart));
+               dprintf(("%s: attrlist: ino: %d, attr: 0x%x, vcn: %qu\n",
+                   __func__, aalp->al_inumber, aalp->al_type,
+                   (long long) aalp->al_vcnstart));
 
                if (len > aalp->reclen) {
                        nextaalp = NTFS_NEXTREC(aalp, struct attr_attrlist *);
@@ -232,7 +229,7 @@
                     NTFS_AALPCMP(nextaalp, type, name, namelen)))
                        continue;
 
-               dprintf(("ntfs_ntvattrget: attribute in ino: %d\n",
+               dprintf(("%s: attribute in ino: %d\n", __func__,
                                 aalp->al_inumber));
 
                /* this is not a main record, so we can't use just plain
@@ -241,7 +238,7 @@
                                NTFS_A_DATA, NULL, LK_EXCLUSIVE,
                                VG_EXT, &newvp);
                if (error) {
-                       printf("ntfs_ntvattrget: CAN'T VGET INO: %d\n",
+                       printf("%s: CAN'T VGET INO: %d\n", __func__,
                               aalp->al_inumber);
                        goto out;
                }
@@ -252,13 +249,13 @@
                vput(newvp);
                if (error == 0)
                        goto out;
-               printf("ntfs_ntvattrget: ATTRLIST ERROR.\n");
+               printf("%s: ATTRLIST ERROR.\n", __func__);
                break;
        }
        error = ENOENT;
 
-       dprintf(("ntfs_ntvattrget: UNEXISTED ATTRIBUTE: "
-           "ino: %llu, type: 0x%x, name: %.*s, vcn: %qu\n",
+       dprintf(("%s: NON-EXISTANT ATTRIBUTE: ino: %llu, type: 0x%x, "
+           "name: %.*s, vcn: %qu\n", __func__,
            (unsigned long long)ip->i_number, type, (int)namelen,
            name, (long long)vcn));
 out:
@@ -282,16 +279,15 @@
        struct attr    *ap;
        struct ntvattr *nvap;
 
-       dprintf(("ntfs_loadntnode: loading ino: %llu\n",
+       dprintf(("%s: loading ino: %llu\n", __func__,
            (unsigned long long)ip->i_number));
 
-       mfrp = (struct filerec *) malloc(ntfs_bntob(ntmp->ntm_bpmftrec),
-              M_TEMP, M_WAITOK);
+       mfrp = malloc(ntfs_bntob(ntmp->ntm_bpmftrec), M_TEMP, M_WAITOK);
 
        if (ip->i_number < NTFS_SYSNODESNUM) {
                struct buf     *bp;
 
-               dprintf(("ntfs_loadntnode: read system node\n"));
+               dprintf(("%s: read system node\n", __func__));
 
                bn = ntfs_cntobn(ntmp->ntm_mftcn) +
                        ntmp->ntm_bpmftrec * ip->i_number;
@@ -300,7 +296,7 @@
                              bn, ntfs_bntob(ntmp->ntm_bpmftrec),
                              NOCRED, 0, &bp);
                if (error) {
-                       printf("ntfs_loadntnode: BREAD FAILED\n");
+                       printf("%s: BREAD FAILED\n", __func__);
                        brelse(bp, 0);
                        goto out;
                }
@@ -314,7 +310,7 @@
                               ip->i_number * ntfs_bntob(ntmp->ntm_bpmftrec),
                               ntfs_bntob(ntmp->ntm_bpmftrec), mfrp, NULL);
                if (error) {
-                       printf("ntfs_loadntnode: ntfs_readattr failed\n");
+                       printf("%s: ntfs_readattr failed\n", __func__);
                        goto out;
                }
        }
@@ -323,12 +319,12 @@
        error = ntfs_procfixups(ntmp, NTFS_FILEMAGIC, (void *)mfrp,
                                ntfs_bntob(ntmp->ntm_bpmftrec));
        if (error) {
-               printf("ntfs_loadntnode: BAD MFT RECORD %d\n",
+               printf("%s: BAD MFT RECORD %d\n", __func__,
                       (u_int32_t) ip->i_number);
                goto out;
        }
 
-       dprintf(("ntfs_loadntnode: load attrs for ino: %llu\n",
+       dprintf(("%s: load attrs for ino: %llu\n", __func__,
            (unsigned long long)ip->i_number));
        off = mfrp->fr_attroff;
        ap = (struct attr *) ((char *)mfrp + off);
@@ -347,7 +343,7 @@
                ap = (struct attr *) ((char *)mfrp + off);
        }
        if (error) {
-               printf("ntfs_loadntnode: failed to load attr ino: %llu\n",
+               printf("%s: failed to load attr ino: %llu\n", __func__,
                    (unsigned long long)ip->i_number);
                goto out;
        }
@@ -370,7 +366,7 @@
 int
 ntfs_ntget(struct ntnode *ip)
 {
-       dprintf(("ntfs_ntget: get ntnode %llu: %p, usecount: %d\n",
+       dprintf(("%s: get ntnode %llu: %p, usecount: %d\n", __func__,
            (unsigned long long)ip->i_number, ip, ip->i_usecount));
 
        mutex_enter(&ip->i_interlock);
@@ -399,19 +395,18 @@
 {
        struct ntnode  *ip;
 
-       dprintf(("ntfs_ntlookup: looking for ntnode %llu\n",
+       dprintf(("%s: looking for ntnode %llu\n", __func__,
            (unsigned long long)ino));
 
        if ((*ipp = ntfs_nthashlookup(ntmp->ntm_dev, ino)) != NULL) {
                ntfs_ntget(*ipp);
-               dprintf(("ntfs_ntlookup: ntnode %llu: %p,"
-                   " usecount: %d\n",
+               dprintf(("%s: ntnode %llu: %p, usecount: %d\n", __func__,
                    (unsigned long long)ino, *ipp, (*ipp)->i_usecount));
                return (0);
        }
 
-       ip = malloc(sizeof(struct ntnode), M_NTFSNTNODE, M_WAITOK|M_ZERO);
-       ddprintf(("ntfs_ntlookup: allocating ntnode: %llu: %p\n",
+       ip = malloc(sizeof(*ip), M_NTFSNTNODE, M_WAITOK|M_ZERO);
+       ddprintf(("%s: allocating ntnode: %llu: %p\n", __func__,
            (unsigned long long)ino, ip));
 
        mutex_enter(&ntfs_hashlock);
@@ -419,8 +414,7 @@
                mutex_exit(&ntfs_hashlock);
                ntfs_ntget(*ipp);
                free(ip, M_NTFSNTNODE);
-               dprintf(("ntfs_ntlookup: ntnode %llu: %p,"
-                   " usecount: %d\n",
+               dprintf(("%s: ntnode %llu: %p, usecount: %d\n", __func__,
                    (unsigned long long)ino, *ipp, (*ipp)->i_usecount));
                return (0);
        }
@@ -444,7 +438,7 @@
 
        *ipp = ip;
 
-       dprintf(("ntfs_ntlookup: ntnode %llu: %p, usecount: %d\n",
+       dprintf(("%s: ntnode %llu: %p, usecount: %d\n", __func__,
            (unsigned long long)ino, ip, ip->i_usecount));
 
        return (0);
@@ -461,7 +455,7 @@
 {
        struct ntvattr *vap;
 
-       dprintf(("ntfs_ntput: rele ntnode %llu: %p, usecount: %d\n",
+       dprintf(("%s: rele ntnode %llu: %p, usecount: %d\n", __func__,
            (unsigned long long)ip->i_number, ip, ip->i_usecount));
 
        mutex_enter(&ip->i_interlock);
@@ -479,7 +473,7 @@
        mutex_exit(&ip->i_interlock);
 
        if (ip->i_usecount == 0) {
-               dprintf(("ntfs_ntput: deallocating ntnode: %llu\n",
+               dprintf(("%s: deallocating ntnode: %llu\n", __func__,
                    (unsigned long long)ip->i_number));
 
                if (ip->i_fnlist.lh_first)
@@ -508,7 +502,7 @@
        ip->i_usecount++;
        mutex_exit(&ip->i_interlock);
 
-       dprintf(("ntfs_ntref: ino %llu, usecount: %d\n",
+       dprintf(("%s: ino %llu, usecount: %d\n", __func__,
            (unsigned long long)ip->i_number, ip->i_usecount));
 
 }
@@ -519,14 +513,14 @@
 void
 ntfs_ntrele(struct ntnode *ip)
 {
-       dprintf(("ntfs_ntrele: rele ntnode %llu: %p, usecount: %d\n",
+       dprintf(("%s: rele ntnode %llu: %p, usecount: %d\n", __func__,
            (unsigned long long)ip->i_number, ip, ip->i_usecount));
 
        mutex_enter(&ip->i_interlock);
        ip->i_usecount--;
 
        if (ip->i_usecount < 0)
-               panic("ntfs_ntrele: ino: %llu usecount: %d ",
+               panic("%s: ino: %llu usecount: %d ", __func__,
                    (unsigned long long)ip->i_number, ip->i_usecount);
        mutex_exit(&ip->i_interlock);
 }
@@ -565,14 +559,15 @@
        error = 0;
        *rvapp = NULL;
 
-       vap = malloc(sizeof(struct ntvattr), M_NTFSNTVATTR, M_WAITOK|M_ZERO);
+       vap = malloc(sizeof(*vap), M_NTFSNTVATTR, M_WAITOK|M_ZERO);



Home | Main Index | Thread Index | Old Index