nwfs_vfsops.c revision 96755
151852Sbp/* 266539Sbp * Copyright (c) 1999, 2000 Boris Popov 351852Sbp * All rights reserved. 451852Sbp * 551852Sbp * Redistribution and use in source and binary forms, with or without 651852Sbp * modification, are permitted provided that the following conditions 751852Sbp * are met: 851852Sbp * 1. Redistributions of source code must retain the above copyright 951852Sbp * notice, this list of conditions and the following disclaimer. 1051852Sbp * 2. Redistributions in binary form must reproduce the above copyright 1151852Sbp * notice, this list of conditions and the following disclaimer in the 1251852Sbp * documentation and/or other materials provided with the distribution. 1351852Sbp * 3. All advertising materials mentioning features or use of this software 1451852Sbp * must display the following acknowledgement: 1551852Sbp * This product includes software developed by Boris Popov. 1651852Sbp * 4. Neither the name of the author nor the names of any co-contributors 1751852Sbp * may be used to endorse or promote products derived from this software 1851852Sbp * without specific prior written permission. 1951852Sbp * 2051852Sbp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2151852Sbp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2251852Sbp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2351852Sbp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2451852Sbp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2551852Sbp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2651852Sbp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2751852Sbp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2851852Sbp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2951852Sbp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3051852Sbp * SUCH DAMAGE. 3151852Sbp * 3251852Sbp * $FreeBSD: head/sys/fs/nwfs/nwfs_vfsops.c 96755 2002-05-16 21:28:32Z trhodes $ 3351852Sbp */ 3451852Sbp#include "opt_ncp.h" 3551852Sbp#ifndef NCP 3651852Sbp#error "NWFS requires NCP protocol" 3751852Sbp#endif 3851852Sbp 3951852Sbp#include <sys/param.h> 4051852Sbp#include <sys/systm.h> 4151852Sbp#include <sys/proc.h> 4251852Sbp#include <sys/kernel.h> 4351852Sbp#include <sys/sysctl.h> 4451852Sbp#include <sys/vnode.h> 4551852Sbp#include <sys/mount.h> 4651852Sbp#include <sys/stat.h> 4751852Sbp#include <sys/malloc.h> 4860041Sphk#include <sys/bio.h> 4951852Sbp#include <sys/buf.h> 5051852Sbp 5151852Sbp#include <netncp/ncp.h> 5251852Sbp#include <netncp/ncp_conn.h> 5351852Sbp#include <netncp/ncp_subr.h> 5451852Sbp#include <netncp/ncp_ncp.h> 5551852Sbp#include <netncp/ncp_nls.h> 5651852Sbp 5777223Sru#include <fs/nwfs/nwfs.h> 5877223Sru#include <fs/nwfs/nwfs_node.h> 5977223Sru#include <fs/nwfs/nwfs_subr.h> 6051852Sbp 6151852Sbpint nwfs_debuglevel = 0; 6251852Sbp 6351852Sbpstatic int nwfs_version = NWFS_VERSION; 6451852Sbp 6551852SbpSYSCTL_DECL(_vfs_nwfs); 6696755StrhodesSYSCTL_NODE(_vfs, OID_AUTO, nwfs, CTLFLAG_RW, 0, "Netware filesystem"); 6751852SbpSYSCTL_INT(_vfs_nwfs, OID_AUTO, version, CTLFLAG_RD, &nwfs_version, 0, ""); 6851852SbpSYSCTL_INT(_vfs_nwfs, OID_AUTO, debuglevel, CTLFLAG_RW, &nwfs_debuglevel, 0, ""); 6951852Sbp 7059755SpeterMODULE_DEPEND(nwfs, ncp, 1, 1, 1); 7174637SbpMODULE_DEPEND(nwfs, libmchain, 1, 1, 1); 7259755Speter 7366539Sbpstatic int nwfs_mount(struct mount *, char *, caddr_t, 7483366Sjulian struct nameidata *, struct thread *); 7583366Sjulianstatic int nwfs_quotactl(struct mount *, int, uid_t, caddr_t, struct thread *); 7666539Sbpstatic int nwfs_root(struct mount *, struct vnode **); 7783366Sjulianstatic int nwfs_start(struct mount *, int, struct thread *); 7883366Sjulianstatic int nwfs_statfs(struct mount *, struct statfs *, struct thread *); 7983366Sjulianstatic int nwfs_sync(struct mount *, int, struct ucred *, struct thread *); 8083366Sjulianstatic int nwfs_unmount(struct mount *, int, struct thread *); 8166539Sbpstatic int nwfs_init(struct vfsconf *vfsp); 8266539Sbpstatic int nwfs_uninit(struct vfsconf *vfsp); 8351852Sbp 8451852Sbpstatic struct vfsops nwfs_vfsops = { 8551852Sbp nwfs_mount, 8651852Sbp nwfs_start, 8751852Sbp nwfs_unmount, 8851852Sbp nwfs_root, 8951852Sbp nwfs_quotactl, 9051852Sbp nwfs_statfs, 9151852Sbp nwfs_sync, 9251852Sbp vfs_stdvget, 9351852Sbp vfs_stdfhtovp, /* shouldn't happen */ 9451852Sbp vfs_stdcheckexp, 9551852Sbp vfs_stdvptofh, /* shouldn't happen */ 9651852Sbp nwfs_init, 9754803Srwatson nwfs_uninit, 9854803Srwatson vfs_stdextattrctl, 9951852Sbp}; 10051852Sbp 10151852Sbp 10251852SbpVFS_SET(nwfs_vfsops, nwfs, VFCF_NETWORK); 10351852Sbp 10451852Sbpint nwfs_pbuf_freecnt = -1; /* start out unlimited */ 10551852Sbpstatic int nwfsid = 1; 10651852Sbp 10751852Sbpstatic int 10851852Sbpnwfs_initnls(struct nwmount *nmp) { 10951852Sbp char *pc, *pe; 11051852Sbp int error = 0; 11151852Sbp#define COPY_TABLE(t,d) { \ 11251852Sbp if (t) { \ 11351852Sbp error = copyin((t), pc, 256); \ 11451852Sbp if (error) break; \ 11551852Sbp } else \ 11651852Sbp bcopy(d, pc, 256); \ 11751852Sbp (t) = pc; pc += 256; \ 11851852Sbp } 11951852Sbp 12051852Sbp nmp->m.nls.opt |= NWHP_NLS | NWHP_DOS; 12151852Sbp if ((nmp->m.flags & NWFS_MOUNT_HAVE_NLS) == 0) { 12252814Sarchie nmp->m.nls.to_lower = ncp_defnls.to_lower; 12352814Sarchie nmp->m.nls.to_upper = ncp_defnls.to_upper; 12451852Sbp nmp->m.nls.n2u = ncp_defnls.n2u; 12551852Sbp nmp->m.nls.u2n = ncp_defnls.u2n; 12651852Sbp return 0; 12751852Sbp } 12851852Sbp MALLOC(pe, char *, 256 * 4, M_NWFSDATA, M_WAITOK); 12951852Sbp pc = pe; 13051852Sbp do { 13152814Sarchie COPY_TABLE(nmp->m.nls.to_lower, ncp_defnls.to_lower); 13252814Sarchie COPY_TABLE(nmp->m.nls.to_upper, ncp_defnls.to_upper); 13351852Sbp COPY_TABLE(nmp->m.nls.n2u, ncp_defnls.n2u); 13451852Sbp COPY_TABLE(nmp->m.nls.u2n, ncp_defnls.u2n); 13551852Sbp } while(0); 13651852Sbp if (error) { 13751852Sbp free(pe, M_NWFSDATA); 13851852Sbp return error; 13951852Sbp } 14051852Sbp return 0; 14151852Sbp} 14251852Sbp/* 14351852Sbp * mp - path - addr in user space of mount point (ie /usr or whatever) 14451852Sbp * data - addr in user space of mount params 14551852Sbp */ 14651852Sbpstatic int nwfs_mount(struct mount *mp, char *path, caddr_t data, 14783366Sjulian struct nameidata *ndp, struct thread *td) 14851852Sbp{ 14951852Sbp struct nwfs_args args; /* will hold data from mount request */ 15051852Sbp int error; 15151852Sbp struct nwmount *nmp = NULL; 15251852Sbp struct ncp_conn *conn = NULL; 15351852Sbp struct ncp_handle *handle = NULL; 15451852Sbp struct vnode *vp; 15551852Sbp char *pc,*pe; 15651852Sbp 15751852Sbp if (data == NULL) { 15851852Sbp nwfs_printf("missing data argument\n"); 15951852Sbp return 1; 16051852Sbp } 16151852Sbp if (mp->mnt_flag & MNT_UPDATE) { 16251852Sbp nwfs_printf("MNT_UPDATE not implemented"); 16351852Sbp return (EOPNOTSUPP); 16451852Sbp } 16551852Sbp error = copyin(data, (caddr_t)&args, sizeof(struct nwfs_args)); 16651852Sbp if (error) 16751852Sbp return (error); 16851852Sbp if (args.version != NWFS_VERSION) { 16951852Sbp nwfs_printf("mount version mismatch: kernel=%d, mount=%d\n",NWFS_VERSION,args.version); 17051852Sbp return (1); 17151852Sbp } 17291406Sjhb error = ncp_conn_getbyref(args.connRef, td , td->td_ucred,NCPM_EXECUTE,&conn); 17351852Sbp if (error) { 17451852Sbp nwfs_printf("invalid connection refernce %d\n",args.connRef); 17551852Sbp return (error); 17651852Sbp } 17751852Sbp error = ncp_conn_gethandle(conn, NULL, &handle); 17851852Sbp if (error) { 17951852Sbp nwfs_printf("can't get connection handle\n"); 18051852Sbp return (error); 18151852Sbp } 18283366Sjulian ncp_conn_unlock(conn, td); /* we keep the ref */ 18351852Sbp mp->mnt_stat.f_iosize = conn->buffer_size; 18451852Sbp /* We must malloc our own mount info */ 18567895Sdwmalone MALLOC(nmp,struct nwmount *,sizeof(struct nwmount),M_NWFSDATA,M_USE_RESERVE | M_ZERO); 18651852Sbp if (nmp == NULL) { 18751852Sbp nwfs_printf("could not alloc nwmount\n"); 18851852Sbp error = ENOMEM; 18951852Sbp goto bad; 19051852Sbp } 19151852Sbp mp->mnt_data = (qaddr_t)nmp; 19251852Sbp nmp->connh = handle; 19351852Sbp nmp->n_root = NULL; 19451852Sbp nmp->n_id = nwfsid++; 19551852Sbp nmp->m = args; 19651852Sbp nmp->m.file_mode = (nmp->m.file_mode & 19751852Sbp (S_IRWXU|S_IRWXG|S_IRWXO)) | S_IFREG; 19851852Sbp nmp->m.dir_mode = (nmp->m.dir_mode & 19951852Sbp (S_IRWXU|S_IRWXG|S_IRWXO)) | S_IFDIR; 20051852Sbp if ((error = nwfs_initnls(nmp)) != 0) goto bad; 20151852Sbp pc = mp->mnt_stat.f_mntfromname; 20251852Sbp pe = pc+sizeof(mp->mnt_stat.f_mntfromname); 20351852Sbp bzero(pc, MNAMELEN); 20451852Sbp *(pc++) = '/'; 20551852Sbp pc = index(strncpy(pc, conn->li.server, pe-pc-2),0); 20651852Sbp if (pc < pe-1) { 20751852Sbp *(pc++) = ':'; 20851852Sbp pc=index(strncpy(pc, conn->li.user, pe-pc-2),0); 20951852Sbp if (pc < pe-1) { 21051852Sbp *(pc++) = '/'; 21151852Sbp strncpy(pc, nmp->m.mounted_vol, pe-pc-2); 21251852Sbp } 21351852Sbp } 21451852Sbp /* protect against invalid mount points */ 21551852Sbp nmp->m.mount_point[sizeof(nmp->m.mount_point)-1] = '\0'; 21651852Sbp vfs_getnewfsid(mp); 21751852Sbp error = nwfs_root(mp, &vp); 21851852Sbp if (error) 21951852Sbp goto bad; 22051852Sbp /* 22151852Sbp * Lose the lock but keep the ref. 22251852Sbp */ 22383366Sjulian VOP_UNLOCK(vp, 0, curthread); 22451852Sbp NCPVODEBUG("rootvp.vrefcnt=%d\n",vp->v_usecount); 22551852Sbp return error; 22651852Sbpbad: 22751852Sbp if (nmp) 22851852Sbp free(nmp, M_NWFSDATA); 22951852Sbp if (handle) 23051852Sbp ncp_conn_puthandle(handle, NULL, 0); 23151852Sbp return error; 23251852Sbp} 23351852Sbp 23451852Sbp/* Unmount the filesystem described by mp. */ 23551852Sbpstatic int 23683366Sjuliannwfs_unmount(struct mount *mp, int mntflags, struct thread *td) 23751852Sbp{ 23851852Sbp struct nwmount *nmp = VFSTONWFS(mp); 23951852Sbp struct ncp_conn *conn; 24051852Sbp int error, flags; 24151852Sbp 24251852Sbp NCPVODEBUG("nwfs_unmount: flags=%04x\n",mntflags); 24351852Sbp flags = 0; 24451852Sbp if (mntflags & MNT_FORCE) 24551852Sbp flags |= FORCECLOSE; 24676688Siedowse /* There is 1 extra root vnode reference from nwfs_mount(). */ 24776688Siedowse error = vflush(mp, 1, flags); 24876688Siedowse if (error) 24951852Sbp return (error); 25051852Sbp conn = NWFSTOCONN(nmp); 25151852Sbp ncp_conn_puthandle(nmp->connh,NULL,0); 25291406Sjhb if (ncp_conn_lock(conn, td, td->td_ucred,NCPM_WRITE | NCPM_EXECUTE) == 0) { 25374062Sbp if(ncp_conn_free(conn)) 25483366Sjulian ncp_conn_unlock(conn, td); 25551852Sbp } 25651852Sbp mp->mnt_data = (qaddr_t)0; 25751852Sbp if (nmp->m.flags & NWFS_MOUNT_HAVE_NLS) 25852814Sarchie free(nmp->m.nls.to_lower, M_NWFSDATA); 25951852Sbp free(nmp, M_NWFSDATA); 26051852Sbp mp->mnt_flag &= ~MNT_LOCAL; 26151852Sbp return (error); 26251852Sbp} 26351852Sbp 26451852Sbp/* Return locked vnode to root of a filesystem */ 26551852Sbpstatic int 26651852Sbpnwfs_root(struct mount *mp, struct vnode **vpp) { 26751852Sbp struct vnode *vp; 26851852Sbp struct nwmount *nmp; 26951852Sbp struct nwnode *np; 27051852Sbp struct ncp_conn *conn; 27151852Sbp struct nw_entry_info fattr; 27283366Sjulian struct thread *td = curthread; 27391406Sjhb struct ucred *cred = td->td_ucred; 27451852Sbp int error, nsf, opt; 27551852Sbp u_char vol; 27651852Sbp 27751852Sbp nmp = VFSTONWFS(mp); 27851852Sbp conn = NWFSTOCONN(nmp); 27951852Sbp if (nmp->n_root) { 28051852Sbp *vpp = NWTOV(nmp->n_root); 28183366Sjulian while (vget(*vpp, LK_EXCLUSIVE, curthread) != 0) 28266540Sbp ; 28351852Sbp return 0; 28451852Sbp } 28551852Sbp error = ncp_lookup_volume(conn, nmp->m.mounted_vol, &vol, 28683366Sjulian &nmp->n_rootent.f_id, td, cred); 28751852Sbp if (error) 28851852Sbp return ENOENT; 28951852Sbp nmp->n_volume = vol; 29083366Sjulian error = ncp_get_namespaces(conn, vol, &nsf, td, cred); 29151852Sbp if (error) 29251852Sbp return ENOENT; 29351852Sbp if (nsf & NW_NSB_OS2) { 29451852Sbp NCPVODEBUG("volume %s has os2 namespace\n",nmp->m.mounted_vol); 29551852Sbp if ((nmp->m.flags & NWFS_MOUNT_NO_OS2) == 0) { 29651852Sbp nmp->name_space = NW_NS_OS2; 29751852Sbp nmp->m.nls.opt &= ~NWHP_DOS; 29851852Sbp } 29951852Sbp } 30051852Sbp opt = nmp->m.nls.opt; 30151852Sbp nsf = opt & (NWHP_UPPER | NWHP_LOWER); 30251852Sbp if (opt & NWHP_DOS) { 30351852Sbp if (nsf == (NWHP_UPPER | NWHP_LOWER)) { 30451852Sbp nmp->m.nls.opt &= ~(NWHP_LOWER | NWHP_UPPER); 30551852Sbp } else if (nsf == 0) { 30651852Sbp nmp->m.nls.opt |= NWHP_LOWER; 30751852Sbp } 30851852Sbp } else { 30951852Sbp if (nsf == (NWHP_UPPER | NWHP_LOWER)) { 31051852Sbp nmp->m.nls.opt &= ~(NWHP_LOWER | NWHP_UPPER); 31151852Sbp } 31251852Sbp } 31351852Sbp if (nmp->m.root_path[0]) { 31451852Sbp nmp->m.root_path[0]--; 31551852Sbp error = ncp_obtain_info(nmp, nmp->n_rootent.f_id, 31683366Sjulian -nmp->m.root_path[0], nmp->m.root_path, &fattr, td, cred); 31751852Sbp if (error) { 31851852Sbp NCPFATAL("Invalid root path specified\n"); 31951852Sbp return ENOENT; 32051852Sbp } 32151852Sbp nmp->n_rootent.f_parent = fattr.dirEntNum; 32251852Sbp nmp->m.root_path[0]++; 32351852Sbp error = ncp_obtain_info(nmp, nmp->n_rootent.f_id, 32483366Sjulian -nmp->m.root_path[0], nmp->m.root_path, &fattr, td, cred); 32551852Sbp if (error) { 32651852Sbp NCPFATAL("Invalid root path specified\n"); 32751852Sbp return ENOENT; 32851852Sbp } 32951852Sbp nmp->n_rootent.f_id = fattr.dirEntNum; 33051852Sbp } else { 33151852Sbp error = ncp_obtain_info(nmp, nmp->n_rootent.f_id, 33283366Sjulian 0, NULL, &fattr, td, cred); 33351852Sbp if (error) { 33451852Sbp NCPFATAL("Can't obtain volume info\n"); 33551852Sbp return ENOENT; 33651852Sbp } 33774064Sbp fattr.nameLen = strlen(strcpy(fattr.entryName, "#.ROOT")); 33851852Sbp nmp->n_rootent.f_parent = nmp->n_rootent.f_id; 33951852Sbp } 34051852Sbp error = nwfs_nget(mp, nmp->n_rootent, &fattr, NULL, &vp); 34151852Sbp if (error) 34251852Sbp return (error); 34351852Sbp vp->v_flag |= VROOT; 34451852Sbp np = VTONW(vp); 34551852Sbp if (nmp->m.root_path[0] == 0) 34651852Sbp np->n_flag |= NVOLUME; 34751852Sbp nmp->n_root = np; 34883366Sjulian/* error = VOP_GETATTR(vp, &vattr, cred, td); 34951852Sbp if (error) { 35051852Sbp vput(vp); 35151852Sbp NCPFATAL("Can't get root directory entry\n"); 35251852Sbp return error; 35351852Sbp }*/ 35451852Sbp *vpp = vp; 35551852Sbp return (0); 35651852Sbp} 35751852Sbp 35851852Sbp/* 35951852Sbp * Vfs start routine, a no-op. 36051852Sbp */ 36151852Sbp/* ARGSUSED */ 36251852Sbpstatic int 36383366Sjuliannwfs_start(mp, flags, td) 36451852Sbp struct mount *mp; 36551852Sbp int flags; 36683366Sjulian struct thread *td; 36751852Sbp{ 36851852Sbp NCPVODEBUG("flags=%04x\n",flags); 36951852Sbp return (0); 37051852Sbp} 37151852Sbp 37251852Sbp/* 37351852Sbp * Do operations associated with quotas, not supported 37451852Sbp */ 37551852Sbp/* ARGSUSED */ 37651852Sbpstatic int 37783366Sjuliannwfs_quotactl(mp, cmd, uid, arg, td) 37851852Sbp struct mount *mp; 37951852Sbp int cmd; 38051852Sbp uid_t uid; 38151852Sbp caddr_t arg; 38283366Sjulian struct thread *td; 38351852Sbp{ 38451852Sbp NCPVODEBUG("return EOPNOTSUPP\n"); 38551852Sbp return (EOPNOTSUPP); 38651852Sbp} 38751852Sbp 38851852Sbp/*ARGSUSED*/ 38951852Sbpint 39051852Sbpnwfs_init(struct vfsconf *vfsp) 39151852Sbp{ 39256034Sbp#ifndef SMP 39356034Sbp int name[2]; 39456034Sbp int olen, ncpu, plen, error; 39551852Sbp 39656034Sbp name[0] = CTL_HW; 39756034Sbp name[1] = HW_NCPU; 39883366Sjulian error = kernel_sysctl(curthread, name, 2, &ncpu, &olen, NULL, 0, &plen); 39956034Sbp if (error == 0 && ncpu > 1) 40056034Sbp printf("warning: nwfs module compiled without SMP support."); 40156034Sbp#endif 40251852Sbp nwfs_hash_init(); 40351852Sbp nwfs_pbuf_freecnt = nswbuf / 2 + 1; 40451852Sbp NCPVODEBUG("always happy to load!\n"); 40551852Sbp return (0); 40651852Sbp} 40751852Sbp 40851852Sbp/*ARGSUSED*/ 40951852Sbpint 41051852Sbpnwfs_uninit(struct vfsconf *vfsp) 41151852Sbp{ 41251852Sbp 41351852Sbp nwfs_hash_free(); 41451852Sbp NCPVODEBUG("unloaded\n"); 41551852Sbp return (0); 41651852Sbp} 41751852Sbp 41851852Sbp/* 41951852Sbp * nwfs_statfs call 42051852Sbp */ 42151852Sbpint 42283366Sjuliannwfs_statfs(mp, sbp, td) 42351852Sbp struct mount *mp; 42466539Sbp struct statfs *sbp; 42583366Sjulian struct thread *td; 42651852Sbp{ 42751852Sbp struct nwmount *nmp = VFSTONWFS(mp); 42851852Sbp int error = 0, secsize; 42951852Sbp struct nwnode *np = nmp->n_root; 43051852Sbp struct ncp_volume_info vi; 43151852Sbp 43251852Sbp if (np == NULL) return EINVAL; 43383366Sjulian error = ncp_get_volume_info_with_number(NWFSTOCONN(nmp), 43491406Sjhb nmp->n_volume, &vi, td, td->td_ucred); 43551852Sbp if (error) return error; 43651852Sbp secsize = 512; /* XXX how to get real value ??? */ 43751852Sbp sbp->f_spare2=0; /* placeholder */ 43896755Strhodes /* fundamental filesystem block size */ 43951852Sbp sbp->f_bsize = vi.sectors_per_block*secsize; 44051852Sbp /* optimal transfer block size */ 44151852Sbp sbp->f_iosize = NWFSTOCONN(nmp)->buffer_size; 44296755Strhodes /* total data blocks in filesystem */ 44351852Sbp sbp->f_blocks= vi.total_blocks; 44451852Sbp /* free blocks in fs */ 44551852Sbp sbp->f_bfree = vi.free_blocks + vi.purgeable_blocks; 44651852Sbp /* free blocks avail to non-superuser */ 44751852Sbp sbp->f_bavail= vi.free_blocks+vi.purgeable_blocks; 44896755Strhodes /* total file nodes in filesystem */ 44951852Sbp sbp->f_files = vi.total_dir_entries; 45051852Sbp /* free file nodes in fs */ 45151852Sbp sbp->f_ffree = vi.available_dir_entries; 45251852Sbp sbp->f_flags = 0; /* copy of mount exported flags */ 45351852Sbp if (sbp != &mp->mnt_stat) { 45496755Strhodes sbp->f_fsid = mp->mnt_stat.f_fsid; /* filesystem id */ 45551852Sbp sbp->f_owner = mp->mnt_stat.f_owner; /* user that mounted the filesystem */ 45651852Sbp sbp->f_type = mp->mnt_vfc->vfc_typenum; /* type of filesystem */ 45751852Sbp bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); 45851852Sbp bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); 45951852Sbp } 46051852Sbp strncpy(sbp->f_fstypename, mp->mnt_vfc->vfc_name, MFSNAMELEN); 46151852Sbp return 0; 46251852Sbp} 46351852Sbp 46451852Sbp/* 46551852Sbp * Flush out the buffer cache 46651852Sbp */ 46751852Sbp/* ARGSUSED */ 46851852Sbpstatic int 46983366Sjuliannwfs_sync(mp, waitfor, cred, td) 47051852Sbp struct mount *mp; 47151852Sbp int waitfor; 47251852Sbp struct ucred *cred; 47383366Sjulian struct thread *td; 47451852Sbp{ 47578906Sjhb struct vnode *vp, *nvp; 47651852Sbp int error, allerror = 0; 47751852Sbp /* 47851852Sbp * Force stale buffer cache information to be flushed. 47951852Sbp */ 48078906Sjhb mtx_lock(&mntvnode_mtx); 48151852Sbploop: 48285339Sdillon for (vp = TAILQ_FIRST(&mp->mnt_nvnodelist); 48351852Sbp vp != NULL; 48478906Sjhb vp = nvp) { 48551852Sbp /* 48651852Sbp * If the vnode that we are about to sync is no longer 48751852Sbp * associated with this mount point, start over. 48851852Sbp */ 48951852Sbp if (vp->v_mount != mp) 49051852Sbp goto loop; 49185339Sdillon nvp = TAILQ_NEXT(vp, v_nmntvnodes); 49278906Sjhb mtx_unlock(&mntvnode_mtx); 49378906Sjhb mtx_lock(&vp->v_interlock); 49454444Seivind if (VOP_ISLOCKED(vp, NULL) || TAILQ_EMPTY(&vp->v_dirtyblkhd) || 49578906Sjhb waitfor == MNT_LAZY) { 49678906Sjhb mtx_unlock(&vp->v_interlock); 49778906Sjhb mtx_lock(&mntvnode_mtx); 49851852Sbp continue; 49978906Sjhb } 50083366Sjulian if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, td)) { 50178906Sjhb mtx_lock(&mntvnode_mtx); 50251852Sbp goto loop; 50378906Sjhb } 50483366Sjulian error = VOP_FSYNC(vp, cred, waitfor, td); 50551852Sbp if (error) 50651852Sbp allerror = error; 50751852Sbp vput(vp); 50878906Sjhb mtx_lock(&mntvnode_mtx); 50951852Sbp } 51078906Sjhb mtx_unlock(&mntvnode_mtx); 51151852Sbp return (allerror); 51251852Sbp} 513