summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2010-09-04 21:35:59 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2010-09-04 21:35:59 +0000
commita1a7ffe8d6492c421846f4481a42ee6ad08fb638 (patch)
tree14439df99c4db5727d68dde8429acf62cf361170 /sys
parent4890afe69020fe918091de424fbecba5d6bd83cc (diff)
revert previous "simplification". kcornies at gmail says it doesn't work.
Diffstat (limited to 'sys')
-rw-r--r--sys/ntfs/ntfs_ihash.c7
-rw-r--r--sys/ntfs/ntfs_subr.c85
-rw-r--r--sys/ntfs/ntfs_subr.h6
-rw-r--r--sys/ntfs/ntfs_vfsops.c17
4 files changed, 91 insertions, 24 deletions
diff --git a/sys/ntfs/ntfs_ihash.c b/sys/ntfs/ntfs_ihash.c
index 714b60b912a..e22f1236eb5 100644
--- a/sys/ntfs/ntfs_ihash.c
+++ b/sys/ntfs/ntfs_ihash.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntfs_ihash.c,v 1.9 2010/08/22 21:23:07 tedu Exp $ */
+/* $OpenBSD: ntfs_ihash.c,v 1.10 2010/09/04 21:35:58 tedu Exp $ */
/* $NetBSD: ntfs_ihash.c,v 1.1 2002/12/23 17:38:32 jdolecek Exp $ */
/*
@@ -39,12 +39,17 @@
#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.
*/
diff --git a/sys/ntfs/ntfs_subr.c b/sys/ntfs/ntfs_subr.c
index 75396c01f47..185c040fa08 100644
--- a/sys/ntfs/ntfs_subr.c
+++ b/sys/ntfs/ntfs_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntfs_subr.c,v 1.21 2010/08/22 21:23:07 tedu Exp $ */
+/* $OpenBSD: ntfs_subr.c,v 1.22 2010/09/04 21:35:58 tedu Exp $ */
/* $NetBSD: ntfs_subr.c,v 1.4 2003/04/10 21:37:32 jdolecek Exp $ */
/*-
@@ -32,6 +32,7 @@
#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>
@@ -55,6 +56,13 @@
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;
@@ -68,10 +76,13 @@ static int ntfs_findvattr(struct ntfsmount *, struct ntnode *, struct ntvattr **
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 */
+/* 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_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) ( \
@@ -1965,16 +1976,32 @@ ntfs_runtocn(
#endif
/*
- * if the ntfs_toupper_tab[] is not filled already
- * read the data from the filesystem we are currently mounting
+ * 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
*/
int
-ntfs_load_toupper(struct mount *mp, struct ntfsmount *ntmp)
+ntfs_toupper_use(mp, ntmp, p)
+ struct mount *mp;
+ struct ntfsmount *ntmp;
+ struct proc *p;
{
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)
@@ -1985,23 +2012,45 @@ ntfs_load_toupper(struct mount *mp, struct ntfsmount *ntmp)
* XXX for now, just the first 256 entries are used anyway,
* so don't bother reading more
*/
- buf = malloc(256 * sizeof(wchar), M_NTFSRDATA, M_WAITOK);
+ ntfs_toupper_tab = malloc(256 * 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 * sizeof(wchar), ntfs_toupper_tab, NULL);
+ error = ntfs_readattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL,
+ 0, 256*256*sizeof(wchar), (char *) ntfs_toupper_tab,
+ NULL);
vput(vp);
- /* check we didn't lose a race */
- if (!ntfs_toupper_tab) {
- ntfs_toupper_tab = buf;
- buf = NULL;
- }
+ out:
+ ntfs_toupper_usecount++;
+ rw_exit_write(&ntfs_toupper_lock);
+ return (error);
+}
-out:
- if (buf)
- free(buf, M_NTFSRDATA);
+/*
+ * 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);
- return (error);
+ 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);
}
diff --git a/sys/ntfs/ntfs_subr.h b/sys/ntfs/ntfs_subr.h
index 589848da1c8..2a5fc111cae 100644
--- a/sys/ntfs/ntfs_subr.h
+++ b/sys/ntfs/ntfs_subr.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntfs_subr.h,v 1.5 2010/08/22 21:23:07 tedu Exp $ */
+/* $OpenBSD: ntfs_subr.h,v 1.6 2010/09/04 21:35:58 tedu Exp $ */
/* $NetBSD: ntfs_subr.h,v 1.1 2002/12/23 17:38:33 jdolecek Exp $ */
/*-
@@ -93,6 +93,7 @@ void ntfs_ntrele(struct ntnode *);
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 *);
@@ -100,7 +101,8 @@ int ntfs_ntlookupfile(struct ntfsmount *, struct vnode *, struct componentname *
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_load_toupper(struct mount *, struct ntfsmount *);
+int ntfs_toupper_use(struct mount *, struct ntfsmount *, struct proc *);
+void ntfs_toupper_unuse(struct proc *);
/* ntfs_conv.c stuff */
ntfs_wget_func_t ntfs_utf8_wget;
diff --git a/sys/ntfs/ntfs_vfsops.c b/sys/ntfs/ntfs_vfsops.c
index a23f681402c..cbc05b179f9 100644
--- a/sys/ntfs/ntfs_vfsops.c
+++ b/sys/ntfs/ntfs_vfsops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntfs_vfsops.c,v 1.20 2010/08/22 21:23:07 tedu Exp $ */
+/* $OpenBSD: ntfs_vfsops.c,v 1.21 2010/09/04 21:35:58 tedu Exp $ */
/* $NetBSD: ntfs_vfsops.c,v 1.7 2003/04/24 07:50:19 christos Exp $ */
/*-
@@ -68,6 +68,13 @@
#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 *);
@@ -143,6 +150,7 @@ ntfs_init (
struct vfsconf *vcp )
{
ntfs_nthashinit();
+ ntfs_toupper_init();
return 0;
}
@@ -404,14 +412,14 @@ ntfs_mountfs(devvp, mp, argsp, p)
/* read the Unicode lowercase --> uppercase translation table,
* if necessary */
- if ((error = ntfs_load_toupper(mp, ntmp)))
+ if ((error = ntfs_toupper_use(mp, ntmp, p)))
goto out1;
/*
* Scan $BitMap and count free clusters
*/
error = ntfs_calccfree(ntmp, &ntmp->ntm_cfree);
- if (error)
+ if(error)
goto out1;
/*
@@ -561,6 +569,9 @@ ntfs_unmount(
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;
mp->mnt_flag &= ~MNT_LOCAL;