2006-11-02 20:34:21 +03:00
|
|
|
/* $NetBSD: smbfs_vfsops.c,v 1.59 2006/11/02 17:34:21 jmmv Exp $ */
|
2002-01-09 20:43:28 +03:00
|
|
|
|
2002-01-09 20:25:32 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2000-2001, Boris Popov
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Boris Popov.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2002-01-09 20:43:28 +03:00
|
|
|
* FreeBSD: src/sys/fs/smbfs/smbfs_vfsops.c,v 1.5 2001/12/13 13:08:34 sheldonh Exp
|
2002-01-09 20:25:32 +03:00
|
|
|
*/
|
|
|
|
|
2003-02-25 12:09:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2006-11-02 20:34:21 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: smbfs_vfsops.c,v 1.59 2006/11/02 17:34:21 jmmv Exp $");
|
2003-06-23 15:00:59 +04:00
|
|
|
|
2003-06-23 18:59:21 +04:00
|
|
|
#ifdef _KERNEL_OPT
|
2003-06-23 15:00:59 +04:00
|
|
|
#include "opt_quota.h"
|
2003-06-23 18:59:21 +04:00
|
|
|
#endif
|
2003-02-25 12:09:31 +03:00
|
|
|
|
2002-01-09 20:25:32 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-04-26 21:08:34 +04:00
|
|
|
#include <sys/dirent.h>
|
2002-01-09 20:25:32 +03:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/malloc.h>
|
2006-05-15 01:31:52 +04:00
|
|
|
#include <sys/kauth.h>
|
2002-01-09 20:25:32 +03:00
|
|
|
|
|
|
|
|
|
|
|
#include <netsmb/smb.h>
|
|
|
|
#include <netsmb/smb_conn.h>
|
|
|
|
#include <netsmb/smb_subr.h>
|
|
|
|
#include <netsmb/smb_dev.h>
|
|
|
|
|
|
|
|
#include <fs/smbfs/smbfs.h>
|
|
|
|
#include <fs/smbfs/smbfs_node.h>
|
|
|
|
#include <fs/smbfs/smbfs_subr.h>
|
|
|
|
|
2002-01-09 20:43:28 +03:00
|
|
|
#ifndef __NetBSD__
|
2002-01-09 20:25:32 +03:00
|
|
|
SYSCTL_NODE(_vfs, OID_AUTO, smbfs, CTLFLAG_RW, 0, "SMB/CIFS file system");
|
|
|
|
SYSCTL_INT(_vfs_smbfs, OID_AUTO, version, CTLFLAG_RD, &smbfs_version, 0, "");
|
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
|
|
|
#else
|
|
|
|
SYSCTL_SETUP(sysctl_vfs_samba_setup, "sysctl vfs.samba subtree setup")
|
|
|
|
{
|
2005-06-20 06:49:18 +04:00
|
|
|
const struct sysctlnode *smb = NULL;
|
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, &smb,
|
|
|
|
CTLFLAG_PERMANENT,
|
2004-05-25 08:44:43 +04:00
|
|
|
CTLTYPE_NODE, "samba",
|
|
|
|
SYSCTL_DESCR("SMB/CIFS remote 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,
|
2004-03-24 18:34:46 +03:00
|
|
|
CTL_VFS, CTL_CREATE, CTL_EOL);
|
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
|
|
|
if (smb != NULL)
|
|
|
|
sysctl_createv(clog, 0, &smb, NULL,
|
|
|
|
CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
|
2004-05-25 08:44:43 +04:00
|
|
|
CTLTYPE_INT, "version",
|
|
|
|
SYSCTL_DESCR("smbfs version"),
|
2004-03-24 18:34:46 +03:00
|
|
|
NULL, SMBFS_VERSION, NULL, 0,
|
|
|
|
CTL_CREATE, CTL_EOL);
|
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
|
|
|
}
|
2003-02-01 09:23:35 +03:00
|
|
|
#endif
|
2002-01-09 20:25:32 +03:00
|
|
|
|
|
|
|
static MALLOC_DEFINE(M_SMBFSHASH, "SMBFS hash", "SMBFS hash table");
|
|
|
|
|
2002-01-09 20:43:28 +03:00
|
|
|
int smbfs_mount(struct mount *, const char *, void *,
|
2005-12-11 15:16:03 +03:00
|
|
|
struct nameidata *, struct lwp *);
|
|
|
|
int smbfs_quotactl(struct mount *, int, uid_t, void *, struct lwp *);
|
2003-06-29 22:43:21 +04:00
|
|
|
int smbfs_root(struct mount *, struct vnode **);
|
2003-02-26 21:16:37 +03:00
|
|
|
static int smbfs_setroot(struct mount *);
|
2005-12-11 15:16:03 +03:00
|
|
|
int smbfs_start(struct mount *, int, struct lwp *);
|
|
|
|
int smbfs_statvfs(struct mount *, struct statvfs *, struct lwp *);
|
2006-05-15 01:31:52 +04:00
|
|
|
int smbfs_sync(struct mount *, int, kauth_cred_t, struct lwp *);
|
2005-12-11 15:16:03 +03:00
|
|
|
int smbfs_unmount(struct mount *, int, struct lwp *);
|
2002-01-09 20:43:28 +03:00
|
|
|
void smbfs_init(void);
|
|
|
|
void smbfs_reinit(void);
|
2003-02-24 21:41:04 +03:00
|
|
|
void smbfs_done(void);
|
2002-01-09 20:43:28 +03:00
|
|
|
|
2003-06-29 22:43:21 +04:00
|
|
|
int smbfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp);
|
2002-01-09 20:25:32 +03:00
|
|
|
|
2004-04-25 20:42:40 +04:00
|
|
|
POOL_INIT(smbfs_node_pool, sizeof(struct smbnode), 0, 0, 0, "smbfsnopl",
|
|
|
|
&pool_allocator_nointr);
|
2002-01-09 20:43:28 +03:00
|
|
|
extern struct vnodeopv_desc smbfs_vnodeop_opv_desc;
|
|
|
|
|
2003-02-24 21:41:04 +03:00
|
|
|
static const struct vnodeopv_desc *smbfs_vnodeopv_descs[] = {
|
2002-01-09 20:43:28 +03:00
|
|
|
&smbfs_vnodeop_opv_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
2002-01-09 20:25:32 +03:00
|
|
|
|
2002-01-09 20:43:28 +03:00
|
|
|
struct vfsops smbfs_vfsops = {
|
|
|
|
MOUNT_SMBFS,
|
2002-01-09 20:25:32 +03:00
|
|
|
smbfs_mount,
|
|
|
|
smbfs_start,
|
|
|
|
smbfs_unmount,
|
|
|
|
smbfs_root,
|
|
|
|
smbfs_quotactl,
|
2004-04-21 05:05:31 +04:00
|
|
|
smbfs_statvfs,
|
2002-01-09 20:25:32 +03:00
|
|
|
smbfs_sync,
|
|
|
|
smbfs_vget,
|
Apply the NFS exports list rototill patch:
- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.
Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
2005-09-23 16:10:31 +04:00
|
|
|
NULL, /* vfs_fhtovp */
|
|
|
|
NULL, /* vfs_vptofh */
|
2002-01-09 20:25:32 +03:00
|
|
|
smbfs_init,
|
2002-01-09 20:43:28 +03:00
|
|
|
smbfs_reinit,
|
2003-02-24 21:41:04 +03:00
|
|
|
smbfs_done,
|
2002-01-09 20:43:28 +03:00
|
|
|
(int (*) (void)) eopnotsupp, /* mountroot */
|
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,
|
2002-01-09 20:43:28 +03:00
|
|
|
smbfs_vnodeopv_descs,
|
2006-09-03 09:27:28 +04:00
|
|
|
0, /* vfs_refcount */
|
|
|
|
{ NULL, NULL },
|
2002-01-09 20:25:32 +03:00
|
|
|
};
|
2005-03-29 06:41:05 +04:00
|
|
|
VFS_ATTACH(smbfs_vfsops);
|
2002-01-09 20:25:32 +03:00
|
|
|
|
2002-01-09 20:43:28 +03:00
|
|
|
int
|
|
|
|
smbfs_mount(struct mount *mp, const char *path, void *data,
|
2006-10-12 05:30:41 +04:00
|
|
|
struct nameidata *ndp __unused, struct lwp *l)
|
2002-01-09 20:25:32 +03:00
|
|
|
{
|
|
|
|
struct smbfs_args args; /* will hold data from mount request */
|
|
|
|
struct smbmount *smp = NULL;
|
|
|
|
struct smb_vc *vcp;
|
|
|
|
struct smb_share *ssp = NULL;
|
|
|
|
struct smb_cred scred;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct proc *p;
|
2002-01-09 20:25:32 +03:00
|
|
|
int error;
|
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
p = l->l_proc;
|
2002-09-21 22:10:34 +04:00
|
|
|
if (mp->mnt_flag & MNT_GETARGS) {
|
|
|
|
smp = VFSTOSMBFS(mp);
|
|
|
|
if (smp == NULL)
|
|
|
|
return EIO;
|
|
|
|
return copyout(&smp->sm_args, data, sizeof(smp->sm_args));
|
|
|
|
}
|
2003-02-16 22:35:16 +03:00
|
|
|
|
|
|
|
if (mp->mnt_flag & MNT_UPDATE)
|
2002-01-09 20:25:32 +03:00
|
|
|
return EOPNOTSUPP;
|
2003-02-16 22:35:16 +03:00
|
|
|
|
2004-05-04 17:26:58 +04:00
|
|
|
error = copyin(data, &args, sizeof(struct smbfs_args));
|
2002-01-09 20:25:32 +03:00
|
|
|
if (error)
|
|
|
|
return error;
|
2003-02-16 22:35:16 +03:00
|
|
|
|
2002-01-09 20:25:32 +03:00
|
|
|
if (args.version != SMBFS_VERSION) {
|
2004-03-21 16:43:46 +03:00
|
|
|
SMBVDEBUG("mount version mismatch: kernel=%d, mount=%d\n",
|
2002-01-09 20:25:32 +03:00
|
|
|
SMBFS_VERSION, args.version);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2006-07-24 02:06:03 +04:00
|
|
|
smb_makescred(&scred, l, l->l_cred);
|
2003-02-24 01:31:17 +03:00
|
|
|
error = smb_dev2share(args.dev_fd, SMBM_EXEC, &scred, &ssp);
|
2003-02-18 13:27:17 +03:00
|
|
|
if (error)
|
2002-01-09 20:25:32 +03:00
|
|
|
return error;
|
2003-02-24 12:57:31 +03:00
|
|
|
smb_share_unlock(ssp, 0); /* keep ref, but unlock */
|
2003-02-18 13:27:17 +03:00
|
|
|
vcp = SSTOVC(ssp);
|
|
|
|
mp->mnt_stat.f_iosize = vcp->vc_txmax;
|
2004-09-13 23:25:48 +04:00
|
|
|
mp->mnt_stat.f_namemax =
|
|
|
|
(vcp->vc_hflags2 & SMB_FLAGS2_KNOWS_LONG_NAMES) ? 255 : 12;
|
2002-01-09 20:25:32 +03:00
|
|
|
|
2003-02-24 21:41:04 +03:00
|
|
|
MALLOC(smp, struct smbmount *, sizeof(*smp), M_SMBFSDATA, M_WAITOK);
|
2003-02-16 22:35:16 +03:00
|
|
|
memset(smp, 0, sizeof(*smp));
|
2003-02-24 21:41:04 +03:00
|
|
|
mp->mnt_data = smp;
|
2003-02-18 13:27:17 +03:00
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
smp->sm_hash = hashinit(desiredvnodes, HASH_LIST,
|
2002-01-09 20:43:28 +03:00
|
|
|
M_SMBFSHASH, M_WAITOK, &smp->sm_hashlen);
|
2003-02-18 13:27:17 +03:00
|
|
|
|
2002-01-09 20:25:32 +03:00
|
|
|
lockinit(&smp->sm_hashlock, PVFS, "smbfsh", 0, 0);
|
|
|
|
smp->sm_share = ssp;
|
|
|
|
smp->sm_root = NULL;
|
2003-02-24 21:41:04 +03:00
|
|
|
smp->sm_args = args;
|
2002-01-09 20:25:32 +03:00
|
|
|
smp->sm_caseopt = args.caseopt;
|
|
|
|
smp->sm_args.file_mode = (smp->sm_args.file_mode &
|
|
|
|
(S_IRWXU|S_IRWXG|S_IRWXO)) | S_IFREG;
|
|
|
|
smp->sm_args.dir_mode = (smp->sm_args.dir_mode &
|
|
|
|
(S_IRWXU|S_IRWXG|S_IRWXO)) | S_IFDIR;
|
|
|
|
|
2004-04-21 05:05:31 +04:00
|
|
|
error = set_statvfs_info(path, UIO_USERSPACE, NULL, UIO_USERSPACE,
|
2005-12-11 15:16:03 +03:00
|
|
|
mp, l);
|
2002-01-09 20:25:32 +03:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
2003-02-16 22:35:16 +03:00
|
|
|
memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN);
|
|
|
|
snprintf(mp->mnt_stat.f_mntfromname, MNAMELEN,
|
2003-04-17 01:44:18 +04:00
|
|
|
"//%s@%s/%s", vcp->vc_username, vcp->vc_srvname, ssp->ss_name);
|
2003-02-16 22:35:16 +03:00
|
|
|
|
2002-01-09 20:25:32 +03:00
|
|
|
vfs_getnewfsid(mp);
|
2003-02-18 13:27:17 +03:00
|
|
|
return (0);
|
2003-02-16 22:35:16 +03:00
|
|
|
|
2002-01-09 20:25:32 +03:00
|
|
|
bad:
|
2003-02-24 21:41:04 +03:00
|
|
|
if (smp) {
|
2002-01-09 20:25:32 +03:00
|
|
|
if (smp->sm_hash)
|
|
|
|
free(smp->sm_hash, M_SMBFSHASH);
|
2003-02-18 22:40:36 +03:00
|
|
|
#ifdef __NetBSD__
|
|
|
|
lockmgr(&smp->sm_hashlock, LK_DRAIN, NULL);
|
|
|
|
#else
|
2002-01-09 20:25:32 +03:00
|
|
|
lockdestroy(&smp->sm_hashlock);
|
2002-01-09 20:43:28 +03:00
|
|
|
#endif
|
2003-02-24 21:41:04 +03:00
|
|
|
FREE(smp, M_SMBFSDATA);
|
2002-01-09 20:25:32 +03:00
|
|
|
}
|
2003-02-24 12:57:31 +03:00
|
|
|
if (ssp) {
|
|
|
|
smb_share_lock(smp->sm_share, 0);
|
2002-01-09 20:25:32 +03:00
|
|
|
smb_share_put(ssp, &scred);
|
2003-02-24 12:57:31 +03:00
|
|
|
}
|
2003-02-24 21:41:04 +03:00
|
|
|
return error;
|
2002-01-09 20:25:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Unmount the filesystem described by mp. */
|
2002-01-09 20:43:28 +03:00
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
smbfs_unmount(struct mount *mp, int mntflags, struct lwp *l)
|
2002-01-09 20:25:32 +03:00
|
|
|
{
|
|
|
|
struct smbmount *smp = VFSTOSMBFS(mp);
|
|
|
|
struct smb_cred scred;
|
|
|
|
int error, flags;
|
|
|
|
|
|
|
|
SMBVDEBUG("smbfs_unmount: flags=%04x\n", mntflags);
|
|
|
|
flags = 0;
|
|
|
|
if (mntflags & MNT_FORCE)
|
|
|
|
flags |= FORCECLOSE;
|
2003-02-18 22:40:36 +03:00
|
|
|
#ifdef QUOTA
|
|
|
|
#endif
|
|
|
|
/* Drop the extra reference to root vnode. */
|
2003-02-26 23:21:40 +03:00
|
|
|
if (smp->sm_root) {
|
|
|
|
vrele(SMBTOV(smp->sm_root));
|
|
|
|
smp->sm_root = NULL;
|
|
|
|
}
|
2003-02-18 22:40:36 +03:00
|
|
|
|
2006-11-02 20:34:21 +03:00
|
|
|
/* Flush all vnodes.
|
|
|
|
* Keep trying to flush the vnode list for the mount while
|
|
|
|
* some are still busy and we are making progress towards
|
|
|
|
* making them not busy. This is needed because smbfs vnodes
|
|
|
|
* reference their parent directory but may appear after their
|
|
|
|
* parent in the list; one pass over the vnode list is not
|
|
|
|
* sufficient in this case. */
|
|
|
|
do {
|
|
|
|
smp->sm_didrele = 0;
|
|
|
|
error = vflush(mp, NULLVP, flags);
|
|
|
|
} while (error == EBUSY && smp->sm_didrele != 0);
|
2003-02-18 22:40:36 +03:00
|
|
|
|
2006-07-24 02:06:03 +04:00
|
|
|
smb_makescred(&scred, l, l->l_cred);
|
2003-02-24 12:57:31 +03:00
|
|
|
smb_share_lock(smp->sm_share, 0);
|
2002-01-09 20:25:32 +03:00
|
|
|
smb_share_put(smp->sm_share, &scred);
|
2002-07-30 11:40:07 +04:00
|
|
|
mp->mnt_data = NULL;
|
2002-01-09 20:25:32 +03:00
|
|
|
|
2003-02-26 21:16:37 +03:00
|
|
|
free(smp->sm_hash, M_SMBFSHASH);
|
2003-02-18 22:40:36 +03:00
|
|
|
#ifdef __NetBSD__
|
|
|
|
lockmgr(&smp->sm_hashlock, LK_DRAIN, NULL);
|
|
|
|
#else
|
2002-01-09 20:25:32 +03:00
|
|
|
lockdestroy(&smp->sm_hashlock);
|
2002-01-09 20:43:28 +03:00
|
|
|
#endif
|
2003-02-24 21:41:04 +03:00
|
|
|
FREE(smp, M_SMBFSDATA);
|
2002-01-09 20:25:32 +03:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2003-02-26 21:16:37 +03:00
|
|
|
/*
|
|
|
|
* Get root vnode of the smbfs filesystem, and store it in sm_root.
|
2002-01-09 20:25:32 +03:00
|
|
|
*/
|
2003-02-26 21:16:37 +03:00
|
|
|
static int
|
|
|
|
smbfs_setroot(struct mount *mp)
|
2002-01-09 20:25:32 +03:00
|
|
|
{
|
|
|
|
struct smbmount *smp = VFSTOSMBFS(mp);
|
|
|
|
struct vnode *vp;
|
|
|
|
struct smbfattr fattr;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l = curlwp;
|
2006-07-24 02:06:03 +04:00
|
|
|
kauth_cred_t cred = l->l_cred;
|
2002-01-09 20:25:32 +03:00
|
|
|
struct smb_cred scred;
|
|
|
|
int error;
|
|
|
|
|
2003-02-26 21:16:37 +03:00
|
|
|
KASSERT(smp->sm_root == NULL);
|
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
smb_makescred(&scred, l, cred);
|
2002-01-09 20:25:32 +03:00
|
|
|
error = smbfs_smb_lookup(NULL, NULL, 0, &fattr, &scred);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = smbfs_nget(mp, NULL, "TheRooT", 7, &fattr, &vp);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2003-02-26 21:16:37 +03:00
|
|
|
|
2003-02-26 23:21:40 +03:00
|
|
|
/*
|
|
|
|
* Someone might have already set sm_root while we slept
|
|
|
|
* in smb_lookup or malloc/getnewvnode.
|
|
|
|
*/
|
|
|
|
if (smp->sm_root)
|
|
|
|
vput(vp);
|
|
|
|
else {
|
|
|
|
vp->v_flag |= VROOT;
|
|
|
|
smp->sm_root = VTOSMB(vp);
|
|
|
|
|
|
|
|
/* Keep reference, but unlock */
|
|
|
|
VOP_UNLOCK(vp, 0);
|
|
|
|
}
|
2003-02-26 21:16:37 +03:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
/*
|
2003-02-26 21:16:37 +03:00
|
|
|
* Return locked root vnode of a filesystem.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-29 22:43:21 +04:00
|
|
|
smbfs_root(struct mount *mp, struct vnode **vpp)
|
2003-02-26 21:16:37 +03:00
|
|
|
{
|
|
|
|
struct smbmount *smp = VFSTOSMBFS(mp);
|
|
|
|
|
2003-02-26 23:21:40 +03:00
|
|
|
if (__predict_false(!smp->sm_root)) {
|
|
|
|
int error = smbfs_setroot(mp);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
/* fallthrough */
|
|
|
|
}
|
|
|
|
|
2003-02-26 21:16:37 +03:00
|
|
|
KASSERT(smp->sm_root != NULL && SMBTOV(smp->sm_root) != NULL);
|
|
|
|
*vpp = SMBTOV(smp->sm_root);
|
2003-06-29 22:43:21 +04:00
|
|
|
return vget(*vpp, LK_EXCLUSIVE | LK_RETRY);
|
2002-01-09 20:25:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-02-26 21:16:37 +03:00
|
|
|
* Make a filesystem operational.
|
|
|
|
* Nothing to do at the moment.
|
2002-01-09 20:25:32 +03:00
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2002-01-09 20:43:28 +03:00
|
|
|
int
|
2006-10-12 05:30:41 +04:00
|
|
|
smbfs_start(struct mount *mp __unused, int flags __unused,
|
|
|
|
struct lwp *l __unused)
|
2002-01-09 20:25:32 +03:00
|
|
|
{
|
|
|
|
SMBVDEBUG("flags=%04x\n", flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do operations associated with quotas, not supported
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2002-01-09 20:43:28 +03:00
|
|
|
int
|
2006-10-12 05:30:41 +04:00
|
|
|
smbfs_quotactl(struct mount *mp __unused, int cmd __unused, uid_t uid __unused,
|
|
|
|
void *arg __unused, struct lwp *l __unused)
|
2002-01-09 20:25:32 +03:00
|
|
|
{
|
|
|
|
SMBVDEBUG("return EOPNOTSUPP\n");
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2002-01-09 20:43:28 +03:00
|
|
|
void
|
|
|
|
smbfs_init(void)
|
2002-01-09 20:25:32 +03:00
|
|
|
{
|
2003-04-02 20:26:53 +04:00
|
|
|
#ifdef _LKM
|
|
|
|
/* Need explicit attach if LKM */
|
|
|
|
malloc_type_attach(M_SMBNODENAME);
|
|
|
|
malloc_type_attach(M_SMBFSDATA);
|
2003-04-08 20:26:31 +04:00
|
|
|
malloc_type_attach(M_SMBFSHASH);
|
2004-05-20 09:39:34 +04:00
|
|
|
pool_init(&smbfs_node_pool, sizeof(struct smbnode), 0, 0, 0,
|
|
|
|
"smbfsnopl", &pool_allocator_nointr);
|
2003-04-02 20:26:53 +04:00
|
|
|
#endif
|
|
|
|
|
2003-02-24 21:41:04 +03:00
|
|
|
SMBVDEBUG("init.\n");
|
2002-01-09 20:25:32 +03:00
|
|
|
}
|
|
|
|
|
2002-01-09 20:43:28 +03:00
|
|
|
void
|
|
|
|
smbfs_reinit(void)
|
2002-01-09 20:25:32 +03:00
|
|
|
{
|
|
|
|
|
2002-01-09 20:43:28 +03:00
|
|
|
SMBVDEBUG("reinit.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-02-24 21:41:04 +03:00
|
|
|
smbfs_done(void)
|
2002-01-09 20:43:28 +03:00
|
|
|
{
|
|
|
|
|
2003-02-24 21:41:04 +03:00
|
|
|
pool_destroy(&smbfs_node_pool);
|
2003-04-02 20:26:53 +04:00
|
|
|
|
|
|
|
#ifdef _LKM
|
|
|
|
/* Need explicit detach if LKM */
|
2004-05-20 09:39:34 +04:00
|
|
|
pool_destroy(&smbfs_node_pool);
|
2003-04-02 20:26:53 +04:00
|
|
|
malloc_type_detach(M_SMBNODENAME);
|
|
|
|
malloc_type_detach(M_SMBFSDATA);
|
2003-04-08 20:26:31 +04:00
|
|
|
malloc_type_detach(M_SMBFSHASH);
|
2003-04-02 20:26:53 +04:00
|
|
|
#endif
|
|
|
|
|
2003-02-24 21:41:04 +03:00
|
|
|
SMBVDEBUG("done.\n");
|
2002-01-09 20:25:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-04-21 05:05:31 +04:00
|
|
|
* smbfs_statvfs call
|
2002-01-09 20:25:32 +03:00
|
|
|
*/
|
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
smbfs_statvfs(struct mount *mp, struct statvfs *sbp, struct lwp *l)
|
2002-01-09 20:25:32 +03:00
|
|
|
{
|
|
|
|
struct smbmount *smp = VFSTOSMBFS(mp);
|
|
|
|
struct smb_share *ssp = smp->sm_share;
|
|
|
|
struct smb_cred scred;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
sbp->f_iosize = SSTOVC(ssp)->vc_txmax; /* optimal transfer block size */
|
2006-07-24 02:06:03 +04:00
|
|
|
smb_makescred(&scred, l, l->l_cred);
|
2002-01-09 20:25:32 +03:00
|
|
|
|
2004-06-05 11:36:25 +04:00
|
|
|
error = smbfs_smb_statvfs(ssp, sbp, &scred);
|
2002-01-09 20:25:32 +03:00
|
|
|
if (error)
|
|
|
|
return error;
|
2004-06-05 11:36:25 +04:00
|
|
|
|
2004-04-21 05:05:31 +04:00
|
|
|
sbp->f_flag = 0; /* copy of mount exported flags */
|
2003-04-17 01:44:18 +04:00
|
|
|
sbp->f_owner = mp->mnt_stat.f_owner; /* user that mounted the filesystem */
|
2004-04-21 05:05:31 +04:00
|
|
|
copy_statvfs_info(sbp, mp);
|
2002-01-09 20:25:32 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush out the buffer cache
|
|
|
|
*/
|
2002-01-09 20:43:28 +03:00
|
|
|
int
|
2006-05-15 01:31:52 +04:00
|
|
|
smbfs_sync(struct mount *mp, int waitfor, kauth_cred_t cred, struct lwp *l)
|
2002-01-09 20:25:32 +03:00
|
|
|
{
|
2006-10-22 04:03:33 +04:00
|
|
|
struct vnode *vp, *nvp;
|
2003-02-26 01:17:20 +03:00
|
|
|
struct smbnode *np;
|
2002-01-09 20:25:32 +03:00
|
|
|
int error, allerror = 0;
|
|
|
|
/*
|
|
|
|
* Force stale buffer cache information to be flushed.
|
|
|
|
*/
|
2003-02-26 01:17:20 +03:00
|
|
|
simple_lock(&mntvnode_slock);
|
2002-01-09 20:25:32 +03:00
|
|
|
loop:
|
2006-10-22 04:03:33 +04:00
|
|
|
/*
|
|
|
|
* NOTE: not using the TAILQ_FOREACH here since in this loop vgone()
|
|
|
|
* and vclean() can be called indirectly
|
|
|
|
*/
|
|
|
|
for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = nvp) {
|
2002-01-09 20:25:32 +03:00
|
|
|
/*
|
|
|
|
* If the vnode that we are about to sync is no longer
|
|
|
|
* associated with this mount point, start over.
|
|
|
|
*/
|
|
|
|
if (vp->v_mount != mp)
|
|
|
|
goto loop;
|
2003-02-26 01:17:20 +03:00
|
|
|
simple_lock(&vp->v_interlock);
|
2006-10-26 02:01:54 +04:00
|
|
|
nvp = TAILQ_NEXT(vp, v_mntvnodes);
|
2003-02-26 01:17:20 +03:00
|
|
|
np = VTOSMB(vp);
|
2003-02-26 02:57:27 +03:00
|
|
|
if ((vp->v_type == VNON || (np->n_flag & NMODIFIED) == 0) &&
|
2003-02-26 01:17:20 +03:00
|
|
|
LIST_EMPTY(&vp->v_dirtyblkhd) &&
|
|
|
|
vp->v_uobj.uo_npages == 0) {
|
|
|
|
simple_unlock(&vp->v_interlock);
|
2002-01-09 20:25:32 +03:00
|
|
|
continue;
|
2003-02-26 01:17:20 +03:00
|
|
|
}
|
|
|
|
simple_unlock(&mntvnode_slock);
|
2003-06-29 22:43:21 +04:00
|
|
|
error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK);
|
2003-02-26 01:17:20 +03:00
|
|
|
if (error) {
|
|
|
|
simple_lock(&mntvnode_slock);
|
|
|
|
if (error == ENOENT)
|
|
|
|
goto loop;
|
|
|
|
continue;
|
|
|
|
}
|
2002-01-09 20:43:28 +03:00
|
|
|
error = VOP_FSYNC(vp, cred,
|
2005-12-11 15:16:03 +03:00
|
|
|
waitfor == MNT_WAIT ? FSYNC_WAIT : 0, 0, 0, l);
|
2002-01-09 20:25:32 +03:00
|
|
|
if (error)
|
|
|
|
allerror = error;
|
|
|
|
vput(vp);
|
2003-02-26 01:17:20 +03:00
|
|
|
simple_lock(&mntvnode_slock);
|
2002-01-09 20:25:32 +03:00
|
|
|
}
|
2003-02-26 01:17:20 +03:00
|
|
|
simple_unlock(&mntvnode_slock);
|
2002-01-09 20:25:32 +03:00
|
|
|
return (allerror);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if __FreeBSD_version < 400009
|
|
|
|
/*
|
|
|
|
* smbfs flat namespace lookup. Unsupported.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2006-10-12 05:30:41 +04:00
|
|
|
int smbfs_vget(struct mount *mp __unused, ino_t ino __unused,
|
|
|
|
struct vnode **vpp __unused)
|
2002-01-09 20:25:32 +03:00
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __FreeBSD_version < 400009 */
|