no need for quite so many shenanigans for something as simple as a lookup
table. can anybody guess why it was multiplying by 256 twice?
also, fun fact: you don't need to initialize static data to 0. that's
what compilers are for.
Index: ntfs_ihash.c
===================================================================
RCS file: /cvs/src/sys/ntfs/ntfs_ihash.c,v
retrieving revision 1.8
diff -u -r1.8 ntfs_ihash.c
--- ntfs_ihash.c 12 Aug 2010 04:05:03 -0000 1.8
+++ ntfs_ihash.c 12 Aug 2010 04:27:53 -0000
@@ -39,16 +39,11 @@
#include <sys/rwlock.h>
#include <sys/vnode.h>
#include <sys/malloc.h>
-#include <sys/proc.h>
#include <sys/mount.h>
#include <ntfs/ntfs.h>
#include <ntfs/ntfs_inode.h>
#include <ntfs/ntfs_ihash.h>
-
-#ifdef MALLOC_DEFINE
-MALLOC_DEFINE(M_NTFSNTHASH, "NTFS nthash", "NTFS ntnode hash tables");
-#endif
/*
* Structures associated with inode cacheing.
Index: ntfs_subr.c
===================================================================
RCS file: /cvs/src/sys/ntfs/ntfs_subr.c,v
retrieving revision 1.20
diff -u -r1.20 ntfs_subr.c
--- ntfs_subr.c 12 Aug 2010 04:05:03 -0000 1.20
+++ ntfs_subr.c 12 Aug 2010 04:27:54 -0000
@@ -32,7 +32,6 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/namei.h>
-#include <sys/proc.h>
#include <sys/kernel.h>
#include <sys/vnode.h>
#include <sys/mount.h>
@@ -56,13 +55,6 @@
int ntfs_debug = NTFS_DEBUG;
#endif
-#ifdef MALLOC_DEFINE
-MALLOC_DEFINE(M_NTFSNTVATTR, "NTFS vattr", "NTFS file attribute information");
-MALLOC_DEFINE(M_NTFSRDATA, "NTFS res data", "NTFS resident data");
-MALLOC_DEFINE(M_NTFSRUN, "NTFS vrun", "NTFS vrun storage");
-MALLOC_DEFINE(M_NTFSDECOMP, "NTFS decomp", "NTFS decompression temporary");
-#endif
-
/* Local struct used in ntfs_ntlookupfile() */
struct ntfs_lookup_ctx {
u_int32_t aoff;
@@ -76,13 +68,10 @@
static int ntfs_uastricmp(struct ntfsmount *, const wchar *, size_t, const
char *, size_t);
static int ntfs_uastrcmp(struct ntfsmount *, const wchar *, size_t, const char
*, size_t);
-/* table for mapping Unicode chars into uppercase; it's filled upon first
- * ntfs mount, freed upon last ntfs umount */
+/* table for mapping Unicode chars into uppercase */
static wchar *ntfs_toupper_tab;
#define NTFS_U28(ch) ((((ch) & 0xE0) == 0) ? '_' : (ch) & 0xFF)
#define NTFS_TOUPPER(ch) (ntfs_toupper_tab[(unsigned char)(ch)])
-struct rwlock ntfs_toupper_lock = RWLOCK_INITIALIZER("ntfs_toupper");
-static signed int ntfs_toupper_usecount;
/* support macro for ntfs_ntvattrget() */
#define NTFS_AALPCMP(aalp,type,name,namelen) ( \
@@ -1976,32 +1965,16 @@
#endif
/*
- * this initializes toupper table & dependant variables to be ready for
- * later work
- */
-void
-ntfs_toupper_init()
-{
- ntfs_toupper_tab = (wchar *) NULL;
- ntfs_toupper_usecount = 0;
-}
-
-/*
- * if the ntfs_toupper_tab[] is filled already, just raise use count;
- * otherwise read the data from the filesystem we are currently mounting
+ * if the ntfs_toupper_tab[] is not filled already
+ * read the data from the filesystem we are currently mounting
*/
int
-ntfs_toupper_use(mp, ntmp, p)
- struct mount *mp;
- struct ntfsmount *ntmp;
- struct proc *p;
+ntfs_load_toupper(struct mount *mp, struct ntfsmount *ntmp)
{
int error = 0;
+ wchar *buf = NULL;
struct vnode *vp;
- /* get exclusive access */
- rw_enter_write(&ntfs_toupper_lock);
-
/* only read the translation data from a file if it hasn't been
* read already */
if (ntfs_toupper_tab)
@@ -2012,45 +1985,23 @@
* XXX for now, just the first 256 entries are used anyway,
* so don't bother reading more
*/
- ntfs_toupper_tab = malloc(256 * 256 * sizeof(wchar), M_NTFSRDATA,
- M_WAITOK);
+ buf = malloc(256 * sizeof(wchar), M_NTFSRDATA, M_WAITOK);
if ((error = VFS_VGET(mp, NTFS_UPCASEINO, &vp)))
goto out;
- error = ntfs_readattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL,
- 0, 256*256*sizeof(wchar), (char *) ntfs_toupper_tab,
- NULL);
+ error = ntfs_readattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL, 0,
+ 256 * sizeof(wchar), ntfs_toupper_tab, NULL);
vput(vp);
- out:
- ntfs_toupper_usecount++;
- rw_exit_write(&ntfs_toupper_lock);
- return (error);
-}
+ /* check we didn't lose a race */
+ if (!ntfs_toupper_tab) {
+ ntfs_toupper_tab = buf;
+ buf = NULL;
+ }
-/*
- * lower the use count and if it reaches zero, free the memory
- * tied by toupper table
- */
-void
-ntfs_toupper_unuse(p)
- struct proc *p;
-{
- /* get exclusive access */
- rw_enter_write(&ntfs_toupper_lock);
+out:
+ if (buf)
+ free(buf, M_NTFSRDATA);
- ntfs_toupper_usecount--;
- if (ntfs_toupper_usecount == 0) {
- free(ntfs_toupper_tab, M_NTFSRDATA);
- ntfs_toupper_tab = NULL;
- }
-#ifdef DIAGNOSTIC
- else if (ntfs_toupper_usecount < 0) {
- panic("ntfs_toupper_unuse(): use count negative: %d",
- ntfs_toupper_usecount);
- }
-#endif
-
- /* release the lock */
- rw_exit_write(&ntfs_toupper_lock);
+ return (error);
}
Index: ntfs_subr.h
===================================================================
RCS file: /cvs/src/sys/ntfs/ntfs_subr.h,v
retrieving revision 1.4
diff -u -r1.4 ntfs_subr.h
--- ntfs_subr.h 13 Aug 2009 16:00:53 -0000 1.4
+++ ntfs_subr.h 12 Aug 2010 04:27:54 -0000
@@ -93,7 +93,6 @@
int ntfs_loadntnode( struct ntfsmount *, struct ntnode * );
int ntfs_writentvattr_plain(struct ntfsmount *, struct ntnode *, struct
ntvattr *, off_t, size_t, void *, size_t *, struct uio *);
int ntfs_writeattr_plain(struct ntfsmount *, struct ntnode *, u_int32_t, char
*, off_t, size_t, void *, size_t *, struct uio *);
-void ntfs_toupper_init(void);
int ntfs_fget(struct ntfsmount *, struct ntnode *, int, char *, struct fnode
**);
void ntfs_frele(struct fnode *);
int ntfs_ntreaddir(struct ntfsmount *, struct fnode *, u_int32_t, struct
attr_indexentry **, struct proc *);
@@ -101,8 +100,7 @@
int ntfs_ntlookup(struct ntfsmount *, ino_t, struct ntnode **, struct proc *);
int ntfs_ntget(struct ntnode *, struct proc *);
void ntfs_ntput(struct ntnode *, struct proc *);
-int ntfs_toupper_use(struct mount *, struct ntfsmount *, struct proc *);
-void ntfs_toupper_unuse(struct proc *);
+int ntfs_load_toupper(struct mount *, struct ntfsmount *);
/* ntfs_conv.c stuff */
ntfs_wget_func_t ntfs_utf8_wget;
Index: ntfs_vfsops.c
===================================================================
RCS file: /cvs/src/sys/ntfs/ntfs_vfsops.c,v
retrieving revision 1.19
diff -u -r1.19 ntfs_vfsops.c
--- ntfs_vfsops.c 12 Aug 2010 04:05:03 -0000 1.19
+++ ntfs_vfsops.c 12 Aug 2010 04:27:54 -0000
@@ -68,13 +68,6 @@
#include <ntfs/ntfsmount.h>
#endif
-#ifdef MALLOC_DEFINE
-MALLOC_DEFINE(M_NTFSMNT, "NTFS mount", "NTFS mount structure");
-MALLOC_DEFINE(M_NTFSNTNODE,"NTFS ntnode", "NTFS ntnode information");
-MALLOC_DEFINE(M_NTFSFNODE,"NTFS fnode", "NTFS fnode information");
-MALLOC_DEFINE(M_NTFSDIR,"NTFS dir", "NTFS dir buffer");
-#endif
-
#if defined(__FreeBSD__)
static int ntfs_mount(struct mount *, char *, caddr_t,
struct nameidata *, struct proc *);
@@ -150,7 +143,6 @@
struct vfsconf *vcp )
{
ntfs_nthashinit();
- ntfs_toupper_init();
return 0;
}
@@ -412,14 +404,14 @@
/* read the Unicode lowercase --> uppercase translation table,
* if necessary */
- if ((error = ntfs_toupper_use(mp, ntmp, p)))
+ if ((error = ntfs_load_toupper(mp, ntmp)))
goto out1;
/*
* Scan $BitMap and count free clusters
*/
error = ntfs_calccfree(ntmp, &ntmp->ntm_cfree);
- if(error)
+ if (error)
goto out1;
/*
@@ -568,9 +560,6 @@
NOCRED, p);
vput(ntmp->ntm_devvp);
-
- /* free the toupper table, if this has been last mounted ntfs volume */
- ntfs_toupper_unuse(p);
dprintf(("ntfs_umount: freeing memory...\n"));
mp->mnt_data = NULL;