]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Unix/ventoy_unix_src/DragonFly/mount_cd9660.c
Update ko_KR.txt (#2025)
[Ventoy.git] / Unix / ventoy_unix_src / DragonFly / mount_cd9660.c
1 /*
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
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).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
21 *
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
32 * SUCH DAMAGE.
33 *
34 * @(#)mount_cd9660.c 8.7 (Berkeley) 5/1/95
35 *
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 $
39 */
40
41 #include <sys/cdio.h>
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>
48
49 #include <err.h>
50 #include <errno.h>
51 #include <fcntl.h>
52 #include <mntopts.h>
53 #include <stdlib.h>
54 #include <stdio.h>
55 #include <string.h>
56 #include <locale.h>
57 #include <sysexits.h>
58 #include <unistd.h>
59
60 static struct mntopt mopts[] = {
61 MOPT_STDOPTS,
62 MOPT_UPDATE,
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 },
68 MOPT_NULL
69 };
70
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);
74
75 int
76 mount_cd9660(char *dev, char *dir)
77 {
78 struct iso_args args;
79 int ch, mntflags, opts;
80 char mntpath[MAXPATHLEN];
81 struct vfsconf vfc;
82 int error, verbose;
83 const char *quirk;
84 char *cs_local = NULL;
85
86 mntflags = opts = verbose = 0;
87 memset(&args, 0, sizeof args);
88 args.ssector = 0;
89
90 /*
91 * Resolve the mountpoint with realpath(3) and remove unnecessary
92 * slashes from the devicename if there are any.
93 */
94 checkpath(dir, mntpath);
95 rmslashes(dev, dev);
96
97 #define DEFAULT_ROOTUID -2
98 /*
99 * ISO 9660 filesystems are not writeable.
100 */
101 mntflags |= MNT_RDONLY;
102 args.export.ex_flags = MNT_EXRDONLY;
103 args.fspec = dev;
104 args.export.ex_root = DEFAULT_ROOTUID;
105 args.flags = opts;
106
107 if (args.ssector == -1) {
108 /*
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.
117 */
118 if ((args.ssector = get_ssector(dev)) == -1) {
119 if (verbose)
120 printf("could not determine starting sector, "
121 "using very first session\n");
122 args.ssector = 0;
123 } else if (verbose)
124 printf("using starting sector %d\n", args.ssector);
125 }
126
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);
133 }
134 if (error)
135 errx(1, "cd9660 filesystem is not available");
136
137 if (mount(vfc.vfc_name, mntpath, mntflags, &args) < 0)
138 err(1, "%s", args.fspec);
139
140 return 0;
141 }
142
143 int
144 set_charset(struct iso_args *args, const char *cs_local, const char *cs_disk)
145 {
146 int error;
147 if (modfind("cd9660_iconv") < 0) {
148 if (kldload("cd9660_iconv") < 0 || modfind("cd9660_iconv") < 0)
149 {
150 warnx("cannot find or load \"cd9660_iconv\" kernel module");
151 return (-1);
152 }
153 }
154 snprintf(args->cs_local, ICONV_CSNMAXLEN, "%s", cs_local);
155 error = kiconv_add_xlat16_cspairs(ENCODING_UNICODE, cs_local);
156 if (error)
157 return (-1);
158 if (!cs_disk)
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);
162 if (error)
163 return (-1);
164 return (0);
165 }
166
167
168 static void
169 usage(void)
170 {
171 fprintf(stderr,
172 "usage: mount_cd9660 [-begjrv] [-C charset] [-o options] [-s startsector] special node\n");
173 exit(EX_USAGE);
174 }
175
176 static int
177 get_ssector(const char *dev)
178 {
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;
183
184 if ((fd = open(dev, O_RDONLY)) == -1)
185 return -1;
186 if (ioctl(fd, CDIOREADTOCHEADER, &h) == -1) {
187 close(fd);
188 return -1;
189 }
190
191 ntocentries = h.ending_track - h.starting_track + 1;
192 if (ntocentries > 100) {
193 /* unreasonable, only 100 allowed */
194 close(fd);
195 return -1;
196 }
197 t.address_format = CD_LBA_FORMAT;
198 t.starting_track = 0;
199 t.data_len = ntocentries * sizeof(struct cd_toc_entry);
200 t.data = toc_buffer;
201
202 if (ioctl(fd, CDIOREADTOCENTRYS, (char *) &t) == -1) {
203 close(fd);
204 return -1;
205 }
206 close(fd);
207
208 for (i = ntocentries - 1; i >= 0; i--)
209 if ((toc_buffer[i].control & 4) != 0)
210 /* found a data track */
211 break;
212 if (i < 0)
213 return -1;
214
215 return ntohl(toc_buffer[i].addr.lba);
216 }