2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley
6 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
7 * Support code is derived from software contributed to Berkeley
8 * by Atsushi Murai (amurai@spec.co.jp).
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)mount_cd9660.c 8.7 (Berkeley) 5/1/95
36 * @(#) Copyright (c) 1992, 1993, 1994 The Regents of the University of California. All rights reserved.
37 * @(#)mount_cd9660.c 8.7 (Berkeley) 5/1/95
38 * $FreeBSD: src/sbin/mount_cd9660/mount_cd9660.c,v 1.15.2.3 2001/03/14 12:05:01 bp Exp $
43 #include <sys/param.h>
44 #include <sys/mount.h>
45 #include <sys/iconv.h>
46 #include <sys/linker.h>
47 #include <sys/module.h>
48 #include <vfs/isofs/cd9660/cd9660_mount.h>
60 struct mntopt mopts
[] = {
63 { "extatt", 0, ISOFSMNT_EXTATT
, 1 },
64 { "gens", 0, ISOFSMNT_GENS
, 1 },
65 { "rrip", 1, ISOFSMNT_NORRIP
, 1 },
66 { "joliet", 1, ISOFSMNT_NOJOLIET
, 1 },
67 { "strictjoliet", 1, ISOFSMNT_BROKENJOLIET
, 1 },
71 static int get_ssector(const char *dev
);
72 static void usage(void);
73 int set_charset(struct iso_args
*args
, const char *cs_local
, const char *cs_disk
);
76 main(int argc
, char **argv
)
79 int ch
, mntflags
, opts
;
80 char *dev
, *dir
, mntpath
[MAXPATHLEN
];
84 char *cs_local
= NULL
;
86 mntflags
= opts
= verbose
= 0;
87 memset(&args
, 0, sizeof args
);
89 while ((ch
= getopt(argc
, argv
, "begjo:rs:C:v")) != -1)
92 opts
|= ISOFSMNT_BROKENJOLIET
;
95 opts
|= ISOFSMNT_EXTATT
;
98 opts
|= ISOFSMNT_GENS
;
101 opts
|= ISOFSMNT_NOJOLIET
;
104 quirk
= kiconv_quirkcs(optarg
, KICONV_VENDOR_MICSFT
);
105 cs_local
= strdup(quirk
);
106 if (set_charset(&args
, cs_local
, NULL
) == -1)
107 err(EX_OSERR
, "cd9660_iconv");
108 opts
|= ISOFSMNT_KICONV
;
111 getmntopts(optarg
, mopts
, &mntflags
, &opts
);
114 opts
|= ISOFSMNT_NORRIP
;
117 args
.ssector
= atoi(optarg
);
136 * Resolve the mountpoint with realpath(3) and remove unnecessary
137 * slashes from the devicename if there are any.
139 checkpath(dir
, mntpath
);
142 #define DEFAULT_ROOTUID -2
144 * ISO 9660 filesystems are not writeable.
146 mntflags
|= MNT_RDONLY
;
147 args
.export
.ex_flags
= MNT_EXRDONLY
;
149 args
.export
.ex_root
= DEFAULT_ROOTUID
;
152 if (args
.ssector
== -1) {
154 * The start of the session has not been specified on
155 * the command line. If we can successfully read the
156 * TOC of a CD-ROM, use the last data track we find.
157 * Otherwise, just use 0, in order to mount the very
158 * first session. This is compatible with the
159 * historic behaviour of mount_cd9660(8). If the user
160 * has specified -s <ssector> above, we don't get here
161 * and leave the user's will.
163 if ((args
.ssector
= get_ssector(dev
)) == -1) {
165 printf("could not determine starting sector, "
166 "using very first session\n");
169 printf("using starting sector %d\n", args
.ssector
);
172 error
= getvfsbyname("cd9660", &vfc
);
173 if (error
&& vfsisloadable("cd9660")) {
174 if (vfsload("cd9660"))
175 err(EX_OSERR
, "vfsload(cd9660)");
176 endvfsent(); /* flush cache */
177 error
= getvfsbyname("cd9660", &vfc
);
180 errx(1, "cd9660 filesystem is not available");
182 if (mount(vfc
.vfc_name
, mntpath
, mntflags
, &args
) < 0)
183 err(1, "%s", args
.fspec
);
188 set_charset(struct iso_args
*args
, const char *cs_local
, const char *cs_disk
)
191 if (modfind("cd9660_iconv") < 0) {
192 if (kldload("cd9660_iconv") < 0 || modfind("cd9660_iconv") < 0)
194 warnx("cannot find or load \"cd9660_iconv\" kernel module");
198 snprintf(args
->cs_local
, ICONV_CSNMAXLEN
, "%s", cs_local
);
199 error
= kiconv_add_xlat16_cspairs(ENCODING_UNICODE
, cs_local
);
203 cs_disk
= strdup(ENCODING_UNICODE
);
204 snprintf(args
->cs_disk
, ICONV_CSNMAXLEN
, "%s", cs_disk
);
205 error
= kiconv_add_xlat16_cspairs(cs_disk
, cs_local
);
216 "usage: mount_cd9660 [-begjrv] [-C charset] [-o options] [-s startsector] special node\n");
221 get_ssector(const char *dev
)
223 struct ioc_toc_header h
;
224 struct ioc_read_toc_entry t
;
225 struct cd_toc_entry toc_buffer
[100];
226 int fd
, ntocentries
, i
;
228 if ((fd
= open(dev
, O_RDONLY
)) == -1)
230 if (ioctl(fd
, CDIOREADTOCHEADER
, &h
) == -1) {
235 ntocentries
= h
.ending_track
- h
.starting_track
+ 1;
236 if (ntocentries
> 100) {
237 /* unreasonable, only 100 allowed */
241 t
.address_format
= CD_LBA_FORMAT
;
242 t
.starting_track
= 0;
243 t
.data_len
= ntocentries
* sizeof(struct cd_toc_entry
);
246 if (ioctl(fd
, CDIOREADTOCENTRYS
, (char *) &t
) == -1) {
252 for (i
= ntocentries
- 1; i
>= 0; i
--)
253 if ((toc_buffer
[i
].control
& 4) != 0)
254 /* found a data track */
259 return ntohl(toc_buffer
[i
].addr
.lba
);