nwfs_vfsops.c revision 60041
151852Sbp/* 251852Sbp * Copyright (c) 1999, 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 60041 2000-05-05 09:59:14Z phk $ 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 5751852Sbp#include <nwfs/nwfs.h> 5851852Sbp#include <nwfs/nwfs_node.h> 5951852Sbp#include <nwfs/nwfs_subr.h> 6051852Sbp 6151852Sbpint nwfs_debuglevel = 0; 6251852Sbp 6351852Sbpstatic int nwfs_version = NWFS_VERSION; 6451852Sbp 6551852SbpSYSCTL_DECL(_vfs_nwfs); 6651852SbpSYSCTL_NODE(_vfs, OID_AUTO, nwfs, CTLFLAG_RW, 0, "Netware file system"); 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); 7159755Speter 7251852Sbpstatic int nwfs_mount __P((struct mount *, char *, caddr_t, 7351852Sbp struct nameidata *, struct proc *)); 7451852Sbpstatic int nwfs_quotactl __P((struct mount *, int, uid_t, caddr_t, 7551852Sbp struct proc *)); 7651852Sbpstatic int nwfs_root __P((struct mount *, struct vnode **)); 7751852Sbpstatic int nwfs_start __P((struct mount *, int, struct proc *)); 7851852Sbpstatic int nwfs_statfs __P((struct mount *, struct statfs *, 7951852Sbp struct proc *)); 8051852Sbpstatic int nwfs_sync __P((struct mount *, int, struct ucred *, 8151852Sbp struct proc *)); 8251852Sbpstatic int nwfs_unmount __P((struct mount *, int, struct proc *)); 8351852Sbpstatic int nwfs_init __P((struct vfsconf *vfsp)); 8451852Sbpstatic int nwfs_uninit __P((struct vfsconf *vfsp)); 8551852Sbp 8651852Sbpstatic struct vfsops nwfs_vfsops = { 8751852Sbp nwfs_mount, 8851852Sbp nwfs_start, 8951852Sbp nwfs_unmount, 9051852Sbp nwfs_root, 9151852Sbp nwfs_quotactl, 9251852Sbp nwfs_statfs, 9351852Sbp nwfs_sync, 9451852Sbp vfs_stdvget, 9551852Sbp vfs_stdfhtovp, /* shouldn't happen */ 9651852Sbp vfs_stdcheckexp, 9751852Sbp vfs_stdvptofh, /* shouldn't happen */ 9851852Sbp nwfs_init, 9954803Srwatson nwfs_uninit, 10054803Srwatson vfs_stdextattrctl, 10151852Sbp}; 10251852Sbp 10351852Sbp 10451852SbpVFS_SET(nwfs_vfsops, nwfs, VFCF_NETWORK); 10551852Sbp 10651852Sbpint nwfs_pbuf_freecnt = -1; /* start out unlimited */ 10751852Sbpstatic int nwfsid = 1; 10851852Sbp 10951852Sbpstatic int 11051852Sbpnwfs_initnls(struct nwmount *nmp) { 11151852Sbp char *pc, *pe; 11251852Sbp int error = 0; 11351852Sbp#define COPY_TABLE(t,d) { \ 11451852Sbp if (t) { \ 11551852Sbp error = copyin((t), pc, 256); \ 11651852Sbp if (error) break; \ 11751852Sbp } else \ 11851852Sbp bcopy(d, pc, 256); \ 11951852Sbp (t) = pc; pc += 256; \ 12051852Sbp } 12151852Sbp 12251852Sbp nmp->m.nls.opt |= NWHP_NLS | NWHP_DOS; 12351852Sbp if ((nmp->m.flags & NWFS_MOUNT_HAVE_NLS) == 0) { 12452814Sarchie nmp->m.nls.to_lower = ncp_defnls.to_lower; 12552814Sarchie nmp->m.nls.to_upper = ncp_defnls.to_upper; 12651852Sbp nmp->m.nls.n2u = ncp_defnls.n2u; 12751852Sbp nmp->m.nls.u2n = ncp_defnls.u2n; 12851852Sbp return 0; 12951852Sbp } 13051852Sbp MALLOC(pe, char *, 256 * 4, M_NWFSDATA, M_WAITOK); 13151852Sbp if (pe == NULL) return ENOMEM; 13251852Sbp pc = pe; 13351852Sbp do { 13452814Sarchie COPY_TABLE(nmp->m.nls.to_lower, ncp_defnls.to_lower); 13552814Sarchie COPY_TABLE(nmp->m.nls.to_upper, ncp_defnls.to_upper); 13651852Sbp COPY_TABLE(nmp->m.nls.n2u, ncp_defnls.n2u); 13751852Sbp COPY_TABLE(nmp->m.nls.u2n, ncp_defnls.u2n); 13851852Sbp } while(0); 13951852Sbp if (error) { 14051852Sbp free(pe, M_NWFSDATA); 14151852Sbp return error; 14251852Sbp } 14351852Sbp return 0; 14451852Sbp} 14551852Sbp/* 14651852Sbp * mp - path - addr in user space of mount point (ie /usr or whatever) 14751852Sbp * data - addr in user space of mount params 14851852Sbp */ 14951852Sbpstatic int nwfs_mount(struct mount *mp, char *path, caddr_t data, 15051852Sbp struct nameidata *ndp, struct proc *p) 15151852Sbp{ 15251852Sbp struct nwfs_args args; /* will hold data from mount request */ 15351852Sbp size_t size; 15451852Sbp int error; 15551852Sbp struct nwmount *nmp = NULL; 15651852Sbp struct ncp_conn *conn = NULL; 15751852Sbp struct ncp_handle *handle = NULL; 15851852Sbp struct vnode *vp; 15951852Sbp char *pc,*pe; 16051852Sbp 16151852Sbp if (data == NULL) { 16251852Sbp nwfs_printf("missing data argument\n"); 16351852Sbp return 1; 16451852Sbp } 16551852Sbp if (mp->mnt_flag & MNT_UPDATE) { 16651852Sbp nwfs_printf("MNT_UPDATE not implemented"); 16751852Sbp return (EOPNOTSUPP); 16851852Sbp } 16951852Sbp error = copyin(data, (caddr_t)&args, sizeof(struct nwfs_args)); 17051852Sbp if (error) 17151852Sbp return (error); 17251852Sbp if (args.version != NWFS_VERSION) { 17351852Sbp nwfs_printf("mount version mismatch: kernel=%d, mount=%d\n",NWFS_VERSION,args.version); 17451852Sbp return (1); 17551852Sbp } 17651852Sbp error = ncp_conn_getbyref(args.connRef,p,p->p_ucred,NCPM_EXECUTE,&conn); 17751852Sbp if (error) { 17851852Sbp nwfs_printf("invalid connection refernce %d\n",args.connRef); 17951852Sbp return (error); 18051852Sbp } 18151852Sbp error = ncp_conn_gethandle(conn, NULL, &handle); 18251852Sbp if (error) { 18351852Sbp nwfs_printf("can't get connection handle\n"); 18451852Sbp return (error); 18551852Sbp } 18651852Sbp ncp_conn_unlock(conn,p); /* we keep the ref */ 18751852Sbp mp->mnt_stat.f_iosize = conn->buffer_size; 18851852Sbp /* We must malloc our own mount info */ 18951852Sbp MALLOC(nmp,struct nwmount *,sizeof(struct nwmount),M_NWFSDATA,M_USE_RESERVE); 19051852Sbp if (nmp == NULL) { 19151852Sbp nwfs_printf("could not alloc nwmount\n"); 19251852Sbp error = ENOMEM; 19351852Sbp goto bad; 19451852Sbp } 19551852Sbp bzero(nmp,sizeof(*nmp)); 19651852Sbp mp->mnt_data = (qaddr_t)nmp; 19751852Sbp nmp->connh = handle; 19851852Sbp nmp->n_root = NULL; 19951852Sbp nmp->n_id = nwfsid++; 20051852Sbp nmp->m = args; 20151852Sbp nmp->m.file_mode = (nmp->m.file_mode & 20251852Sbp (S_IRWXU|S_IRWXG|S_IRWXO)) | S_IFREG; 20351852Sbp nmp->m.dir_mode = (nmp->m.dir_mode & 20451852Sbp (S_IRWXU|S_IRWXG|S_IRWXO)) | S_IFDIR; 20551852Sbp if ((error = nwfs_initnls(nmp)) != 0) goto bad; 20651852Sbp (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); 20751852Sbp bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size); 20851852Sbp pc = mp->mnt_stat.f_mntfromname; 20951852Sbp pe = pc+sizeof(mp->mnt_stat.f_mntfromname); 21051852Sbp bzero(pc, MNAMELEN); 21151852Sbp *(pc++) = '/'; 21251852Sbp pc = index(strncpy(pc, conn->li.server, pe-pc-2),0); 21351852Sbp if (pc < pe-1) { 21451852Sbp *(pc++) = ':'; 21551852Sbp pc=index(strncpy(pc, conn->li.user, pe-pc-2),0); 21651852Sbp if (pc < pe-1) { 21751852Sbp *(pc++) = '/'; 21851852Sbp strncpy(pc, nmp->m.mounted_vol, pe-pc-2); 21951852Sbp } 22051852Sbp } 22151852Sbp /* protect against invalid mount points */ 22251852Sbp nmp->m.mount_point[sizeof(nmp->m.mount_point)-1] = '\0'; 22351852Sbp vfs_getnewfsid(mp); 22451852Sbp error = nwfs_root(mp, &vp); 22551852Sbp if (error) 22651852Sbp goto bad; 22751852Sbp /* 22851852Sbp * Lose the lock but keep the ref. 22951852Sbp */ 23051852Sbp VOP_UNLOCK(vp, 0, curproc); 23151852Sbp NCPVODEBUG("rootvp.vrefcnt=%d\n",vp->v_usecount); 23251852Sbp return error; 23351852Sbpbad: 23451852Sbp if (nmp) 23551852Sbp free(nmp, M_NWFSDATA); 23651852Sbp if (handle) 23751852Sbp ncp_conn_puthandle(handle, NULL, 0); 23851852Sbp return error; 23951852Sbp} 24051852Sbp 24151852Sbp/* Unmount the filesystem described by mp. */ 24251852Sbpstatic int 24351852Sbpnwfs_unmount(struct mount *mp, int mntflags, struct proc *p) 24451852Sbp{ 24551852Sbp struct nwmount *nmp = VFSTONWFS(mp); 24651852Sbp struct ncp_conn *conn; 24751852Sbp struct vnode *vp; 24851852Sbp int error, flags; 24951852Sbp 25051852Sbp NCPVODEBUG("nwfs_unmount: flags=%04x\n",mntflags); 25151852Sbp flags = 0; 25251852Sbp if (mntflags & MNT_FORCE) 25351852Sbp flags |= FORCECLOSE; 25451852Sbp error = VFS_ROOT(mp,&vp); 25551852Sbp if (error) return (error); 25651852Sbp if (vp->v_usecount > 2) { 25751852Sbp printf("nwfs_unmount: usecnt=%d\n",vp->v_usecount); 25851852Sbp vput(vp); 25951852Sbp return (EBUSY); 26051852Sbp } 26151852Sbp error = vflush(mp, vp, flags); 26251852Sbp if (error) { 26351852Sbp vput(vp); 26451852Sbp return (error); 26551852Sbp } 26651852Sbp /* 26751852Sbp * There are two reference counts and one lock to get rid of here. 26851852Sbp */ 26951852Sbp NCPVODEBUG("v_use: %d\n",vp->v_usecount); 27051852Sbp vput(vp); 27151852Sbp NCPVODEBUG("v_use after vput: %d\n",vp->v_usecount); 27251852Sbp vrele(vp); 27351852Sbp NCPVODEBUG("v_use after vrele: %d\n",vp->v_usecount); 27451852Sbp vgone(vp); 27551852Sbp NCPVODEBUG("v_gone finished !!!!\n"); 27651852Sbp conn = NWFSTOCONN(nmp); 27751852Sbp ncp_conn_puthandle(nmp->connh,NULL,0); 27851852Sbp if (ncp_conn_lock(conn,p,p->p_ucred,NCPM_WRITE | NCPM_EXECUTE) == 0) { 27951852Sbp if(ncp_disconnect(conn)) 28051852Sbp ncp_conn_unlock(conn,p); 28151852Sbp } 28251852Sbp mp->mnt_data = (qaddr_t)0; 28351852Sbp if (nmp->m.flags & NWFS_MOUNT_HAVE_NLS) 28452814Sarchie free(nmp->m.nls.to_lower, M_NWFSDATA); 28551852Sbp free(nmp, M_NWFSDATA); 28651852Sbp mp->mnt_flag &= ~MNT_LOCAL; 28751852Sbp return (error); 28851852Sbp} 28951852Sbp 29051852Sbp/* Return locked vnode to root of a filesystem */ 29151852Sbpstatic int 29251852Sbpnwfs_root(struct mount *mp, struct vnode **vpp) { 29351852Sbp struct vnode *vp; 29451852Sbp struct nwmount *nmp; 29551852Sbp struct nwnode *np; 29651852Sbp struct ncp_conn *conn; 29751852Sbp struct nw_entry_info fattr; 29851852Sbp struct proc *p = curproc; 29951852Sbp struct ucred *cred = p->p_ucred; 30051852Sbp int error, nsf, opt; 30151852Sbp u_char vol; 30251852Sbp 30351852Sbp nmp = VFSTONWFS(mp); 30451852Sbp conn = NWFSTOCONN(nmp); 30551852Sbp if (nmp->n_root) { 30651852Sbp *vpp = NWTOV(nmp->n_root); 30751852Sbp vget(*vpp, LK_EXCLUSIVE, curproc); 30851852Sbp return 0; 30951852Sbp } 31051852Sbp error = ncp_lookup_volume(conn, nmp->m.mounted_vol, &vol, 31151852Sbp &nmp->n_rootent.f_id, p, cred); 31251852Sbp if (error) 31351852Sbp return ENOENT; 31451852Sbp nmp->n_volume = vol; 31551852Sbp error = ncp_get_namespaces(conn, vol, &nsf, p, cred); 31651852Sbp if (error) 31751852Sbp return ENOENT; 31851852Sbp if (nsf & NW_NSB_OS2) { 31951852Sbp NCPVODEBUG("volume %s has os2 namespace\n",nmp->m.mounted_vol); 32051852Sbp if ((nmp->m.flags & NWFS_MOUNT_NO_OS2) == 0) { 32151852Sbp nmp->name_space = NW_NS_OS2; 32251852Sbp nmp->m.nls.opt &= ~NWHP_DOS; 32351852Sbp } 32451852Sbp } 32551852Sbp opt = nmp->m.nls.opt; 32651852Sbp nsf = opt & (NWHP_UPPER | NWHP_LOWER); 32751852Sbp if (opt & NWHP_DOS) { 32851852Sbp if (nsf == (NWHP_UPPER | NWHP_LOWER)) { 32951852Sbp nmp->m.nls.opt &= ~(NWHP_LOWER | NWHP_UPPER); 33051852Sbp } else if (nsf == 0) { 33151852Sbp nmp->m.nls.opt |= NWHP_LOWER; 33251852Sbp } 33351852Sbp } else { 33451852Sbp if (nsf == (NWHP_UPPER | NWHP_LOWER)) { 33551852Sbp nmp->m.nls.opt &= ~(NWHP_LOWER | NWHP_UPPER); 33651852Sbp } 33751852Sbp } 33851852Sbp if (nmp->m.root_path[0]) { 33951852Sbp nmp->m.root_path[0]--; 34051852Sbp error = ncp_obtain_info(nmp, nmp->n_rootent.f_id, 34151852Sbp -nmp->m.root_path[0], nmp->m.root_path, &fattr, p, cred); 34251852Sbp if (error) { 34351852Sbp NCPFATAL("Invalid root path specified\n"); 34451852Sbp return ENOENT; 34551852Sbp } 34651852Sbp nmp->n_rootent.f_parent = fattr.dirEntNum; 34751852Sbp nmp->m.root_path[0]++; 34851852Sbp error = ncp_obtain_info(nmp, nmp->n_rootent.f_id, 34951852Sbp -nmp->m.root_path[0], nmp->m.root_path, &fattr, p, cred); 35051852Sbp if (error) { 35151852Sbp NCPFATAL("Invalid root path specified\n"); 35251852Sbp return ENOENT; 35351852Sbp } 35451852Sbp nmp->n_rootent.f_id = fattr.dirEntNum; 35551852Sbp } else { 35651852Sbp error = ncp_obtain_info(nmp, nmp->n_rootent.f_id, 35751852Sbp 0, NULL, &fattr, p, cred); 35851852Sbp if (error) { 35951852Sbp NCPFATAL("Can't obtain volume info\n"); 36051852Sbp return ENOENT; 36151852Sbp } 36251852Sbp fattr.nameLen = strlen(strcpy(fattr.entryName, NWFS_ROOTVOL)); 36351852Sbp nmp->n_rootent.f_parent = nmp->n_rootent.f_id; 36451852Sbp } 36551852Sbp error = nwfs_nget(mp, nmp->n_rootent, &fattr, NULL, &vp); 36651852Sbp if (error) 36751852Sbp return (error); 36851852Sbp vp->v_flag |= VROOT; 36951852Sbp np = VTONW(vp); 37051852Sbp if (nmp->m.root_path[0] == 0) 37151852Sbp np->n_flag |= NVOLUME; 37251852Sbp nmp->n_root = np; 37351852Sbp/* error = VOP_GETATTR(vp, &vattr, cred, p); 37451852Sbp if (error) { 37551852Sbp vput(vp); 37651852Sbp NCPFATAL("Can't get root directory entry\n"); 37751852Sbp return error; 37851852Sbp }*/ 37951852Sbp *vpp = vp; 38051852Sbp return (0); 38151852Sbp} 38251852Sbp 38351852Sbp/* 38451852Sbp * Vfs start routine, a no-op. 38551852Sbp */ 38651852Sbp/* ARGSUSED */ 38751852Sbpstatic int 38851852Sbpnwfs_start(mp, flags, p) 38951852Sbp struct mount *mp; 39051852Sbp int flags; 39151852Sbp struct proc *p; 39251852Sbp{ 39351852Sbp NCPVODEBUG("flags=%04x\n",flags); 39451852Sbp return (0); 39551852Sbp} 39651852Sbp 39751852Sbp/* 39851852Sbp * Do operations associated with quotas, not supported 39951852Sbp */ 40051852Sbp/* ARGSUSED */ 40151852Sbpstatic int 40251852Sbpnwfs_quotactl(mp, cmd, uid, arg, p) 40351852Sbp struct mount *mp; 40451852Sbp int cmd; 40551852Sbp uid_t uid; 40651852Sbp caddr_t arg; 40751852Sbp struct proc *p; 40851852Sbp{ 40951852Sbp NCPVODEBUG("return EOPNOTSUPP\n"); 41051852Sbp return (EOPNOTSUPP); 41151852Sbp} 41251852Sbp 41351852Sbp/*ARGSUSED*/ 41451852Sbpint 41551852Sbpnwfs_init(struct vfsconf *vfsp) 41651852Sbp{ 41756034Sbp#ifndef SMP 41856034Sbp int name[2]; 41956034Sbp int olen, ncpu, plen, error; 42051852Sbp 42156034Sbp name[0] = CTL_HW; 42256034Sbp name[1] = HW_NCPU; 42356034Sbp error = kernel_sysctl(curproc, name, 2, &ncpu, &olen, NULL, 0, &plen); 42456034Sbp if (error == 0 && ncpu > 1) 42556034Sbp printf("warning: nwfs module compiled without SMP support."); 42656034Sbp#endif 42751852Sbp nwfs_hash_init(); 42851852Sbp nwfs_pbuf_freecnt = nswbuf / 2 + 1; 42951852Sbp NCPVODEBUG("always happy to load!\n"); 43051852Sbp return (0); 43151852Sbp} 43251852Sbp 43351852Sbp/*ARGSUSED*/ 43451852Sbpint 43551852Sbpnwfs_uninit(struct vfsconf *vfsp) 43651852Sbp{ 43751852Sbp 43851852Sbp nwfs_hash_free(); 43951852Sbp NCPVODEBUG("unloaded\n"); 44051852Sbp return (0); 44151852Sbp} 44251852Sbp 44351852Sbp/* 44451852Sbp * nwfs_statfs call 44551852Sbp */ 44651852Sbpint 44751852Sbpnwfs_statfs(mp, sbp, p) 44851852Sbp struct mount *mp; 44951852Sbp register struct statfs *sbp; 45051852Sbp struct proc *p; 45151852Sbp{ 45251852Sbp struct nwmount *nmp = VFSTONWFS(mp); 45351852Sbp int error = 0, secsize; 45451852Sbp struct nwnode *np = nmp->n_root; 45551852Sbp struct ncp_volume_info vi; 45651852Sbp 45751852Sbp if (np == NULL) return EINVAL; 45851852Sbp error = ncp_get_volume_info_with_number(NWFSTOCONN(nmp), nmp->n_volume, &vi,p,p->p_ucred); 45951852Sbp if (error) return error; 46051852Sbp secsize = 512; /* XXX how to get real value ??? */ 46151852Sbp sbp->f_spare2=0; /* placeholder */ 46251852Sbp /* fundamental file system block size */ 46351852Sbp sbp->f_bsize = vi.sectors_per_block*secsize; 46451852Sbp /* optimal transfer block size */ 46551852Sbp sbp->f_iosize = NWFSTOCONN(nmp)->buffer_size; 46651852Sbp /* total data blocks in file system */ 46751852Sbp sbp->f_blocks= vi.total_blocks; 46851852Sbp /* free blocks in fs */ 46951852Sbp sbp->f_bfree = vi.free_blocks + vi.purgeable_blocks; 47051852Sbp /* free blocks avail to non-superuser */ 47151852Sbp sbp->f_bavail= vi.free_blocks+vi.purgeable_blocks; 47251852Sbp /* total file nodes in file system */ 47351852Sbp sbp->f_files = vi.total_dir_entries; 47451852Sbp /* free file nodes in fs */ 47551852Sbp sbp->f_ffree = vi.available_dir_entries; 47651852Sbp sbp->f_flags = 0; /* copy of mount exported flags */ 47751852Sbp if (sbp != &mp->mnt_stat) { 47851852Sbp sbp->f_fsid = mp->mnt_stat.f_fsid; /* file system id */ 47951852Sbp sbp->f_owner = mp->mnt_stat.f_owner; /* user that mounted the filesystem */ 48051852Sbp sbp->f_type = mp->mnt_vfc->vfc_typenum; /* type of filesystem */ 48151852Sbp bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); 48251852Sbp bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); 48351852Sbp } 48451852Sbp strncpy(sbp->f_fstypename, mp->mnt_vfc->vfc_name, MFSNAMELEN); 48551852Sbp return 0; 48651852Sbp} 48751852Sbp 48851852Sbp/* 48951852Sbp * Flush out the buffer cache 49051852Sbp */ 49151852Sbp/* ARGSUSED */ 49251852Sbpstatic int 49351852Sbpnwfs_sync(mp, waitfor, cred, p) 49451852Sbp struct mount *mp; 49551852Sbp int waitfor; 49651852Sbp struct ucred *cred; 49751852Sbp struct proc *p; 49851852Sbp{ 49951852Sbp register struct vnode *vp; 50051852Sbp int error, allerror = 0; 50151852Sbp /* 50251852Sbp * Force stale buffer cache information to be flushed. 50351852Sbp */ 50451852Sbploop: 50551852Sbp for (vp = mp->mnt_vnodelist.lh_first; 50651852Sbp vp != NULL; 50751852Sbp vp = vp->v_mntvnodes.le_next) { 50851852Sbp /* 50951852Sbp * If the vnode that we are about to sync is no longer 51051852Sbp * associated with this mount point, start over. 51151852Sbp */ 51251852Sbp if (vp->v_mount != mp) 51351852Sbp goto loop; 51454444Seivind if (VOP_ISLOCKED(vp, NULL) || TAILQ_EMPTY(&vp->v_dirtyblkhd) || 51551852Sbp waitfor == MNT_LAZY) 51651852Sbp continue; 51751852Sbp if (vget(vp, LK_EXCLUSIVE, p)) 51851852Sbp goto loop; 51951852Sbp error = VOP_FSYNC(vp, cred, waitfor, p); 52051852Sbp if (error) 52151852Sbp allerror = error; 52251852Sbp vput(vp); 52351852Sbp } 52451852Sbp return (allerror); 52551852Sbp} 526