Standardize License information
[openafs.git] / src / afs / HPUX / 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 /*
11  * osi_vfsops.c for HPUX
12  */
13 #include "../afs/param.h"       /* Should be always first */
14 #include "../afs/sysincludes.h" /* Standard vendor system headers */
15 #include "../afs/afsincludes.h" /* Afs-based standard headers */
16 #include "../afs/afs_stats.h"   /* statistics stuff */
17 #include <sys/scall_kernprivate.h>
18
19
20 static char afs_mountpath[512];
21 struct vfs *afs_globalVFS = 0;
22 struct vcache *afs_globalVp = 0;
23
24 int afs_mount(struct vfs *afsp, char *path, smountargs_t *data)
25 {
26     AFS_GLOCK();
27     AFS_STATCNT(afs_mount);
28
29     if (afs_globalVFS) { /* Don't allow remounts. */
30         AFS_GUNLOCK();
31         return (setuerror(EBUSY));
32     }
33
34     afs_globalVFS = afsp;
35     afsp->vfs_bsize = 8192;
36     afsp->vfs_fsid[0] = AFS_VFSMAGIC; /* magic */
37     afsp->vfs_fsid[1] = AFS_VFSFSID; 
38     strcpy(afsp->vfs_name, "AFS");
39     afsp->vfs_name[3] = '\0';
40
41     strncpy(afs_mountpath, path, sizeof(afs_mountpath));
42     afs_mountpath[sizeof afs_mountpath - 1] = '\0';
43
44 #ifndef AFS_NONFSTRANS
45     /* Set up the xlator in case it wasn't done elsewhere */
46     afs_xlatorinit_v2(); 
47 #endif
48
49     AFS_GUNLOCK();
50     return 0;
51 }
52
53
54 int afs_unmount(struct vfs *afsp)
55 {
56     AFS_GLOCK();
57     AFS_STATCNT(afs_unmount);
58
59     afs_globalVFS = 0;
60     afs_shutdown();
61
62     AFS_GUNLOCK();
63     return 0;
64 }       
65
66 int afs_root (struct vfs *afsp, struct vnode **avpp, char *unused1)
67 {
68     int code = 0;
69     struct vrequest treq;
70     register struct vcache *tvp=0;
71     AFS_GLOCK();
72     AFS_STATCNT(afs_root);
73
74     if (afs_globalVp && (afs_globalVp->states & CStatd)) {
75         tvp = afs_globalVp;
76     } else {
77         if (!(code = afs_InitReq(&treq,  p_cred(u.u_procp))) &&
78             !(code = afs_CheckInit())) {
79             tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0,
80                                 (struct vcache*)0, WRITE_LOCK);
81             /* we really want this to stay around */
82             if (tvp) {
83                 afs_globalVp = tvp;
84             } else
85                 code = ENOENT;
86         }
87     }
88     if (tvp) {
89         VN_HOLD((struct vnode *)tvp);
90         SET_V_FLAG( ((struct vnode *)tvp), VROOT);
91
92         afs_globalVFS = afsp;
93         *avpp = (struct vnode *) tvp;
94     }
95
96     afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *avpp,
97                ICL_TYPE_INT32, code);
98
99     AFS_GUNLOCK();
100     return code;
101 }       
102
103 int afs_statfs(register struct vfs *afsp, struct k_statvfs *abp)
104 {
105     AFS_GLOCK();
106     AFS_STATCNT(afs_statfs);
107
108     abp->f_type = 0;
109     abp->f_frsize = 1024;
110     abp->f_bsize = afsp->vfs_bsize;
111     /* Fake a high number below to satisfy programs that use the statfs
112      * call to make sure that there's enough space in the device partition
113      * before storing something there.
114      */
115     abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
116         abp->f_ffree = abp->f_favail = 9000000;
117     abp->f_fsid = (AFS_VFSMAGIC << 16) || AFS_VFSFSID;
118
119     AFS_GUNLOCK();
120     return 0;
121 }       
122
123 int afs_sync(struct vfs *unused1, int unused2)
124 {
125     AFS_STATCNT(afs_sync);
126     return 0;
127 }
128
129 int afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp)
130 {
131     int code;
132     struct vrequest treq;
133     AFS_GLOCK();
134     AFS_STATCNT(afs_vget);
135
136     * avcp = NULL;
137
138     if ((code = afs_InitReq(&treq, p_cred(u.u_procp)))==0) {
139         code = afs_osi_vget((struct vcache**)avcp, fidp, &treq);
140     }
141
142     afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp,
143                ICL_TYPE_INT32, treq.uid, ICL_TYPE_FID, fidp);
144     code = afs_CheckCode(code, &treq, 42);
145
146     AFS_GUNLOCK();
147     return code;
148 }       
149
150 int afs_getmount(struct vfs *vfsp, char *fsmntdir, struct mount_data *mdp, char *unused1)
151 {
152     int l;
153
154     mdp->md_msite = 0;
155     mdp->md_dev = 0;
156     mdp->md_rdev = 0;
157     return(copyoutstr(afs_mountpath, fsmntdir, strlen(afs_mountpath)+1, &l));
158 }
159
160
161 struct vfsops Afs_vfsops = {
162     afs_mount,
163     afs_unmount,
164     afs_root,
165     afs_statfs,
166     afs_sync,
167     afs_vget,
168     afs_getmount,
169     (vfs_freeze_t *)0,  /* vfs_freeze */
170     (vfs_thaw_t *)0,    /* vfs_thaw */
171     (vfs_quota_t *)0,   /* vfs_quota */
172     (vfs_mountroot_t *)0,               /* vfs_mountroot. Note: afs_mountroot_nullop in this
173                          *                position panicked HP 11.00+
174                          */
175     (vfs_size_t *)0     /* vfs_size */
176 };
177
178 static int afs_Starting = 0;
179
180 #pragma align 64
181 sema_t afs_global_sema = {
182    NULL, 0, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, /* sa_type */
183    0, 0, 0, 0, 0, 0, 0, NULL, /* sa_link */
184    NULL, NULL
185 #ifdef SEMA_COUNTING
186    , 0, 0, 0, NULL
187 #endif
188   };
189
190 void
191 osi_InitGlock()
192 {
193     register ulong_t context;
194
195     SPINLOCK_USAV(sched_lock, context);
196     if ( !afs_Starting ) {
197         afs_Starting = 1;
198         SPINUNLOCK_USAV(sched_lock, context);
199         initsema(&afs_global_sema, 1, FILESYS_SEMA_PRI, FILESYS_SEMA_ORDER);
200         afsHash(64);    /* 64 buckets */
201     } else {
202         SPINUNLOCK_USAV(sched_lock, context);
203     }
204     if (!afs_Starting) {
205         osi_Panic("osi_Init lost initialization race");
206     }
207 }
208
209 /*
210  * afsc_link - Initialize VFS
211  */
212 int afs_vfs_slot=-1; 
213
214
215 afsc_link()
216 {
217     extern int Afs_syscall(), afs_xioctl(), Afs_xsetgroups();
218
219     /* For now nothing special is required during AFS initialization. */
220     AFS_STATCNT(afsc_link);
221     osi_Init();         
222     if ( (afs_vfs_slot=add_vfs_type("afs", &Afs_vfsops)) < 0 )
223         return;
224     sysent_assign_function(AFS_SYSCALL, 7, (void (*)())Afs_syscall, "Afs_syscall");
225     sysent_define_arg(AFS_SYSCALL, 0, longArg);
226     sysent_define_arg(AFS_SYSCALL, 1, longArg);
227     sysent_define_arg(AFS_SYSCALL, 2, longArg);
228     sysent_define_arg(AFS_SYSCALL, 3, longArg);
229     sysent_define_arg(AFS_SYSCALL, 4, longArg);
230     sysent_define_arg(AFS_SYSCALL, 5, longArg);
231     sysent_define_arg(AFS_SYSCALL, 6, longArg);
232     sysent_returns_long(AFS_SYSCALL);
233
234     sysent_delete(80);
235     sysent_assign_function(80, 2, (void (*)())Afs_xsetgroups, "setgroups");
236     sysent_define_arg(80, 0, longArg);
237     sysent_define_arg(80, 1, longArg);
238     sysent_returns_long(80);
239     return 0;
240 }
241