Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/ntfs Add per-mount filename conversion and compare hooks...
details: https://anonhg.NetBSD.org/src/rev/487a66628e75
branches: trunk
changeset: 503793:487a66628e75
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Tue Feb 13 19:53:52 2001 +0000
description:
Add per-mount filename conversion and compare hooks, which can be used
to recode Unicode names to other representation, like encoding form
or national character/code sets. This replaces the ugly NTFS_U28() hack.
Use these hooks to encode the filenames to UTF-8.
diffstat:
sys/ntfs/ntfs.h | 9 ++++-
sys/ntfs/ntfs_subr.c | 98 ++++++++++++++++++++++++++-----------------------
sys/ntfs/ntfs_subr.h | 8 +++-
sys/ntfs/ntfs_vfsops.c | 7 +++-
sys/ntfs/ntfs_vnops.c | 16 ++++++--
5 files changed, 83 insertions(+), 55 deletions(-)
diffs (287 lines):
diff -r e0e32838bf59 -r 487a66628e75 sys/ntfs/ntfs.h
--- a/sys/ntfs/ntfs.h Tue Feb 13 19:39:34 2001 +0000
+++ b/sys/ntfs/ntfs.h Tue Feb 13 19:53:52 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ntfs.h,v 1.10 2000/11/08 14:28:15 ad Exp $ */
+/* $NetBSD: ntfs.h,v 1.11 2001/02/13 19:53:52 jdolecek Exp $ */
/*-
* Copyright (c) 1998, 1999 Semen Ustimenko
@@ -240,6 +240,10 @@
u_int32_t bf_volsn; /* volume ser. num. */
};
+typedef wchar (ntfs_wget_func_t) __P((const char **));
+typedef int (ntfs_wput_func_t) __P((char *, size_t, wchar));
+typedef int (ntfs_wcmp_func_t) __P((wchar, wchar));
+
#define NTFS_SYSNODESNUM 0x0B
struct ntfsmount {
struct mount *ntm_mountp; /* filesystem vfs structure */
@@ -256,6 +260,9 @@
struct ntvattrdef *ntm_ad;
int ntm_adnum;
struct netexport ntm_export; /* export information */
+ ntfs_wget_func_t *ntm_wget; /* decode string to Unicode string */
+ ntfs_wput_func_t *ntm_wput; /* encode Unicode string to string */
+ ntfs_wcmp_func_t *ntm_wcmp; /* compare to wide characters */
};
#define ntm_mftcn ntm_bootfile.bf_mftcn
diff -r e0e32838bf59 -r 487a66628e75 sys/ntfs/ntfs_subr.c
--- a/sys/ntfs/ntfs_subr.c Tue Feb 13 19:39:34 2001 +0000
+++ b/sys/ntfs/ntfs_subr.c Tue Feb 13 19:53:52 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ntfs_subr.c,v 1.25 2001/02/12 19:17:05 jdolecek Exp $ */
+/* $NetBSD: ntfs_subr.c,v 1.26 2001/02/13 19:53:52 jdolecek Exp $ */
/*-
* Copyright (c) 1998, 1999 Semen Ustimenko (semenu%FreeBSD.org@localhost)
@@ -72,8 +72,8 @@
static int ntfs_ntlookupattr __P((struct ntfsmount *, const char *, int, int *, char **));
static int ntfs_findvattr __P((struct ntfsmount *, struct ntnode *, struct ntvattr **, struct ntvattr **, u_int32_t, const char *, size_t, cn_t));
-static int ntfs_uastricmp __P((const wchar *, size_t, const char *, size_t));
-static int ntfs_uastrcmp __P((const wchar *, size_t, const char *, size_t));
+static int ntfs_uastricmp __P((struct ntfsmount *, const wchar *, size_t, const char *, size_t));
+static int ntfs_uastrcmp __P((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 */
@@ -86,7 +86,7 @@
/* support macro for ntfs_ntvattrget() */
#define NTFS_AALPCMP(aalp,type,name,namelen) ( \
(aalp->al_type == type) && (aalp->al_namelen == namelen) && \
- !ntfs_uastrcmp(aalp->al_name,aalp->al_namelen,name,namelen) )
+ !ntfs_uastrcmp(ntmp, aalp->al_name,aalp->al_namelen,name,namelen) )
/*
*
@@ -669,7 +669,38 @@
* Compare unicode and ascii string case insens.
*/
static int
-ntfs_uastricmp(ustr, ustrlen, astr, astrlen)
+ntfs_uastricmp(ntmp, ustr, ustrlen, astr, astrlen)
+ struct ntfsmount *ntmp;
+ const wchar *ustr;
+ size_t ustrlen;
+ const char *astr;
+ size_t astrlen;
+{
+ size_t i;
+ int res;
+ const char *astrend = astr + astrlen;
+
+ for (i = 0; i < ustrlen && astr < astrend; i++) {
+ res = (*ntmp->ntm_wcmp)(NTFS_TOUPPER(ustr[i]),
+ NTFS_TOUPPER((*ntmp->ntm_wget)(&astr)) );
+ if (res)
+ return res;
+ }
+
+ if (i == ustrlen && astr == astrend)
+ return 0;
+ else if (i == ustrlen)
+ return -1;
+ else
+ return 1;
+}
+
+/*
+ * Compare unicode and ascii string case sens.
+ */
+static int
+ntfs_uastrcmp(ntmp, ustr, ustrlen, astr, astrlen)
+ struct ntfsmount *ntmp;
const wchar *ustr;
size_t ustrlen;
const char *astr;
@@ -677,34 +708,20 @@
{
size_t i;
int res;
+ const char *astrend = astr + astrlen;
- for (i = 0; i < ustrlen && i < astrlen; i++) {
- res = NTFS_TOUPPER(NTFS_U28(ustr[i])) - NTFS_TOUPPER(astr[i]);
+ for (i = 0; (i < ustrlen) && (astr < astrend); i++) {
+ res = (*ntmp->ntm_wcmp)(ustr[i], (*ntmp->ntm_wget)(&astr));
if (res)
return res;
}
- return (ustrlen - astrlen);
-}
-/*
- * Compare unicode and ascii string case sens.
- */
-static int
-ntfs_uastrcmp(ustr, ustrlen, astr, astrlen)
- const wchar *ustr;
- size_t ustrlen;
- const char *astr;
- size_t astrlen;
-{
- size_t i;
- int res;
-
- for (i = 0; (i < ustrlen) && (i < astrlen); i++) {
- res = NTFS_U28(ustr[i]) - (u_char) astr[i];
- if (res)
- return res;
- }
- return (ustrlen - astrlen);
+ if (i == ustrlen && astr == astrend)
+ return 0;
+ else if (i == ustrlen)
+ return -1;
+ else
+ return 1;
}
/*
@@ -924,8 +941,8 @@
/* 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);
+ res = ntfs_uastricmp(ntmp, iep->ie_fname,
+ iep->ie_fnamelen, fname, fnamelen);
if (!fullscan) {
if (res > 0) break;
if (res < 0) continue;
@@ -934,7 +951,7 @@
if (iep->ie_fnametype == 0 ||
!(ntmp->ntm_flag & NTFS_MFLAG_CASEINS))
{
- res = ntfs_uastrcmp(iep->ie_fname,
+ res = ntfs_uastrcmp(ntmp, iep->ie_fname,
iep->ie_fnamelen, fname, fnamelen);
if (res != 0 && !fullscan) continue;
}
@@ -2014,13 +2031,14 @@
* XXX for now, just the first 256 entries are used anyway,
* so don't bother reading more
*/
- MALLOC(ntfs_toupper_tab, wchar *, 256 * sizeof(wchar),
+ MALLOC(ntfs_toupper_tab, wchar *, 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), (char *) ntfs_toupper_tab, NULL);
+ 0, 256*256*sizeof(wchar), (char *) ntfs_toupper_tab,
+ NULL);
vput(vp);
out:
@@ -2054,17 +2072,3 @@
/* release the lock */
lockmgr(&ntfs_toupper_lock, LK_RELEASE, NULL);
}
-
-/*
- * maps the Unicode char to 8bit equivalent
- * XXX currently only gets lower 8bit from the Unicode char
- * and substitutes a '_' for it if the result would be '\0';
- * something better has to be definitely though out
- */
-char
-ntfs_u28(unichar)
- wchar unichar;
-{
- return (char) NTFS_U28(unichar);
-}
-
diff -r e0e32838bf59 -r 487a66628e75 sys/ntfs/ntfs_subr.h
--- a/sys/ntfs/ntfs_subr.h Tue Feb 13 19:39:34 2001 +0000
+++ b/sys/ntfs/ntfs_subr.h Tue Feb 13 19:53:52 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ntfs_subr.h,v 1.8 1999/10/10 14:48:37 jdolecek Exp $ */
+/* $NetBSD: ntfs_subr.h,v 1.9 2001/02/13 19:53:52 jdolecek Exp $ */
/*-
* Copyright (c) 1998, 1999 Semen Ustimenko
@@ -80,7 +80,6 @@
int ntfs_times __P(( struct ntfsmount *, struct ntnode *, ntfs_times_t *));
struct timespec ntfs_nttimetounix __P(( u_int64_t ));
int ntfs_ntreaddir __P(( struct ntfsmount *, struct fnode *, u_int32_t, struct attr_indexentry **));
-char ntfs_u28 __P((wchar));
int ntfs_runtovrun __P(( cn_t **, cn_t **, u_long *, u_int8_t *));
int ntfs_attrtontvattr __P(( struct ntfsmount *, struct ntvattr **, struct attr * ));
void ntfs_freentvattr __P(( struct ntvattr * ));
@@ -103,3 +102,8 @@
void ntfs_toupper_unuse __P((void));
int ntfs_fget __P((struct ntfsmount *, struct ntnode *, int, char *, struct fnode **));
void ntfs_frele __P((struct fnode *));
+
+/* ntfs_conv.c stuff */
+ntfs_wget_func_t ntfs_utf8_wget;
+ntfs_wput_func_t ntfs_utf8_wput;
+ntfs_wcmp_func_t ntfs_utf8_wcmp;
diff -r e0e32838bf59 -r 487a66628e75 sys/ntfs/ntfs_vfsops.c
--- a/sys/ntfs/ntfs_vfsops.c Tue Feb 13 19:39:34 2001 +0000
+++ b/sys/ntfs/ntfs_vfsops.c Tue Feb 13 19:53:52 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ntfs_vfsops.c,v 1.32 2001/02/10 14:28:51 jdolecek Exp $ */
+/* $NetBSD: ntfs_vfsops.c,v 1.33 2001/02/13 19:53:52 jdolecek Exp $ */
/*-
* Copyright (c) 1998, 1999 Semen Ustimenko
@@ -495,6 +495,11 @@
ntmp->ntm_flag = argsp->flag;
mp->mnt_data = (qaddr_t)ntmp;
+ /* set file name encode/decode hooks XXX utf-8 only for now */
+ ntmp->ntm_wget = ntfs_utf8_wget;
+ ntmp->ntm_wput = ntfs_utf8_wput;
+ ntmp->ntm_wcmp = ntfs_utf8_wcmp;
+
dprintf(("ntfs_mountfs(): case-%s,%s uid: %d, gid: %d, mode: %o\n",
(ntmp->ntm_flag & NTFS_MFLAG_CASEINS)?"insens.":"sens.",
(ntmp->ntm_flag & NTFS_MFLAG_ALLNAMES)?" allnames,":"",
diff -r e0e32838bf59 -r 487a66628e75 sys/ntfs/ntfs_vnops.c
--- a/sys/ntfs/ntfs_vnops.c Tue Feb 13 19:39:34 2001 +0000
+++ b/sys/ntfs/ntfs_vnops.c Tue Feb 13 19:53:52 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ntfs_vnops.c,v 1.31 2001/01/22 12:17:37 jdolecek Exp $ */
+/* $NetBSD: ntfs_vnops.c,v 1.32 2001/02/13 19:53:52 jdolecek Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -623,6 +623,9 @@
while( uio->uio_resid >= sizeof(struct dirent) ) {
struct attr_indexentry *iep;
+ char *fname;
+ size_t remains;
+ int sz;
error = ntfs_ntreaddir(ntmp, fp, num, &iep);
@@ -638,14 +641,19 @@
if(!ntfs_isnamepermitted(ntmp,iep))
continue;
+ remains = sizeof(cde.d_name) - 1;
+ fname = cde.d_name;
for(i=0; i<iep->ie_fnamelen; i++) {
- cde.d_name[i] = ntfs_u28(iep->ie_fname[i]);
+ sz = (*ntmp->ntm_wput)(fname, remains,
+ iep->ie_fname[i]);
+ fname += sz;
+ remains -= sz;
}
- cde.d_name[i] = '\0';
+ *fname = '\0';
dprintf(("ntfs_readdir: elem: %d, fname:[%s] type: %d, flag: %d, ",
num, cde.d_name, iep->ie_fnametype,
iep->ie_flag));
- cde.d_namlen = iep->ie_fnamelen;
+ cde.d_namlen = fname - (char *) cde.d_name + 1;
cde.d_fileno = iep->ie_number;
cde.d_type = (iep->ie_fflag & NTFS_FFLAG_DIR) ? DT_DIR : DT_REG;
cde.d_reclen = sizeof(struct dirent);
Home |
Main Index |
Thread Index |
Old Index