aboutsummaryrefslogtreecommitdiff
path: root/sbin/mount_udf
diff options
context:
space:
mode:
authorScott Long <scottl@FreeBSD.org>2003-11-05 06:21:45 +0000
committerScott Long <scottl@FreeBSD.org>2003-11-05 06:21:45 +0000
commitcc2c948fb55612e17e5615cfaab13f9f0c9f3452 (patch)
tree2f76e11835b791a6ed0a28cce865fbe610719dcb /sbin/mount_udf
parent252af39a9690b5b7ece2100903f83aaf47264ae8 (diff)
downloadsrc-cc2c948fb55612e17e5615cfaab13f9f0c9f3452.tar.gz
src-cc2c948fb55612e17e5615cfaab13f9f0c9f3452.zip
Add support for multibyte character conversions.
Submitted by: imura@ryu16.org
Notes
Notes: svn path=/head/; revision=122097
Diffstat (limited to 'sbin/mount_udf')
-rw-r--r--sbin/mount_udf/Makefile6
-rw-r--r--sbin/mount_udf/mount_udf.85
-rw-r--r--sbin/mount_udf/mount_udf.c93
3 files changed, 86 insertions, 18 deletions
diff --git a/sbin/mount_udf/Makefile b/sbin/mount_udf/Makefile
index 3e33dfea21b4..bd9163c8720c 100644
--- a/sbin/mount_udf/Makefile
+++ b/sbin/mount_udf/Makefile
@@ -3,10 +3,16 @@
PROG= mount_udf
SRCS= mount_udf.c getmntopts.c
MAN= mount_udf.8
+DPADD= ${LIBKICONV}
+LDADD= -lkiconv
MOUNT= ${.CURDIR}/../mount
CFLAGS+= -I${MOUNT} -I${.CURDIR}/../../sys -Wall
.PATH: ${MOUNT}
WARNS= 1
+# Needs to be dynamically linked for optional dlopen() access to
+# userland libiconv
+NOSHARED?= NO
+
.include <bsd.prog.mk>
diff --git a/sbin/mount_udf/mount_udf.8 b/sbin/mount_udf/mount_udf.8
index aae29f8c94ba..f91a866542c2 100644
--- a/sbin/mount_udf/mount_udf.8
+++ b/sbin/mount_udf/mount_udf.8
@@ -36,6 +36,7 @@
.Nm
.Op Fl v
.Op Fl o Ar options
+.Op Fl C Ar charset
.Ar special | node
.Sh DESCRIPTION
The
@@ -57,6 +58,10 @@ man page for possible options and their meanings.
The following UDF specific options are available:
.It Fl v
Be verbose about mounting the UDF file system.
+.It Fl C Ar charset
+Specify local
+.Ar charset
+to convert Unicode file names.
.El
.Sh SEE ALSO
.Xr cdcontrol 1 ,
diff --git a/sbin/mount_udf/mount_udf.c b/sbin/mount_udf/mount_udf.c
index eb68a4d02e78..825d54be258d 100644
--- a/sbin/mount_udf/mount_udf.c
+++ b/sbin/mount_udf/mount_udf.c
@@ -46,10 +46,15 @@
#include <sys/cdio.h>
#include <sys/file.h>
+#include <sys/iconv.h>
#include <sys/param.h>
+#include <sys/linker.h>
+#include <sys/module.h>
#include <sys/mount.h>
#include <sys/uio.h>
+#include <fs/udf/udf_mount.h>
+
#include <err.h>
#include <errno.h>
#include <stdlib.h>
@@ -66,18 +71,21 @@ struct mntopt mopts[] = {
{ NULL, 0, 0, 0 }
};
+int set_charset(char **, char **, const char *);
void usage(void);
int
main(int argc, char **argv)
{
- struct iovec iov[6];
- int ch, mntflags, opts;
+ struct iovec iov[12];
+ int ch, i, mntflags, opts, udf_flags;
char *dev, *dir, mntpath[MAXPATHLEN];
+ char *cs_disk, *cs_local;
int verbose;
- mntflags = opts = verbose = 0;
- while ((ch = getopt(argc, argv, "o:v")) != -1)
+ i = mntflags = opts = udf_flags = verbose = 0;
+ cs_disk = cs_local = NULL;
+ while ((ch = getopt(argc, argv, "o:vC:")) != -1)
switch (ch) {
case 'o':
getmntopts(optarg, mopts, &mntflags, &opts);
@@ -85,6 +93,11 @@ main(int argc, char **argv)
case 'v':
verbose++;
break;
+ case 'C':
+ if (set_charset(&cs_disk, &cs_local, optarg) == -1)
+ err(EX_OSERR, "udf_iconv");
+ udf_flags |= UDFMNT_KICONV;
+ break;
case '?':
default:
usage();
@@ -110,27 +123,71 @@ main(int argc, char **argv)
*/
mntflags |= MNT_RDONLY;
- iov[0].iov_base = "fstype";
- iov[0].iov_len = sizeof("fstype");
- iov[1].iov_base = "udf";
- iov[1].iov_len = strlen(iov[1].iov_base) + 1;
- iov[2].iov_base = "fspath";
- iov[2].iov_len = sizeof("fspath");
- iov[3].iov_base = mntpath;
- iov[3].iov_len = strlen(mntpath) + 1;
- iov[4].iov_base = "from";
- iov[4].iov_len = sizeof("from");
- iov[5].iov_base = dev;
- iov[5].iov_len = strlen(dev) + 1;
- if (nmount(iov, 6, mntflags) < 0)
+ iov[i].iov_base = "fstype";
+ iov[i++].iov_len = sizeof("fstype");
+ iov[i].iov_base = "udf";
+ iov[i].iov_len = strlen(iov[i].iov_base) + 1;
+ i++;
+ iov[i].iov_base = "fspath";
+ iov[i++].iov_len = sizeof("fspath");
+ iov[i].iov_base = mntpath;
+ iov[i++].iov_len = strlen(mntpath) + 1;
+ iov[i].iov_base = "from";
+ iov[i++].iov_len = sizeof("from");
+ iov[i].iov_base = dev;
+ iov[i++].iov_len = strlen(dev) + 1;
+ iov[i].iov_base = "flags";
+ iov[i++].iov_len = sizeof("flags");
+ iov[i].iov_base = &udf_flags;
+ iov[i++].iov_len = sizeof(udf_flags);
+ if (udf_flags & UDFMNT_KICONV) {
+ iov[i].iov_base = "cs_disk";
+ iov[i++].iov_len = sizeof("cs_disk") + 1;
+ iov[i].iov_base = cs_disk;
+ iov[i++].iov_len = strlen(cs_disk) + 1;
+ iov[i].iov_base = "cs_local";
+ iov[i++].iov_len = sizeof("cs_local") + 1;
+ iov[i].iov_base = cs_local;
+ iov[i++].iov_len = strlen(cs_local) + 1;
+ }
+ if (nmount(iov, i, mntflags) < 0)
err(1, "%s", dev);
exit(0);
}
+int
+set_charset(char **cs_disk, char **cs_local, const char *localcs)
+{
+ int error;
+
+ if (modfind("udf_iconv") < 0)
+ if (kldload("udf_iconv") < 0 || modfind("udf_iconv") < 0) {
+ warnx( "cannot find or load \"udf_iconv\" kernel module");
+ return (-1);
+ }
+
+ if ((*cs_disk = malloc(ICONV_CSNMAXLEN)) == NULL)
+ return (-1);
+ if ((*cs_local = malloc(ICONV_CSNMAXLEN)) == NULL)
+ return (-1);
+ strncpy(*cs_disk, ENCODING_UNICODE, ICONV_CSNMAXLEN);
+ strncpy(*cs_local, localcs, ICONV_CSNMAXLEN);
+ error = kiconv_add_xlat16_cspair(*cs_local, *cs_disk, 0);
+ if (error)
+ return (-1);
+#if 0
+ error = kiconv_add_xlat16_cspair(*cs_disk, *cs_local, 0);
+ if (error)
+ return (-1);
+#endif
+
+ return (0);
+}
+
void
usage(void)
{
(void)fprintf(stderr,
- "usage: mount_udf [-v] [-o options] special node\n");
+ "usage: mount_udf [-v] [-o options] [-C charset] special node\n");
exit(EX_USAGE);
}