1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
|
/* $OpenBSD: xfs_vfsops.c,v 1.3 1998/09/06 01:48:58 art Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998 Kungliga Tekniska H�gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Kungliga Tekniska
* H�gskolan and its contributors.
*
* 4. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/uio.h>
#include <sys/mount.h>
#include <sys/systm.h>
#include <sys/namei.h>
#include <sys/conf.h>
#include <sys/proc.h>
#include <sys/vnode.h>
#include <xfs/xfs_common.h>
#include <xfs/xfs_message.h>
#include <xfs/xfs_dev.h>
#include <xfs/xfs_fs.h>
#include <xfs/xfs_deb.h>
RCSID("$KTH: xfs_vfsops.c,v 1.22 1998/08/13 01:38:49 art Exp $");
/*
* XFS vfs operations.
*/
static struct vnode *make_dead_vnode(struct mount *mp);
struct xfs xfs[NXFS];
static int
xfs_mount(struct mount *mp,
const char *user_path,
caddr_t user_data,
struct nameidata *ndp,
struct proc *p)
{
struct vnode *devvp;
dev_t dev;
int error;
struct vattr vat;
char path[MAXPATHLEN];
char data[MAXPATHLEN];
size_t len;
error = copyinstr(user_path, path, MAXPATHLEN, &len);
if (error)
return error;
error = copyinstr(user_data, data, MAXPATHLEN, &len);
if (error)
return error;
XFSDEB(XDEBVFOPS, ("xfs_mount: "
"struct mount mp = %p path = %s data = '%s'\n",
mp, path, data));
NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF,
UIO_SYSSPACE, data, p);
error = namei(ndp);
if (error)
return error;
devvp = ndp->ni_vp;
if (devvp->v_type != VCHR) {
vput(devvp);
return ENXIO;
}
error = VOP_GETATTR(devvp, &vat, p->p_ucred, p);
if (error) {
vput(devvp);
return error;
}
dev = vat.va_rdev;
vput(devvp);
/* Check that this device really is an xfs_dev */
if (major(dev) < 0 || nchrdev < major(dev))
return ENXIO;
if (minor(dev) < 0 || NXFS < minor(dev))
return ENXIO;
#if defined(__NetBSD__) || defined(__OpenBSD__)
if (cdevsw[major(dev)].d_open != xfs_devopen)
return ENXIO;
#elif defined(__FreeBSD__)
if (cdevsw[major(dev)] == NULL
|| cdevsw[major(dev)]->d_open != xfs_devopen)
return ENXIO;
#endif
if (xfs[minor(dev)].status & XFS_MOUNTED)
return EBUSY;
xfs[minor(dev)].status = XFS_MOUNTED;
xfs[minor(dev)].mp = mp;
xfs[minor(dev)].root = 0;
xfs[minor(dev)].nnodes = 0;
xfs[minor(dev)].fd = minor(dev);
VFS_TO_XFS(mp) = &xfs[minor(dev)];
vfs_getnewfsid(mp);
mp->mnt_stat.f_bsize = DEV_BSIZE;
mp->mnt_stat.f_iosize = DEV_BSIZE;
mp->mnt_stat.f_blocks = 4711 * 4711;
mp->mnt_stat.f_bfree = 4711 * 4711;
mp->mnt_stat.f_bavail = 4711 * 4711;
mp->mnt_stat.f_files = 4711;
mp->mnt_stat.f_ffree = 4711;
mp->mnt_stat.f_owner = 0;
mp->mnt_stat.f_flags = mp->mnt_flag;
strncpy(mp->mnt_stat.f_mntonname, path,
sizeof(mp->mnt_stat.f_mntonname));
/* XXX - It shouldn't be arla, but that will be solved later */
strncpy(mp->mnt_stat.f_mntfromname, "arla",
sizeof(mp->mnt_stat.f_mntfromname));
strncpy(mp->mnt_stat.f_fstypename, "xfs",
sizeof(mp->mnt_stat.f_fstypename));
return 0;
}
static int
xfs_start(struct mount *mp, int flags, struct proc *p)
{
XFSDEB(XDEBVFOPS, ("xfs_start mp = 0x%x\n", (u_int) mp));
return 0;
}
static int
xfs_unmount(struct mount *mp, int mntflags, struct proc *p)
{
struct xfs *xfsp = VFS_TO_XFS(mp);
extern int doforce;
int flags = 0;
int error;
XFSDEB(XDEBVFOPS, ("xfs_unmount mp = 0x%x\n", (u_int) mp));
if (mntflags & MNT_FORCE) {
if (!doforce)
return EINVAL;
flags |= FORCECLOSE;
}
error = free_all_xfs_nodes(xfsp, flags);
if (error)
return error;
xfsp->status = 0;
return 0;
}
static int
xfs_root(struct mount *mp, struct vnode **vpp)
{
struct xfs *xfsp = VFS_TO_XFS(mp);
struct xfs_message_getroot msg;
int error;
XFSDEB(XDEBVFOPS, ("xfs_root mp = 0x%x\n", (u_int) mp));
do {
if (xfsp->root != NULL) {
*vpp = XNODE_TO_VNODE(xfsp->root);
VREF(*vpp);
return 0;
}
msg.header.opcode = XFS_MSG_GETROOT;
msg.cred.uid = curproc->p_ucred->cr_uid;
msg.cred.pag = 0; /* XXX */
error = xfs_message_rpc(xfsp->fd, &msg.header, sizeof(msg));
if (error == 0)
error = ((struct xfs_message_wakeup *) & msg)->error;
} while (error == 0);
/*
* Failed to get message through, need to pretend that all went well
* and return a fake dead vnode to be able to unmount.
*/
*vpp = make_dead_vnode(mp);
(*vpp)->v_flag |= VROOT;
return 0;
}
static int
xfs_quotactl(struct mount *mp, int cmd, uid_t uid, caddr_t arg, struct proc *p)
{
XFSDEB(XDEBVFOPS, ("xfs_quotactl\n"));
return (EOPNOTSUPP);
}
static int
xfs_statfs(struct mount *mp, struct statfs *sbp, struct proc *p)
{
XFSDEB(XDEBVFOPS, ("xfs_statfs\n"));
bcopy(&mp->mnt_stat, sbp, sizeof(*sbp));
return 0;
}
static int
xfs_sync(struct mount *mp, int waitfor, struct ucred *cred, struct proc *p)
{
XFSDEB(XDEBVFOPS, ("xfs_sync\n"));
return 0;
}
/*
* This could be implemented by searching if ino_t was bigger.
*/
static int
xfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
{
XFSDEB(XDEBVFOPS, ("xfs_vget\n"));
return EOPNOTSUPP;
}
static int
xfs_fhtovp(struct mount *mp, struct fid *fhp, struct mbuf *nam,
struct vnode **vpp, int *exflagsp, struct ucred **credanonp)
{
XFSDEB(XDEBVFOPS, ("xfs_fhtovp\n"));
return EOPNOTSUPP;
}
static int
xfs_vptofh(struct vnode *vp, struct fid *fhp)
{
XFSDEB(XDEBVFOPS, ("xfs_vptofh\n"));
return EOPNOTSUPP;
}
/* sysctl()able variables :-) */
static int
xfs_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen, struct proc *p)
{
/* Supposed to be terminal... */
if (namelen != 1)
return (ENOTDIR);
return (EOPNOTSUPP);
}
static int
xfs_init(struct vfsconf *vfsp)
{
XFSDEB(XDEBVFOPS, ("xfs_init\n"));
return (0);
}
struct vfsops xfs_vfsops = {
xfs_mount,
xfs_start,
xfs_unmount,
xfs_root,
xfs_quotactl,
xfs_statfs,
xfs_sync,
xfs_vget,
xfs_fhtovp,
xfs_vptofh,
xfs_init,
xfs_sysctl
};
/*
*
*/
static int
xfs_uprintf_filsys(void)
{
return 0;
}
/*
* Install and uninstall filesystem.
*/
extern struct vnodeopv_desc xfs_vnodeop_opv_desc;
int
xfs_install_filesys(void)
{
struct vfsconf *vfsp;
struct vfsconf **vfspp;
/* Check if filesystem already known */
for (vfspp = &vfsconf, vfsp = vfsconf;
vfsp;
vfspp = &vfsp->vfc_next, vfsp = vfsp->vfc_next)
if (strncmp(vfsp->vfc_name,
"xfs", MFSNAMELEN) == 0)
return (EEXIST);
/* Allocate and initialize */
MALLOC(vfsp, struct vfsconf *, sizeof(struct vfsconf),
M_VFS, M_WAITOK);
vfsp->vfc_vfsops = &xfs_vfsops;
strncpy(vfsp->vfc_name, "xfs", MFSNAMELEN);
vfsp->vfc_typenum = 0;
vfsp->vfc_refcount = 0;
vfsp->vfc_flags = 0;
vfsp->vfc_mountroot = 0;
vfsp->vfc_next = NULL;
maxvfsconf++;
/* Add to the end of the list */
*vfspp = vfsp;
/* Call vfs_init() */
printf("Calling vfs_init()\n");
(*(vfsp->vfc_vfsops->vfs_init)) (vfsp);
/* done! */
return 0;
}
int
xfs_uninstall_filesys(void)
{
struct vfsconf *vfsp;
struct vfsconf **vfspp;
/* Find our vfsconf struct */
for (vfspp = &vfsconf, vfsp = vfsconf;
vfsp;
vfspp = &vfsp->vfc_next, vfsp = vfsp->vfc_next)
if (strncmp(vfsp->vfc_name,
"xfs",
MFSNAMELEN) == 0)
break;
if (!vfsp) /* Not found */
return (EEXIST);
if (vfsp->vfc_refcount) /* In use */
return (EBUSY);
/* Remove from list and free */
*vfspp = vfsp->vfc_next;
FREE(vfsp, M_VFS);
maxvfsconf--;
return 0;
}
int
xfs_stat_filesys(void)
{
return xfs_uprintf_filsys();
}
/*
* To be able to unmount when the XFS daemon is not
* responding we need a root vnode, use a dead vnode!
*/
extern int (**dead_vnodeop_p) (void *);
static struct vnode *
make_dead_vnode(struct mount *mp)
{
struct vnode *dead;
int error;
XFSDEB(XDEBNODE, ("make_dead_vnode mp = 0x%x\n", (u_int) mp));
if ((error = getnewvnode(VT_NON, mp, dead_vnodeop_p, &dead)))
panic("make_dead_vnode: getnewvnode failed: error = %d\n",
error);
return dead;
}
|