2005-01-09 12:27:17 +03:00
|
|
|
/* $NetBSD: ntfs_vfsops.c,v 1.28 2005/01/09 09:27:17 mycroft Exp $ */
|
1999-05-06 19:43:17 +04:00
|
|
|
|
1999-05-06 19:36:39 +04: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-07-26 18:02:30 +04:00
|
|
|
* Id: ntfs_vfsops.c,v 1.7 1999/05/31 11:28:30 phk Exp
|
1999-05-06 19:36:39 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-10 16:22:20 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-01-09 12:27:17 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.28 2005/01/09 09:27:17 mycroft Exp $");
|
1999-05-06 19:36:39 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/malloc.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>
|
1999-09-10 20:14:02 +04:00
|
|
|
#include <sys/device.h>
|
2002-09-06 17:18:43 +04:00
|
|
|
#include <sys/conf.h>
|
1999-05-06 19:36:39 +04:00
|
|
|
|
2000-06-28 07:32:55 +04:00
|
|
|
#if defined(__NetBSD__)
|
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
#else
|
1999-05-06 19:36:39 +04:00
|
|
|
#include <vm/vm.h>
|
2000-06-28 07:32:55 +04:00
|
|
|
#endif
|
1999-05-06 19:36:39 +04:00
|
|
|
|
|
|
|
#include <miscfs/specfs/specdev.h>
|
|
|
|
|
|
|
|
/*#define NTFS_DEBUG 1*/
|
2002-12-23 20:38:19 +03:00
|
|
|
#include <fs/ntfs/ntfs.h>
|
|
|
|
#include <fs/ntfs/ntfs_inode.h>
|
|
|
|
#include <fs/ntfs/ntfs_subr.h>
|
|
|
|
#include <fs/ntfs/ntfs_vfsops.h>
|
|
|
|
#include <fs/ntfs/ntfs_ihash.h>
|
|
|
|
#include <fs/ntfs/ntfsmount.h>
|
1999-05-06 19:36:39 +04:00
|
|
|
|
|
|
|
MALLOC_DEFINE(M_NTFSMNT, "NTFS mount", "NTFS mount structure");
|
|
|
|
MALLOC_DEFINE(M_NTFSNTNODE,"NTFS ntnode", "NTFS ntnode information");
|
|
|
|
MALLOC_DEFINE(M_NTFSFNODE,"NTFS fnode", "NTFS fnode information");
|
|
|
|
MALLOC_DEFINE(M_NTFSDIR,"NTFS dir", "NTFS dir buffer");
|
|
|
|
|
1999-07-26 18:02:30 +04:00
|
|
|
#if defined(__FreeBSD__)
|
1999-05-06 19:36:39 +04:00
|
|
|
static int ntfs_mount __P((struct mount *, char *, caddr_t,
|
|
|
|
struct nameidata *, struct proc *));
|
1999-05-06 19:43:17 +04:00
|
|
|
#else
|
|
|
|
static int ntfs_mount __P((struct mount *, const char *, void *,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct nameidata *, struct proc *));
|
1999-05-06 19:43:17 +04:00
|
|
|
#endif
|
2004-04-27 21:37:30 +04:00
|
|
|
static int ntfs_quotactl __P((struct mount *, int, uid_t, void *,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *));
|
2003-06-29 22:43:21 +04:00
|
|
|
static int ntfs_root __P((struct mount *, struct vnode **));
|
2003-06-30 02:28:00 +04:00
|
|
|
static int ntfs_start __P((struct mount *, int, struct proc *));
|
2004-04-21 05:05:31 +04:00
|
|
|
static int ntfs_statvfs __P((struct mount *, struct statvfs *,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *));
|
1999-05-06 19:36:39 +04:00
|
|
|
static int ntfs_sync __P((struct mount *, int, struct ucred *,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *));
|
|
|
|
static int ntfs_unmount __P((struct mount *, int, struct proc *));
|
1999-05-06 19:36:39 +04:00
|
|
|
static int ntfs_vget __P((struct mount *mp, ino_t ino,
|
2003-06-29 22:43:21 +04:00
|
|
|
struct vnode **vpp));
|
2000-03-30 16:41:09 +04:00
|
|
|
static int ntfs_mountfs __P((struct vnode *, struct mount *,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct ntfs_args *, struct proc *));
|
1999-05-06 19:36:39 +04:00
|
|
|
static int ntfs_vptofh __P((struct vnode *, struct fid *));
|
|
|
|
|
1999-07-26 18:02:30 +04:00
|
|
|
#if defined(__FreeBSD__)
|
1999-05-06 19:36:39 +04:00
|
|
|
static int ntfs_init __P((struct vfsconf *));
|
|
|
|
static int ntfs_fhtovp __P((struct mount *, struct fid *,
|
|
|
|
struct sockaddr *, struct vnode **,
|
|
|
|
int *, struct ucred **));
|
1999-05-06 19:43:17 +04:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
static void ntfs_init __P((void));
|
2001-09-15 20:12:54 +04:00
|
|
|
static void ntfs_reinit __P((void));
|
2000-03-16 21:08:17 +03:00
|
|
|
static void ntfs_done __P((void));
|
1999-05-06 19:43:17 +04:00
|
|
|
static int ntfs_fhtovp __P((struct mount *, struct fid *,
|
2003-06-29 22:43:21 +04:00
|
|
|
struct vnode **));
|
1999-05-06 19:43:17 +04:00
|
|
|
static int ntfs_checkexp __P((struct mount *, struct mbuf *,
|
|
|
|
int *, struct ucred **));
|
|
|
|
static int ntfs_mountroot __P((void));
|
1999-05-06 19:36:39 +04:00
|
|
|
#else
|
|
|
|
static int ntfs_init __P((void));
|
|
|
|
static int ntfs_fhtovp __P((struct mount *, struct fid *,
|
|
|
|
struct mbuf *, struct vnode **,
|
|
|
|
int *, struct ucred **));
|
|
|
|
#endif
|
|
|
|
|
2001-12-18 10:51:16 +03:00
|
|
|
struct genfs_ops ntfs_genfsops = {
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
genfs_compat_gop_write,
|
|
|
|
};
|
|
|
|
|
1999-05-06 19:43:17 +04:00
|
|
|
#ifdef __NetBSD__
|
1999-09-10 20:14:02 +04:00
|
|
|
/*
|
|
|
|
* Verify a remote client has export rights and return these rights via.
|
|
|
|
* exflagsp and credanonp.
|
|
|
|
*/
|
1999-05-06 19:43:17 +04:00
|
|
|
static int
|
|
|
|
ntfs_checkexp(mp, nam, exflagsp, credanonp)
|
2000-03-30 16:41:09 +04:00
|
|
|
struct mount *mp;
|
1999-05-06 19:43:17 +04:00
|
|
|
struct mbuf *nam;
|
|
|
|
int *exflagsp;
|
|
|
|
struct ucred **credanonp;
|
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct netcred *np;
|
|
|
|
struct ntfsmount *ntm = VFSTONTFS(mp);
|
1999-05-06 19:43:17 +04:00
|
|
|
|
1999-09-10 20:14:02 +04: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-06 19:43:17 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
SYSCTL_SETUP(sysctl_vfs_ntfs_setup, "sysctl vfs.ntfs subtree setup")
|
1999-05-06 19:43:17 +04:00
|
|
|
{
|
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
|
|
|
|
2004-03-24 18:34:46 +03:00
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
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
|
|
|
CTLTYPE_NODE, "vfs", NULL,
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_VFS, CTL_EOL);
|
2004-03-24 18:34:46 +03:00
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
2004-05-25 08:44:43 +04:00
|
|
|
CTLTYPE_NODE, "ntfs",
|
|
|
|
SYSCTL_DESCR("NTFS file system"),
|
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
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_VFS, 20, CTL_EOL);
|
|
|
|
/*
|
|
|
|
* XXX the "20" above could be dynamic, thereby eliminating
|
|
|
|
* one more instance of the "number to vfs" mapping problem,
|
|
|
|
* but "20" is the order as taken from sys/mount.h
|
|
|
|
*/
|
1999-05-06 19:43:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_mountroot()
|
|
|
|
{
|
1999-09-10 21:30:08 +04:00
|
|
|
struct mount *mp;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p = curproc; /* XXX */
|
1999-09-10 21:30:08 +04:00
|
|
|
int error;
|
|
|
|
struct ntfs_args args;
|
|
|
|
|
|
|
|
if (root_device->dv_class != DV_DISK)
|
|
|
|
return (ENODEV);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
if ((error = ntfs_mountfs(rootvp, mp, &args, p)) != 0) {
|
1999-09-10 21:30:08 +04:00
|
|
|
mp->mnt_op->vfs_refcount--;
|
|
|
|
vfs_unbusy(mp);
|
|
|
|
free(mp, M_MOUNT);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
simple_lock(&mountlist_slock);
|
|
|
|
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
|
|
|
simple_unlock(&mountlist_slock);
|
2004-04-21 05:05:31 +04:00
|
|
|
(void)ntfs_statvfs(mp, &mp->mnt_stat, p);
|
1999-09-10 21:30:08 +04:00
|
|
|
vfs_unbusy(mp);
|
|
|
|
return (0);
|
1999-05-06 19:43:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-03-16 21:08:17 +03:00
|
|
|
ntfs_init()
|
1999-09-10 20:14:02 +04:00
|
|
|
{
|
2003-04-22 20:48:19 +04:00
|
|
|
#ifdef _LKM
|
|
|
|
malloc_type_attach(M_NTFSMNT);
|
|
|
|
malloc_type_attach(M_NTFSNTNODE);
|
|
|
|
malloc_type_attach(M_NTFSFNODE);
|
|
|
|
malloc_type_attach(M_NTFSDIR);
|
|
|
|
malloc_type_attach(M_NTFSNTHASH);
|
2003-04-22 21:23:47 +04:00
|
|
|
malloc_type_attach(M_NTFSNTVATTR);
|
2003-04-24 11:50:19 +04:00
|
|
|
malloc_type_attach(M_NTFSRDATA);
|
|
|
|
malloc_type_attach(M_NTFSDECOMP);
|
|
|
|
malloc_type_attach(M_NTFSRUN);
|
2003-04-22 20:48:19 +04:00
|
|
|
#endif
|
1999-09-10 20:14:02 +04:00
|
|
|
ntfs_nthashinit();
|
1999-09-28 09:44:21 +04:00
|
|
|
ntfs_toupper_init();
|
1999-09-10 20:14:02 +04:00
|
|
|
}
|
|
|
|
|
2001-09-15 20:12:54 +04:00
|
|
|
static void
|
|
|
|
ntfs_reinit()
|
|
|
|
{
|
|
|
|
ntfs_nthashreinit();
|
|
|
|
}
|
|
|
|
|
2000-03-16 21:08:17 +03:00
|
|
|
static void
|
|
|
|
ntfs_done()
|
|
|
|
{
|
|
|
|
ntfs_nthashdone();
|
2003-04-22 20:48:19 +04:00
|
|
|
#ifdef _LKM
|
|
|
|
malloc_type_detach(M_NTFSMNT);
|
|
|
|
malloc_type_detach(M_NTFSNTNODE);
|
|
|
|
malloc_type_detach(M_NTFSFNODE);
|
|
|
|
malloc_type_detach(M_NTFSDIR);
|
|
|
|
malloc_type_detach(M_NTFSNTHASH);
|
2003-04-22 21:23:47 +04:00
|
|
|
malloc_type_detach(M_NTFSNTVATTR);
|
2003-04-24 11:50:19 +04:00
|
|
|
malloc_type_detach(M_NTFSRDATA);
|
|
|
|
malloc_type_detach(M_NTFSDECOMP);
|
|
|
|
malloc_type_detach(M_NTFSRUN);
|
2003-04-22 20:48:19 +04:00
|
|
|
#endif
|
2000-03-16 21:08:17 +03:00
|
|
|
}
|
|
|
|
|
1999-09-10 20:14:02 +04:00
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
|
1999-05-06 19:36:39 +04:00
|
|
|
static int
|
1999-09-10 20:14:02 +04:00
|
|
|
ntfs_init (
|
|
|
|
struct vfsconf *vcp )
|
1999-05-06 19:36:39 +04:00
|
|
|
{
|
|
|
|
ntfs_nthashinit();
|
1999-09-28 09:44:21 +04:00
|
|
|
ntfs_toupper_init();
|
1999-05-06 19:36:39 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-09-10 20:14:02 +04:00
|
|
|
#endif /* NetBSD */
|
|
|
|
|
1999-05-06 19:36:39 +04:00
|
|
|
static int
|
|
|
|
ntfs_mount (
|
|
|
|
struct mount *mp,
|
1999-07-26 18:02:30 +04:00
|
|
|
#if defined(__FreeBSD__)
|
1999-05-06 19:36:39 +04:00
|
|
|
char *path,
|
|
|
|
caddr_t data,
|
1999-05-06 19:43:17 +04:00
|
|
|
#else
|
|
|
|
const char *path,
|
|
|
|
void *data,
|
|
|
|
#endif
|
1999-05-06 19:36:39 +04:00
|
|
|
struct nameidata *ndp,
|
|
|
|
struct proc *p )
|
|
|
|
{
|
2005-01-09 12:27:17 +03:00
|
|
|
int err = 0, flags;
|
1999-05-06 19:36:39 +04:00
|
|
|
struct vnode *devvp;
|
|
|
|
struct ntfs_args args;
|
|
|
|
|
2002-09-21 22:10:34 +04:00
|
|
|
if (mp->mnt_flag & MNT_GETARGS) {
|
|
|
|
struct ntfsmount *ntmp = VFSTONTFS(mp);
|
|
|
|
if (ntmp == NULL)
|
|
|
|
return EIO;
|
|
|
|
args.fspec = NULL;
|
|
|
|
args.uid = ntmp->ntm_uid;
|
|
|
|
args.gid = ntmp->ntm_gid;
|
|
|
|
args.mode = ntmp->ntm_mode;
|
|
|
|
args.flag = ntmp->ntm_flag;
|
|
|
|
vfs_showexport(mp, &args.export, &ntmp->ntm_export);
|
|
|
|
return copyout(&args, data, sizeof(args));
|
|
|
|
}
|
1999-05-06 19:36:39 +04:00
|
|
|
/*
|
|
|
|
***
|
|
|
|
* Mounting non-root file system or updating a file system
|
|
|
|
***
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* copy in user arguments*/
|
2004-05-04 17:26:58 +04:00
|
|
|
err = copyin(data, &args, sizeof (struct ntfs_args));
|
1999-05-06 19:36:39 +04:00
|
|
|
if (err)
|
2005-01-09 12:27:17 +03:00
|
|
|
return (err); /* can't get arguments*/
|
1999-05-06 19:36:39 +04: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) {
|
|
|
|
/* if not updating name...*/
|
|
|
|
if (args.fspec == 0) {
|
|
|
|
/*
|
|
|
|
* Process export requests. Jumping to "success"
|
|
|
|
* will return the vfs_export() error code.
|
|
|
|
*/
|
1999-09-10 20:14:02 +04:00
|
|
|
struct ntfsmount *ntm = VFSTONTFS(mp);
|
2005-01-09 12:27:17 +03:00
|
|
|
return (vfs_export(mp, &ntm->ntm_export, &args.export));
|
1999-05-06 19:36:39 +04:00
|
|
|
}
|
1999-09-10 20:14:02 +04:00
|
|
|
|
|
|
|
printf("ntfs_mount(): MNT_UPDATE not supported\n");
|
2005-01-09 12:27:17 +03:00
|
|
|
return (EINVAL);
|
1999-05-06 19:36:39 +04: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!*/
|
2005-01-09 12:27:17 +03:00
|
|
|
return (err);
|
1999-05-06 19:36:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
devvp = ndp->ni_vp;
|
|
|
|
|
|
|
|
if (devvp->v_type != VBLK) {
|
|
|
|
err = ENOTBLK;
|
2005-01-09 12:27:17 +03:00
|
|
|
goto fail;
|
1999-05-06 19:36:39 +04:00
|
|
|
}
|
1999-07-26 18:35:19 +04:00
|
|
|
#ifdef __FreeBSD__
|
1999-07-26 18:02:30 +04:00
|
|
|
if (bdevsw(devvp->v_rdev) == NULL) {
|
1999-07-26 18:35:19 +04:00
|
|
|
#else
|
2002-09-06 17:18:43 +04:00
|
|
|
if (bdevsw_lookup(devvp->v_rdev) == NULL) {
|
1999-07-26 18:35:19 +04:00
|
|
|
#endif
|
1999-05-06 19:36:39 +04:00
|
|
|
err = ENXIO;
|
2005-01-09 12:27:17 +03:00
|
|
|
goto fail;
|
1999-05-06 19:36:39 +04:00
|
|
|
}
|
|
|
|
if (mp->mnt_flag & MNT_UPDATE) {
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
********************
|
|
|
|
* UPDATE
|
|
|
|
********************
|
|
|
|
*/
|
|
|
|
|
2005-01-09 12:27:17 +03:00
|
|
|
if (devvp != ntmp->um_devvp) {
|
1999-05-06 19:36:39 +04:00
|
|
|
err = EINVAL; /* needs translation */
|
2005-01-09 12:27:17 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
1999-05-06 19:36:39 +04:00
|
|
|
/*
|
|
|
|
* Update device name only on success
|
|
|
|
*/
|
2005-01-09 12:27:17 +03:00
|
|
|
err = set_statvfs_info(NULL, UIO_USERSPACE, args.fspec,
|
|
|
|
UIO_USERSPACE, mp, p);
|
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
vrele(devvp);
|
1999-05-06 19:36:39 +04:00
|
|
|
#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.
|
|
|
|
*/
|
2005-01-09 12:27:17 +03:00
|
|
|
|
1999-05-06 19:36:39 +04:00
|
|
|
/* Save "last mounted on" info for mount point (NULL pad)*/
|
2004-04-21 05:05:31 +04:00
|
|
|
err = set_statvfs_info(path, UIO_USERSPACE, args.fspec,
|
2003-06-30 02:28:00 +04:00
|
|
|
UIO_USERSPACE, mp, p);
|
2005-01-09 12:27:17 +03:00
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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).
|
|
|
|
*/
|
|
|
|
err = vfs_mountedon(devvp);
|
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
if (vcount(devvp) > 1 && devvp != rootvp) {
|
|
|
|
err = EBUSY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (mp->mnt_flag & MNT_RDONLY)
|
|
|
|
flags = FREAD;
|
|
|
|
else
|
|
|
|
flags = FREAD|FWRITE;
|
|
|
|
err = VOP_OPEN(devvp, flags, FSCRED, p);
|
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
err = ntfs_mountfs(devvp, mp, &args, p);
|
|
|
|
if (err) {
|
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
(void)VOP_CLOSE(devvp, flags, NOCRED, p);
|
|
|
|
VOP_UNLOCK(devvp, 0);
|
|
|
|
goto fail;
|
2003-04-17 01:44:18 +04:00
|
|
|
}
|
1999-05-06 19:36:39 +04:00
|
|
|
}
|
|
|
|
|
1999-09-10 20:14:02 +04:00
|
|
|
#ifdef __FreeBSD__
|
2004-04-21 05:05:31 +04:00
|
|
|
dostatvfs:
|
1999-09-10 20:14:02 +04:00
|
|
|
#endif
|
1999-05-06 19:36:39 +04: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
|
|
|
|
*/
|
2004-04-21 05:05:31 +04:00
|
|
|
(void)VFS_STATVFS(mp, &mp->mnt_stat, p);
|
2005-01-09 12:27:17 +03:00
|
|
|
return (err);
|
1999-05-06 19:36:39 +04:00
|
|
|
|
2005-01-09 12:27:17 +03:00
|
|
|
fail:
|
1999-05-06 19:36:39 +04:00
|
|
|
vrele(devvp);
|
2005-01-09 12:27:17 +03:00
|
|
|
return (err);
|
1999-05-06 19:36:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common code for mount and mountroot
|
|
|
|
*/
|
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
ntfs_mountfs(devvp, mp, argsp, p)
|
2000-03-30 16:41:09 +04:00
|
|
|
struct vnode *devvp;
|
1999-05-06 19:36:39 +04:00
|
|
|
struct mount *mp;
|
|
|
|
struct ntfs_args *argsp;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p;
|
1999-05-06 19:36:39 +04:00
|
|
|
{
|
|
|
|
struct buf *bp;
|
|
|
|
struct ntfsmount *ntmp;
|
|
|
|
dev_t dev = devvp->v_rdev;
|
2005-01-09 12:27:17 +03:00
|
|
|
int error, ronly, i;
|
1999-05-06 19:36:39 +04:00
|
|
|
struct vnode *vp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush out any old buffers remaining from a previous use.
|
|
|
|
*/
|
2005-01-09 12:27:17 +03:00
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
|
2003-06-30 02:28:00 +04:00
|
|
|
error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0);
|
2005-01-09 12:27:17 +03:00
|
|
|
VOP_UNLOCK(devvp, 0);
|
1999-05-06 19:36:39 +04:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
|
|
|
|
|
|
|
|
bp = NULL;
|
|
|
|
|
|
|
|
error = bread(devvp, BBLOCK, BBSIZE, NOCRED, &bp);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
ntmp = malloc( sizeof *ntmp, M_NTFSMNT, M_WAITOK );
|
|
|
|
bzero( ntmp, sizeof *ntmp );
|
|
|
|
bcopy( bp->b_data, &ntmp->ntm_bootfile, sizeof(struct bootfile) );
|
|
|
|
brelse( bp );
|
|
|
|
bp = NULL;
|
|
|
|
|
|
|
|
if (strncmp(ntmp->ntm_bootfile.bf_sysid, NTFS_BBID, NTFS_BBIDLEN)) {
|
|
|
|
error = EINVAL;
|
1999-09-14 00:21:45 +04:00
|
|
|
dprintf(("ntfs_mountfs: invalid boot block\n"));
|
1999-05-06 19:36:39 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
dprintf(("ntfs_mountfs(): bps: %d, spc: %d, media: %x, mftrecsz: %d (%d sects)\n",
|
|
|
|
ntmp->ntm_bps,ntmp->ntm_spc,ntmp->ntm_bootfile.bf_media,
|
|
|
|
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));
|
|
|
|
|
|
|
|
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;
|
2002-07-30 11:40:07 +04:00
|
|
|
mp->mnt_data = ntmp;
|
1999-05-06 19:36:39 +04:00
|
|
|
|
2001-02-13 22:53:52 +03:00
|
|
|
/* set file name encode/decode hooks XXX utf-8 only for now */
|
|
|
|
ntmp->ntm_wget = ntfs_utf8_wget;
|
|
|
|
ntmp->ntm_wput = ntfs_utf8_wput;
|
|
|
|
ntmp->ntm_wcmp = ntfs_utf8_wcmp;
|
|
|
|
|
1999-05-06 19:36:39 +04:00
|
|
|
dprintf(("ntfs_mountfs(): case-%s,%s uid: %d, gid: %d, mode: %o\n",
|
|
|
|
(ntmp->ntm_flag & NTFS_MFLAG_CASEINS)?"insens.":"sens.",
|
|
|
|
(ntmp->ntm_flag & NTFS_MFLAG_ALLNAMES)?" allnames,":"",
|
|
|
|
ntmp->ntm_uid, ntmp->ntm_gid, ntmp->ntm_mode));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We read in some system nodes to do not allow
|
|
|
|
* reclaim them and to have everytime access to them.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int pi[3] = { NTFS_MFTINO, NTFS_ROOTINO, NTFS_BITMAPINO };
|
|
|
|
for (i=0; i<3; i++) {
|
2003-06-29 22:43:21 +04:00
|
|
|
error = VFS_VGET(mp, pi[i], &(ntmp->ntm_sysvn[pi[i]]));
|
1999-05-06 19:36:39 +04:00
|
|
|
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-08-16 12:11:34 +04:00
|
|
|
/* read the Unicode lowercase --> uppercase translation table,
|
|
|
|
* if necessary */
|
|
|
|
if ((error = ntfs_toupper_use(mp, ntmp)))
|
1999-05-06 19:36:39 +04:00
|
|
|
goto out1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int num,j;
|
|
|
|
struct attrdef ad;
|
|
|
|
|
|
|
|
/* Open $AttrDef */
|
2003-06-30 02:28:00 +04:00
|
|
|
error = VFS_VGET(mp, NTFS_ATTRDEFINO, &vp );
|
1999-05-06 19:36:39 +04:00
|
|
|
if(error)
|
|
|
|
goto out1;
|
|
|
|
|
|
|
|
/* Count valid entries */
|
|
|
|
for(num=0;;num++) {
|
|
|
|
error = ntfs_readattr(ntmp, VTONT(vp),
|
|
|
|
NTFS_A_DATA, NULL,
|
|
|
|
num * sizeof(ad), sizeof(ad),
|
1999-09-05 14:45:03 +04:00
|
|
|
&ad, NULL);
|
1999-05-06 19:36:39 +04:00
|
|
|
if (error)
|
|
|
|
goto out1;
|
|
|
|
if (ad.ad_name[0] == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Alloc memory for attribute definitions */
|
2001-05-16 02:38:40 +04:00
|
|
|
ntmp->ntm_ad = (struct ntvattrdef *) malloc(
|
1999-05-06 19:36:39 +04:00
|
|
|
num * sizeof(struct ntvattrdef),
|
|
|
|
M_NTFSMNT, M_WAITOK);
|
|
|
|
|
|
|
|
ntmp->ntm_adnum = num;
|
|
|
|
|
|
|
|
/* Read them and translate */
|
|
|
|
for(i=0;i<num;i++){
|
|
|
|
error = ntfs_readattr(ntmp, VTONT(vp),
|
|
|
|
NTFS_A_DATA, NULL,
|
|
|
|
i * sizeof(ad), sizeof(ad),
|
1999-09-05 14:45:03 +04:00
|
|
|
&ad, NULL);
|
1999-05-06 19:36:39 +04: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
vput(vp);
|
|
|
|
}
|
|
|
|
|
1999-07-26 18:02:30 +04:00
|
|
|
#if defined(__FreeBSD__)
|
1999-07-26 18:35:19 +04:00
|
|
|
mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
|
1999-05-06 19:36:39 +04:00
|
|
|
mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
|
|
|
|
#else
|
2004-04-21 05:05:31 +04:00
|
|
|
mp->mnt_stat.f_fsidx.__fsid_val[0] = dev;
|
|
|
|
mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_NTFS);
|
|
|
|
mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
|
2004-09-13 23:25:48 +04:00
|
|
|
mp->mnt_stat.f_namemax = NTFS_MAXFILENAME;
|
1999-05-06 19:36:39 +04:00
|
|
|
#endif
|
|
|
|
mp->mnt_flag |= MNT_LOCAL;
|
|
|
|
devvp->v_specmountpoint = mp;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
out1:
|
|
|
|
for(i=0;i<NTFS_SYSNODESNUM;i++)
|
|
|
|
if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
|
|
|
|
|
|
|
|
if (vflush(mp,NULLVP,0))
|
1999-09-14 00:21:45 +04:00
|
|
|
dprintf(("ntfs_mountfs: vflush failed\n"));
|
1999-05-06 19:36:39 +04:00
|
|
|
|
|
|
|
out:
|
|
|
|
devvp->v_specmountpoint = NULL;
|
|
|
|
if (bp)
|
|
|
|
brelse(bp);
|
1999-10-17 14:18:15 +04:00
|
|
|
|
1999-05-06 19:36:39 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_start (
|
|
|
|
struct mount *mp,
|
|
|
|
int flags,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p )
|
1999-05-06 19:36:39 +04:00
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_unmount(
|
|
|
|
struct mount *mp,
|
|
|
|
int mntflags,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p)
|
1999-05-06 19:36:39 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct ntfsmount *ntmp;
|
1999-05-06 19:36:39 +04:00
|
|
|
int error, ronly = 0, flags, i;
|
|
|
|
|
|
|
|
dprintf(("ntfs_unmount: unmounting...\n"));
|
|
|
|
ntmp = VFSTONTFS(mp);
|
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
if(mntflags & MNT_FORCE)
|
|
|
|
flags |= FORCECLOSE;
|
|
|
|
|
|
|
|
dprintf(("ntfs_unmount: vflushing...\n"));
|
|
|
|
error = vflush(mp,NULLVP,flags | SKIPSYSTEM);
|
|
|
|
if (error) {
|
2001-02-10 17:28:51 +03:00
|
|
|
dprintf(("ntfs_unmount: vflush failed: %d\n",error));
|
1999-05-06 19:36:39 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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-08-16 12:11:34 +04:00
|
|
|
/* Dereference all system vnodes */
|
1999-05-06 19:36:39 +04:00
|
|
|
for(i=0;i<NTFS_SYSNODESNUM;i++)
|
|
|
|
if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
|
|
|
|
|
|
|
|
/* vflush system vnodes */
|
|
|
|
error = vflush(mp,NULLVP,flags);
|
2001-02-10 17:28:51 +03:00
|
|
|
if (error) {
|
|
|
|
/* XXX should this be panic() ? */
|
1999-05-06 19:36:39 +04:00
|
|
|
printf("ntfs_unmount: vflush failed(sysnodes): %d\n",error);
|
2001-02-10 17:28:51 +03:00
|
|
|
}
|
1999-05-06 19:36:39 +04:00
|
|
|
|
1999-10-25 23:08:26 +04: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.
|
|
|
|
*/
|
1999-10-20 18:32:09 +04:00
|
|
|
if (ntmp->ntm_devvp->v_type != VBAD)
|
1999-11-15 21:49:07 +03:00
|
|
|
ntmp->ntm_devvp->v_specmountpoint = NULL;
|
1999-05-06 19:36:39 +04:00
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
vinvalbuf(ntmp->ntm_devvp, V_SAVE, NOCRED, p, 0, 0);
|
1999-10-17 14:18:15 +04:00
|
|
|
|
|
|
|
/* lock the device vnode before calling VOP_CLOSE() */
|
2004-05-31 00:46:25 +04:00
|
|
|
vn_lock(ntmp->ntm_devvp, LK_EXCLUSIVE | LK_RETRY);
|
1999-05-06 19:36:39 +04:00
|
|
|
error = VOP_CLOSE(ntmp->ntm_devvp, ronly ? FREAD : FREAD|FWRITE,
|
2003-06-30 02:28:00 +04:00
|
|
|
NOCRED, p);
|
2003-04-09 20:18:17 +04:00
|
|
|
VOP_UNLOCK(ntmp->ntm_devvp, 0);
|
1999-05-06 19:36:39 +04:00
|
|
|
|
|
|
|
vrele(ntmp->ntm_devvp);
|
|
|
|
|
1999-08-16 12:11:34 +04:00
|
|
|
/* free the toupper table, if this has been last mounted ntfs volume */
|
|
|
|
ntfs_toupper_unuse();
|
|
|
|
|
1999-05-06 19:36:39 +04:00
|
|
|
dprintf(("ntfs_umount: freeing memory...\n"));
|
2002-07-30 11:40:07 +04:00
|
|
|
mp->mnt_data = NULL;
|
1999-05-06 19:36:39 +04:00
|
|
|
mp->mnt_flag &= ~MNT_LOCAL;
|
2001-05-16 02:38:40 +04:00
|
|
|
free(ntmp->ntm_ad, M_NTFSMNT);
|
1999-05-06 19:36:39 +04:00
|
|
|
FREE(ntmp, M_NTFSMNT);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_root(
|
|
|
|
struct mount *mp,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct vnode **vpp )
|
1999-05-06 19:36:39 +04:00
|
|
|
{
|
|
|
|
struct vnode *nvp;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
dprintf(("ntfs_root(): sysvn: %p\n",
|
|
|
|
VFSTONTFS(mp)->ntm_sysvn[NTFS_ROOTINO]));
|
2003-06-29 22:43:21 +04:00
|
|
|
error = VFS_VGET(mp, (ino_t)NTFS_ROOTINO, &nvp);
|
1999-05-06 19:36:39 +04:00
|
|
|
if(error) {
|
|
|
|
printf("ntfs_root: VFS_VGET failed: %d\n",error);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
*vpp = nvp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2003-08-02 16:11:56 +04:00
|
|
|
/*
|
|
|
|
* Do operations associated with quotas, not supported
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
1999-05-06 19:36:39 +04:00
|
|
|
static int
|
|
|
|
ntfs_quotactl (
|
|
|
|
struct mount *mp,
|
|
|
|
int cmds,
|
|
|
|
uid_t uid,
|
2004-04-27 21:37:30 +04:00
|
|
|
void *arg,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p)
|
1999-05-06 19:36:39 +04:00
|
|
|
{
|
2003-08-02 16:11:56 +04:00
|
|
|
|
1999-05-06 19:36:39 +04:00
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ntfs_calccfree(
|
|
|
|
struct ntfsmount *ntmp,
|
|
|
|
cn_t *cfreep)
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
u_int8_t *tmp;
|
|
|
|
int j, error;
|
2004-02-22 11:18:11 +03:00
|
|
|
cn_t cfree = 0;
|
1999-05-06 19:36:39 +04:00
|
|
|
size_t bmsize, i;
|
|
|
|
|
|
|
|
vp = ntmp->ntm_sysvn[NTFS_BITMAPINO];
|
|
|
|
|
|
|
|
bmsize = VTOF(vp)->f_size;
|
|
|
|
|
2001-05-16 02:38:40 +04:00
|
|
|
tmp = (u_int8_t *) malloc(bmsize, M_TEMP, M_WAITOK);
|
1999-05-06 19:36:39 +04:00
|
|
|
|
|
|
|
error = ntfs_readattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL,
|
1999-09-05 14:45:03 +04:00
|
|
|
0, bmsize, tmp, NULL);
|
1999-08-16 12:11:34 +04:00
|
|
|
if (error)
|
|
|
|
goto out;
|
1999-05-06 19:36:39 +04:00
|
|
|
|
|
|
|
for(i=0;i<bmsize;i++)
|
|
|
|
for(j=0;j<8;j++)
|
|
|
|
if(~tmp[i] & (1 << j)) cfree++;
|
|
|
|
*cfreep = cfree;
|
|
|
|
|
1999-08-16 12:11:34 +04:00
|
|
|
out:
|
2001-05-16 02:38:40 +04:00
|
|
|
free(tmp, M_TEMP);
|
1999-08-16 12:11:34 +04:00
|
|
|
return(error);
|
1999-05-06 19:36:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-04-21 05:05:31 +04:00
|
|
|
ntfs_statvfs(
|
1999-05-06 19:36:39 +04:00
|
|
|
struct mount *mp,
|
2004-04-21 05:05:31 +04:00
|
|
|
struct statvfs *sbp,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p)
|
1999-05-06 19:36:39 +04:00
|
|
|
{
|
|
|
|
struct ntfsmount *ntmp = VFSTONTFS(mp);
|
2001-11-06 10:15:34 +03:00
|
|
|
u_int64_t mftallocated;
|
1999-05-06 19:36:39 +04:00
|
|
|
|
2004-04-21 05:05:31 +04:00
|
|
|
dprintf(("ntfs_statvfs():\n"));
|
1999-05-06 19:36:39 +04:00
|
|
|
|
|
|
|
mftallocated = VTOF(ntmp->ntm_sysvn[NTFS_MFTINO])->f_allocated;
|
|
|
|
|
1999-07-26 18:02:30 +04:00
|
|
|
#if defined(__FreeBSD__)
|
1999-05-06 19:36:39 +04:00
|
|
|
sbp->f_type = mp->mnt_vfc->vfc_typenum;
|
|
|
|
#endif
|
|
|
|
sbp->f_bsize = ntmp->ntm_bps;
|
2004-04-21 05:05:31 +04:00
|
|
|
sbp->f_frsize = sbp->f_bsize; /* XXX */
|
1999-05-06 19:36:39 +04:00
|
|
|
sbp->f_iosize = ntmp->ntm_bps * ntmp->ntm_spc;
|
|
|
|
sbp->f_blocks = ntmp->ntm_bootfile.bf_spv;
|
|
|
|
sbp->f_bfree = sbp->f_bavail = ntfs_cntobn(ntmp->ntm_cfree);
|
2004-04-21 05:05:31 +04:00
|
|
|
sbp->f_ffree = sbp->f_favail = sbp->f_bfree / ntmp->ntm_bpmftrec;
|
1999-05-06 19:36:39 +04:00
|
|
|
sbp->f_files = mftallocated / ntfs_bntob(ntmp->ntm_bpmftrec) +
|
2004-04-21 05:05:31 +04:00
|
|
|
sbp->f_ffree;
|
|
|
|
sbp->f_fresvd = sbp->f_bresvd = 0; /* XXX */
|
|
|
|
sbp->f_flag = mp->mnt_flag;
|
|
|
|
copy_statvfs_info(sbp, mp);
|
1999-05-06 19:36:39 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_sync (
|
|
|
|
struct mount *mp,
|
|
|
|
int waitfor,
|
|
|
|
struct ucred *cred,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p)
|
1999-05-06 19:36:39 +04:00
|
|
|
{
|
|
|
|
/*dprintf(("ntfs_sync():\n"));*/
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-05-06 19:43:17 +04:00
|
|
|
/*ARGSUSED*/
|
1999-05-06 19:36:39 +04:00
|
|
|
static int
|
|
|
|
ntfs_fhtovp(
|
1999-07-26 18:02:30 +04:00
|
|
|
#if defined(__FreeBSD__)
|
1999-05-06 19:36:39 +04:00
|
|
|
struct mount *mp,
|
|
|
|
struct fid *fhp,
|
|
|
|
struct sockaddr *nam,
|
|
|
|
struct vnode **vpp,
|
|
|
|
int *exflagsp,
|
|
|
|
struct ucred **credanonp)
|
1999-05-06 19:43:17 +04:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
struct mount *mp,
|
|
|
|
struct fid *fhp,
|
2003-06-29 22:43:21 +04:00
|
|
|
struct vnode **vpp)
|
1999-05-06 19:36:39 +04:00
|
|
|
#else
|
|
|
|
struct mount *mp,
|
|
|
|
struct fid *fhp,
|
|
|
|
struct mbuf *nam,
|
|
|
|
struct vnode **vpp,
|
|
|
|
int *exflagsp,
|
|
|
|
struct ucred **credanonp)
|
|
|
|
#endif
|
|
|
|
{
|
1999-09-10 20:14:02 +04:00
|
|
|
struct ntfid *ntfhp = (struct ntfid *)fhp;
|
|
|
|
int error;
|
|
|
|
|
2001-03-29 14:47:44 +04:00
|
|
|
ddprintf(("ntfs_fhtovp(): %s: %d\n", mp->mnt_stat.f_mntonname,
|
1999-09-10 20:14:02 +04:00
|
|
|
ntfhp->ntfid_ino));
|
|
|
|
|
2000-02-08 19:17:58 +03:00
|
|
|
error = ntfs_vgetex(mp, ntfhp->ntfid_ino, ntfhp->ntfid_attr, NULL,
|
2003-06-30 02:28:00 +04:00
|
|
|
LK_EXCLUSIVE | LK_RETRY, 0, curproc, vpp); /* XXX */
|
2000-02-08 19:17:58 +03:00
|
|
|
if (error != 0) {
|
1999-09-10 20:14:02 +04:00
|
|
|
*vpp = NULLVP;
|
|
|
|
return (error);
|
|
|
|
}
|
2000-02-08 19:17:58 +03:00
|
|
|
|
1999-09-10 20:14:02 +04:00
|
|
|
/* XXX as unlink/rmdir/mkdir/creat are not currently possible
|
|
|
|
* with NTFS, we don't need to check anything else for now */
|
|
|
|
return (0);
|
1999-05-06 19:36:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_vptofh(
|
|
|
|
struct vnode *vp,
|
|
|
|
struct fid *fhp)
|
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct ntnode *ntp;
|
|
|
|
struct ntfid *ntfhp;
|
2000-02-08 19:17:58 +03:00
|
|
|
struct fnode *fn;
|
1999-09-10 20:14:02 +04:00
|
|
|
|
2001-03-29 14:47:44 +04:00
|
|
|
ddprintf(("ntfs_fhtovp(): %s: %p\n", vp->v_mount->mnt_stat.f_mntonname,
|
1999-09-10 20:14:02 +04:00
|
|
|
vp));
|
|
|
|
|
2000-02-08 19:17:58 +03:00
|
|
|
fn = VTOF(vp);
|
1999-09-10 20:14:02 +04:00
|
|
|
ntp = VTONT(vp);
|
|
|
|
ntfhp = (struct ntfid *)fhp;
|
|
|
|
ntfhp->ntfid_len = sizeof(struct ntfid);
|
|
|
|
ntfhp->ntfid_ino = ntp->i_number;
|
2000-02-08 19:17:58 +03:00
|
|
|
ntfhp->ntfid_attr = fn->f_attrtype;
|
|
|
|
#ifdef notyet
|
|
|
|
ntfhp->ntfid_gen = ntp->i_gen;
|
|
|
|
#endif
|
1999-09-10 20:14:02 +04:00
|
|
|
return (0);
|
1999-05-06 19:36:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ntfs_vgetex(
|
|
|
|
struct mount *mp,
|
|
|
|
ino_t ino,
|
|
|
|
u_int32_t attrtype,
|
|
|
|
char *attrname,
|
|
|
|
u_long lkflags,
|
|
|
|
u_long flags,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p,
|
1999-05-06 19:36:39 +04:00
|
|
|
struct vnode **vpp)
|
|
|
|
{
|
|
|
|
int error;
|
2000-03-30 16:41:09 +04:00
|
|
|
struct ntfsmount *ntmp;
|
1999-05-06 19:36:39 +04:00
|
|
|
struct ntnode *ip;
|
|
|
|
struct fnode *fp;
|
|
|
|
struct vnode *vp;
|
2003-10-25 23:10:34 +04:00
|
|
|
enum vtype f_type = VBAD;
|
1999-05-06 19:36:39 +04:00
|
|
|
|
1999-07-29 00:42:54 +04: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-05-06 19:36:39 +04:00
|
|
|
|
|
|
|
ntmp = VFSTONTFS(mp);
|
|
|
|
*vpp = NULL;
|
|
|
|
|
|
|
|
/* Get ntnode */
|
|
|
|
error = ntfs_ntlookup(ntmp, ino, &ip);
|
|
|
|
if (error) {
|
|
|
|
printf("ntfs_vget: ntfs_ntget failed\n");
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error = ntfs_fget(ntmp, ip, attrtype, attrname, &fp);
|
|
|
|
if (error) {
|
|
|
|
printf("ntfs_vget: ntfs_fget failed\n");
|
|
|
|
ntfs_ntput(ip);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(flags & VG_DONTVALIDFN) && !(fp->f_flag & FN_VALID)) {
|
|
|
|
if ((ip->i_frflag & NTFS_FRFLAG_DIR) &&
|
1999-10-25 23:08:26 +04:00
|
|
|
(fp->f_attrtype == NTFS_A_DATA && fp->f_attrname == NULL)) {
|
1999-10-09 18:27:42 +04:00
|
|
|
f_type = VDIR;
|
1999-10-25 23:08:26 +04:00
|
|
|
} else if (flags & VG_EXT) {
|
1999-10-09 18:27:42 +04:00
|
|
|
f_type = VNON;
|
1999-10-25 23:08:26 +04:00
|
|
|
fp->f_size = fp->f_allocated = 0;
|
1999-05-06 19:36:39 +04:00
|
|
|
} else {
|
1999-10-09 18:27:42 +04:00
|
|
|
f_type = VREG;
|
1999-05-06 19:36:39 +04:00
|
|
|
|
|
|
|
error = ntfs_filesize(ntmp, fp,
|
|
|
|
&fp->f_size, &fp->f_allocated);
|
|
|
|
if (error) {
|
|
|
|
ntfs_ntput(ip);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fp->f_flag |= FN_VALID;
|
|
|
|
}
|
|
|
|
|
2001-06-20 02:14:14 +04:00
|
|
|
/*
|
|
|
|
* We may be calling vget() now. To avoid potential deadlock, we need
|
|
|
|
* to release ntnode lock, since due to locking order vnode
|
|
|
|
* lock has to be acquired first.
|
|
|
|
* ntfs_fget() bumped ntnode usecount, so ntnode won't be recycled
|
|
|
|
* prematurely.
|
|
|
|
*/
|
|
|
|
ntfs_ntput(ip);
|
|
|
|
|
1999-05-06 19:36:39 +04:00
|
|
|
if (FTOV(fp)) {
|
2001-06-20 02:14:14 +04:00
|
|
|
/* vget() returns error if the vnode has been recycled */
|
2003-06-29 22:43:21 +04:00
|
|
|
if (vget(FTOV(fp), lkflags) == 0) {
|
2001-06-20 02:14:14 +04:00
|
|
|
*vpp = FTOV(fp);
|
|
|
|
return (0);
|
|
|
|
}
|
1999-05-06 19:36:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
error = getnewvnode(VT_NTFS, ntmp->ntm_mountp, ntfs_vnodeop_p, &vp);
|
|
|
|
if(error) {
|
|
|
|
ntfs_frele(fp);
|
|
|
|
ntfs_ntput(ip);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
dprintf(("ntfs_vget: vnode: %p for ntnode: %d\n", vp,ino));
|
|
|
|
|
1999-09-29 19:58:28 +04:00
|
|
|
#ifdef __FreeBSD__
|
1999-05-06 19:36:39 +04:00
|
|
|
lockinit(&fp->f_lock, PINOD, "fnode", 0, 0);
|
1999-09-29 19:58:28 +04:00
|
|
|
#endif
|
1999-05-06 19:36:39 +04:00
|
|
|
fp->f_vp = vp;
|
|
|
|
vp->v_data = fp;
|
2003-11-11 03:44:16 +03:00
|
|
|
if (f_type != VBAD)
|
|
|
|
vp->v_type = f_type;
|
1999-05-06 19:36:39 +04:00
|
|
|
|
|
|
|
if (ino == NTFS_ROOTINO)
|
|
|
|
vp->v_flag |= VROOT;
|
|
|
|
|
|
|
|
if (lkflags & LK_TYPE_MASK) {
|
2003-04-09 20:18:17 +04:00
|
|
|
error = vn_lock(vp, lkflags);
|
1999-05-06 19:36:39 +04:00
|
|
|
if (error) {
|
|
|
|
vput(vp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-18 10:51:16 +03:00
|
|
|
genfs_node_init(vp, &ntfs_genfsops);
|
1999-10-09 18:27:42 +04:00
|
|
|
VREF(ip->i_devvp);
|
1999-05-06 19:36:39 +04:00
|
|
|
*vpp = vp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ntfs_vget(
|
|
|
|
struct mount *mp,
|
|
|
|
ino_t ino,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct vnode **vpp)
|
1999-05-06 19:36:39 +04:00
|
|
|
{
|
|
|
|
return ntfs_vgetex(mp, ino, NTFS_A_DATA, NULL,
|
2003-06-30 02:28:00 +04:00
|
|
|
LK_EXCLUSIVE | LK_RETRY, 0, curproc, vpp); /* XXX */
|
1999-05-06 19:36:39 +04:00
|
|
|
}
|
|
|
|
|
1999-07-26 18:02:30 +04:00
|
|
|
#if defined(__FreeBSD__)
|
1999-05-06 19:36:39 +04:00
|
|
|
static struct vfsops ntfs_vfsops = {
|
|
|
|
ntfs_mount,
|
|
|
|
ntfs_start,
|
|
|
|
ntfs_unmount,
|
|
|
|
ntfs_root,
|
|
|
|
ntfs_quotactl,
|
2004-04-21 05:05:31 +04:00
|
|
|
ntfs_statvfs,
|
1999-05-06 19:36:39 +04:00
|
|
|
ntfs_sync,
|
|
|
|
ntfs_vget,
|
|
|
|
ntfs_fhtovp,
|
|
|
|
ntfs_vptofh,
|
|
|
|
ntfs_init,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
VFS_SET(ntfs_vfsops, ntfs, 0);
|
1999-05-06 19:43:17 +04:00
|
|
|
#elif defined(__NetBSD__)
|
2001-01-22 15:17:35 +03:00
|
|
|
extern const struct vnodeopv_desc ntfs_vnodeop_opv_desc;
|
1999-05-06 19:43:17 +04:00
|
|
|
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_desc * const ntfs_vnodeopv_descs[] = {
|
1999-05-06 19:43:17 +04:00
|
|
|
&ntfs_vnodeop_opv_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vfsops ntfs_vfsops = {
|
|
|
|
MOUNT_NTFS,
|
|
|
|
ntfs_mount,
|
|
|
|
ntfs_start,
|
|
|
|
ntfs_unmount,
|
|
|
|
ntfs_root,
|
|
|
|
ntfs_quotactl,
|
2004-04-21 05:05:31 +04:00
|
|
|
ntfs_statvfs,
|
1999-05-06 19:43:17 +04:00
|
|
|
ntfs_sync,
|
|
|
|
ntfs_vget,
|
|
|
|
ntfs_fhtovp,
|
|
|
|
ntfs_vptofh,
|
|
|
|
ntfs_init,
|
2001-09-15 20:12:54 +04:00
|
|
|
ntfs_reinit,
|
2000-03-16 21:08:17 +03:00
|
|
|
ntfs_done,
|
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
|
|
|
NULL,
|
1999-05-06 19:43:17 +04:00
|
|
|
ntfs_mountroot,
|
|
|
|
ntfs_checkexp,
|
2004-05-25 18:54:55 +04:00
|
|
|
(int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
|
2005-01-02 19:08:28 +03:00
|
|
|
vfs_stdextattrctl,
|
1999-05-06 19:43:17 +04:00
|
|
|
ntfs_vnodeopv_descs,
|
|
|
|
};
|
1999-05-06 19:36:39 +04:00
|
|
|
#endif
|