]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Unix/ventoy_unix_src/DragonFly/mount_cd9660.c
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 $
42 #include <sys/param.h>
43 #include <sys/mount.h>
44 #include <sys/iconv.h>
45 #include <sys/linker.h>
46 #include <sys/module.h>
47 #include <vfs/isofs/cd9660/cd9660_mount.h>
60 static 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 mount_cd9660(char *dev
, char *dir
)
79 int ch
, mntflags
, opts
;
80 char mntpath
[MAXPATHLEN
];
84 char *cs_local
= NULL
;
86 mntflags
= opts
= verbose
= 0;
87 memset(&args
, 0, sizeof args
);
91 * Resolve the mountpoint with realpath(3) and remove unnecessary
92 * slashes from the devicename if there are any.
94 checkpath(dir
, mntpath
);
97 #define DEFAULT_ROOTUID -2
99 * ISO 9660 filesystems are not writeable.
101 mntflags
|= MNT_RDONLY
;
102 args
.export
.ex_flags
= MNT_EXRDONLY
;
104 args
.export
.ex_root
= DEFAULT_ROOTUID
;
107 if (args
.ssector
== -1) {
109 * The start of the session has not been specified on
110 * the command line. If we can successfully read the
111 * TOC of a CD-ROM, use the last data track we find.
112 * Otherwise, just use 0, in order to mount the very
113 * first session. This is compatible with the
114 * historic behaviour of mount_cd9660(8). If the user
115 * has specified -s <ssector> above, we don't get here
116 * and leave the user's will.
118 if ((args
.ssector
= get_ssector(dev
)) == -1) {
120 printf("could not determine starting sector, "
121 "using very first session\n");
124 printf("using starting sector %d\n", args
.ssector
);
127 error
= getvfsbyname("cd9660", &vfc
);
128 if (error
&& vfsisloadable("cd9660")) {
129 if (vfsload("cd9660"))
130 err(EX_OSERR
, "vfsload(cd9660)");
131 endvfsent(); /* flush cache */
132 error
= getvfsbyname("cd9660", &vfc
);
135 errx(1, "cd9660 filesystem is not available");
137 if (mount(vfc
.vfc_name
, mntpath
, mntflags
, &args
) < 0)
138 err(1, "%s", args
.fspec
);
144 set_charset(struct iso_args
*args
, const char *cs_local
, const char *cs_disk
)
147 if (modfind("cd9660_iconv") < 0) {
148 if (kldload("cd9660_iconv") < 0 || modfind("cd9660_iconv") < 0)
150 warnx("cannot find or load \"cd9660_iconv\" kernel module");
154 snprintf(args
->cs_local
, ICONV_CSNMAXLEN
, "%s", cs_local
);
155 error
= kiconv_add_xlat16_cspairs(ENCODING_UNICODE
, cs_local
);
159 cs_disk
= strdup(ENCODING_UNICODE
);
160 snprintf(args
->cs_disk
, ICONV_CSNMAXLEN
, "%s", cs_disk
);
161 error
= kiconv_add_xlat16_cspairs(cs_disk
, cs_local
);
172 "usage: mount_cd9660 [-begjrv] [-C charset] [-o options] [-s startsector] special node\n");
177 get_ssector(const char *dev
)
179 struct ioc_toc_header h
;
180 struct ioc_read_toc_entry t
;
181 struct cd_toc_entry toc_buffer
[100];
182 int fd
, ntocentries
, i
;
184 if ((fd
= open(dev
, O_RDONLY
)) == -1)
186 if (ioctl(fd
, CDIOREADTOCHEADER
, &h
) == -1) {
191 ntocentries
= h
.ending_track
- h
.starting_track
+ 1;
192 if (ntocentries
> 100) {
193 /* unreasonable, only 100 allowed */
197 t
.address_format
= CD_LBA_FORMAT
;
198 t
.starting_track
= 0;
199 t
.data_len
= ntocentries
* sizeof(struct cd_toc_entry
);
202 if (ioctl(fd
, CDIOREADTOCENTRYS
, (char *) &t
) == -1) {
208 for (i
= ntocentries
- 1; i
>= 0; i
--)
209 if ((toc_buffer
[i
].control
& 4) != 0)
210 /* found a data track */
215 return ntohl(toc_buffer
[i
].addr
.lba
);