Commit | Line | Data |
---|---|---|
da7c5cc6 | 1 | /* |
52ff95c2 | 2 | * Copyright (c) 1989, 1991, 1993, 1994 |
ad0f93d2 | 3 | * The Regents of the University of California. All rights reserved. |
da7c5cc6 | 4 | * |
b702c21d | 5 | * %sccs.include.redist.c% |
7188ac27 | 6 | * |
9e8b5f02 | 7 | * @(#)lfs_vfsops.c 8.20 (Berkeley) %G% |
da7c5cc6 | 8 | */ |
71e4e98b | 9 | |
c7e94c3a KB |
10 | #include <sys/param.h> |
11 | #include <sys/systm.h> | |
12 | #include <sys/namei.h> | |
13 | #include <sys/proc.h> | |
14 | #include <sys/kernel.h> | |
15 | #include <sys/vnode.h> | |
c7e94c3a KB |
16 | #include <sys/mount.h> |
17 | #include <sys/buf.h> | |
3a0a9bdc | 18 | #include <sys/mbuf.h> |
c7e94c3a KB |
19 | #include <sys/file.h> |
20 | #include <sys/disklabel.h> | |
21 | #include <sys/ioctl.h> | |
22 | #include <sys/errno.h> | |
23 | #include <sys/malloc.h> | |
3a0a9bdc | 24 | #include <sys/socket.h> |
cff1d696 KM |
25 | |
26 | #include <miscfs/specfs/specdev.h> | |
609e7cfa MK |
27 | #include "ioctl.h" |
28 | #include "disklabel.h" | |
29 | #include "stat.h" | |
71e4e98b | 30 | |
d9f5f868 KB |
31 | #include <ufs/ufs/quota.h> |
32 | #include <ufs/ufs/inode.h> | |
33 | #include <ufs/ufs/ufsmount.h> | |
34 | #include <ufs/ufs/ufs_extern.h> | |
c6f5111d | 35 | |
d9f5f868 KB |
36 | #include <ufs/lfs/lfs.h> |
37 | #include <ufs/lfs/lfs_extern.h> | |
275ca4f0 | 38 | |
79a0d4bf | 39 | int lfs_mountfs __P((struct vnode *, struct mount *, struct proc *)); |
0b4d6502 KB |
40 | |
41 | struct vfsops lfs_vfsops = { | |
42 | lfs_mount, | |
5bf9d21f | 43 | ufs_start, |
0b4d6502 | 44 | lfs_unmount, |
52ff95c2 | 45 | ufs_root, |
8dc876c1 | 46 | ufs_quotactl, |
0b4d6502 KB |
47 | lfs_statfs, |
48 | lfs_sync, | |
f7802306 | 49 | lfs_vget, |
b16ed5f4 KM |
50 | lfs_fhtovp, |
51 | lfs_vptofh, | |
c7e94c3a | 52 | lfs_init, |
06ce3734 | 53 | lfs_sysctl, |
7188ac27 KM |
54 | }; |
55 | ||
c4c82039 KM |
56 | /* |
57 | * Called by main() when ufs is going to be mounted as root. | |
58 | */ | |
0b4d6502 | 59 | lfs_mountroot() |
71e4e98b | 60 | { |
c4c82039 KM |
61 | extern struct vnode *rootvp; |
62 | struct fs *fs; | |
63 | struct mount *mp; | |
64 | struct proc *p = curproc; /* XXX */ | |
65 | int error; | |
66 | ||
67 | /* | |
68 | * Get vnodes for swapdev and rootdev. | |
69 | */ | |
8b04865c KM |
70 | if ((error = bdevvp(swapdev, &swapdev_vp)) || |
71 | (error = bdevvp(rootdev, &rootvp))) { | |
72 | printf("lfs_mountroot: can't setup bdevvp's"); | |
73 | return (error); | |
74 | } | |
c4c82039 KM |
75 | if (error = vfs_rootmountalloc("lfs", "root_device", &mp)) |
76 | return (error); | |
77 | if (error = lfs_mountfs(rootvp, mp, p)) { | |
78 | mp->mnt_vfc->vfc_refcount--; | |
9cc53703 | 79 | vfs_unbusy(mp, p); |
c4c82039 KM |
80 | free(mp, M_MOUNT); |
81 | return (error); | |
82 | } | |
9cc53703 | 83 | simple_lock(&mountlist_slock); |
c4c82039 | 84 | CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); |
9cc53703 | 85 | simple_unlock(&mountlist_slock); |
c4c82039 | 86 | (void)lfs_statfs(mp, &mp->mnt_stat, p); |
9cc53703 | 87 | vfs_unbusy(mp, p); |
c4c82039 | 88 | return (0); |
7188ac27 KM |
89 | } |
90 | ||
91 | /* | |
92 | * VFS Operations. | |
93 | * | |
94 | * mount system call | |
95 | */ | |
0b4d6502 | 96 | lfs_mount(mp, path, data, ndp, p) |
d45de50d | 97 | register struct mount *mp; |
7188ac27 KM |
98 | char *path; |
99 | caddr_t data; | |
100 | struct nameidata *ndp; | |
0eb6f54a | 101 | struct proc *p; |
7188ac27 KM |
102 | { |
103 | struct vnode *devvp; | |
104 | struct ufs_args args; | |
105 | struct ufsmount *ump; | |
d9f5f868 | 106 | register struct lfs *fs; /* LFS */ |
7188ac27 KM |
107 | u_int size; |
108 | int error; | |
38047d55 | 109 | mode_t accessmode; |
7188ac27 KM |
110 | |
111 | if (error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args))) | |
112 | return (error); | |
c7e94c3a KB |
113 | |
114 | /* Until LFS can do NFS right. XXX */ | |
ea7e18a7 | 115 | if (args.export.ex_flags & MNT_EXPORTED) |
c7e94c3a | 116 | return (EINVAL); |
ea7e18a7 | 117 | |
190244fb MK |
118 | /* |
119 | * If updating, check whether changing from read-only to | |
120 | * read/write; if there is no device name, that's all we do. | |
121 | */ | |
122 | if (mp->mnt_flag & MNT_UPDATE) { | |
d48157d5 | 123 | ump = VFSTOUFS(mp); |
38047d55 KM |
124 | if (fs->lfs_ronly && (mp->mnt_flag & MNT_WANTRDWR)) { |
125 | /* | |
126 | * If upgrade to read-write by non-root, then verify | |
127 | * that user has necessary permissions on the device. | |
128 | */ | |
129 | if (p->p_ucred->cr_uid != 0) { | |
4a780c24 KM |
130 | vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY, |
131 | p); | |
38047d55 KM |
132 | if (error = VOP_ACCESS(ump->um_devvp, |
133 | VREAD | VWRITE, p->p_ucred, p)) { | |
4a780c24 | 134 | VOP_UNLOCK(ump->um_devvp, 0, p); |
38047d55 KM |
135 | return (error); |
136 | } | |
4a780c24 | 137 | VOP_UNLOCK(ump->um_devvp, 0, p); |
38047d55 | 138 | } |
0b4d6502 | 139 | fs->lfs_ronly = 0; |
38047d55 | 140 | } |
64583792 KM |
141 | if (args.fspec == 0) { |
142 | /* | |
143 | * Process export requests. | |
144 | */ | |
ea7e18a7 | 145 | return (vfs_export(mp, &ump->um_export, &args.export)); |
64583792 | 146 | } |
190244fb MK |
147 | } |
148 | /* | |
149 | * Not an update, or updating the name: look up the name | |
150 | * and verify that it refers to a sensible block device. | |
151 | */ | |
995e59df KM |
152 | NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p); |
153 | if (error = namei(ndp)) | |
190244fb MK |
154 | return (error); |
155 | devvp = ndp->ni_vp; | |
156 | if (devvp->v_type != VBLK) { | |
157 | vrele(devvp); | |
158 | return (ENOTBLK); | |
159 | } | |
160 | if (major(devvp->v_rdev) >= nblkdev) { | |
161 | vrele(devvp); | |
162 | return (ENXIO); | |
163 | } | |
38047d55 KM |
164 | /* |
165 | * If mount by non-root, then verify that user has necessary | |
166 | * permissions on the device. | |
167 | */ | |
168 | if (p->p_ucred->cr_uid != 0) { | |
169 | accessmode = VREAD; | |
170 | if ((mp->mnt_flag & MNT_RDONLY) == 0) | |
171 | accessmode |= VWRITE; | |
4a780c24 | 172 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p); |
38047d55 KM |
173 | if (error = VOP_ACCESS(devvp, accessmode, p->p_ucred, p)) { |
174 | vput(devvp); | |
175 | return (error); | |
176 | } | |
4a780c24 | 177 | VOP_UNLOCK(devvp, 0, p); |
38047d55 | 178 | } |
190244fb | 179 | if ((mp->mnt_flag & MNT_UPDATE) == 0) |
0b4d6502 | 180 | error = lfs_mountfs(devvp, mp, p); /* LFS */ |
190244fb | 181 | else { |
d48157d5 KM |
182 | if (devvp != ump->um_devvp) |
183 | error = EINVAL; /* needs translation */ | |
2a7dbb09 KM |
184 | else |
185 | vrele(devvp); | |
d48157d5 | 186 | } |
7188ac27 KM |
187 | if (error) { |
188 | vrele(devvp); | |
189 | return (error); | |
27d00e76 | 190 | } |
7188ac27 | 191 | ump = VFSTOUFS(mp); |
0b4d6502 KB |
192 | fs = ump->um_lfs; /* LFS */ |
193 | #ifdef NOTLFS /* LFS */ | |
7188ac27 KM |
194 | (void) copyinstr(path, fs->fs_fsmnt, sizeof(fs->fs_fsmnt) - 1, &size); |
195 | bzero(fs->fs_fsmnt + size, sizeof(fs->fs_fsmnt) - size); | |
82161bc8 KM |
196 | bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname, |
197 | MNAMELEN); | |
79a0d4bf | 198 | (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, |
82161bc8 KM |
199 | &size); |
200 | bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); | |
0eb6f54a | 201 | (void) ufs_statfs(mp, &mp->mnt_stat, p); |
0b4d6502 KB |
202 | #else |
203 | (void)copyinstr(path, fs->lfs_fsmnt, sizeof(fs->lfs_fsmnt) - 1, &size); | |
204 | bzero(fs->lfs_fsmnt + size, sizeof(fs->lfs_fsmnt) - size); | |
205 | bcopy((caddr_t)fs->lfs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname, | |
206 | MNAMELEN); | |
79a0d4bf | 207 | (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, |
0b4d6502 KB |
208 | &size); |
209 | bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); | |
210 | (void) lfs_statfs(mp, &mp->mnt_stat, p); | |
211 | #endif | |
7188ac27 | 212 | return (0); |
71e4e98b SL |
213 | } |
214 | ||
7188ac27 KM |
215 | /* |
216 | * Common code for mount and mountroot | |
0b4d6502 | 217 | * LFS specific |
7188ac27 | 218 | */ |
79a0d4bf | 219 | int |
0b4d6502 | 220 | lfs_mountfs(devvp, mp, p) |
1182ae61 | 221 | register struct vnode *devvp; |
7188ac27 | 222 | struct mount *mp; |
0eb6f54a | 223 | struct proc *p; |
71e4e98b | 224 | { |
1c26e003 | 225 | extern struct vnode *rootvp; |
d9f5f868 | 226 | register struct lfs *fs; |
0b4d6502 | 227 | register struct ufsmount *ump; |
0b4d6502 KB |
228 | struct vnode *vp; |
229 | struct buf *bp; | |
230 | struct partinfo dpart; | |
0b4d6502 KB |
231 | dev_t dev; |
232 | int error, i, ronly, size; | |
9f246d5e | 233 | struct ucred *cred; |
71e4e98b | 234 | |
9f246d5e | 235 | cred = p ? p->p_ucred : NOCRED; |
1feabdab | 236 | if (error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p)) |
7188ac27 | 237 | return (error); |
0b4d6502 | 238 | |
9f246d5e | 239 | if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, cred, p) != 0) |
609e7cfa | 240 | size = DEV_BSIZE; |
0eb6f54a | 241 | else { |
ec67a3ce | 242 | size = dpart.disklab->d_secsize; |
0b4d6502 KB |
243 | #ifdef NEVER_USED |
244 | dpart.part->p_fstype = FS_LFS; | |
245 | dpart.part->p_fsize = fs->lfs_fsize; /* frag size */ | |
246 | dpart.part->p_frag = fs->lfs_frag; /* frags per block */ | |
247 | dpart.part->p_cpg = fs->lfs_segshift; /* segment shift */ | |
248 | #endif | |
7188ac27 | 249 | } |
0b4d6502 KB |
250 | |
251 | /* Don't free random space on error. */ | |
252 | bp = NULL; | |
253 | ump = NULL; | |
254 | ||
255 | /* Read in the superblock. */ | |
9f246d5e | 256 | if (error = bread(devvp, LFS_LABELPAD / size, LFS_SBPAD, cred, &bp)) |
71e4e98b | 257 | goto out; |
8dc876c1 | 258 | error = EINVAL; /* XXX needs translation */ |
1c281610 MK |
259 | goto out; |
260 | } | |
0b4d6502 KB |
261 | |
262 | /* Allocate the mount structure, copy the superblock into it. */ | |
8dc876c1 | 263 | ump = (struct ufsmount *)malloc(sizeof *ump, M_UFSMNT, M_WAITOK); |
0c0b26ec | 264 | fs = ump->um_lfs = malloc(sizeof(struct lfs), M_UFSMNT, M_WAITOK); |
cb84e0ab | 265 | bcopy(bp->b_data, fs, sizeof(struct lfs)); |
d9f5f868 | 266 | if (sizeof(struct lfs) < LFS_SBPAD) /* XXX why? */ |
5d96a9ad | 267 | bp->b_flags |= B_INVAL; |
e018935f MK |
268 | brelse(bp); |
269 | bp = NULL; | |
0b4d6502 | 270 | |
d5075120 KB |
271 | /* Set up the I/O information */ |
272 | fs->lfs_iocount = 0; | |
d5075120 | 273 | |
0c0b26ec | 274 | /* Set up the ifile and lock aflags */ |
3ce71481 KB |
275 | fs->lfs_doifile = 0; |
276 | fs->lfs_writer = 0; | |
277 | fs->lfs_dirops = 0; | |
0c0b26ec | 278 | fs->lfs_seglock = 0; |
3ce71481 | 279 | |
0b4d6502 | 280 | /* Set the file system readonly/modify bits. */ |
0b4d6502 | 281 | fs->lfs_ronly = ronly; |
71e4e98b | 282 | if (ronly == 0) |
0b4d6502 KB |
283 | fs->lfs_fmod = 1; |
284 | ||
285 | /* Initialize the mount structure. */ | |
286 | dev = devvp->v_rdev; | |
82161bc8 KM |
287 | mp->mnt_data = (qaddr_t)ump; |
288 | mp->mnt_stat.f_fsid.val[0] = (long)dev; | |
06ce3734 | 289 | mp->mnt_stat.f_fsid.val[1] = lfs_mount_type; |
b390cbb0 | 290 | mp->mnt_maxsymlinklen = fs->lfs_maxsymlinklen; |
82161bc8 | 291 | mp->mnt_flag |= MNT_LOCAL; |
7188ac27 KM |
292 | ump->um_mountp = mp; |
293 | ump->um_dev = dev; | |
294 | ump->um_devvp = devvp; | |
5e539b49 MS |
295 | ump->um_bptrtodb = 0; |
296 | ump->um_seqinc = 1 << fs->lfs_fsbtodb; | |
297 | ump->um_nindir = fs->lfs_nindir; | |
8dc876c1 KM |
298 | for (i = 0; i < MAXQUOTAS; i++) |
299 | ump->um_quotas[i] = NULLVP; | |
f9c367e8 | 300 | devvp->v_specflags |= SI_MOUNTEDON; |
7188ac27 | 301 | |
f9c367e8 KB |
302 | /* |
303 | * We use the ifile vnode for almost every operation. Instead of | |
304 | * retrieving it from the hash table each time we retrieve it here, | |
305 | * artificially increment the reference count and keep a pointer | |
306 | * to it in the incore copy of the superblock. | |
307 | */ | |
f7802306 | 308 | if (error = VFS_VGET(mp, LFS_IFILE_INUM, &vp)) |
0b4d6502 | 309 | goto out; |
0b4d6502 | 310 | fs->lfs_ivnode = vp; |
f9c367e8 KB |
311 | VREF(vp); |
312 | vput(vp); | |
0b4d6502 | 313 | |
609e7cfa | 314 | |
7188ac27 | 315 | return (0); |
71e4e98b | 316 | out: |
c86c9b6e KM |
317 | if (bp) |
318 | brelse(bp); | |
9f246d5e | 319 | (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, cred, p); |
8dc876c1 | 320 | if (ump) { |
ece51ee9 | 321 | free(ump->um_lfs, M_UFSMNT); |
d9f5f868 | 322 | free(ump, M_UFSMNT); |
82161bc8 | 323 | mp->mnt_data = (qaddr_t)0; |
27d00e76 | 324 | } |
7188ac27 | 325 | return (error); |
71e4e98b SL |
326 | } |
327 | ||
7188ac27 KM |
328 | /* |
329 | * unmount system call | |
330 | */ | |
0b4d6502 | 331 | lfs_unmount(mp, mntflags, p) |
7188ac27 | 332 | struct mount *mp; |
8dc876c1 | 333 | int mntflags; |
0eb6f54a | 334 | struct proc *p; |
71e4e98b | 335 | { |
d9f5f868 | 336 | extern int doforce; |
7188ac27 | 337 | register struct ufsmount *ump; |
0c0b26ec | 338 | register struct lfs *fs; |
f7802306 | 339 | int i, error, flags, ronly; |
71e4e98b | 340 | |
f7802306 | 341 | flags = 0; |
fe5239dc | 342 | if (mntflags & MNT_FORCE) |
8dc876c1 | 343 | flags |= FORCECLOSE; |
3ce71481 | 344 | |
7188ac27 | 345 | ump = VFSTOUFS(mp); |
3ce71481 | 346 | fs = ump->um_lfs; |
ec67a3ce | 347 | return (error); |
71e4e98b | 348 | #ifdef QUOTA |
82161bc8 | 349 | if (mp->mnt_flag & MNT_QUOTA) { |
3ce71481 | 350 | if (error = vflush(mp, fs->lfs_ivnode, SKIPSYSTEM|flags)) |
6d943995 | 351 | return (error); |
8dc876c1 KM |
352 | for (i = 0; i < MAXQUOTAS; i++) { |
353 | if (ump->um_quotas[i] == NULLVP) | |
354 | continue; | |
70a360ba | 355 | quotaoff(p, mp, i); |
8dc876c1 | 356 | } |
6d943995 | 357 | /* |
8dc876c1 KM |
358 | * Here we fall through to vflush again to ensure |
359 | * that we have gotten rid of all the system vnodes. | |
6d943995 | 360 | */ |
8dc876c1 | 361 | } |
71e4e98b | 362 | #endif |
f7802306 | 363 | if (error = vflush(mp, fs->lfs_ivnode, flags)) |
6d943995 | 364 | return (error); |
0c0b26ec | 365 | fs->lfs_clean = 1; |
f7802306 KB |
366 | if (error = VFS_SYNC(mp, 1, p->p_ucred, p)) |
367 | return (error); | |
eb49bed5 | 368 | if (fs->lfs_ivnode->v_dirtyblkhd.lh_first) |
f7802306 | 369 | panic("lfs_unmount: still dirty blocks on ifile vnode\n"); |
4c9381d8 | 370 | vrele(fs->lfs_ivnode); |
f7802306 KB |
371 | vgone(fs->lfs_ivnode); |
372 | ||
0b4d6502 | 373 | ronly = !fs->lfs_ronly; |
7188ac27 KM |
374 | * Get file system statistics. |
375 | */ | |
0b4d6502 | 376 | lfs_statfs(mp, sbp, p) |
7188ac27 KM |
377 | struct mount *mp; |
378 | register struct statfs *sbp; | |
0eb6f54a | 379 | struct proc *p; |
7188ac27 | 380 | { |
d9f5f868 | 381 | register struct lfs *fs; |
7188ac27 | 382 | register struct ufsmount *ump; |
7188ac27 KM |
383 | |
384 | ump = VFSTOUFS(mp); | |
0b4d6502 KB |
385 | fs = ump->um_lfs; |
386 | if (fs->lfs_magic != LFS_MAGIC) | |
387 | panic("lfs_statfs: magic"); | |
9e8b5f02 | 388 | sbp->f_bsize = fs->lfs_fsize; |
cc173077 | 389 | sbp->f_iosize = fs->lfs_bsize; |
9e8b5f02 MS |
390 | sbp->f_blocks = dbtofrags(fs,fs->lfs_dsize); |
391 | sbp->f_bfree = dbtofrags(fs, fs->lfs_bfree); | |
a50a16b5 KM |
392 | /* |
393 | * To compute the available space. Subtract the minimum free | |
394 | * from the total number of blocks in the file system. Set avail | |
395 | * to the smaller of this number and fs->lfs_bfree. | |
396 | */ | |
397 | sbp->f_bavail = fs->lfs_dsize * (100 - fs->lfs_minfree) / 100; | |
398 | sbp->f_bavail = | |
399 | sbp->f_bavail > fs->lfs_bfree ? fs->lfs_bfree : sbp->f_bavail; | |
9e8b5f02 | 400 | sbp->f_bavail = dbtofrags(fs, sbp->f_bavail); |
0b4d6502 | 401 | sbp->f_files = fs->lfs_nfiles; |
435a74c9 | 402 | sbp->f_ffree = sbp->f_bfree * INOPB(fs); |
82161bc8 | 403 | if (sbp != &mp->mnt_stat) { |
06ce3734 | 404 | sbp->f_type = mp->mnt_vfc->vfc_typenum; |
82161bc8 | 405 | bcopy((caddr_t)mp->mnt_stat.f_mntonname, |
d45de50d | 406 | (caddr_t)&sbp->f_mntonname[0], MNAMELEN); |
82161bc8 | 407 | bcopy((caddr_t)mp->mnt_stat.f_mntfromname, |
d45de50d KM |
408 | (caddr_t)&sbp->f_mntfromname[0], MNAMELEN); |
409 | } | |
7188ac27 KM |
410 | return (0); |
411 | } | |
412 | ||
7188ac27 KM |
413 | /* |
414 | * Go through the disk queues to initiate sandbagged IO; | |
415 | * go through the inodes to write those that have been modified; | |
416 | * initiate the writing of the super block if it has been modified. | |
8dc876c1 KM |
417 | * |
418 | * Note: we are always called with the filesystem marked `MPBUSY'. | |
7188ac27 | 419 | */ |
f7802306 | 420 | lfs_sync(mp, waitfor, cred, p) |
71e4e98b | 421 | struct mount *mp; |
7188ac27 | 422 | int waitfor; |
f7802306 KB |
423 | struct ucred *cred; |
424 | struct proc *p; | |
71e4e98b | 425 | { |
275ca4f0 | 426 | int error; |
7188ac27 | 427 | |
c9cbb645 | 428 | /* All syncs must be checkpoints until roll-forward is implemented. */ |
d2495626 | 429 | error = lfs_segwrite(mp, SEGM_CKP | (waitfor ? SEGM_SYNC : 0)); |
8dc876c1 KM |
430 | #ifdef QUOTA |
431 | qsync(mp); | |
432 | #endif | |
275ca4f0 | 433 | return (error); |
7188ac27 | 434 | } |
b16ed5f4 | 435 | |
f7802306 KB |
436 | /* |
437 | * Look up an LFS dinode number to find its incore vnode. If not already | |
438 | * in core, read it in from the specified device. Return the inode locked. | |
439 | * Detection and handling of mount points must be done by the calling routine. | |
440 | */ | |
441 | int | |
442 | lfs_vget(mp, ino, vpp) | |
443 | struct mount *mp; | |
444 | ino_t ino; | |
445 | struct vnode **vpp; | |
446 | { | |
447 | register struct lfs *fs; | |
448 | register struct inode *ip; | |
449 | struct buf *bp; | |
450 | struct ifile *ifp; | |
451 | struct vnode *vp; | |
452 | struct ufsmount *ump; | |
89e2bb79 | 453 | ufs_daddr_t daddr; |
f7802306 KB |
454 | dev_t dev; |
455 | int error; | |
456 | ||
f7802306 KB |
457 | ump = VFSTOUFS(mp); |
458 | dev = ump->um_dev; | |
459 | if ((*vpp = ufs_ihashget(dev, ino)) != NULL) | |
460 | return (0); | |
461 | ||
462 | /* Translate the inode number to a disk address. */ | |
463 | fs = ump->um_lfs; | |
464 | if (ino == LFS_IFILE_INUM) | |
465 | daddr = fs->lfs_idaddr; | |
466 | else { | |
467 | LFS_IENTRY(ifp, fs, ino, bp); | |
468 | daddr = ifp->if_daddr; | |
469 | brelse(bp); | |
470 | if (daddr == LFS_UNUSED_DADDR) | |
471 | return (ENOENT); | |
472 | } | |
473 | ||
474 | /* Allocate new vnode/inode. */ | |
475 | if (error = lfs_vcreate(mp, ino, &vp)) { | |
476 | *vpp = NULL; | |
477 | return (error); | |
478 | } | |
479 | ||
480 | /* | |
481 | * Put it onto its hash chain and lock it so that other requests for | |
482 | * this inode will block if they arrive while we are sleeping waiting | |
483 | * for old data structures to be purged or for the contents of the | |
484 | * disk portion of this inode to be read. | |
485 | */ | |
486 | ip = VTOI(vp); | |
487 | ufs_ihashins(ip); | |
488 | ||
489 | /* | |
490 | * XXX | |
491 | * This may not need to be here, logically it should go down with | |
492 | * the i_devvp initialization. | |
493 | * Ask Kirk. | |
494 | */ | |
495 | ip->i_lfs = ump->um_lfs; | |
496 | ||
497 | /* Read in the disk contents for the inode, copy into the inode. */ | |
498 | if (error = | |
499 | bread(ump->um_devvp, daddr, (int)fs->lfs_bsize, NOCRED, &bp)) { | |
500 | /* | |
f345d060 KM |
501 | * The inode does not contain anything useful, so it would |
502 | * be misleading to leave it on its hash chain. With mode | |
503 | * still zero, it will be unlinked and returned to the free | |
504 | * list by vput(). | |
f7802306 | 505 | */ |
eca11e88 | 506 | vput(vp); |
f7802306 KB |
507 | brelse(bp); |
508 | *vpp = NULL; | |
509 | return (error); | |
510 | } | |
cb84e0ab | 511 | ip->i_din = *lfs_ifind(fs, ino, (struct dinode *)bp->b_data); |
f7802306 KB |
512 | brelse(bp); |
513 | ||
514 | /* | |
515 | * Initialize the vnode from the inode, check for aliases. In all | |
516 | * cases re-init ip, the underlying vnode/inode may have changed. | |
517 | */ | |
518 | if (error = ufs_vinit(mp, lfs_specop_p, LFS_FIFOOPS, &vp)) { | |
eca11e88 | 519 | vput(vp); |
f7802306 KB |
520 | *vpp = NULL; |
521 | return (error); | |
522 | } | |
523 | /* | |
524 | * Finish inode initialization now that aliasing has been resolved. | |
525 | */ | |
526 | ip->i_devvp = ump->um_devvp; | |
527 | VREF(ip->i_devvp); | |
528 | *vpp = vp; | |
529 | return (0); | |
530 | } | |
531 | ||
b16ed5f4 KM |
532 | /* |
533 | * File handle to vnode | |
534 | * | |
535 | * Have to be really careful about stale file handles: | |
536 | * - check that the inode number is valid | |
537 | * - call lfs_vget() to get the locked inode | |
538 | * - check for an unallocated inode (i_mode == 0) | |
9e4a3a4a KM |
539 | * - check that the given client host has export rights and return |
540 | * those rights via. exflagsp and credanonp | |
b16ed5f4 KM |
541 | * |
542 | * XXX | |
543 | * use ifile to see if inode is allocated instead of reading off disk | |
544 | * what is the relationship between my generational number and the NFS | |
545 | * generational number. | |
546 | */ | |
547 | int | |
3a0a9bdc | 548 | lfs_fhtovp(mp, fhp, nam, vpp, exflagsp, credanonp) |
b16ed5f4 KM |
549 | register struct mount *mp; |
550 | struct fid *fhp; | |
3a0a9bdc | 551 | struct mbuf *nam; |
b16ed5f4 | 552 | struct vnode **vpp; |
3a0a9bdc KM |
553 | int *exflagsp; |
554 | struct ucred **credanonp; | |
b16ed5f4 | 555 | { |
b16ed5f4 | 556 | register struct ufid *ufhp; |
b16ed5f4 KM |
557 | |
558 | ufhp = (struct ufid *)fhp; | |
559 | if (ufhp->ufid_ino < ROOTINO) | |
3a0a9bdc | 560 | return (ESTALE); |
485cf2ee | 561 | return (ufs_check_export(mp, ufhp, nam, vpp, exflagsp, credanonp)); |
b16ed5f4 KM |
562 | } |
563 | ||
564 | /* | |
565 | * Vnode pointer to File handle | |
566 | */ | |
567 | /* ARGSUSED */ | |
568 | lfs_vptofh(vp, fhp) | |
569 | struct vnode *vp; | |
570 | struct fid *fhp; | |
571 | { | |
572 | register struct inode *ip; | |
573 | register struct ufid *ufhp; | |
574 | ||
575 | ip = VTOI(vp); | |
576 | ufhp = (struct ufid *)fhp; | |
577 | ufhp->ufid_len = sizeof(struct ufid); | |
578 | ufhp->ufid_ino = ip->i_number; | |
579 | ufhp->ufid_gen = ip->i_gen; | |
580 | return (0); | |
581 | } | |
06ce3734 KM |
582 | |
583 | /* | |
584 | * Initialize the filesystem, most work done by ufs_init. | |
585 | */ | |
586 | int lfs_mount_type; | |
587 | ||
588 | int | |
589 | lfs_init(vfsp) | |
590 | struct vfsconf *vfsp; | |
591 | { | |
592 | ||
593 | lfs_mount_type = vfsp->vfc_typenum; | |
594 | return (ufs_init(vfsp)); | |
595 | } |