1d167cf6fSWarner Losh /*- 2d63027b6SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3d63027b6SPedro F. Giffuni * 4681a5bbeSBoris Popov * Copyright (c) 2000-2001 Boris Popov 5681a5bbeSBoris Popov * All rights reserved. 6681a5bbeSBoris Popov * 7681a5bbeSBoris Popov * Redistribution and use in source and binary forms, with or without 8681a5bbeSBoris Popov * modification, are permitted provided that the following conditions 9681a5bbeSBoris Popov * are met: 10681a5bbeSBoris Popov * 1. Redistributions of source code must retain the above copyright 11681a5bbeSBoris Popov * notice, this list of conditions and the following disclaimer. 12681a5bbeSBoris Popov * 2. Redistributions in binary form must reproduce the above copyright 13681a5bbeSBoris Popov * notice, this list of conditions and the following disclaimer in the 14681a5bbeSBoris Popov * documentation and/or other materials provided with the distribution. 15681a5bbeSBoris Popov * 16681a5bbeSBoris Popov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17681a5bbeSBoris Popov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18681a5bbeSBoris Popov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19681a5bbeSBoris Popov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20681a5bbeSBoris Popov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21681a5bbeSBoris Popov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22681a5bbeSBoris Popov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23681a5bbeSBoris Popov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24681a5bbeSBoris Popov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25681a5bbeSBoris Popov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26681a5bbeSBoris Popov * SUCH DAMAGE. 27681a5bbeSBoris Popov * 28681a5bbeSBoris Popov * $FreeBSD$ 29681a5bbeSBoris Popov */ 30681a5bbeSBoris Popov #include <sys/param.h> 31681a5bbeSBoris Popov #include <sys/systm.h> 328680dc80SDavide Italiano #include <sys/fnv_hash.h> 33681a5bbeSBoris Popov #include <sys/kernel.h> 34fb919e4dSMark Murray #include <sys/lock.h> 35681a5bbeSBoris Popov #include <sys/malloc.h> 36fb919e4dSMark Murray #include <sys/mount.h> 37fb919e4dSMark Murray #include <sys/proc.h> 38681a5bbeSBoris Popov #include <sys/queue.h> 39fb8e9eadSBoris Popov #include <sys/stat.h> 407947229fSRobert Watson #include <sys/sx.h> 41fb919e4dSMark Murray #include <sys/sysctl.h> 42fb919e4dSMark Murray #include <sys/time.h> 43fb919e4dSMark Murray #include <sys/vnode.h> 44681a5bbeSBoris Popov 45681a5bbeSBoris Popov #include <netsmb/smb.h> 46681a5bbeSBoris Popov #include <netsmb/smb_conn.h> 47681a5bbeSBoris Popov #include <netsmb/smb_subr.h> 48681a5bbeSBoris Popov 49fb919e4dSMark Murray #include <vm/vm.h> 50fb919e4dSMark Murray #include <vm/vm_extern.h> 51fb919e4dSMark Murray /*#include <vm/vm_page.h> 52fb919e4dSMark Murray #include <vm/vm_object.h>*/ 53fb919e4dSMark Murray 54681a5bbeSBoris Popov #include <fs/smbfs/smbfs.h> 55681a5bbeSBoris Popov #include <fs/smbfs/smbfs_node.h> 56681a5bbeSBoris Popov #include <fs/smbfs/smbfs_subr.h> 57681a5bbeSBoris Popov 58aec0fb7bSPoul-Henning Kamp extern struct vop_vector smbfs_vnodeops; /* XXX -> .h file */ 59681a5bbeSBoris Popov 60d745c852SEd Schouten static MALLOC_DEFINE(M_SMBNODE, "smbufs_node", "SMBFS vnode private part"); 615bb84bc8SRobert Watson static MALLOC_DEFINE(M_SMBNODENAME, "smbufs_nname", "SMBFS node name"); 62681a5bbeSBoris Popov 638680dc80SDavide Italiano u_int32_t __inline 64681a5bbeSBoris Popov smbfs_hash(const u_char *name, int nmlen) 65681a5bbeSBoris Popov { 668680dc80SDavide Italiano return (fnv_32_buf(name, nmlen, FNV1_32_INIT)); 67681a5bbeSBoris Popov } 68681a5bbeSBoris Popov 69681a5bbeSBoris Popov static char * 70681a5bbeSBoris Popov smbfs_name_alloc(const u_char *name, int nmlen) 71681a5bbeSBoris Popov { 72681a5bbeSBoris Popov u_char *cp; 73681a5bbeSBoris Popov 74681a5bbeSBoris Popov nmlen++; 75a163d034SWarner Losh cp = malloc(nmlen, M_SMBNODENAME, M_WAITOK); 76681a5bbeSBoris Popov bcopy(name, cp, nmlen - 1); 77681a5bbeSBoris Popov cp[nmlen - 1] = 0; 78681a5bbeSBoris Popov return cp; 79681a5bbeSBoris Popov } 80681a5bbeSBoris Popov 81681a5bbeSBoris Popov static void 82681a5bbeSBoris Popov smbfs_name_free(u_char *name) 83681a5bbeSBoris Popov { 84681a5bbeSBoris Popov 85681a5bbeSBoris Popov free(name, M_SMBNODENAME); 86681a5bbeSBoris Popov } 87681a5bbeSBoris Popov 888680dc80SDavide Italiano static int __inline 898680dc80SDavide Italiano smbfs_vnode_cmp(struct vnode *vp, void *_sc) 908680dc80SDavide Italiano { 918680dc80SDavide Italiano struct smbnode *np; 928680dc80SDavide Italiano struct smbcmp *sc; 938680dc80SDavide Italiano 94bbc6d2c1SDavide Italiano np = (struct smbnode *) vp->v_data; 958680dc80SDavide Italiano sc = (struct smbcmp *) _sc; 968680dc80SDavide Italiano if (np->n_parent != sc->n_parent || np->n_nmlen != sc->n_nmlen || 978680dc80SDavide Italiano bcmp(sc->n_name, np->n_name, sc->n_nmlen) != 0) 988680dc80SDavide Italiano return 1; 998680dc80SDavide Italiano return 0; 1008680dc80SDavide Italiano } 1018680dc80SDavide Italiano 102681a5bbeSBoris Popov static int 10380704a47SDavide Italiano smbfs_node_alloc(struct mount *mp, struct vnode *dvp, const char *dirnm, 10480704a47SDavide Italiano int dirlen, const char *name, int nmlen, char sep, 10580704a47SDavide Italiano struct smbfattr *fap, struct vnode **vpp) 106681a5bbeSBoris Popov { 107b4484bf0STim J. Robbins struct vattr vattr; 108b1c996c4SBoris Popov struct thread *td = curthread; /* XXX */ 109681a5bbeSBoris Popov struct smbmount *smp = VFSTOSMBFS(mp); 1108680dc80SDavide Italiano struct smbnode *np, *dnp; 1118680dc80SDavide Italiano struct vnode *vp, *vp2; 1128680dc80SDavide Italiano struct smbcmp sc; 11380704a47SDavide Italiano char *p, *rpath; 11480704a47SDavide Italiano int error, rplen; 115681a5bbeSBoris Popov 1168680dc80SDavide Italiano sc.n_parent = dvp; 1178680dc80SDavide Italiano sc.n_nmlen = nmlen; 1188680dc80SDavide Italiano sc.n_name = name; 119681a5bbeSBoris Popov if (smp->sm_root != NULL && dvp == NULL) { 120681a5bbeSBoris Popov SMBERROR("do not allocate root vnode twice!\n"); 121681a5bbeSBoris Popov return EINVAL; 122681a5bbeSBoris Popov } 123681a5bbeSBoris Popov if (nmlen == 2 && bcmp(name, "..", 2) == 0) { 124681a5bbeSBoris Popov if (dvp == NULL) 125681a5bbeSBoris Popov return EINVAL; 12611de0c59STim J. Robbins vp = VTOSMB(VTOSMB(dvp)->n_parent)->n_vnode; 127a92a971bSMateusz Guzik error = vget(vp, LK_EXCLUSIVE); 128681a5bbeSBoris Popov if (error == 0) 129681a5bbeSBoris Popov *vpp = vp; 130681a5bbeSBoris Popov return error; 131681a5bbeSBoris Popov } else if (nmlen == 1 && name[0] == '.') { 132681a5bbeSBoris Popov SMBERROR("do not call me with dot!\n"); 133681a5bbeSBoris Popov return EINVAL; 134681a5bbeSBoris Popov } 135681a5bbeSBoris Popov dnp = dvp ? VTOSMB(dvp) : NULL; 136681a5bbeSBoris Popov if (dnp == NULL && dvp != NULL) { 137411455a8SEdward Tomasz Napierala vn_printf(dvp, "smbfs_node_alloc: dead parent vnode "); 138681a5bbeSBoris Popov return EINVAL; 139681a5bbeSBoris Popov } 1408680dc80SDavide Italiano error = vfs_hash_get(mp, smbfs_hash(name, nmlen), LK_EXCLUSIVE, td, 1418680dc80SDavide Italiano vpp, smbfs_vnode_cmp, &sc); 1428680dc80SDavide Italiano if (error) 1438680dc80SDavide Italiano return (error); 1448680dc80SDavide Italiano if (*vpp) { 1458680dc80SDavide Italiano np = VTOSMB(*vpp); 146b4484bf0STim J. Robbins /* Force cached attributes to be refreshed if stale. */ 1478680dc80SDavide Italiano (void)VOP_GETATTR(*vpp, &vattr, td->td_ucred); 148b4484bf0STim J. Robbins /* 149b4484bf0STim J. Robbins * If the file type on the server is inconsistent with 150b4484bf0STim J. Robbins * what it was when we created the vnode, kill the 151b4484bf0STim J. Robbins * bogus vnode now and fall through to the code below 152b4484bf0STim J. Robbins * to create a new one with the right type. 153b4484bf0STim J. Robbins */ 1548680dc80SDavide Italiano if (((*vpp)->v_type == VDIR && 1558680dc80SDavide Italiano (np->n_dosattr & SMB_FA_DIR) == 0) || 1568680dc80SDavide Italiano ((*vpp)->v_type == VREG && 1578680dc80SDavide Italiano (np->n_dosattr & SMB_FA_DIR) != 0)) { 1588680dc80SDavide Italiano vgone(*vpp); 1598680dc80SDavide Italiano vput(*vpp); 160b4484bf0STim J. Robbins } 1618680dc80SDavide Italiano else { 1628680dc80SDavide Italiano SMBVDEBUG("vnode taken from the hashtable\n"); 1638680dc80SDavide Italiano return (0); 164681a5bbeSBoris Popov } 1658680dc80SDavide Italiano } 166681a5bbeSBoris Popov /* 167681a5bbeSBoris Popov * If we don't have node attributes, then it is an explicit lookup 168681a5bbeSBoris Popov * for an existing vnode. 169681a5bbeSBoris Popov */ 170681a5bbeSBoris Popov if (fap == NULL) 171681a5bbeSBoris Popov return ENOENT; 172681a5bbeSBoris Popov 1738680dc80SDavide Italiano error = getnewvnode("smbfs", mp, &smbfs_vnodeops, vpp); 1748680dc80SDavide Italiano if (error) 17561b9d89fSTor Egge return (error); 1768680dc80SDavide Italiano vp = *vpp; 17701cc0b65SChristian Brueffer np = malloc(sizeof *np, M_SMBNODE, M_WAITOK | M_ZERO); 17880704a47SDavide Italiano rplen = dirlen; 17980704a47SDavide Italiano if (sep != '\0') 18080704a47SDavide Italiano rplen++; 18180704a47SDavide Italiano rplen += nmlen; 18280704a47SDavide Italiano rpath = malloc(rplen + 1, M_SMBNODENAME, M_WAITOK); 18380704a47SDavide Italiano p = rpath; 18480704a47SDavide Italiano bcopy(dirnm, p, dirlen); 18580704a47SDavide Italiano p += dirlen; 18680704a47SDavide Italiano if (sep != '\0') 18780704a47SDavide Italiano *p++ = sep; 18880704a47SDavide Italiano if (name != NULL) { 18980704a47SDavide Italiano bcopy(name, p, nmlen); 19080704a47SDavide Italiano p += nmlen; 19180704a47SDavide Italiano } 19242039c5bSDavide Italiano *p = '\0'; 19380704a47SDavide Italiano MPASS(p == rpath + rplen); 1948680dc80SDavide Italiano lockmgr(vp->v_vnlock, LK_EXCLUSIVE, NULL); 1958680dc80SDavide Italiano /* Vnode initialization */ 196681a5bbeSBoris Popov vp->v_type = fap->fa_attr & SMB_FA_DIR ? VDIR : VREG; 197681a5bbeSBoris Popov vp->v_data = np; 198681a5bbeSBoris Popov np->n_vnode = vp; 199681a5bbeSBoris Popov np->n_mount = VFSTOSMBFS(mp); 20080704a47SDavide Italiano np->n_rpath = rpath; 20180704a47SDavide Italiano np->n_rplen = rplen; 202681a5bbeSBoris Popov np->n_nmlen = nmlen; 203681a5bbeSBoris Popov np->n_name = smbfs_name_alloc(name, nmlen); 204681a5bbeSBoris Popov np->n_ino = fap->fa_ino; 205681a5bbeSBoris Popov if (dvp) { 206e6e370a7SJeff Roberson ASSERT_VOP_LOCKED(dvp, "smbfs_node_alloc"); 20711de0c59STim J. Robbins np->n_parent = dvp; 20880704a47SDavide Italiano np->n_parentino = VTOSMB(dvp)->n_ino; 209e6e370a7SJeff Roberson if (/*vp->v_type == VDIR &&*/ (dvp->v_vflag & VV_ROOT) == 0) { 210681a5bbeSBoris Popov vref(dvp); 211681a5bbeSBoris Popov np->n_flag |= NREFPARENT; 212681a5bbeSBoris Popov } 213681a5bbeSBoris Popov } else if (vp->v_type == VREG) 214681a5bbeSBoris Popov SMBERROR("new vnode '%s' born without parent ?\n", np->n_name); 2158680dc80SDavide Italiano error = insmntque(vp, mp); 2168680dc80SDavide Italiano if (error) { 2178680dc80SDavide Italiano free(np, M_SMBNODE); 2188680dc80SDavide Italiano return (error); 219681a5bbeSBoris Popov } 220829f0bcbSMateusz Guzik vn_set_state(vp, VSTATE_CONSTRUCTED); 2218680dc80SDavide Italiano error = vfs_hash_insert(vp, smbfs_hash(name, nmlen), LK_EXCLUSIVE, 2228680dc80SDavide Italiano td, &vp2, smbfs_vnode_cmp, &sc); 2238680dc80SDavide Italiano if (error) 2248680dc80SDavide Italiano return (error); 2258680dc80SDavide Italiano if (vp2 != NULL) 2268680dc80SDavide Italiano *vpp = vp2; 2278680dc80SDavide Italiano return (0); 228681a5bbeSBoris Popov } 229681a5bbeSBoris Popov 230681a5bbeSBoris Popov int 231681a5bbeSBoris Popov smbfs_nget(struct mount *mp, struct vnode *dvp, const char *name, int nmlen, 232681a5bbeSBoris Popov struct smbfattr *fap, struct vnode **vpp) 233681a5bbeSBoris Popov { 234771e4a86SJohn Baldwin struct smbnode *dnp; 235681a5bbeSBoris Popov struct vnode *vp; 23680704a47SDavide Italiano int error, sep; 237681a5bbeSBoris Popov 23880704a47SDavide Italiano dnp = (dvp) ? VTOSMB(dvp) : NULL; 23980704a47SDavide Italiano sep = 0; 24080704a47SDavide Italiano if (dnp != NULL) { 24180704a47SDavide Italiano sep = SMBFS_DNP_SEP(dnp); 24280704a47SDavide Italiano error = smbfs_node_alloc(mp, dvp, dnp->n_rpath, dnp->n_rplen, 24380704a47SDavide Italiano name, nmlen, sep, fap, &vp); 24480704a47SDavide Italiano } else 24580704a47SDavide Italiano error = smbfs_node_alloc(mp, NULL, "\\", 1, name, nmlen, 24680704a47SDavide Italiano sep, fap, &vp); 247681a5bbeSBoris Popov if (error) 248681a5bbeSBoris Popov return error; 24980704a47SDavide Italiano MPASS(vp != NULL); 250681a5bbeSBoris Popov if (fap) 251681a5bbeSBoris Popov smbfs_attr_cacheenter(vp, fap); 252681a5bbeSBoris Popov *vpp = vp; 253681a5bbeSBoris Popov return 0; 254681a5bbeSBoris Popov } 255681a5bbeSBoris Popov 256681a5bbeSBoris Popov /* 257681a5bbeSBoris Popov * Free smbnode, and give vnode back to system 258681a5bbeSBoris Popov */ 259681a5bbeSBoris Popov int 260*b09b03a1SMateusz Guzik smbfs_reclaim(struct vop_reclaim_args *ap) 261681a5bbeSBoris Popov { 262681a5bbeSBoris Popov struct vnode *vp = ap->a_vp; 263681a5bbeSBoris Popov struct vnode *dvp; 264681a5bbeSBoris Popov struct smbnode *np = VTOSMB(vp); 265681a5bbeSBoris Popov struct smbmount *smp = VTOSMBFS(vp); 266681a5bbeSBoris Popov 2674d93c0beSJeff Roberson SMBVDEBUG("%s,%d\n", np->n_name, vrefcnt(vp)); 268681a5bbeSBoris Popov 2692a4ad258STim J. Robbins KASSERT((np->n_flag & NOPEN) == 0, ("file not closed before reclaim")); 2702a4ad258STim J. Robbins 271681a5bbeSBoris Popov dvp = (np->n_parent && (np->n_flag & NREFPARENT)) ? 27211de0c59STim J. Robbins np->n_parent : NULL; 273681a5bbeSBoris Popov 2748680dc80SDavide Italiano /* 2758680dc80SDavide Italiano * Remove the vnode from its hash chain. 2768680dc80SDavide Italiano */ 2778680dc80SDavide Italiano vfs_hash_remove(vp); 278681a5bbeSBoris Popov if (np->n_name) 279681a5bbeSBoris Popov smbfs_name_free(np->n_name); 28080704a47SDavide Italiano if (np->n_rpath) 28180704a47SDavide Italiano free(np->n_rpath, M_SMBNODENAME); 2821ede983cSDag-Erling Smørgrav free(np, M_SMBNODE); 2838680dc80SDavide Italiano vp->v_data = NULL; 28470a3c70aSTim J. Robbins if (dvp != NULL) { 285681a5bbeSBoris Popov vrele(dvp); 286578dcf0cSTim J. Robbins /* 287578dcf0cSTim J. Robbins * Indicate that we released something; see comment 288578dcf0cSTim J. Robbins * in smbfs_unmount(). 289578dcf0cSTim J. Robbins */ 290578dcf0cSTim J. Robbins smp->sm_didrele = 1; 291681a5bbeSBoris Popov } 292681a5bbeSBoris Popov return 0; 293681a5bbeSBoris Popov } 294681a5bbeSBoris Popov 295681a5bbeSBoris Popov int 296*b09b03a1SMateusz Guzik smbfs_inactive(struct vop_inactive_args *ap) 297681a5bbeSBoris Popov { 298ab21ed17SMateusz Guzik struct thread *td = curthread; 299a854ed98SJohn Baldwin struct ucred *cred = td->td_ucred; 300681a5bbeSBoris Popov struct vnode *vp = ap->a_vp; 301681a5bbeSBoris Popov struct smbnode *np = VTOSMB(vp); 302afe09751SDavide Italiano struct smb_cred *scred; 3032a4ad258STim J. Robbins struct vattr va; 304681a5bbeSBoris Popov 3054d93c0beSJeff Roberson SMBVDEBUG("%s: %d\n", VTOSMB(vp)->n_name, vrefcnt(vp)); 3062a4ad258STim J. Robbins if ((np->n_flag & NOPEN) != 0) { 307afe09751SDavide Italiano scred = smbfs_malloc_scred(); 308afe09751SDavide Italiano smb_makescred(scred, td, cred); 309e50508dfSPoul-Henning Kamp smbfs_vinvalbuf(vp, td); 3102a4ad258STim J. Robbins if (vp->v_type == VREG) { 3110359a12eSAttilio Rao VOP_GETATTR(vp, &va, cred); 3122a4ad258STim J. Robbins smbfs_smb_close(np->n_mount->sm_share, np->n_fid, 313afe09751SDavide Italiano &np->n_mtime, scred); 3142a4ad258STim J. Robbins } else if (vp->v_type == VDIR) { 3152a4ad258STim J. Robbins if (np->n_dirseq != NULL) { 316afe09751SDavide Italiano smbfs_findclose(np->n_dirseq, scred); 3172a4ad258STim J. Robbins np->n_dirseq = NULL; 318681a5bbeSBoris Popov } 3192a4ad258STim J. Robbins } 3202a4ad258STim J. Robbins np->n_flag &= ~NOPEN; 3212a4ad258STim J. Robbins smbfs_attr_cacheremove(vp); 322afe09751SDavide Italiano smbfs_free_scred(scred); 323208a7a97STim J. Robbins } 324b4484bf0STim J. Robbins if (np->n_flag & NGONE) 325af6e6b87SEdward Tomasz Napierala vrecycle(vp); 326681a5bbeSBoris Popov return (0); 327681a5bbeSBoris Popov } 328681a5bbeSBoris Popov /* 329681a5bbeSBoris Popov * routines to maintain vnode attributes cache 330681a5bbeSBoris Popov * smbfs_attr_cacheenter: unpack np.i to vattr structure 331681a5bbeSBoris Popov */ 332681a5bbeSBoris Popov void 333681a5bbeSBoris Popov smbfs_attr_cacheenter(struct vnode *vp, struct smbfattr *fap) 334681a5bbeSBoris Popov { 335681a5bbeSBoris Popov struct smbnode *np = VTOSMB(vp); 336681a5bbeSBoris Popov 337681a5bbeSBoris Popov if (vp->v_type == VREG) { 338681a5bbeSBoris Popov if (np->n_size != fap->fa_size) { 339681a5bbeSBoris Popov np->n_size = fap->fa_size; 340681a5bbeSBoris Popov vnode_pager_setsize(vp, np->n_size); 341681a5bbeSBoris Popov } 342681a5bbeSBoris Popov } else if (vp->v_type == VDIR) { 343681a5bbeSBoris Popov np->n_size = 16384; /* should be a better way ... */ 344681a5bbeSBoris Popov } else 345681a5bbeSBoris Popov return; 346681a5bbeSBoris Popov np->n_mtime = fap->fa_mtime; 347681a5bbeSBoris Popov np->n_dosattr = fap->fa_attr; 348681a5bbeSBoris Popov np->n_attrage = time_second; 349681a5bbeSBoris Popov return; 350681a5bbeSBoris Popov } 351681a5bbeSBoris Popov 352681a5bbeSBoris Popov int 353681a5bbeSBoris Popov smbfs_attr_cachelookup(struct vnode *vp, struct vattr *va) 354681a5bbeSBoris Popov { 355681a5bbeSBoris Popov struct smbnode *np = VTOSMB(vp); 356681a5bbeSBoris Popov struct smbmount *smp = VTOSMBFS(vp); 357681a5bbeSBoris Popov int diff; 358681a5bbeSBoris Popov 359681a5bbeSBoris Popov diff = time_second - np->n_attrage; 360681a5bbeSBoris Popov if (diff > 2) /* XXX should be configurable */ 361681a5bbeSBoris Popov return ENOENT; 362681a5bbeSBoris Popov va->va_type = vp->v_type; /* vnode type (for create) */ 3637da1a731SKenneth D. Merry va->va_flags = 0; /* flags defined for file */ 364681a5bbeSBoris Popov if (vp->v_type == VREG) { 365d14c8441SPoul-Henning Kamp va->va_mode = smp->sm_file_mode; /* files access mode and type */ 3667da1a731SKenneth D. Merry if (np->n_dosattr & SMB_FA_RDONLY) { 367fb8e9eadSBoris Popov va->va_mode &= ~(S_IWUSR|S_IWGRP|S_IWOTH); 3687da1a731SKenneth D. Merry va->va_flags |= UF_READONLY; 3697da1a731SKenneth D. Merry } 370681a5bbeSBoris Popov } else if (vp->v_type == VDIR) { 371d14c8441SPoul-Henning Kamp va->va_mode = smp->sm_dir_mode; /* files access mode and type */ 372681a5bbeSBoris Popov } else 373681a5bbeSBoris Popov return EINVAL; 374681a5bbeSBoris Popov va->va_size = np->n_size; 375681a5bbeSBoris Popov va->va_nlink = 1; /* number of references to file */ 376d14c8441SPoul-Henning Kamp va->va_uid = smp->sm_uid; /* owner user id */ 377d14c8441SPoul-Henning Kamp va->va_gid = smp->sm_gid; /* owner group id */ 378681a5bbeSBoris Popov va->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0]; 379681a5bbeSBoris Popov va->va_fileid = np->n_ino; /* file id */ 380681a5bbeSBoris Popov if (va->va_fileid == 0) 381681a5bbeSBoris Popov va->va_fileid = 2; 382681a5bbeSBoris Popov va->va_blocksize = SSTOVC(smp->sm_share)->vc_txmax; 383681a5bbeSBoris Popov va->va_mtime = np->n_mtime; 384681a5bbeSBoris Popov va->va_atime = va->va_ctime = va->va_mtime; /* time file changed */ 385681a5bbeSBoris Popov va->va_gen = VNOVAL; /* generation number of file */ 3867da1a731SKenneth D. Merry if (np->n_dosattr & SMB_FA_HIDDEN) 3877da1a731SKenneth D. Merry va->va_flags |= UF_HIDDEN; 3887da1a731SKenneth D. Merry if (np->n_dosattr & SMB_FA_SYSTEM) 3897da1a731SKenneth D. Merry va->va_flags |= UF_SYSTEM; 3907da1a731SKenneth D. Merry /* 3917da1a731SKenneth D. Merry * We don't set the archive bit for directories. 3927da1a731SKenneth D. Merry */ 3937da1a731SKenneth D. Merry if ((vp->v_type != VDIR) && (np->n_dosattr & SMB_FA_ARCHIVE)) 3947da1a731SKenneth D. Merry va->va_flags |= UF_ARCHIVE; 3954c5a20e3SKonstantin Belousov va->va_rdev = NODEV; /* device the special file represents */ 396681a5bbeSBoris Popov va->va_bytes = va->va_size; /* bytes of disk space held by file */ 397681a5bbeSBoris Popov va->va_filerev = 0; /* file modification number */ 398681a5bbeSBoris Popov va->va_vaflags = 0; /* operations flags */ 399681a5bbeSBoris Popov return 0; 400681a5bbeSBoris Popov } 401