1999-12-09 19:10:13 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998, 1999 Semen Ustimenko (semenu@FreeBSD.org)
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/mount.h>
|
2000-05-05 09:59:14 +00:00
|
|
|
#include <sys/bio.h>
|
1999-12-09 19:10:13 +00:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
2004-10-29 10:43:07 +00:00
|
|
|
#include <geom/geom.h>
|
|
|
|
#include <geom/geom_vfs.h>
|
|
|
|
|
1999-12-09 19:10:13 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/vm_page.h>
|
|
|
|
#include <vm/vm_object.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
|
|
|
|
#include <fs/hpfs/hpfs.h>
|
|
|
|
#include <fs/hpfs/hpfsmount.h>
|
|
|
|
#include <fs/hpfs/hpfs_subr.h>
|
|
|
|
|
2005-10-31 15:41:29 +00:00
|
|
|
MALLOC_DEFINE(M_HPFSMNT, "hpfs_mount", "HPFS mount structure");
|
|
|
|
MALLOC_DEFINE(M_HPFSNO, "hpfs_node", "HPFS node structure");
|
2001-09-12 23:39:36 +00:00
|
|
|
|
2001-11-26 23:45:12 +00:00
|
|
|
struct sockaddr;
|
1999-12-09 19:10:13 +00:00
|
|
|
|
2002-03-19 22:20:14 +00:00
|
|
|
static int hpfs_mountfs(register struct vnode *, struct mount *,
|
2004-12-06 20:14:20 +00:00
|
|
|
struct thread *);
|
2003-06-12 20:48:38 +00:00
|
|
|
|
|
|
|
static vfs_fhtovp_t hpfs_fhtovp;
|
|
|
|
static vfs_vget_t hpfs_vget;
|
2004-12-06 20:14:20 +00:00
|
|
|
static vfs_cmount_t hpfs_cmount;
|
|
|
|
static vfs_mount_t hpfs_mount;
|
2003-06-12 20:48:38 +00:00
|
|
|
static vfs_root_t hpfs_root;
|
|
|
|
static vfs_statfs_t hpfs_statfs;
|
|
|
|
static vfs_unmount_t hpfs_unmount;
|
1999-12-09 19:10:13 +00:00
|
|
|
|
|
|
|
static int
|
2004-12-06 20:14:20 +00:00
|
|
|
hpfs_cmount (
|
|
|
|
struct mntarg *ma,
|
|
|
|
void *data,
|
2009-05-11 15:33:26 +00:00
|
|
|
int flags)
|
2004-12-06 20:14:20 +00:00
|
|
|
{
|
|
|
|
struct hpfs_args args;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = copyin(data, (caddr_t)&args, sizeof (struct hpfs_args));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN);
|
|
|
|
ma = mount_arg(ma, "export", &args.export, sizeof args.export);
|
|
|
|
ma = mount_argf(ma, "uid", "%d", args.uid);
|
|
|
|
ma = mount_argf(ma, "gid", "%d", args.gid);
|
|
|
|
ma = mount_argf(ma, "mode", "%d", args.mode);
|
|
|
|
if (args.flags & HPFSMNT_TABLES) {
|
|
|
|
ma = mount_arg(ma, "d2u", args.d2u, sizeof args.d2u);
|
|
|
|
ma = mount_arg(ma, "u2d", args.u2d, sizeof args.u2d);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = kernel_mount(ma, flags);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *hpfs_opts[] = {
|
|
|
|
"from", "export", "uid", "gid", "mode", "d2u", "u2d", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2009-05-11 15:33:26 +00:00
|
|
|
hpfs_mount (struct mount *mp)
|
1999-12-09 19:10:13 +00:00
|
|
|
{
|
2004-12-06 20:14:20 +00:00
|
|
|
int err = 0, error;
|
1999-12-09 19:10:13 +00:00
|
|
|
struct vnode *devvp;
|
2009-05-11 15:33:26 +00:00
|
|
|
struct thread *td;
|
2004-07-30 22:08:52 +00:00
|
|
|
struct nameidata ndp;
|
2004-12-06 20:14:20 +00:00
|
|
|
struct export_args export;
|
|
|
|
char *from;
|
1999-12-09 19:10:13 +00:00
|
|
|
|
2009-05-11 15:33:26 +00:00
|
|
|
td = curthread;
|
2004-07-30 22:08:52 +00:00
|
|
|
dprintf(("hpfs_omount():\n"));
|
1999-12-09 19:10:13 +00:00
|
|
|
/*
|
|
|
|
***
|
2002-05-16 21:28:32 +00:00
|
|
|
* Mounting non-root filesystem or updating a filesystem
|
1999-12-09 19:10:13 +00:00
|
|
|
***
|
|
|
|
*/
|
2004-12-06 20:14:20 +00:00
|
|
|
if (vfs_filteropt(mp->mnt_optnew, hpfs_opts))
|
|
|
|
return (EINVAL);
|
1999-12-09 19:10:13 +00:00
|
|
|
|
2004-12-06 20:14:20 +00:00
|
|
|
from = vfs_getopts(mp->mnt_optnew, "from", &error);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
1999-12-09 19:10:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If updating, check whether changing from read-only to
|
|
|
|
* read/write; if there is no device name, that's all we do.
|
|
|
|
*/
|
|
|
|
if (mp->mnt_flag & MNT_UPDATE) {
|
2004-07-30 22:08:52 +00:00
|
|
|
dprintf(("hpfs_omount: MNT_UPDATE: "));
|
1999-12-09 19:10:13 +00:00
|
|
|
|
2004-12-06 20:14:20 +00:00
|
|
|
if (from == NULL) {
|
|
|
|
error = vfs_copyopt(mp->mnt_optnew, "export",
|
|
|
|
&export, sizeof export);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
1999-12-09 19:10:13 +00:00
|
|
|
dprintf(("export 0x%x\n",args.export.ex_flags));
|
2004-12-06 20:14:20 +00:00
|
|
|
err = vfs_export(mp, &export);
|
1999-12-09 19:10:13 +00:00
|
|
|
if (err) {
|
2004-07-30 22:08:52 +00:00
|
|
|
printf("hpfs_omount: vfs_export failed %d\n",
|
1999-12-09 19:10:13 +00:00
|
|
|
err);
|
|
|
|
}
|
|
|
|
goto success;
|
|
|
|
} else {
|
|
|
|
dprintf(("name [FAILED]\n"));
|
|
|
|
err = EINVAL;
|
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
dprintf(("\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Not an update, or updating the name: look up the name
|
|
|
|
* and verify that it refers to a sensible block device.
|
|
|
|
*/
|
2005-09-02 15:27:23 +00:00
|
|
|
NDINIT(&ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, from, td);
|
2004-07-30 22:08:52 +00:00
|
|
|
err = namei(&ndp);
|
1999-12-09 19:10:13 +00:00
|
|
|
if (err) {
|
|
|
|
/* can't get devvp!*/
|
|
|
|
goto error_1;
|
|
|
|
}
|
|
|
|
|
2004-07-30 22:08:52 +00:00
|
|
|
devvp = ndp.ni_vp;
|
1999-12-09 19:10:13 +00:00
|
|
|
|
2005-09-02 15:27:23 +00:00
|
|
|
if (!vn_isdisk(devvp, &err)) {
|
|
|
|
vput(devvp);
|
|
|
|
return (err);
|
|
|
|
}
|
1999-12-09 19:10:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
********************
|
|
|
|
* NEW MOUNT
|
|
|
|
********************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since this is a new mount, we want the names for
|
|
|
|
* the device and the mount point copied in. If an
|
2001-03-01 21:00:17 +00:00
|
|
|
* error occurs, the mountpoint is discarded by the
|
2004-07-30 22:08:52 +00:00
|
|
|
* upper level code. Note that vfs_omount() handles
|
2001-03-01 21:00:17 +00:00
|
|
|
* copying the mountpoint f_mntonname for us, so we
|
|
|
|
* don't have to do it here unless we want to set it
|
|
|
|
* to something other than "path" for some rason.
|
1999-12-09 19:10:13 +00:00
|
|
|
*/
|
|
|
|
/* Save "mounted from" info for mount point (NULL pad)*/
|
2004-12-06 20:14:20 +00:00
|
|
|
vfs_mountedfrom(mp, from);
|
1999-12-09 19:10:13 +00:00
|
|
|
|
2004-12-06 20:14:20 +00:00
|
|
|
err = hpfs_mountfs(devvp, mp, td);
|
2005-09-03 00:40:19 +00:00
|
|
|
if (err) {
|
|
|
|
vrele(devvp);
|
|
|
|
goto error_1;
|
|
|
|
}
|
1999-12-09 19:10:13 +00:00
|
|
|
|
|
|
|
goto success;
|
|
|
|
|
|
|
|
error_1: /* no state to back out*/
|
2004-07-30 22:08:52 +00:00
|
|
|
/* XXX: Missing NDFREE(&ndp, ...) */
|
1999-12-09 19:10:13 +00:00
|
|
|
|
|
|
|
success:
|
|
|
|
return( err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common code for mount and mountroot
|
|
|
|
*/
|
|
|
|
int
|
2004-12-06 20:14:20 +00:00
|
|
|
hpfs_mountfs(devvp, mp, td)
|
1999-12-09 19:10:13 +00:00
|
|
|
register struct vnode *devvp;
|
|
|
|
struct mount *mp;
|
2001-11-27 00:34:13 +00:00
|
|
|
struct thread *td;
|
1999-12-09 19:10:13 +00:00
|
|
|
{
|
2004-12-06 20:14:20 +00:00
|
|
|
int error, ronly, v;
|
1999-12-09 19:10:13 +00:00
|
|
|
struct sublock *sup;
|
|
|
|
struct spblock *spp;
|
|
|
|
struct hpfsmount *hpmp;
|
|
|
|
struct buf *bp = NULL;
|
|
|
|
struct vnode *vp;
|
2004-06-16 09:47:26 +00:00
|
|
|
struct cdev *dev = devvp->v_rdev;
|
2004-10-29 10:43:07 +00:00
|
|
|
struct g_consumer *cp;
|
|
|
|
struct bufobj *bo;
|
1999-12-09 19:10:13 +00:00
|
|
|
|
2004-11-09 22:14:57 +00:00
|
|
|
if (mp->mnt_flag & MNT_ROOTFS)
|
|
|
|
return (EOPNOTSUPP);
|
1999-12-09 19:10:13 +00:00
|
|
|
dprintf(("hpfs_mountfs():\n"));
|
|
|
|
ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
|
2004-10-29 10:43:07 +00:00
|
|
|
/* XXX: use VOP_ACCESS to check FS perms */
|
|
|
|
DROP_GIANT();
|
|
|
|
g_topology_lock();
|
|
|
|
error = g_vfs_open(devvp, &cp, "hpfs", ronly ? 0 : 1);
|
|
|
|
g_topology_unlock();
|
|
|
|
PICKUP_GIANT();
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(devvp, 0);
|
1999-12-09 19:10:13 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2004-10-29 10:43:07 +00:00
|
|
|
bo = &devvp->v_bufobj;
|
|
|
|
bo->bo_private = cp;
|
|
|
|
bo->bo_ops = g_vfs_bufops;
|
|
|
|
|
1999-12-09 19:10:13 +00:00
|
|
|
/*
|
|
|
|
* Do actual mount
|
|
|
|
*/
|
2003-02-19 05:47:46 +00:00
|
|
|
hpmp = malloc(sizeof(struct hpfsmount), M_HPFSMNT, M_WAITOK | M_ZERO);
|
1999-12-09 19:10:13 +00:00
|
|
|
|
2004-10-29 10:43:07 +00:00
|
|
|
hpmp->hpm_cp = cp;
|
|
|
|
hpmp->hpm_bo = bo;
|
|
|
|
|
1999-12-09 19:10:13 +00:00
|
|
|
/* Read in SuperBlock */
|
|
|
|
error = bread(devvp, SUBLOCK, SUSIZE, NOCRED, &bp);
|
|
|
|
if (error)
|
|
|
|
goto failed;
|
|
|
|
bcopy(bp->b_data, &hpmp->hpm_su, sizeof(struct sublock));
|
|
|
|
brelse(bp); bp = NULL;
|
|
|
|
|
|
|
|
/* Read in SpareBlock */
|
|
|
|
error = bread(devvp, SPBLOCK, SPSIZE, NOCRED, &bp);
|
|
|
|
if (error)
|
|
|
|
goto failed;
|
|
|
|
bcopy(bp->b_data, &hpmp->hpm_sp, sizeof(struct spblock));
|
|
|
|
brelse(bp); bp = NULL;
|
|
|
|
|
|
|
|
sup = &hpmp->hpm_su;
|
|
|
|
spp = &hpmp->hpm_sp;
|
|
|
|
|
|
|
|
/* Check magic */
|
|
|
|
if (sup->su_magic != SU_MAGIC) {
|
|
|
|
printf("hpfs_mountfs: SuperBlock MAGIC DOESN'T MATCH\n");
|
|
|
|
error = EINVAL;
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
if (spp->sp_magic != SP_MAGIC) {
|
|
|
|
printf("hpfs_mountfs: SpareBlock MAGIC DOESN'T MATCH\n");
|
|
|
|
error = EINVAL;
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2007-10-16 10:54:55 +00:00
|
|
|
mp->mnt_data = hpmp;
|
1999-12-09 19:10:13 +00:00
|
|
|
hpmp->hpm_devvp = devvp;
|
|
|
|
hpmp->hpm_dev = devvp->v_rdev;
|
|
|
|
hpmp->hpm_mp = mp;
|
2004-12-06 20:14:20 +00:00
|
|
|
if (1 == vfs_scanopt(mp->mnt_optnew, "uid", "%d", &v))
|
|
|
|
hpmp->hpm_uid = v;
|
|
|
|
if (1 == vfs_scanopt(mp->mnt_optnew, "gid", "%d", &v))
|
|
|
|
hpmp->hpm_gid = v;
|
|
|
|
if (1 == vfs_scanopt(mp->mnt_optnew, "mode", "%d", &v))
|
|
|
|
hpmp->hpm_mode = v;
|
1999-12-09 19:10:13 +00:00
|
|
|
|
|
|
|
error = hpfs_bminit(hpmp);
|
|
|
|
if (error)
|
|
|
|
goto failed;
|
|
|
|
|
2004-12-06 20:14:20 +00:00
|
|
|
error = hpfs_cpinit(mp, hpmp);
|
1999-12-09 19:10:13 +00:00
|
|
|
if (error) {
|
|
|
|
hpfs_bmdeinit(hpmp);
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2009-05-11 15:33:26 +00:00
|
|
|
error = hpfs_root(mp, LK_EXCLUSIVE, &vp);
|
1999-12-09 19:10:13 +00:00
|
|
|
if (error) {
|
|
|
|
hpfs_cpdeinit(hpmp);
|
|
|
|
hpfs_bmdeinit(hpmp);
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
vput(vp);
|
|
|
|
|
|
|
|
mp->mnt_stat.f_fsid.val[0] = (long)dev2udev(dev);
|
|
|
|
mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
|
|
|
|
mp->mnt_maxsymlinklen = 0;
|
2006-09-26 04:12:49 +00:00
|
|
|
MNT_ILOCK(mp);
|
1999-12-09 19:10:13 +00:00
|
|
|
mp->mnt_flag |= MNT_LOCAL;
|
2006-09-26 04:12:49 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
1999-12-09 19:10:13 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
failed:
|
|
|
|
if (bp)
|
|
|
|
brelse (bp);
|
2007-10-16 10:54:55 +00:00
|
|
|
mp->mnt_data = NULL;
|
2008-01-07 16:51:24 +00:00
|
|
|
DROP_GIANT();
|
|
|
|
g_topology_lock();
|
2008-10-10 21:23:50 +00:00
|
|
|
g_vfs_close(cp);
|
2008-01-07 16:51:24 +00:00
|
|
|
g_topology_unlock();
|
|
|
|
PICKUP_GIANT();
|
1999-12-09 19:10:13 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hpfs_unmount(
|
|
|
|
struct mount *mp,
|
2009-05-11 15:33:26 +00:00
|
|
|
int mntflags)
|
1999-12-09 19:10:13 +00:00
|
|
|
{
|
2009-01-31 17:36:22 +00:00
|
|
|
int error, flags;
|
1999-12-09 19:10:13 +00:00
|
|
|
register struct hpfsmount *hpmp = VFSTOHPFS(mp);
|
|
|
|
|
|
|
|
dprintf(("hpfs_unmount():\n"));
|
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
if(mntflags & MNT_FORCE)
|
|
|
|
flags |= FORCECLOSE;
|
|
|
|
|
|
|
|
dprintf(("hpfs_unmount: vflushing...\n"));
|
|
|
|
|
2009-05-11 15:33:26 +00:00
|
|
|
error = vflush(mp, 0, flags, curthread);
|
1999-12-09 19:10:13 +00:00
|
|
|
if (error) {
|
|
|
|
printf("hpfs_unmount: vflush failed: %d\n",error);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2008-10-10 21:23:50 +00:00
|
|
|
vinvalbuf(hpmp->hpm_devvp, V_SAVE, 0, 0);
|
2008-01-07 16:51:24 +00:00
|
|
|
DROP_GIANT();
|
|
|
|
g_topology_lock();
|
2008-10-10 21:23:50 +00:00
|
|
|
g_vfs_close(hpmp->hpm_cp);
|
2008-01-07 16:51:24 +00:00
|
|
|
g_topology_unlock();
|
|
|
|
PICKUP_GIANT();
|
1999-12-09 19:10:13 +00:00
|
|
|
vrele(hpmp->hpm_devvp);
|
|
|
|
|
|
|
|
dprintf(("hpfs_umount: freeing memory...\n"));
|
|
|
|
hpfs_cpdeinit(hpmp);
|
|
|
|
hpfs_bmdeinit(hpmp);
|
2007-10-16 10:54:55 +00:00
|
|
|
mp->mnt_data = NULL;
|
2006-09-26 04:12:49 +00:00
|
|
|
MNT_ILOCK(mp);
|
1999-12-09 19:10:13 +00:00
|
|
|
mp->mnt_flag &= ~MNT_LOCAL;
|
2006-09-26 04:12:49 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
2008-10-23 15:53:51 +00:00
|
|
|
free(hpmp, M_HPFSMNT);
|
1999-12-09 19:10:13 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hpfs_root(
|
|
|
|
struct mount *mp,
|
2005-03-24 07:36:16 +00:00
|
|
|
int flags,
|
2009-05-11 15:33:26 +00:00
|
|
|
struct vnode **vpp)
|
1999-12-09 19:10:13 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
struct hpfsmount *hpmp = VFSTOHPFS(mp);
|
|
|
|
|
|
|
|
dprintf(("hpfs_root():\n"));
|
2002-03-17 01:25:47 +00:00
|
|
|
error = VFS_VGET(mp, (ino_t)hpmp->hpm_su.su_rootfno, LK_EXCLUSIVE, vpp);
|
1999-12-09 19:10:13 +00:00
|
|
|
if(error) {
|
|
|
|
printf("hpfs_root: VFS_VGET failed: %d\n",error);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hpfs_statfs(
|
|
|
|
struct mount *mp,
|
2009-05-11 15:33:26 +00:00
|
|
|
struct statfs *sbp)
|
1999-12-09 19:10:13 +00:00
|
|
|
{
|
|
|
|
struct hpfsmount *hpmp = VFSTOHPFS(mp);
|
|
|
|
|
|
|
|
dprintf(("hpfs_statfs(): HPFS%d.%d\n",
|
|
|
|
hpmp->hpm_su.su_hpfsver, hpmp->hpm_su.su_fnctver));
|
|
|
|
|
|
|
|
sbp->f_type = mp->mnt_vfc->vfc_typenum;
|
|
|
|
sbp->f_bsize = DEV_BSIZE;
|
|
|
|
sbp->f_iosize = DEV_BSIZE;
|
|
|
|
sbp->f_blocks = hpmp->hpm_su.su_btotal;
|
|
|
|
sbp->f_bfree = sbp->f_bavail = hpmp->hpm_bavail;
|
|
|
|
sbp->f_ffree = 0;
|
|
|
|
sbp->f_files = 0;
|
|
|
|
sbp->f_flags = mp->mnt_flag;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
static int
|
|
|
|
hpfs_fhtovp(
|
|
|
|
struct mount *mp,
|
|
|
|
struct fid *fhp,
|
|
|
|
struct vnode **vpp)
|
|
|
|
{
|
|
|
|
struct vnode *nvp;
|
|
|
|
struct hpfid *hpfhp = (struct hpfid *)fhp;
|
|
|
|
int error;
|
|
|
|
|
2002-03-17 01:25:47 +00:00
|
|
|
if ((error = VFS_VGET(mp, hpfhp->hpfid_ino, LK_EXCLUSIVE, &nvp)) != 0) {
|
1999-12-09 19:10:13 +00:00
|
|
|
*vpp = NULLVP;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
/* XXX as unlink/rmdir/mkdir/creat are not currently possible
|
|
|
|
* with HPFS, we don't need to check anything else for now */
|
|
|
|
*vpp = nvp;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hpfs_vget(
|
|
|
|
struct mount *mp,
|
|
|
|
ino_t ino,
|
2002-03-17 01:25:47 +00:00
|
|
|
int flags,
|
1999-12-09 19:10:13 +00:00
|
|
|
struct vnode **vpp)
|
|
|
|
{
|
|
|
|
struct hpfsmount *hpmp = VFSTOHPFS(mp);
|
|
|
|
struct vnode *vp;
|
|
|
|
struct hpfsnode *hp;
|
|
|
|
struct buf *bp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
dprintf(("hpfs_vget(0x%x): ",ino));
|
|
|
|
|
2005-03-16 11:20:51 +00:00
|
|
|
error = vfs_hash_get(mp, ino, flags, curthread, vpp, NULL, NULL);
|
2005-03-15 08:07:07 +00:00
|
|
|
if (error || *vpp != NULL)
|
2005-03-14 14:41:37 +00:00
|
|
|
return (error);
|
|
|
|
|
1999-12-09 19:10:13 +00:00
|
|
|
*vpp = NULL;
|
|
|
|
hp = NULL;
|
|
|
|
vp = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to lock node creation for a while,
|
|
|
|
* but then we have to call getnewvnode(),
|
|
|
|
* this may cause hpfs_reclaim() to be called,
|
|
|
|
* this may need to VOP_VGET() parent dir for
|
|
|
|
* update reasons, and if parent is not in
|
|
|
|
* hash, we have to lock node creation...
|
|
|
|
* To solve this, we MALLOC, getnewvnode and init while
|
|
|
|
* not locked (probability of node appearence
|
|
|
|
* at that time is little, and anyway - we'll
|
|
|
|
* check for it).
|
|
|
|
*/
|
2008-10-23 15:53:51 +00:00
|
|
|
hp = malloc(sizeof(struct hpfsnode),
|
2003-02-19 05:47:46 +00:00
|
|
|
M_HPFSNO, M_WAITOK);
|
1999-12-09 19:10:13 +00:00
|
|
|
|
2007-03-13 01:50:27 +00:00
|
|
|
error = getnewvnode("hpfs", mp, &hpfs_vnodeops, &vp);
|
1999-12-09 19:10:13 +00:00
|
|
|
if (error) {
|
|
|
|
printf("hpfs_vget: can't get new vnode\n");
|
2008-10-23 15:53:51 +00:00
|
|
|
free(hp, M_HPFSNO);
|
1999-12-09 19:10:13 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
dprintf(("prenew "));
|
|
|
|
|
|
|
|
vp->v_data = hp;
|
|
|
|
|
|
|
|
if (ino == (ino_t)hpmp->hpm_su.su_rootfno)
|
2002-08-04 10:29:36 +00:00
|
|
|
vp->v_vflag |= VV_ROOT;
|
1999-12-09 19:10:13 +00:00
|
|
|
|
2001-01-24 12:35:55 +00:00
|
|
|
|
2002-04-04 21:03:38 +00:00
|
|
|
mtx_init(&hp->h_interlock, "hpfsnode interlock", NULL, MTX_DEF);
|
1999-12-09 19:10:13 +00:00
|
|
|
|
|
|
|
hp->h_flag = H_INVAL;
|
|
|
|
hp->h_vp = vp;
|
|
|
|
hp->h_hpmp = hpmp;
|
|
|
|
hp->h_no = ino;
|
|
|
|
hp->h_dev = hpmp->hpm_dev;
|
|
|
|
hp->h_uid = hpmp->hpm_uid;
|
|
|
|
hp->h_gid = hpmp->hpm_uid;
|
|
|
|
hp->h_mode = hpmp->hpm_mode;
|
|
|
|
hp->h_devvp = hpmp->hpm_devvp;
|
|
|
|
|
2008-01-24 12:34:30 +00:00
|
|
|
lockmgr(vp->v_vnlock, LK_EXCLUSIVE, NULL);
|
2007-03-13 01:50:27 +00:00
|
|
|
error = insmntque(vp, mp);
|
|
|
|
if (error != 0) {
|
|
|
|
free(hp, M_HPFSNO);
|
|
|
|
return (error);
|
|
|
|
}
|
2008-01-24 12:34:30 +00:00
|
|
|
error = vfs_hash_insert(vp, ino, flags, curthread, vpp, NULL, NULL);
|
2005-03-15 20:00:03 +00:00
|
|
|
if (error || *vpp != NULL)
|
1999-12-09 19:10:13 +00:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
error = bread(hpmp->hpm_devvp, ino, FNODESIZE, NOCRED, &bp);
|
|
|
|
if (error) {
|
|
|
|
printf("hpfs_vget: can't read ino %d\n",ino);
|
|
|
|
vput(vp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
bcopy(bp->b_data, &hp->h_fn, sizeof(struct fnode));
|
|
|
|
brelse(bp);
|
|
|
|
|
|
|
|
if (hp->h_fn.fn_magic != FN_MAGIC) {
|
|
|
|
printf("hpfs_vget: MAGIC DOESN'T MATCH\n");
|
|
|
|
vput(vp);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
vp->v_type = hp->h_fn.fn_flag ? VDIR:VREG;
|
|
|
|
hp->h_flag &= ~H_INVAL;
|
|
|
|
|
|
|
|
*vpp = vp;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct vfsops hpfs_vfsops = {
|
2003-06-12 20:48:38 +00:00
|
|
|
.vfs_fhtovp = hpfs_fhtovp,
|
2004-12-06 20:14:20 +00:00
|
|
|
.vfs_cmount = hpfs_cmount,
|
|
|
|
.vfs_mount = hpfs_mount,
|
2003-06-12 20:48:38 +00:00
|
|
|
.vfs_root = hpfs_root,
|
|
|
|
.vfs_statfs = hpfs_statfs,
|
|
|
|
.vfs_unmount = hpfs_unmount,
|
|
|
|
.vfs_vget = hpfs_vget,
|
1999-12-09 19:10:13 +00:00
|
|
|
};
|
|
|
|
VFS_SET(hpfs_vfsops, hpfs, 0);
|