| @@ -1,1101 +1,1101 @@ | | | @@ -1,1101 +1,1101 @@ |
1 | /* $NetBSD: msdosfs_vfsops.c,v 1.96 2012/07/07 16:18:50 tsutsui Exp $ */ | | 1 | /* $NetBSD: msdosfs_vfsops.c,v 1.97 2012/10/03 23:32:43 jakllsch Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. | | 4 | * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. |
5 | * Copyright (C) 1994, 1995, 1997 TooLs GmbH. | | 5 | * Copyright (C) 1994, 1995, 1997 TooLs GmbH. |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). | | 7 | * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
15 | * notice, this list of conditions and the following disclaimer in the | | 15 | * notice, this list of conditions and the following disclaimer in the |
16 | * documentation and/or other materials provided with the distribution. | | 16 | * documentation and/or other materials provided with the distribution. |
17 | * 3. All advertising materials mentioning features or use of this software | | 17 | * 3. All advertising materials mentioning features or use of this software |
18 | * must display the following acknowledgement: | | 18 | * must display the following acknowledgement: |
19 | * This product includes software developed by TooLs GmbH. | | 19 | * This product includes software developed by TooLs GmbH. |
20 | * 4. The name of TooLs GmbH may not be used to endorse or promote products | | 20 | * 4. The name of TooLs GmbH may not be used to endorse or promote products |
21 | * derived from this software without specific prior written permission. | | 21 | * derived from this software without specific prior written permission. |
22 | * | | 22 | * |
23 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR | | 23 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR |
24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
26 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | | 26 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | | 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
28 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | | 28 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
29 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | | 29 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
30 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | | 30 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
31 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | | 31 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
32 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 32 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | | 33 | */ |
34 | /* | | 34 | /* |
35 | * Written by Paul Popelka (paulp@uts.amdahl.com) | | 35 | * Written by Paul Popelka (paulp@uts.amdahl.com) |
36 | * | | 36 | * |
37 | * You can do anything you want with this software, just don't say you wrote | | 37 | * You can do anything you want with this software, just don't say you wrote |
38 | * it, and don't remove this notice. | | 38 | * it, and don't remove this notice. |
39 | * | | 39 | * |
40 | * This software is provided "as is". | | 40 | * This software is provided "as is". |
41 | * | | 41 | * |
42 | * The author supplies this software to be publicly redistributed on the | | 42 | * The author supplies this software to be publicly redistributed on the |
43 | * understanding that the author is not responsible for the correct | | 43 | * understanding that the author is not responsible for the correct |
44 | * functioning of this software in any circumstances and is not liable for | | 44 | * functioning of this software in any circumstances and is not liable for |
45 | * any damages caused by this software. | | 45 | * any damages caused by this software. |
46 | * | | 46 | * |
47 | * October 1992 | | 47 | * October 1992 |
48 | */ | | 48 | */ |
49 | | | 49 | |
50 | #include <sys/cdefs.h> | | 50 | #include <sys/cdefs.h> |
51 | __KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.96 2012/07/07 16:18:50 tsutsui Exp $"); | | 51 | __KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.97 2012/10/03 23:32:43 jakllsch Exp $"); |
52 | | | 52 | |
53 | #if defined(_KERNEL_OPT) | | 53 | #if defined(_KERNEL_OPT) |
54 | #include "opt_compat_netbsd.h" | | 54 | #include "opt_compat_netbsd.h" |
55 | #endif | | 55 | #endif |
56 | | | 56 | |
57 | #include <sys/param.h> | | 57 | #include <sys/param.h> |
58 | #include <sys/systm.h> | | 58 | #include <sys/systm.h> |
59 | #include <sys/sysctl.h> | | 59 | #include <sys/sysctl.h> |
60 | #include <sys/namei.h> | | 60 | #include <sys/namei.h> |
61 | #include <sys/proc.h> | | 61 | #include <sys/proc.h> |
62 | #include <sys/kernel.h> | | 62 | #include <sys/kernel.h> |
63 | #include <sys/vnode.h> | | 63 | #include <sys/vnode.h> |
64 | #include <miscfs/genfs/genfs.h> | | 64 | #include <miscfs/genfs/genfs.h> |
65 | #include <miscfs/specfs/specdev.h> /* XXX */ /* defines v_rdev */ | | 65 | #include <miscfs/specfs/specdev.h> /* XXX */ /* defines v_rdev */ |
66 | #include <sys/mount.h> | | 66 | #include <sys/mount.h> |
67 | #include <sys/buf.h> | | 67 | #include <sys/buf.h> |
68 | #include <sys/file.h> | | 68 | #include <sys/file.h> |
69 | #include <sys/device.h> | | 69 | #include <sys/device.h> |
70 | #include <sys/disklabel.h> | | 70 | #include <sys/disklabel.h> |
71 | #include <sys/disk.h> | | 71 | #include <sys/disk.h> |
72 | #include <sys/fstrans.h> | | 72 | #include <sys/fstrans.h> |
73 | #include <sys/ioctl.h> | | 73 | #include <sys/ioctl.h> |
74 | #include <sys/malloc.h> | | 74 | #include <sys/malloc.h> |
75 | #include <sys/dirent.h> | | 75 | #include <sys/dirent.h> |
76 | #include <sys/stat.h> | | 76 | #include <sys/stat.h> |
77 | #include <sys/conf.h> | | 77 | #include <sys/conf.h> |
78 | #include <sys/kauth.h> | | 78 | #include <sys/kauth.h> |
79 | #include <sys/module.h> | | 79 | #include <sys/module.h> |
80 | | | 80 | |
81 | #include <fs/msdosfs/bpb.h> | | 81 | #include <fs/msdosfs/bpb.h> |
82 | #include <fs/msdosfs/bootsect.h> | | 82 | #include <fs/msdosfs/bootsect.h> |
83 | #include <fs/msdosfs/direntry.h> | | 83 | #include <fs/msdosfs/direntry.h> |
84 | #include <fs/msdosfs/denode.h> | | 84 | #include <fs/msdosfs/denode.h> |
85 | #include <fs/msdosfs/msdosfsmount.h> | | 85 | #include <fs/msdosfs/msdosfsmount.h> |
86 | #include <fs/msdosfs/fat.h> | | 86 | #include <fs/msdosfs/fat.h> |
87 | | | 87 | |
88 | MODULE(MODULE_CLASS_VFS, msdos, NULL); | | 88 | MODULE(MODULE_CLASS_VFS, msdos, NULL); |
89 | | | 89 | |
90 | #ifdef MSDOSFS_DEBUG | | 90 | #ifdef MSDOSFS_DEBUG |
91 | #define DPRINTF(a) uprintf a | | 91 | #define DPRINTF(a) uprintf a |
92 | #else | | 92 | #else |
93 | #define DPRINTF(a) | | 93 | #define DPRINTF(a) |
94 | #endif | | 94 | #endif |
95 | | | 95 | |
96 | #define MSDOSFS_NAMEMAX(pmp) \ | | 96 | #define MSDOSFS_NAMEMAX(pmp) \ |
97 | (pmp)->pm_flags & MSDOSFSMNT_LONGNAME ? WIN_MAXLEN : 12 | | 97 | (pmp)->pm_flags & MSDOSFSMNT_LONGNAME ? WIN_MAXLEN : 12 |
98 | | | 98 | |
99 | VFS_PROTOS(msdosfs); | | 99 | VFS_PROTOS(msdosfs); |
100 | | | 100 | |
101 | int msdosfs_mountfs(struct vnode *, struct mount *, struct lwp *, | | 101 | int msdosfs_mountfs(struct vnode *, struct mount *, struct lwp *, |
102 | struct msdosfs_args *); | | 102 | struct msdosfs_args *); |
103 | | | 103 | |
104 | static int update_mp(struct mount *, struct msdosfs_args *); | | 104 | static int update_mp(struct mount *, struct msdosfs_args *); |
105 | | | 105 | |
106 | MALLOC_JUSTDEFINE(M_MSDOSFSMNT, "MSDOSFS mount", "MSDOS FS mount structure"); | | 106 | MALLOC_JUSTDEFINE(M_MSDOSFSMNT, "MSDOSFS mount", "MSDOS FS mount structure"); |
107 | MALLOC_JUSTDEFINE(M_MSDOSFSFAT, "MSDOSFS fat", "MSDOS FS fat table"); | | 107 | MALLOC_JUSTDEFINE(M_MSDOSFSFAT, "MSDOSFS fat", "MSDOS FS fat table"); |
108 | MALLOC_JUSTDEFINE(M_MSDOSFSTMP, "MSDOSFS temp", "MSDOS FS temp. structures"); | | 108 | MALLOC_JUSTDEFINE(M_MSDOSFSTMP, "MSDOSFS temp", "MSDOS FS temp. structures"); |
109 | | | 109 | |
110 | #define ROOTNAME "root_device" | | 110 | #define ROOTNAME "root_device" |
111 | | | 111 | |
112 | static struct sysctllog *msdosfs_sysctl_log; | | 112 | static struct sysctllog *msdosfs_sysctl_log; |
113 | | | 113 | |
114 | extern const struct vnodeopv_desc msdosfs_vnodeop_opv_desc; | | 114 | extern const struct vnodeopv_desc msdosfs_vnodeop_opv_desc; |
115 | | | 115 | |
116 | const struct vnodeopv_desc * const msdosfs_vnodeopv_descs[] = { | | 116 | const struct vnodeopv_desc * const msdosfs_vnodeopv_descs[] = { |
117 | &msdosfs_vnodeop_opv_desc, | | 117 | &msdosfs_vnodeop_opv_desc, |
118 | NULL, | | 118 | NULL, |
119 | }; | | 119 | }; |
120 | | | 120 | |
121 | struct vfsops msdosfs_vfsops = { | | 121 | struct vfsops msdosfs_vfsops = { |
122 | MOUNT_MSDOS, | | 122 | MOUNT_MSDOS, |
123 | sizeof (struct msdosfs_args), | | 123 | sizeof (struct msdosfs_args), |
124 | msdosfs_mount, | | 124 | msdosfs_mount, |
125 | msdosfs_start, | | 125 | msdosfs_start, |
126 | msdosfs_unmount, | | 126 | msdosfs_unmount, |
127 | msdosfs_root, | | 127 | msdosfs_root, |
128 | (void *)eopnotsupp, /* vfs_quotactl */ | | 128 | (void *)eopnotsupp, /* vfs_quotactl */ |
129 | msdosfs_statvfs, | | 129 | msdosfs_statvfs, |
130 | msdosfs_sync, | | 130 | msdosfs_sync, |
131 | msdosfs_vget, | | 131 | msdosfs_vget, |
132 | msdosfs_fhtovp, | | 132 | msdosfs_fhtovp, |
133 | msdosfs_vptofh, | | 133 | msdosfs_vptofh, |
134 | msdosfs_init, | | 134 | msdosfs_init, |
135 | msdosfs_reinit, | | 135 | msdosfs_reinit, |
136 | msdosfs_done, | | 136 | msdosfs_done, |
137 | msdosfs_mountroot, | | 137 | msdosfs_mountroot, |
138 | (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp, | | 138 | (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp, |
139 | vfs_stdextattrctl, | | 139 | vfs_stdextattrctl, |
140 | msdosfs_suspendctl, | | 140 | msdosfs_suspendctl, |
141 | genfs_renamelock_enter, | | 141 | genfs_renamelock_enter, |
142 | genfs_renamelock_exit, | | 142 | genfs_renamelock_exit, |
143 | (void *)eopnotsupp, | | 143 | (void *)eopnotsupp, |
144 | msdosfs_vnodeopv_descs, | | 144 | msdosfs_vnodeopv_descs, |
145 | 0, | | 145 | 0, |
146 | { NULL, NULL }, | | 146 | { NULL, NULL }, |
147 | }; | | 147 | }; |
148 | | | 148 | |
149 | static int | | 149 | static int |
150 | msdos_modcmd(modcmd_t cmd, void *arg) | | 150 | msdos_modcmd(modcmd_t cmd, void *arg) |
151 | { | | 151 | { |
152 | int error; | | 152 | int error; |
153 | | | 153 | |
154 | switch (cmd) { | | 154 | switch (cmd) { |
155 | case MODULE_CMD_INIT: | | 155 | case MODULE_CMD_INIT: |
156 | error = vfs_attach(&msdosfs_vfsops); | | 156 | error = vfs_attach(&msdosfs_vfsops); |
157 | if (error != 0) | | 157 | if (error != 0) |
158 | break; | | 158 | break; |
159 | sysctl_createv(&msdosfs_sysctl_log, 0, NULL, NULL, | | 159 | sysctl_createv(&msdosfs_sysctl_log, 0, NULL, NULL, |
160 | CTLFLAG_PERMANENT, | | 160 | CTLFLAG_PERMANENT, |
161 | CTLTYPE_NODE, "vfs", NULL, | | 161 | CTLTYPE_NODE, "vfs", NULL, |
162 | NULL, 0, NULL, 0, | | 162 | NULL, 0, NULL, 0, |
163 | CTL_VFS, CTL_EOL); | | 163 | CTL_VFS, CTL_EOL); |
164 | sysctl_createv(&msdosfs_sysctl_log, 0, NULL, NULL, | | 164 | sysctl_createv(&msdosfs_sysctl_log, 0, NULL, NULL, |
165 | CTLFLAG_PERMANENT, | | 165 | CTLFLAG_PERMANENT, |
166 | CTLTYPE_NODE, "msdosfs", | | 166 | CTLTYPE_NODE, "msdosfs", |
167 | SYSCTL_DESCR("MS-DOS file system"), | | 167 | SYSCTL_DESCR("MS-DOS file system"), |
168 | NULL, 0, NULL, 0, | | 168 | NULL, 0, NULL, 0, |
169 | CTL_VFS, 4, CTL_EOL); | | 169 | CTL_VFS, 4, CTL_EOL); |
170 | /* | | 170 | /* |
171 | * XXX the "4" above could be dynamic, thereby eliminating one | | 171 | * XXX the "4" above could be dynamic, thereby eliminating one |
172 | * more instance of the "number to vfs" mapping problem, but | | 172 | * more instance of the "number to vfs" mapping problem, but |
173 | * "4" is the order as taken from sys/mount.h | | 173 | * "4" is the order as taken from sys/mount.h |
174 | */ | | 174 | */ |
175 | break; | | 175 | break; |
176 | case MODULE_CMD_FINI: | | 176 | case MODULE_CMD_FINI: |
177 | error = vfs_detach(&msdosfs_vfsops); | | 177 | error = vfs_detach(&msdosfs_vfsops); |
178 | if (error != 0) | | 178 | if (error != 0) |
179 | break; | | 179 | break; |
180 | sysctl_teardown(&msdosfs_sysctl_log); | | 180 | sysctl_teardown(&msdosfs_sysctl_log); |
181 | break; | | 181 | break; |
182 | default: | | 182 | default: |
183 | error = ENOTTY; | | 183 | error = ENOTTY; |
184 | break; | | 184 | break; |
185 | } | | 185 | } |
186 | | | 186 | |
187 | return (error); | | 187 | return (error); |
188 | } | | 188 | } |
189 | | | 189 | |
190 | static int | | 190 | static int |
191 | update_mp(struct mount *mp, struct msdosfs_args *argp) | | 191 | update_mp(struct mount *mp, struct msdosfs_args *argp) |
192 | { | | 192 | { |
193 | struct msdosfsmount *pmp = VFSTOMSDOSFS(mp); | | 193 | struct msdosfsmount *pmp = VFSTOMSDOSFS(mp); |
194 | int error; | | 194 | int error; |
195 | | | 195 | |
196 | pmp->pm_gid = argp->gid; | | 196 | pmp->pm_gid = argp->gid; |
197 | pmp->pm_uid = argp->uid; | | 197 | pmp->pm_uid = argp->uid; |
198 | pmp->pm_mask = argp->mask & ALLPERMS; | | 198 | pmp->pm_mask = argp->mask & ALLPERMS; |
199 | pmp->pm_dirmask = argp->dirmask & ALLPERMS; | | 199 | pmp->pm_dirmask = argp->dirmask & ALLPERMS; |
200 | pmp->pm_gmtoff = argp->gmtoff; | | 200 | pmp->pm_gmtoff = argp->gmtoff; |
201 | pmp->pm_flags |= argp->flags & MSDOSFSMNT_MNTOPT; | | 201 | pmp->pm_flags |= argp->flags & MSDOSFSMNT_MNTOPT; |
202 | | | 202 | |
203 | /* | | 203 | /* |
204 | * GEMDOS knows nothing about win95 long filenames | | 204 | * GEMDOS knows nothing about win95 long filenames |
205 | */ | | 205 | */ |
206 | if (pmp->pm_flags & MSDOSFSMNT_GEMDOSFS) | | 206 | if (pmp->pm_flags & MSDOSFSMNT_GEMDOSFS) |
207 | pmp->pm_flags |= MSDOSFSMNT_NOWIN95; | | 207 | pmp->pm_flags |= MSDOSFSMNT_NOWIN95; |
208 | | | 208 | |
209 | if (pmp->pm_flags & MSDOSFSMNT_NOWIN95) | | 209 | if (pmp->pm_flags & MSDOSFSMNT_NOWIN95) |
210 | pmp->pm_flags |= MSDOSFSMNT_SHORTNAME; | | 210 | pmp->pm_flags |= MSDOSFSMNT_SHORTNAME; |
211 | else if (!(pmp->pm_flags & | | 211 | else if (!(pmp->pm_flags & |
212 | (MSDOSFSMNT_SHORTNAME | MSDOSFSMNT_LONGNAME))) { | | 212 | (MSDOSFSMNT_SHORTNAME | MSDOSFSMNT_LONGNAME))) { |
213 | struct vnode *rtvp; | | 213 | struct vnode *rtvp; |
214 | | | 214 | |
215 | /* | | 215 | /* |
216 | * Try to divine whether to support Win'95 long filenames | | 216 | * Try to divine whether to support Win'95 long filenames |
217 | */ | | 217 | */ |
218 | if (FAT32(pmp)) | | 218 | if (FAT32(pmp)) |
219 | pmp->pm_flags |= MSDOSFSMNT_LONGNAME; | | 219 | pmp->pm_flags |= MSDOSFSMNT_LONGNAME; |
220 | else { | | 220 | else { |
221 | if ((error = msdosfs_root(mp, &rtvp)) != 0) | | 221 | if ((error = msdosfs_root(mp, &rtvp)) != 0) |
222 | return error; | | 222 | return error; |
223 | pmp->pm_flags |= findwin95(VTODE(rtvp)) | | 223 | pmp->pm_flags |= findwin95(VTODE(rtvp)) |
224 | ? MSDOSFSMNT_LONGNAME | | 224 | ? MSDOSFSMNT_LONGNAME |
225 | : MSDOSFSMNT_SHORTNAME; | | 225 | : MSDOSFSMNT_SHORTNAME; |
226 | vput(rtvp); | | 226 | vput(rtvp); |
227 | } | | 227 | } |
228 | } | | 228 | } |
229 | | | 229 | |
230 | mp->mnt_stat.f_namemax = MSDOSFS_NAMEMAX(pmp); | | 230 | mp->mnt_stat.f_namemax = MSDOSFS_NAMEMAX(pmp); |
231 | | | 231 | |
232 | return 0; | | 232 | return 0; |
233 | } | | 233 | } |
234 | | | 234 | |
235 | int | | 235 | int |
236 | msdosfs_mountroot(void) | | 236 | msdosfs_mountroot(void) |
237 | { | | 237 | { |
238 | struct mount *mp; | | 238 | struct mount *mp; |
239 | struct lwp *l = curlwp; /* XXX */ | | 239 | struct lwp *l = curlwp; /* XXX */ |
240 | int error; | | 240 | int error; |
241 | struct msdosfs_args args; | | 241 | struct msdosfs_args args; |
242 | | | 242 | |
243 | if (device_class(root_device) != DV_DISK) | | 243 | if (device_class(root_device) != DV_DISK) |
244 | return (ENODEV); | | 244 | return (ENODEV); |
245 | | | 245 | |
246 | if ((error = vfs_rootmountalloc(MOUNT_MSDOS, "root_device", &mp))) { | | 246 | if ((error = vfs_rootmountalloc(MOUNT_MSDOS, "root_device", &mp))) { |
247 | vrele(rootvp); | | 247 | vrele(rootvp); |
248 | return (error); | | 248 | return (error); |
249 | } | | 249 | } |
250 | | | 250 | |
251 | args.flags = MSDOSFSMNT_VERSIONED; | | 251 | args.flags = MSDOSFSMNT_VERSIONED; |
252 | args.uid = 0; | | 252 | args.uid = 0; |
253 | args.gid = 0; | | 253 | args.gid = 0; |
254 | args.mask = 0777; | | 254 | args.mask = 0777; |
255 | args.version = MSDOSFSMNT_VERSION; | | 255 | args.version = MSDOSFSMNT_VERSION; |
256 | args.dirmask = 0777; | | 256 | args.dirmask = 0777; |
257 | | | 257 | |
258 | if ((error = msdosfs_mountfs(rootvp, mp, l, &args)) != 0) { | | 258 | if ((error = msdosfs_mountfs(rootvp, mp, l, &args)) != 0) { |
259 | vfs_unbusy(mp, false, NULL); | | 259 | vfs_unbusy(mp, false, NULL); |
260 | vfs_destroy(mp); | | 260 | vfs_destroy(mp); |
261 | return (error); | | 261 | return (error); |
262 | } | | 262 | } |
263 | | | 263 | |
264 | if ((error = update_mp(mp, &args)) != 0) { | | 264 | if ((error = update_mp(mp, &args)) != 0) { |
265 | (void)msdosfs_unmount(mp, 0); | | 265 | (void)msdosfs_unmount(mp, 0); |
266 | vfs_unbusy(mp, false, NULL); | | 266 | vfs_unbusy(mp, false, NULL); |
267 | vfs_destroy(mp); | | 267 | vfs_destroy(mp); |
268 | vrele(rootvp); | | 268 | vrele(rootvp); |
269 | return (error); | | 269 | return (error); |
270 | } | | 270 | } |
271 | | | 271 | |
272 | mutex_enter(&mountlist_lock); | | 272 | mutex_enter(&mountlist_lock); |
273 | CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); | | 273 | CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); |
274 | mutex_exit(&mountlist_lock); | | 274 | mutex_exit(&mountlist_lock); |
275 | (void)msdosfs_statvfs(mp, &mp->mnt_stat); | | 275 | (void)msdosfs_statvfs(mp, &mp->mnt_stat); |
276 | vfs_unbusy(mp, false, NULL); | | 276 | vfs_unbusy(mp, false, NULL); |
277 | return (0); | | 277 | return (0); |
278 | } | | 278 | } |
279 | | | 279 | |
280 | /* | | 280 | /* |
281 | * mp - path - addr in user space of mount point (ie /usr or whatever) | | 281 | * mp - path - addr in user space of mount point (ie /usr or whatever) |
282 | * data - addr in user space of mount params including the name of the block | | 282 | * data - addr in user space of mount params including the name of the block |
283 | * special file to treat as a filesystem. | | 283 | * special file to treat as a filesystem. |
284 | */ | | 284 | */ |
285 | int | | 285 | int |
286 | msdosfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) | | 286 | msdosfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) |
287 | { | | 287 | { |
288 | struct lwp *l = curlwp; | | 288 | struct lwp *l = curlwp; |
289 | struct vnode *devvp; /* vnode for blk device to mount */ | | 289 | struct vnode *devvp; /* vnode for blk device to mount */ |
290 | struct msdosfs_args *args = data; /* holds data from mount request */ | | 290 | struct msdosfs_args *args = data; /* holds data from mount request */ |
291 | /* msdosfs specific mount control block */ | | 291 | /* msdosfs specific mount control block */ |
292 | struct msdosfsmount *pmp = NULL; | | 292 | struct msdosfsmount *pmp = NULL; |
293 | int error, flags; | | 293 | int error, flags; |
294 | mode_t accessmode; | | 294 | mode_t accessmode; |
295 | | | 295 | |
296 | if (*data_len < sizeof *args) | | 296 | if (*data_len < sizeof *args) |
297 | return EINVAL; | | 297 | return EINVAL; |
298 | | | 298 | |
299 | if (mp->mnt_flag & MNT_GETARGS) { | | 299 | if (mp->mnt_flag & MNT_GETARGS) { |
300 | pmp = VFSTOMSDOSFS(mp); | | 300 | pmp = VFSTOMSDOSFS(mp); |
301 | if (pmp == NULL) | | 301 | if (pmp == NULL) |
302 | return EIO; | | 302 | return EIO; |
303 | args->fspec = NULL; | | 303 | args->fspec = NULL; |
304 | args->uid = pmp->pm_uid; | | 304 | args->uid = pmp->pm_uid; |
305 | args->gid = pmp->pm_gid; | | 305 | args->gid = pmp->pm_gid; |
306 | args->mask = pmp->pm_mask; | | 306 | args->mask = pmp->pm_mask; |
307 | args->flags = pmp->pm_flags; | | 307 | args->flags = pmp->pm_flags; |
308 | args->version = MSDOSFSMNT_VERSION; | | 308 | args->version = MSDOSFSMNT_VERSION; |
309 | args->dirmask = pmp->pm_dirmask; | | 309 | args->dirmask = pmp->pm_dirmask; |
310 | args->gmtoff = pmp->pm_gmtoff; | | 310 | args->gmtoff = pmp->pm_gmtoff; |
311 | *data_len = sizeof *args; | | 311 | *data_len = sizeof *args; |
312 | return 0; | | 312 | return 0; |
313 | } | | 313 | } |
314 | | | 314 | |
315 | /* | | 315 | /* |
316 | * If not versioned (i.e. using old mount_msdos(8)), fill in | | 316 | * If not versioned (i.e. using old mount_msdos(8)), fill in |
317 | * the additional structure items with suitable defaults. | | 317 | * the additional structure items with suitable defaults. |
318 | */ | | 318 | */ |
319 | if ((args->flags & MSDOSFSMNT_VERSIONED) == 0) { | | 319 | if ((args->flags & MSDOSFSMNT_VERSIONED) == 0) { |
320 | args->version = 1; | | 320 | args->version = 1; |
321 | args->dirmask = args->mask; | | 321 | args->dirmask = args->mask; |
322 | } | | 322 | } |
323 | | | 323 | |
324 | /* | | 324 | /* |
325 | * Reset GMT offset for pre-v3 mount structure args. | | 325 | * Reset GMT offset for pre-v3 mount structure args. |
326 | */ | | 326 | */ |
327 | if (args->version < 3) | | 327 | if (args->version < 3) |
328 | args->gmtoff = 0; | | 328 | args->gmtoff = 0; |
329 | | | 329 | |
330 | /* | | 330 | /* |
331 | * If updating, check whether changing from read-only to | | 331 | * If updating, check whether changing from read-only to |
332 | * read/write; if there is no device name, that's all we do. | | 332 | * read/write; if there is no device name, that's all we do. |
333 | */ | | 333 | */ |
334 | if (mp->mnt_flag & MNT_UPDATE) { | | 334 | if (mp->mnt_flag & MNT_UPDATE) { |
335 | pmp = VFSTOMSDOSFS(mp); | | 335 | pmp = VFSTOMSDOSFS(mp); |
336 | error = 0; | | 336 | error = 0; |
337 | if (!(pmp->pm_flags & MSDOSFSMNT_RONLY) && | | 337 | if (!(pmp->pm_flags & MSDOSFSMNT_RONLY) && |
338 | (mp->mnt_flag & MNT_RDONLY)) { | | 338 | (mp->mnt_flag & MNT_RDONLY)) { |
339 | flags = WRITECLOSE; | | 339 | flags = WRITECLOSE; |
340 | if (mp->mnt_flag & MNT_FORCE) | | 340 | if (mp->mnt_flag & MNT_FORCE) |
341 | flags |= FORCECLOSE; | | 341 | flags |= FORCECLOSE; |
342 | error = vflush(mp, NULLVP, flags); | | 342 | error = vflush(mp, NULLVP, flags); |
343 | } | | 343 | } |
344 | if (!error && (mp->mnt_flag & MNT_RELOAD)) | | 344 | if (!error && (mp->mnt_flag & MNT_RELOAD)) |
345 | /* not yet implemented */ | | 345 | /* not yet implemented */ |
346 | error = EOPNOTSUPP; | | 346 | error = EOPNOTSUPP; |
347 | if (error) { | | 347 | if (error) { |
348 | DPRINTF(("vflush %d\n", error)); | | 348 | DPRINTF(("vflush %d\n", error)); |
349 | return (error); | | 349 | return (error); |
350 | } | | 350 | } |
351 | if ((pmp->pm_flags & MSDOSFSMNT_RONLY) && | | 351 | if ((pmp->pm_flags & MSDOSFSMNT_RONLY) && |
352 | (mp->mnt_iflag & IMNT_WANTRDWR)) { | | 352 | (mp->mnt_iflag & IMNT_WANTRDWR)) { |
353 | /* | | 353 | /* |
354 | * If upgrade to read-write by non-root, then verify | | 354 | * If upgrade to read-write by non-root, then verify |
355 | * that user has necessary permissions on the device. | | 355 | * that user has necessary permissions on the device. |
356 | * | | 356 | * |
357 | * Permission to update a mount is checked higher, so | | 357 | * Permission to update a mount is checked higher, so |
358 | * here we presume updating the mount is okay (for | | 358 | * here we presume updating the mount is okay (for |
359 | * example, as far as securelevel goes) which leaves us | | 359 | * example, as far as securelevel goes) which leaves us |
360 | * with the normal check. | | 360 | * with the normal check. |
361 | */ | | 361 | */ |
362 | devvp = pmp->pm_devvp; | | 362 | devvp = pmp->pm_devvp; |
363 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); | | 363 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); |
364 | error = kauth_authorize_system(l->l_cred, | | 364 | error = kauth_authorize_system(l->l_cred, |
365 | KAUTH_SYSTEM_MOUNT, KAUTH_REQ_SYSTEM_MOUNT_DEVICE, | | 365 | KAUTH_SYSTEM_MOUNT, KAUTH_REQ_SYSTEM_MOUNT_DEVICE, |
366 | mp, devvp, KAUTH_ARG(VREAD | VWRITE)); | | 366 | mp, devvp, KAUTH_ARG(VREAD | VWRITE)); |
367 | VOP_UNLOCK(devvp); | | 367 | VOP_UNLOCK(devvp); |
368 | DPRINTF(("KAUTH_REQ_SYSTEM_MOUNT_DEVICE %d\n", error)); | | 368 | DPRINTF(("KAUTH_REQ_SYSTEM_MOUNT_DEVICE %d\n", error)); |
369 | if (error) | | 369 | if (error) |
370 | return (error); | | 370 | return (error); |
371 | | | 371 | |
372 | pmp->pm_flags &= ~MSDOSFSMNT_RONLY; | | 372 | pmp->pm_flags &= ~MSDOSFSMNT_RONLY; |
373 | } | | 373 | } |
374 | if (args->fspec == NULL) { | | 374 | if (args->fspec == NULL) { |
375 | DPRINTF(("missing fspec\n")); | | 375 | DPRINTF(("missing fspec\n")); |
376 | return EINVAL; | | 376 | return EINVAL; |
377 | } | | 377 | } |
378 | } | | 378 | } |
379 | /* | | 379 | /* |
380 | * Not an update, or updating the name: look up the name | | 380 | * Not an update, or updating the name: look up the name |
381 | * and verify that it refers to a sensible block device. | | 381 | * and verify that it refers to a sensible block device. |
382 | */ | | 382 | */ |
383 | error = namei_simple_user(args->fspec, | | 383 | error = namei_simple_user(args->fspec, |
384 | NSM_FOLLOW_NOEMULROOT, &devvp); | | 384 | NSM_FOLLOW_NOEMULROOT, &devvp); |
385 | if (error != 0) { | | 385 | if (error != 0) { |
386 | DPRINTF(("namei %d\n", error)); | | 386 | DPRINTF(("namei %d\n", error)); |
387 | return (error); | | 387 | return (error); |
388 | } | | 388 | } |
389 | | | 389 | |
390 | if (devvp->v_type != VBLK) { | | 390 | if (devvp->v_type != VBLK) { |
391 | DPRINTF(("not block\n")); | | 391 | DPRINTF(("not block\n")); |
392 | vrele(devvp); | | 392 | vrele(devvp); |
393 | return (ENOTBLK); | | 393 | return (ENOTBLK); |
394 | } | | 394 | } |
395 | if (bdevsw_lookup(devvp->v_rdev) == NULL) { | | 395 | if (bdevsw_lookup(devvp->v_rdev) == NULL) { |
396 | DPRINTF(("no block switch\n")); | | 396 | DPRINTF(("no block switch\n")); |
397 | vrele(devvp); | | 397 | vrele(devvp); |
398 | return (ENXIO); | | 398 | return (ENXIO); |
399 | } | | 399 | } |
400 | /* | | 400 | /* |
401 | * If mount by non-root, then verify that user has necessary | | 401 | * If mount by non-root, then verify that user has necessary |
402 | * permissions on the device. | | 402 | * permissions on the device. |
403 | */ | | 403 | */ |
404 | accessmode = VREAD; | | 404 | accessmode = VREAD; |
405 | if ((mp->mnt_flag & MNT_RDONLY) == 0) | | 405 | if ((mp->mnt_flag & MNT_RDONLY) == 0) |
406 | accessmode |= VWRITE; | | 406 | accessmode |= VWRITE; |
407 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); | | 407 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); |
408 | error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT, | | 408 | error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT, |
409 | KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp, KAUTH_ARG(accessmode)); | | 409 | KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp, KAUTH_ARG(accessmode)); |
410 | VOP_UNLOCK(devvp); | | 410 | VOP_UNLOCK(devvp); |
411 | if (error) { | | 411 | if (error) { |
412 | DPRINTF(("KAUTH_REQ_SYSTEM_MOUNT_DEVICE %d\n", error)); | | 412 | DPRINTF(("KAUTH_REQ_SYSTEM_MOUNT_DEVICE %d\n", error)); |
413 | vrele(devvp); | | 413 | vrele(devvp); |
414 | return (error); | | 414 | return (error); |
415 | } | | 415 | } |
416 | if ((mp->mnt_flag & MNT_UPDATE) == 0) { | | 416 | if ((mp->mnt_flag & MNT_UPDATE) == 0) { |
417 | int xflags; | | 417 | int xflags; |
418 | | | 418 | |
419 | if (mp->mnt_flag & MNT_RDONLY) | | 419 | if (mp->mnt_flag & MNT_RDONLY) |
420 | xflags = FREAD; | | 420 | xflags = FREAD; |
421 | else | | 421 | else |
422 | xflags = FREAD|FWRITE; | | 422 | xflags = FREAD|FWRITE; |
423 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); | | 423 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); |
424 | error = VOP_OPEN(devvp, xflags, FSCRED); | | 424 | error = VOP_OPEN(devvp, xflags, FSCRED); |
425 | VOP_UNLOCK(devvp); | | 425 | VOP_UNLOCK(devvp); |
426 | if (error) { | | 426 | if (error) { |
427 | DPRINTF(("VOP_OPEN %d\n", error)); | | 427 | DPRINTF(("VOP_OPEN %d\n", error)); |
428 | goto fail; | | 428 | goto fail; |
429 | } | | 429 | } |
430 | error = msdosfs_mountfs(devvp, mp, l, args); | | 430 | error = msdosfs_mountfs(devvp, mp, l, args); |
431 | if (error) { | | 431 | if (error) { |
432 | DPRINTF(("msdosfs_mountfs %d\n", error)); | | 432 | DPRINTF(("msdosfs_mountfs %d\n", error)); |
433 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); | | 433 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); |
434 | (void) VOP_CLOSE(devvp, xflags, NOCRED); | | 434 | (void) VOP_CLOSE(devvp, xflags, NOCRED); |
435 | VOP_UNLOCK(devvp); | | 435 | VOP_UNLOCK(devvp); |
436 | goto fail; | | 436 | goto fail; |
437 | } | | 437 | } |
438 | #ifdef MSDOSFS_DEBUG /* only needed for the printf below */ | | 438 | #ifdef MSDOSFS_DEBUG /* only needed for the printf below */ |
439 | pmp = VFSTOMSDOSFS(mp); | | 439 | pmp = VFSTOMSDOSFS(mp); |
440 | #endif | | 440 | #endif |
441 | } else { | | 441 | } else { |
442 | vrele(devvp); | | 442 | vrele(devvp); |
443 | if (devvp != pmp->pm_devvp) { | | 443 | if (devvp != pmp->pm_devvp) { |
444 | DPRINTF(("devvp %p pmp %p\n", | | 444 | DPRINTF(("devvp %p pmp %p\n", |
445 | devvp, pmp->pm_devvp)); | | 445 | devvp, pmp->pm_devvp)); |
446 | return (EINVAL); /* needs translation */ | | 446 | return (EINVAL); /* needs translation */ |
447 | } | | 447 | } |
448 | } | | 448 | } |
449 | if ((error = update_mp(mp, args)) != 0) { | | 449 | if ((error = update_mp(mp, args)) != 0) { |
450 | msdosfs_unmount(mp, MNT_FORCE); | | 450 | msdosfs_unmount(mp, MNT_FORCE); |
451 | DPRINTF(("update_mp %d\n", error)); | | 451 | DPRINTF(("update_mp %d\n", error)); |
452 | return error; | | 452 | return error; |
453 | } | | 453 | } |
454 | | | 454 | |
455 | #ifdef MSDOSFS_DEBUG | | 455 | #ifdef MSDOSFS_DEBUG |
456 | printf("msdosfs_mount(): mp %p, pmp %p, inusemap %p\n", mp, pmp, pmp->pm_inusemap); | | 456 | printf("msdosfs_mount(): mp %p, pmp %p, inusemap %p\n", mp, pmp, pmp->pm_inusemap); |
457 | #endif | | 457 | #endif |
458 | return set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE, | | 458 | return set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE, |
459 | mp->mnt_op->vfs_name, mp, l); | | 459 | mp->mnt_op->vfs_name, mp, l); |
460 | | | 460 | |
461 | fail: | | 461 | fail: |
462 | vrele(devvp); | | 462 | vrele(devvp); |
463 | return (error); | | 463 | return (error); |
464 | } | | 464 | } |
465 | | | 465 | |
466 | int | | 466 | int |
467 | msdosfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l, struct msdosfs_args *argp) | | 467 | msdosfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l, struct msdosfs_args *argp) |
468 | { | | 468 | { |
469 | struct msdosfsmount *pmp; | | 469 | struct msdosfsmount *pmp; |
470 | struct buf *bp; | | 470 | struct buf *bp; |
471 | dev_t dev = devvp->v_rdev; | | 471 | dev_t dev = devvp->v_rdev; |
472 | union bootsector *bsp; | | 472 | union bootsector *bsp; |
473 | struct byte_bpb33 *b33; | | 473 | struct byte_bpb33 *b33; |
474 | struct byte_bpb50 *b50; | | 474 | struct byte_bpb50 *b50; |
475 | struct byte_bpb710 *b710; | | 475 | struct byte_bpb710 *b710; |
476 | uint8_t SecPerClust; | | 476 | uint8_t SecPerClust; |
477 | int ronly, error, tmp; | | 477 | int ronly, error, tmp; |
478 | int bsize; | | 478 | int bsize; |
479 | uint64_t psize; | | 479 | uint64_t psize; |
480 | unsigned secsize; | | 480 | unsigned secsize; |
481 | | | 481 | |
482 | /* Flush out any old buffers remaining from a previous use. */ | | 482 | /* Flush out any old buffers remaining from a previous use. */ |
483 | if ((error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0)) != 0) | | 483 | if ((error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0)) != 0) |
484 | return (error); | | 484 | return (error); |
485 | | | 485 | |
486 | ronly = (mp->mnt_flag & MNT_RDONLY) != 0; | | 486 | ronly = (mp->mnt_flag & MNT_RDONLY) != 0; |
487 | | | 487 | |
488 | bp = NULL; /* both used in error_exit */ | | 488 | bp = NULL; /* both used in error_exit */ |
489 | pmp = NULL; | | 489 | pmp = NULL; |
490 | | | 490 | |
491 | error = fstrans_mount(mp); | | 491 | error = fstrans_mount(mp); |
492 | if (error) | | 492 | if (error) |
493 | goto error_exit; | | 493 | goto error_exit; |
494 | | | 494 | |
495 | error = getdisksize(devvp, &psize, &secsize); | | 495 | error = getdisksize(devvp, &psize, &secsize); |
496 | if (error) { | | 496 | if (error) { |
497 | if (argp->flags & MSDOSFSMNT_GEMDOSFS) | | 497 | if (argp->flags & MSDOSFSMNT_GEMDOSFS) |
498 | goto error_exit; | | 498 | goto error_exit; |
499 | | | 499 | |
500 | /* ok, so it failed. we most likely don't need the info */ | | 500 | /* ok, so it failed. we most likely don't need the info */ |
501 | secsize = DEV_BSIZE; | | 501 | secsize = DEV_BSIZE; |
502 | psize = 0; | | 502 | psize = 0; |
503 | error = 0; | | 503 | error = 0; |
504 | } | | 504 | } |
505 | | | 505 | |
506 | if (argp->flags & MSDOSFSMNT_GEMDOSFS) { | | 506 | if (argp->flags & MSDOSFSMNT_GEMDOSFS) { |
507 | bsize = secsize; | | 507 | bsize = secsize; |
508 | if (bsize != 512) { | | 508 | if (bsize != 512) { |
509 | DPRINTF(("Invalid block bsize %d for gemdos\n", bsize)); | | 509 | DPRINTF(("Invalid block bsize %d for gemdos\n", bsize)); |
510 | error = EINVAL; | | 510 | error = EINVAL; |
511 | goto error_exit; | | 511 | goto error_exit; |
512 | } | | 512 | } |
513 | } else | | 513 | } else |
514 | bsize = 0; | | 514 | bsize = 0; |
515 | | | 515 | |
516 | /* | | 516 | /* |
517 | * Read the boot sector of the filesystem, and then check the | | 517 | * Read the boot sector of the filesystem, and then check the |
518 | * boot signature. If not a dos boot sector then error out. | | 518 | * boot signature. If not a dos boot sector then error out. |
519 | */ | | 519 | */ |
520 | if ((error = bread(devvp, 0, secsize, NOCRED, 0, &bp)) != 0) | | 520 | if ((error = bread(devvp, 0, secsize, NOCRED, 0, &bp)) != 0) |
521 | goto error_exit; | | 521 | goto error_exit; |
522 | bsp = (union bootsector *)bp->b_data; | | 522 | bsp = (union bootsector *)bp->b_data; |
523 | b33 = (struct byte_bpb33 *)bsp->bs33.bsBPB; | | 523 | b33 = (struct byte_bpb33 *)bsp->bs33.bsBPB; |
524 | b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB; | | 524 | b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB; |
525 | b710 = (struct byte_bpb710 *)bsp->bs710.bsBPB; | | 525 | b710 = (struct byte_bpb710 *)bsp->bs710.bsBPB; |
526 | | | 526 | |
527 | if (!(argp->flags & MSDOSFSMNT_GEMDOSFS)) { | | 527 | if (!(argp->flags & MSDOSFSMNT_GEMDOSFS)) { |
528 | if (bsp->bs50.bsBootSectSig0 != BOOTSIG0 | | 528 | if (bsp->bs50.bsBootSectSig0 != BOOTSIG0 |
529 | || bsp->bs50.bsBootSectSig1 != BOOTSIG1) { | | 529 | || bsp->bs50.bsBootSectSig1 != BOOTSIG1) { |
530 | DPRINTF(("bootsig0 %d bootsig1 %d\n", | | 530 | DPRINTF(("bootsig0 %d bootsig1 %d\n", |
531 | bsp->bs50.bsBootSectSig0, | | 531 | bsp->bs50.bsBootSectSig0, |
532 | bsp->bs50.bsBootSectSig1)); | | 532 | bsp->bs50.bsBootSectSig1)); |
533 | error = EINVAL; | | 533 | error = EINVAL; |
534 | goto error_exit; | | 534 | goto error_exit; |
535 | } | | 535 | } |
536 | } | | 536 | } |
537 | | | 537 | |
538 | pmp = malloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK); | | 538 | pmp = malloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK); |
539 | memset(pmp, 0, sizeof *pmp); | | 539 | memset(pmp, 0, sizeof *pmp); |
540 | pmp->pm_mountp = mp; | | 540 | pmp->pm_mountp = mp; |
541 | | | 541 | |
542 | /* | | 542 | /* |
543 | * Compute several useful quantities from the bpb in the | | 543 | * Compute several useful quantities from the bpb in the |
544 | * bootsector. Copy in the dos 5 variant of the bpb then fix up | | 544 | * bootsector. Copy in the dos 5 variant of the bpb then fix up |
545 | * the fields that are different between dos 5 and dos 3.3. | | 545 | * the fields that are different between dos 5 and dos 3.3. |
546 | */ | | 546 | */ |
547 | SecPerClust = b50->bpbSecPerClust; | | 547 | SecPerClust = b50->bpbSecPerClust; |
548 | pmp->pm_BytesPerSec = getushort(b50->bpbBytesPerSec); | | 548 | pmp->pm_BytesPerSec = getushort(b50->bpbBytesPerSec); |
549 | pmp->pm_ResSectors = getushort(b50->bpbResSectors); | | 549 | pmp->pm_ResSectors = getushort(b50->bpbResSectors); |
550 | pmp->pm_FATs = b50->bpbFATs; | | 550 | pmp->pm_FATs = b50->bpbFATs; |
551 | pmp->pm_RootDirEnts = getushort(b50->bpbRootDirEnts); | | 551 | pmp->pm_RootDirEnts = getushort(b50->bpbRootDirEnts); |
552 | pmp->pm_Sectors = getushort(b50->bpbSectors); | | 552 | pmp->pm_Sectors = getushort(b50->bpbSectors); |
553 | pmp->pm_FATsecs = getushort(b50->bpbFATsecs); | | 553 | pmp->pm_FATsecs = getushort(b50->bpbFATsecs); |
554 | pmp->pm_SecPerTrack = getushort(b50->bpbSecPerTrack); | | 554 | pmp->pm_SecPerTrack = getushort(b50->bpbSecPerTrack); |
555 | pmp->pm_Heads = getushort(b50->bpbHeads); | | 555 | pmp->pm_Heads = getushort(b50->bpbHeads); |
556 | pmp->pm_Media = b50->bpbMedia; | | 556 | pmp->pm_Media = b50->bpbMedia; |
557 | | | 557 | |
558 | if (!(argp->flags & MSDOSFSMNT_GEMDOSFS)) { | | 558 | if (!(argp->flags & MSDOSFSMNT_GEMDOSFS)) { |
559 | /* XXX - We should probably check more values here */ | | 559 | /* XXX - We should probably check more values here */ |
560 | if (!pmp->pm_BytesPerSec || !SecPerClust | | 560 | if (!pmp->pm_BytesPerSec || !SecPerClust |
561 | || pmp->pm_SecPerTrack > 63) { | | 561 | || pmp->pm_SecPerTrack > 63) { |
562 | DPRINTF(("bytespersec %d secperclust %d " | | 562 | DPRINTF(("bytespersec %d secperclust %d " |
563 | "secpertrack %d\n", | | 563 | "secpertrack %d\n", |
564 | pmp->pm_BytesPerSec, SecPerClust, | | 564 | pmp->pm_BytesPerSec, SecPerClust, |
565 | pmp->pm_SecPerTrack)); | | 565 | pmp->pm_SecPerTrack)); |
566 | error = EINVAL; | | 566 | error = EINVAL; |
567 | goto error_exit; | | 567 | goto error_exit; |
568 | } | | 568 | } |
569 | } | | 569 | } |
570 | | | 570 | |
571 | if (pmp->pm_Sectors == 0) { | | 571 | if (pmp->pm_Sectors == 0) { |
572 | pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs); | | 572 | pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs); |
573 | pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors); | | 573 | pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors); |
574 | } else { | | 574 | } else { |
575 | pmp->pm_HiddenSects = getushort(b33->bpbHiddenSecs); | | 575 | pmp->pm_HiddenSects = getushort(b33->bpbHiddenSecs); |
576 | pmp->pm_HugeSectors = pmp->pm_Sectors; | | 576 | pmp->pm_HugeSectors = pmp->pm_Sectors; |
577 | } | | 577 | } |
578 | | | 578 | |
579 | if (pmp->pm_RootDirEnts == 0) { | | 579 | if (pmp->pm_RootDirEnts == 0) { |
580 | unsigned short vers = getushort(b710->bpbFSVers); | | 580 | unsigned short vers = getushort(b710->bpbFSVers); |
581 | /* | | 581 | /* |
582 | * Some say that bsBootSectSig[23] must be zero, but | | 582 | * Some say that bsBootSectSig[23] must be zero, but |
583 | * Windows does not require this and some digital cameras | | 583 | * Windows does not require this and some digital cameras |
584 | * do not set these to zero. Therefore, do not insist. | | 584 | * do not set these to zero. Therefore, do not insist. |
585 | */ | | 585 | */ |
586 | if (pmp->pm_Sectors || pmp->pm_FATsecs || vers) { | | 586 | if (pmp->pm_Sectors || pmp->pm_FATsecs || vers) { |
587 | DPRINTF(("sectors %d fatsecs %lu vers %d\n", | | 587 | DPRINTF(("sectors %d fatsecs %lu vers %d\n", |
588 | pmp->pm_Sectors, pmp->pm_FATsecs, vers)); | | 588 | pmp->pm_Sectors, pmp->pm_FATsecs, vers)); |
589 | error = EINVAL; | | 589 | error = EINVAL; |
590 | goto error_exit; | | 590 | goto error_exit; |
591 | } | | 591 | } |
592 | pmp->pm_fatmask = FAT32_MASK; | | 592 | pmp->pm_fatmask = FAT32_MASK; |
593 | pmp->pm_fatmult = 4; | | 593 | pmp->pm_fatmult = 4; |
594 | pmp->pm_fatdiv = 1; | | 594 | pmp->pm_fatdiv = 1; |
595 | pmp->pm_FATsecs = getulong(b710->bpbBigFATsecs); | | 595 | pmp->pm_FATsecs = getulong(b710->bpbBigFATsecs); |
596 | | | 596 | |
597 | /* mirrorring is enabled if the FATMIRROR bit is not set */ | | 597 | /* mirrorring is enabled if the FATMIRROR bit is not set */ |
598 | if ((getushort(b710->bpbExtFlags) & FATMIRROR) == 0) | | 598 | if ((getushort(b710->bpbExtFlags) & FATMIRROR) == 0) |
599 | pmp->pm_flags |= MSDOSFS_FATMIRROR; | | 599 | pmp->pm_flags |= MSDOSFS_FATMIRROR; |
600 | else | | 600 | else |
601 | pmp->pm_curfat = getushort(b710->bpbExtFlags) & FATNUM; | | 601 | pmp->pm_curfat = getushort(b710->bpbExtFlags) & FATNUM; |
602 | } else | | 602 | } else |
603 | pmp->pm_flags |= MSDOSFS_FATMIRROR; | | 603 | pmp->pm_flags |= MSDOSFS_FATMIRROR; |
604 | | | 604 | |
605 | if (argp->flags & MSDOSFSMNT_GEMDOSFS) { | | 605 | if (argp->flags & MSDOSFSMNT_GEMDOSFS) { |
606 | if (FAT32(pmp)) { | | 606 | if (FAT32(pmp)) { |
607 | DPRINTF(("fat32 for gemdos\n")); | | 607 | DPRINTF(("fat32 for gemdos\n")); |
608 | /* | | 608 | /* |
609 | * GEMDOS doesn't know fat32. | | 609 | * GEMDOS doesn't know fat32. |
610 | */ | | 610 | */ |
611 | error = EINVAL; | | 611 | error = EINVAL; |
612 | goto error_exit; | | 612 | goto error_exit; |
613 | } | | 613 | } |
614 | | | 614 | |
615 | /* | | 615 | /* |
616 | * Check a few values (could do some more): | | 616 | * Check a few values (could do some more): |
617 | * - logical sector size: power of 2, >= block size | | 617 | * - logical sector size: power of 2, >= block size |
618 | * - sectors per cluster: power of 2, >= 1 | | 618 | * - sectors per cluster: power of 2, >= 1 |
619 | * - number of sectors: >= 1, <= size of partition | | 619 | * - number of sectors: >= 1, <= size of partition |
620 | */ | | 620 | */ |
621 | if ( (SecPerClust == 0) | | 621 | if ( (SecPerClust == 0) |
622 | || (SecPerClust & (SecPerClust - 1)) | | 622 | || (SecPerClust & (SecPerClust - 1)) |
623 | || (pmp->pm_BytesPerSec < bsize) | | 623 | || (pmp->pm_BytesPerSec < bsize) |
624 | || (pmp->pm_BytesPerSec & (pmp->pm_BytesPerSec - 1)) | | 624 | || (pmp->pm_BytesPerSec & (pmp->pm_BytesPerSec - 1)) |
625 | || (pmp->pm_HugeSectors == 0) | | 625 | || (pmp->pm_HugeSectors == 0) |
626 | || (pmp->pm_HugeSectors * (pmp->pm_BytesPerSec / bsize) | | 626 | || (pmp->pm_HugeSectors * (pmp->pm_BytesPerSec / bsize) |
627 | > psize)) { | | 627 | > psize)) { |
628 | DPRINTF(("consistency checks for gemdos\n")); | | 628 | DPRINTF(("consistency checks for gemdos\n")); |
629 | error = EINVAL; | | 629 | error = EINVAL; |
630 | goto error_exit; | | 630 | goto error_exit; |
631 | } | | 631 | } |
632 | /* | | 632 | /* |
633 | * XXX - Many parts of the msdos fs driver seem to assume that | | 633 | * XXX - Many parts of the msdos fs driver seem to assume that |
634 | * the number of bytes per logical sector (BytesPerSec) will | | 634 | * the number of bytes per logical sector (BytesPerSec) will |
635 | * always be the same as the number of bytes per disk block | | 635 | * always be the same as the number of bytes per disk block |
636 | * Let's pretend it is. | | 636 | * Let's pretend it is. |
637 | */ | | 637 | */ |
638 | tmp = pmp->pm_BytesPerSec / bsize; | | 638 | tmp = pmp->pm_BytesPerSec / bsize; |
639 | pmp->pm_BytesPerSec = bsize; | | 639 | pmp->pm_BytesPerSec = bsize; |
640 | pmp->pm_HugeSectors *= tmp; | | 640 | pmp->pm_HugeSectors *= tmp; |
641 | pmp->pm_HiddenSects *= tmp; | | 641 | pmp->pm_HiddenSects *= tmp; |
642 | pmp->pm_ResSectors *= tmp; | | 642 | pmp->pm_ResSectors *= tmp; |
643 | pmp->pm_Sectors *= tmp; | | 643 | pmp->pm_Sectors *= tmp; |
644 | pmp->pm_FATsecs *= tmp; | | 644 | pmp->pm_FATsecs *= tmp; |
645 | SecPerClust *= tmp; | | 645 | SecPerClust *= tmp; |
646 | } | | 646 | } |
647 | | | 647 | |
648 | /* Check that fs has nonzero FAT size */ | | 648 | /* Check that fs has nonzero FAT size */ |
649 | if (pmp->pm_FATsecs == 0) { | | 649 | if (pmp->pm_FATsecs == 0) { |
650 | DPRINTF(("FATsecs is 0\n")); | | 650 | DPRINTF(("FATsecs is 0\n")); |
651 | error = EINVAL; | | 651 | error = EINVAL; |
652 | goto error_exit; | | 652 | goto error_exit; |
653 | } | | 653 | } |
654 | | | 654 | |
655 | pmp->pm_fatblk = pmp->pm_ResSectors; | | 655 | pmp->pm_fatblk = pmp->pm_ResSectors; |
656 | if (FAT32(pmp)) { | | 656 | if (FAT32(pmp)) { |
657 | pmp->pm_rootdirblk = getulong(b710->bpbRootClust); | | 657 | pmp->pm_rootdirblk = getulong(b710->bpbRootClust); |
658 | pmp->pm_firstcluster = pmp->pm_fatblk | | 658 | pmp->pm_firstcluster = pmp->pm_fatblk |
659 | + (pmp->pm_FATs * pmp->pm_FATsecs); | | 659 | + (pmp->pm_FATs * pmp->pm_FATsecs); |
660 | pmp->pm_fsinfo = getushort(b710->bpbFSInfo); | | 660 | pmp->pm_fsinfo = getushort(b710->bpbFSInfo); |
661 | } else { | | 661 | } else { |
662 | pmp->pm_rootdirblk = pmp->pm_fatblk + | | 662 | pmp->pm_rootdirblk = pmp->pm_fatblk + |
663 | (pmp->pm_FATs * pmp->pm_FATsecs); | | 663 | (pmp->pm_FATs * pmp->pm_FATsecs); |
664 | pmp->pm_rootdirsize = (pmp->pm_RootDirEnts * sizeof(struct direntry) | | 664 | pmp->pm_rootdirsize = (pmp->pm_RootDirEnts * sizeof(struct direntry) |
665 | + pmp->pm_BytesPerSec - 1) | | 665 | + pmp->pm_BytesPerSec - 1) |
666 | / pmp->pm_BytesPerSec;/* in sectors */ | | 666 | / pmp->pm_BytesPerSec;/* in sectors */ |
667 | pmp->pm_firstcluster = pmp->pm_rootdirblk + pmp->pm_rootdirsize; | | 667 | pmp->pm_firstcluster = pmp->pm_rootdirblk + pmp->pm_rootdirsize; |
668 | } | | 668 | } |
669 | | | 669 | |
670 | pmp->pm_nmbrofclusters = (pmp->pm_HugeSectors - pmp->pm_firstcluster) / | | 670 | pmp->pm_nmbrofclusters = (pmp->pm_HugeSectors - pmp->pm_firstcluster) / |
671 | SecPerClust; | | 671 | SecPerClust; |
672 | pmp->pm_maxcluster = pmp->pm_nmbrofclusters + 1; | | 672 | pmp->pm_maxcluster = pmp->pm_nmbrofclusters + 1; |
673 | pmp->pm_fatsize = pmp->pm_FATsecs * pmp->pm_BytesPerSec; | | 673 | pmp->pm_fatsize = pmp->pm_FATsecs * pmp->pm_BytesPerSec; |
674 | | | 674 | |
675 | if (argp->flags & MSDOSFSMNT_GEMDOSFS) { | | 675 | if (argp->flags & MSDOSFSMNT_GEMDOSFS) { |
676 | if (pmp->pm_nmbrofclusters <= (0xff0 - 2)) { | | 676 | if (pmp->pm_nmbrofclusters <= (0xff0 - 2)) { |
677 | pmp->pm_fatmask = FAT12_MASK; | | 677 | pmp->pm_fatmask = FAT12_MASK; |
678 | pmp->pm_fatmult = 3; | | 678 | pmp->pm_fatmult = 3; |
679 | pmp->pm_fatdiv = 2; | | 679 | pmp->pm_fatdiv = 2; |
680 | } else { | | 680 | } else { |
681 | pmp->pm_fatmask = FAT16_MASK; | | 681 | pmp->pm_fatmask = FAT16_MASK; |
682 | pmp->pm_fatmult = 2; | | 682 | pmp->pm_fatmult = 2; |
683 | pmp->pm_fatdiv = 1; | | 683 | pmp->pm_fatdiv = 1; |
684 | } | | 684 | } |
685 | } else if (pmp->pm_fatmask == 0) { | | 685 | } else if (pmp->pm_fatmask == 0) { |
686 | if (pmp->pm_maxcluster | | 686 | if (pmp->pm_maxcluster |
687 | <= ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK)) { | | 687 | <= ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK)) { |
688 | /* | | 688 | /* |
689 | * This will usually be a floppy disk. This size makes | | 689 | * This will usually be a floppy disk. This size makes |
690 | * sure that one fat entry will not be split across | | 690 | * sure that one fat entry will not be split across |
691 | * multiple blocks. | | 691 | * multiple blocks. |
692 | */ | | 692 | */ |
693 | pmp->pm_fatmask = FAT12_MASK; | | 693 | pmp->pm_fatmask = FAT12_MASK; |
694 | pmp->pm_fatmult = 3; | | 694 | pmp->pm_fatmult = 3; |
695 | pmp->pm_fatdiv = 2; | | 695 | pmp->pm_fatdiv = 2; |
696 | } else { | | 696 | } else { |
697 | pmp->pm_fatmask = FAT16_MASK; | | 697 | pmp->pm_fatmask = FAT16_MASK; |
698 | pmp->pm_fatmult = 2; | | 698 | pmp->pm_fatmult = 2; |
699 | pmp->pm_fatdiv = 1; | | 699 | pmp->pm_fatdiv = 1; |
700 | } | | 700 | } |
701 | } | | 701 | } |
702 | if (FAT12(pmp)) | | 702 | if (FAT12(pmp)) |
703 | pmp->pm_fatblocksize = 3 * pmp->pm_BytesPerSec; | | 703 | pmp->pm_fatblocksize = 3 * pmp->pm_BytesPerSec; |
704 | else | | 704 | else |
705 | pmp->pm_fatblocksize = MAXBSIZE; | | 705 | pmp->pm_fatblocksize = MAXBSIZE; |
706 | | | 706 | |
707 | pmp->pm_fatblocksec = pmp->pm_fatblocksize / pmp->pm_BytesPerSec; | | 707 | pmp->pm_fatblocksec = pmp->pm_fatblocksize / pmp->pm_BytesPerSec; |
708 | pmp->pm_bnshift = ffs(pmp->pm_BytesPerSec) - 1; | | 708 | pmp->pm_bnshift = ffs(pmp->pm_BytesPerSec) - 1; |
709 | | | 709 | |
710 | /* | | 710 | /* |
711 | * Compute mask and shift value for isolating cluster relative byte | | 711 | * Compute mask and shift value for isolating cluster relative byte |
712 | * offsets and cluster numbers from a file offset. | | 712 | * offsets and cluster numbers from a file offset. |
713 | */ | | 713 | */ |
714 | pmp->pm_bpcluster = SecPerClust * pmp->pm_BytesPerSec; | | 714 | pmp->pm_bpcluster = SecPerClust * pmp->pm_BytesPerSec; |
715 | pmp->pm_crbomask = pmp->pm_bpcluster - 1; | | 715 | pmp->pm_crbomask = pmp->pm_bpcluster - 1; |
716 | pmp->pm_cnshift = ffs(pmp->pm_bpcluster) - 1; | | 716 | pmp->pm_cnshift = ffs(pmp->pm_bpcluster) - 1; |
717 | | | 717 | |
718 | /* | | 718 | /* |
719 | * Check for valid cluster size | | 719 | * Check for valid cluster size |
720 | * must be a power of 2 | | 720 | * must be a power of 2 |
721 | */ | | 721 | */ |
722 | if (pmp->pm_bpcluster ^ (1 << pmp->pm_cnshift)) { | | 722 | if (pmp->pm_bpcluster ^ (1 << pmp->pm_cnshift)) { |
723 | DPRINTF(("bpcluster %lu cnshift %lu\n", | | 723 | DPRINTF(("bpcluster %lu cnshift %lu\n", |
724 | pmp->pm_bpcluster, pmp->pm_cnshift)); | | 724 | pmp->pm_bpcluster, pmp->pm_cnshift)); |
725 | error = EINVAL; | | 725 | error = EINVAL; |
726 | goto error_exit; | | 726 | goto error_exit; |
727 | } | | 727 | } |
728 | | | 728 | |
729 | /* | | 729 | /* |
730 | * Release the bootsector buffer. | | 730 | * Release the bootsector buffer. |
731 | */ | | 731 | */ |
732 | brelse(bp, BC_AGE); | | 732 | brelse(bp, BC_AGE); |
733 | bp = NULL; | | 733 | bp = NULL; |
734 | | | 734 | |
735 | /* | | 735 | /* |
736 | * Check FSInfo. | | 736 | * Check FSInfo. |
737 | */ | | 737 | */ |
738 | if (pmp->pm_fsinfo) { | | 738 | if (pmp->pm_fsinfo) { |
739 | struct fsinfo *fp; | | 739 | struct fsinfo *fp; |
740 | | | 740 | |
741 | /* | | 741 | /* |
742 | * XXX If the fsinfo block is stored on media with | | 742 | * XXX If the fsinfo block is stored on media with |
743 | * 2KB or larger sectors, is the fsinfo structure | | 743 | * 2KB or larger sectors, is the fsinfo structure |
744 | * padded at the end or in the middle? | | 744 | * padded at the end or in the middle? |
745 | */ | | 745 | */ |
746 | if ((error = bread(devvp, de_bn2kb(pmp, pmp->pm_fsinfo), | | 746 | if ((error = bread(devvp, de_bn2kb(pmp, pmp->pm_fsinfo), |
747 | pmp->pm_BytesPerSec, NOCRED, 0, &bp)) != 0) | | 747 | pmp->pm_BytesPerSec, NOCRED, 0, &bp)) != 0) |
748 | goto error_exit; | | 748 | goto error_exit; |
749 | fp = (struct fsinfo *)bp->b_data; | | 749 | fp = (struct fsinfo *)bp->b_data; |
750 | if (!memcmp(fp->fsisig1, "RRaA", 4) | | 750 | if (!memcmp(fp->fsisig1, "RRaA", 4) |
751 | && !memcmp(fp->fsisig2, "rrAa", 4) | | 751 | && !memcmp(fp->fsisig2, "rrAa", 4) |
752 | && !memcmp(fp->fsisig3, "\0\0\125\252", 4) | | 752 | && !memcmp(fp->fsisig3, "\0\0\125\252", 4) |
753 | && !memcmp(fp->fsisig4, "\0\0\125\252", 4)) | | 753 | && !memcmp(fp->fsisig4, "\0\0\125\252", 4)) |
754 | pmp->pm_nxtfree = getulong(fp->fsinxtfree); | | 754 | pmp->pm_nxtfree = getulong(fp->fsinxtfree); |
755 | else | | 755 | else |
756 | pmp->pm_fsinfo = 0; | | 756 | pmp->pm_fsinfo = 0; |
757 | brelse(bp, 0); | | 757 | brelse(bp, 0); |
758 | bp = NULL; | | 758 | bp = NULL; |
759 | } | | 759 | } |
760 | | | 760 | |
761 | /* | | 761 | /* |
762 | * Check and validate (or perhaps invalidate?) the fsinfo structure? | | 762 | * Check and validate (or perhaps invalidate?) the fsinfo structure? |
763 | * XXX | | 763 | * XXX |
764 | */ | | 764 | */ |
765 | if (pmp->pm_fsinfo) { | | 765 | if (pmp->pm_fsinfo) { |
766 | if (pmp->pm_nxtfree == (u_long)-1) | | 766 | if (pmp->pm_nxtfree == (u_long)-1) |
767 | pmp->pm_fsinfo = 0; | | 767 | pmp->pm_fsinfo = 0; |
768 | } | | 768 | } |
769 | | | 769 | |
770 | /* | | 770 | /* |
771 | * Allocate memory for the bitmap of allocated clusters, and then | | 771 | * Allocate memory for the bitmap of allocated clusters, and then |
772 | * fill it in. | | 772 | * fill it in. |
773 | */ | | 773 | */ |
774 | pmp->pm_inusemap = malloc(((pmp->pm_maxcluster + N_INUSEBITS - 1) | | 774 | pmp->pm_inusemap = malloc(((pmp->pm_maxcluster + N_INUSEBITS) |
775 | / N_INUSEBITS) | | 775 | / N_INUSEBITS) |
776 | * sizeof(*pmp->pm_inusemap), | | 776 | * sizeof(*pmp->pm_inusemap), |
777 | M_MSDOSFSFAT, M_WAITOK); | | 777 | M_MSDOSFSFAT, M_WAITOK); |
778 | | | 778 | |
779 | /* | | 779 | /* |
780 | * fillinusemap() needs pm_devvp. | | 780 | * fillinusemap() needs pm_devvp. |
781 | */ | | 781 | */ |
782 | pmp->pm_dev = dev; | | 782 | pmp->pm_dev = dev; |
783 | pmp->pm_devvp = devvp; | | 783 | pmp->pm_devvp = devvp; |
784 | | | 784 | |
785 | /* | | 785 | /* |
786 | * Have the inuse map filled in. | | 786 | * Have the inuse map filled in. |
787 | */ | | 787 | */ |
788 | if ((error = fillinusemap(pmp)) != 0) { | | 788 | if ((error = fillinusemap(pmp)) != 0) { |
789 | DPRINTF(("fillinusemap %d\n", error)); | | 789 | DPRINTF(("fillinusemap %d\n", error)); |
790 | goto error_exit; | | 790 | goto error_exit; |
791 | } | | 791 | } |
792 | | | 792 | |
793 | /* | | 793 | /* |
794 | * If they want fat updates to be synchronous then let them suffer | | 794 | * If they want fat updates to be synchronous then let them suffer |
795 | * the performance degradation in exchange for the on disk copy of | | 795 | * the performance degradation in exchange for the on disk copy of |
796 | * the fat being correct just about all the time. I suppose this | | 796 | * the fat being correct just about all the time. I suppose this |
797 | * would be a good thing to turn on if the kernel is still flakey. | | 797 | * would be a good thing to turn on if the kernel is still flakey. |
798 | */ | | 798 | */ |
799 | if (mp->mnt_flag & MNT_SYNCHRONOUS) | | 799 | if (mp->mnt_flag & MNT_SYNCHRONOUS) |
800 | pmp->pm_flags |= MSDOSFSMNT_WAITONFAT; | | 800 | pmp->pm_flags |= MSDOSFSMNT_WAITONFAT; |
801 | | | 801 | |
802 | /* | | 802 | /* |
803 | * Finish up. | | 803 | * Finish up. |
804 | */ | | 804 | */ |
805 | if (ronly) | | 805 | if (ronly) |
806 | pmp->pm_flags |= MSDOSFSMNT_RONLY; | | 806 | pmp->pm_flags |= MSDOSFSMNT_RONLY; |
807 | else | | 807 | else |
808 | pmp->pm_fmod = 1; | | 808 | pmp->pm_fmod = 1; |
809 | mp->mnt_data = pmp; | | 809 | mp->mnt_data = pmp; |
810 | mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev; | | 810 | mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev; |
811 | mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_MSDOS); | | 811 | mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_MSDOS); |
812 | mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0]; | | 812 | mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0]; |
813 | mp->mnt_stat.f_namemax = MSDOSFS_NAMEMAX(pmp); | | 813 | mp->mnt_stat.f_namemax = MSDOSFS_NAMEMAX(pmp); |
814 | mp->mnt_flag |= MNT_LOCAL; | | 814 | mp->mnt_flag |= MNT_LOCAL; |
815 | mp->mnt_dev_bshift = pmp->pm_bnshift; | | 815 | mp->mnt_dev_bshift = pmp->pm_bnshift; |
816 | mp->mnt_fs_bshift = pmp->pm_cnshift; | | 816 | mp->mnt_fs_bshift = pmp->pm_cnshift; |
817 | | | 817 | |
818 | /* | | 818 | /* |
819 | * If we ever do quotas for DOS filesystems this would be a place | | 819 | * If we ever do quotas for DOS filesystems this would be a place |
820 | * to fill in the info in the msdosfsmount structure. You dolt, | | 820 | * to fill in the info in the msdosfsmount structure. You dolt, |
821 | * quotas on dos filesystems make no sense because files have no | | 821 | * quotas on dos filesystems make no sense because files have no |
822 | * owners on dos filesystems. of course there is some empty space | | 822 | * owners on dos filesystems. of course there is some empty space |
823 | * in the directory entry where we could put uid's and gid's. | | 823 | * in the directory entry where we could put uid's and gid's. |
824 | */ | | 824 | */ |
825 | | | 825 | |
826 | devvp->v_specmountpoint = mp; | | 826 | devvp->v_specmountpoint = mp; |
827 | | | 827 | |
828 | return (0); | | 828 | return (0); |
829 | | | 829 | |
830 | error_exit: | | 830 | error_exit: |
831 | fstrans_unmount(mp); | | 831 | fstrans_unmount(mp); |
832 | if (bp) | | 832 | if (bp) |
833 | brelse(bp, BC_AGE); | | 833 | brelse(bp, BC_AGE); |
834 | if (pmp) { | | 834 | if (pmp) { |
835 | if (pmp->pm_inusemap) | | 835 | if (pmp->pm_inusemap) |
836 | free(pmp->pm_inusemap, M_MSDOSFSFAT); | | 836 | free(pmp->pm_inusemap, M_MSDOSFSFAT); |
837 | free(pmp, M_MSDOSFSMNT); | | 837 | free(pmp, M_MSDOSFSMNT); |
838 | mp->mnt_data = NULL; | | 838 | mp->mnt_data = NULL; |
839 | } | | 839 | } |
840 | return (error); | | 840 | return (error); |
841 | } | | 841 | } |
842 | | | 842 | |
843 | int | | 843 | int |
844 | msdosfs_start(struct mount *mp, int flags) | | 844 | msdosfs_start(struct mount *mp, int flags) |
845 | { | | 845 | { |
846 | | | 846 | |
847 | return (0); | | 847 | return (0); |
848 | } | | 848 | } |
849 | | | 849 | |
850 | /* | | 850 | /* |
851 | * Unmount the filesystem described by mp. | | 851 | * Unmount the filesystem described by mp. |
852 | */ | | 852 | */ |
853 | int | | 853 | int |
854 | msdosfs_unmount(struct mount *mp, int mntflags) | | 854 | msdosfs_unmount(struct mount *mp, int mntflags) |
855 | { | | 855 | { |
856 | struct msdosfsmount *pmp; | | 856 | struct msdosfsmount *pmp; |
857 | int error, flags; | | 857 | int error, flags; |
858 | | | 858 | |
859 | flags = 0; | | 859 | flags = 0; |
860 | if (mntflags & MNT_FORCE) | | 860 | if (mntflags & MNT_FORCE) |
861 | flags |= FORCECLOSE; | | 861 | flags |= FORCECLOSE; |
862 | if ((error = vflush(mp, NULLVP, flags)) != 0) | | 862 | if ((error = vflush(mp, NULLVP, flags)) != 0) |
863 | return (error); | | 863 | return (error); |
864 | pmp = VFSTOMSDOSFS(mp); | | 864 | pmp = VFSTOMSDOSFS(mp); |
865 | if (pmp->pm_devvp->v_type != VBAD) | | 865 | if (pmp->pm_devvp->v_type != VBAD) |
866 | pmp->pm_devvp->v_specmountpoint = NULL; | | 866 | pmp->pm_devvp->v_specmountpoint = NULL; |
867 | #ifdef MSDOSFS_DEBUG | | 867 | #ifdef MSDOSFS_DEBUG |
868 | { | | 868 | { |
869 | struct vnode *vp = pmp->pm_devvp; | | 869 | struct vnode *vp = pmp->pm_devvp; |
870 | | | 870 | |
871 | printf("msdosfs_umount(): just before calling VOP_CLOSE()\n"); | | 871 | printf("msdosfs_umount(): just before calling VOP_CLOSE()\n"); |
872 | printf("flag %08x, usecount %d, writecount %d, holdcnt %d\n", | | 872 | printf("flag %08x, usecount %d, writecount %d, holdcnt %d\n", |
873 | vp->v_vflag | vp->v_iflag | vp->v_uflag, vp->v_usecount, | | 873 | vp->v_vflag | vp->v_iflag | vp->v_uflag, vp->v_usecount, |
874 | vp->v_writecount, vp->v_holdcnt); | | 874 | vp->v_writecount, vp->v_holdcnt); |
875 | printf("mount %p, op %p\n", | | 875 | printf("mount %p, op %p\n", |
876 | vp->v_mount, vp->v_op); | | 876 | vp->v_mount, vp->v_op); |
877 | printf("freef %p, freeb %p, mount %p\n", | | 877 | printf("freef %p, freeb %p, mount %p\n", |
878 | vp->v_freelist.tqe_next, vp->v_freelist.tqe_prev, | | 878 | vp->v_freelist.tqe_next, vp->v_freelist.tqe_prev, |
879 | vp->v_mount); | | 879 | vp->v_mount); |
880 | printf("cleanblkhd %p, dirtyblkhd %p, numoutput %d, type %d\n", | | 880 | printf("cleanblkhd %p, dirtyblkhd %p, numoutput %d, type %d\n", |
881 | vp->v_cleanblkhd.lh_first, | | 881 | vp->v_cleanblkhd.lh_first, |
882 | vp->v_dirtyblkhd.lh_first, | | 882 | vp->v_dirtyblkhd.lh_first, |
883 | vp->v_numoutput, vp->v_type); | | 883 | vp->v_numoutput, vp->v_type); |
884 | printf("union %p, tag %d, data[0] %08x, data[1] %08x\n", | | 884 | printf("union %p, tag %d, data[0] %08x, data[1] %08x\n", |
885 | vp->v_socket, vp->v_tag, | | 885 | vp->v_socket, vp->v_tag, |
886 | ((u_int *)vp->v_data)[0], | | 886 | ((u_int *)vp->v_data)[0], |
887 | ((u_int *)vp->v_data)[1]); | | 887 | ((u_int *)vp->v_data)[1]); |
888 | } | | 888 | } |
889 | #endif | | 889 | #endif |
890 | vn_lock(pmp->pm_devvp, LK_EXCLUSIVE | LK_RETRY); | | 890 | vn_lock(pmp->pm_devvp, LK_EXCLUSIVE | LK_RETRY); |
891 | (void) VOP_CLOSE(pmp->pm_devvp, | | 891 | (void) VOP_CLOSE(pmp->pm_devvp, |
892 | pmp->pm_flags & MSDOSFSMNT_RONLY ? FREAD : FREAD|FWRITE, NOCRED); | | 892 | pmp->pm_flags & MSDOSFSMNT_RONLY ? FREAD : FREAD|FWRITE, NOCRED); |
893 | vput(pmp->pm_devvp); | | 893 | vput(pmp->pm_devvp); |
894 | msdosfs_fh_destroy(pmp); | | 894 | msdosfs_fh_destroy(pmp); |
895 | free(pmp->pm_inusemap, M_MSDOSFSFAT); | | 895 | free(pmp->pm_inusemap, M_MSDOSFSFAT); |
896 | free(pmp, M_MSDOSFSMNT); | | 896 | free(pmp, M_MSDOSFSMNT); |
897 | mp->mnt_data = NULL; | | 897 | mp->mnt_data = NULL; |
898 | mp->mnt_flag &= ~MNT_LOCAL; | | 898 | mp->mnt_flag &= ~MNT_LOCAL; |
899 | fstrans_unmount(mp); | | 899 | fstrans_unmount(mp); |
900 | return (0); | | 900 | return (0); |
901 | } | | 901 | } |
902 | | | 902 | |
903 | int | | 903 | int |
904 | msdosfs_root(struct mount *mp, struct vnode **vpp) | | 904 | msdosfs_root(struct mount *mp, struct vnode **vpp) |
905 | { | | 905 | { |
906 | struct msdosfsmount *pmp = VFSTOMSDOSFS(mp); | | 906 | struct msdosfsmount *pmp = VFSTOMSDOSFS(mp); |
907 | struct denode *ndep; | | 907 | struct denode *ndep; |
908 | int error; | | 908 | int error; |
909 | | | 909 | |
910 | #ifdef MSDOSFS_DEBUG | | 910 | #ifdef MSDOSFS_DEBUG |
911 | printf("msdosfs_root(); mp %p, pmp %p\n", mp, pmp); | | 911 | printf("msdosfs_root(); mp %p, pmp %p\n", mp, pmp); |
912 | #endif | | 912 | #endif |
913 | if ((error = deget(pmp, MSDOSFSROOT, MSDOSFSROOT_OFS, &ndep)) != 0) | | 913 | if ((error = deget(pmp, MSDOSFSROOT, MSDOSFSROOT_OFS, &ndep)) != 0) |
914 | return (error); | | 914 | return (error); |
915 | *vpp = DETOV(ndep); | | 915 | *vpp = DETOV(ndep); |
916 | return (0); | | 916 | return (0); |
917 | } | | 917 | } |
918 | | | 918 | |
919 | int | | 919 | int |
920 | msdosfs_statvfs(struct mount *mp, struct statvfs *sbp) | | 920 | msdosfs_statvfs(struct mount *mp, struct statvfs *sbp) |
921 | { | | 921 | { |
922 | struct msdosfsmount *pmp; | | 922 | struct msdosfsmount *pmp; |
923 | | | 923 | |
924 | pmp = VFSTOMSDOSFS(mp); | | 924 | pmp = VFSTOMSDOSFS(mp); |
925 | sbp->f_bsize = pmp->pm_bpcluster; | | 925 | sbp->f_bsize = pmp->pm_bpcluster; |
926 | sbp->f_frsize = sbp->f_bsize; | | 926 | sbp->f_frsize = sbp->f_bsize; |
927 | sbp->f_iosize = pmp->pm_bpcluster; | | 927 | sbp->f_iosize = pmp->pm_bpcluster; |
928 | sbp->f_blocks = pmp->pm_nmbrofclusters; | | 928 | sbp->f_blocks = pmp->pm_nmbrofclusters; |
929 | sbp->f_bfree = pmp->pm_freeclustercount; | | 929 | sbp->f_bfree = pmp->pm_freeclustercount; |
930 | sbp->f_bavail = pmp->pm_freeclustercount; | | 930 | sbp->f_bavail = pmp->pm_freeclustercount; |
931 | sbp->f_bresvd = 0; | | 931 | sbp->f_bresvd = 0; |
932 | sbp->f_files = pmp->pm_RootDirEnts; /* XXX */ | | 932 | sbp->f_files = pmp->pm_RootDirEnts; /* XXX */ |
933 | sbp->f_ffree = 0; /* what to put in here? */ | | 933 | sbp->f_ffree = 0; /* what to put in here? */ |
934 | sbp->f_favail = 0; /* what to put in here? */ | | 934 | sbp->f_favail = 0; /* what to put in here? */ |
935 | sbp->f_fresvd = 0; | | 935 | sbp->f_fresvd = 0; |
936 | copy_statvfs_info(sbp, mp); | | 936 | copy_statvfs_info(sbp, mp); |
937 | return (0); | | 937 | return (0); |
938 | } | | 938 | } |
939 | | | 939 | |
940 | int | | 940 | int |
941 | msdosfs_sync(struct mount *mp, int waitfor, kauth_cred_t cred) | | 941 | msdosfs_sync(struct mount *mp, int waitfor, kauth_cred_t cred) |
942 | { | | 942 | { |
943 | struct vnode *vp, *mvp; | | 943 | struct vnode *vp, *mvp; |
944 | struct denode *dep; | | 944 | struct denode *dep; |
945 | struct msdosfsmount *pmp = VFSTOMSDOSFS(mp); | | 945 | struct msdosfsmount *pmp = VFSTOMSDOSFS(mp); |
946 | int error, allerror = 0; | | 946 | int error, allerror = 0; |
947 | | | 947 | |
948 | /* | | 948 | /* |
949 | * If we ever switch to not updating all of the fats all the time, | | 949 | * If we ever switch to not updating all of the fats all the time, |
950 | * this would be the place to update them from the first one. | | 950 | * this would be the place to update them from the first one. |
951 | */ | | 951 | */ |
952 | if (pmp->pm_fmod != 0) { | | 952 | if (pmp->pm_fmod != 0) { |
953 | if (pmp->pm_flags & MSDOSFSMNT_RONLY) | | 953 | if (pmp->pm_flags & MSDOSFSMNT_RONLY) |
954 | panic("msdosfs_sync: rofs mod"); | | 954 | panic("msdosfs_sync: rofs mod"); |
955 | else { | | 955 | else { |
956 | /* update fats here */ | | 956 | /* update fats here */ |
957 | } | | 957 | } |
958 | } | | 958 | } |
959 | /* Allocate a marker vnode. */ | | 959 | /* Allocate a marker vnode. */ |
960 | mvp = vnalloc(mp); | | 960 | mvp = vnalloc(mp); |
961 | fstrans_start(mp, FSTRANS_SHARED); | | 961 | fstrans_start(mp, FSTRANS_SHARED); |
962 | /* | | 962 | /* |
963 | * Write back each (modified) denode. | | 963 | * Write back each (modified) denode. |
964 | */ | | 964 | */ |
965 | mutex_enter(&mntvnode_lock); | | 965 | mutex_enter(&mntvnode_lock); |
966 | loop: | | 966 | loop: |
967 | for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = vunmark(mvp)) { | | 967 | for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = vunmark(mvp)) { |
968 | vmark(mvp, vp); | | 968 | vmark(mvp, vp); |
969 | if (vp->v_mount != mp || vismarker(vp)) | | 969 | if (vp->v_mount != mp || vismarker(vp)) |
970 | continue; | | 970 | continue; |
971 | mutex_enter(vp->v_interlock); | | 971 | mutex_enter(vp->v_interlock); |
972 | dep = VTODE(vp); | | 972 | dep = VTODE(vp); |
973 | if (waitfor == MNT_LAZY || vp->v_type == VNON || | | 973 | if (waitfor == MNT_LAZY || vp->v_type == VNON || |
974 | dep == NULL || (((dep->de_flag & | | 974 | dep == NULL || (((dep->de_flag & |
975 | (DE_ACCESS | DE_CREATE | DE_UPDATE | DE_MODIFIED)) == 0) && | | 975 | (DE_ACCESS | DE_CREATE | DE_UPDATE | DE_MODIFIED)) == 0) && |
976 | (LIST_EMPTY(&vp->v_dirtyblkhd) && | | 976 | (LIST_EMPTY(&vp->v_dirtyblkhd) && |
977 | UVM_OBJ_IS_CLEAN(&vp->v_uobj)))) { | | 977 | UVM_OBJ_IS_CLEAN(&vp->v_uobj)))) { |
978 | mutex_exit(vp->v_interlock); | | 978 | mutex_exit(vp->v_interlock); |
979 | continue; | | 979 | continue; |
980 | } | | 980 | } |
981 | mutex_exit(&mntvnode_lock); | | 981 | mutex_exit(&mntvnode_lock); |
982 | error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT); | | 982 | error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT); |
983 | if (error) { | | 983 | if (error) { |
984 | mutex_enter(&mntvnode_lock); | | 984 | mutex_enter(&mntvnode_lock); |
985 | if (error == ENOENT) { | | 985 | if (error == ENOENT) { |
986 | (void)vunmark(mvp); | | 986 | (void)vunmark(mvp); |
987 | goto loop; | | 987 | goto loop; |
988 | } | | 988 | } |
989 | continue; | | 989 | continue; |
990 | } | | 990 | } |
991 | if ((error = VOP_FSYNC(vp, cred, | | 991 | if ((error = VOP_FSYNC(vp, cred, |
992 | waitfor == MNT_WAIT ? FSYNC_WAIT : 0, 0, 0)) != 0) | | 992 | waitfor == MNT_WAIT ? FSYNC_WAIT : 0, 0, 0)) != 0) |
993 | allerror = error; | | 993 | allerror = error; |
994 | vput(vp); | | 994 | vput(vp); |
995 | mutex_enter(&mntvnode_lock); | | 995 | mutex_enter(&mntvnode_lock); |
996 | } | | 996 | } |
997 | mutex_exit(&mntvnode_lock); | | 997 | mutex_exit(&mntvnode_lock); |
998 | vnfree(mvp); | | 998 | vnfree(mvp); |
999 | | | 999 | |
1000 | /* | | 1000 | /* |
1001 | * Force stale file system control information to be flushed. | | 1001 | * Force stale file system control information to be flushed. |
1002 | */ | | 1002 | */ |
1003 | if ((error = VOP_FSYNC(pmp->pm_devvp, cred, | | 1003 | if ((error = VOP_FSYNC(pmp->pm_devvp, cred, |
1004 | waitfor == MNT_WAIT ? FSYNC_WAIT : 0, 0, 0)) != 0) | | 1004 | waitfor == MNT_WAIT ? FSYNC_WAIT : 0, 0, 0)) != 0) |
1005 | allerror = error; | | 1005 | allerror = error; |
1006 | fstrans_done(mp); | | 1006 | fstrans_done(mp); |
1007 | return (allerror); | | 1007 | return (allerror); |
1008 | } | | 1008 | } |
1009 | | | 1009 | |
1010 | int | | 1010 | int |
1011 | msdosfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp) | | 1011 | msdosfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp) |
1012 | { | | 1012 | { |
1013 | struct msdosfsmount *pmp = VFSTOMSDOSFS(mp); | | 1013 | struct msdosfsmount *pmp = VFSTOMSDOSFS(mp); |
1014 | struct defid defh; | | 1014 | struct defid defh; |
1015 | struct denode *dep; | | 1015 | struct denode *dep; |
1016 | uint32_t gen; | | 1016 | uint32_t gen; |
1017 | int error; | | 1017 | int error; |
1018 | | | 1018 | |
1019 | if (fhp->fid_len != sizeof(struct defid)) { | | 1019 | if (fhp->fid_len != sizeof(struct defid)) { |
1020 | DPRINTF(("fid_len %d %zd\n", fhp->fid_len, | | 1020 | DPRINTF(("fid_len %d %zd\n", fhp->fid_len, |
1021 | sizeof(struct defid))); | | 1021 | sizeof(struct defid))); |
1022 | return EINVAL; | | 1022 | return EINVAL; |
1023 | } | | 1023 | } |
1024 | memcpy(&defh, fhp, sizeof(defh)); | | 1024 | memcpy(&defh, fhp, sizeof(defh)); |
1025 | error = msdosfs_fh_lookup(pmp, defh.defid_dirclust, defh.defid_dirofs, | | 1025 | error = msdosfs_fh_lookup(pmp, defh.defid_dirclust, defh.defid_dirofs, |
1026 | &gen); | | 1026 | &gen); |
1027 | if (error == 0 && gen != defh.defid_gen) | | 1027 | if (error == 0 && gen != defh.defid_gen) |
1028 | error = ESTALE; | | 1028 | error = ESTALE; |
1029 | if (error) { | | 1029 | if (error) { |
1030 | *vpp = NULLVP; | | 1030 | *vpp = NULLVP; |
1031 | return error; | | 1031 | return error; |
1032 | } | | 1032 | } |
1033 | error = deget(pmp, defh.defid_dirclust, defh.defid_dirofs, &dep); | | 1033 | error = deget(pmp, defh.defid_dirclust, defh.defid_dirofs, &dep); |
1034 | if (error) { | | 1034 | if (error) { |
1035 | DPRINTF(("deget %d\n", error)); | | 1035 | DPRINTF(("deget %d\n", error)); |
1036 | *vpp = NULLVP; | | 1036 | *vpp = NULLVP; |
1037 | return (error); | | 1037 | return (error); |
1038 | } | | 1038 | } |
1039 | *vpp = DETOV(dep); | | 1039 | *vpp = DETOV(dep); |
1040 | return (0); | | 1040 | return (0); |
1041 | } | | 1041 | } |
1042 | | | 1042 | |
1043 | int | | 1043 | int |
1044 | msdosfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size) | | 1044 | msdosfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size) |
1045 | { | | 1045 | { |
1046 | struct msdosfsmount *pmp = VFSTOMSDOSFS(vp->v_mount); | | 1046 | struct msdosfsmount *pmp = VFSTOMSDOSFS(vp->v_mount); |
1047 | struct denode *dep; | | 1047 | struct denode *dep; |
1048 | struct defid defh; | | 1048 | struct defid defh; |
1049 | int error; | | 1049 | int error; |
1050 | | | 1050 | |
1051 | if (*fh_size < sizeof(struct defid)) { | | 1051 | if (*fh_size < sizeof(struct defid)) { |
1052 | *fh_size = sizeof(struct defid); | | 1052 | *fh_size = sizeof(struct defid); |
1053 | return E2BIG; | | 1053 | return E2BIG; |
1054 | } | | 1054 | } |
1055 | *fh_size = sizeof(struct defid); | | 1055 | *fh_size = sizeof(struct defid); |
1056 | dep = VTODE(vp); | | 1056 | dep = VTODE(vp); |
1057 | memset(&defh, 0, sizeof(defh)); | | 1057 | memset(&defh, 0, sizeof(defh)); |
1058 | defh.defid_len = sizeof(struct defid); | | 1058 | defh.defid_len = sizeof(struct defid); |
1059 | defh.defid_dirclust = dep->de_dirclust; | | 1059 | defh.defid_dirclust = dep->de_dirclust; |
1060 | defh.defid_dirofs = dep->de_diroffset; | | 1060 | defh.defid_dirofs = dep->de_diroffset; |
1061 | error = msdosfs_fh_enter(pmp, dep->de_dirclust, dep->de_diroffset, | | 1061 | error = msdosfs_fh_enter(pmp, dep->de_dirclust, dep->de_diroffset, |
1062 | &defh.defid_gen); | | 1062 | &defh.defid_gen); |
1063 | if (error == 0) | | 1063 | if (error == 0) |
1064 | memcpy(fhp, &defh, sizeof(defh)); | | 1064 | memcpy(fhp, &defh, sizeof(defh)); |
1065 | return error; | | 1065 | return error; |
1066 | } | | 1066 | } |
1067 | | | 1067 | |
1068 | int | | 1068 | int |
1069 | msdosfs_vget(struct mount *mp, ino_t ino, | | 1069 | msdosfs_vget(struct mount *mp, ino_t ino, |
1070 | struct vnode **vpp) | | 1070 | struct vnode **vpp) |
1071 | { | | 1071 | { |
1072 | | | 1072 | |
1073 | return (EOPNOTSUPP); | | 1073 | return (EOPNOTSUPP); |
1074 | } | | 1074 | } |
1075 | | | 1075 | |
1076 | int | | 1076 | int |
1077 | msdosfs_suspendctl(struct mount *mp, int cmd) | | 1077 | msdosfs_suspendctl(struct mount *mp, int cmd) |
1078 | { | | 1078 | { |
1079 | int error; | | 1079 | int error; |
1080 | struct lwp *l = curlwp; | | 1080 | struct lwp *l = curlwp; |
1081 | | | 1081 | |
1082 | switch (cmd) { | | 1082 | switch (cmd) { |
1083 | case SUSPEND_SUSPEND: | | 1083 | case SUSPEND_SUSPEND: |
1084 | if ((error = fstrans_setstate(mp, FSTRANS_SUSPENDING)) != 0) | | 1084 | if ((error = fstrans_setstate(mp, FSTRANS_SUSPENDING)) != 0) |
1085 | return error; | | 1085 | return error; |
1086 | error = msdosfs_sync(mp, MNT_WAIT, l->l_proc->p_cred); | | 1086 | error = msdosfs_sync(mp, MNT_WAIT, l->l_proc->p_cred); |
1087 | if (error == 0) | | 1087 | if (error == 0) |
1088 | error = fstrans_setstate(mp, FSTRANS_SUSPENDED); | | 1088 | error = fstrans_setstate(mp, FSTRANS_SUSPENDED); |
1089 | if (error != 0) { | | 1089 | if (error != 0) { |
1090 | (void) fstrans_setstate(mp, FSTRANS_NORMAL); | | 1090 | (void) fstrans_setstate(mp, FSTRANS_NORMAL); |
1091 | return error; | | 1091 | return error; |
1092 | } | | 1092 | } |
1093 | return 0; | | 1093 | return 0; |
1094 | | | 1094 | |
1095 | case SUSPEND_RESUME: | | 1095 | case SUSPEND_RESUME: |
1096 | return fstrans_setstate(mp, FSTRANS_NORMAL); | | 1096 | return fstrans_setstate(mp, FSTRANS_NORMAL); |
1097 | | | 1097 | |
1098 | default: | | 1098 | default: |
1099 | return EINVAL; | | 1099 | return EINVAL; |
1100 | } | | 1100 | } |
1101 | } | | 1101 | } |