2015-11-19 01:06:25 +03:00
|
|
|
/* $NetBSD: advfsops.c,v 1.75 2015/11/18 22:06:25 phx Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1994-05-11 22:49:06 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994 Christian E. Hopps
|
1996-04-05 09:06:07 +04:00
|
|
|
* Copyright (c) 1996 Matthias Scheler
|
1994-05-11 22:49:06 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Christian E. Hopps.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1998-07-05 12:49:30 +04:00
|
|
|
|
2001-11-13 01:54:03 +03:00
|
|
|
#include <sys/cdefs.h>
|
2015-11-19 01:06:25 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: advfsops.c,v 1.75 2015/11/18 22:06:25 phx Exp $");
|
2001-11-13 01:54:03 +03:00
|
|
|
|
2001-05-30 15:40:35 +04:00
|
|
|
#if defined(_KERNEL_OPT)
|
1998-07-05 12:49:30 +04:00
|
|
|
#include "opt_compat_netbsd.h"
|
|
|
|
#endif
|
|
|
|
|
1994-05-11 22:49:06 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
#include <sys/sysctl.h>
|
1994-05-11 22:49:06 +04:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/mount.h>
|
1994-06-18 00:06:05 +04:00
|
|
|
#include <sys/proc.h>
|
1994-05-11 22:49:06 +04:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/malloc.h>
|
1998-09-01 07:33:26 +04:00
|
|
|
#include <sys/pool.h>
|
1994-05-11 22:49:06 +04:00
|
|
|
#include <sys/disklabel.h>
|
2012-10-03 11:20:50 +04:00
|
|
|
#include <sys/disk.h>
|
2008-01-28 17:31:15 +03:00
|
|
|
#include <miscfs/genfs/genfs.h>
|
1994-05-11 22:49:06 +04:00
|
|
|
#include <miscfs/specfs/specdev.h> /* XXX */
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/buf.h>
|
2002-09-06 17:18:43 +04:00
|
|
|
#include <sys/conf.h>
|
2006-05-15 05:29:02 +04:00
|
|
|
#include <sys/kauth.h>
|
2008-05-10 06:26:09 +04:00
|
|
|
#include <sys/module.h>
|
2002-12-23 20:15:20 +03:00
|
|
|
#include <fs/adosfs/adosfs.h>
|
1994-05-11 22:49:06 +04:00
|
|
|
|
2008-05-10 06:26:09 +04:00
|
|
|
MODULE(MODULE_CLASS_VFS, adosfs, NULL);
|
|
|
|
|
2007-08-01 01:14:15 +04:00
|
|
|
VFS_PROTOS(adosfs);
|
1996-02-09 22:06:38 +03:00
|
|
|
|
2008-06-28 05:34:05 +04:00
|
|
|
static struct sysctllog *adosfs_sysctl_log;
|
|
|
|
|
2009-03-14 17:45:51 +03:00
|
|
|
int adosfs_mountfs(struct vnode *, struct mount *, struct lwp *);
|
|
|
|
int adosfs_loadbitmap(struct adosfsmount *);
|
1998-03-01 05:20:01 +03:00
|
|
|
|
2007-06-30 13:37:53 +04:00
|
|
|
struct pool adosfs_node_pool;
|
1998-09-01 07:33:26 +04:00
|
|
|
|
2007-06-30 13:37:53 +04:00
|
|
|
MALLOC_JUSTDEFINE(M_ANODE, "adosfs anode","adosfs anode structures and tables");
|
2003-02-01 09:23:35 +03:00
|
|
|
|
2005-06-28 13:30:37 +04:00
|
|
|
static const struct genfs_ops adosfs_genfsops = {
|
|
|
|
.gop_size = genfs_size,
|
2001-09-30 22:47:48 +04:00
|
|
|
};
|
|
|
|
|
2009-03-14 17:45:51 +03:00
|
|
|
int (**adosfs_vnodeop_p)(void *);
|
2002-05-14 04:05:56 +04:00
|
|
|
|
1994-05-11 22:49:06 +04:00
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
adosfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
|
1994-05-11 22:49:06 +04:00
|
|
|
{
|
2007-11-26 22:01:26 +03:00
|
|
|
struct lwp *l = curlwp;
|
1995-01-18 12:16:37 +03:00
|
|
|
struct vnode *devvp;
|
2007-07-12 23:35:32 +04:00
|
|
|
struct adosfs_args *args = data;
|
1995-01-18 12:16:37 +03:00
|
|
|
struct adosfsmount *amp;
|
1994-05-11 22:49:06 +04:00
|
|
|
int error;
|
1995-01-18 12:16:37 +03:00
|
|
|
mode_t accessmode;
|
1994-05-11 22:49:06 +04:00
|
|
|
|
2014-04-16 22:55:17 +04:00
|
|
|
if (args == NULL)
|
|
|
|
return EINVAL;
|
2007-07-12 23:35:32 +04:00
|
|
|
if (*data_len < sizeof *args)
|
|
|
|
return EINVAL;
|
|
|
|
|
2002-09-21 22:10:04 +04:00
|
|
|
if (mp->mnt_flag & MNT_GETARGS) {
|
|
|
|
amp = VFSTOADOSFS(mp);
|
|
|
|
if (amp == NULL)
|
|
|
|
return EIO;
|
2007-07-12 23:35:32 +04:00
|
|
|
args->uid = amp->uid;
|
|
|
|
args->gid = amp->gid;
|
|
|
|
args->mask = amp->mask;
|
|
|
|
args->fspec = NULL;
|
|
|
|
*data_len = sizeof *args;
|
|
|
|
return 0;
|
2002-09-21 22:10:04 +04:00
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1995-01-18 12:16:37 +03:00
|
|
|
if ((mp->mnt_flag & MNT_RDONLY) == 0)
|
|
|
|
return (EROFS);
|
Apply the NFS exports list rototill patch:
- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.
Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
2005-09-23 16:10:31 +04:00
|
|
|
|
2007-07-12 23:35:32 +04:00
|
|
|
if ((mp->mnt_flag & MNT_UPDATE) && args->fspec == NULL)
|
Apply the NFS exports list rototill patch:
- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.
Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
2005-09-23 16:10:31 +04:00
|
|
|
return EOPNOTSUPP;
|
|
|
|
|
1995-01-18 12:16:37 +03:00
|
|
|
/*
|
|
|
|
* Not an update, or updating the name: look up the name
|
|
|
|
* and verify that it refers to a sensible block device.
|
1994-05-11 22:49:06 +04:00
|
|
|
*/
|
Convert 67 namei call sites to use namei_simple, in these functions:
check_console, veriexecclose, veriexec_delete, veriexec_file_add,
emul_find_root, coff_load_shlib (sh3 version), coff_load_shlib,
compat_20_sys_statfs, compat_20_netbsd32_statfs,
ELFNAME2(netbsd32,probe_noteless), darwin_sys_statfs,
ibcs2_sys_statfs, ibcs2_sys_statvfs, linux_sys_uselib,
osf1_sys_statfs, sunos_sys_statfs, sunos32_sys_statfs,
ultrix_sys_statfs, do_sys_mount, fss_create_files (3 of 4),
adosfs_mount, cd9660_mount, coda_ioctl, coda_mount, ext2fs_mount,
ffs_mount, filecore_mount, hfs_mount, lfs_mount, msdosfs_mount,
ntfs_mount, sysvbfs_mount, udf_mount, union_mount, sys_chflags,
sys_lchflags, sys_chmod, sys_lchmod, sys_chown, sys_lchown,
sys___posix_chown, sys___posix_lchown, sys_link, do_sys_pstatvfs,
sys_quotactl, sys_revoke, sys_truncate, do_sys_utimes, sys_extattrctl,
sys_extattr_set_file, sys_extattr_set_link, sys_extattr_get_file,
sys_extattr_get_link, sys_extattr_delete_file,
sys_extattr_delete_link, sys_extattr_list_file, sys_extattr_list_link,
sys_setxattr, sys_lsetxattr, sys_getxattr, sys_lgetxattr,
sys_listxattr, sys_llistxattr, sys_removexattr, sys_lremovexattr
All have been scrutinized (several times, in fact) and compile-tested,
but not all have been explicitly tested in action.
XXX: While I haven't (intentionally) changed the use or nonuse of
XXX: TRYEMULROOT in any of these places, I'm not convinced all the
XXX: uses are correct; an audit might be desirable.
2009-06-29 09:08:15 +04:00
|
|
|
error = namei_simple_user(args->fspec,
|
|
|
|
NSM_FOLLOW_NOEMULROOT, &devvp);
|
|
|
|
if (error != 0)
|
1994-06-18 00:06:05 +04:00
|
|
|
return (error);
|
|
|
|
|
1995-01-18 12:16:37 +03:00
|
|
|
if (devvp->v_type != VBLK) {
|
|
|
|
vrele(devvp);
|
1994-06-18 00:06:05 +04:00
|
|
|
return (ENOTBLK);
|
1994-05-11 22:49:06 +04:00
|
|
|
}
|
2002-09-06 17:18:43 +04:00
|
|
|
if (bdevsw_lookup(devvp->v_rdev) == NULL) {
|
1995-01-18 12:16:37 +03:00
|
|
|
vrele(devvp);
|
1994-06-18 00:06:05 +04:00
|
|
|
return (ENXIO);
|
1994-05-11 22:49:06 +04:00
|
|
|
}
|
1995-01-18 12:16:37 +03:00
|
|
|
/*
|
|
|
|
* If mount by non-root, then verify that user has necessary
|
|
|
|
* permissions on the device.
|
|
|
|
*/
|
2009-04-25 22:53:43 +04:00
|
|
|
accessmode = VREAD;
|
|
|
|
if ((mp->mnt_flag & MNT_RDONLY) == 0)
|
|
|
|
accessmode |= VWRITE;
|
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
|
2012-03-13 22:40:26 +04:00
|
|
|
error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
|
|
|
|
KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp, KAUTH_ARG(accessmode));
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(devvp);
|
2009-04-25 22:53:43 +04:00
|
|
|
if (error) {
|
|
|
|
vrele(devvp);
|
|
|
|
return (error);
|
1995-01-18 12:16:37 +03:00
|
|
|
}
|
1995-08-18 19:14:33 +04:00
|
|
|
/* MNT_UPDATE? */
|
2005-12-11 15:16:03 +03:00
|
|
|
if ((error = adosfs_mountfs(devvp, mp, l)) != 0) {
|
1995-01-18 12:16:37 +03:00
|
|
|
vrele(devvp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
amp = VFSTOADOSFS(mp);
|
2007-07-12 23:35:32 +04:00
|
|
|
amp->uid = args->uid;
|
|
|
|
amp->gid = args->gid;
|
|
|
|
amp->mask = args->mask;
|
|
|
|
return set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
|
2007-07-17 15:19:31 +04:00
|
|
|
mp->mnt_op->vfs_name, mp, l);
|
1994-05-11 22:49:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
adosfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l)
|
1994-05-11 22:49:06 +04:00
|
|
|
{
|
|
|
|
struct disklabel dl;
|
|
|
|
struct partition *parp;
|
1995-01-18 12:17:32 +03:00
|
|
|
struct adosfsmount *amp;
|
1996-04-05 09:06:07 +04:00
|
|
|
struct buf *bp;
|
1994-06-18 00:06:05 +04:00
|
|
|
struct vnode *rvp;
|
2011-05-24 02:00:30 +04:00
|
|
|
size_t bitmap_sz = 0;
|
2014-08-05 12:50:54 +04:00
|
|
|
int error;
|
2012-10-03 11:20:50 +04:00
|
|
|
uint64_t numsecs;
|
|
|
|
unsigned secsize;
|
|
|
|
unsigned long secsperblk, blksperdisk, resvblks;
|
1994-05-11 22:49:06 +04:00
|
|
|
|
1994-06-18 00:06:05 +04:00
|
|
|
amp = NULL;
|
1995-01-18 12:16:37 +03:00
|
|
|
|
2008-01-24 20:32:52 +03:00
|
|
|
if ((error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0)) != 0)
|
1994-06-18 00:06:05 +04:00
|
|
|
return (error);
|
1994-05-11 22:49:06 +04:00
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
/*
|
2012-10-03 11:20:50 +04:00
|
|
|
* open blkdev and read boot and root block
|
1994-05-11 22:49:06 +04:00
|
|
|
*/
|
2011-11-14 22:35:12 +04:00
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
if ((error = VOP_OPEN(devvp, FREAD, NOCRED)) != 0) {
|
|
|
|
VOP_UNLOCK(devvp);
|
1994-06-18 00:06:05 +04:00
|
|
|
return (error);
|
2011-11-14 22:35:12 +04:00
|
|
|
}
|
2012-10-03 11:20:50 +04:00
|
|
|
|
|
|
|
error = getdisksize(devvp, &numsecs, &secsize);
|
1996-02-09 22:06:38 +03:00
|
|
|
if (error)
|
1994-05-11 22:49:06 +04:00
|
|
|
goto fail;
|
|
|
|
|
2011-05-24 02:00:30 +04:00
|
|
|
amp = kmem_zalloc(sizeof(struct adosfsmount), KM_SLEEP);
|
2012-10-03 11:20:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* compute filesystem parameters from disklabel
|
|
|
|
* on arch/amiga the disklabel is computed from the native
|
|
|
|
* partition tables
|
|
|
|
* - p_fsize is the filesystem block size
|
|
|
|
* - p_frag is the number of sectors per filesystem block
|
|
|
|
* - p_cpg is the number of reserved blocks (boot blocks)
|
|
|
|
* - p_psize is reduced by the number of preallocated blocks
|
|
|
|
* at the end of a partition
|
|
|
|
*
|
|
|
|
* XXX
|
|
|
|
* - bsize and secsperblk could be computed from the first sector
|
|
|
|
* of the root block
|
|
|
|
* - resvblks (the number of boot blocks) can only be guessed
|
|
|
|
* by scanning for the root block as its position moves
|
|
|
|
* with resvblks
|
|
|
|
*/
|
|
|
|
error = VOP_IOCTL(devvp, DIOCGDINFO, &dl, FREAD, NOCRED);
|
|
|
|
VOP_UNLOCK(devvp);
|
|
|
|
if (error)
|
|
|
|
goto fail;
|
|
|
|
parp = &dl.d_partitions[DISKPART(devvp->v_rdev)];
|
2015-01-02 22:42:05 +03:00
|
|
|
if (dl.d_type == DKTYPE_FLOPPY) {
|
2012-10-03 11:20:50 +04:00
|
|
|
amp->bsize = secsize;
|
|
|
|
secsperblk = 1;
|
|
|
|
resvblks = 2;
|
|
|
|
} else if (parp->p_fsize > 0 && parp->p_frag > 0) {
|
1996-04-05 09:06:07 +04:00
|
|
|
amp->bsize = parp->p_fsize * parp->p_frag;
|
2012-10-03 11:20:50 +04:00
|
|
|
secsperblk = parp->p_frag;
|
|
|
|
resvblks = parp->p_cpg;
|
|
|
|
} else {
|
2000-11-08 11:06:24 +03:00
|
|
|
error = EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-10-03 11:20:50 +04:00
|
|
|
blksperdisk = numsecs / secsperblk;
|
1996-04-05 09:06:07 +04:00
|
|
|
|
2012-10-03 11:20:50 +04:00
|
|
|
|
|
|
|
/* The filesytem variant ('dostype') is stored in the boot block */
|
1996-04-05 09:06:07 +04:00
|
|
|
bp = NULL;
|
|
|
|
if ((error = bread(devvp, (daddr_t)BBOFF,
|
2015-03-28 22:24:04 +03:00
|
|
|
amp->bsize, 0, &bp)) != 0) {
|
1996-04-05 09:06:07 +04:00
|
|
|
goto fail;
|
1999-02-10 16:14:08 +03:00
|
|
|
}
|
1996-04-05 09:06:07 +04:00
|
|
|
amp->dostype = adoswordn(bp, 0);
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(bp, 0);
|
1996-04-05 09:06:07 +04:00
|
|
|
|
2000-11-08 11:06:24 +03:00
|
|
|
/* basic sanity checks */
|
1996-04-05 09:06:07 +04:00
|
|
|
if (amp->dostype < 0x444f5300 || amp->dostype > 0x444f5305) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2012-10-03 11:20:50 +04:00
|
|
|
amp->rootb = (blksperdisk - 1 + resvblks) / 2;
|
|
|
|
amp->numblks = blksperdisk - resvblks;
|
2000-11-08 11:06:24 +03:00
|
|
|
|
1994-05-11 22:49:06 +04:00
|
|
|
amp->nwords = amp->bsize >> 2;
|
1996-04-05 09:06:07 +04:00
|
|
|
amp->dbsize = amp->bsize - (IS_FFS(amp) ? 0 : OFS_DATA_OFFSET);
|
1995-01-18 12:16:37 +03:00
|
|
|
amp->devvp = devvp;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2012-10-03 11:20:50 +04:00
|
|
|
amp->mp = mp;
|
2002-07-30 11:40:07 +04:00
|
|
|
mp->mnt_data = amp;
|
2004-09-13 23:25:48 +04:00
|
|
|
mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)devvp->v_rdev;
|
|
|
|
mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_ADOSFS);
|
|
|
|
mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
|
2004-09-14 14:58:45 +04:00
|
|
|
mp->mnt_stat.f_namemax = ADMAXNAMELEN;
|
2001-04-03 09:40:27 +04:00
|
|
|
mp->mnt_fs_bshift = ffs(amp->bsize) - 1;
|
2012-10-03 11:20:50 +04:00
|
|
|
mp->mnt_dev_bshift = DEV_BSHIFT;
|
1995-01-18 12:16:37 +03:00
|
|
|
mp->mnt_flag |= MNT_LOCAL;
|
1994-05-11 22:49:06 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* get the root anode, if not a valid fs this will fail.
|
|
|
|
*/
|
2003-06-29 22:53:52 +04:00
|
|
|
if ((error = VFS_ROOT(mp, &rvp)) != 0)
|
1994-05-11 22:49:06 +04:00
|
|
|
goto fail;
|
1996-04-05 09:06:07 +04:00
|
|
|
/* allocate and load bitmap, set free space */
|
2011-05-24 02:00:30 +04:00
|
|
|
bitmap_sz = ((amp->numblks + 31) / 32) * sizeof(*amp->bitmap);
|
|
|
|
amp->bitmap = kmem_alloc(bitmap_sz, KM_SLEEP);
|
1996-04-05 09:06:07 +04:00
|
|
|
if (amp->bitmap)
|
|
|
|
adosfs_loadbitmap(amp);
|
|
|
|
if (mp->mnt_flag & MNT_RDONLY && amp->bitmap) {
|
|
|
|
/*
|
|
|
|
* Don't need the bitmap any more if it's read-only.
|
|
|
|
*/
|
2011-05-24 02:00:30 +04:00
|
|
|
kmem_free(amp->bitmap, bitmap_sz);
|
1996-04-05 09:06:07 +04:00
|
|
|
amp->bitmap = NULL;
|
|
|
|
}
|
1994-06-18 00:06:05 +04:00
|
|
|
vput(rvp);
|
1994-05-11 22:49:06 +04:00
|
|
|
|
|
|
|
return(0);
|
1995-01-18 12:16:37 +03:00
|
|
|
|
1994-05-11 22:49:06 +04:00
|
|
|
fail:
|
1999-10-18 23:52:24 +04:00
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
|
2007-11-26 22:01:26 +03:00
|
|
|
(void) VOP_CLOSE(devvp, FREAD, NOCRED);
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(devvp);
|
1996-04-05 09:06:07 +04:00
|
|
|
if (amp && amp->bitmap)
|
2011-05-24 02:00:30 +04:00
|
|
|
kmem_free(amp->bitmap, bitmap_sz);
|
1994-06-18 00:06:05 +04:00
|
|
|
if (amp)
|
2011-05-24 02:00:30 +04:00
|
|
|
kmem_free(amp, sizeof(*amp));
|
1995-01-18 12:16:37 +03:00
|
|
|
return (error);
|
1994-05-11 22:49:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
adosfs_start(struct mount *mp, int flags)
|
1994-05-11 22:49:06 +04:00
|
|
|
{
|
1995-01-18 12:16:37 +03:00
|
|
|
|
|
|
|
return (0);
|
1994-05-11 22:49:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
adosfs_unmount(struct mount *mp, int mntflags)
|
1994-05-11 22:49:06 +04:00
|
|
|
{
|
1995-01-18 12:17:32 +03:00
|
|
|
struct adosfsmount *amp;
|
1995-01-18 12:16:37 +03:00
|
|
|
int error, flags;
|
1994-05-11 22:49:06 +04:00
|
|
|
|
1995-01-18 12:16:37 +03:00
|
|
|
flags = 0;
|
|
|
|
if (mntflags & MNT_FORCE)
|
|
|
|
flags |= FORCECLOSE;
|
1996-02-09 22:06:38 +03:00
|
|
|
if ((error = vflush(mp, NULLVP, flags)) != 0)
|
1994-06-18 00:06:05 +04:00
|
|
|
return (error);
|
1995-01-18 12:16:37 +03:00
|
|
|
amp = VFSTOADOSFS(mp);
|
1999-10-20 18:32:09 +04:00
|
|
|
if (amp->devvp->v_type != VBAD)
|
2013-09-30 22:57:59 +04:00
|
|
|
spec_node_setmountedfs(amp->devvp, NULL);
|
1999-10-17 03:53:26 +04:00
|
|
|
vn_lock(amp->devvp, LK_EXCLUSIVE | LK_RETRY);
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_CLOSE(amp->devvp, FREAD, NOCRED);
|
1999-10-17 03:53:26 +04:00
|
|
|
vput(amp->devvp);
|
2011-05-24 02:00:30 +04:00
|
|
|
if (amp->bitmap) {
|
|
|
|
size_t bitmap_sz = ((amp->numblks + 31) / 32) *
|
|
|
|
sizeof(*amp->bitmap);
|
|
|
|
kmem_free(amp->bitmap, bitmap_sz);
|
|
|
|
}
|
|
|
|
kmem_free(amp, sizeof(*amp));
|
2002-07-30 11:40:07 +04:00
|
|
|
mp->mnt_data = NULL;
|
1994-06-18 00:06:05 +04:00
|
|
|
mp->mnt_flag &= ~MNT_LOCAL;
|
|
|
|
return (error);
|
1994-05-11 22:49:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
adosfs_root(struct mount *mp, struct vnode **vpp)
|
1994-05-11 22:49:06 +04:00
|
|
|
{
|
1994-06-18 00:06:05 +04:00
|
|
|
struct vnode *nvp;
|
|
|
|
int error;
|
1994-05-11 22:49:06 +04:00
|
|
|
|
1996-02-09 22:06:38 +03:00
|
|
|
if ((error = VFS_VGET(mp, (ino_t)VFSTOADOSFS(mp)->rootb, &nvp)) != 0)
|
1994-06-18 00:06:05 +04:00
|
|
|
return (error);
|
1996-04-05 09:06:07 +04:00
|
|
|
/* XXX verify it's a root block? */
|
1994-06-18 00:06:05 +04:00
|
|
|
*vpp = nvp;
|
|
|
|
return (0);
|
1994-05-11 22:49:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
adosfs_statvfs(struct mount *mp, struct statvfs *sbp)
|
1994-05-11 22:49:06 +04:00
|
|
|
{
|
1995-01-18 12:17:32 +03:00
|
|
|
struct adosfsmount *amp;
|
1995-01-18 12:16:37 +03:00
|
|
|
|
1994-05-11 22:49:06 +04:00
|
|
|
amp = VFSTOADOSFS(mp);
|
|
|
|
sbp->f_bsize = amp->bsize;
|
2004-04-21 05:05:31 +04:00
|
|
|
sbp->f_frsize = amp->bsize;
|
1996-04-05 09:06:07 +04:00
|
|
|
sbp->f_iosize = amp->dbsize;
|
|
|
|
sbp->f_blocks = amp->numblks;
|
|
|
|
sbp->f_bfree = amp->freeblks;
|
|
|
|
sbp->f_bavail = amp->freeblks;
|
2004-04-21 05:05:31 +04:00
|
|
|
sbp->f_bresvd = 0;
|
1994-05-11 22:49:06 +04:00
|
|
|
sbp->f_files = 0; /* who knows */
|
|
|
|
sbp->f_ffree = 0; /* " " */
|
2004-04-21 05:05:31 +04:00
|
|
|
sbp->f_favail = 0; /* " " */
|
|
|
|
sbp->f_fresvd = 0;
|
|
|
|
copy_statvfs_info(sbp, mp);
|
1995-01-18 12:16:37 +03:00
|
|
|
return (0);
|
1994-05-11 22:49:06 +04:00
|
|
|
}
|
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
/*
|
2014-08-05 12:50:54 +04:00
|
|
|
* lookup an anode, if not found, create
|
2015-04-20 16:44:16 +03:00
|
|
|
* return locked and referenced
|
1994-06-18 00:06:05 +04:00
|
|
|
*/
|
1994-05-11 22:49:06 +04:00
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
adosfs_vget(struct mount *mp, ino_t an, struct vnode **vpp)
|
2014-08-05 12:50:54 +04:00
|
|
|
{
|
2015-11-19 01:06:25 +03:00
|
|
|
u_long block;
|
2014-08-05 12:50:54 +04:00
|
|
|
int error;
|
|
|
|
|
2015-11-19 01:06:25 +03:00
|
|
|
block = an;
|
|
|
|
KASSERT(block == an);
|
|
|
|
error = vcache_get(mp, &block, sizeof(block), vpp);
|
2014-08-05 12:50:54 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = vn_lock(*vpp, LK_EXCLUSIVE);
|
|
|
|
if (error) {
|
|
|
|
vrele(*vpp);
|
|
|
|
*vpp = NULL;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize this vnode / anode pair.
|
|
|
|
* Caller assures no other thread will try to load this inode.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
adosfs_loadvnode(struct mount *mp, struct vnode *vp,
|
|
|
|
const void *key, size_t key_len, const void **new_key)
|
1994-05-11 22:49:06 +04:00
|
|
|
{
|
1995-01-18 12:17:32 +03:00
|
|
|
struct adosfsmount *amp;
|
1994-06-18 00:06:05 +04:00
|
|
|
struct anode *ap;
|
|
|
|
struct buf *bp;
|
2015-11-19 01:06:25 +03:00
|
|
|
u_long an;
|
1994-06-18 00:06:05 +04:00
|
|
|
char *nam, *tmp;
|
1996-04-05 09:06:07 +04:00
|
|
|
int namlen, error;
|
1994-06-18 00:06:05 +04:00
|
|
|
|
2014-08-05 12:50:54 +04:00
|
|
|
KASSERT(key_len == sizeof(an));
|
|
|
|
memcpy(&an, key, key_len);
|
1994-06-18 00:06:05 +04:00
|
|
|
amp = VFSTOADOSFS(mp);
|
|
|
|
|
2014-08-05 12:50:54 +04:00
|
|
|
if ((error = bread(amp->devvp, an * amp->bsize / DEV_BSIZE,
|
2015-03-28 22:24:04 +03:00
|
|
|
amp->bsize, 0, &bp)) != 0)
|
2014-08-05 12:50:54 +04:00
|
|
|
return error;
|
1994-06-18 00:06:05 +04:00
|
|
|
|
2014-08-05 12:50:54 +04:00
|
|
|
ap = pool_get(&adosfs_node_pool, PR_WAITOK);
|
1998-08-10 00:15:38 +04:00
|
|
|
memset(ap, 0, sizeof(struct anode));
|
1994-06-18 00:06:05 +04:00
|
|
|
ap->vp = vp;
|
|
|
|
ap->amp = amp;
|
|
|
|
ap->block = an;
|
|
|
|
ap->nwords = amp->nwords;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get type and fill rest in based on that.
|
|
|
|
*/
|
|
|
|
switch (ap->type = adosfs_getblktype(amp, bp)) {
|
|
|
|
case AROOT:
|
|
|
|
vp->v_type = VDIR;
|
2007-10-11 00:42:20 +04:00
|
|
|
vp->v_vflag |= VV_ROOT;
|
1994-06-18 00:06:05 +04:00
|
|
|
ap->mtimev.days = adoswordn(bp, ap->nwords - 10);
|
|
|
|
ap->mtimev.mins = adoswordn(bp, ap->nwords - 9);
|
|
|
|
ap->mtimev.ticks = adoswordn(bp, ap->nwords - 8);
|
|
|
|
ap->created.days = adoswordn(bp, ap->nwords - 7);
|
|
|
|
ap->created.mins = adoswordn(bp, ap->nwords - 6);
|
|
|
|
ap->created.ticks = adoswordn(bp, ap->nwords - 5);
|
|
|
|
break;
|
|
|
|
case ALDIR:
|
|
|
|
case ADIR:
|
|
|
|
vp->v_type = VDIR;
|
|
|
|
break;
|
|
|
|
case ALFILE:
|
|
|
|
case AFILE:
|
|
|
|
vp->v_type = VREG;
|
|
|
|
ap->fsize = adoswordn(bp, ap->nwords - 47);
|
|
|
|
break;
|
|
|
|
case ASLINK: /* XXX soft link */
|
|
|
|
vp->v_type = VLNK;
|
|
|
|
/*
|
|
|
|
* convert from BCPL string and
|
|
|
|
* from: "part:dir/file" to: "/part/dir/file"
|
|
|
|
*/
|
2007-03-04 17:53:09 +03:00
|
|
|
nam = (char *)bp->b_data + (6 * sizeof(long));
|
1996-04-05 09:06:07 +04:00
|
|
|
namlen = strlen(nam);
|
1994-06-18 00:06:05 +04:00
|
|
|
tmp = nam;
|
1996-04-05 09:06:07 +04:00
|
|
|
while (*tmp && *tmp != ':')
|
1994-06-18 00:06:05 +04:00
|
|
|
tmp++;
|
|
|
|
if (*tmp == 0) {
|
|
|
|
ap->slinkto = malloc(namlen + 1, M_ANODE, M_WAITOK);
|
1998-08-10 00:15:38 +04:00
|
|
|
memcpy(ap->slinkto, nam, namlen);
|
1994-06-18 00:06:05 +04:00
|
|
|
} else if (*nam == ':') {
|
|
|
|
ap->slinkto = malloc(namlen + 1, M_ANODE, M_WAITOK);
|
1998-08-10 00:15:38 +04:00
|
|
|
memcpy(ap->slinkto, nam, namlen);
|
1994-06-18 00:06:05 +04:00
|
|
|
ap->slinkto[0] = '/';
|
|
|
|
} else {
|
|
|
|
ap->slinkto = malloc(namlen + 2, M_ANODE, M_WAITOK);
|
|
|
|
ap->slinkto[0] = '/';
|
1998-08-10 00:15:38 +04:00
|
|
|
memcpy(&ap->slinkto[1], nam, namlen);
|
1994-06-18 00:06:05 +04:00
|
|
|
ap->slinkto[tmp - nam + 1] = '/';
|
|
|
|
namlen++;
|
|
|
|
}
|
|
|
|
ap->slinkto[namlen] = 0;
|
1996-04-28 10:18:12 +04:00
|
|
|
ap->fsize = namlen;
|
1994-06-18 00:06:05 +04:00
|
|
|
break;
|
|
|
|
default:
|
2014-08-05 12:50:54 +04:00
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
1994-06-18 00:06:05 +04:00
|
|
|
}
|
1996-04-05 09:06:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get appropriate data from this block; hard link needs
|
|
|
|
* to get other data from the "real" block.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copy in name (from original block)
|
|
|
|
*/
|
2007-03-04 17:53:09 +03:00
|
|
|
nam = (char *)bp->b_data + (ap->nwords - 20) * sizeof(u_int32_t);
|
1996-04-05 09:06:07 +04:00
|
|
|
namlen = *(u_char *)nam++;
|
|
|
|
if (namlen > 30) {
|
|
|
|
#ifdef DIAGNOSTIC
|
2005-08-19 08:15:02 +04:00
|
|
|
printf("adosfs: aget: name length too long blk %llu\n",
|
|
|
|
(unsigned long long)an);
|
1996-04-05 09:06:07 +04:00
|
|
|
#endif
|
2014-08-05 12:50:54 +04:00
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
1996-04-05 09:06:07 +04:00
|
|
|
}
|
1998-08-10 00:15:38 +04:00
|
|
|
memcpy(ap->name, nam, namlen);
|
1996-04-05 09:06:07 +04:00
|
|
|
ap->name[namlen] = 0;
|
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
/*
|
|
|
|
* if dir alloc hash table and copy it in
|
1994-06-18 00:06:05 +04:00
|
|
|
*/
|
|
|
|
if (vp->v_type == VDIR) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ap->tab = malloc(ANODETABSZ(ap) * 2, M_ANODE, M_WAITOK);
|
|
|
|
ap->ntabent = ANODETABENT(ap);
|
|
|
|
ap->tabi = (int *)&ap->tab[ap->ntabent];
|
1998-08-10 00:15:38 +04:00
|
|
|
memset(ap->tabi, 0, ANODETABSZ(ap));
|
1994-06-18 00:06:05 +04:00
|
|
|
for (i = 0; i < ap->ntabent; i++)
|
|
|
|
ap->tab[i] = adoswordn(bp, i + 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* misc.
|
|
|
|
*/
|
|
|
|
ap->pblock = adoswordn(bp, ap->nwords - 3);
|
|
|
|
ap->hashf = adoswordn(bp, ap->nwords - 4);
|
|
|
|
ap->linknext = adoswordn(bp, ap->nwords - 10);
|
|
|
|
ap->linkto = adoswordn(bp, ap->nwords - 11);
|
1994-07-11 09:07:38 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* setup last indirect block cache.
|
|
|
|
*/
|
|
|
|
ap->lastlindblk = 0;
|
1996-04-05 09:06:07 +04:00
|
|
|
if (ap->type == AFILE) {
|
1994-07-11 09:07:38 +04:00
|
|
|
ap->lastindblk = ap->block;
|
1996-04-05 09:06:07 +04:00
|
|
|
if (adoswordn(bp, ap->nwords - 10))
|
|
|
|
ap->linkto = ap->block;
|
|
|
|
} else if (ap->type == ALFILE) {
|
1994-07-11 09:07:38 +04:00
|
|
|
ap->lastindblk = ap->linkto;
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(bp, 0);
|
1996-04-05 09:06:07 +04:00
|
|
|
bp = NULL;
|
1999-06-03 02:04:30 +04:00
|
|
|
error = bread(amp->devvp, ap->linkto * amp->bsize / DEV_BSIZE,
|
2015-03-28 22:24:04 +03:00
|
|
|
amp->bsize, 0, &bp);
|
2014-08-05 12:50:54 +04:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
1996-04-05 09:06:07 +04:00
|
|
|
ap->fsize = adoswordn(bp, ap->nwords - 47);
|
|
|
|
}
|
1994-07-11 09:07:38 +04:00
|
|
|
|
1994-12-28 11:51:56 +03:00
|
|
|
if (ap->type == AROOT) {
|
1996-04-05 09:06:07 +04:00
|
|
|
ap->adprot = 15;
|
1994-12-28 11:51:56 +03:00
|
|
|
ap->uid = amp->uid;
|
|
|
|
ap->gid = amp->gid;
|
|
|
|
} else {
|
1996-04-05 09:06:07 +04:00
|
|
|
ap->adprot = adoswordn(bp, ap->nwords - 48) ^ 15;
|
1997-06-27 01:04:32 +04:00
|
|
|
/*
|
|
|
|
* ADOS directories do not have a `x' protection bit as
|
|
|
|
* it is known in VFS; this functionality is fulfilled
|
|
|
|
* by the ADOS `r' bit.
|
|
|
|
*
|
|
|
|
* To retain the ADOS behaviour, fake execute permissions
|
|
|
|
* in that case.
|
|
|
|
*/
|
1997-07-08 13:11:29 +04:00
|
|
|
if ((ap->type == ADIR || ap->type == ALDIR) &&
|
|
|
|
(ap->adprot & 0x00000008) == 0)
|
|
|
|
ap->adprot &= ~0x00000002;
|
1997-06-27 01:04:32 +04:00
|
|
|
|
1994-12-28 11:51:56 +03:00
|
|
|
/*
|
|
|
|
* Get uid/gid from extensions in file header
|
|
|
|
* (really need to know if this is a muFS partition)
|
|
|
|
*/
|
|
|
|
ap->uid = (adoswordn(bp, ap->nwords - 49) >> 16) & 0xffff;
|
|
|
|
ap->gid = adoswordn(bp, ap->nwords - 49) & 0xffff;
|
|
|
|
if (ap->uid || ap->gid) {
|
|
|
|
if (ap->uid == 0xffff)
|
|
|
|
ap->uid = 0;
|
|
|
|
if (ap->gid == 0xffff)
|
|
|
|
ap->gid = 0;
|
|
|
|
ap->adprot |= 0x40000000; /* Kludge */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* uid & gid extension don't exist,
|
|
|
|
* so use the mount-point uid/gid
|
|
|
|
*/
|
|
|
|
ap->uid = amp->uid;
|
|
|
|
ap->gid = amp->gid;
|
|
|
|
}
|
|
|
|
}
|
1994-06-18 00:06:05 +04:00
|
|
|
ap->mtime.days = adoswordn(bp, ap->nwords - 23);
|
|
|
|
ap->mtime.mins = adoswordn(bp, ap->nwords - 22);
|
|
|
|
ap->mtime.ticks = adoswordn(bp, ap->nwords - 21);
|
|
|
|
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(bp, 0);
|
2014-08-05 12:50:54 +04:00
|
|
|
vp->v_tag = VT_ADOSFS;
|
|
|
|
vp->v_op = adosfs_vnodeop_p;
|
|
|
|
vp->v_data = ap;
|
|
|
|
genfs_node_init(vp, &adosfs_genfsops);
|
2007-07-23 15:27:45 +04:00
|
|
|
uvm_vnp_setsize(vp, ap->fsize);
|
2014-08-05 12:50:54 +04:00
|
|
|
*new_key = &ap->block;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
if (bp)
|
|
|
|
brelse(bp, 0);
|
|
|
|
pool_put(&adosfs_node_pool, ap);
|
|
|
|
return error;
|
1994-05-11 22:49:06 +04:00
|
|
|
}
|
|
|
|
|
1996-04-05 09:06:07 +04:00
|
|
|
/*
|
|
|
|
* Load the bitmap into memory, and count the number of available
|
|
|
|
* blocks.
|
|
|
|
* The bitmap will be released if the filesystem is read-only; it's
|
|
|
|
* only needed to find the free space.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
adosfs_loadbitmap(struct adosfsmount *amp)
|
1996-04-05 09:06:07 +04:00
|
|
|
{
|
|
|
|
struct buf *bp, *mapbp;
|
|
|
|
u_long bn;
|
|
|
|
int blkix, endix, mapix;
|
|
|
|
int bmsize;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
bp = mapbp = NULL;
|
|
|
|
bn = amp->rootb;
|
1999-06-03 02:04:30 +04:00
|
|
|
if ((error = bread(amp->devvp, bn * amp->bsize / DEV_BSIZE, amp->bsize,
|
2015-03-28 22:24:04 +03:00
|
|
|
0, &bp)) != 0) {
|
1996-04-05 09:06:07 +04:00
|
|
|
return (error);
|
1999-02-10 16:14:08 +03:00
|
|
|
}
|
1996-04-05 09:06:07 +04:00
|
|
|
blkix = amp->nwords - 49;
|
|
|
|
endix = amp->nwords - 24;
|
|
|
|
mapix = 0;
|
|
|
|
bmsize = (amp->numblks + 31) / 32;
|
|
|
|
while (mapix < bmsize) {
|
|
|
|
int n;
|
|
|
|
u_long bits;
|
|
|
|
|
|
|
|
if (adoswordn(bp, blkix) == 0)
|
|
|
|
break;
|
|
|
|
if (mapbp != NULL)
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(mapbp, 0);
|
1996-04-05 09:06:07 +04:00
|
|
|
if ((error = bread(amp->devvp,
|
1999-06-03 02:04:30 +04:00
|
|
|
adoswordn(bp, blkix) * amp->bsize / DEV_BSIZE, amp->bsize,
|
2015-03-28 22:24:04 +03:00
|
|
|
0, &mapbp)) != 0)
|
1996-04-05 09:06:07 +04:00
|
|
|
break;
|
|
|
|
if (adoscksum(mapbp, amp->nwords)) {
|
|
|
|
#ifdef DIAGNOSTIC
|
1996-10-13 06:52:06 +04:00
|
|
|
printf("adosfs: loadbitmap - cksum of blk %d failed\n",
|
1996-10-10 21:47:29 +04:00
|
|
|
adoswordn(bp, blkix));
|
1996-04-05 09:06:07 +04:00
|
|
|
#endif
|
|
|
|
/* XXX Force read-only? Set free space 0? */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
n = 1;
|
|
|
|
while (n < amp->nwords && mapix < bmsize) {
|
|
|
|
amp->bitmap[mapix++] = bits = adoswordn(mapbp, n);
|
|
|
|
++n;
|
|
|
|
if (mapix == bmsize && amp->numblks & 31)
|
|
|
|
bits &= ~(0xffffffff << (amp->numblks & 31));
|
|
|
|
while (bits) {
|
|
|
|
if (bits & 1)
|
|
|
|
++amp->freeblks;
|
|
|
|
bits >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++blkix;
|
|
|
|
if (mapix < bmsize && blkix == endix) {
|
|
|
|
bn = adoswordn(bp, blkix);
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(bp, 0);
|
1999-06-03 02:04:30 +04:00
|
|
|
if ((error = bread(amp->devvp, bn * amp->bsize / DEV_BSIZE,
|
2015-03-28 22:24:04 +03:00
|
|
|
amp->bsize, 0, &bp)) != 0)
|
1996-04-05 09:06:07 +04:00
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Why is there no checksum on these blocks?
|
|
|
|
*/
|
|
|
|
blkix = 0;
|
|
|
|
endix = amp->nwords - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bp)
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(bp, 0);
|
1996-04-05 09:06:07 +04:00
|
|
|
if (mapbp)
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(mapbp, 0);
|
1996-04-05 09:06:07 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1995-08-18 19:14:33 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* File handle to vnode
|
|
|
|
*
|
|
|
|
* Have to be really careful about stale file handles:
|
|
|
|
* - check that the inode number is in range
|
|
|
|
* - call iget() to get the locked inode
|
|
|
|
* - check for an unallocated inode (i_mode == 0)
|
|
|
|
* - check that the generation number matches
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ifid {
|
|
|
|
ushort ifid_len;
|
|
|
|
ushort ifid_pad;
|
|
|
|
int ifid_ino;
|
|
|
|
long ifid_start;
|
|
|
|
};
|
|
|
|
|
1994-05-11 22:49:06 +04:00
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
adosfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
|
1994-05-11 22:49:06 +04:00
|
|
|
{
|
2006-07-13 16:00:24 +04:00
|
|
|
struct ifid ifh;
|
1996-02-09 22:06:38 +03:00
|
|
|
#if 0
|
1995-08-18 19:14:33 +04:00
|
|
|
struct anode *ap;
|
1996-02-09 22:06:38 +03:00
|
|
|
#endif
|
1995-08-18 19:14:33 +04:00
|
|
|
struct vnode *nvp;
|
|
|
|
int error;
|
|
|
|
|
2006-07-13 16:00:24 +04:00
|
|
|
if (fhp->fid_len != sizeof(struct ifid))
|
|
|
|
return EINVAL;
|
|
|
|
|
1994-05-11 22:49:06 +04:00
|
|
|
#ifdef ADOSFS_DIAGNOSTIC
|
2009-08-30 16:36:38 +04:00
|
|
|
printf("adfhtovp(%p, %p, %p)\n", mp, fhp, vpp);
|
1994-05-11 22:49:06 +04:00
|
|
|
#endif
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2006-07-13 16:00:24 +04:00
|
|
|
memcpy(&ifh, fhp, sizeof(ifh));
|
|
|
|
|
|
|
|
if ((error = VFS_VGET(mp, ifh.ifid_ino, &nvp)) != 0) {
|
1995-08-18 19:14:33 +04:00
|
|
|
*vpp = NULLVP;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
ap = VTOA(nvp);
|
|
|
|
if (ap->inode.iso_mode == 0) {
|
|
|
|
vput(nvp);
|
|
|
|
*vpp = NULLVP;
|
|
|
|
return (ESTALE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
*vpp = nvp;
|
1999-02-27 02:44:43 +03:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1994-05-11 22:49:06 +04:00
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
adosfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
|
1994-05-11 22:49:06 +04:00
|
|
|
{
|
1995-08-18 19:14:33 +04:00
|
|
|
struct anode *ap = VTOA(vp);
|
2006-07-13 16:00:24 +04:00
|
|
|
struct ifid ifh;
|
1995-08-18 19:14:33 +04:00
|
|
|
|
2006-07-13 16:00:24 +04:00
|
|
|
if (*fh_size < sizeof(struct ifid)) {
|
|
|
|
*fh_size = sizeof(struct ifid);
|
|
|
|
return E2BIG;
|
|
|
|
}
|
|
|
|
*fh_size = sizeof(struct ifid);
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2006-07-13 16:00:24 +04:00
|
|
|
memset(&ifh, 0, sizeof(ifh));
|
|
|
|
ifh.ifid_len = sizeof(struct ifid);
|
|
|
|
ifh.ifid_ino = ap->block;
|
|
|
|
ifh.ifid_start = ap->block;
|
|
|
|
memcpy(fhp, &ifh, sizeof(ifh));
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1994-05-11 22:49:06 +04:00
|
|
|
#ifdef ADOSFS_DIAGNOSTIC
|
2009-08-30 16:36:38 +04:00
|
|
|
printf("advptofh(%p, %p)\n", vp, fhp);
|
1994-05-11 22:49:06 +04:00
|
|
|
#endif
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
adosfs_sync(struct mount *mp, int waitfor, kauth_cred_t uc)
|
1994-05-11 22:49:06 +04:00
|
|
|
{
|
|
|
|
#ifdef ADOSFS_DIAGNOSTIC
|
2009-08-30 16:36:38 +04:00
|
|
|
printf("ad_sync(%p, %d)\n", mp, waitfor);
|
1994-05-11 22:49:06 +04:00
|
|
|
#endif
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1996-02-09 22:06:38 +03:00
|
|
|
void
|
2009-03-15 20:14:40 +03:00
|
|
|
adosfs_init(void)
|
1994-06-18 00:06:05 +04:00
|
|
|
{
|
2007-06-30 13:37:53 +04:00
|
|
|
|
2004-03-27 07:43:43 +03:00
|
|
|
malloc_type_attach(M_ANODE);
|
2004-05-20 09:39:34 +04:00
|
|
|
pool_init(&adosfs_node_pool, sizeof(struct anode), 0, 0, 0, "adosndpl",
|
2007-03-13 04:34:21 +03:00
|
|
|
&pool_allocator_nointr, IPL_NONE);
|
1998-03-01 05:20:01 +03:00
|
|
|
}
|
|
|
|
|
2000-03-16 21:08:17 +03:00
|
|
|
void
|
2009-03-15 20:14:40 +03:00
|
|
|
adosfs_done(void)
|
2000-03-16 21:08:17 +03:00
|
|
|
{
|
2007-06-30 13:37:53 +04:00
|
|
|
|
2004-05-20 09:39:34 +04:00
|
|
|
pool_destroy(&adosfs_node_pool);
|
2004-03-27 07:43:43 +03:00
|
|
|
malloc_type_detach(M_ANODE);
|
2000-03-16 21:08:17 +03:00
|
|
|
}
|
|
|
|
|
1994-05-11 22:49:06 +04:00
|
|
|
/*
|
|
|
|
* vfs generic function call table
|
|
|
|
*/
|
1998-02-18 10:05:47 +03:00
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
extern const struct vnodeopv_desc adosfs_vnodeop_opv_desc;
|
1998-02-18 10:05:47 +03:00
|
|
|
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_desc *adosfs_vnodeopv_descs[] = {
|
1998-02-18 10:05:47 +03:00
|
|
|
&adosfs_vnodeop_opv_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
1994-05-11 22:49:06 +04:00
|
|
|
struct vfsops adosfs_vfsops = {
|
2014-03-23 19:21:15 +04:00
|
|
|
.vfs_name = MOUNT_ADOSFS,
|
|
|
|
.vfs_min_mount_data = sizeof (struct adosfs_args),
|
|
|
|
.vfs_mount = adosfs_mount,
|
|
|
|
.vfs_start = adosfs_start,
|
|
|
|
.vfs_unmount = adosfs_unmount,
|
|
|
|
.vfs_root = adosfs_root,
|
|
|
|
.vfs_quotactl = (void *)eopnotsupp,
|
|
|
|
.vfs_statvfs = adosfs_statvfs,
|
|
|
|
.vfs_sync = adosfs_sync,
|
|
|
|
.vfs_vget = adosfs_vget,
|
2014-08-05 12:50:54 +04:00
|
|
|
.vfs_loadvnode = adosfs_loadvnode,
|
2014-03-23 19:21:15 +04:00
|
|
|
.vfs_fhtovp = adosfs_fhtovp,
|
|
|
|
.vfs_vptofh = adosfs_vptofh,
|
|
|
|
.vfs_init = adosfs_init,
|
|
|
|
.vfs_done = adosfs_done,
|
|
|
|
.vfs_snapshot = (void *)eopnotsupp,
|
|
|
|
.vfs_extattrctl = vfs_stdextattrctl,
|
|
|
|
.vfs_suspendctl = (void *)eopnotsupp,
|
|
|
|
.vfs_renamelock_enter = genfs_renamelock_enter,
|
|
|
|
.vfs_renamelock_exit = genfs_renamelock_exit,
|
|
|
|
.vfs_fsync = (void *)eopnotsupp,
|
|
|
|
.vfs_opv_descs = adosfs_vnodeopv_descs
|
1998-02-18 10:05:47 +03:00
|
|
|
};
|
2008-05-10 06:26:09 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
adosfs_modcmd(modcmd_t cmd, void *arg)
|
|
|
|
{
|
2008-06-28 05:34:05 +04:00
|
|
|
int error;
|
2008-05-10 06:26:09 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MODULE_CMD_INIT:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = vfs_attach(&adosfs_vfsops);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
sysctl_createv(&adosfs_sysctl_log, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "adosfs",
|
|
|
|
SYSCTL_DESCR("AmigaDOS file system"),
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_VFS, 16, CTL_EOL);
|
|
|
|
/*
|
|
|
|
* XXX the "16" above could be dynamic, thereby eliminating
|
|
|
|
* one more instance of the "number to vfs" mapping problem,
|
|
|
|
* but "16" is the order as taken from sys/mount.h
|
|
|
|
*/
|
|
|
|
break;
|
2008-05-10 06:26:09 +04:00
|
|
|
case MODULE_CMD_FINI:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = vfs_detach(&adosfs_vfsops);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
sysctl_teardown(&adosfs_sysctl_log);
|
|
|
|
break;
|
2008-05-10 06:26:09 +04:00
|
|
|
default:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
2008-05-10 06:26:09 +04:00
|
|
|
}
|
2008-06-28 05:34:05 +04:00
|
|
|
|
|
|
|
return (error);
|
2008-05-10 06:26:09 +04:00
|
|
|
}
|