Date: Tue, 05 Jun 2012 11:45:00 +0000 From: oleksandr@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r237125 - soc2012/oleksandr/udf-head/sbin/mount_udf2 Message-ID: <20120605114500.5C2ED106564A@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: oleksandr Date: Tue Jun 5 11:44:59 2012 New Revision: 237125 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=237125 Log: add command for mounting udf2 Added: soc2012/oleksandr/udf-head/sbin/mount_udf2/ soc2012/oleksandr/udf-head/sbin/mount_udf2/Makefile soc2012/oleksandr/udf-head/sbin/mount_udf2/getmntopts.c soc2012/oleksandr/udf-head/sbin/mount_udf2/mntopts.h soc2012/oleksandr/udf-head/sbin/mount_udf2/mount_udf.8 soc2012/oleksandr/udf-head/sbin/mount_udf2/mount_udf.c Added: soc2012/oleksandr/udf-head/sbin/mount_udf2/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/oleksandr/udf-head/sbin/mount_udf2/Makefile Tue Jun 5 11:44:59 2012 (r237125) @@ -0,0 +1,20 @@ +# $FreeBSD: src/sbin/mount_udf/Makefile,v 1.6 2006/07/17 20:53:25 stefanf Exp $ + +PROG= mount_udf2 +SRCS= mount_udf.c getmntopts.c +MAN= mount_udf.8 +DPADD= ${LIBKICONV} +LDADD= -lkiconv + +#MOUNT= ${.CURDIR}/../mount +#CFLAGS+= -I${MOUNT} -I${.CURDIR}/../../sys +#.PATH: ${MOUNT} +WARNS?= 1 + +# Needs to be dynamically linked for optional dlopen() access to +# userland libiconv +NO_SHARED?= NO + +BINDIR=/sbin + +.include <bsd.prog.mk> Added: soc2012/oleksandr/udf-head/sbin/mount_udf2/getmntopts.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/oleksandr/udf-head/sbin/mount_udf2/getmntopts.c Tue Jun 5 11:44:59 2012 (r237125) @@ -0,0 +1,182 @@ +/*- + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if 0 +#ifndef lint +static char sccsid[] = "@(#)getmntopts.c 8.3 (Berkeley) 3/29/95"; +#endif /* not lint */ +#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD: src/sbin/mount/getmntopts.c,v 1.19 2008/12/26 22:55:38 obrien Exp $"); + +#include <sys/param.h> +#include <sys/mount.h> +#include <sys/stat.h> +#include <sys/uio.h> + +#include <err.h> +#include <errno.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sysexits.h> + +#include "mntopts.h" + +int getmnt_silent = 0; + +void +getmntopts(const char *options, const struct mntopt *m0, int *flagp, + int *altflagp) +{ + const struct mntopt *m; + int negative, len; + char *opt, *optbuf, *p; + int *thisflagp; + + /* Copy option string, since it is about to be torn asunder... */ + if ((optbuf = strdup(options)) == NULL) + err(1, NULL); + + for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) { + /* Check for "no" prefix. */ + if (opt[0] == 'n' && opt[1] == 'o') { + negative = 1; + opt += 2; + } else + negative = 0; + + /* + * for options with assignments in them (ie. quotas) + * ignore the assignment as it's handled elsewhere + */ + p = strchr(opt, '='); + if (p != NULL) + *++p = '\0'; + + /* Scan option table. */ + for (m = m0; m->m_option != NULL; ++m) { + len = strlen(m->m_option); + if (strncasecmp(opt, m->m_option, len) == 0) + if (opt[len] == '\0' || opt[len] == '=') + break; + } + + /* Save flag, or fail if option is not recognized. */ + if (m->m_option) { + thisflagp = m->m_altloc ? altflagp : flagp; + if (negative == m->m_inverse) + *thisflagp |= m->m_flag; + else + *thisflagp &= ~m->m_flag; + } else if (!getmnt_silent) { + errx(1, "-o %s: option not supported", opt); + } + } + + free(optbuf); +} + +void +rmslashes(char *rrpin, char *rrpout) +{ + char *rrpoutstart; + + *rrpout = *rrpin; + for (rrpoutstart = rrpout; *rrpin != '\0'; *rrpout++ = *rrpin++) { + + /* skip all double slashes */ + while (*rrpin == '/' && *(rrpin + 1) == '/') + rrpin++; + } + + /* remove trailing slash if necessary */ + if (rrpout - rrpoutstart > 1 && *(rrpout - 1) == '/') + *(rrpout - 1) = '\0'; + else + *rrpout = '\0'; +} + +void +checkpath(const char *path, char *resolved) +{ + struct stat sb; + + if (realpath(path, resolved) != NULL && stat(resolved, &sb) == 0) { + if (!S_ISDIR(sb.st_mode)) + errx(EX_USAGE, "%s: not a directory", resolved); + } else + errx(EX_USAGE, "%s: %s", resolved, strerror(errno)); +} + +void +build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, + size_t len) +{ + int i; + + if (*iovlen < 0) + return; + i = *iovlen; + *iov = realloc(*iov, sizeof **iov * (i + 2)); + if (*iov == NULL) { + *iovlen = -1; + return; + } + (*iov)[i].iov_base = strdup(name); + (*iov)[i].iov_len = strlen(name) + 1; + i++; + (*iov)[i].iov_base = val; + if (len == (size_t)-1) { + if (val != NULL) + len = strlen(val) + 1; + else + len = 0; + } + (*iov)[i].iov_len = (int)len; + *iovlen = ++i; +} + +/* + * This function is needed for compatibility with parameters + * which used to use the mount_argf() command for the old mount() syscall. + */ +void +build_iovec_argf(struct iovec **iov, int *iovlen, const char *name, + const char *fmt, ...) +{ + va_list ap; + char val[255] = { 0 }; + + va_start(ap, fmt); + vsnprintf(val, sizeof(val), fmt, ap); + va_end(ap); + build_iovec(iov, iovlen, name, strdup(val), (size_t)-1); +} Added: soc2012/oleksandr/udf-head/sbin/mount_udf2/mntopts.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/oleksandr/udf-head/sbin/mount_udf2/mntopts.h Tue Jun 5 11:44:59 2012 (r237125) @@ -0,0 +1,99 @@ +/*- + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)mntopts.h 8.7 (Berkeley) 3/29/95 + * $FreeBSD: src/sbin/mount/mntopts.h,v 1.30 2009/12/21 19:39:10 trasz Exp $ + */ + +struct mntopt { + const char *m_option; /* option name */ + int m_inverse; /* if a negative option, e.g. "atime" */ + int m_flag; /* bit to set, e.g. MNT_RDONLY */ + int m_altloc; /* 1 => set bit in altflags */ +}; + +/* User-visible MNT_ flags. */ +#define MOPT_ASYNC { "async", 0, MNT_ASYNC, 0 } +#define MOPT_NOATIME { "atime", 1, MNT_NOATIME, 0 } +#define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC, 0 } +#define MOPT_NOSUID { "suid", 1, MNT_NOSUID, 0 } +#define MOPT_NOSYMFOLLOW { "symfollow", 1, MNT_NOSYMFOLLOW, 0 } +#define MOPT_RDONLY { "rdonly", 0, MNT_RDONLY, 0 } +#define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS, 0 } +#define MOPT_UNION { "union", 0, MNT_UNION, 0 } +#define MOPT_USERQUOTA { "userquota", 0, 0, 0 } +#define MOPT_GROUPQUOTA { "groupquota", 0, 0, 0 } +#define MOPT_NOCLUSTERR { "clusterr", 1, MNT_NOCLUSTERR, 0 } +#define MOPT_NOCLUSTERW { "clusterw", 1, MNT_NOCLUSTERW, 0 } +#define MOPT_SUIDDIR { "suiddir", 0, MNT_SUIDDIR, 0 } +#define MOPT_SNAPSHOT { "snapshot", 0, MNT_SNAPSHOT, 0 } +#define MOPT_MULTILABEL { "multilabel", 0, MNT_MULTILABEL, 0 } +#define MOPT_ACLS { "acls", 0, MNT_ACLS, 0 } +#define MOPT_NFS4ACLS { "nfsv4acls", 0, MNT_NFS4ACLS, 0 } + +/* Control flags. */ +#define MOPT_FORCE { "force", 0, MNT_FORCE, 0 } +#define MOPT_UPDATE { "update", 0, MNT_UPDATE, 0 } +#define MOPT_RO { "ro", 0, MNT_RDONLY, 0 } +#define MOPT_RW { "rw", 1, MNT_RDONLY, 0 } + +/* This is parsed by mount(8), but is ignored by specific mount_*(8)s. */ +#define MOPT_AUTO { "auto", 0, 0, 0 } + +/* A handy macro as terminator of MNT_ array. */ +#define MOPT_END { NULL, 0, 0, 0 } + +#define MOPT_FSTAB_COMPAT \ + MOPT_RO, \ + MOPT_RW, \ + MOPT_AUTO + +/* Standard options which all mounts can understand. */ +#define MOPT_STDOPTS \ + MOPT_USERQUOTA, \ + MOPT_GROUPQUOTA, \ + MOPT_FSTAB_COMPAT, \ + MOPT_NOATIME, \ + MOPT_NOEXEC, \ + MOPT_SUIDDIR, /* must be before MOPT_NOSUID */ \ + MOPT_NOSUID, \ + MOPT_NOSYMFOLLOW, \ + MOPT_RDONLY, \ + MOPT_UNION, \ + MOPT_NOCLUSTERR, \ + MOPT_NOCLUSTERW, \ + MOPT_MULTILABEL, \ + MOPT_ACLS, \ + MOPT_NFS4ACLS + +void getmntopts(const char *, const struct mntopt *, int *, int *); +void rmslashes(char *, char *); +void checkpath(const char *, char resolved_path[]); +extern int getmnt_silent; +void build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, size_t len); +void build_iovec_argf(struct iovec **iov, int *iovlen, const char *name, const char *fmt, ...); Added: soc2012/oleksandr/udf-head/sbin/mount_udf2/mount_udf.8 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/oleksandr/udf-head/sbin/mount_udf2/mount_udf.8 Tue Jun 5 11:44:59 2012 (r237125) @@ -0,0 +1,76 @@ +.\" Copyright (c) 2002 +.\" Scott Long <scottl@FreeBSD.org> +.\" Jeroen Ruigrok van der Werven <asmodai@wxs.nl> +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/sbin/mount_udf/mount_udf.8,v 1.6 2005/02/10 09:19:31 ru Exp $ +.\" +.Dd March 23, 2002 +.Dt MOUNT_UDF 8 +.Os +.Sh NAME +.Nm mount_udf +.Nd mount a UDF file system +.Sh SYNOPSIS +.Nm +.Op Fl v +.Op Fl o Ar options +.Op Fl C Ar charset +.Ar special node +.Sh DESCRIPTION +The +.Nm +utility attaches the UDF file system residing on the device +.Ar special +to the global file system namespace at the location indicated by +.Ar node . +.Pp +The options are as follows: +.Bl -tag -width indent +.It Fl o +Options are specified with a +.Fl o +flag followed by a comma separated string of options. +See the +.Xr mount 8 +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 , +.Xr mount 2 , +.Xr unmount 2 , +.Xr fstab 5 , +.Xr mount 8 +.Sh HISTORY +The +.Nm +utility first appeared in +.Fx 5.0 . Added: soc2012/oleksandr/udf-head/sbin/mount_udf2/mount_udf.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/oleksandr/udf-head/sbin/mount_udf2/mount_udf.c Tue Jun 5 11:44:59 2012 (r237125) @@ -0,0 +1,284 @@ +/* + * Copyright (c) 1992, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * Copyright (c) 2002 Scott Long + * + * This code is derived from software contributed to Berkeley + * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension + * Support code is derived from software contributed to Berkeley + * by Atsushi Murai (amurai@spec.co.jp). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/sbin/mount_udf/mount_udf.c,v 1.13 2005/06/10 09:51:43 delphij Exp $ + */ + +/* + * This is just a rip-off of mount_iso9660.c. It's been vastly simplified + * because UDF doesn't take any options at this time. + */ + +#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 <sys/endian.h> +#include <sys/ioctl.h> +#include <sys/udfio.h> + + +#include <err.h> +#include <errno.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <sysexits.h> +#include <unistd.h> +#include <fcntl.h> + +#include "mntopts.h" +//#include "fs/udf2/udf_mount.h" +#include "udf2/udf_mount.h" + + +struct mntopt mopts[] = { + MOPT_STDOPTS, + MOPT_UPDATE, + MOPT_END +}; + +static int set_charset(char **, char **, const char *); +static void getlastblock(char *dev, struct udf_session_info *usi, + int session_num); +static void usage(void); +static void print_session_info(char *dev, int session_num); + +int +main(int argc, char **argv) +{ + struct udf_session_info usi; + struct iovec iov[18]; + long session_num; + int ch, i, mntflags, opts, udf_flags, sessioninfo, verbose; + int32_t first_trackblank; + char *dev, *dir, mntpath[MAXPATHLEN], *cs_disk, *cs_local, *endp; + + session_num = 0; + sessioninfo = 0; + + i = mntflags = opts = udf_flags = verbose = 0; + cs_disk = cs_local = NULL; + while ((ch = getopt(argc, argv, "o:vC:s:p")) != -1) + switch (ch) { + case 'o': + getmntopts(optarg, mopts, &mntflags, &opts); + break; + case 'v': + verbose++; + break; + case 'C': + if (set_charset(&cs_disk, &cs_local, optarg) == -1) + err(EX_OSERR, "udf2_iconv"); + udf_flags |= UDFMNT_KICONV; + break; + case 's': + session_num = strtol(optarg, &endp, 10); + if (optarg == endp || *endp != '\0') + usage(); + break; + case 'p': + sessioninfo = 1; + break; + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (sessioninfo) { + if (argc != 1) + usage(); + print_session_info(argv[0], session_num); + } + + if (argc != 2) + usage(); + + dev = argv[0]; + dir = argv[1]; + + + /* + * Resolve the mountpoint with realpath(3) and remove unnecessary + * slashes from the devicename if there are any. + */ + (void)checkpath(dir, mntpath); + (void)rmslashes(dev, dev); + + /* + * Get session info from device + */ + getlastblock(dev, &usi, session_num); + + /* + * UDF file systems are not writeable. + */ + mntflags |= MNT_RDONLY; + + iov[i].iov_base = "fstype"; + iov[i++].iov_len = sizeof("fstype"); + iov[i].iov_base = "udf2"; + 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); + + iov[i].iov_base = "first_trackblank"; + iov[i++].iov_len = sizeof("first_trackblank"); + first_trackblank = 0; + iov[i].iov_base = &first_trackblank; + iov[i++].iov_len = sizeof(uint32_t); + + iov[i].iov_base = "session_start_addr"; + iov[i++].iov_len = sizeof("session_start_addr"); + iov[i].iov_base = &usi.session_start_addr; + iov[i++].iov_len = sizeof(uint32_t); + + iov[i].iov_base = "session_end_addr"; + iov[i++].iov_len = sizeof("session_end_addr"); + iov[i].iov_base = &usi.session_end_addr; + iov[i++].iov_len = sizeof(uint32_t); + + if (udf_flags & UDFMNT_KICONV) { + iov[i].iov_base = "cs_disk"; + iov[i++].iov_len = sizeof("cs_disk"); + 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"); + 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); +} + +static int +set_charset(char **cs_disk, char **cs_local, const char *localcs) +{ + int error; + + if (modfind("udf2_iconv") < 0) + if (kldload("udf2_iconv") < 0 || modfind("udf2_iconv") < 0) { + warnx( "cannot find or load \"udf2_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_cspairs(*cs_disk, *cs_local); + if (error) + return (-1); + + return (0); +} + +static void +getlastblock(char *dev, struct udf_session_info *usi, int session_num) +{ + int fd, error; + unsigned int out; + fd = open(dev, O_RDONLY, 0); + + if (fd < 0) + err(1, "open"); + + bzero(usi, sizeof(struct udf_session_info)); + usi->session_num = session_num; + error = ioctl(fd, UDFIOTEST, usi); + if (error != 0) { + if (session_num == 0) + warn("This device not not support sessions"); + else + err(2, "This device does not support sessions"); + } + + close(fd); +} + +static void +print_session_info(char *dev, int session_num) +{ + struct udf_session_info usi; + + rmslashes(dev, dev); + getlastblock(dev, &usi, session_num); + + + printf("session_num: %u\n", usi.session_num); + + printf("sector_size: %u\n", usi.sector_size); + printf("num_sessions: %u\n", usi.num_sessions); + printf("session_start_addr: %u\n", usi.session_start_addr); + printf("session_end_addr: %u\n", usi.session_end_addr); + + printf("num_tracks: %u\n", usi.num_tracks); + printf("first_track: %u\n", usi.first_track); + printf("session_first_track: %u\n", usi.session_first_track); + printf("session_last_track: %u\n", usi.session_last_track); + + exit(0); +} + +static void +usage(void) +{ + (void)fprintf(stderr, + "usage: mount_udf [-v] [-o options] [-C charset] [-s session] [-p] special node\n"); + exit(EX_USAGE); +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120605114500.5C2ED106564A>