2005-01-06 18:10:42 +00:00
|
|
|
/*-
|
2001-04-10 07:59:06 +00: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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/unistd.h>
|
|
|
|
#include <sys/vnode.h>
|
2003-04-29 13:36:06 +00:00
|
|
|
#include <sys/limits.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/lockf.h>
|
2006-11-05 06:38:42 +00:00
|
|
|
#include <sys/stat.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <netsmb/smb.h>
|
|
|
|
#include <netsmb/smb_conn.h>
|
|
|
|
#include <netsmb/smb_subr.h>
|
|
|
|
|
|
|
|
#include <fs/smbfs/smbfs.h>
|
|
|
|
#include <fs/smbfs/smbfs_node.h>
|
|
|
|
#include <fs/smbfs/smbfs_subr.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prototypes for SMBFS vnode operations
|
|
|
|
*/
|
2004-12-01 12:24:41 +00:00
|
|
|
static vop_create_t smbfs_create;
|
|
|
|
static vop_mknod_t smbfs_mknod;
|
|
|
|
static vop_open_t smbfs_open;
|
|
|
|
static vop_close_t smbfs_close;
|
|
|
|
static vop_access_t smbfs_access;
|
|
|
|
static vop_getattr_t smbfs_getattr;
|
|
|
|
static vop_setattr_t smbfs_setattr;
|
|
|
|
static vop_read_t smbfs_read;
|
|
|
|
static vop_write_t smbfs_write;
|
|
|
|
static vop_fsync_t smbfs_fsync;
|
|
|
|
static vop_remove_t smbfs_remove;
|
|
|
|
static vop_link_t smbfs_link;
|
|
|
|
static vop_lookup_t smbfs_lookup;
|
|
|
|
static vop_rename_t smbfs_rename;
|
|
|
|
static vop_mkdir_t smbfs_mkdir;
|
|
|
|
static vop_rmdir_t smbfs_rmdir;
|
|
|
|
static vop_symlink_t smbfs_symlink;
|
|
|
|
static vop_readdir_t smbfs_readdir;
|
|
|
|
static vop_strategy_t smbfs_strategy;
|
|
|
|
static vop_print_t smbfs_print;
|
|
|
|
static vop_pathconf_t smbfs_pathconf;
|
|
|
|
static vop_advlock_t smbfs_advlock;
|
|
|
|
static vop_getextattr_t smbfs_getextattr;
|
2001-04-10 07:59:06 +00:00
|
|
|
|
2004-12-01 23:16:38 +00:00
|
|
|
struct vop_vector smbfs_vnodeops = {
|
|
|
|
.vop_default = &default_vnodeops,
|
2005-01-13 18:59:48 +00:00
|
|
|
|
2004-12-01 23:16:38 +00:00
|
|
|
.vop_access = smbfs_access,
|
|
|
|
.vop_advlock = smbfs_advlock,
|
|
|
|
.vop_close = smbfs_close,
|
|
|
|
.vop_create = smbfs_create,
|
|
|
|
.vop_fsync = smbfs_fsync,
|
|
|
|
.vop_getattr = smbfs_getattr,
|
2005-01-13 18:59:48 +00:00
|
|
|
.vop_getextattr = smbfs_getextattr,
|
2004-12-01 23:16:38 +00:00
|
|
|
.vop_getpages = smbfs_getpages,
|
|
|
|
.vop_inactive = smbfs_inactive,
|
|
|
|
.vop_ioctl = smbfs_ioctl,
|
|
|
|
.vop_link = smbfs_link,
|
|
|
|
.vop_lookup = smbfs_lookup,
|
|
|
|
.vop_mkdir = smbfs_mkdir,
|
|
|
|
.vop_mknod = smbfs_mknod,
|
|
|
|
.vop_open = smbfs_open,
|
|
|
|
.vop_pathconf = smbfs_pathconf,
|
|
|
|
.vop_print = smbfs_print,
|
|
|
|
.vop_putpages = smbfs_putpages,
|
|
|
|
.vop_read = smbfs_read,
|
|
|
|
.vop_readdir = smbfs_readdir,
|
|
|
|
.vop_reclaim = smbfs_reclaim,
|
|
|
|
.vop_remove = smbfs_remove,
|
|
|
|
.vop_rename = smbfs_rename,
|
|
|
|
.vop_rmdir = smbfs_rmdir,
|
|
|
|
.vop_setattr = smbfs_setattr,
|
2005-01-13 18:59:48 +00:00
|
|
|
/* .vop_setextattr = smbfs_setextattr,*/
|
2004-12-01 23:16:38 +00:00
|
|
|
.vop_strategy = smbfs_strategy,
|
|
|
|
.vop_symlink = smbfs_symlink,
|
|
|
|
.vop_write = smbfs_write,
|
2001-04-10 07:59:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
smbfs_access(ap)
|
|
|
|
struct vop_access_args /* {
|
|
|
|
struct vnode *a_vp;
|
2008-10-28 13:44:11 +00:00
|
|
|
accmode_t a_accmode;
|
2001-04-10 07:59:06 +00:00
|
|
|
struct ucred *a_cred;
|
2001-12-02 08:56:58 +00:00
|
|
|
struct thread *a_td;
|
2001-04-10 07:59:06 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
2008-10-28 13:44:11 +00:00
|
|
|
accmode_t accmode = ap->a_accmode;
|
2003-02-03 09:04:34 +00:00
|
|
|
mode_t mpmode;
|
2001-04-10 07:59:06 +00:00
|
|
|
struct smbmount *smp = VTOSMBFS(vp);
|
|
|
|
|
|
|
|
SMBVDEBUG("\n");
|
2008-10-28 13:44:11 +00:00
|
|
|
if ((accmode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
|
2001-04-10 07:59:06 +00:00
|
|
|
switch (vp->v_type) {
|
|
|
|
case VREG: case VDIR: case VLNK:
|
|
|
|
return EROFS;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-12-06 20:31:08 +00:00
|
|
|
mpmode = vp->v_type == VREG ? smp->sm_file_mode : smp->sm_dir_mode;
|
|
|
|
return (vaccess(vp->v_type, mpmode, smp->sm_uid,
|
2008-10-28 13:44:11 +00:00
|
|
|
smp->sm_gid, ap->a_accmode, ap->a_cred, NULL));
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
smbfs_open(ap)
|
|
|
|
struct vop_open_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_mode;
|
|
|
|
struct ucred *a_cred;
|
2001-12-02 08:56:58 +00:00
|
|
|
struct thread *a_td;
|
2001-04-10 07:59:06 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct smbnode *np = VTOSMB(vp);
|
2012-10-31 03:34:07 +00:00
|
|
|
struct smb_cred *scred;
|
2001-04-10 07:59:06 +00:00
|
|
|
struct vattr vattr;
|
|
|
|
int mode = ap->a_mode;
|
|
|
|
int error, accmode;
|
|
|
|
|
2003-06-17 12:58:02 +00:00
|
|
|
SMBVDEBUG("%s,%d\n", np->n_name, (np->n_flag & NOPEN) != 0);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (vp->v_type != VREG && vp->v_type != VDIR) {
|
|
|
|
SMBFSERR("open eacces vtype=%d\n", vp->v_type);
|
|
|
|
return EACCES;
|
|
|
|
}
|
|
|
|
if (vp->v_type == VDIR) {
|
2003-06-17 12:58:02 +00:00
|
|
|
np->n_flag |= NOPEN;
|
2001-04-10 07:59:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (np->n_flag & NMODIFIED) {
|
2005-01-14 08:52:55 +00:00
|
|
|
if ((error = smbfs_vinvalbuf(vp, ap->a_td)) == EINTR)
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
|
|
|
smbfs_attr_cacheremove(vp);
|
2008-08-28 15:23:18 +00:00
|
|
|
error = VOP_GETATTR(vp, &vattr, ap->a_cred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
|
|
|
|
} else {
|
2008-08-28 15:23:18 +00:00
|
|
|
error = VOP_GETATTR(vp, &vattr, ap->a_cred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
if (np->n_mtime.tv_sec != vattr.va_mtime.tv_sec) {
|
2005-01-14 08:52:55 +00:00
|
|
|
error = smbfs_vinvalbuf(vp, ap->a_td);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error == EINTR)
|
|
|
|
return error;
|
|
|
|
np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
|
|
|
|
}
|
|
|
|
}
|
2003-06-17 12:58:02 +00:00
|
|
|
if ((np->n_flag & NOPEN) != 0)
|
2001-04-10 07:59:06 +00:00
|
|
|
return 0;
|
2002-09-18 09:54:16 +00:00
|
|
|
/*
|
|
|
|
* Use DENYNONE to give unixy semantics of permitting
|
|
|
|
* everything not forbidden by permissions. Ie denial
|
|
|
|
* is up to server with clients/openers needing to use
|
|
|
|
* advisory locks for further control.
|
|
|
|
*/
|
|
|
|
accmode = SMB_SM_DENYNONE|SMB_AM_OPENREAD;
|
2001-04-10 07:59:06 +00:00
|
|
|
if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
|
2002-09-18 09:54:16 +00:00
|
|
|
accmode = SMB_SM_DENYNONE|SMB_AM_OPENRW;
|
2012-10-31 03:34:07 +00:00
|
|
|
scred = smbfs_malloc_scred();
|
|
|
|
smb_makescred(scred, ap->a_td, ap->a_cred);
|
|
|
|
error = smbfs_smb_open(np, accmode, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error) {
|
|
|
|
if (mode & FWRITE)
|
|
|
|
return EACCES;
|
2002-09-18 09:54:16 +00:00
|
|
|
else if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
|
|
|
|
accmode = SMB_SM_DENYNONE|SMB_AM_OPENREAD;
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_open(np, accmode, scred);
|
2002-09-18 09:54:16 +00:00
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
2005-01-29 16:23:39 +00:00
|
|
|
if (error == 0) {
|
2003-06-17 12:58:02 +00:00
|
|
|
np->n_flag |= NOPEN;
|
2005-01-29 16:23:39 +00:00
|
|
|
vnode_create_vobject(ap->a_vp, vattr.va_size, ap->a_td);
|
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
smbfs_attr_cacheremove(vp);
|
2012-10-31 03:34:07 +00:00
|
|
|
smbfs_free_scred(scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
smbfs_close(ap)
|
|
|
|
struct vop_close_args /* {
|
|
|
|
struct vnodeop_desc *a_desc;
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_fflag;
|
|
|
|
struct ucred *a_cred;
|
2001-12-02 08:56:58 +00:00
|
|
|
struct thread *a_td;
|
2001-04-10 07:59:06 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
2001-12-02 08:56:58 +00:00
|
|
|
struct thread *td = ap->a_td;
|
2004-01-10 03:45:30 +00:00
|
|
|
struct smbnode *np = VTOSMB(vp);
|
2012-10-31 03:34:07 +00:00
|
|
|
struct smb_cred *scred;
|
2001-04-10 07:59:06 +00:00
|
|
|
|
2004-01-10 03:45:30 +00:00
|
|
|
if (vp->v_type == VDIR && (np->n_flag & NOPEN) != 0 &&
|
|
|
|
np->n_dirseq != NULL) {
|
2012-10-31 03:34:07 +00:00
|
|
|
scred = smbfs_malloc_scred();
|
|
|
|
smb_makescred(scred, td, ap->a_cred);
|
|
|
|
smbfs_findclose(np->n_dirseq, scred);
|
|
|
|
smbfs_free_scred(scred);
|
2004-01-10 03:45:30 +00:00
|
|
|
np->n_dirseq = NULL;
|
|
|
|
}
|
2003-06-17 12:58:02 +00:00
|
|
|
return 0;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* smbfs_getattr call from vfs.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
smbfs_getattr(ap)
|
|
|
|
struct vop_getattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct smbnode *np = VTOSMB(vp);
|
|
|
|
struct vattr *va=ap->a_vap;
|
|
|
|
struct smbfattr fattr;
|
2012-10-31 03:34:07 +00:00
|
|
|
struct smb_cred *scred;
|
2003-12-22 12:33:31 +00:00
|
|
|
u_quad_t oldsize;
|
2001-04-10 07:59:06 +00:00
|
|
|
int error;
|
|
|
|
|
2002-08-04 10:29:36 +00:00
|
|
|
SMBVDEBUG("%lx: '%s' %d\n", (long)vp, np->n_name, (vp->v_vflag & VV_ROOT) != 0);
|
2001-04-10 07:59:06 +00:00
|
|
|
error = smbfs_attr_cachelookup(vp, va);
|
|
|
|
if (!error)
|
|
|
|
return 0;
|
|
|
|
SMBVDEBUG("not in the cache\n");
|
2012-10-31 03:34:07 +00:00
|
|
|
scred = smbfs_malloc_scred();
|
|
|
|
smb_makescred(scred, curthread, ap->a_cred);
|
2001-04-10 07:59:06 +00:00
|
|
|
oldsize = np->n_size;
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_lookup(np, NULL, 0, &fattr, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error) {
|
|
|
|
SMBVDEBUG("error %d\n", error);
|
2012-10-31 03:34:07 +00:00
|
|
|
smbfs_free_scred(scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
smbfs_attr_cacheenter(vp, &fattr);
|
|
|
|
smbfs_attr_cachelookup(vp, va);
|
2003-06-17 12:58:02 +00:00
|
|
|
if (np->n_flag & NOPEN)
|
2001-04-10 07:59:06 +00:00
|
|
|
np->n_size = oldsize;
|
2012-10-31 03:34:07 +00:00
|
|
|
smbfs_free_scred(scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
smbfs_setattr(ap)
|
|
|
|
struct vop_setattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct smbnode *np = VTOSMB(vp);
|
|
|
|
struct vattr *vap = ap->a_vap;
|
|
|
|
struct timespec *mtime, *atime;
|
2012-10-31 03:34:07 +00:00
|
|
|
struct smb_cred *scred;
|
2001-04-10 07:59:06 +00:00
|
|
|
struct smb_share *ssp = np->n_mount->sm_share;
|
|
|
|
struct smb_vc *vcp = SSTOVC(ssp);
|
2008-08-28 15:23:18 +00:00
|
|
|
struct thread *td = curthread;
|
2001-04-10 07:59:06 +00:00
|
|
|
u_quad_t tsize = 0;
|
|
|
|
int isreadonly, doclose, error = 0;
|
2006-11-05 06:38:42 +00:00
|
|
|
int old_n_dosattr;
|
2001-04-10 07:59:06 +00:00
|
|
|
|
|
|
|
SMBVDEBUG("\n");
|
|
|
|
isreadonly = (vp->v_mount->mnt_flag & MNT_RDONLY);
|
|
|
|
/*
|
|
|
|
* Disallow write attempts if the filesystem is mounted read-only.
|
|
|
|
*/
|
|
|
|
if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
|
|
|
|
vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
vap->va_mode != (mode_t)VNOVAL || vap->va_flags != VNOVAL) &&
|
|
|
|
isreadonly)
|
2001-04-10 07:59:06 +00:00
|
|
|
return EROFS;
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We only support setting four flags. Don't allow setting others.
|
|
|
|
*
|
|
|
|
* We map UF_READONLY to SMB_FA_RDONLY, unlike the MacOS X version
|
|
|
|
* of this code, which maps both UF_IMMUTABLE AND SF_IMMUTABLE to
|
|
|
|
* SMB_FA_RDONLY. The immutable flags have different semantics
|
|
|
|
* than readonly, which is the reason for the difference.
|
|
|
|
*/
|
|
|
|
if (vap->va_flags != VNOVAL) {
|
|
|
|
if (vap->va_flags & ~(UF_HIDDEN|UF_SYSTEM|UF_ARCHIVE|
|
|
|
|
UF_READONLY))
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-10-31 03:34:07 +00:00
|
|
|
scred = smbfs_malloc_scred();
|
|
|
|
smb_makescred(scred, td, ap->a_cred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (vap->va_size != VNOVAL) {
|
|
|
|
switch (vp->v_type) {
|
|
|
|
case VDIR:
|
2012-10-31 03:34:07 +00:00
|
|
|
error = EISDIR;
|
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
case VREG:
|
|
|
|
break;
|
|
|
|
default:
|
2012-10-31 03:34:07 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
};
|
2012-10-31 03:34:07 +00:00
|
|
|
if (isreadonly) {
|
|
|
|
error = EROFS;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
doclose = 0;
|
|
|
|
vnode_pager_setsize(vp, (u_long)vap->va_size);
|
|
|
|
tsize = np->n_size;
|
|
|
|
np->n_size = vap->va_size;
|
2003-06-17 12:58:02 +00:00
|
|
|
if ((np->n_flag & NOPEN) == 0) {
|
2002-09-18 09:54:16 +00:00
|
|
|
error = smbfs_smb_open(np,
|
|
|
|
SMB_SM_DENYNONE|SMB_AM_OPENRW,
|
2012-10-31 03:34:07 +00:00
|
|
|
scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error == 0)
|
|
|
|
doclose = 1;
|
|
|
|
}
|
|
|
|
if (error == 0)
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_setfsize(np, vap->va_size, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (doclose)
|
2012-10-31 03:34:07 +00:00
|
|
|
smbfs_smb_close(ssp, np->n_fid, NULL, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error) {
|
|
|
|
np->n_size = tsize;
|
|
|
|
vnode_pager_setsize(vp, (u_long)tsize);
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
}
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
if ((vap->va_flags != VNOVAL) || (vap->va_mode != (mode_t)VNOVAL)) {
|
2006-11-05 06:38:42 +00:00
|
|
|
old_n_dosattr = np->n_dosattr;
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
|
|
|
|
if (vap->va_mode != (mode_t)VNOVAL) {
|
|
|
|
if (vap->va_mode & S_IWUSR)
|
|
|
|
np->n_dosattr &= ~SMB_FA_RDONLY;
|
|
|
|
else
|
|
|
|
np->n_dosattr |= SMB_FA_RDONLY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vap->va_flags != VNOVAL) {
|
|
|
|
if (vap->va_flags & UF_HIDDEN)
|
|
|
|
np->n_dosattr |= SMB_FA_HIDDEN;
|
|
|
|
else
|
|
|
|
np->n_dosattr &= ~SMB_FA_HIDDEN;
|
|
|
|
|
|
|
|
if (vap->va_flags & UF_SYSTEM)
|
|
|
|
np->n_dosattr |= SMB_FA_SYSTEM;
|
|
|
|
else
|
|
|
|
np->n_dosattr &= ~SMB_FA_SYSTEM;
|
|
|
|
|
|
|
|
if (vap->va_flags & UF_ARCHIVE)
|
|
|
|
np->n_dosattr |= SMB_FA_ARCHIVE;
|
|
|
|
else
|
|
|
|
np->n_dosattr &= ~SMB_FA_ARCHIVE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We only support setting the immutable / readonly
|
|
|
|
* bit for regular files. According to comments in
|
|
|
|
* the MacOS X version of this code, supporting the
|
|
|
|
* readonly bit on directories doesn't do the same
|
|
|
|
* thing in Windows as in Unix.
|
|
|
|
*/
|
|
|
|
if (vp->v_type == VREG) {
|
|
|
|
if (vap->va_flags & UF_READONLY)
|
|
|
|
np->n_dosattr |= SMB_FA_RDONLY;
|
|
|
|
else
|
|
|
|
np->n_dosattr &= ~SMB_FA_RDONLY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-05 06:38:42 +00:00
|
|
|
if (np->n_dosattr != old_n_dosattr) {
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_setpattr(np, np->n_dosattr, NULL, scred);
|
2006-11-05 06:38:42 +00:00
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2006-11-05 06:38:42 +00:00
|
|
|
}
|
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
mtime = atime = NULL;
|
|
|
|
if (vap->va_mtime.tv_sec != VNOVAL)
|
|
|
|
mtime = &vap->va_mtime;
|
|
|
|
if (vap->va_atime.tv_sec != VNOVAL)
|
|
|
|
atime = &vap->va_atime;
|
|
|
|
if (mtime != atime) {
|
2006-11-06 13:42:10 +00:00
|
|
|
if (vap->va_vaflags & VA_UTIMES_NULL) {
|
2008-08-28 15:23:18 +00:00
|
|
|
error = VOP_ACCESS(vp, VADMIN, ap->a_cred, td);
|
2006-11-06 13:42:10 +00:00
|
|
|
if (error)
|
2008-08-28 15:23:18 +00:00
|
|
|
error = VOP_ACCESS(vp, VWRITE, ap->a_cred, td);
|
2006-11-06 13:42:10 +00:00
|
|
|
} else
|
2008-08-28 15:23:18 +00:00
|
|
|
error = VOP_ACCESS(vp, VADMIN, ap->a_cred, td);
|
2001-04-10 07:59:06 +00:00
|
|
|
#if 0
|
|
|
|
if (mtime == NULL)
|
|
|
|
mtime = &np->n_mtime;
|
|
|
|
if (atime == NULL)
|
|
|
|
atime = &np->n_atime;
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* If file is opened, then we can use handle based calls.
|
|
|
|
* If not, use path based ones.
|
|
|
|
*/
|
2003-06-17 12:58:02 +00:00
|
|
|
if ((np->n_flag & NOPEN) == 0) {
|
2001-04-10 07:59:06 +00:00
|
|
|
if (vcp->vc_flags & SMBV_WIN95) {
|
2008-08-28 15:23:18 +00:00
|
|
|
error = VOP_OPEN(vp, FWRITE, ap->a_cred, td,
|
|
|
|
NULL);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (!error) {
|
2008-08-28 15:23:18 +00:00
|
|
|
/* error = smbfs_smb_setfattrNT(np, 0,
|
2012-10-31 03:34:07 +00:00
|
|
|
mtime, atime, scred);
|
2008-08-28 15:23:18 +00:00
|
|
|
VOP_GETATTR(vp, &vattr, ap->a_cred); */
|
|
|
|
if (mtime)
|
|
|
|
np->n_mtime = *mtime;
|
|
|
|
VOP_CLOSE(vp, FWRITE, ap->a_cred, td);
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
} else if ((vcp->vc_sopt.sv_caps & SMB_CAP_NT_SMBS)) {
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_setptime2(np, mtime, atime, 0, scred);
|
|
|
|
/* error = smbfs_smb_setpattrNT(np, 0, mtime, atime, scred);*/
|
2001-04-10 07:59:06 +00:00
|
|
|
} else if (SMB_DIALECT(vcp) >= SMB_DIALECT_LANMAN2_0) {
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_setptime2(np, mtime, atime, 0, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
} else {
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_setpattr(np, 0, mtime, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (vcp->vc_sopt.sv_caps & SMB_CAP_NT_SMBS) {
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_setfattrNT(np, 0, mtime, atime, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
} else if (SMB_DIALECT(vcp) >= SMB_DIALECT_LANMAN1_0) {
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_setftime(np, mtime, atime, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* I have no idea how to handle this for core
|
|
|
|
* level servers. The possible solution is to
|
|
|
|
* update mtime after file is closed.
|
|
|
|
*/
|
|
|
|
SMBERROR("can't update times on an opened file\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Invalidate attribute cache in case if server doesn't set
|
|
|
|
* required attributes.
|
|
|
|
*/
|
|
|
|
smbfs_attr_cacheremove(vp); /* invalidate cache */
|
2008-08-28 15:23:18 +00:00
|
|
|
VOP_GETATTR(vp, vap, ap->a_cred);
|
2001-04-10 07:59:06 +00:00
|
|
|
np->n_mtime.tv_sec = vap->va_mtime.tv_sec;
|
2012-10-31 03:34:07 +00:00
|
|
|
out:
|
|
|
|
smbfs_free_scred(scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* smbfs_read call.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
smbfs_read(ap)
|
|
|
|
struct vop_read_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
int a_ioflag;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
|
|
|
|
SMBVDEBUG("\n");
|
|
|
|
if (vp->v_type != VREG && vp->v_type != VDIR)
|
|
|
|
return EPERM;
|
|
|
|
return smbfs_readvnode(vp, uio, ap->a_cred);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
smbfs_write(ap)
|
|
|
|
struct vop_write_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
int a_ioflag;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
|
2012-10-31 02:54:44 +00:00
|
|
|
SMBVDEBUG("%d,ofs=%jd,sz=%zd\n",vp->v_type, (intmax_t)uio->uio_offset,
|
2012-10-25 21:08:02 +00:00
|
|
|
uio->uio_resid);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (vp->v_type != VREG)
|
|
|
|
return (EPERM);
|
|
|
|
return smbfs_writevnode(vp, uio, ap->a_cred,ap->a_ioflag);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* smbfs_create call
|
|
|
|
* Create a regular file. On entry the directory to contain the file being
|
|
|
|
* created is locked. We must release before we return. We must also free
|
|
|
|
* the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
|
|
|
|
* only if the SAVESTART bit in cn_flags is clear on success.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
smbfs_create(ap)
|
|
|
|
struct vop_create_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *dvp = ap->a_dvp;
|
|
|
|
struct vattr *vap = ap->a_vap;
|
|
|
|
struct vnode **vpp=ap->a_vpp;
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct smbnode *dnp = VTOSMB(dvp);
|
|
|
|
struct vnode *vp;
|
|
|
|
struct vattr vattr;
|
|
|
|
struct smbfattr fattr;
|
2012-10-31 03:34:07 +00:00
|
|
|
struct smb_cred *scred;
|
2001-04-10 07:59:06 +00:00
|
|
|
char *name = cnp->cn_nameptr;
|
|
|
|
int nmlen = cnp->cn_namelen;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
|
|
SMBVDEBUG("\n");
|
|
|
|
*vpp = NULL;
|
|
|
|
if (vap->va_type != VREG)
|
|
|
|
return EOPNOTSUPP;
|
2008-08-28 15:23:18 +00:00
|
|
|
if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred)))
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
2012-10-31 03:34:07 +00:00
|
|
|
scred = smbfs_malloc_scred();
|
|
|
|
smb_makescred(scred, cnp->cn_thread, cnp->cn_cred);
|
2001-04-10 07:59:06 +00:00
|
|
|
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_create(dnp, name, nmlen, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
|
|
|
error = smbfs_smb_lookup(dnp, name, nmlen, &fattr, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
error = smbfs_nget(VTOVFS(dvp), dvp, name, nmlen, &fattr, &vp);
|
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
*vpp = vp;
|
|
|
|
if (cnp->cn_flags & MAKEENTRY)
|
|
|
|
cache_enter(dvp, vp, cnp);
|
2012-10-31 03:34:07 +00:00
|
|
|
out:
|
|
|
|
smbfs_free_scred(scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
smbfs_remove(ap)
|
|
|
|
struct vop_remove_args /* {
|
|
|
|
struct vnodeop_desc *a_desc;
|
|
|
|
struct vnode * a_dvp;
|
|
|
|
struct vnode * a_vp;
|
|
|
|
struct componentname * a_cnp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
/* struct vnode *dvp = ap->a_dvp;*/
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct smbnode *np = VTOSMB(vp);
|
2012-10-31 03:34:07 +00:00
|
|
|
struct smb_cred *scred;
|
2001-04-10 07:59:06 +00:00
|
|
|
int error;
|
|
|
|
|
2003-06-17 12:58:02 +00:00
|
|
|
if (vp->v_type == VDIR || (np->n_flag & NOPEN) != 0 || vrefcnt(vp) != 1)
|
2001-04-10 07:59:06 +00:00
|
|
|
return EPERM;
|
2012-10-31 03:34:07 +00:00
|
|
|
scred = smbfs_malloc_scred();
|
|
|
|
smb_makescred(scred, cnp->cn_thread, cnp->cn_cred);
|
|
|
|
error = smbfs_smb_delete(np, scred);
|
2004-02-10 05:53:02 +00:00
|
|
|
if (error == 0)
|
|
|
|
np->n_flag |= NGONE;
|
2001-04-10 07:59:06 +00:00
|
|
|
cache_purge(vp);
|
2012-10-31 03:34:07 +00:00
|
|
|
smbfs_free_scred(scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* smbfs_file rename call
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
smbfs_rename(ap)
|
|
|
|
struct vop_rename_args /* {
|
|
|
|
struct vnode *a_fdvp;
|
|
|
|
struct vnode *a_fvp;
|
|
|
|
struct componentname *a_fcnp;
|
|
|
|
struct vnode *a_tdvp;
|
|
|
|
struct vnode *a_tvp;
|
|
|
|
struct componentname *a_tcnp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *fvp = ap->a_fvp;
|
|
|
|
struct vnode *tvp = ap->a_tvp;
|
|
|
|
struct vnode *fdvp = ap->a_fdvp;
|
|
|
|
struct vnode *tdvp = ap->a_tdvp;
|
|
|
|
struct componentname *tcnp = ap->a_tcnp;
|
|
|
|
/* struct componentname *fcnp = ap->a_fcnp;*/
|
2012-10-31 03:34:07 +00:00
|
|
|
struct smb_cred *scred;
|
2001-04-10 07:59:06 +00:00
|
|
|
u_int16_t flags = 6;
|
|
|
|
int error=0;
|
|
|
|
|
2013-03-09 13:05:21 +00:00
|
|
|
scred = NULL;
|
2001-04-10 07:59:06 +00:00
|
|
|
/* Check for cross-device rename */
|
|
|
|
if ((fvp->v_mount != tdvp->v_mount) ||
|
|
|
|
(tvp && (fvp->v_mount != tvp->v_mount))) {
|
2012-11-26 04:29:47 +00:00
|
|
|
error = EXDEV;
|
2001-04-10 07:59:06 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2002-09-25 02:32:42 +00:00
|
|
|
if (tvp && vrefcnt(tvp) > 1) {
|
2012-11-26 04:29:47 +00:00
|
|
|
error = EBUSY;
|
2001-04-10 07:59:06 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
flags = 0x10; /* verify all writes */
|
|
|
|
if (fvp->v_type == VDIR) {
|
|
|
|
flags |= 2;
|
|
|
|
} else if (fvp->v_type == VREG) {
|
|
|
|
flags |= 1;
|
2003-02-19 11:54:35 +00:00
|
|
|
} else {
|
2012-10-31 03:34:07 +00:00
|
|
|
return EINVAL;
|
2003-02-19 11:54:35 +00:00
|
|
|
}
|
2012-10-31 03:34:07 +00:00
|
|
|
scred = smbfs_malloc_scred();
|
|
|
|
smb_makescred(scred, tcnp->cn_thread, tcnp->cn_cred);
|
2001-04-10 07:59:06 +00:00
|
|
|
/*
|
|
|
|
* It seems that Samba doesn't implement SMB_COM_MOVE call...
|
|
|
|
*/
|
|
|
|
#ifdef notnow
|
|
|
|
if (SMB_DIALECT(SSTOCN(smp->sm_share)) >= SMB_DIALECT_LANMAN1_0) {
|
|
|
|
error = smbfs_smb_move(VTOSMB(fvp), VTOSMB(tdvp),
|
2012-10-31 03:34:07 +00:00
|
|
|
tcnp->cn_nameptr, tcnp->cn_namelen, flags, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We have to do the work atomicaly
|
|
|
|
*/
|
|
|
|
if (tvp && tvp != fvp) {
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_delete(VTOSMB(tvp), scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
2003-02-19 11:54:35 +00:00
|
|
|
goto out_cacherem;
|
2004-02-10 05:53:02 +00:00
|
|
|
VTOSMB(fvp)->n_flag |= NGONE;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
error = smbfs_smb_rename(VTOSMB(fvp), VTOSMB(tdvp),
|
2012-10-31 03:34:07 +00:00
|
|
|
tcnp->cn_nameptr, tcnp->cn_namelen, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fvp->v_type == VDIR) {
|
|
|
|
if (tvp != NULL && tvp->v_type == VDIR)
|
|
|
|
cache_purge(tdvp);
|
|
|
|
cache_purge(fdvp);
|
|
|
|
}
|
2003-02-19 11:54:35 +00:00
|
|
|
|
|
|
|
out_cacherem:
|
|
|
|
smbfs_attr_cacheremove(fdvp);
|
|
|
|
smbfs_attr_cacheremove(tdvp);
|
2001-04-10 07:59:06 +00:00
|
|
|
out:
|
2012-10-31 03:34:07 +00:00
|
|
|
smbfs_free_scred(scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (tdvp == tvp)
|
|
|
|
vrele(tdvp);
|
|
|
|
else
|
|
|
|
vput(tdvp);
|
|
|
|
if (tvp)
|
|
|
|
vput(tvp);
|
|
|
|
vrele(fdvp);
|
|
|
|
vrele(fvp);
|
|
|
|
#ifdef possible_mistake
|
|
|
|
vgone(fvp);
|
|
|
|
if (tvp)
|
|
|
|
vgone(tvp);
|
|
|
|
#endif
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2003-02-08 05:48:04 +00:00
|
|
|
/*
|
|
|
|
* somtime it will come true...
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
smbfs_link(ap)
|
|
|
|
struct vop_link_args /* {
|
|
|
|
struct vnode *a_tdvp;
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* smbfs_symlink link create call.
|
|
|
|
* Sometime it will be functional...
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
smbfs_symlink(ap)
|
|
|
|
struct vop_symlink_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
char *a_target;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
smbfs_mknod(ap)
|
|
|
|
struct vop_mknod_args /* {
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:59:06 +00:00
|
|
|
static int
|
|
|
|
smbfs_mkdir(ap)
|
|
|
|
struct vop_mkdir_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *dvp = ap->a_dvp;
|
|
|
|
/* struct vattr *vap = ap->a_vap;*/
|
|
|
|
struct vnode *vp;
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct smbnode *dnp = VTOSMB(dvp);
|
|
|
|
struct vattr vattr;
|
2012-10-31 03:34:07 +00:00
|
|
|
struct smb_cred *scred;
|
2001-04-10 07:59:06 +00:00
|
|
|
struct smbfattr fattr;
|
|
|
|
char *name = cnp->cn_nameptr;
|
|
|
|
int len = cnp->cn_namelen;
|
|
|
|
int error;
|
|
|
|
|
2008-08-28 15:23:18 +00:00
|
|
|
if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred))) {
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.'))))
|
|
|
|
return EEXIST;
|
2012-10-31 03:34:07 +00:00
|
|
|
scred = smbfs_malloc_scred();
|
|
|
|
smb_makescred(scred, cnp->cn_thread, cnp->cn_cred);
|
|
|
|
error = smbfs_smb_mkdir(dnp, name, len, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
|
|
|
error = smbfs_smb_lookup(dnp, name, len, &fattr, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
error = smbfs_nget(VTOVFS(dvp), dvp, name, len, &fattr, &vp);
|
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
*ap->a_vpp = vp;
|
2012-10-31 03:34:07 +00:00
|
|
|
out:
|
|
|
|
smbfs_free_scred(scred);
|
2013-03-09 13:05:21 +00:00
|
|
|
return error;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* smbfs_remove directory call
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
smbfs_rmdir(ap)
|
|
|
|
struct vop_rmdir_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct vnode *dvp = ap->a_dvp;
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
/* struct smbmount *smp = VTOSMBFS(vp);*/
|
|
|
|
struct smbnode *dnp = VTOSMB(dvp);
|
|
|
|
struct smbnode *np = VTOSMB(vp);
|
2012-10-31 03:34:07 +00:00
|
|
|
struct smb_cred *scred;
|
2001-04-10 07:59:06 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
if (dvp == vp)
|
|
|
|
return EINVAL;
|
|
|
|
|
2012-10-31 03:34:07 +00:00
|
|
|
scred = smbfs_malloc_scred();
|
|
|
|
smb_makescred(scred, cnp->cn_thread, cnp->cn_cred);
|
|
|
|
error = smbfs_smb_rmdir(np, scred);
|
2004-02-10 05:53:02 +00:00
|
|
|
if (error == 0)
|
|
|
|
np->n_flag |= NGONE;
|
2001-04-10 07:59:06 +00:00
|
|
|
dnp->n_flag |= NMODIFIED;
|
|
|
|
smbfs_attr_cacheremove(dvp);
|
|
|
|
/* cache_purge(dvp);*/
|
|
|
|
cache_purge(vp);
|
2012-10-31 03:34:07 +00:00
|
|
|
smbfs_free_scred(scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* smbfs_readdir call
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
smbfs_readdir(ap)
|
|
|
|
struct vop_readdir_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
int *a_eofflag;
|
|
|
|
u_long *a_cookies;
|
|
|
|
int a_ncookies;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (vp->v_type != VDIR)
|
|
|
|
return (EPERM);
|
|
|
|
#ifdef notnow
|
|
|
|
if (ap->a_ncookies) {
|
|
|
|
printf("smbfs_readdir: no support for cookies now...");
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
error = smbfs_readvnode(vp, uio, ap->a_cred);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
smbfs_fsync(ap)
|
|
|
|
struct vop_fsync_args /* {
|
|
|
|
struct vnodeop_desc *a_desc;
|
|
|
|
struct vnode * a_vp;
|
|
|
|
struct ucred * a_cred;
|
|
|
|
int a_waitfor;
|
2001-12-02 08:56:58 +00:00
|
|
|
struct thread * a_td;
|
2001-04-10 07:59:06 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
2001-12-02 08:56:58 +00:00
|
|
|
/* return (smb_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));*/
|
2001-04-10 07:59:06 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int smbfs_print (ap)
|
|
|
|
struct vop_print_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct smbnode *np = VTOSMB(vp);
|
|
|
|
|
|
|
|
if (np == NULL) {
|
|
|
|
printf("no smbnode data\n");
|
|
|
|
return (0);
|
|
|
|
}
|
2003-06-17 12:58:02 +00:00
|
|
|
printf("\tname = %s, parent = %p, open = %d\n", np->n_name,
|
|
|
|
np->n_parent ? np->n_parent : NULL, (np->n_flag & NOPEN) != 0);
|
2001-04-10 07:59:06 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
smbfs_pathconf (ap)
|
|
|
|
struct vop_pathconf_args /* {
|
|
|
|
struct vnode *vp;
|
|
|
|
int name;
|
|
|
|
register_t *retval;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct smbmount *smp = VFSTOSMBFS(VTOVFS(ap->a_vp));
|
|
|
|
struct smb_vc *vcp = SSTOVC(smp->sm_share);
|
|
|
|
register_t *retval = ap->a_retval;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (ap->a_name) {
|
|
|
|
case _PC_LINK_MAX:
|
|
|
|
*retval = 0;
|
|
|
|
break;
|
|
|
|
case _PC_NAME_MAX:
|
2001-08-21 08:25:09 +00:00
|
|
|
*retval = (vcp->vc_hflags2 & SMB_FLAGS2_KNOWS_LONG_NAMES) ? 255 : 12;
|
2001-04-10 07:59:06 +00:00
|
|
|
break;
|
|
|
|
case _PC_PATH_MAX:
|
|
|
|
*retval = 800; /* XXX: a correct one ? */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
smbfs_strategy (ap)
|
|
|
|
struct vop_strategy_args /* {
|
|
|
|
struct buf *a_bp
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct buf *bp=ap->a_bp;
|
|
|
|
struct ucred *cr;
|
2001-12-02 08:56:58 +00:00
|
|
|
struct thread *td;
|
2001-04-10 07:59:06 +00:00
|
|
|
|
|
|
|
SMBVDEBUG("\n");
|
|
|
|
if (bp->b_flags & B_ASYNC)
|
2001-12-02 08:56:58 +00:00
|
|
|
td = (struct thread *)0;
|
2001-04-10 07:59:06 +00:00
|
|
|
else
|
2001-12-02 08:56:58 +00:00
|
|
|
td = curthread; /* XXX */
|
2001-04-10 07:59:06 +00:00
|
|
|
if (bp->b_iocmd == BIO_READ)
|
|
|
|
cr = bp->b_rcred;
|
|
|
|
else
|
|
|
|
cr = bp->b_wcred;
|
|
|
|
|
|
|
|
if ((bp->b_flags & B_ASYNC) == 0 )
|
2009-01-31 18:06:34 +00:00
|
|
|
(void)smbfs_doio(ap->a_vp, bp, cr, td);
|
2008-12-16 21:13:11 +00:00
|
|
|
return (0);
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
|
2003-02-08 05:48:04 +00:00
|
|
|
int
|
|
|
|
smbfs_ioctl(ap)
|
|
|
|
struct vop_ioctl_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
u_long a_command;
|
|
|
|
caddr_t a_data;
|
|
|
|
int fflag;
|
|
|
|
struct ucred *cred;
|
|
|
|
struct thread *td;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
return ENOTTY;
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:59:06 +00:00
|
|
|
static char smbfs_atl[] = "rhsvda";
|
|
|
|
static int
|
|
|
|
smbfs_getextattr(struct vop_getextattr_args *ap)
|
|
|
|
/* {
|
|
|
|
IN struct vnode *a_vp;
|
|
|
|
IN char *a_name;
|
|
|
|
INOUT struct uio *a_uio;
|
|
|
|
IN struct ucred *a_cred;
|
2001-12-02 08:56:58 +00:00
|
|
|
IN struct thread *a_td;
|
2001-04-10 07:59:06 +00:00
|
|
|
};
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
2001-12-02 08:56:58 +00:00
|
|
|
struct thread *td = ap->a_td;
|
2001-04-10 07:59:06 +00:00
|
|
|
struct ucred *cred = ap->a_cred;
|
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
const char *name = ap->a_name;
|
|
|
|
struct smbnode *np = VTOSMB(vp);
|
|
|
|
struct vattr vattr;
|
|
|
|
char buf[10];
|
|
|
|
int i, attr, error;
|
|
|
|
|
2001-12-02 08:56:58 +00:00
|
|
|
error = VOP_ACCESS(vp, VREAD, cred, td);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
2008-08-28 15:23:18 +00:00
|
|
|
error = VOP_GETATTR(vp, &vattr, cred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
if (strcmp(name, "dosattr") == 0) {
|
|
|
|
attr = np->n_dosattr;
|
|
|
|
for (i = 0; i < 6; i++, attr >>= 1)
|
|
|
|
buf[i] = (attr & 1) ? smbfs_atl[i] : '-';
|
|
|
|
buf[i] = 0;
|
|
|
|
error = uiomove(buf, i, uio);
|
|
|
|
|
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since we expected to support F_GETLK (and SMB protocol has no such function),
|
|
|
|
* it is necessary to use lf_advlock(). It would be nice if this function had
|
|
|
|
* a callback mechanism because it will help to improve a level of consistency.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
smbfs_advlock(ap)
|
|
|
|
struct vop_advlock_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
caddr_t a_id;
|
|
|
|
int a_op;
|
|
|
|
struct flock *a_fl;
|
|
|
|
int a_flags;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct smbnode *np = VTOSMB(vp);
|
|
|
|
struct flock *fl = ap->a_fl;
|
|
|
|
caddr_t id = (caddr_t)1 /* ap->a_id */;
|
|
|
|
/* int flags = ap->a_flags;*/
|
2001-12-02 08:56:58 +00:00
|
|
|
struct thread *td = curthread;
|
2012-10-31 03:34:07 +00:00
|
|
|
struct smb_cred *scred;
|
2001-08-23 08:54:22 +00:00
|
|
|
u_quad_t size;
|
2001-08-26 10:28:58 +00:00
|
|
|
off_t start, end, oadd;
|
2001-04-10 07:59:06 +00:00
|
|
|
int error, lkop;
|
|
|
|
|
|
|
|
if (vp->v_type == VDIR) {
|
|
|
|
/*
|
|
|
|
* SMB protocol have no support for directory locking.
|
|
|
|
* Although locks can be processed on local machine, I don't
|
|
|
|
* think that this is a good idea, because some programs
|
|
|
|
* can work wrong assuming directory is locked. So, we just
|
|
|
|
* return 'operation not supported
|
|
|
|
*/
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
size = np->n_size;
|
|
|
|
switch (fl->l_whence) {
|
2001-08-29 18:59:04 +00:00
|
|
|
|
|
|
|
case SEEK_SET:
|
|
|
|
case SEEK_CUR:
|
2001-04-10 07:59:06 +00:00
|
|
|
start = fl->l_start;
|
|
|
|
break;
|
2001-08-29 18:59:04 +00:00
|
|
|
|
|
|
|
case SEEK_END:
|
|
|
|
if (size > OFF_MAX ||
|
|
|
|
(fl->l_start > 0 && size > OFF_MAX - fl->l_start))
|
2001-08-23 08:54:22 +00:00
|
|
|
return EOVERFLOW;
|
2001-08-29 18:59:04 +00:00
|
|
|
start = size + fl->l_start;
|
2001-08-23 14:45:31 +00:00
|
|
|
break;
|
2001-08-29 18:59:04 +00:00
|
|
|
|
|
|
|
default:
|
2001-04-10 07:59:06 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
if (start < 0)
|
|
|
|
return EINVAL;
|
2001-08-23 15:44:24 +00:00
|
|
|
if (fl->l_len < 0) {
|
2001-08-23 16:06:14 +00:00
|
|
|
if (start == 0)
|
2001-08-23 15:44:24 +00:00
|
|
|
return EINVAL;
|
|
|
|
end = start - 1;
|
2001-08-23 16:06:14 +00:00
|
|
|
start += fl->l_len;
|
|
|
|
if (start < 0)
|
|
|
|
return EINVAL;
|
2001-08-23 15:44:24 +00:00
|
|
|
} else if (fl->l_len == 0)
|
2001-04-10 07:59:06 +00:00
|
|
|
end = -1;
|
|
|
|
else {
|
2001-08-26 10:28:58 +00:00
|
|
|
oadd = fl->l_len - 1;
|
2001-08-23 08:54:22 +00:00
|
|
|
if (oadd > OFF_MAX - start)
|
|
|
|
return EOVERFLOW;
|
|
|
|
end = start + oadd;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
2012-10-31 03:34:07 +00:00
|
|
|
scred = smbfs_malloc_scred();
|
|
|
|
smb_makescred(scred, td, td->td_ucred);
|
2001-04-10 07:59:06 +00:00
|
|
|
switch (ap->a_op) {
|
|
|
|
case F_SETLK:
|
|
|
|
switch (fl->l_type) {
|
|
|
|
case F_WRLCK:
|
|
|
|
lkop = SMB_LOCK_EXCL;
|
|
|
|
break;
|
|
|
|
case F_RDLCK:
|
|
|
|
lkop = SMB_LOCK_SHARED;
|
|
|
|
break;
|
|
|
|
case F_UNLCK:
|
|
|
|
lkop = SMB_LOCK_RELEASE;
|
|
|
|
break;
|
|
|
|
default:
|
2012-10-31 03:34:07 +00:00
|
|
|
smbfs_free_scred(scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
Move the head of byte-level advisory lock list from the
filesystem-specific vnode data to the struct vnode. Provide the
default implementation for the vop_advlock and vop_advlockasync.
Purge the locks on the vnode reclaim by using the lf_purgelocks().
The default implementation is augmented for the nfs and smbfs.
In the nfs_advlock, push the Giant inside the nfs_dolock.
Before the change, the vop_advlock and vop_advlockasync have taken the
unlocked vnode and dereferenced the fs-private inode data, racing with
with the vnode reclamation due to forced unmount. Now, the vop_getattr
under the shared vnode lock is used to obtain the inode size, and
later, in the lf_advlockasync, after locking the vnode interlock, the
VI_DOOMED flag is checked to prevent an operation on the doomed vnode.
The implementation of the lf_purgelocks() is submitted by dfr.
Reported by: kris
Tested by: kris, pho
Discussed with: jeff, dfr
MFC after: 2 weeks
2008-04-16 11:33:32 +00:00
|
|
|
error = lf_advlock(ap, &vp->v_lockf, size);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
lkop = SMB_LOCK_EXCL;
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_lock(np, lkop, id, start, end, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error) {
|
2008-04-14 09:22:48 +00:00
|
|
|
int oldtype = fl->l_type;
|
|
|
|
fl->l_type = F_UNLCK;
|
2001-04-10 07:59:06 +00:00
|
|
|
ap->a_op = F_UNLCK;
|
Move the head of byte-level advisory lock list from the
filesystem-specific vnode data to the struct vnode. Provide the
default implementation for the vop_advlock and vop_advlockasync.
Purge the locks on the vnode reclaim by using the lf_purgelocks().
The default implementation is augmented for the nfs and smbfs.
In the nfs_advlock, push the Giant inside the nfs_dolock.
Before the change, the vop_advlock and vop_advlockasync have taken the
unlocked vnode and dereferenced the fs-private inode data, racing with
with the vnode reclamation due to forced unmount. Now, the vop_getattr
under the shared vnode lock is used to obtain the inode size, and
later, in the lf_advlockasync, after locking the vnode interlock, the
VI_DOOMED flag is checked to prevent an operation on the doomed vnode.
The implementation of the lf_purgelocks() is submitted by dfr.
Reported by: kris
Tested by: kris, pho
Discussed with: jeff, dfr
MFC after: 2 weeks
2008-04-16 11:33:32 +00:00
|
|
|
lf_advlock(ap, &vp->v_lockf, size);
|
2008-04-14 09:22:48 +00:00
|
|
|
fl->l_type = oldtype;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case F_UNLCK:
|
Move the head of byte-level advisory lock list from the
filesystem-specific vnode data to the struct vnode. Provide the
default implementation for the vop_advlock and vop_advlockasync.
Purge the locks on the vnode reclaim by using the lf_purgelocks().
The default implementation is augmented for the nfs and smbfs.
In the nfs_advlock, push the Giant inside the nfs_dolock.
Before the change, the vop_advlock and vop_advlockasync have taken the
unlocked vnode and dereferenced the fs-private inode data, racing with
with the vnode reclamation due to forced unmount. Now, the vop_getattr
under the shared vnode lock is used to obtain the inode size, and
later, in the lf_advlockasync, after locking the vnode interlock, the
VI_DOOMED flag is checked to prevent an operation on the doomed vnode.
The implementation of the lf_purgelocks() is submitted by dfr.
Reported by: kris
Tested by: kris, pho
Discussed with: jeff, dfr
MFC after: 2 weeks
2008-04-16 11:33:32 +00:00
|
|
|
lf_advlock(ap, &vp->v_lockf, size);
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_lock(np, SMB_LOCK_RELEASE, id, start, end, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
break;
|
|
|
|
case F_GETLK:
|
Move the head of byte-level advisory lock list from the
filesystem-specific vnode data to the struct vnode. Provide the
default implementation for the vop_advlock and vop_advlockasync.
Purge the locks on the vnode reclaim by using the lf_purgelocks().
The default implementation is augmented for the nfs and smbfs.
In the nfs_advlock, push the Giant inside the nfs_dolock.
Before the change, the vop_advlock and vop_advlockasync have taken the
unlocked vnode and dereferenced the fs-private inode data, racing with
with the vnode reclamation due to forced unmount. Now, the vop_getattr
under the shared vnode lock is used to obtain the inode size, and
later, in the lf_advlockasync, after locking the vnode interlock, the
VI_DOOMED flag is checked to prevent an operation on the doomed vnode.
The implementation of the lf_purgelocks() is submitted by dfr.
Reported by: kris
Tested by: kris, pho
Discussed with: jeff, dfr
MFC after: 2 weeks
2008-04-16 11:33:32 +00:00
|
|
|
error = lf_advlock(ap, &vp->v_lockf, size);
|
2001-04-10 07:59:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-10-31 03:34:07 +00:00
|
|
|
smbfs_free_scred(scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
2012-10-31 03:34:07 +00:00
|
|
|
smbfs_free_scred(scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
smbfs_pathcheck(struct smbmount *smp, const char *name, int nmlen, int nameiop)
|
|
|
|
{
|
2006-05-31 22:32:22 +00:00
|
|
|
static const char *badchars = "*/:<>;?";
|
2003-09-26 12:11:08 +00:00
|
|
|
static const char *badchars83 = " +|,[]=";
|
2001-04-10 07:59:06 +00:00
|
|
|
const char *cp;
|
|
|
|
int i, error;
|
|
|
|
|
2006-05-31 22:32:22 +00:00
|
|
|
/*
|
|
|
|
* Backslash characters, being a path delimiter, are prohibited
|
|
|
|
* within a path component even for LOOKUP operations.
|
|
|
|
*/
|
2012-01-02 12:12:10 +00:00
|
|
|
if (strchr(name, '\\') != NULL)
|
2006-05-31 22:32:22 +00:00
|
|
|
return ENOENT;
|
|
|
|
|
2001-04-10 07:59:06 +00:00
|
|
|
if (nameiop == LOOKUP)
|
|
|
|
return 0;
|
|
|
|
error = ENOENT;
|
|
|
|
if (SMB_DIALECT(SSTOVC(smp->sm_share)) < SMB_DIALECT_LANMAN2_0) {
|
|
|
|
/*
|
|
|
|
* Name should conform 8.3 format
|
|
|
|
*/
|
|
|
|
if (nmlen > 12)
|
|
|
|
return ENAMETOOLONG;
|
2012-01-02 12:12:10 +00:00
|
|
|
cp = strchr(name, '.');
|
2001-04-10 07:59:06 +00:00
|
|
|
if (cp == NULL)
|
|
|
|
return error;
|
|
|
|
if (cp == name || (cp - name) > 8)
|
|
|
|
return error;
|
2012-01-02 12:12:10 +00:00
|
|
|
cp = strchr(cp + 1, '.');
|
2001-04-10 07:59:06 +00:00
|
|
|
if (cp != NULL)
|
|
|
|
return error;
|
|
|
|
for (cp = name, i = 0; i < nmlen; i++, cp++)
|
2012-01-02 12:12:10 +00:00
|
|
|
if (strchr(badchars83, *cp) != NULL)
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
for (cp = name, i = 0; i < nmlen; i++, cp++)
|
2012-01-02 12:12:10 +00:00
|
|
|
if (strchr(badchars, *cp) != NULL)
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Things go even weird without fixed inode numbers...
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
smbfs_lookup(ap)
|
|
|
|
struct vop_lookup_args /* {
|
|
|
|
struct vnodeop_desc *a_desc;
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
2001-12-02 08:56:58 +00:00
|
|
|
struct thread *td = cnp->cn_thread;
|
2001-04-10 07:59:06 +00:00
|
|
|
struct vnode *dvp = ap->a_dvp;
|
|
|
|
struct vnode **vpp = ap->a_vpp;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct smbmount *smp;
|
|
|
|
struct mount *mp = dvp->v_mount;
|
|
|
|
struct smbnode *dnp;
|
|
|
|
struct smbfattr fattr, *fap;
|
2012-10-31 03:34:07 +00:00
|
|
|
struct smb_cred *scred;
|
2001-04-10 07:59:06 +00:00
|
|
|
char *name = cnp->cn_nameptr;
|
|
|
|
int flags = cnp->cn_flags;
|
|
|
|
int nameiop = cnp->cn_nameiop;
|
|
|
|
int nmlen = cnp->cn_namelen;
|
2005-03-29 13:09:42 +00:00
|
|
|
int error, islastcn, isdot;
|
2004-02-10 05:53:02 +00:00
|
|
|
int killit;
|
2001-04-10 07:59:06 +00:00
|
|
|
|
|
|
|
SMBVDEBUG("\n");
|
|
|
|
if (dvp->v_type != VDIR)
|
|
|
|
return ENOTDIR;
|
2002-08-04 10:29:36 +00:00
|
|
|
if ((flags & ISDOTDOT) && (dvp->v_vflag & VV_ROOT)) {
|
2001-04-10 07:59:06 +00:00
|
|
|
SMBFSERR("invalid '..'\n");
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
islastcn = flags & ISLASTCN;
|
|
|
|
if (islastcn && (mp->mnt_flag & MNT_RDONLY) && (nameiop != LOOKUP))
|
|
|
|
return EROFS;
|
2001-12-02 08:56:58 +00:00
|
|
|
if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td)) != 0)
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
|
|
|
smp = VFSTOSMBFS(mp);
|
|
|
|
dnp = VTOSMB(dvp);
|
|
|
|
isdot = (nmlen == 1 && name[0] == '.');
|
|
|
|
|
|
|
|
error = smbfs_pathcheck(smp, cnp->cn_nameptr, cnp->cn_namelen, nameiop);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
return ENOENT;
|
|
|
|
|
2012-02-06 17:00:28 +00:00
|
|
|
error = cache_lookup(dvp, vpp, cnp, NULL, NULL);
|
2001-04-10 07:59:06 +00:00
|
|
|
SMBVDEBUG("cache_lookup returned %d\n", error);
|
|
|
|
if (error > 0)
|
|
|
|
return error;
|
|
|
|
if (error) { /* name was found */
|
|
|
|
struct vattr vattr;
|
|
|
|
|
2005-03-29 13:00:37 +00:00
|
|
|
killit = 0;
|
2005-04-10 03:17:42 +00:00
|
|
|
vp = *vpp;
|
2008-08-28 15:23:18 +00:00
|
|
|
error = VOP_GETATTR(vp, &vattr, cnp->cn_cred);
|
2005-03-29 13:00:37 +00:00
|
|
|
/*
|
|
|
|
* If the file type on the server is inconsistent
|
|
|
|
* with what it was when we created the vnode,
|
|
|
|
* kill the bogus vnode now and fall through to
|
|
|
|
* the code below to create a new one with the
|
|
|
|
* right type.
|
|
|
|
*/
|
|
|
|
if (error == 0 &&
|
|
|
|
((vp->v_type == VDIR &&
|
|
|
|
(VTOSMB(vp)->n_dosattr & SMB_FA_DIR) == 0) ||
|
|
|
|
(vp->v_type == VREG &&
|
|
|
|
(VTOSMB(vp)->n_dosattr & SMB_FA_DIR) != 0)))
|
|
|
|
killit = 1;
|
|
|
|
else if (error == 0
|
|
|
|
/* && vattr.va_ctime.tv_sec == VTOSMB(vp)->n_ctime*/) {
|
|
|
|
if (nameiop != LOOKUP && islastcn)
|
|
|
|
cnp->cn_flags |= SAVENAME;
|
|
|
|
SMBVDEBUG("use cached vnode\n");
|
|
|
|
return (0);
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
2005-03-29 13:00:37 +00:00
|
|
|
cache_purge(vp);
|
|
|
|
/*
|
|
|
|
* XXX This is not quite right, if '.' is
|
|
|
|
* inconsistent, we really need to start the lookup
|
|
|
|
* all over again. Hopefully there is some other
|
|
|
|
* guarantee that prevents this case from happening.
|
|
|
|
*/
|
|
|
|
if (killit && vp != dvp)
|
|
|
|
vgone(vp);
|
|
|
|
if (vp != dvp)
|
|
|
|
vput(vp);
|
|
|
|
else
|
|
|
|
vrele(vp);
|
2001-04-10 07:59:06 +00:00
|
|
|
*vpp = NULLVP;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* entry is not in the cache or has been expired
|
|
|
|
*/
|
|
|
|
error = 0;
|
|
|
|
*vpp = NULLVP;
|
2012-10-31 03:34:07 +00:00
|
|
|
scred = smbfs_malloc_scred();
|
|
|
|
smb_makescred(scred, td, cnp->cn_cred);
|
2001-04-10 07:59:06 +00:00
|
|
|
fap = &fattr;
|
|
|
|
if (flags & ISDOTDOT) {
|
2013-03-09 13:25:45 +00:00
|
|
|
/*
|
|
|
|
* In the DOTDOT case, don't go over-the-wire
|
|
|
|
* in order to request attributes. We already
|
|
|
|
* know it's a directory and subsequent call to
|
|
|
|
* smbfs_getattr() will restore consistency.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
SMBVDEBUG("smbfs_smb_lookup: dotdot\n");
|
|
|
|
} else if (isdot) {
|
|
|
|
error = smbfs_smb_lookup(dnp, NULL, 0, fap, scred);
|
|
|
|
SMBVDEBUG("result of smbfs_smb_lookup: %d\n", error);
|
|
|
|
}
|
|
|
|
else {
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smbfs_smb_lookup(dnp, name, nmlen, fap, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
SMBVDEBUG("result of smbfs_smb_lookup: %d\n", error);
|
|
|
|
}
|
|
|
|
if (error && error != ENOENT)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error) { /* entry not found */
|
|
|
|
/*
|
|
|
|
* Handle RENAME or CREATE case...
|
|
|
|
*/
|
2005-03-29 13:09:42 +00:00
|
|
|
if ((nameiop == CREATE || nameiop == RENAME) && islastcn) {
|
2002-04-13 15:33:26 +00:00
|
|
|
error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
|
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
cnp->cn_flags |= SAVENAME;
|
2012-10-31 03:34:07 +00:00
|
|
|
error = EJUSTRETURN;
|
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
2012-10-31 03:34:07 +00:00
|
|
|
error = ENOENT;
|
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
}/* else {
|
|
|
|
SMBVDEBUG("Found entry %s with id=%d\n", fap->entryName, fap->dirEntNum);
|
|
|
|
}*/
|
|
|
|
/*
|
|
|
|
* handle DELETE case ...
|
|
|
|
*/
|
|
|
|
if (nameiop == DELETE && islastcn) { /* delete last component */
|
2001-12-02 08:56:58 +00:00
|
|
|
error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
if (isdot) {
|
|
|
|
VREF(dvp);
|
|
|
|
*vpp = dvp;
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
error = smbfs_nget(mp, dvp, name, nmlen, fap, &vp);
|
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
*vpp = vp;
|
|
|
|
cnp->cn_flags |= SAVENAME;
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
2005-03-29 13:09:42 +00:00
|
|
|
if (nameiop == RENAME && islastcn) {
|
2001-12-02 08:56:58 +00:00
|
|
|
error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
|
|
|
if (isdot) {
|
|
|
|
error = EISDIR;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
error = smbfs_nget(mp, dvp, name, nmlen, fap, &vp);
|
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
*vpp = vp;
|
|
|
|
cnp->cn_flags |= SAVENAME;
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
if (flags & ISDOTDOT) {
|
2012-11-14 18:43:58 +00:00
|
|
|
mp = dvp->v_mount;
|
|
|
|
error = vfs_busy(mp, MBF_NOWAIT);
|
|
|
|
if (error != 0) {
|
|
|
|
vfs_ref(mp);
|
|
|
|
VOP_UNLOCK(dvp, 0);
|
|
|
|
error = vfs_busy(mp, 0);
|
|
|
|
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
vfs_rel(mp);
|
2013-06-28 20:07:24 +00:00
|
|
|
if (error) {
|
|
|
|
error = ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-11-14 18:43:58 +00:00
|
|
|
if ((dvp->v_iflag & VI_DOOMED) != 0) {
|
|
|
|
vfs_unbusy(mp);
|
2013-06-28 20:07:24 +00:00
|
|
|
error = ENOENT;
|
|
|
|
goto out;
|
2012-11-14 18:43:58 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(dvp, 0);
|
2001-04-10 07:59:06 +00:00
|
|
|
error = smbfs_nget(mp, dvp, name, nmlen, NULL, &vp);
|
2012-11-14 18:43:58 +00:00
|
|
|
vfs_unbusy(mp);
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
|
2012-11-14 18:43:58 +00:00
|
|
|
if ((dvp->v_iflag & VI_DOOMED) != 0) {
|
|
|
|
if (error == 0)
|
|
|
|
vput(vp);
|
|
|
|
error = ENOENT;
|
|
|
|
}
|
2005-04-13 10:59:09 +00:00
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
*vpp = vp;
|
|
|
|
} else if (isdot) {
|
|
|
|
vref(dvp);
|
|
|
|
*vpp = dvp;
|
|
|
|
} else {
|
|
|
|
error = smbfs_nget(mp, dvp, name, nmlen, fap, &vp);
|
|
|
|
if (error)
|
2012-10-31 03:34:07 +00:00
|
|
|
goto out;
|
2001-04-10 07:59:06 +00:00
|
|
|
*vpp = vp;
|
|
|
|
SMBVDEBUG("lookup: getnewvp!\n");
|
|
|
|
}
|
|
|
|
if ((cnp->cn_flags & MAKEENTRY)/* && !islastcn*/) {
|
|
|
|
/* VTOSMB(*vpp)->n_ctime = VTOSMB(*vpp)->n_vattr.va_ctime.tv_sec;*/
|
|
|
|
cache_enter(dvp, *vpp, cnp);
|
|
|
|
}
|
2012-10-31 03:34:07 +00:00
|
|
|
out:
|
|
|
|
smbfs_free_scred(scred);
|
|
|
|
return (error);
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|