1999-12-03 20:37:40 +00:00
|
|
|
/* $NetBSD: ntfs_vfsops.c,v 1.23 1999/11/15 19:38:14 jdolecek Exp $ */
|
1999-05-12 09:43:09 +00:00
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998, 1999 Semen Ustimenko
|
|
|
|
* 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.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1999-02-03 04:07:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#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-02-03 04:07:38 +00:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/malloc.h>
|
1999-12-03 20:37:40 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#if defined(__NetBSD__)
|
|
|
|
#include <sys/device.h>
|
|
|
|
#endif
|
1999-02-03 04:07:38 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_param.h>
|
1999-12-03 20:37:40 +00:00
|
|
|
#if defined(__NetBSD__)
|
|
|
|
#include <vm/vm_prot.h>
|
|
|
|
#endif
|
1999-02-03 04:07:38 +00:00
|
|
|
#include <vm/vm_page.h>
|
|
|
|
#include <vm/vm_object.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
#if defined(__NetBSD__)
|
|
|
|
#include <miscfs/specfs/specdev.h>
|
|
|
|
#endif
|
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
/*#define NTFS_DEBUG 1*/
|
|
|
|
#include <ntfs/ntfs.h>
|
|
|
|
#include <ntfs/ntfs_inode.h>
|
|
|
|
#include <ntfs/ntfs_subr.h>
|
1999-02-19 12:31:02 +00:00
|
|
|
#include <ntfs/ntfs_vfsops.h>
|
|
|
|
#include <ntfs/ntfs_ihash.h>
|
1999-02-03 04:07:38 +00:00
|
|
|
#include <ntfs/ntfsmount.h>
|
|
|
|
|
1999-05-12 09:43:09 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1999-02-03 04:07:38 +00:00
|
|
|
MALLOC_DEFINE(M_NTFSMNT, "NTFS mount", "NTFS mount structure");
|
1999-02-19 12:31:02 +00:00
|
|
|
MALLOC_DEFINE(M_NTFSNTNODE,"NTFS ntnode", "NTFS ntnode information");
|
|
|
|
MALLOC_DEFINE(M_NTFSFNODE,"NTFS fnode", "NTFS fnode information");
|
1999-02-03 04:07:38 +00:00
|
|
|
MALLOC_DEFINE(M_NTFSDIR,"NTFS dir", "NTFS dir buffer");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int ntfs_root __P((struct mount *, struct vnode **));
|
|
|
|
static int ntfs_statfs __P((struct mount *, struct statfs *,
|
|
|
|
struct proc *));
|
|
|
|
static int ntfs_unmount __P((struct mount *, int, struct proc *));
|
|
|
|
static int ntfs_vget __P((struct mount *mp, ino_t ino,
|
|
|
|
struct vnode **vpp));
|
|
|
|
static int ntfs_mountfs __P((register struct vnode *, struct mount *,
|
|
|
|
struct ntfs_args *, struct proc *));
|
1999-12-03 20:37:40 +00:00
|
|
|
static int ntfs_vptofh __P((struct vnode *, struct fid *));
|
|
|
|
static int ntfs_fhtovp __P((struct mount *, struct fid *,
|
|
|
|
struct vnode **));
|
1999-09-07 22:42:38 +00:00
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
#if !defined (__FreeBSD__)
|
1999-09-07 22:42:38 +00:00
|
|
|
static int ntfs_quotactl __P((struct mount *, int, uid_t, caddr_t,
|
|
|
|
struct proc *));
|
|
|
|
static int ntfs_start __P((struct mount *, int, struct proc *));
|
|
|
|
static int ntfs_sync __P((struct mount *, int, struct ucred *,
|
|
|
|
struct proc *));
|
1999-12-03 20:37:40 +00:00
|
|
|
#endif
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-05-12 09:43:09 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1999-12-03 20:37:40 +00:00
|
|
|
struct sockaddr;
|
|
|
|
static int ntfs_mount __P((struct mount *, char *, caddr_t,
|
|
|
|
struct nameidata *, struct proc *));
|
1999-02-03 04:07:38 +00:00
|
|
|
static int ntfs_init __P((struct vfsconf *));
|
1999-12-03 20:37:40 +00:00
|
|
|
static int ntfs_checkexp __P((struct mount *, struct sockaddr *,
|
1999-09-11 00:46:08 +00:00
|
|
|
int *, struct ucred **));
|
1999-05-12 09:43:09 +00:00
|
|
|
#elif defined(__NetBSD__)
|
1999-12-03 20:37:40 +00:00
|
|
|
static int ntfs_mount __P((struct mount *, const char *, void *,
|
|
|
|
struct nameidata *, struct proc *));
|
1999-05-12 09:43:09 +00:00
|
|
|
static void ntfs_init __P((void));
|
|
|
|
static int ntfs_mountroot __P((void));
|
|
|
|
static int ntfs_sysctl __P((int *, u_int, void *, size_t *, void *,
|
|
|
|
size_t, struct proc *));
|
1999-12-03 20:37:40 +00:00
|
|
|
static int ntfs_checkexp __P((struct mount *, struct mbuf *,
|
|
|
|
int *, struct ucred **));
|
1999-02-03 04:07:38 +00:00
|
|
|
#endif
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
/*
|
|
|
|
* Verify a remote client has export rights and return these rights via.
|
|
|
|
* exflagsp and credanonp.
|
|
|
|
*/
|
1999-05-12 09:43:09 +00:00
|
|
|
static int
|
|
|
|
ntfs_checkexp(mp, nam, exflagsp, credanonp)
|
1999-12-03 20:37:40 +00:00
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
register struct mount *mp;
|
|
|
|
struct sockaddr *nam;
|
|
|
|
int *exflagsp;
|
|
|
|
struct ucred **credanonp;
|
|
|
|
#else /* defined(__NetBSD__) */
|
1999-05-12 09:43:09 +00:00
|
|
|
register struct mount *mp;
|
|
|
|
struct mbuf *nam;
|
|
|
|
int *exflagsp;
|
|
|
|
struct ucred **credanonp;
|
1999-12-03 20:37:40 +00:00
|
|
|
#endif
|
1999-05-12 09:43:09 +00:00
|
|
|
{
|
1999-12-03 20:37:40 +00:00
|
|
|
register struct netcred *np;
|
|
|
|
register struct ntfsmount *ntm = VFSTONTFS(mp);
|
1999-05-12 09:43:09 +00:00
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
/*
|
|
|
|
* Get the export permission structure for this <mp, client> tuple.
|
|
|
|
*/
|
|
|
|
np = vfs_export_lookup(mp, &ntm->ntm_export, nam);
|
|
|
|
if (np == NULL)
|
|
|
|
return (EACCES);
|
|
|
|
|
|
|
|
*exflagsp = np->netc_exflags;
|
|
|
|
*credanonp = &np->netc_anon;
|
|
|
|
return (0);
|
1999-05-12 09:43:09 +00:00
|
|
|
}
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
#if defined(__NetBSD__)
|
1999-05-12 09:43:09 +00:00
|
|
|
/*ARGSUSED*/
|
|
|
|
static int
|
|
|
|
ntfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
|
|
|
|
int *name;
|
|
|
|
u_int namelen;
|
|
|
|
void *oldp;
|
|
|
|
size_t *oldlenp;
|
|
|
|
void *newp;
|
|
|
|
size_t newlen;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_mountroot()
|
|
|
|
{
|
1999-12-03 20:37:40 +00:00
|
|
|
struct mount *mp;
|
|
|
|
extern struct vnode *rootvp;
|
|
|
|
struct proc *p = curproc; /* XXX */
|
|
|
|
int error;
|
|
|
|
struct ntfs_args args;
|
|
|
|
|
|
|
|
if (root_device->dv_class != DV_DISK)
|
|
|
|
return (ENODEV);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get vnodes for rootdev.
|
|
|
|
*/
|
|
|
|
if (bdevvp(rootdev, &rootvp))
|
|
|
|
panic("ntfs_mountroot: can't setup rootvp");
|
|
|
|
|
|
|
|
if ((error = vfs_rootmountalloc(MOUNT_NTFS, "root_device", &mp))) {
|
|
|
|
vrele(rootvp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
args.flag = 0;
|
|
|
|
args.uid = 0;
|
|
|
|
args.gid = 0;
|
|
|
|
args.mode = 0777;
|
|
|
|
|
|
|
|
if ((error = ntfs_mountfs(rootvp, mp, &args, p)) != 0) {
|
|
|
|
mp->mnt_op->vfs_refcount--;
|
|
|
|
vfs_unbusy(mp);
|
|
|
|
free(mp, M_MOUNT);
|
|
|
|
vrele(rootvp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2000-10-04 01:29:17 +00:00
|
|
|
mtx_enter(&mountlist_mtx, MTX_DEF);
|
2000-11-14 06:38:18 +00:00
|
|
|
TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
2000-10-04 01:29:17 +00:00
|
|
|
mtx_exit(&mountlist_mtx, MTX_DEF);
|
1999-12-03 20:37:40 +00:00
|
|
|
(void)ntfs_statfs(mp, &mp->mnt_stat, p);
|
|
|
|
vfs_unbusy(mp);
|
|
|
|
return (0);
|
1999-05-12 09:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ntfs_init ()
|
1999-12-03 20:37:40 +00:00
|
|
|
{
|
|
|
|
ntfs_nthashinit();
|
|
|
|
ntfs_toupper_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
static int
|
1999-12-03 20:37:40 +00:00
|
|
|
ntfs_init (
|
|
|
|
struct vfsconf *vcp )
|
1999-02-03 04:07:38 +00:00
|
|
|
{
|
1999-02-19 12:31:02 +00:00
|
|
|
ntfs_nthashinit();
|
1999-12-03 20:37:40 +00:00
|
|
|
ntfs_toupper_init();
|
1999-02-03 04:07:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-04 01:29:17 +00:00
|
|
|
static int
|
|
|
|
ntfs_uninit (
|
|
|
|
struct vfsconf *vcp )
|
|
|
|
{
|
|
|
|
ntfs_toupper_destroy();
|
|
|
|
ntfs_nthashdestroy();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
#endif /* NetBSD */
|
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
static int
|
|
|
|
ntfs_mount (
|
|
|
|
struct mount *mp,
|
1999-05-12 09:43:09 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1999-02-03 04:07:38 +00:00
|
|
|
char *path,
|
|
|
|
caddr_t data,
|
1999-05-12 09:43:09 +00:00
|
|
|
#else
|
|
|
|
const char *path,
|
|
|
|
void *data,
|
|
|
|
#endif
|
1999-02-03 04:07:38 +00:00
|
|
|
struct nameidata *ndp,
|
|
|
|
struct proc *p )
|
|
|
|
{
|
1999-12-03 20:37:40 +00:00
|
|
|
size_t size;
|
1999-02-03 04:07:38 +00:00
|
|
|
int err = 0;
|
|
|
|
struct vnode *devvp;
|
|
|
|
struct ntfs_args args;
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
#ifdef __FreeBSD__
|
1999-02-03 04:07:38 +00:00
|
|
|
/*
|
|
|
|
* Use NULL path to flag a root mount
|
|
|
|
*/
|
|
|
|
if( path == NULL) {
|
|
|
|
/*
|
|
|
|
***
|
|
|
|
* Mounting root file system
|
|
|
|
***
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Get vnode for root device*/
|
|
|
|
if( bdevvp( rootdev, &rootvp))
|
|
|
|
panic("ffs_mountroot: can't setup bdevvp for root");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FS specific handling
|
|
|
|
*/
|
|
|
|
mp->mnt_flag |= MNT_RDONLY; /* XXX globally applicable?*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt mount
|
|
|
|
*/
|
|
|
|
if( ( err = ntfs_mountfs(rootvp, mp, &args, p)) != 0) {
|
|
|
|
/* fs specific cleanup (if any)*/
|
|
|
|
goto error_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto dostatfs; /* success*/
|
|
|
|
|
|
|
|
}
|
1999-12-03 20:37:40 +00:00
|
|
|
#endif /* FreeBSD */
|
1999-02-03 04:07:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
***
|
|
|
|
* Mounting non-root file system or updating a file system
|
|
|
|
***
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* copy in user arguments*/
|
|
|
|
err = copyin(data, (caddr_t)&args, sizeof (struct ntfs_args));
|
|
|
|
if (err)
|
|
|
|
goto error_1; /* can't get arguments*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
|
|
|
/* if not updating name...*/
|
|
|
|
if (args.fspec == 0) {
|
|
|
|
/*
|
|
|
|
* Process export requests. Jumping to "success"
|
|
|
|
* will return the vfs_export() error code.
|
|
|
|
*/
|
1999-12-03 20:37:40 +00:00
|
|
|
struct ntfsmount *ntm = VFSTONTFS(mp);
|
|
|
|
err = vfs_export(mp, &ntm->ntm_export, &args.export);
|
1999-02-03 04:07:38 +00:00
|
|
|
goto success;
|
|
|
|
}
|
1999-12-03 20:37:40 +00:00
|
|
|
|
|
|
|
printf("ntfs_mount(): MNT_UPDATE not supported\n");
|
|
|
|
err = EINVAL;
|
|
|
|
goto error_1;
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Not an update, or updating the name: look up the name
|
|
|
|
* and verify that it refers to a sensible block device.
|
|
|
|
*/
|
|
|
|
NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
|
|
|
|
err = namei(ndp);
|
|
|
|
if (err) {
|
|
|
|
/* can't get devvp!*/
|
|
|
|
goto error_1;
|
|
|
|
}
|
1999-12-15 23:02:35 +00:00
|
|
|
NDFREE(ndp, NDF_ONLY_PNBUF);
|
1999-02-03 04:07:38 +00:00
|
|
|
devvp = ndp->ni_vp;
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
#if defined(__FreeBSD__)
|
2000-01-10 12:04:27 +00:00
|
|
|
if (!vn_isdisk(devvp, &err))
|
1999-02-03 04:07:38 +00:00
|
|
|
goto error_2;
|
1999-12-03 20:37:40 +00:00
|
|
|
#else
|
|
|
|
if (devvp->v_type != VBLK) {
|
|
|
|
err = ENOTBLK;
|
|
|
|
goto error_2;
|
|
|
|
}
|
|
|
|
if (major(devvp->v_rdev) >= nblkdev) {
|
|
|
|
err = ENXIO;
|
|
|
|
goto error_2;
|
|
|
|
}
|
|
|
|
#endif
|
1999-02-03 04:07:38 +00:00
|
|
|
if (mp->mnt_flag & MNT_UPDATE) {
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
********************
|
|
|
|
* UPDATE
|
|
|
|
********************
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (devvp != ntmp->um_devvp)
|
|
|
|
err = EINVAL; /* needs translation */
|
|
|
|
else
|
|
|
|
vrele(devvp);
|
|
|
|
/*
|
|
|
|
* Update device name only on success
|
|
|
|
*/
|
|
|
|
if( !err) {
|
|
|
|
/* Save "mounted from" info for mount point (NULL pad)*/
|
|
|
|
copyinstr( args.fspec,
|
|
|
|
mp->mnt_stat.f_mntfromname,
|
|
|
|
MNAMELEN - 1,
|
|
|
|
&size);
|
|
|
|
bzero( mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
********************
|
|
|
|
* NEW MOUNT
|
|
|
|
********************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since this is a new mount, we want the names for
|
|
|
|
* the device and the mount point copied in. If an
|
|
|
|
* error occurs, the mountpoint is discarded by the
|
|
|
|
* upper level code.
|
|
|
|
*/
|
|
|
|
/* Save "last mounted on" info for mount point (NULL pad)*/
|
|
|
|
copyinstr( path, /* mount point*/
|
|
|
|
mp->mnt_stat.f_mntonname, /* save area*/
|
|
|
|
MNAMELEN - 1, /* max size*/
|
|
|
|
&size); /* real size*/
|
|
|
|
bzero( mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
|
|
|
|
|
|
|
|
/* Save "mounted from" info for mount point (NULL pad)*/
|
|
|
|
copyinstr( args.fspec, /* device name*/
|
|
|
|
mp->mnt_stat.f_mntfromname, /* save area*/
|
|
|
|
MNAMELEN - 1, /* max size*/
|
|
|
|
&size); /* real size*/
|
|
|
|
bzero( mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
|
|
|
|
|
|
|
|
err = ntfs_mountfs(devvp, mp, &args, p);
|
|
|
|
}
|
|
|
|
if (err) {
|
|
|
|
goto error_2;
|
|
|
|
}
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
#ifdef __FreeBSD__
|
1999-02-03 04:07:38 +00:00
|
|
|
dostatfs:
|
1999-12-03 20:37:40 +00:00
|
|
|
#endif
|
1999-02-03 04:07:38 +00:00
|
|
|
/*
|
|
|
|
* Initialize FS stat information in mount struct; uses both
|
|
|
|
* mp->mnt_stat.f_mntonname and mp->mnt_stat.f_mntfromname
|
|
|
|
*
|
|
|
|
* This code is common to root and non-root mounts
|
|
|
|
*/
|
|
|
|
(void)VFS_STATFS(mp, &mp->mnt_stat, p);
|
|
|
|
|
|
|
|
goto success;
|
|
|
|
|
|
|
|
|
|
|
|
error_2: /* error with devvp held*/
|
|
|
|
|
|
|
|
/* release devvp before failing*/
|
|
|
|
vrele(devvp);
|
|
|
|
|
|
|
|
error_1: /* no state to back out*/
|
|
|
|
|
|
|
|
success:
|
1999-12-03 20:37:40 +00:00
|
|
|
return(err);
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common code for mount and mountroot
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ntfs_mountfs(devvp, mp, argsp, p)
|
|
|
|
register struct vnode *devvp;
|
|
|
|
struct mount *mp;
|
|
|
|
struct ntfs_args *argsp;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct buf *bp;
|
|
|
|
struct ntfsmount *ntmp;
|
|
|
|
dev_t dev = devvp->v_rdev;
|
|
|
|
int error, ronly, ncount, i;
|
|
|
|
struct vnode *vp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disallow multiple mounts of the same device.
|
|
|
|
* Disallow mounting of a device that is currently in use
|
|
|
|
* (except for root, which might share swap device for miniroot).
|
|
|
|
* Flush out any old buffers remaining from a previous use.
|
|
|
|
*/
|
|
|
|
error = vfs_mountedon(devvp);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
ncount = vcount(devvp);
|
1999-05-12 09:43:09 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1999-02-03 04:07:38 +00:00
|
|
|
if (devvp->v_object)
|
|
|
|
ncount -= 1;
|
1999-05-12 09:43:09 +00:00
|
|
|
#endif
|
1999-02-03 04:07:38 +00:00
|
|
|
if (ncount > 1 && devvp != rootvp)
|
|
|
|
return (EBUSY);
|
1999-05-12 09:43:09 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1999-12-03 20:37:40 +00:00
|
|
|
VN_LOCK(devvp, LK_EXCLUSIVE | LK_RETRY, p);
|
1999-02-03 04:07:38 +00:00
|
|
|
error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0);
|
1999-12-03 20:37:40 +00:00
|
|
|
VOP__UNLOCK(devvp, 0, p);
|
1999-02-03 04:07:38 +00:00
|
|
|
#else
|
|
|
|
error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0);
|
|
|
|
#endif
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
|
1999-12-03 20:37:40 +00:00
|
|
|
VN_LOCK(devvp, LK_EXCLUSIVE | LK_RETRY, p);
|
1999-02-03 04:07:38 +00:00
|
|
|
error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p);
|
1999-12-03 20:37:40 +00:00
|
|
|
VOP__UNLOCK(devvp, 0, p);
|
1999-02-03 04:07:38 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
bp = NULL;
|
|
|
|
|
|
|
|
error = bread(devvp, BBLOCK, BBSIZE, NOCRED, &bp);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
2000-12-08 21:51:06 +00:00
|
|
|
ntmp = malloc( sizeof *ntmp, M_NTFSMNT, M_WAITOK | M_ZERO);
|
1999-02-03 04:07:38 +00:00
|
|
|
bcopy( bp->b_data, &ntmp->ntm_bootfile, sizeof(struct bootfile) );
|
|
|
|
brelse( bp );
|
|
|
|
bp = NULL;
|
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
if (strncmp(ntmp->ntm_bootfile.bf_sysid, NTFS_BBID, NTFS_BBIDLEN)) {
|
|
|
|
error = EINVAL;
|
1999-12-03 20:37:40 +00:00
|
|
|
dprintf(("ntfs_mountfs: invalid boot block\n"));
|
1999-04-20 21:06:44 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
{
|
|
|
|
int8_t cpr = ntmp->ntm_mftrecsz;
|
|
|
|
if( cpr > 0 )
|
|
|
|
ntmp->ntm_bpmftrec = ntmp->ntm_spc * cpr;
|
|
|
|
else
|
|
|
|
ntmp->ntm_bpmftrec = (1 << (-cpr)) / ntmp->ntm_bps;
|
|
|
|
}
|
1999-04-20 21:06:44 +00:00
|
|
|
dprintf(("ntfs_mountfs(): bps: %d, spc: %d, media: %x, mftrecsz: %d (%d sects)\n",
|
1999-02-03 04:07:38 +00:00
|
|
|
ntmp->ntm_bps,ntmp->ntm_spc,ntmp->ntm_bootfile.bf_media,
|
1999-04-20 21:06:44 +00:00
|
|
|
ntmp->ntm_mftrecsz,ntmp->ntm_bpmftrec));
|
|
|
|
dprintf(("ntfs_mountfs(): mftcn: 0x%x|0x%x\n",
|
|
|
|
(u_int32_t)ntmp->ntm_mftcn,(u_int32_t)ntmp->ntm_mftmirrcn));
|
1999-02-03 04:07:38 +00:00
|
|
|
|
|
|
|
ntmp->ntm_mountp = mp;
|
|
|
|
ntmp->ntm_dev = dev;
|
|
|
|
ntmp->ntm_devvp = devvp;
|
|
|
|
ntmp->ntm_uid = argsp->uid;
|
|
|
|
ntmp->ntm_gid = argsp->gid;
|
|
|
|
ntmp->ntm_mode = argsp->mode;
|
|
|
|
ntmp->ntm_flag = argsp->flag;
|
|
|
|
mp->mnt_data = (qaddr_t)ntmp;
|
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
dprintf(("ntfs_mountfs(): case-%s,%s uid: %d, gid: %d, mode: %o\n",
|
1999-02-03 04:07:38 +00:00
|
|
|
(ntmp->ntm_flag & NTFS_MFLAG_CASEINS)?"insens.":"sens.",
|
|
|
|
(ntmp->ntm_flag & NTFS_MFLAG_ALLNAMES)?" allnames,":"",
|
1999-04-20 21:06:44 +00:00
|
|
|
ntmp->ntm_uid, ntmp->ntm_gid, ntmp->ntm_mode));
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
/*
|
|
|
|
* We read in some system nodes to do not allow
|
|
|
|
* reclaim them and to have everytime access to them.
|
|
|
|
*/
|
1999-02-03 04:07:38 +00:00
|
|
|
{
|
1999-04-20 21:06:44 +00:00
|
|
|
int pi[3] = { NTFS_MFTINO, NTFS_ROOTINO, NTFS_BITMAPINO };
|
|
|
|
for (i=0; i<3; i++) {
|
|
|
|
error = VFS_VGET(mp, pi[i], &(ntmp->ntm_sysvn[pi[i]]));
|
|
|
|
if(error)
|
|
|
|
goto out1;
|
|
|
|
ntmp->ntm_sysvn[pi[i]]->v_flag |= VSYSTEM;
|
|
|
|
VREF(ntmp->ntm_sysvn[pi[i]]);
|
|
|
|
vput(ntmp->ntm_sysvn[pi[i]]);
|
|
|
|
}
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
/* read the Unicode lowercase --> uppercase translation table,
|
|
|
|
* if necessary */
|
|
|
|
if ((error = ntfs_toupper_use(mp, ntmp)))
|
1999-02-03 04:07:38 +00:00
|
|
|
goto out1;
|
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
/*
|
|
|
|
* Scan $BitMap and count free clusters
|
|
|
|
*/
|
|
|
|
error = ntfs_calccfree(ntmp, &ntmp->ntm_cfree);
|
|
|
|
if(error)
|
|
|
|
goto out1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read and translate to internal format attribute
|
|
|
|
* definition file.
|
|
|
|
*/
|
1999-02-03 04:07:38 +00:00
|
|
|
{
|
|
|
|
int num,j;
|
|
|
|
struct attrdef ad;
|
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
/* Open $AttrDef */
|
1999-02-03 04:07:38 +00:00
|
|
|
error = VFS_VGET(mp, NTFS_ATTRDEFINO, &vp );
|
|
|
|
if(error)
|
|
|
|
goto out1;
|
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
/* Count valid entries */
|
1999-02-03 04:07:38 +00:00
|
|
|
for(num=0;;num++) {
|
1999-02-19 12:31:02 +00:00
|
|
|
error = ntfs_readattr(ntmp, VTONT(vp),
|
1999-02-03 04:07:38 +00:00
|
|
|
NTFS_A_DATA, NULL,
|
|
|
|
num * sizeof(ad), sizeof(ad),
|
1999-12-03 20:37:40 +00:00
|
|
|
&ad, NULL);
|
1999-02-03 04:07:38 +00:00
|
|
|
if (error)
|
|
|
|
goto out1;
|
|
|
|
if (ad.ad_name[0] == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
/* Alloc memory for attribute definitions */
|
1999-02-03 04:07:38 +00:00
|
|
|
MALLOC(ntmp->ntm_ad, struct ntvattrdef *,
|
|
|
|
num * sizeof(struct ntvattrdef),
|
|
|
|
M_NTFSMNT, M_WAITOK);
|
|
|
|
|
|
|
|
ntmp->ntm_adnum = num;
|
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
/* Read them and translate */
|
1999-02-03 04:07:38 +00:00
|
|
|
for(i=0;i<num;i++){
|
1999-02-19 12:31:02 +00:00
|
|
|
error = ntfs_readattr(ntmp, VTONT(vp),
|
1999-02-03 04:07:38 +00:00
|
|
|
NTFS_A_DATA, NULL,
|
|
|
|
i * sizeof(ad), sizeof(ad),
|
1999-12-03 20:37:40 +00:00
|
|
|
&ad, NULL);
|
1999-02-03 04:07:38 +00:00
|
|
|
if (error)
|
|
|
|
goto out1;
|
|
|
|
j = 0;
|
|
|
|
do {
|
|
|
|
ntmp->ntm_ad[i].ad_name[j] = ad.ad_name[j];
|
|
|
|
} while(ad.ad_name[j++]);
|
|
|
|
ntmp->ntm_ad[i].ad_namelen = j - 1;
|
|
|
|
ntmp->ntm_ad[i].ad_type = ad.ad_type;
|
|
|
|
}
|
1999-04-20 21:06:44 +00:00
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
vput(vp);
|
|
|
|
}
|
|
|
|
|
1999-05-12 09:43:09 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1999-12-03 20:37:40 +00:00
|
|
|
mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
|
1999-02-03 04:07:38 +00:00
|
|
|
mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
|
|
|
|
#else
|
1999-12-03 20:37:40 +00:00
|
|
|
mp->mnt_stat.f_fsid.val[0] = dev;
|
1999-05-12 09:43:09 +00:00
|
|
|
mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_NTFS);
|
1999-02-03 04:07:38 +00:00
|
|
|
#endif
|
|
|
|
mp->mnt_maxsymlinklen = 0;
|
|
|
|
mp->mnt_flag |= MNT_LOCAL;
|
2000-10-09 17:31:39 +00:00
|
|
|
devvp->v_rdev->si_mountpoint = mp;
|
1999-02-03 04:07:38 +00:00
|
|
|
return (0);
|
1999-04-20 21:06:44 +00:00
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
out1:
|
|
|
|
for(i=0;i<NTFS_SYSNODESNUM;i++)
|
|
|
|
if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
|
1999-04-20 21:06:44 +00:00
|
|
|
|
|
|
|
if (vflush(mp,NULLVP,0))
|
1999-12-03 20:37:40 +00:00
|
|
|
dprintf(("ntfs_mountfs: vflush failed\n"));
|
1999-04-20 21:06:44 +00:00
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
out:
|
2000-10-09 17:31:39 +00:00
|
|
|
devvp->v_rdev->si_mountpoint = NULL;
|
1999-02-03 04:07:38 +00:00
|
|
|
if (bp)
|
|
|
|
brelse(bp);
|
1999-12-03 20:37:40 +00:00
|
|
|
|
|
|
|
#if defined __NetBSD__
|
|
|
|
/* lock the device vnode before calling VOP_CLOSE() */
|
|
|
|
VN_LOCK(devvp, LK_EXCLUSIVE | LK_RETRY, p);
|
|
|
|
(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
|
|
|
|
VOP__UNLOCK(devvp, 0, p);
|
|
|
|
#else
|
1999-02-03 04:07:38 +00:00
|
|
|
(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
|
1999-12-03 20:37:40 +00:00
|
|
|
#endif
|
|
|
|
|
1999-02-03 04:07:38 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-09-07 22:42:38 +00:00
|
|
|
#if !defined(__FreeBSD__)
|
1999-02-03 04:07:38 +00:00
|
|
|
static int
|
|
|
|
ntfs_start (
|
|
|
|
struct mount *mp,
|
|
|
|
int flags,
|
|
|
|
struct proc *p )
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
1999-12-03 20:37:40 +00:00
|
|
|
#endif
|
1999-02-03 04:07:38 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_unmount(
|
|
|
|
struct mount *mp,
|
|
|
|
int mntflags,
|
|
|
|
struct proc *p)
|
|
|
|
{
|
|
|
|
register struct ntfsmount *ntmp;
|
|
|
|
int error, ronly = 0, flags, i;
|
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
dprintf(("ntfs_unmount: unmounting...\n"));
|
1999-02-03 04:07:38 +00:00
|
|
|
ntmp = VFSTONTFS(mp);
|
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
if(mntflags & MNT_FORCE)
|
|
|
|
flags |= FORCECLOSE;
|
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
dprintf(("ntfs_unmount: vflushing...\n"));
|
1999-02-19 12:31:02 +00:00
|
|
|
error = vflush(mp,NULLVP,flags | SKIPSYSTEM);
|
1999-02-03 04:07:38 +00:00
|
|
|
if (error) {
|
|
|
|
printf("ntfs_unmount: vflush failed: %d\n",error);
|
|
|
|
return (error);
|
|
|
|
}
|
1999-04-20 21:06:44 +00:00
|
|
|
|
|
|
|
/* Check if only system vnodes are rest */
|
|
|
|
for(i=0;i<NTFS_SYSNODESNUM;i++)
|
|
|
|
if((ntmp->ntm_sysvn[i]) &&
|
|
|
|
(ntmp->ntm_sysvn[i]->v_usecount > 1)) return (EBUSY);
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
/* Dereference all system vnodes */
|
1999-02-19 12:31:02 +00:00
|
|
|
for(i=0;i<NTFS_SYSNODESNUM;i++)
|
|
|
|
if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
|
1999-04-20 21:06:44 +00:00
|
|
|
|
|
|
|
/* vflush system vnodes */
|
1999-02-19 12:31:02 +00:00
|
|
|
error = vflush(mp,NULLVP,flags);
|
|
|
|
if (error)
|
1999-04-20 21:06:44 +00:00
|
|
|
printf("ntfs_unmount: vflush failed(sysnodes): %d\n",error);
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
/* Check if the type of device node isn't VBAD before
|
|
|
|
* touching v_specinfo. If the device vnode is revoked, the
|
|
|
|
* field is NULL and touching it causes null pointer derefercence.
|
|
|
|
*/
|
|
|
|
if (ntmp->ntm_devvp->v_type != VBAD)
|
2000-10-09 17:31:39 +00:00
|
|
|
ntmp->ntm_devvp->v_rdev->si_mountpoint = NULL;
|
1999-02-03 04:07:38 +00:00
|
|
|
|
|
|
|
vinvalbuf(ntmp->ntm_devvp, V_SAVE, NOCRED, p, 0, 0);
|
1999-12-03 20:37:40 +00:00
|
|
|
|
|
|
|
#if defined(__NetBSD__)
|
|
|
|
/* lock the device vnode before calling VOP_CLOSE() */
|
|
|
|
VOP_LOCK(ntmp->ntm_devvp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
error = VOP_CLOSE(ntmp->ntm_devvp, ronly ? FREAD : FREAD|FWRITE,
|
|
|
|
NOCRED, p);
|
|
|
|
VOP__UNLOCK(ntmp->ntm_devvp, 0, p);
|
|
|
|
#else
|
1999-02-03 04:07:38 +00:00
|
|
|
error = VOP_CLOSE(ntmp->ntm_devvp, ronly ? FREAD : FREAD|FWRITE,
|
|
|
|
NOCRED, p);
|
1999-12-03 20:37:40 +00:00
|
|
|
#endif
|
1999-02-03 04:07:38 +00:00
|
|
|
|
|
|
|
vrele(ntmp->ntm_devvp);
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
/* free the toupper table, if this has been last mounted ntfs volume */
|
|
|
|
ntfs_toupper_unuse();
|
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
dprintf(("ntfs_umount: freeing memory...\n"));
|
1999-02-03 04:07:38 +00:00
|
|
|
mp->mnt_data = (qaddr_t)0;
|
|
|
|
mp->mnt_flag &= ~MNT_LOCAL;
|
|
|
|
FREE(ntmp->ntm_ad, M_NTFSMNT);
|
|
|
|
FREE(ntmp, M_NTFSMNT);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_root(
|
|
|
|
struct mount *mp,
|
|
|
|
struct vnode **vpp )
|
|
|
|
{
|
|
|
|
struct vnode *nvp;
|
|
|
|
int error = 0;
|
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
dprintf(("ntfs_root(): sysvn: %p\n",
|
|
|
|
VFSTONTFS(mp)->ntm_sysvn[NTFS_ROOTINO]));
|
1999-02-03 04:07:38 +00:00
|
|
|
error = VFS_VGET(mp, (ino_t)NTFS_ROOTINO, &nvp);
|
|
|
|
if(error) {
|
|
|
|
printf("ntfs_root: VFS_VGET failed: %d\n",error);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
*vpp = nvp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-09-07 22:42:38 +00:00
|
|
|
#if !defined(__FreeBSD__)
|
1999-02-03 04:07:38 +00:00
|
|
|
static int
|
|
|
|
ntfs_quotactl (
|
|
|
|
struct mount *mp,
|
|
|
|
int cmds,
|
|
|
|
uid_t uid,
|
|
|
|
caddr_t arg,
|
|
|
|
struct proc *p)
|
|
|
|
{
|
|
|
|
printf("\nntfs_quotactl():\n");
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
1999-12-03 20:37:40 +00:00
|
|
|
#endif
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
int
|
|
|
|
ntfs_calccfree(
|
|
|
|
struct ntfsmount *ntmp,
|
|
|
|
cn_t *cfreep)
|
1999-02-03 04:07:38 +00:00
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
u_int8_t *tmp;
|
1999-04-20 21:06:44 +00:00
|
|
|
int j, error;
|
|
|
|
long cfree = 0;
|
|
|
|
size_t bmsize, i;
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
vp = ntmp->ntm_sysvn[NTFS_BITMAPINO];
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
bmsize = VTOF(vp)->f_size;
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
MALLOC(tmp, u_int8_t *, bmsize, M_TEMP, M_WAITOK);
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
error = ntfs_readattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL,
|
1999-12-03 20:37:40 +00:00
|
|
|
0, bmsize, tmp, NULL);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
1999-02-03 04:07:38 +00:00
|
|
|
|
|
|
|
for(i=0;i<bmsize;i++)
|
|
|
|
for(j=0;j<8;j++)
|
1999-04-20 21:06:44 +00:00
|
|
|
if(~tmp[i] & (1 << j)) cfree++;
|
|
|
|
*cfreep = cfree;
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
out:
|
|
|
|
FREE(tmp, M_TEMP);
|
|
|
|
return(error);
|
1999-04-20 21:06:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_statfs(
|
|
|
|
struct mount *mp,
|
|
|
|
struct statfs *sbp,
|
|
|
|
struct proc *p)
|
|
|
|
{
|
|
|
|
struct ntfsmount *ntmp = VFSTONTFS(mp);
|
|
|
|
u_int64_t mftsize,mftallocated;
|
|
|
|
|
|
|
|
dprintf(("ntfs_statfs():\n"));
|
|
|
|
|
|
|
|
mftsize = VTOF(ntmp->ntm_sysvn[NTFS_MFTINO])->f_size;
|
|
|
|
mftallocated = VTOF(ntmp->ntm_sysvn[NTFS_MFTINO])->f_allocated;
|
|
|
|
|
1999-05-12 09:43:09 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1999-02-03 04:07:38 +00:00
|
|
|
sbp->f_type = mp->mnt_vfc->vfc_typenum;
|
1999-05-12 09:43:09 +00:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
sbp->f_type = 0;
|
1999-02-03 04:07:38 +00:00
|
|
|
#else
|
|
|
|
sbp->f_type = MOUNT_NTFS;
|
|
|
|
#endif
|
|
|
|
sbp->f_bsize = ntmp->ntm_bps;
|
|
|
|
sbp->f_iosize = ntmp->ntm_bps * ntmp->ntm_spc;
|
|
|
|
sbp->f_blocks = ntmp->ntm_bootfile.bf_spv;
|
1999-04-20 21:06:44 +00:00
|
|
|
sbp->f_bfree = sbp->f_bavail = ntfs_cntobn(ntmp->ntm_cfree);
|
1999-02-03 04:07:38 +00:00
|
|
|
sbp->f_ffree = sbp->f_bfree / ntmp->ntm_bpmftrec;
|
|
|
|
sbp->f_files = mftallocated / ntfs_bntob(ntmp->ntm_bpmftrec) +
|
|
|
|
sbp->f_ffree;
|
|
|
|
if (sbp != &mp->mnt_stat) {
|
|
|
|
bcopy((caddr_t)mp->mnt_stat.f_mntonname,
|
|
|
|
(caddr_t)&sbp->f_mntonname[0], MNAMELEN);
|
|
|
|
bcopy((caddr_t)mp->mnt_stat.f_mntfromname,
|
|
|
|
(caddr_t)&sbp->f_mntfromname[0], MNAMELEN);
|
|
|
|
}
|
1999-02-19 12:31:02 +00:00
|
|
|
sbp->f_flags = mp->mnt_flag;
|
1999-12-03 20:37:40 +00:00
|
|
|
#ifdef __NetBSD__
|
|
|
|
strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
|
|
|
|
#endif
|
1999-02-03 04:07:38 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-09-07 22:42:38 +00:00
|
|
|
#if !defined(__FreeBSD__)
|
1999-02-03 04:07:38 +00:00
|
|
|
static int
|
|
|
|
ntfs_sync (
|
|
|
|
struct mount *mp,
|
|
|
|
int waitfor,
|
|
|
|
struct ucred *cred,
|
|
|
|
struct proc *p)
|
|
|
|
{
|
|
|
|
/*dprintf(("ntfs_sync():\n"));*/
|
|
|
|
return (0);
|
|
|
|
}
|
1999-12-03 20:37:40 +00:00
|
|
|
#endif
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-05-12 09:43:09 +00:00
|
|
|
/*ARGSUSED*/
|
1999-02-03 04:07:38 +00:00
|
|
|
static int
|
|
|
|
ntfs_fhtovp(
|
1999-05-12 09:43:09 +00:00
|
|
|
struct mount *mp,
|
|
|
|
struct fid *fhp,
|
|
|
|
struct vnode **vpp)
|
1999-02-03 04:07:38 +00:00
|
|
|
{
|
1999-12-03 20:37:40 +00:00
|
|
|
struct vnode *nvp;
|
|
|
|
struct ntfid *ntfhp = (struct ntfid *)fhp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ddprintf(("ntfs_fhtovp(): %s: %d\n", mp->mnt_stat->f_mntonname,
|
|
|
|
ntfhp->ntfid_ino));
|
|
|
|
|
|
|
|
if ((error = VFS_VGET(mp, ntfhp->ntfid_ino, &nvp)) != 0) {
|
|
|
|
*vpp = NULLVP;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
/* XXX as unlink/rmdir/mkdir/creat are not currently possible
|
|
|
|
* with NTFS, we don't need to check anything else for now */
|
|
|
|
*vpp = nvp;
|
|
|
|
|
|
|
|
return (0);
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_vptofh(
|
|
|
|
struct vnode *vp,
|
|
|
|
struct fid *fhp)
|
|
|
|
{
|
1999-12-03 20:37:40 +00:00
|
|
|
register struct ntnode *ntp;
|
|
|
|
register struct ntfid *ntfhp;
|
|
|
|
|
|
|
|
ddprintf(("ntfs_fhtovp(): %s: %p\n", vp->v_mount->mnt_stat->f_mntonname,
|
|
|
|
vp));
|
|
|
|
|
|
|
|
ntp = VTONT(vp);
|
|
|
|
ntfhp = (struct ntfid *)fhp;
|
|
|
|
ntfhp->ntfid_len = sizeof(struct ntfid);
|
|
|
|
ntfhp->ntfid_ino = ntp->i_number;
|
|
|
|
/* ntfhp->ntfid_gen = ntp->i_gen; */
|
|
|
|
return (0);
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
int
|
|
|
|
ntfs_vgetex(
|
1999-02-03 04:07:38 +00:00
|
|
|
struct mount *mp,
|
|
|
|
ino_t ino,
|
1999-02-19 12:31:02 +00:00
|
|
|
u_int32_t attrtype,
|
|
|
|
char *attrname,
|
|
|
|
u_long lkflags,
|
|
|
|
u_long flags,
|
|
|
|
struct proc *p,
|
1999-02-03 04:07:38 +00:00
|
|
|
struct vnode **vpp)
|
|
|
|
{
|
1999-02-19 12:31:02 +00:00
|
|
|
int error;
|
1999-02-03 04:07:38 +00:00
|
|
|
register struct ntfsmount *ntmp;
|
|
|
|
struct ntnode *ip;
|
1999-02-19 12:31:02 +00:00
|
|
|
struct fnode *fp;
|
|
|
|
struct vnode *vp;
|
1999-12-03 20:37:40 +00:00
|
|
|
enum vtype f_type;
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
dprintf(("ntfs_vgetex: ino: %d, attr: 0x%x:%s, lkf: 0x%lx, f: 0x%lx\n",
|
|
|
|
ino, attrtype, attrname?attrname:"", (u_long)lkflags,
|
|
|
|
(u_long)flags ));
|
1999-02-03 04:07:38 +00:00
|
|
|
|
|
|
|
ntmp = VFSTONTFS(mp);
|
1999-02-19 12:31:02 +00:00
|
|
|
*vpp = NULL;
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
/* Get ntnode */
|
1999-04-20 21:06:44 +00:00
|
|
|
error = ntfs_ntlookup(ntmp, ino, &ip);
|
1999-02-19 12:31:02 +00:00
|
|
|
if (error) {
|
1999-02-03 04:07:38 +00:00
|
|
|
printf("ntfs_vget: ntfs_ntget failed\n");
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
/* It may be not initialized fully, so force load it */
|
|
|
|
if (!(flags & VG_DONTLOADIN) && !(ip->i_flag & IN_LOADED)) {
|
|
|
|
error = ntfs_loadntnode(ntmp, ip);
|
|
|
|
if(error) {
|
|
|
|
printf("ntfs_vget: CAN'T LOAD ATTRIBUTES FOR INO: %d\n",
|
|
|
|
ip->i_number);
|
|
|
|
ntfs_ntput(ip);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
error = ntfs_fget(ntmp, ip, attrtype, attrname, &fp);
|
|
|
|
if (error) {
|
|
|
|
printf("ntfs_vget: ntfs_fget failed\n");
|
1999-04-20 21:06:44 +00:00
|
|
|
ntfs_ntput(ip);
|
1999-02-03 04:07:38 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
f_type = VNON;
|
1999-04-20 21:06:44 +00:00
|
|
|
if (!(flags & VG_DONTVALIDFN) && !(fp->f_flag & FN_VALID)) {
|
|
|
|
if ((ip->i_frflag & NTFS_FRFLAG_DIR) &&
|
1999-12-03 20:37:40 +00:00
|
|
|
(fp->f_attrtype == NTFS_A_DATA && fp->f_attrname == NULL)) {
|
|
|
|
f_type = VDIR;
|
|
|
|
} else if (flags & VG_EXT) {
|
|
|
|
f_type = VNON;
|
|
|
|
fp->f_size = fp->f_allocated = 0;
|
1999-04-20 21:06:44 +00:00
|
|
|
} else {
|
1999-12-03 20:37:40 +00:00
|
|
|
f_type = VREG;
|
1999-04-20 21:06:44 +00:00
|
|
|
|
|
|
|
error = ntfs_filesize(ntmp, fp,
|
|
|
|
&fp->f_size, &fp->f_allocated);
|
|
|
|
if (error) {
|
|
|
|
ntfs_ntput(ip);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fp->f_flag |= FN_VALID;
|
|
|
|
}
|
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
if (FTOV(fp)) {
|
1999-05-12 09:43:09 +00:00
|
|
|
VGET(FTOV(fp), lkflags, p);
|
1999-02-19 12:31:02 +00:00
|
|
|
*vpp = FTOV(fp);
|
1999-04-20 21:06:44 +00:00
|
|
|
ntfs_ntput(ip);
|
1999-02-19 12:31:02 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
error = getnewvnode(VT_NTFS, ntmp->ntm_mountp, ntfs_vnodeop_p, &vp);
|
1999-02-03 04:07:38 +00:00
|
|
|
if(error) {
|
1999-02-19 12:31:02 +00:00
|
|
|
ntfs_frele(fp);
|
1999-04-20 21:06:44 +00:00
|
|
|
ntfs_ntput(ip);
|
1999-02-03 04:07:38 +00:00
|
|
|
return (error);
|
|
|
|
}
|
1999-02-19 12:31:02 +00:00
|
|
|
dprintf(("ntfs_vget: vnode: %p for ntnode: %d\n", vp,ino));
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
#ifdef __FreeBSD__
|
1999-02-19 12:31:02 +00:00
|
|
|
lockinit(&fp->f_lock, PINOD, "fnode", 0, 0);
|
1999-12-03 20:37:40 +00:00
|
|
|
#endif
|
1999-02-19 12:31:02 +00:00
|
|
|
fp->f_vp = vp;
|
|
|
|
vp->v_data = fp;
|
1999-12-03 20:37:40 +00:00
|
|
|
vp->v_type = f_type;
|
1999-02-03 04:07:38 +00:00
|
|
|
|
1999-02-19 12:31:02 +00:00
|
|
|
if (ino == NTFS_ROOTINO)
|
|
|
|
vp->v_flag |= VROOT;
|
|
|
|
|
1999-04-20 21:06:44 +00:00
|
|
|
ntfs_ntput(ip);
|
1999-02-19 12:31:02 +00:00
|
|
|
|
|
|
|
if (lkflags & LK_TYPE_MASK) {
|
1999-05-12 09:43:09 +00:00
|
|
|
error = VN_LOCK(vp, lkflags, p);
|
1999-02-19 12:31:02 +00:00
|
|
|
if (error) {
|
|
|
|
vput(vp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-03 20:37:40 +00:00
|
|
|
VREF(ip->i_devvp);
|
1999-02-19 12:31:02 +00:00
|
|
|
*vpp = vp;
|
1999-02-03 04:07:38 +00:00
|
|
|
return (0);
|
1999-02-19 12:31:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_vget(
|
|
|
|
struct mount *mp,
|
|
|
|
ino_t ino,
|
|
|
|
struct vnode **vpp)
|
|
|
|
{
|
|
|
|
return ntfs_vgetex(mp, ino, NTFS_A_DATA, NULL,
|
1999-12-03 20:37:40 +00:00
|
|
|
LK_EXCLUSIVE | LK_RETRY, 0, curproc, vpp);
|
1999-02-03 04:07:38 +00:00
|
|
|
}
|
|
|
|
|
1999-05-12 09:43:09 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1999-02-03 04:07:38 +00:00
|
|
|
static struct vfsops ntfs_vfsops = {
|
|
|
|
ntfs_mount,
|
1999-09-07 22:42:38 +00:00
|
|
|
vfs_stdstart,
|
1999-02-03 04:07:38 +00:00
|
|
|
ntfs_unmount,
|
|
|
|
ntfs_root,
|
1999-09-07 22:42:38 +00:00
|
|
|
vfs_stdquotactl,
|
1999-02-03 04:07:38 +00:00
|
|
|
ntfs_statfs,
|
1999-09-07 22:42:38 +00:00
|
|
|
vfs_stdsync,
|
1999-02-03 04:07:38 +00:00
|
|
|
ntfs_vget,
|
1999-12-03 20:37:40 +00:00
|
|
|
ntfs_fhtovp,
|
|
|
|
ntfs_checkexp,
|
|
|
|
ntfs_vptofh,
|
1999-02-03 04:07:38 +00:00
|
|
|
ntfs_init,
|
2000-10-04 01:29:17 +00:00
|
|
|
ntfs_uninit,
|
1999-12-19 06:08:07 +00:00
|
|
|
vfs_stdextattrctl,
|
1999-02-03 04:07:38 +00:00
|
|
|
};
|
|
|
|
VFS_SET(ntfs_vfsops, ntfs, 0);
|
1999-05-12 09:43:09 +00:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
extern struct vnodeopv_desc ntfs_vnodeop_opv_desc;
|
|
|
|
|
|
|
|
struct vnodeopv_desc *ntfs_vnodeopv_descs[] = {
|
|
|
|
&ntfs_vnodeop_opv_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vfsops ntfs_vfsops = {
|
|
|
|
MOUNT_NTFS,
|
|
|
|
ntfs_mount,
|
|
|
|
ntfs_start,
|
|
|
|
ntfs_unmount,
|
|
|
|
ntfs_root,
|
|
|
|
ntfs_quotactl,
|
|
|
|
ntfs_statfs,
|
|
|
|
ntfs_sync,
|
|
|
|
ntfs_vget,
|
|
|
|
ntfs_fhtovp,
|
|
|
|
ntfs_vptofh,
|
|
|
|
ntfs_init,
|
|
|
|
ntfs_sysctl,
|
|
|
|
ntfs_mountroot,
|
|
|
|
ntfs_checkexp,
|
|
|
|
ntfs_vnodeopv_descs,
|
|
|
|
};
|
1999-12-03 20:37:40 +00:00
|
|
|
#else /* !NetBSD && !FreeBSD */
|
1999-02-03 04:07:38 +00:00
|
|
|
static struct vfsops ntfs_vfsops = {
|
|
|
|
ntfs_mount,
|
|
|
|
ntfs_start,
|
|
|
|
ntfs_unmount,
|
|
|
|
ntfs_root,
|
|
|
|
ntfs_quotactl,
|
|
|
|
ntfs_statfs,
|
|
|
|
ntfs_sync,
|
|
|
|
ntfs_vget,
|
|
|
|
ntfs_fhtovp,
|
|
|
|
ntfs_vptofh,
|
|
|
|
ntfs_init,
|
|
|
|
};
|
|
|
|
VFS_SET(ntfs_vfsops, ntfs, MOUNT_NTFS, 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|