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