ext2fs_vfsops.c revision 1.106 1 /* $NetBSD: ext2fs_vfsops.c,v 1.106 2007/01/04 16:55:29 elad Exp $ */
2
3 /*
4 * Copyright (c) 1989, 1991, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)ffs_vfsops.c 8.14 (Berkeley) 11/28/94
32 * Modified for ext2fs by Manuel Bouyer.
33 */
34
35 /*
36 * Copyright (c) 1997 Manuel Bouyer.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by Manuel Bouyer.
49 * 4. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 *
63 * @(#)ffs_vfsops.c 8.14 (Berkeley) 11/28/94
64 * Modified for ext2fs by Manuel Bouyer.
65 */
66
67 #include <sys/cdefs.h>
68 __KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.106 2007/01/04 16:55:29 elad Exp $");
69
70 #if defined(_KERNEL_OPT)
71 #include "opt_compat_netbsd.h"
72 #endif
73
74 #include <sys/param.h>
75 #include <sys/systm.h>
76 #include <sys/sysctl.h>
77 #include <sys/namei.h>
78 #include <sys/proc.h>
79 #include <sys/kernel.h>
80 #include <sys/vnode.h>
81 #include <sys/socket.h>
82 #include <sys/mount.h>
83 #include <sys/buf.h>
84 #include <sys/device.h>
85 #include <sys/mbuf.h>
86 #include <sys/file.h>
87 #include <sys/disklabel.h>
88 #include <sys/ioctl.h>
89 #include <sys/errno.h>
90 #include <sys/malloc.h>
91 #include <sys/pool.h>
92 #include <sys/lock.h>
93 #include <sys/conf.h>
94 #include <sys/kauth.h>
95
96 #include <miscfs/specfs/specdev.h>
97
98 #include <ufs/ufs/quota.h>
99 #include <ufs/ufs/ufsmount.h>
100 #include <ufs/ufs/inode.h>
101 #include <ufs/ufs/dir.h>
102 #include <ufs/ufs/ufs_extern.h>
103
104 #include <ufs/ext2fs/ext2fs.h>
105 #include <ufs/ext2fs/ext2fs_dir.h>
106 #include <ufs/ext2fs/ext2fs_extern.h>
107
108 extern struct lock ufs_hashlock;
109
110 int ext2fs_sbupdate(struct ufsmount *, int);
111 static int ext2fs_checksb(struct ext2fs *, int);
112
113 extern const struct vnodeopv_desc ext2fs_vnodeop_opv_desc;
114 extern const struct vnodeopv_desc ext2fs_specop_opv_desc;
115 extern const struct vnodeopv_desc ext2fs_fifoop_opv_desc;
116
117 const struct vnodeopv_desc * const ext2fs_vnodeopv_descs[] = {
118 &ext2fs_vnodeop_opv_desc,
119 &ext2fs_specop_opv_desc,
120 &ext2fs_fifoop_opv_desc,
121 NULL,
122 };
123
124 struct vfsops ext2fs_vfsops = {
125 MOUNT_EXT2FS,
126 ext2fs_mount,
127 ufs_start,
128 ext2fs_unmount,
129 ufs_root,
130 ufs_quotactl,
131 ext2fs_statvfs,
132 ext2fs_sync,
133 ext2fs_vget,
134 ext2fs_fhtovp,
135 ext2fs_vptofh,
136 ext2fs_init,
137 ext2fs_reinit,
138 ext2fs_done,
139 ext2fs_mountroot,
140 (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
141 vfs_stdextattrctl,
142 ext2fs_vnodeopv_descs,
143 0,
144 { NULL, NULL },
145 };
146 VFS_ATTACH(ext2fs_vfsops);
147
148 static const struct genfs_ops ext2fs_genfsops = {
149 .gop_size = genfs_size,
150 .gop_alloc = ext2fs_gop_alloc,
151 .gop_write = genfs_gop_write,
152 .gop_markupdate = ufs_gop_markupdate,
153 };
154
155 static const struct ufs_ops ext2fs_ufsops = {
156 .uo_itimes = ext2fs_itimes,
157 .uo_update = ext2fs_update,
158 };
159
160 /*
161 * XXX Same structure as FFS inodes? Should we share a common pool?
162 */
163 POOL_INIT(ext2fs_inode_pool, sizeof(struct inode), 0, 0, 0, "ext2fsinopl",
164 &pool_allocator_nointr);
165 POOL_INIT(ext2fs_dinode_pool, sizeof(struct ext2fs_dinode), 0, 0, 0,
166 "ext2dinopl", &pool_allocator_nointr);
167
168 extern u_long ext2gennumber;
169
170 void
171 ext2fs_init(void)
172 {
173 #ifdef _LKM
174 pool_init(&ext2fs_inode_pool, sizeof(struct inode), 0, 0, 0,
175 "ext2fsinopl", &pool_allocator_nointr);
176 pool_init(&ext2fs_dinode_pool, sizeof(struct ext2fs_dinode), 0, 0, 0,
177 "ext2dinopl", &pool_allocator_nointr);
178 #endif
179 ufs_init();
180 }
181
182 void
183 ext2fs_reinit(void)
184 {
185 ufs_reinit();
186 }
187
188 void
189 ext2fs_done(void)
190 {
191 ufs_done();
192 #ifdef _LKM
193 pool_destroy(&ext2fs_inode_pool);
194 pool_destroy(&ext2fs_dinode_pool);
195 #endif
196 }
197
198 /*
199 * Called by main() when ext2fs is going to be mounted as root.
200 *
201 * Name is updated by mount(8) after booting.
202 */
203 #define ROOTNAME "root_device"
204
205 int
206 ext2fs_mountroot(void)
207 {
208 extern struct vnode *rootvp;
209 struct m_ext2fs *fs;
210 struct mount *mp;
211 struct lwp *l = curlwp; /* XXX */
212 struct ufsmount *ump;
213 int error;
214
215 if (device_class(root_device) != DV_DISK)
216 return (ENODEV);
217
218 if ((error = vfs_rootmountalloc(MOUNT_EXT2FS, "root_device", &mp))) {
219 vrele(rootvp);
220 return (error);
221 }
222
223 if ((error = ext2fs_mountfs(rootvp, mp, l)) != 0) {
224 mp->mnt_op->vfs_refcount--;
225 vfs_unbusy(mp);
226 free(mp, M_MOUNT);
227 return (error);
228 }
229 simple_lock(&mountlist_slock);
230 CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
231 simple_unlock(&mountlist_slock);
232 ump = VFSTOUFS(mp);
233 fs = ump->um_e2fs;
234 memset(fs->e2fs_fsmnt, 0, sizeof(fs->e2fs_fsmnt));
235 (void) copystr(mp->mnt_stat.f_mntonname, fs->e2fs_fsmnt,
236 sizeof(fs->e2fs_fsmnt) - 1, 0);
237 if (fs->e2fs.e2fs_rev > E2FS_REV0) {
238 memset(fs->e2fs.e2fs_fsmnt, 0, sizeof(fs->e2fs.e2fs_fsmnt));
239 (void) copystr(mp->mnt_stat.f_mntonname, fs->e2fs.e2fs_fsmnt,
240 sizeof(fs->e2fs.e2fs_fsmnt) - 1, 0);
241 }
242 (void)ext2fs_statvfs(mp, &mp->mnt_stat, l);
243 vfs_unbusy(mp);
244 setrootfstime((time_t)fs->e2fs.e2fs_wtime);
245 return (0);
246 }
247
248 /*
249 * VFS Operations.
250 *
251 * mount system call
252 */
253 int
254 ext2fs_mount(struct mount *mp, const char *path, void *data,
255 struct nameidata *ndp, struct lwp *l)
256 {
257 struct vnode *devvp;
258 struct ufs_args args;
259 struct ufsmount *ump = NULL;
260 struct m_ext2fs *fs;
261 size_t size;
262 int error, flags, update;
263 mode_t accessmode;
264
265 if (mp->mnt_flag & MNT_GETARGS) {
266 ump = VFSTOUFS(mp);
267 if (ump == NULL)
268 return EIO;
269 args.fspec = NULL;
270 return copyout(&args, data, sizeof(args));
271 }
272 error = copyin(data, &args, sizeof (struct ufs_args));
273 if (error)
274 return (error);
275
276 update = mp->mnt_flag & MNT_UPDATE;
277
278 /* Check arguments */
279 if (args.fspec != NULL) {
280 /*
281 * Look up the name and verify that it's sane.
282 */
283 NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, l);
284 if ((error = namei(ndp)) != 0)
285 return (error);
286 devvp = ndp->ni_vp;
287
288 if (!update) {
289 /*
290 * Be sure this is a valid block device
291 */
292 if (devvp->v_type != VBLK)
293 error = ENOTBLK;
294 else if (bdevsw_lookup(devvp->v_rdev) == NULL)
295 error = ENXIO;
296 } else {
297 /*
298 * Be sure we're still naming the same device
299 * used for our initial mount
300 */
301 ump = VFSTOUFS(mp);
302 if (devvp != ump->um_devvp)
303 error = EINVAL;
304 }
305 } else {
306 if (!update) {
307 /* New mounts must have a filename for the device */
308 return (EINVAL);
309 } else {
310 ump = VFSTOUFS(mp);
311 devvp = ump->um_devvp;
312 vref(devvp);
313 }
314 }
315
316 /*
317 * If mount by non-root, then verify that user has necessary
318 * permissions on the device.
319 */
320 if (error == 0 && kauth_authorize_generic(l->l_cred,
321 KAUTH_GENERIC_ISSUSER, NULL) != 0) {
322 accessmode = VREAD;
323 if (update ?
324 (mp->mnt_iflag & IMNT_WANTRDWR) != 0 :
325 (mp->mnt_flag & MNT_RDONLY) == 0)
326 accessmode |= VWRITE;
327 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
328 error = VOP_ACCESS(devvp, accessmode, l->l_cred, l);
329 VOP_UNLOCK(devvp, 0);
330 }
331
332 if (error) {
333 vrele(devvp);
334 return (error);
335 }
336
337 if (!update) {
338 int xflags;
339
340 /*
341 * Disallow multiple mounts of the same device.
342 * Disallow mounting of a device that is currently in use
343 * (except for root, which might share swap device for
344 * miniroot).
345 */
346 error = vfs_mountedon(devvp);
347 if (error)
348 goto fail;
349 if (vcount(devvp) > 1 && devvp != rootvp) {
350 error = EBUSY;
351 goto fail;
352 }
353 if (mp->mnt_flag & MNT_RDONLY)
354 xflags = FREAD;
355 else
356 xflags = FREAD|FWRITE;
357 error = VOP_OPEN(devvp, xflags, FSCRED, l);
358 if (error)
359 goto fail;
360 error = ext2fs_mountfs(devvp, mp, l);
361 if (error) {
362 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
363 (void)VOP_CLOSE(devvp, xflags, NOCRED, l);
364 VOP_UNLOCK(devvp, 0);
365 goto fail;
366 }
367
368 ump = VFSTOUFS(mp);
369 fs = ump->um_e2fs;
370 } else {
371 /*
372 * Update the mount.
373 */
374
375 /*
376 * The initial mount got a reference on this
377 * device, so drop the one obtained via
378 * namei(), above.
379 */
380 vrele(devvp);
381
382 ump = VFSTOUFS(mp);
383 fs = ump->um_e2fs;
384 if (fs->e2fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
385 /*
386 * Changing from r/w to r/o
387 */
388 flags = WRITECLOSE;
389 if (mp->mnt_flag & MNT_FORCE)
390 flags |= FORCECLOSE;
391 error = ext2fs_flushfiles(mp, flags, l);
392 if (error == 0 &&
393 ext2fs_cgupdate(ump, MNT_WAIT) == 0 &&
394 (fs->e2fs.e2fs_state & E2FS_ERRORS) == 0) {
395 fs->e2fs.e2fs_state = E2FS_ISCLEAN;
396 (void) ext2fs_sbupdate(ump, MNT_WAIT);
397 }
398 if (error)
399 return (error);
400 fs->e2fs_ronly = 1;
401 }
402
403 if (mp->mnt_flag & MNT_RELOAD) {
404 error = ext2fs_reload(mp, ndp->ni_cnd.cn_cred, l);
405 if (error)
406 return (error);
407 }
408
409 if (fs->e2fs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR)) {
410 /*
411 * Changing from read-only to read/write
412 */
413 fs->e2fs_ronly = 0;
414 if (fs->e2fs.e2fs_state == E2FS_ISCLEAN)
415 fs->e2fs.e2fs_state = 0;
416 else
417 fs->e2fs.e2fs_state = E2FS_ERRORS;
418 fs->e2fs_fmod = 1;
419 }
420 if (args.fspec == NULL)
421 return EINVAL;
422 }
423
424 error = set_statvfs_info(path, UIO_USERSPACE, args.fspec,
425 UIO_USERSPACE, mp, l);
426 (void) copystr(mp->mnt_stat.f_mntonname, fs->e2fs_fsmnt,
427 sizeof(fs->e2fs_fsmnt) - 1, &size);
428 memset(fs->e2fs_fsmnt + size, 0, sizeof(fs->e2fs_fsmnt) - size);
429 if (fs->e2fs.e2fs_rev > E2FS_REV0) {
430 (void) copystr(mp->mnt_stat.f_mntonname, fs->e2fs.e2fs_fsmnt,
431 sizeof(fs->e2fs.e2fs_fsmnt) - 1, &size);
432 memset(fs->e2fs.e2fs_fsmnt, 0,
433 sizeof(fs->e2fs.e2fs_fsmnt) - size);
434 }
435 if (fs->e2fs_fmod != 0) { /* XXX */
436 fs->e2fs_fmod = 0;
437 if (fs->e2fs.e2fs_state == 0)
438 fs->e2fs.e2fs_wtime = time_second;
439 else
440 printf("%s: file system not clean; please fsck(8)\n",
441 mp->mnt_stat.f_mntfromname);
442 (void) ext2fs_cgupdate(ump, MNT_WAIT);
443 }
444 return (error);
445
446 fail:
447 vrele(devvp);
448 return (error);
449 }
450
451 /*
452 * Reload all incore data for a filesystem (used after running fsck on
453 * the root filesystem and finding things to fix). The filesystem must
454 * be mounted read-only.
455 *
456 * Things to do to update the mount:
457 * 1) invalidate all cached meta-data.
458 * 2) re-read superblock from disk.
459 * 3) re-read summary information from disk.
460 * 4) invalidate all inactive vnodes.
461 * 5) invalidate all cached file data.
462 * 6) re-read inode data for all active vnodes.
463 */
464 int
465 ext2fs_reload(struct mount *mountp, kauth_cred_t cred, struct lwp *l)
466 {
467 struct vnode *vp, *nvp, *devvp;
468 struct inode *ip;
469 struct buf *bp;
470 struct m_ext2fs *fs;
471 struct ext2fs *newfs;
472 struct partinfo dpart;
473 int i, size, error;
474 caddr_t cp;
475
476 if ((mountp->mnt_flag & MNT_RDONLY) == 0)
477 return (EINVAL);
478 /*
479 * Step 1: invalidate all cached meta-data.
480 */
481 devvp = VFSTOUFS(mountp)->um_devvp;
482 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
483 error = vinvalbuf(devvp, 0, cred, l, 0, 0);
484 VOP_UNLOCK(devvp, 0);
485 if (error)
486 panic("ext2fs_reload: dirty1");
487 /*
488 * Step 2: re-read superblock from disk.
489 */
490 if (VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, NOCRED, l) != 0)
491 size = DEV_BSIZE;
492 else
493 size = dpart.disklab->d_secsize;
494 error = bread(devvp, (daddr_t)(SBOFF / size), SBSIZE, NOCRED, &bp);
495 if (error) {
496 brelse(bp);
497 return (error);
498 }
499 newfs = (struct ext2fs *)bp->b_data;
500 error = ext2fs_checksb(newfs, (mountp->mnt_flag & MNT_RDONLY) != 0);
501 if (error) {
502 brelse(bp);
503 return (error);
504 }
505
506 fs = VFSTOUFS(mountp)->um_e2fs;
507 /*
508 * copy in new superblock, and compute in-memory values
509 */
510 e2fs_sbload(newfs, &fs->e2fs);
511 fs->e2fs_ncg =
512 howmany(fs->e2fs.e2fs_bcount - fs->e2fs.e2fs_first_dblock,
513 fs->e2fs.e2fs_bpg);
514 /* XXX assume hw bsize = 512 */
515 fs->e2fs_fsbtodb = fs->e2fs.e2fs_log_bsize + 1;
516 fs->e2fs_bsize = 1024 << fs->e2fs.e2fs_log_bsize;
517 fs->e2fs_bshift = LOG_MINBSIZE + fs->e2fs.e2fs_log_bsize;
518 fs->e2fs_qbmask = fs->e2fs_bsize - 1;
519 fs->e2fs_bmask = ~fs->e2fs_qbmask;
520 fs->e2fs_ngdb = howmany(fs->e2fs_ncg,
521 fs->e2fs_bsize / sizeof(struct ext2_gd));
522 fs->e2fs_ipb = fs->e2fs_bsize / EXT2_DINODE_SIZE;
523 fs->e2fs_itpg = fs->e2fs.e2fs_ipg/fs->e2fs_ipb;
524
525 /*
526 * Step 3: re-read summary information from disk.
527 */
528
529 for (i=0; i < fs->e2fs_ngdb; i++) {
530 error = bread(devvp ,
531 fsbtodb(fs, ((fs->e2fs_bsize>1024)? 0 : 1) + i + 1),
532 fs->e2fs_bsize, NOCRED, &bp);
533 if (error) {
534 brelse(bp);
535 return (error);
536 }
537 e2fs_cgload((struct ext2_gd*)bp->b_data,
538 &fs->e2fs_gd[i* fs->e2fs_bsize / sizeof(struct ext2_gd)],
539 fs->e2fs_bsize);
540 brelse(bp);
541 }
542
543 loop:
544 /*
545 * NOTE: not using the TAILQ_FOREACH here since in this loop vgone()
546 * and vclean() can be called indirectly
547 */
548 simple_lock(&mntvnode_slock);
549 for (vp = TAILQ_FIRST(&mountp->mnt_vnodelist); vp; vp = nvp) {
550 if (vp->v_mount != mountp) {
551 simple_unlock(&mntvnode_slock);
552 goto loop;
553 }
554 /*
555 * Step 4: invalidate all inactive vnodes.
556 */
557 if (vrecycle(vp, &mntvnode_slock, l))
558 goto loop;
559 /*
560 * Step 5: invalidate all cached file data.
561 */
562 simple_lock(&vp->v_interlock);
563 nvp = TAILQ_NEXT(vp, v_mntvnodes);
564 simple_unlock(&mntvnode_slock);
565 if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK))
566 goto loop;
567 if (vinvalbuf(vp, 0, cred, l, 0, 0))
568 panic("ext2fs_reload: dirty2");
569 /*
570 * Step 6: re-read inode data for all active vnodes.
571 */
572 ip = VTOI(vp);
573 error = bread(devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
574 (int)fs->e2fs_bsize, NOCRED, &bp);
575 if (error) {
576 vput(vp);
577 return (error);
578 }
579 cp = (caddr_t)bp->b_data +
580 (ino_to_fsbo(fs, ip->i_number) * EXT2_DINODE_SIZE);
581 e2fs_iload((struct ext2fs_dinode *)cp, ip->i_din.e2fs_din);
582 brelse(bp);
583 vput(vp);
584 simple_lock(&mntvnode_slock);
585 }
586 simple_unlock(&mntvnode_slock);
587 return (0);
588 }
589
590 /*
591 * Common code for mount and mountroot
592 */
593 int
594 ext2fs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l)
595 {
596 struct ufsmount *ump;
597 struct buf *bp;
598 struct ext2fs *fs;
599 struct m_ext2fs *m_fs;
600 dev_t dev;
601 struct partinfo dpart;
602 int error, i, size, ronly;
603 kauth_cred_t cred;
604 struct proc *p;
605
606 dev = devvp->v_rdev;
607 p = l ? l->l_proc : NULL;
608 cred = l ? l->l_cred : NOCRED;
609
610 /* Flush out any old buffers remaining from a previous use. */
611 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
612 error = vinvalbuf(devvp, V_SAVE, cred, l, 0, 0);
613 VOP_UNLOCK(devvp, 0);
614 if (error)
615 return (error);
616
617 ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
618 if (VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, cred, l) != 0)
619 size = DEV_BSIZE;
620 else
621 size = dpart.disklab->d_secsize;
622
623 bp = NULL;
624 ump = NULL;
625
626 #ifdef DEBUG_EXT2
627 printf("sb size: %d ino size %d\n", sizeof(struct ext2fs),
628 EXT2_DINODE_SIZE);
629 #endif
630 error = bread(devvp, (SBOFF / size), SBSIZE, cred, &bp);
631 if (error)
632 goto out;
633 fs = (struct ext2fs *)bp->b_data;
634 error = ext2fs_checksb(fs, ronly);
635 if (error)
636 goto out;
637 ump = malloc(sizeof *ump, M_UFSMNT, M_WAITOK);
638 memset(ump, 0, sizeof *ump);
639 ump->um_fstype = UFS1;
640 ump->um_ops = &ext2fs_ufsops;
641 ump->um_e2fs = malloc(sizeof(struct m_ext2fs), M_UFSMNT, M_WAITOK);
642 memset(ump->um_e2fs, 0, sizeof(struct m_ext2fs));
643 e2fs_sbload((struct ext2fs*)bp->b_data, &ump->um_e2fs->e2fs);
644 brelse(bp);
645 bp = NULL;
646 m_fs = ump->um_e2fs;
647 m_fs->e2fs_ronly = ronly;
648 if (ronly == 0) {
649 if (m_fs->e2fs.e2fs_state == E2FS_ISCLEAN)
650 m_fs->e2fs.e2fs_state = 0;
651 else
652 m_fs->e2fs.e2fs_state = E2FS_ERRORS;
653 m_fs->e2fs_fmod = 1;
654 }
655
656 /* compute dynamic sb infos */
657 m_fs->e2fs_ncg =
658 howmany(m_fs->e2fs.e2fs_bcount - m_fs->e2fs.e2fs_first_dblock,
659 m_fs->e2fs.e2fs_bpg);
660 /* XXX assume hw bsize = 512 */
661 m_fs->e2fs_fsbtodb = m_fs->e2fs.e2fs_log_bsize + 1;
662 m_fs->e2fs_bsize = 1024 << m_fs->e2fs.e2fs_log_bsize;
663 m_fs->e2fs_bshift = LOG_MINBSIZE + m_fs->e2fs.e2fs_log_bsize;
664 m_fs->e2fs_qbmask = m_fs->e2fs_bsize - 1;
665 m_fs->e2fs_bmask = ~m_fs->e2fs_qbmask;
666 m_fs->e2fs_ngdb = howmany(m_fs->e2fs_ncg,
667 m_fs->e2fs_bsize / sizeof(struct ext2_gd));
668 m_fs->e2fs_ipb = m_fs->e2fs_bsize / EXT2_DINODE_SIZE;
669 m_fs->e2fs_itpg = m_fs->e2fs.e2fs_ipg/m_fs->e2fs_ipb;
670
671 m_fs->e2fs_gd = malloc(m_fs->e2fs_ngdb * m_fs->e2fs_bsize,
672 M_UFSMNT, M_WAITOK);
673 for (i=0; i < m_fs->e2fs_ngdb; i++) {
674 error = bread(devvp ,
675 fsbtodb(m_fs, ((m_fs->e2fs_bsize>1024)? 0 : 1) + i + 1),
676 m_fs->e2fs_bsize, NOCRED, &bp);
677 if (error) {
678 free(m_fs->e2fs_gd, M_UFSMNT);
679 goto out;
680 }
681 e2fs_cgload((struct ext2_gd*)bp->b_data,
682 &m_fs->e2fs_gd[
683 i * m_fs->e2fs_bsize / sizeof(struct ext2_gd)],
684 m_fs->e2fs_bsize);
685 brelse(bp);
686 bp = NULL;
687 }
688
689 mp->mnt_data = ump;
690 mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev;
691 mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_EXT2FS);
692 mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
693 mp->mnt_stat.f_namemax = EXT2FS_MAXNAMLEN;
694 mp->mnt_flag |= MNT_LOCAL;
695 mp->mnt_dev_bshift = DEV_BSHIFT; /* XXX */
696 mp->mnt_fs_bshift = m_fs->e2fs_bshift;
697 mp->mnt_iflag |= IMNT_DTYPE;
698 ump->um_flags = 0;
699 ump->um_mountp = mp;
700 ump->um_dev = dev;
701 ump->um_devvp = devvp;
702 ump->um_nindir = NINDIR(m_fs);
703 ump->um_lognindir = ffs(NINDIR(m_fs)) - 1;
704 ump->um_bptrtodb = m_fs->e2fs_fsbtodb;
705 ump->um_seqinc = 1; /* no frags */
706 ump->um_maxsymlinklen = EXT2_MAXSYMLINKLEN;
707 ump->um_dirblksiz = m_fs->e2fs_bsize;
708 ump->um_maxfilesize = ((u_int64_t)0x80000000 * m_fs->e2fs_bsize - 1);
709 devvp->v_specmountpoint = mp;
710 return (0);
711
712 out:
713 KASSERT(bp != NULL);
714 brelse(bp);
715 if (ump) {
716 free(ump->um_e2fs, M_UFSMNT);
717 free(ump, M_UFSMNT);
718 mp->mnt_data = NULL;
719 }
720 return (error);
721 }
722
723 /*
724 * unmount system call
725 */
726 int
727 ext2fs_unmount(struct mount *mp, int mntflags, struct lwp *l)
728 {
729 struct ufsmount *ump;
730 struct m_ext2fs *fs;
731 int error, flags;
732
733 flags = 0;
734 if (mntflags & MNT_FORCE)
735 flags |= FORCECLOSE;
736 if ((error = ext2fs_flushfiles(mp, flags, l)) != 0)
737 return (error);
738 ump = VFSTOUFS(mp);
739 fs = ump->um_e2fs;
740 if (fs->e2fs_ronly == 0 &&
741 ext2fs_cgupdate(ump, MNT_WAIT) == 0 &&
742 (fs->e2fs.e2fs_state & E2FS_ERRORS) == 0) {
743 fs->e2fs.e2fs_state = E2FS_ISCLEAN;
744 (void) ext2fs_sbupdate(ump, MNT_WAIT);
745 }
746 if (ump->um_devvp->v_type != VBAD)
747 ump->um_devvp->v_specmountpoint = NULL;
748 vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY);
749 error = VOP_CLOSE(ump->um_devvp, fs->e2fs_ronly ? FREAD : FREAD|FWRITE,
750 NOCRED, l);
751 vput(ump->um_devvp);
752 free(fs->e2fs_gd, M_UFSMNT);
753 free(fs, M_UFSMNT);
754 free(ump, M_UFSMNT);
755 mp->mnt_data = NULL;
756 mp->mnt_flag &= ~MNT_LOCAL;
757 return (error);
758 }
759
760 /*
761 * Flush out all the files in a filesystem.
762 */
763 int
764 ext2fs_flushfiles(struct mount *mp, int flags, struct lwp *l)
765 {
766 extern int doforce;
767 int error;
768
769 if (!doforce)
770 flags &= ~FORCECLOSE;
771 error = vflush(mp, NULLVP, flags);
772 return (error);
773 }
774
775 /*
776 * Get file system statistics.
777 */
778 int
779 ext2fs_statvfs(struct mount *mp, struct statvfs *sbp, struct lwp *l)
780 {
781 struct ufsmount *ump;
782 struct m_ext2fs *fs;
783 u_int32_t overhead, overhead_per_group;
784 int i, ngroups;
785
786 ump = VFSTOUFS(mp);
787 fs = ump->um_e2fs;
788 if (fs->e2fs.e2fs_magic != E2FS_MAGIC)
789 panic("ext2fs_statvfs");
790
791 /*
792 * Compute the overhead (FS structures)
793 */
794 overhead_per_group = 1 /* block bitmap */ +
795 1 /* inode bitmap */ +
796 fs->e2fs_itpg;
797 overhead = fs->e2fs.e2fs_first_dblock +
798 fs->e2fs_ncg * overhead_per_group;
799 if (fs->e2fs.e2fs_rev > E2FS_REV0 &&
800 fs->e2fs.e2fs_features_rocompat & EXT2F_ROCOMPAT_SPARSESUPER) {
801 for (i = 0, ngroups = 0; i < fs->e2fs_ncg; i++) {
802 if (cg_has_sb(i))
803 ngroups++;
804 }
805 } else {
806 ngroups = fs->e2fs_ncg;
807 }
808 overhead += ngroups * (1 + fs->e2fs_ngdb);
809
810 sbp->f_bsize = fs->e2fs_bsize;
811 sbp->f_frsize = 1024 << fs->e2fs.e2fs_fsize;
812 sbp->f_iosize = fs->e2fs_bsize;
813 sbp->f_blocks = fs->e2fs.e2fs_bcount - overhead;
814 sbp->f_bfree = fs->e2fs.e2fs_fbcount;
815 sbp->f_bresvd = fs->e2fs.e2fs_rbcount;
816 if (sbp->f_bfree > sbp->f_bresvd)
817 sbp->f_bavail = sbp->f_bfree - sbp->f_bresvd;
818 else
819 sbp->f_bavail = 0;
820 sbp->f_files = fs->e2fs.e2fs_icount;
821 sbp->f_ffree = fs->e2fs.e2fs_ficount;
822 sbp->f_favail = fs->e2fs.e2fs_ficount;
823 sbp->f_fresvd = 0;
824 copy_statvfs_info(sbp, mp);
825 return (0);
826 }
827
828 /*
829 * Go through the disk queues to initiate sandbagged IO;
830 * go through the inodes to write those that have been modified;
831 * initiate the writing of the super block if it has been modified.
832 *
833 * Note: we are always called with the filesystem marked `MPBUSY'.
834 */
835 int
836 ext2fs_sync(struct mount *mp, int waitfor, kauth_cred_t cred, struct lwp *l)
837 {
838 struct vnode *vp, *nvp;
839 struct inode *ip;
840 struct ufsmount *ump = VFSTOUFS(mp);
841 struct m_ext2fs *fs;
842 int error, allerror = 0;
843
844 fs = ump->um_e2fs;
845 if (fs->e2fs_fmod != 0 && fs->e2fs_ronly != 0) { /* XXX */
846 printf("fs = %s\n", fs->e2fs_fsmnt);
847 panic("update: rofs mod");
848 }
849 /*
850 * Write back each (modified) inode.
851 */
852 simple_lock(&mntvnode_slock);
853 loop:
854 /*
855 * NOTE: not using the TAILQ_FOREACH here since in this loop vgone()
856 * and vclean() can be called indirectly
857 */
858 for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = nvp) {
859 /*
860 * If the vnode that we are about to sync is no longer
861 * associated with this mount point, start over.
862 */
863 if (vp->v_mount != mp)
864 goto loop;
865 simple_lock(&vp->v_interlock);
866 nvp = TAILQ_NEXT(vp, v_mntvnodes);
867 ip = VTOI(vp);
868 if (vp->v_type == VNON ||
869 ((ip->i_flag &
870 (IN_CHANGE | IN_UPDATE | IN_MODIFIED)) == 0 &&
871 LIST_EMPTY(&vp->v_dirtyblkhd) &&
872 vp->v_uobj.uo_npages == 0))
873 {
874 simple_unlock(&vp->v_interlock);
875 continue;
876 }
877 simple_unlock(&mntvnode_slock);
878 error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK);
879 if (error) {
880 simple_lock(&mntvnode_slock);
881 if (error == ENOENT)
882 goto loop;
883 continue;
884 }
885 if (vp->v_type == VREG && waitfor == MNT_LAZY)
886 error = ext2fs_update(vp, NULL, NULL, 0);
887 else
888 error = VOP_FSYNC(vp, cred,
889 waitfor == MNT_WAIT ? FSYNC_WAIT : 0, 0, 0, l);
890 if (error)
891 allerror = error;
892 vput(vp);
893 simple_lock(&mntvnode_slock);
894 }
895 simple_unlock(&mntvnode_slock);
896 /*
897 * Force stale file system control information to be flushed.
898 */
899 if (waitfor != MNT_LAZY) {
900 vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY);
901 if ((error = VOP_FSYNC(ump->um_devvp, cred,
902 waitfor == MNT_WAIT ? FSYNC_WAIT : 0, 0, 0, l)) != 0)
903 allerror = error;
904 VOP_UNLOCK(ump->um_devvp, 0);
905 }
906 /*
907 * Write back modified superblock.
908 */
909 if (fs->e2fs_fmod != 0) {
910 fs->e2fs_fmod = 0;
911 fs->e2fs.e2fs_wtime = time_second;
912 if ((error = ext2fs_cgupdate(ump, waitfor)))
913 allerror = error;
914 }
915 return (allerror);
916 }
917
918 /*
919 * Look up a EXT2FS dinode number to find its incore vnode, otherwise read it
920 * in from disk. If it is in core, wait for the lock bit to clear, then
921 * return the inode locked. Detection and handling of mount points must be
922 * done by the calling routine.
923 */
924 int
925 ext2fs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
926 {
927 struct m_ext2fs *fs;
928 struct inode *ip;
929 struct ufsmount *ump;
930 struct buf *bp;
931 struct vnode *vp;
932 dev_t dev;
933 int error;
934 caddr_t cp;
935
936 ump = VFSTOUFS(mp);
937 dev = ump->um_dev;
938
939 if ((*vpp = ufs_ihashget(dev, ino, LK_EXCLUSIVE)) != NULL)
940 return (0);
941
942 /* Allocate a new vnode/inode. */
943 if ((error = getnewvnode(VT_EXT2FS, mp, ext2fs_vnodeop_p, &vp)) != 0) {
944 *vpp = NULL;
945 return (error);
946 }
947
948 do {
949 if ((*vpp = ufs_ihashget(dev, ino, LK_EXCLUSIVE)) != NULL) {
950 ungetnewvnode(vp);
951 return (0);
952 }
953 } while (lockmgr(&ufs_hashlock, LK_EXCLUSIVE|LK_SLEEPFAIL, 0));
954
955 vp->v_flag |= VLOCKSWORK;
956
957 ip = pool_get(&ext2fs_inode_pool, PR_WAITOK);
958 memset(ip, 0, sizeof(struct inode));
959 vp->v_data = ip;
960 ip->i_vnode = vp;
961 ip->i_ump = ump;
962 ip->i_e2fs = fs = ump->um_e2fs;
963 ip->i_dev = dev;
964 ip->i_number = ino;
965 ip->i_e2fs_last_lblk = 0;
966 ip->i_e2fs_last_blk = 0;
967
968 /*
969 * Put it onto its hash chain and lock it so that other requests for
970 * this inode will block if they arrive while we are sleeping waiting
971 * for old data structures to be purged or for the contents of the
972 * disk portion of this inode to be read.
973 */
974
975 ufs_ihashins(ip);
976 lockmgr(&ufs_hashlock, LK_RELEASE, 0);
977
978 /* Read in the disk contents for the inode, copy into the inode. */
979 error = bread(ump->um_devvp, fsbtodb(fs, ino_to_fsba(fs, ino)),
980 (int)fs->e2fs_bsize, NOCRED, &bp);
981 if (error) {
982
983 /*
984 * The inode does not contain anything useful, so it would
985 * be misleading to leave it on its hash chain. With mode
986 * still zero, it will be unlinked and returned to the free
987 * list by vput().
988 */
989
990 vput(vp);
991 brelse(bp);
992 *vpp = NULL;
993 return (error);
994 }
995 cp = (caddr_t)bp->b_data +
996 (ino_to_fsbo(fs, ino) * EXT2_DINODE_SIZE);
997 ip->i_din.e2fs_din = pool_get(&ext2fs_dinode_pool, PR_WAITOK);
998 e2fs_iload((struct ext2fs_dinode *)cp, ip->i_din.e2fs_din);
999 brelse(bp);
1000
1001 /* If the inode was deleted, reset all fields */
1002 if (ip->i_e2fs_dtime != 0) {
1003 ip->i_e2fs_mode = ip->i_e2fs_nblock = 0;
1004 (void)ext2fs_setsize(ip, 0);
1005 memset(ip->i_e2fs_blocks, 0, sizeof(ip->i_e2fs_blocks));
1006 }
1007
1008 /*
1009 * Initialize the vnode from the inode, check for aliases.
1010 * Note that the underlying vnode may have changed.
1011 */
1012
1013 error = ext2fs_vinit(mp, ext2fs_specop_p, ext2fs_fifoop_p, &vp);
1014 if (error) {
1015 vput(vp);
1016 *vpp = NULL;
1017 return (error);
1018 }
1019 /*
1020 * Finish inode initialization now that aliasing has been resolved.
1021 */
1022
1023 genfs_node_init(vp, &ext2fs_genfsops);
1024 ip->i_devvp = ump->um_devvp;
1025 VREF(ip->i_devvp);
1026
1027 /*
1028 * Set up a generation number for this inode if it does not
1029 * already have one. This should only happen on old filesystems.
1030 */
1031
1032 if (ip->i_e2fs_gen == 0) {
1033 if (++ext2gennumber < (u_long)time_second)
1034 ext2gennumber = time_second;
1035 ip->i_e2fs_gen = ext2gennumber;
1036 if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
1037 ip->i_flag |= IN_MODIFIED;
1038 }
1039 vp->v_size = ext2fs_size(ip);
1040 *vpp = vp;
1041 return (0);
1042 }
1043
1044 /*
1045 * File handle to vnode
1046 *
1047 * Have to be really careful about stale file handles:
1048 * - check that the inode number is valid
1049 * - call ext2fs_vget() to get the locked inode
1050 * - check for an unallocated inode (i_mode == 0)
1051 */
1052 int
1053 ext2fs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
1054 {
1055 struct inode *ip;
1056 struct vnode *nvp;
1057 int error;
1058 struct ufid ufh;
1059 struct m_ext2fs *fs;
1060
1061 if (fhp->fid_len != sizeof(struct ufid))
1062 return EINVAL;
1063
1064 memcpy(&ufh, fhp, sizeof(struct ufid));
1065 fs = VFSTOUFS(mp)->um_e2fs;
1066 if ((ufh.ufid_ino < EXT2_FIRSTINO && ufh.ufid_ino != EXT2_ROOTINO) ||
1067 ufh.ufid_ino >= fs->e2fs_ncg * fs->e2fs.e2fs_ipg)
1068 return (ESTALE);
1069
1070 if ((error = VFS_VGET(mp, ufh.ufid_ino, &nvp)) != 0) {
1071 *vpp = NULLVP;
1072 return (error);
1073 }
1074 ip = VTOI(nvp);
1075 if (ip->i_e2fs_mode == 0 || ip->i_e2fs_dtime != 0 ||
1076 ip->i_e2fs_gen != ufh.ufid_gen) {
1077 vput(nvp);
1078 *vpp = NULLVP;
1079 return (ESTALE);
1080 }
1081 *vpp = nvp;
1082 return (0);
1083 }
1084
1085 /*
1086 * Vnode pointer to File handle
1087 */
1088 /* ARGSUSED */
1089 int
1090 ext2fs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
1091 {
1092 struct inode *ip;
1093 struct ufid ufh;
1094
1095 if (*fh_size < sizeof(struct ufid)) {
1096 *fh_size = sizeof(struct ufid);
1097 return E2BIG;
1098 }
1099 *fh_size = sizeof(struct ufid);
1100
1101 ip = VTOI(vp);
1102 memset(&ufh, 0, sizeof(ufh));
1103 ufh.ufid_len = sizeof(struct ufid);
1104 ufh.ufid_ino = ip->i_number;
1105 ufh.ufid_gen = ip->i_e2fs_gen;
1106 memcpy(fhp, &ufh, sizeof(ufh));
1107 return (0);
1108 }
1109
1110 SYSCTL_SETUP(sysctl_vfs_ext2fs_setup, "sysctl vfs.ext2fs subtree setup")
1111 {
1112
1113 sysctl_createv(clog, 0, NULL, NULL,
1114 CTLFLAG_PERMANENT,
1115 CTLTYPE_NODE, "vfs", NULL,
1116 NULL, 0, NULL, 0,
1117 CTL_VFS, CTL_EOL);
1118 sysctl_createv(clog, 0, NULL, NULL,
1119 CTLFLAG_PERMANENT,
1120 CTLTYPE_NODE, "ext2fs",
1121 SYSCTL_DESCR("Linux EXT2FS file system"),
1122 NULL, 0, NULL, 0,
1123 CTL_VFS, 17, CTL_EOL);
1124 /*
1125 * XXX the "17" above could be dynamic, thereby eliminating
1126 * one more instance of the "number to vfs" mapping problem,
1127 * but "17" is the order as taken from sys/mount.h
1128 */
1129 }
1130
1131 /*
1132 * Write a superblock and associated information back to disk.
1133 */
1134 int
1135 ext2fs_sbupdate(struct ufsmount *mp, int waitfor)
1136 {
1137 struct m_ext2fs *fs = mp->um_e2fs;
1138 struct buf *bp;
1139 int error = 0;
1140
1141 bp = getblk(mp->um_devvp, SBLOCK, SBSIZE, 0, 0);
1142 e2fs_sbsave(&fs->e2fs, (struct ext2fs*)bp->b_data);
1143 if (waitfor == MNT_WAIT)
1144 error = bwrite(bp);
1145 else
1146 bawrite(bp);
1147 return (error);
1148 }
1149
1150 int
1151 ext2fs_cgupdate(struct ufsmount *mp, int waitfor)
1152 {
1153 struct m_ext2fs *fs = mp->um_e2fs;
1154 struct buf *bp;
1155 int i, error = 0, allerror = 0;
1156
1157 allerror = ext2fs_sbupdate(mp, waitfor);
1158 for (i = 0; i < fs->e2fs_ngdb; i++) {
1159 bp = getblk(mp->um_devvp, fsbtodb(fs, ((fs->e2fs_bsize>1024)?0:1)+i+1),
1160 fs->e2fs_bsize, 0, 0);
1161 e2fs_cgsave(&fs->e2fs_gd[i* fs->e2fs_bsize / sizeof(struct ext2_gd)],
1162 (struct ext2_gd*)bp->b_data, fs->e2fs_bsize);
1163 if (waitfor == MNT_WAIT)
1164 error = bwrite(bp);
1165 else
1166 bawrite(bp);
1167 }
1168
1169 if (!allerror && error)
1170 allerror = error;
1171 return (allerror);
1172 }
1173
1174 static int
1175 ext2fs_checksb(struct ext2fs *fs, int ronly)
1176 {
1177 if (fs2h16(fs->e2fs_magic) != E2FS_MAGIC) {
1178 return (EINVAL); /* XXX needs translation */
1179 }
1180 if (fs2h32(fs->e2fs_rev) > E2FS_REV1) {
1181 #ifdef DIAGNOSTIC
1182 printf("Ext2 fs: unsupported revision number: %x\n",
1183 fs2h32(fs->e2fs_rev));
1184 #endif
1185 return (EINVAL); /* XXX needs translation */
1186 }
1187 if (fs2h32(fs->e2fs_log_bsize) > 2) { /* block size = 1024|2048|4096 */
1188 #ifdef DIAGNOSTIC
1189 printf("Ext2 fs: bad block size: %d (expected <=2 for ext2 fs)\n",
1190 fs2h32(fs->e2fs_log_bsize));
1191 #endif
1192 return (EINVAL); /* XXX needs translation */
1193 }
1194 if (fs2h32(fs->e2fs_rev) > E2FS_REV0) {
1195 if (fs2h32(fs->e2fs_first_ino) != EXT2_FIRSTINO ||
1196 fs2h16(fs->e2fs_inode_size) != EXT2_DINODE_SIZE) {
1197 printf("Ext2 fs: unsupported inode size\n");
1198 return (EINVAL); /* XXX needs translation */
1199 }
1200 if (fs2h32(fs->e2fs_features_incompat) &
1201 ~EXT2F_INCOMPAT_SUPP) {
1202 printf("Ext2 fs: unsupported optional feature\n");
1203 return (EINVAL); /* XXX needs translation */
1204 }
1205 if (!ronly && fs2h32(fs->e2fs_features_rocompat) &
1206 ~EXT2F_ROCOMPAT_SUPP) {
1207 return (EROFS); /* XXX needs translation */
1208 }
1209 }
1210 return (0);
1211 }
1212