Commit | Line | Data |
---|---|---|
da7c5cc6 | 1 | /* |
7188ac27 KM |
2 | * Copyright (c) 1989 The Regents of the University of California. |
3 | * All rights reserved. | |
da7c5cc6 | 4 | * |
7188ac27 KM |
5 | * Redistribution and use in source and binary forms are permitted |
6 | * provided that the above copyright notice and this paragraph are | |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
16 | * | |
0f93ba7b | 17 | * @(#)ufs_vfsops.c 7.38 (Berkeley) %G% |
da7c5cc6 | 18 | */ |
71e4e98b | 19 | |
94368568 JB |
20 | #include "param.h" |
21 | #include "systm.h" | |
7188ac27 KM |
22 | #include "time.h" |
23 | #include "kernel.h" | |
24 | #include "namei.h" | |
25 | #include "vnode.h" | |
0f93ba7b | 26 | #include "specdev.h" |
94368568 | 27 | #include "mount.h" |
7188ac27 | 28 | #include "buf.h" |
a937f856 | 29 | #include "ucred.h" |
94368568 | 30 | #include "file.h" |
ec67a3ce | 31 | #include "disklabel.h" |
7188ac27 KM |
32 | #include "ioctl.h" |
33 | #include "errno.h" | |
4def0c5e | 34 | #include "malloc.h" |
7188ac27 KM |
35 | #include "../ufs/fs.h" |
36 | #include "../ufs/ufsmount.h" | |
37 | #include "../ufs/inode.h" | |
609e7cfa MK |
38 | #include "ioctl.h" |
39 | #include "disklabel.h" | |
40 | #include "stat.h" | |
71e4e98b | 41 | |
7188ac27 KM |
42 | /* |
43 | * ufs vfs operations. | |
44 | */ | |
45 | int ufs_mount(); | |
5bf9d21f | 46 | int ufs_start(); |
7188ac27 KM |
47 | int ufs_unmount(); |
48 | int ufs_root(); | |
49 | int ufs_statfs(); | |
50 | int ufs_sync(); | |
51 | int ufs_fhtovp(); | |
52 | int ufs_vptofh(); | |
de0d8667 | 53 | int ufs_init(); |
7188ac27 KM |
54 | |
55 | struct vfsops ufs_vfsops = { | |
56 | ufs_mount, | |
5bf9d21f | 57 | ufs_start, |
7188ac27 KM |
58 | ufs_unmount, |
59 | ufs_root, | |
60 | ufs_statfs, | |
61 | ufs_sync, | |
62 | ufs_fhtovp, | |
de0d8667 KM |
63 | ufs_vptofh, |
64 | ufs_init | |
7188ac27 KM |
65 | }; |
66 | ||
67 | /* | |
68 | * ufs mount table. | |
69 | */ | |
70 | struct ufsmount mounttab[NMOUNT]; | |
71 | ||
72 | /* | |
d48157d5 | 73 | * Called by vfs_mountroot when ufs is going to be mounted as root. |
7188ac27 | 74 | * |
d48157d5 | 75 | * Name is updated by mount(8) after booting. |
7188ac27 | 76 | */ |
8a4911ca | 77 | #define ROOTNAME "root_device" |
7188ac27 KM |
78 | |
79 | ufs_mountroot() | |
71e4e98b | 80 | { |
7188ac27 KM |
81 | register struct mount *mp; |
82 | extern struct vnode *rootvp; | |
83 | struct ufsmount *ump; | |
71e4e98b | 84 | register struct fs *fs; |
7188ac27 KM |
85 | u_int size; |
86 | int error; | |
71e4e98b | 87 | |
7188ac27 KM |
88 | mp = (struct mount *)malloc((u_long)sizeof(struct mount), |
89 | M_MOUNT, M_WAITOK); | |
90 | mp->m_op = &ufs_vfsops; | |
5d96a9ad | 91 | mp->m_flag = M_RDONLY; |
7188ac27 | 92 | mp->m_exroot = 0; |
31593ba7 | 93 | mp->m_mounth = (struct vnode *)0; |
7188ac27 KM |
94 | error = mountfs(rootvp, mp); |
95 | if (error) { | |
96 | free((caddr_t)mp, M_MOUNT); | |
97 | return (error); | |
71e4e98b | 98 | } |
d48157d5 | 99 | if (error = vfs_lock(mp)) { |
7188ac27 KM |
100 | (void)ufs_unmount(mp, 0); |
101 | free((caddr_t)mp, M_MOUNT); | |
102 | return (error); | |
6d07f4cd | 103 | } |
d48157d5 KM |
104 | rootfs = mp; |
105 | mp->m_next = mp; | |
106 | mp->m_prev = mp; | |
107 | mp->m_vnodecovered = (struct vnode *)0; | |
7188ac27 KM |
108 | ump = VFSTOUFS(mp); |
109 | fs = ump->um_fs; | |
d45de50d | 110 | bzero(fs->fs_fsmnt, sizeof(fs->fs_fsmnt)); |
7188ac27 | 111 | fs->fs_fsmnt[0] = '/'; |
d45de50d KM |
112 | bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)mp->m_stat.f_mntonname, MNAMELEN); |
113 | (void) copystr(ROOTNAME, mp->m_stat.f_mntfromname, MNAMELEN - 1, &size); | |
114 | bzero(mp->m_stat.f_mntfromname + size, MNAMELEN - size); | |
115 | (void) ufs_statfs(mp, &mp->m_stat); | |
7188ac27 KM |
116 | vfs_unlock(mp); |
117 | inittodr(fs->fs_time); | |
118 | return (0); | |
119 | } | |
120 | ||
121 | /* | |
122 | * VFS Operations. | |
123 | * | |
124 | * mount system call | |
125 | */ | |
126 | ufs_mount(mp, path, data, ndp) | |
d45de50d | 127 | register struct mount *mp; |
7188ac27 KM |
128 | char *path; |
129 | caddr_t data; | |
130 | struct nameidata *ndp; | |
131 | { | |
132 | struct vnode *devvp; | |
133 | struct ufs_args args; | |
134 | struct ufsmount *ump; | |
135 | register struct fs *fs; | |
136 | u_int size; | |
137 | int error; | |
138 | ||
139 | if (error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args))) | |
140 | return (error); | |
3b931949 KM |
141 | /* |
142 | * Process export requests. | |
143 | */ | |
144 | if ((args.exflags & M_EXPORTED) || (mp->m_flag & M_EXPORTED)) { | |
145 | if (args.exflags & M_EXPORTED) | |
146 | mp->m_flag |= M_EXPORTED; | |
147 | else | |
148 | mp->m_flag &= ~M_EXPORTED; | |
149 | if (args.exflags & M_EXRDONLY) | |
150 | mp->m_flag |= M_EXRDONLY; | |
151 | else | |
152 | mp->m_flag &= ~M_EXRDONLY; | |
153 | mp->m_exroot = args.exroot; | |
154 | } | |
d48157d5 | 155 | if ((mp->m_flag & M_UPDATE) == 0) { |
3b931949 KM |
156 | if ((error = getmdev(&devvp, args.fspec, ndp)) != 0) |
157 | return (error); | |
d48157d5 KM |
158 | error = mountfs(devvp, mp); |
159 | } else { | |
160 | ump = VFSTOUFS(mp); | |
161 | fs = ump->um_fs; | |
162 | if (fs->fs_ronly && (mp->m_flag & M_RDONLY) == 0) | |
163 | fs->fs_ronly = 0; | |
164 | /* | |
165 | * Verify that the specified device is the one that | |
166 | * is really being used for the root file system. | |
167 | */ | |
3b931949 KM |
168 | if (args.fspec == 0) |
169 | return (0); | |
170 | if ((error = getmdev(&devvp, args.fspec, ndp)) != 0) | |
171 | return (error); | |
d48157d5 KM |
172 | if (devvp != ump->um_devvp) |
173 | error = EINVAL; /* needs translation */ | |
174 | } | |
7188ac27 KM |
175 | if (error) { |
176 | vrele(devvp); | |
177 | return (error); | |
27d00e76 | 178 | } |
7188ac27 KM |
179 | ump = VFSTOUFS(mp); |
180 | fs = ump->um_fs; | |
181 | (void) copyinstr(path, fs->fs_fsmnt, sizeof(fs->fs_fsmnt) - 1, &size); | |
182 | bzero(fs->fs_fsmnt + size, sizeof(fs->fs_fsmnt) - size); | |
d45de50d KM |
183 | bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)mp->m_stat.f_mntonname, MNAMELEN); |
184 | (void) copyinstr(args.fspec, mp->m_stat.f_mntfromname, MNAMELEN - 1, | |
185 | &size); | |
186 | bzero(mp->m_stat.f_mntfromname + size, MNAMELEN - size); | |
187 | (void) ufs_statfs(mp, &mp->m_stat); | |
7188ac27 | 188 | return (0); |
71e4e98b SL |
189 | } |
190 | ||
7188ac27 KM |
191 | /* |
192 | * Common code for mount and mountroot | |
193 | */ | |
194 | mountfs(devvp, mp) | |
1182ae61 | 195 | register struct vnode *devvp; |
7188ac27 | 196 | struct mount *mp; |
71e4e98b | 197 | { |
7188ac27 | 198 | register struct ufsmount *ump; |
7188ac27 | 199 | struct buf *bp = NULL; |
71e4e98b | 200 | register struct fs *fs; |
7188ac27 | 201 | dev_t dev = devvp->v_rdev; |
ec67a3ce MK |
202 | struct partinfo dpart; |
203 | int havepart = 0, blks; | |
27d00e76 | 204 | caddr_t base, space; |
7188ac27 KM |
205 | int havepart = 0, blks; |
206 | int error, i, size; | |
6d07f4cd | 207 | int needclose = 0; |
7188ac27 | 208 | int ronly = (mp->m_flag & M_RDONLY) != 0; |
71e4e98b | 209 | |
ec67a3ce MK |
210 | (*bdevsw[major(dev)].d_open)(dev, ronly ? FREAD : FREAD|FWRITE, |
211 | S_IFBLK); | |
27d00e76 | 212 | if (error) { |
7188ac27 KM |
213 | ump->um_fs = NULL; |
214 | return (error); | |
27d00e76 | 215 | } |
6d07f4cd | 216 | needclose = 1; |
a937f856 | 217 | if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, NOCRED) != 0) |
609e7cfa | 218 | size = DEV_BSIZE; |
7188ac27 | 219 | else { |
ec67a3ce MK |
220 | havepart = 1; |
221 | size = dpart.disklab->d_secsize; | |
7188ac27 | 222 | } |
a937f856 | 223 | if (error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) { |
7188ac27 | 224 | ump->um_fs = NULL; |
71e4e98b | 225 | goto out; |
27d00e76 | 226 | } |
e018935f | 227 | fs = bp->b_un.b_fs; |
7188ac27 KM |
228 | ump->um_fs = NULL; |
229 | error = EINVAL; /* XXX also needs translation */ | |
1c281610 MK |
230 | goto out; |
231 | } | |
7188ac27 | 232 | ump->um_fs = (struct fs *)malloc((u_long)fs->fs_sbsize, M_SUPERBLK, |
5adcb337 | 233 | M_WAITOK); |
7188ac27 | 234 | bcopy((caddr_t)bp->b_un.b_addr, (caddr_t)ump->um_fs, |
71e4e98b | 235 | (u_int)fs->fs_sbsize); |
5d96a9ad KM |
236 | if (fs->fs_sbsize < SBSIZE) |
237 | bp->b_flags |= B_INVAL; | |
e018935f MK |
238 | brelse(bp); |
239 | bp = NULL; | |
7188ac27 KM |
240 | fs = ump->um_fs; |
241 | fs->fs_ronly = ronly; | |
71e4e98b SL |
242 | if (ronly == 0) |
243 | fs->fs_fmod = 1; | |
609e7cfa MK |
244 | if (havepart) { |
245 | dpart.part->p_fstype = FS_BSDFFS; | |
246 | dpart.part->p_fsize = fs->fs_fsize; | |
247 | dpart.part->p_frag = fs->fs_frag; | |
42ff4c2e | 248 | dpart.part->p_cpg = fs->fs_cpg; |
609e7cfa | 249 | } |
ec67a3ce MK |
250 | #ifdef SECSIZE |
251 | /* | |
252 | * If we have a disk label, force per-partition | |
253 | * filesystem information to be correct | |
254 | * and set correct current fsbtodb shift. | |
255 | */ | |
256 | #endif SECSIZE | |
257 | if (havepart) { | |
258 | dpart.part->p_fstype = FS_BSDFFS; | |
259 | dpart.part->p_fsize = fs->fs_fsize; | |
260 | dpart.part->p_frag = fs->fs_frag; | |
261 | #ifdef SECSIZE | |
262 | #ifdef tahoe | |
263 | /* | |
264 | * Save the original fsbtodb shift to restore on updates. | |
265 | * (Console doesn't understand fsbtodb changes.) | |
266 | */ | |
267 | fs->fs_sparecon[0] = fs->fs_fsbtodb; | |
268 | #endif | |
269 | i = fs->fs_fsize / size; | |
270 | for (fs->fs_fsbtodb = 0; i > 1; i >>= 1) | |
271 | fs->fs_fsbtodb++; | |
272 | #endif SECSIZE | |
273 | fs->fs_dbsize = size; | |
274 | } | |
71e4e98b | 275 | blks = howmany(fs->fs_cssize, fs->fs_fsize); |
5adcb337 KM |
276 | base = space = (caddr_t)malloc((u_long)fs->fs_cssize, M_SUPERBLK, |
277 | M_WAITOK); | |
71e4e98b SL |
278 | for (i = 0; i < blks; i += fs->fs_frag) { |
279 | size = fs->fs_bsize; | |
280 | if (i + fs->fs_frag > blks) | |
281 | size = (blks - i) * fs->fs_fsize; | |
ec67a3ce MK |
282 | #ifdef SECSIZE |
283 | tp = bread(dev, fsbtodb(fs, fs->fs_csaddr + i), size, | |
284 | fs->fs_dbsize); | |
285 | #else SECSIZE | |
a937f856 KM |
286 | error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), size, |
287 | NOCRED, &bp); | |
7188ac27 | 288 | if (error) { |
5adcb337 | 289 | free((caddr_t)base, M_SUPERBLK); |
71e4e98b SL |
290 | goto out; |
291 | } | |
e018935f | 292 | bcopy((caddr_t)bp->b_un.b_addr, space, (u_int)size); |
60f9c9e3 | 293 | fs->fs_csp[fragstoblks(fs, i)] = (struct csum *)space; |
71e4e98b | 294 | space += size; |
e018935f MK |
295 | brelse(bp); |
296 | bp = NULL; | |
71e4e98b | 297 | } |
7188ac27 | 298 | mp->m_data = (qaddr_t)ump; |
d45de50d KM |
299 | mp->m_stat.f_fsid.val[0] = (long)dev; |
300 | mp->m_stat.f_fsid.val[1] = MOUNT_UFS; | |
7188ac27 KM |
301 | ump->um_mountp = mp; |
302 | ump->um_dev = dev; | |
303 | ump->um_devvp = devvp; | |
304 | ump->um_qinod = NULL; | |
0f93ba7b | 305 | devvp->v_specflags |= SI_MOUNTEDON; |
7188ac27 | 306 | |
94354803 KM |
307 | /* Sanity checks for old file systems. XXX */ |
308 | fs->fs_npsect = MAX(fs->fs_npsect, fs->fs_nsect); /* XXX */ | |
309 | fs->fs_interleave = MAX(fs->fs_interleave, 1); /* XXX */ | |
2af59000 KM |
310 | if (fs->fs_postblformat == FS_42POSTBLFMT) /* XXX */ |
311 | fs->fs_nrpos = 8; /* XXX */ | |
609e7cfa | 312 | |
7188ac27 | 313 | return (0); |
71e4e98b | 314 | out: |
609e7cfa | 315 | if (needclose) |
a937f856 | 316 | (void) VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED); |
7188ac27 KM |
317 | if (ump->um_fs) { |
318 | free((caddr_t)ump->um_fs, M_SUPERBLK); | |
319 | ump->um_fs = NULL; | |
27d00e76 | 320 | } |
e018935f MK |
321 | if (bp) |
322 | brelse(bp); | |
7188ac27 | 323 | return (error); |
71e4e98b SL |
324 | } |
325 | ||
5bf9d21f KM |
326 | /* |
327 | * Make a filesystem operational. | |
328 | * Nothing to do at the moment. | |
329 | */ | |
31593ba7 | 330 | /* ARGSUSED */ |
5bf9d21f KM |
331 | ufs_start(mp, flags) |
332 | struct mount *mp; | |
333 | int flags; | |
334 | { | |
335 | ||
336 | return (0); | |
337 | } | |
71e4e98b | 338 | |
7188ac27 KM |
339 | /* |
340 | * unmount system call | |
341 | */ | |
342 | ufs_unmount(mp, flags) | |
343 | struct mount *mp; | |
344 | int flags; | |
71e4e98b | 345 | { |
7188ac27 | 346 | register struct ufsmount *ump; |
71e4e98b | 347 | register struct fs *fs; |
7188ac27 | 348 | int error, ronly; |
71e4e98b | 349 | |
7188ac27 KM |
350 | if (flags & MNT_FORCE) |
351 | return (EINVAL); | |
5d96a9ad KM |
352 | mntflushbuf(mp, 0); |
353 | if (mntinvalbuf(mp)) | |
354 | return (EBUSY); | |
7188ac27 | 355 | ump = VFSTOUFS(mp); |
ec67a3ce | 356 | return (error); |
71e4e98b | 357 | #ifdef QUOTA |
6d943995 KM |
358 | if (ump->um_qinod) { |
359 | if (error = vflush(mp, ITOV(ump->um_qinod), flags)) | |
360 | return (error); | |
361 | (void) closedq(ump); | |
362 | /* | |
363 | * Here we have to vflush again to get rid of the quota inode. | |
364 | * A drag, but it would be ugly to cheat, and this system | |
365 | * call does not happen often. | |
366 | */ | |
367 | if (vflush(mp, (struct vnode *)NULL, MNT_NOFORCE)) | |
368 | panic("ufs_unmount: quota"); | |
369 | } else | |
71e4e98b | 370 | #endif |
6d943995 KM |
371 | if (error = vflush(mp, (struct vnode *)NULL, flags)) |
372 | return (error); | |
7188ac27 KM |
373 | fs = ump->um_fs; |
374 | ronly = !fs->fs_ronly; | |
4def0c5e | 375 | free((caddr_t)fs->fs_csp[0], M_SUPERBLK); |
ec67a3ce MK |
376 | error = closei(dev, IFBLK, fs->fs_ronly? FREAD : FREAD|FWRITE); |
377 | irele(ip); | |
378 | return (error); | |
71e4e98b SL |
379 | } |
380 | ||
7188ac27 KM |
381 | /* |
382 | * Return root of a filesystem | |
383 | */ | |
384 | ufs_root(mp, vpp) | |
385 | struct mount *mp; | |
386 | struct vnode **vpp; | |
387 | { | |
31593ba7 KM |
388 | register struct inode *ip; |
389 | struct inode *nip; | |
390 | struct vnode tvp; | |
7188ac27 KM |
391 | int error; |
392 | ||
31593ba7 KM |
393 | tvp.v_mount = mp; |
394 | ip = VTOI(&tvp); | |
395 | ip->i_vnode = &tvp; | |
396 | ip->i_dev = VFSTOUFS(mp)->um_dev; | |
397 | error = iget(ip, (ino_t)ROOTINO, &nip); | |
7188ac27 KM |
398 | if (error) |
399 | return (error); | |
31593ba7 | 400 | *vpp = ITOV(nip); |
7188ac27 KM |
401 | return (0); |
402 | } | |
403 | ||
404 | /* | |
405 | * Get file system statistics. | |
406 | */ | |
407 | ufs_statfs(mp, sbp) | |
408 | struct mount *mp; | |
409 | register struct statfs *sbp; | |
410 | { | |
411 | register struct ufsmount *ump; | |
412 | register struct fs *fs; | |
413 | ||
414 | ump = VFSTOUFS(mp); | |
415 | fs = ump->um_fs; | |
416 | if (fs->fs_magic != FS_MAGIC) | |
417 | panic("ufs_statfs"); | |
418 | sbp->f_type = MOUNT_UFS; | |
7188ac27 KM |
419 | sbp->f_fsize = fs->fs_fsize; |
420 | sbp->f_bsize = fs->fs_bsize; | |
421 | sbp->f_blocks = fs->fs_dsize; | |
422 | sbp->f_bfree = fs->fs_cstotal.cs_nbfree * fs->fs_frag + | |
423 | fs->fs_cstotal.cs_nffree; | |
424 | sbp->f_bavail = (fs->fs_dsize * (100 - fs->fs_minfree) / 100) - | |
425 | (fs->fs_dsize - sbp->f_bfree); | |
5c41c19e | 426 | sbp->f_files = fs->fs_ncg * fs->fs_ipg - ROOTINO; |
7188ac27 | 427 | sbp->f_ffree = fs->fs_cstotal.cs_nifree; |
d45de50d KM |
428 | if (sbp != &mp->m_stat) { |
429 | bcopy((caddr_t)mp->m_stat.f_mntonname, | |
430 | (caddr_t)&sbp->f_mntonname[0], MNAMELEN); | |
431 | bcopy((caddr_t)mp->m_stat.f_mntfromname, | |
432 | (caddr_t)&sbp->f_mntfromname[0], MNAMELEN); | |
433 | } | |
7188ac27 KM |
434 | return (0); |
435 | } | |
436 | ||
437 | int syncprt = 0; | |
438 | ||
439 | /* | |
440 | * Go through the disk queues to initiate sandbagged IO; | |
441 | * go through the inodes to write those that have been modified; | |
442 | * initiate the writing of the super block if it has been modified. | |
443 | */ | |
444 | ufs_sync(mp, waitfor) | |
71e4e98b | 445 | struct mount *mp; |
7188ac27 | 446 | int waitfor; |
71e4e98b | 447 | { |
31593ba7 | 448 | register struct vnode *vp; |
7188ac27 KM |
449 | register struct inode *ip; |
450 | register struct ufsmount *ump = VFSTOUFS(mp); | |
451 | register struct fs *fs; | |
25b5cf58 | 452 | struct vnode *nvp; |
812b91f3 | 453 | int error, allerror = 0; |
7188ac27 KM |
454 | static int updlock = 0; |
455 | ||
456 | if (syncprt) | |
457 | bufstats(); | |
458 | if (updlock) | |
459 | return (EBUSY); | |
460 | fs = ump->um_fs; | |
461 | if (fs == (struct fs *)1) | |
462 | return (0); | |
463 | updlock++; | |
464 | /* | |
465 | * Write back modified superblock. | |
466 | * Consistency check that the superblock | |
467 | * is still in the buffer cache. | |
468 | */ | |
469 | if (fs->fs_fmod != 0) { | |
470 | if (fs->fs_ronly != 0) { /* XXX */ | |
471 | printf("fs = %s\n", fs->fs_fsmnt); | |
472 | panic("update: rofs mod"); | |
473 | } | |
474 | fs->fs_fmod = 0; | |
475 | fs->fs_time = time.tv_sec; | |
476 | error = sbupdate(ump, waitfor); | |
477 | } | |
478 | /* | |
479 | * Write back each (modified) inode. | |
480 | */ | |
25b5cf58 KM |
481 | loop: |
482 | for (vp = mp->m_mounth; vp; vp = nvp) { | |
483 | nvp = vp->v_mountf; | |
31593ba7 | 484 | ip = VTOI(vp); |
25b5cf58 KM |
485 | if ((ip->i_flag & (IMOD|IACC|IUPD|ICHG)) == 0 && |
486 | vp->v_dirtyblkhd == NULL) | |
7188ac27 | 487 | continue; |
25b5cf58 KM |
488 | if (vget(vp)) |
489 | goto loop; | |
490 | if (vp->v_dirtyblkhd) | |
491 | vflushbuf(vp, 0); | |
492 | if ((ip->i_flag & (IMOD|IACC|IUPD|ICHG)) && | |
493 | (error = iupdat(ip, &time, &time, 0))) | |
812b91f3 KM |
494 | allerror = error; |
495 | vput(vp); | |
7188ac27 KM |
496 | } |
497 | updlock = 0; | |
498 | /* | |
5d96a9ad | 499 | * Force stale file system control information to be flushed. |
7188ac27 | 500 | */ |
5d96a9ad | 501 | vflushbuf(ump->um_devvp, waitfor == MNT_WAIT ? B_SYNC : 0); |
812b91f3 | 502 | return (allerror); |
7188ac27 KM |
503 | } |
504 | ||
505 | /* | |
506 | * Write a superblock and associated information back to disk. | |
507 | */ | |
508 | sbupdate(mp, waitfor) | |
509 | struct ufsmount *mp; | |
510 | int waitfor; | |
511 | { | |
512 | register struct fs *fs = mp->um_fs; | |
71e4e98b SL |
513 | register struct buf *bp; |
514 | int blks; | |
515 | caddr_t space; | |
7188ac27 | 516 | int i, size, error = 0; |
71e4e98b | 517 | |
ec67a3ce MK |
518 | #ifdef SECSIZE |
519 | bp = getblk(mp->m_dev, (daddr_t)fsbtodb(fs, SBOFF / fs->fs_fsize), | |
520 | (int)fs->fs_sbsize, fs->fs_dbsize); | |
521 | #else SECSIZE | |
7188ac27 | 522 | bp = getblk(mp->um_devvp, SBLOCK, (int)fs->fs_sbsize); |
ec67a3ce | 523 | #endif SECSIZE |
71e4e98b | 524 | bcopy((caddr_t)fs, bp->b_un.b_addr, (u_int)fs->fs_sbsize); |
2af59000 KM |
525 | /* Restore compatibility to old file systems. XXX */ |
526 | if (fs->fs_postblformat == FS_42POSTBLFMT) /* XXX */ | |
527 | bp->b_un.b_fs->fs_nrpos = -1; /* XXX */ | |
ec67a3ce MK |
528 | #ifdef SECSIZE |
529 | #ifdef tahoe | |
530 | /* restore standard fsbtodb shift */ | |
531 | bp->b_un.b_fs->fs_fsbtodb = fs->fs_sparecon[0]; | |
532 | bp->b_un.b_fs->fs_sparecon[0] = 0; | |
533 | #endif | |
534 | #endif SECSIZE | |
7188ac27 KM |
535 | if (waitfor == MNT_WAIT) |
536 | error = bwrite(bp); | |
537 | else | |
538 | bawrite(bp); | |
71e4e98b SL |
539 | blks = howmany(fs->fs_cssize, fs->fs_fsize); |
540 | space = (caddr_t)fs->fs_csp[0]; | |
541 | for (i = 0; i < blks; i += fs->fs_frag) { | |
542 | size = fs->fs_bsize; | |
543 | if (i + fs->fs_frag > blks) | |
544 | size = (blks - i) * fs->fs_fsize; | |
ec67a3ce MK |
545 | #ifdef SECSIZE |
546 | bp = getblk(mp->m_dev, fsbtodb(fs, fs->fs_csaddr + i), size, | |
547 | fs->fs_dbsize); | |
548 | #else SECSIZE | |
7188ac27 | 549 | bp = getblk(mp->um_devvp, fsbtodb(fs, fs->fs_csaddr + i), size); |
ec67a3ce | 550 | #endif SECSIZE |
71e4e98b SL |
551 | bcopy(space, bp->b_un.b_addr, (u_int)size); |
552 | space += size; | |
7188ac27 KM |
553 | if (waitfor == MNT_WAIT) |
554 | error = bwrite(bp); | |
555 | else | |
556 | bawrite(bp); | |
71e4e98b | 557 | } |
7188ac27 | 558 | return (error); |
71e4e98b SL |
559 | } |
560 | ||
561 | /* | |
7188ac27 KM |
562 | * Print out statistics on the current allocation of the buffer pool. |
563 | * Can be enabled to print out on every ``sync'' by setting "syncprt" | |
564 | * above. | |
565 | */ | |
566 | bufstats() | |
567 | { | |
568 | int s, i, j, count; | |
569 | register struct buf *bp, *dp; | |
570 | int counts[MAXBSIZE/CLBYTES+1]; | |
571 | static char *bname[BQUEUES] = { "LOCKED", "LRU", "AGE", "EMPTY" }; | |
572 | ||
573 | for (bp = bfreelist, i = 0; bp < &bfreelist[BQUEUES]; bp++, i++) { | |
574 | count = 0; | |
575 | for (j = 0; j <= MAXBSIZE/CLBYTES; j++) | |
576 | counts[j] = 0; | |
577 | s = splbio(); | |
578 | for (dp = bp->av_forw; dp != bp; dp = dp->av_forw) { | |
579 | counts[dp->b_bufsize/CLBYTES]++; | |
580 | count++; | |
581 | } | |
582 | splx(s); | |
583 | printf("%s: total-%d", bname[i], count); | |
584 | for (j = 0; j <= MAXBSIZE/CLBYTES; j++) | |
585 | if (counts[j] != 0) | |
586 | printf(", %d-%d", j * CLBYTES, counts[j]); | |
587 | printf("\n"); | |
588 | } | |
589 | } | |
590 | ||
591 | /* | |
592 | * File handle to vnode | |
113c35f2 KM |
593 | * |
594 | * Have to be really careful about stale file handles: | |
595 | * - check that the inode number is in range | |
596 | * - call iget() to get the locked inode | |
597 | * - check for an unallocated inode (i_mode == 0) | |
598 | * - check that the generation number matches | |
7188ac27 KM |
599 | */ |
600 | ufs_fhtovp(mp, fhp, vpp) | |
113c35f2 | 601 | register struct mount *mp; |
7188ac27 KM |
602 | struct fid *fhp; |
603 | struct vnode **vpp; | |
604 | { | |
605 | register struct ufid *ufhp; | |
113c35f2 | 606 | register struct fs *fs; |
31593ba7 KM |
607 | register struct inode *ip; |
608 | struct inode *nip; | |
609 | struct vnode tvp; | |
7188ac27 KM |
610 | int error; |
611 | ||
612 | ufhp = (struct ufid *)fhp; | |
113c35f2 KM |
613 | fs = VFSTOUFS(mp)->um_fs; |
614 | if (ufhp->ufid_ino < ROOTINO || | |
615 | ufhp->ufid_ino >= fs->fs_ncg * fs->fs_ipg) { | |
616 | *vpp = (struct vnode *)0; | |
617 | return (EINVAL); | |
618 | } | |
31593ba7 KM |
619 | tvp.v_mount = mp; |
620 | ip = VTOI(&tvp); | |
621 | ip->i_vnode = &tvp; | |
622 | ip->i_dev = VFSTOUFS(mp)->um_dev; | |
623 | if (error = iget(ip, ufhp->ufid_ino, &nip)) { | |
113c35f2 | 624 | *vpp = (struct vnode *)0; |
7188ac27 KM |
625 | return (error); |
626 | } | |
31593ba7 | 627 | ip = nip; |
113c35f2 KM |
628 | if (ip->i_mode == 0) { |
629 | iput(ip); | |
630 | *vpp = (struct vnode *)0; | |
631 | return (EINVAL); | |
632 | } | |
7188ac27 KM |
633 | if (ip->i_gen != ufhp->ufid_gen) { |
634 | iput(ip); | |
113c35f2 | 635 | *vpp = (struct vnode *)0; |
7188ac27 KM |
636 | return (EINVAL); |
637 | } | |
638 | *vpp = ITOV(ip); | |
639 | return (0); | |
640 | } | |
641 | ||
642 | /* | |
29e77c27 | 643 | * Vnode pointer to File handle |
7188ac27 KM |
644 | */ |
645 | /* ARGSUSED */ | |
758e3529 KM |
646 | ufs_vptofh(vp, fhp) |
647 | struct vnode *vp; | |
7188ac27 | 648 | struct fid *fhp; |
7188ac27 | 649 | { |
758e3529 KM |
650 | register struct inode *ip = VTOI(vp); |
651 | register struct ufid *ufhp; | |
7188ac27 | 652 | |
758e3529 KM |
653 | ufhp = (struct ufid *)fhp; |
654 | ufhp->ufid_len = sizeof(struct ufid); | |
655 | ufhp->ufid_ino = ip->i_number; | |
656 | ufhp->ufid_gen = ip->i_gen; | |
657 | return (0); | |
7188ac27 KM |
658 | } |
659 | ||
660 | /* | |
661 | * Common code for mount and quota. | |
71e4e98b SL |
662 | * Check that the user's argument is a reasonable |
663 | * thing on which to mount, and return the device number if so. | |
664 | */ | |
7188ac27 KM |
665 | getmdev(devvpp, fname, ndp) |
666 | struct vnode **devvpp; | |
715baff1 | 667 | caddr_t fname; |
7188ac27 | 668 | register struct nameidata *ndp; |
71e4e98b | 669 | { |
7188ac27 KM |
670 | register struct vnode *vp; |
671 | int error; | |
71e4e98b | 672 | |
7188ac27 | 673 | ndp->ni_nameiop = LOOKUP | LOCKLEAF | FOLLOW; |
715baff1 KM |
674 | ndp->ni_segflg = UIO_USERSPACE; |
675 | ndp->ni_dirp = fname; | |
7188ac27 KM |
676 | if (error = namei(ndp)) { |
677 | if (error == ENOENT) | |
678 | return (ENODEV); /* needs translation */ | |
679 | return (error); | |
6d07f4cd | 680 | } |
7188ac27 KM |
681 | vp = ndp->ni_vp; |
682 | if (vp->v_type != VBLK) { | |
683 | vput(vp); | |
71e4e98b | 684 | return (ENOTBLK); |
e95cdf5c | 685 | } |
e547d435 KM |
686 | if (major(vp->v_rdev) >= nblkdev) { |
687 | vput(vp); | |
71e4e98b | 688 | return (ENXIO); |
e547d435 | 689 | } |
7188ac27 KM |
690 | iunlock(VTOI(vp)); |
691 | *devvpp = vp; | |
71e4e98b SL |
692 | return (0); |
693 | } |