clean up some chunks of the baboon code in here. as a bonus, it fixes an
off by one error in a string copy. yes, a fucking off by one string
termination bug in 2010. otherwise, i don't think this changes any
behavior.
Index: ntfs.h
===================================================================
RCS file: /home/tedu/cvs/src/sys/ntfs/ntfs.h,v
retrieving revision 1.8
diff -u -r1.8 ntfs.h
--- ntfs.h 6 Jun 2010 12:04:27 -0000 1.8
+++ ntfs.h 11 Aug 2010 23:49:44 -0000
@@ -283,11 +283,6 @@
#define ntfs_bntob(bn) (int32_t)((bn) * (ntmp)->ntm_bps)
typedef int (vop_t)(void *);
-#define HASHINIT(a, b, c, d) hashinit((a), (b), (c), (d))
-#define bqrelse(bp) brelse(bp)
-#define VOP__UNLOCK(a, b, c) VOP_UNLOCK((a), (b), (c))
-#define VGET(a, b, c) vget((a), (b), (c))
-#define VN_LOCK(a, b, c) vn_lock((a), (b), (c))
#if defined(NTFS_DEBUG)
extern int ntfs_debug;
Index: ntfs_ihash.c
===================================================================
RCS file: /home/tedu/cvs/src/sys/ntfs/ntfs_ihash.c,v
retrieving revision 1.7
diff -u -r1.7 ntfs_ihash.c
--- ntfs_ihash.c 23 Apr 2010 19:32:57 -0000 1.7
+++ ntfs_ihash.c 11 Aug 2010 23:50:01 -0000
@@ -64,7 +64,7 @@
void
ntfs_nthashinit()
{
- ntfs_nthashtbl = HASHINIT(desiredvnodes, M_NTFSNTHASH, M_WAITOK,
+ ntfs_nthashtbl = hashinit(desiredvnodes, M_NTFSNTHASH, M_WAITOK,
&ntfs_nthash);
}
Index: ntfs_subr.c
===================================================================
RCS file: /home/tedu/cvs/src/sys/ntfs/ntfs_subr.c,v
retrieving revision 1.19
diff -u -r1.19 ntfs_subr.c
--- ntfs_subr.c 6 Aug 2010 00:00:41 -0000 1.19
+++ ntfs_subr.c 11 Aug 2010 23:53:32 -0000
@@ -204,7 +204,7 @@
}
/* Scan $ATTRIBUTE_LIST for requested attribute */
len = lvap->va_datalen;
- alpool = (caddr_t) 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)
@@ -282,8 +282,7 @@
dprintf(("ntfs_loadntnode: loading ino: %d\n",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;
@@ -302,7 +301,7 @@
goto out;
}
memcpy(mfrp, bp->b_data, ntfs_bntob(ntmp->ntm_bpmftrec));
- bqrelse(bp);
+ brelse(bp);
} else {
struct vnode *vp;
@@ -584,8 +583,7 @@
vap->va_allocated = rap->a_r.a_datalen;
vap->va_vcnstart = 0;
vap->va_vcnend = ntfs_btocn(vap->va_allocated);
- vap->va_datap = (caddr_t) malloc(vap->va_datalen,
- M_NTFSRDATA, M_WAITOK);
+ vap->va_datap = malloc(vap->va_datalen, M_NTFSRDATA, M_WAITOK);
memcpy(vap->va_datap, (caddr_t) rap + rap->a_r.a_dataoff,
rap->a_r.a_datalen);
}
@@ -626,8 +624,8 @@
off += (run[off] & 0xF) + ((run[off] >> 4) & 0xF) + 1;
cnt++;
}
- cn = (cn_t *) malloc(cnt * sizeof(cn_t), M_NTFSRUN, M_WAITOK);
- cl = (cn_t *) malloc(cnt * sizeof(cn_t), M_NTFSRUN, M_WAITOK);
+ cn = malloc(cnt * sizeof(cn_t), M_NTFSRUN, M_WAITOK);
+ cl = malloc(cnt * sizeof(cn_t), M_NTFSRUN, M_WAITOK);
off = 0;
cnt = 0;
@@ -831,7 +829,7 @@
adp = ntmp->ntm_ad;
for (i = 0; i < ntmp->ntm_adnum; i++, adp++){
if (syslen != adp->ad_namelen ||
- strncmp(sys, adp->ad_name, syslen) != 0)
+ strncmp(sys, adp->ad_name, syslen) != 0)
continue;
*attrtype = adp->ad_type;
@@ -842,8 +840,8 @@
out:
if (namelen) {
- *attrname = (char *) malloc(namelen, M_TEMP, M_WAITOK);
- memcpy((*attrname), name, namelen);
+ *attrname = malloc(namelen + 1, M_TEMP, M_WAITOK);
+ memcpy(*attrname, name, namelen);
(*attrname)[namelen] = '\0';
*attrtype = NTFS_A_DATA;
}
@@ -910,7 +908,7 @@
blsize = vap->va_a_iroot->ir_size;
dprintf(("ntfs_ntlookupfile: blksz: %d\n", blsize));
- rdbuf = (caddr_t) malloc(blsize, M_TEMP, M_WAITOK);
+ rdbuf = malloc(blsize, M_TEMP, M_WAITOK);
loop:
rdsize = vap->va_datalen;
@@ -1188,8 +1186,8 @@
if (fp->f_dirblbuf == NULL) {
fp->f_dirblsz = vap->va_a_iroot->ir_size;
- fp->f_dirblbuf = (caddr_t) malloc(
- MAX(vap->va_datalen,fp->f_dirblsz), M_NTFSDIR, M_WAITOK);
+ fp->f_dirblbuf = malloc(MAX(vap->va_datalen,fp->f_dirblsz),
+ M_NTFSDIR, M_WAITOK);
}
blsize = fp->f_dirblsz;
@@ -1204,7 +1202,7 @@
error = ENOTDIR;
goto fail;
}
- bmp = (u_int8_t *) malloc(bmvap->va_datalen, M_TEMP, M_WAITOK);
+ bmp = malloc(bmvap->va_datalen, M_TEMP, M_WAITOK);
error = ntfs_readattr(ntmp, ip, NTFS_A_INDXBITMAP, "$I30", 0,
bmvap->va_datalen, bmp, NULL);
if (error)
Index: ntfs_vfsops.c
===================================================================
RCS file: /home/tedu/cvs/src/sys/ntfs/ntfs_vfsops.c,v
retrieving revision 1.18
diff -u -r1.18 ntfs_vfsops.c
--- ntfs_vfsops.c 8 Aug 2010 01:28:33 -0000 1.18
+++ ntfs_vfsops.c 11 Aug 2010 23:56:32 -0000
@@ -436,11 +436,10 @@
goto out1;
/* Count valid entries */
- for(num=0;;num++) {
+ for(num = 0; ; num++) {
error = ntfs_readattr(ntmp, VTONT(vp),
- NTFS_A_DATA, NULL,
- num * sizeof(ad), sizeof(ad),
- &ad, NULL);
+ NTFS_A_DATA, NULL, num * sizeof(ad), sizeof(ad),
+ &ad, NULL);
if (error)
goto out1;
if (ad.ad_name[0] == 0)
@@ -448,18 +447,16 @@
}
/* Alloc memory for attribute definitions */
- ntmp->ntm_ad = (struct ntvattrdef *) malloc(
- num * sizeof(struct ntvattrdef),
- M_NTFSMNT, M_WAITOK);
+ ntmp->ntm_ad = malloc(num * sizeof(struct ntvattrdef),
+ M_NTFSMNT, M_WAITOK);
ntmp->ntm_adnum = num;
/* Read them and translate */
- for(i=0;i<num;i++){
+ for(i = 0; i < num; i++){
error = ntfs_readattr(ntmp, VTONT(vp),
- NTFS_A_DATA, NULL,
- i * sizeof(ad), sizeof(ad),
- &ad, NULL);
+ NTFS_A_DATA, NULL, i * sizeof(ad), sizeof(ad),
+ &ad, NULL);
if (error)
goto out1;
j = 0;
@@ -501,9 +498,9 @@
}
/* lock the device vnode before calling VOP_CLOSE() */
- VN_LOCK(devvp, LK_EXCLUSIVE | LK_RETRY, p);
+ vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
- VOP__UNLOCK(devvp, 0, p);
+ VOP_UNLOCK(devvp, 0, p);
return (error);
}
@@ -634,7 +631,7 @@
bmsize = VTOF(vp)->f_size;
- tmp = (u_int8_t *) malloc(bmsize, M_TEMP, M_WAITOK);
+ tmp = malloc(bmsize, M_TEMP, M_WAITOK);
error = ntfs_readattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL,
0, bmsize, tmp, NULL);
@@ -828,7 +825,7 @@
if (FTOV(fp)) {
/* vget() returns error if the vnode has been recycled */
- if (VGET(FTOV(fp), lkflags, p) == 0) {
+ if (vget(FTOV(fp), lkflags, p) == 0) {
*vpp = FTOV(fp);
return (0);
}
@@ -851,7 +848,7 @@
vp->v_flag |= VROOT;
if (lkflags & LK_TYPE_MASK) {
- error = VN_LOCK(vp, lkflags, p);
+ error = vn_lock(vp, lkflags, p);
if (error) {
vput(vp);
return (error);
Index: ntfs_vnops.c
===================================================================
RCS file: /home/tedu/cvs/src/sys/ntfs/ntfs_vnops.c,v
retrieving revision 1.17
diff -u -r1.17 ntfs_vnops.c
--- ntfs_vnops.c 20 Apr 2010 22:05:44 -0000 1.17
+++ ntfs_vnops.c 11 Aug 2010 23:48:09 -0000
@@ -192,7 +192,7 @@
vprint("ntfs_inactive: pushing active", vp);
#endif
- VOP__UNLOCK(vp, 0, p);
+ VOP_UNLOCK(vp, 0, p);
/* XXX since we don't support any filesystem changes
* right now, nothing more needs to be done
@@ -658,7 +658,7 @@
dprintf(("ntfs_lookup: faking .. directory in %d\n",
dip->i_number));
- VOP__UNLOCK(dvp, 0, p);
+ VOP_UNLOCK(dvp, 0, p);
cnp->cn_flags |= PDIRUNLOCK;
error = ntfs_ntvattrget(ntmp, dip, NTFS_A_NAME, NULL, 0, &vap);
@@ -671,13 +671,13 @@
vap->va_a_name->n_pnumber,ap->a_vpp);
ntfs_ntvattrrele(vap);
if (error) {
- if (VN_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p) == 0)
+ if (vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, p) == 0)
cnp->cn_flags &= ~PDIRUNLOCK;
return (error);
}
if (lockparent && (cnp->cn_flags & ISLASTCN)) {
- error = VN_LOCK(dvp, LK_EXCLUSIVE, p);
+ error = vn_lock(dvp, LK_EXCLUSIVE, p);
if (error) {
vput( *(ap->a_vpp) );
return (error);
@@ -695,7 +695,7 @@
VTONT(*ap->a_vpp)->i_number));
if(!lockparent || (cnp->cn_flags & ISLASTCN) == 0) {
- VOP__UNLOCK(dvp, 0, p);
+ VOP_UNLOCK(dvp, 0, p);
cnp->cn_flags |= PDIRUNLOCK;
}
}