lfs_vfsops.c revision 1.1 1 1.1 mycroft /*
2 1.1 mycroft * Copyright (c) 1989, 1991, 1993, 1994
3 1.1 mycroft * The Regents of the University of California. All rights reserved.
4 1.1 mycroft *
5 1.1 mycroft * Redistribution and use in source and binary forms, with or without
6 1.1 mycroft * modification, are permitted provided that the following conditions
7 1.1 mycroft * are met:
8 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
9 1.1 mycroft * notice, this list of conditions and the following disclaimer.
10 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
12 1.1 mycroft * documentation and/or other materials provided with the distribution.
13 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
14 1.1 mycroft * must display the following acknowledgement:
15 1.1 mycroft * This product includes software developed by the University of
16 1.1 mycroft * California, Berkeley and its contributors.
17 1.1 mycroft * 4. Neither the name of the University nor the names of its contributors
18 1.1 mycroft * may be used to endorse or promote products derived from this software
19 1.1 mycroft * without specific prior written permission.
20 1.1 mycroft *
21 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 mycroft * SUCH DAMAGE.
32 1.1 mycroft *
33 1.1 mycroft * from: @(#)lfs_vfsops.c 8.7 (Berkeley) 4/16/94
34 1.1 mycroft * $Id: lfs_vfsops.c,v 1.1 1994/06/08 11:42:48 mycroft Exp $
35 1.1 mycroft */
36 1.1 mycroft
37 1.1 mycroft #include <sys/param.h>
38 1.1 mycroft #include <sys/systm.h>
39 1.1 mycroft #include <sys/namei.h>
40 1.1 mycroft #include <sys/proc.h>
41 1.1 mycroft #include <sys/kernel.h>
42 1.1 mycroft #include <sys/vnode.h>
43 1.1 mycroft #include <sys/mount.h>
44 1.1 mycroft #include <sys/buf.h>
45 1.1 mycroft #include <sys/mbuf.h>
46 1.1 mycroft #include <sys/file.h>
47 1.1 mycroft #include <sys/disklabel.h>
48 1.1 mycroft #include <sys/ioctl.h>
49 1.1 mycroft #include <sys/errno.h>
50 1.1 mycroft #include <sys/malloc.h>
51 1.1 mycroft #include <sys/socket.h>
52 1.1 mycroft
53 1.1 mycroft #include <miscfs/specfs/specdev.h>
54 1.1 mycroft
55 1.1 mycroft #include <ufs/ufs/quota.h>
56 1.1 mycroft #include <ufs/ufs/inode.h>
57 1.1 mycroft #include <ufs/ufs/ufsmount.h>
58 1.1 mycroft #include <ufs/ufs/ufs_extern.h>
59 1.1 mycroft
60 1.1 mycroft #include <ufs/lfs/lfs.h>
61 1.1 mycroft #include <ufs/lfs/lfs_extern.h>
62 1.1 mycroft
63 1.1 mycroft int lfs_mountfs __P((struct vnode *, struct mount *, struct proc *));
64 1.1 mycroft
65 1.1 mycroft struct vfsops lfs_vfsops = {
66 1.1 mycroft MOUNT_LFS,
67 1.1 mycroft lfs_mount,
68 1.1 mycroft ufs_start,
69 1.1 mycroft lfs_unmount,
70 1.1 mycroft ufs_root,
71 1.1 mycroft ufs_quotactl,
72 1.1 mycroft lfs_statfs,
73 1.1 mycroft lfs_sync,
74 1.1 mycroft lfs_vget,
75 1.1 mycroft lfs_fhtovp,
76 1.1 mycroft lfs_vptofh,
77 1.1 mycroft lfs_init,
78 1.1 mycroft };
79 1.1 mycroft
80 1.1 mycroft int
81 1.1 mycroft lfs_mountroot()
82 1.1 mycroft {
83 1.1 mycroft panic("lfs_mountroot"); /* XXX -- implement */
84 1.1 mycroft }
85 1.1 mycroft
86 1.1 mycroft /*
87 1.1 mycroft * VFS Operations.
88 1.1 mycroft *
89 1.1 mycroft * mount system call
90 1.1 mycroft */
91 1.1 mycroft lfs_mount(mp, path, data, ndp, p)
92 1.1 mycroft register struct mount *mp;
93 1.1 mycroft char *path;
94 1.1 mycroft caddr_t data;
95 1.1 mycroft struct nameidata *ndp;
96 1.1 mycroft struct proc *p;
97 1.1 mycroft {
98 1.1 mycroft struct vnode *devvp;
99 1.1 mycroft struct ufs_args args;
100 1.1 mycroft struct ufsmount *ump;
101 1.1 mycroft register struct lfs *fs; /* LFS */
102 1.1 mycroft u_int size;
103 1.1 mycroft int error;
104 1.1 mycroft
105 1.1 mycroft if (error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args)))
106 1.1 mycroft return (error);
107 1.1 mycroft
108 1.1 mycroft /* Until LFS can do NFS right. XXX */
109 1.1 mycroft if (args.export.ex_flags & MNT_EXPORTED)
110 1.1 mycroft return (EINVAL);
111 1.1 mycroft
112 1.1 mycroft /*
113 1.1 mycroft * If updating, check whether changing from read-only to
114 1.1 mycroft * read/write; if there is no device name, that's all we do.
115 1.1 mycroft */
116 1.1 mycroft if (mp->mnt_flag & MNT_UPDATE) {
117 1.1 mycroft ump = VFSTOUFS(mp);
118 1.1 mycroft #ifdef NOTLFS /* LFS */
119 1.1 mycroft fs = ump->um_fs;
120 1.1 mycroft if (fs->fs_ronly && (mp->mnt_flag & MNT_RDONLY) == 0)
121 1.1 mycroft fs->fs_ronly = 0;
122 1.1 mycroft #else
123 1.1 mycroft fs = ump->um_lfs;
124 1.1 mycroft if (fs->lfs_ronly && (mp->mnt_flag & MNT_RDONLY) == 0)
125 1.1 mycroft fs->lfs_ronly = 0;
126 1.1 mycroft #endif
127 1.1 mycroft if (args.fspec == 0) {
128 1.1 mycroft /*
129 1.1 mycroft * Process export requests.
130 1.1 mycroft */
131 1.1 mycroft return (vfs_export(mp, &ump->um_export, &args.export));
132 1.1 mycroft }
133 1.1 mycroft }
134 1.1 mycroft /*
135 1.1 mycroft * Not an update, or updating the name: look up the name
136 1.1 mycroft * and verify that it refers to a sensible block device.
137 1.1 mycroft */
138 1.1 mycroft NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
139 1.1 mycroft if (error = namei(ndp))
140 1.1 mycroft return (error);
141 1.1 mycroft devvp = ndp->ni_vp;
142 1.1 mycroft if (devvp->v_type != VBLK) {
143 1.1 mycroft vrele(devvp);
144 1.1 mycroft return (ENOTBLK);
145 1.1 mycroft }
146 1.1 mycroft if (major(devvp->v_rdev) >= nblkdev) {
147 1.1 mycroft vrele(devvp);
148 1.1 mycroft return (ENXIO);
149 1.1 mycroft }
150 1.1 mycroft if ((mp->mnt_flag & MNT_UPDATE) == 0)
151 1.1 mycroft error = lfs_mountfs(devvp, mp, p); /* LFS */
152 1.1 mycroft else {
153 1.1 mycroft if (devvp != ump->um_devvp)
154 1.1 mycroft error = EINVAL; /* needs translation */
155 1.1 mycroft else
156 1.1 mycroft vrele(devvp);
157 1.1 mycroft }
158 1.1 mycroft if (error) {
159 1.1 mycroft vrele(devvp);
160 1.1 mycroft return (error);
161 1.1 mycroft }
162 1.1 mycroft ump = VFSTOUFS(mp);
163 1.1 mycroft fs = ump->um_lfs; /* LFS */
164 1.1 mycroft #ifdef NOTLFS /* LFS */
165 1.1 mycroft (void) copyinstr(path, fs->fs_fsmnt, sizeof(fs->fs_fsmnt) - 1, &size);
166 1.1 mycroft bzero(fs->fs_fsmnt + size, sizeof(fs->fs_fsmnt) - size);
167 1.1 mycroft bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname,
168 1.1 mycroft MNAMELEN);
169 1.1 mycroft (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
170 1.1 mycroft &size);
171 1.1 mycroft bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
172 1.1 mycroft (void) ufs_statfs(mp, &mp->mnt_stat, p);
173 1.1 mycroft #else
174 1.1 mycroft (void)copyinstr(path, fs->lfs_fsmnt, sizeof(fs->lfs_fsmnt) - 1, &size);
175 1.1 mycroft bzero(fs->lfs_fsmnt + size, sizeof(fs->lfs_fsmnt) - size);
176 1.1 mycroft bcopy((caddr_t)fs->lfs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname,
177 1.1 mycroft MNAMELEN);
178 1.1 mycroft (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
179 1.1 mycroft &size);
180 1.1 mycroft bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
181 1.1 mycroft (void) lfs_statfs(mp, &mp->mnt_stat, p);
182 1.1 mycroft #endif
183 1.1 mycroft return (0);
184 1.1 mycroft }
185 1.1 mycroft
186 1.1 mycroft /*
187 1.1 mycroft * Common code for mount and mountroot
188 1.1 mycroft * LFS specific
189 1.1 mycroft */
190 1.1 mycroft int
191 1.1 mycroft lfs_mountfs(devvp, mp, p)
192 1.1 mycroft register struct vnode *devvp;
193 1.1 mycroft struct mount *mp;
194 1.1 mycroft struct proc *p;
195 1.1 mycroft {
196 1.1 mycroft extern struct vnode *rootvp;
197 1.1 mycroft register struct lfs *fs;
198 1.1 mycroft register struct ufsmount *ump;
199 1.1 mycroft struct vnode *vp;
200 1.1 mycroft struct buf *bp;
201 1.1 mycroft struct partinfo dpart;
202 1.1 mycroft dev_t dev;
203 1.1 mycroft int error, i, ronly, size;
204 1.1 mycroft
205 1.1 mycroft /*
206 1.1 mycroft * Disallow multiple mounts of the same device.
207 1.1 mycroft * Disallow mounting of a device that is currently in use
208 1.1 mycroft * (except for root, which might share swap device for miniroot).
209 1.1 mycroft * Flush out any old buffers remaining from a previous use.
210 1.1 mycroft */
211 1.1 mycroft if (error = vfs_mountedon(devvp))
212 1.1 mycroft return (error);
213 1.1 mycroft if (vcount(devvp) > 1 && devvp != rootvp)
214 1.1 mycroft return (EBUSY);
215 1.1 mycroft if (error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0))
216 1.1 mycroft return (error);
217 1.1 mycroft
218 1.1 mycroft ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
219 1.1 mycroft if (error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p))
220 1.1 mycroft return (error);
221 1.1 mycroft
222 1.1 mycroft if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, NOCRED, p) != 0)
223 1.1 mycroft size = DEV_BSIZE;
224 1.1 mycroft else {
225 1.1 mycroft size = dpart.disklab->d_secsize;
226 1.1 mycroft #ifdef NEVER_USED
227 1.1 mycroft dpart.part->p_fstype = FS_LFS;
228 1.1 mycroft dpart.part->p_fsize = fs->lfs_fsize; /* frag size */
229 1.1 mycroft dpart.part->p_frag = fs->lfs_frag; /* frags per block */
230 1.1 mycroft dpart.part->p_cpg = fs->lfs_segshift; /* segment shift */
231 1.1 mycroft #endif
232 1.1 mycroft }
233 1.1 mycroft
234 1.1 mycroft /* Don't free random space on error. */
235 1.1 mycroft bp = NULL;
236 1.1 mycroft ump = NULL;
237 1.1 mycroft
238 1.1 mycroft /* Read in the superblock. */
239 1.1 mycroft if (error = bread(devvp, LFS_LABELPAD / size, LFS_SBPAD, NOCRED, &bp))
240 1.1 mycroft goto out;
241 1.1 mycroft fs = (struct lfs *)bp->b_data;
242 1.1 mycroft
243 1.1 mycroft /* Check the basics. */
244 1.1 mycroft if (fs->lfs_magic != LFS_MAGIC || fs->lfs_bsize > MAXBSIZE ||
245 1.1 mycroft fs->lfs_bsize < sizeof(struct lfs)) {
246 1.1 mycroft error = EINVAL; /* XXX needs translation */
247 1.1 mycroft goto out;
248 1.1 mycroft }
249 1.1 mycroft
250 1.1 mycroft /* Allocate the mount structure, copy the superblock into it. */
251 1.1 mycroft ump = (struct ufsmount *)malloc(sizeof *ump, M_UFSMNT, M_WAITOK);
252 1.1 mycroft fs = ump->um_lfs = malloc(sizeof(struct lfs), M_UFSMNT, M_WAITOK);
253 1.1 mycroft bcopy(bp->b_data, fs, sizeof(struct lfs));
254 1.1 mycroft if (sizeof(struct lfs) < LFS_SBPAD) /* XXX why? */
255 1.1 mycroft bp->b_flags |= B_INVAL;
256 1.1 mycroft brelse(bp);
257 1.1 mycroft bp = NULL;
258 1.1 mycroft
259 1.1 mycroft /* Set up the I/O information */
260 1.1 mycroft fs->lfs_iocount = 0;
261 1.1 mycroft
262 1.1 mycroft /* Set up the ifile and lock aflags */
263 1.1 mycroft fs->lfs_doifile = 0;
264 1.1 mycroft fs->lfs_writer = 0;
265 1.1 mycroft fs->lfs_dirops = 0;
266 1.1 mycroft fs->lfs_seglock = 0;
267 1.1 mycroft
268 1.1 mycroft /* Set the file system readonly/modify bits. */
269 1.1 mycroft fs->lfs_ronly = ronly;
270 1.1 mycroft if (ronly == 0)
271 1.1 mycroft fs->lfs_fmod = 1;
272 1.1 mycroft
273 1.1 mycroft /* Initialize the mount structure. */
274 1.1 mycroft dev = devvp->v_rdev;
275 1.1 mycroft mp->mnt_data = (qaddr_t)ump;
276 1.1 mycroft mp->mnt_stat.f_fsid.val[0] = (long)dev;
277 1.1 mycroft mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_LFS);
278 1.1 mycroft mp->mnt_maxsymlinklen = fs->lfs_maxsymlinklen;
279 1.1 mycroft mp->mnt_flag |= MNT_LOCAL;
280 1.1 mycroft ump->um_mountp = mp;
281 1.1 mycroft ump->um_dev = dev;
282 1.1 mycroft ump->um_devvp = devvp;
283 1.1 mycroft ump->um_bptrtodb = 0;
284 1.1 mycroft ump->um_seqinc = 1 << fs->lfs_fsbtodb;
285 1.1 mycroft ump->um_nindir = fs->lfs_nindir;
286 1.1 mycroft for (i = 0; i < MAXQUOTAS; i++)
287 1.1 mycroft ump->um_quotas[i] = NULLVP;
288 1.1 mycroft devvp->v_specflags |= SI_MOUNTEDON;
289 1.1 mycroft
290 1.1 mycroft /*
291 1.1 mycroft * We use the ifile vnode for almost every operation. Instead of
292 1.1 mycroft * retrieving it from the hash table each time we retrieve it here,
293 1.1 mycroft * artificially increment the reference count and keep a pointer
294 1.1 mycroft * to it in the incore copy of the superblock.
295 1.1 mycroft */
296 1.1 mycroft if (error = VFS_VGET(mp, LFS_IFILE_INUM, &vp))
297 1.1 mycroft goto out;
298 1.1 mycroft fs->lfs_ivnode = vp;
299 1.1 mycroft VREF(vp);
300 1.1 mycroft vput(vp);
301 1.1 mycroft
302 1.1 mycroft return (0);
303 1.1 mycroft out:
304 1.1 mycroft if (bp)
305 1.1 mycroft brelse(bp);
306 1.1 mycroft (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
307 1.1 mycroft if (ump) {
308 1.1 mycroft free(ump->um_lfs, M_UFSMNT);
309 1.1 mycroft free(ump, M_UFSMNT);
310 1.1 mycroft mp->mnt_data = (qaddr_t)0;
311 1.1 mycroft }
312 1.1 mycroft return (error);
313 1.1 mycroft }
314 1.1 mycroft
315 1.1 mycroft /*
316 1.1 mycroft * unmount system call
317 1.1 mycroft */
318 1.1 mycroft lfs_unmount(mp, mntflags, p)
319 1.1 mycroft struct mount *mp;
320 1.1 mycroft int mntflags;
321 1.1 mycroft struct proc *p;
322 1.1 mycroft {
323 1.1 mycroft extern int doforce;
324 1.1 mycroft register struct ufsmount *ump;
325 1.1 mycroft register struct lfs *fs;
326 1.1 mycroft int i, error, flags, ronly;
327 1.1 mycroft
328 1.1 mycroft flags = 0;
329 1.1 mycroft if (mntflags & MNT_FORCE) {
330 1.1 mycroft if (!doforce || (mp->mnt_flag & MNT_ROOTFS))
331 1.1 mycroft return (EINVAL);
332 1.1 mycroft flags |= FORCECLOSE;
333 1.1 mycroft }
334 1.1 mycroft
335 1.1 mycroft ump = VFSTOUFS(mp);
336 1.1 mycroft fs = ump->um_lfs;
337 1.1 mycroft #ifdef QUOTA
338 1.1 mycroft if (mp->mnt_flag & MNT_QUOTA) {
339 1.1 mycroft if (error = vflush(mp, fs->lfs_ivnode, SKIPSYSTEM|flags))
340 1.1 mycroft return (error);
341 1.1 mycroft for (i = 0; i < MAXQUOTAS; i++) {
342 1.1 mycroft if (ump->um_quotas[i] == NULLVP)
343 1.1 mycroft continue;
344 1.1 mycroft quotaoff(p, mp, i);
345 1.1 mycroft }
346 1.1 mycroft /*
347 1.1 mycroft * Here we fall through to vflush again to ensure
348 1.1 mycroft * that we have gotten rid of all the system vnodes.
349 1.1 mycroft */
350 1.1 mycroft }
351 1.1 mycroft #endif
352 1.1 mycroft if (error = vflush(mp, fs->lfs_ivnode, flags))
353 1.1 mycroft return (error);
354 1.1 mycroft fs->lfs_clean = 1;
355 1.1 mycroft if (error = VFS_SYNC(mp, 1, p->p_ucred, p))
356 1.1 mycroft return (error);
357 1.1 mycroft if (fs->lfs_ivnode->v_dirtyblkhd.lh_first)
358 1.1 mycroft panic("lfs_unmount: still dirty blocks on ifile vnode\n");
359 1.1 mycroft vrele(fs->lfs_ivnode);
360 1.1 mycroft vgone(fs->lfs_ivnode);
361 1.1 mycroft
362 1.1 mycroft ronly = !fs->lfs_ronly;
363 1.1 mycroft ump->um_devvp->v_specflags &= ~SI_MOUNTEDON;
364 1.1 mycroft error = VOP_CLOSE(ump->um_devvp,
365 1.1 mycroft ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
366 1.1 mycroft vrele(ump->um_devvp);
367 1.1 mycroft free(fs, M_UFSMNT);
368 1.1 mycroft free(ump, M_UFSMNT);
369 1.1 mycroft mp->mnt_data = (qaddr_t)0;
370 1.1 mycroft mp->mnt_flag &= ~MNT_LOCAL;
371 1.1 mycroft return (error);
372 1.1 mycroft }
373 1.1 mycroft
374 1.1 mycroft /*
375 1.1 mycroft * Get file system statistics.
376 1.1 mycroft */
377 1.1 mycroft lfs_statfs(mp, sbp, p)
378 1.1 mycroft struct mount *mp;
379 1.1 mycroft register struct statfs *sbp;
380 1.1 mycroft struct proc *p;
381 1.1 mycroft {
382 1.1 mycroft register struct lfs *fs;
383 1.1 mycroft register struct ufsmount *ump;
384 1.1 mycroft
385 1.1 mycroft ump = VFSTOUFS(mp);
386 1.1 mycroft fs = ump->um_lfs;
387 1.1 mycroft if (fs->lfs_magic != LFS_MAGIC)
388 1.1 mycroft panic("lfs_statfs: magic");
389 1.1 mycroft sbp->f_type = 0;
390 1.1 mycroft sbp->f_bsize = fs->lfs_bsize;
391 1.1 mycroft sbp->f_iosize = fs->lfs_bsize;
392 1.1 mycroft sbp->f_blocks = dbtofsb(fs,fs->lfs_dsize);
393 1.1 mycroft sbp->f_bfree = dbtofsb(fs, fs->lfs_bfree);
394 1.1 mycroft sbp->f_bavail = (fs->lfs_dsize * (100 - fs->lfs_minfree) / 100) -
395 1.1 mycroft (fs->lfs_dsize - fs->lfs_bfree);
396 1.1 mycroft sbp->f_bavail = dbtofsb(fs, sbp->f_bavail);
397 1.1 mycroft sbp->f_files = fs->lfs_nfiles;
398 1.1 mycroft sbp->f_ffree = sbp->f_bfree * INOPB(fs);
399 1.1 mycroft if (sbp != &mp->mnt_stat) {
400 1.1 mycroft bcopy((caddr_t)mp->mnt_stat.f_mntonname,
401 1.1 mycroft (caddr_t)&sbp->f_mntonname[0], MNAMELEN);
402 1.1 mycroft bcopy((caddr_t)mp->mnt_stat.f_mntfromname,
403 1.1 mycroft (caddr_t)&sbp->f_mntfromname[0], MNAMELEN);
404 1.1 mycroft }
405 1.1 mycroft strncpy(&sbp->f_fstypename[0], mp->mnt_op->vfs_name, MFSNAMELEN);
406 1.1 mycroft sbp->f_fstypename[MFSNAMELEN] = '\0';
407 1.1 mycroft return (0);
408 1.1 mycroft }
409 1.1 mycroft
410 1.1 mycroft /*
411 1.1 mycroft * Go through the disk queues to initiate sandbagged IO;
412 1.1 mycroft * go through the inodes to write those that have been modified;
413 1.1 mycroft * initiate the writing of the super block if it has been modified.
414 1.1 mycroft *
415 1.1 mycroft * Note: we are always called with the filesystem marked `MPBUSY'.
416 1.1 mycroft */
417 1.1 mycroft lfs_sync(mp, waitfor, cred, p)
418 1.1 mycroft struct mount *mp;
419 1.1 mycroft int waitfor;
420 1.1 mycroft struct ucred *cred;
421 1.1 mycroft struct proc *p;
422 1.1 mycroft {
423 1.1 mycroft int error;
424 1.1 mycroft
425 1.1 mycroft /* All syncs must be checkpoints until roll-forward is implemented. */
426 1.1 mycroft error = lfs_segwrite(mp, SEGM_CKP | (waitfor ? SEGM_SYNC : 0));
427 1.1 mycroft #ifdef QUOTA
428 1.1 mycroft qsync(mp);
429 1.1 mycroft #endif
430 1.1 mycroft return (error);
431 1.1 mycroft }
432 1.1 mycroft
433 1.1 mycroft /*
434 1.1 mycroft * Look up an LFS dinode number to find its incore vnode. If not already
435 1.1 mycroft * in core, read it in from the specified device. Return the inode locked.
436 1.1 mycroft * Detection and handling of mount points must be done by the calling routine.
437 1.1 mycroft */
438 1.1 mycroft int
439 1.1 mycroft lfs_vget(mp, ino, vpp)
440 1.1 mycroft struct mount *mp;
441 1.1 mycroft ino_t ino;
442 1.1 mycroft struct vnode **vpp;
443 1.1 mycroft {
444 1.1 mycroft register struct lfs *fs;
445 1.1 mycroft register struct inode *ip;
446 1.1 mycroft struct buf *bp;
447 1.1 mycroft struct ifile *ifp;
448 1.1 mycroft struct vnode *vp;
449 1.1 mycroft struct ufsmount *ump;
450 1.1 mycroft daddr_t daddr;
451 1.1 mycroft dev_t dev;
452 1.1 mycroft int error;
453 1.1 mycroft
454 1.1 mycroft ump = VFSTOUFS(mp);
455 1.1 mycroft dev = ump->um_dev;
456 1.1 mycroft if ((*vpp = ufs_ihashget(dev, ino)) != NULL)
457 1.1 mycroft return (0);
458 1.1 mycroft
459 1.1 mycroft /* Translate the inode number to a disk address. */
460 1.1 mycroft fs = ump->um_lfs;
461 1.1 mycroft if (ino == LFS_IFILE_INUM)
462 1.1 mycroft daddr = fs->lfs_idaddr;
463 1.1 mycroft else {
464 1.1 mycroft LFS_IENTRY(ifp, fs, ino, bp);
465 1.1 mycroft daddr = ifp->if_daddr;
466 1.1 mycroft brelse(bp);
467 1.1 mycroft if (daddr == LFS_UNUSED_DADDR)
468 1.1 mycroft return (ENOENT);
469 1.1 mycroft }
470 1.1 mycroft
471 1.1 mycroft /* Allocate new vnode/inode. */
472 1.1 mycroft if (error = lfs_vcreate(mp, ino, &vp)) {
473 1.1 mycroft *vpp = NULL;
474 1.1 mycroft return (error);
475 1.1 mycroft }
476 1.1 mycroft
477 1.1 mycroft /*
478 1.1 mycroft * Put it onto its hash chain and lock it so that other requests for
479 1.1 mycroft * this inode will block if they arrive while we are sleeping waiting
480 1.1 mycroft * for old data structures to be purged or for the contents of the
481 1.1 mycroft * disk portion of this inode to be read.
482 1.1 mycroft */
483 1.1 mycroft ip = VTOI(vp);
484 1.1 mycroft ufs_ihashins(ip);
485 1.1 mycroft
486 1.1 mycroft /*
487 1.1 mycroft * XXX
488 1.1 mycroft * This may not need to be here, logically it should go down with
489 1.1 mycroft * the i_devvp initialization.
490 1.1 mycroft * Ask Kirk.
491 1.1 mycroft */
492 1.1 mycroft ip->i_lfs = ump->um_lfs;
493 1.1 mycroft
494 1.1 mycroft /* Read in the disk contents for the inode, copy into the inode. */
495 1.1 mycroft if (error =
496 1.1 mycroft bread(ump->um_devvp, daddr, (int)fs->lfs_bsize, NOCRED, &bp)) {
497 1.1 mycroft /*
498 1.1 mycroft * The inode does not contain anything useful, so it would
499 1.1 mycroft * be misleading to leave it on its hash chain. With mode
500 1.1 mycroft * still zero, it will be unlinked and returned to the free
501 1.1 mycroft * list by vput().
502 1.1 mycroft */
503 1.1 mycroft vput(vp);
504 1.1 mycroft brelse(bp);
505 1.1 mycroft *vpp = NULL;
506 1.1 mycroft return (error);
507 1.1 mycroft }
508 1.1 mycroft ip->i_din = *lfs_ifind(fs, ino, (struct dinode *)bp->b_data);
509 1.1 mycroft brelse(bp);
510 1.1 mycroft
511 1.1 mycroft /*
512 1.1 mycroft * Initialize the vnode from the inode, check for aliases. In all
513 1.1 mycroft * cases re-init ip, the underlying vnode/inode may have changed.
514 1.1 mycroft */
515 1.1 mycroft if (error = ufs_vinit(mp, lfs_specop_p, LFS_FIFOOPS, &vp)) {
516 1.1 mycroft vput(vp);
517 1.1 mycroft *vpp = NULL;
518 1.1 mycroft return (error);
519 1.1 mycroft }
520 1.1 mycroft /*
521 1.1 mycroft * Finish inode initialization now that aliasing has been resolved.
522 1.1 mycroft */
523 1.1 mycroft ip->i_devvp = ump->um_devvp;
524 1.1 mycroft VREF(ip->i_devvp);
525 1.1 mycroft *vpp = vp;
526 1.1 mycroft return (0);
527 1.1 mycroft }
528 1.1 mycroft
529 1.1 mycroft /*
530 1.1 mycroft * File handle to vnode
531 1.1 mycroft *
532 1.1 mycroft * Have to be really careful about stale file handles:
533 1.1 mycroft * - check that the inode number is valid
534 1.1 mycroft * - call lfs_vget() to get the locked inode
535 1.1 mycroft * - check for an unallocated inode (i_mode == 0)
536 1.1 mycroft * - check that the given client host has export rights and return
537 1.1 mycroft * those rights via. exflagsp and credanonp
538 1.1 mycroft *
539 1.1 mycroft * XXX
540 1.1 mycroft * use ifile to see if inode is allocated instead of reading off disk
541 1.1 mycroft * what is the relationship between my generational number and the NFS
542 1.1 mycroft * generational number.
543 1.1 mycroft */
544 1.1 mycroft int
545 1.1 mycroft lfs_fhtovp(mp, fhp, nam, vpp, exflagsp, credanonp)
546 1.1 mycroft register struct mount *mp;
547 1.1 mycroft struct fid *fhp;
548 1.1 mycroft struct mbuf *nam;
549 1.1 mycroft struct vnode **vpp;
550 1.1 mycroft int *exflagsp;
551 1.1 mycroft struct ucred **credanonp;
552 1.1 mycroft {
553 1.1 mycroft register struct ufid *ufhp;
554 1.1 mycroft
555 1.1 mycroft ufhp = (struct ufid *)fhp;
556 1.1 mycroft if (ufhp->ufid_ino < ROOTINO)
557 1.1 mycroft return (ESTALE);
558 1.1 mycroft return (ufs_check_export(mp, ufhp, nam, vpp, exflagsp, credanonp));
559 1.1 mycroft }
560 1.1 mycroft
561 1.1 mycroft /*
562 1.1 mycroft * Vnode pointer to File handle
563 1.1 mycroft */
564 1.1 mycroft /* ARGSUSED */
565 1.1 mycroft lfs_vptofh(vp, fhp)
566 1.1 mycroft struct vnode *vp;
567 1.1 mycroft struct fid *fhp;
568 1.1 mycroft {
569 1.1 mycroft register struct inode *ip;
570 1.1 mycroft register struct ufid *ufhp;
571 1.1 mycroft
572 1.1 mycroft ip = VTOI(vp);
573 1.1 mycroft ufhp = (struct ufid *)fhp;
574 1.1 mycroft ufhp->ufid_len = sizeof(struct ufid);
575 1.1 mycroft ufhp->ufid_ino = ip->i_number;
576 1.1 mycroft ufhp->ufid_gen = ip->i_gen;
577 1.1 mycroft return (0);
578 1.1 mycroft }
579