UKERNEL: add uafs_statvfs
[openafs.git] / src / afs / UKERNEL / osi_vfsops.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include "afs/param.h"
12
13
14 #include "afs/sysincludes.h"    /* Standard vendor system headers */
15 #include "afsincludes.h"        /* Afs-based standard headers */
16 #include "afs/afs_stats.h"      /* statistics stuff */
17
18 int afs_statfs(register struct vfs *afsp, struct statfs *abp);
19 int afs_sync(struct vfs *afsp);
20
21
22 struct vfsops Afs_vfsops = {
23     afs_mount,
24     afs_unmount,
25     afs_root,
26     afs_statfs,
27     afs_sync,
28 };
29
30 struct vfs *afs_globalVFS = 0;
31 struct vcache *afs_globalVp = 0;
32 int afs_rootCellIndex = 0;
33
34 #if !defined(AFS_USR_AIX_ENV)
35 #include "sys/syscall.h"
36 #endif
37
38 int
39 afs_mount(struct vfs *afsp, char *path, void *data)
40 {
41     AFS_STATCNT(afs_mount);
42
43     if (afs_globalVFS) {
44         /* Don't allow remounts since some system (like AIX) don't handle it well */
45         return (setuerror(EBUSY));
46     }
47     afs_globalVFS = afsp;
48     afsp->vfs_bsize = 8192;
49     afsp->vfs_fsid.val[0] = AFS_VFSMAGIC;       /* magic */
50     afsp->vfs_fsid.val[1] = (intptr_t)AFS_VFSFSID;
51
52     return 0;
53 }
54
55 int
56 afs_unmount(struct vfs *afsp)
57 {
58     AFS_STATCNT(afs_unmount);
59     afs_globalVFS = 0;
60     afs_shutdown();
61     return 0;
62 }
63
64 int
65 afs_root(OSI_VFS_DECL(afsp), struct vnode **avpp)
66 {
67     register afs_int32 code = 0;
68     struct vrequest treq;
69     register struct vcache *tvp = 0;
70     OSI_VFS_CONVERT(afsp);
71
72     AFS_STATCNT(afs_root);
73     if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
74         tvp = afs_globalVp;
75     } else {
76         if (afs_globalVp) {
77             afs_PutVCache(afs_globalVp);
78             afs_globalVp = NULL;
79         }
80
81         if (!(code = afs_InitReq(&treq, get_user_struct()->u_cred))
82             && !(code = afs_CheckInit())) {
83             tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
84             /* we really want this to stay around */
85             if (tvp) {
86                 afs_globalVp = tvp;
87             } else
88                 code = ENOENT;
89         }
90     }
91     if (tvp) {
92         VN_HOLD(AFSTOV(tvp));
93
94         AFSTOV(tvp)->v_flag |= VROOT;   /* No-op on Ultrix 2.2 */
95         afs_globalVFS = afsp;
96         *avpp = AFSTOV(tvp);
97     }
98
99     afs_Trace3(afs_iclSetp, CM_TRACE_GOPEN, ICL_TYPE_POINTER, *avpp,
100                ICL_TYPE_INT32, 0, ICL_TYPE_INT32, code);
101     return code;
102 }
103
104 int
105 afs_sync(struct vfs *afsp)
106 {
107     AFS_STATCNT(afs_sync);
108     return 0;
109 }
110
111 int
112 afs_statfs(register struct vfs *afsp, struct statfs *abp)
113 {
114     AFS_STATCNT(afs_statfs);
115     abp->f_type = 0;
116     abp->f_bsize = afsp->vfs_bsize;
117     abp->f_fsid.val[0] = AFS_VFSMAGIC;  /* magic */
118     abp->f_fsid.val[1] = (intptr_t)AFS_VFSFSID;
119     return 0;
120 }
121
122 int
123 afs_statvfs(struct vfs *afsp, struct statvfs *abp)
124 {
125     AFS_STATCNT(afs_statfs);
126
127     abp->f_frsize = 1024;
128     abp->f_favail = 9000000;
129     abp->f_bsize = afsp->vfs_bsize;
130     abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
131       abp->f_ffree = 9000000;
132     abp->f_fsid = (AFS_VFSMAGIC << 16) || AFS_VFSFSID;
133
134     return 0;
135 }
136
137 int
138 afs_mountroot(void)
139 {
140     AFS_STATCNT(afs_mountroot);
141     return (EINVAL);
142 }
143
144 int
145 afs_swapvp(void)
146 {
147     AFS_STATCNT(afs_swapvp);
148     return (EINVAL);
149 }