1 /* 2 * Copyright (c) 1991 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)ufs_vfsops.c 7.58 (Berkeley) 11/05/91 8 */ 9 10 #include <sys/param.h> 11 #include <sys/mount.h> 12 #include <sys/proc.h> 13 #include <sys/buf.h> 14 #include <sys/vnode.h> 15 #include <sys/specdev.h> 16 17 #include <ufs/ufs/quota.h> 18 #include <ufs/ufs/inode.h> 19 #include <ufs/ufs/ufsmount.h> 20 #include <ufs/ufs/ufs_extern.h> 21 22 /* 23 * Flag to permit forcible unmounting. 24 */ 25 int doforce = 1; 26 27 /* 28 * Make a filesystem operational. 29 * Nothing to do at the moment. 30 */ 31 /* ARGSUSED */ 32 int 33 ufs_start(mp, flags, p) 34 struct mount *mp; 35 int flags; 36 struct proc *p; 37 { 38 39 return (0); 40 } 41 42 /* 43 * Check to see if a filesystem is mounted on a block device. 44 */ 45 int 46 ufs_mountedon(vp) 47 register struct vnode *vp; 48 { 49 register struct vnode *vq; 50 51 if (vp->v_specflags & SI_MOUNTEDON) 52 return (EBUSY); 53 if (vp->v_flag & VALIASED) { 54 for (vq = *vp->v_hashchain; vq; vq = vq->v_specnext) { 55 if (vq->v_rdev != vp->v_rdev || 56 vq->v_type != vp->v_type) 57 continue; 58 if (vq->v_specflags & SI_MOUNTEDON) 59 return (EBUSY); 60 } 61 } 62 return (0); 63 } 64 65 /* 66 * Do operations associated with quotas 67 */ 68 int 69 ufs_quotactl(mp, cmds, uid, arg, p) 70 struct mount *mp; 71 int cmds; 72 u_int uid; 73 caddr_t arg; 74 struct proc *p; 75 { 76 int cmd, type, error; 77 78 #ifndef QUOTA 79 return (EOPNOTSUPP); 80 #else 81 if (uid == -1) 82 uid = p->p_cred->p_ruid; 83 cmd = cmds >> SUBCMDSHIFT; 84 85 switch (cmd) { 86 case Q_GETQUOTA: 87 case Q_SYNC: 88 if (uid == p->p_cred->p_ruid) 89 break; 90 /* fall through */ 91 default: 92 if (error = suser(p->p_ucred, &p->p_acflag)) 93 return (error); 94 } 95 96 type = cmd & SUBCMDMASK; 97 if ((u_int)type >= MAXQUOTAS) 98 return (EINVAL); 99 100 switch (cmd) { 101 102 case Q_QUOTAON: 103 return (quotaon(p, mp, type, arg)); 104 105 case Q_QUOTAOFF: 106 if (vfs_busy(mp)) 107 return (0); 108 error = quotaoff(p, mp, type); 109 vfs_unbusy(mp); 110 return (error); 111 112 case Q_SETQUOTA: 113 return (setquota(mp, uid, type, arg)); 114 115 case Q_SETUSE: 116 return (setuse(mp, uid, type, arg)); 117 118 case Q_GETQUOTA: 119 return (getquota(mp, uid, type, arg)); 120 121 case Q_SYNC: 122 if (vfs_busy(mp)) 123 return (0); 124 error = qsync(mp); 125 vfs_unbusy(mp); 126 return (error); 127 128 default: 129 return (EINVAL); 130 } 131 /* NOTREACHED */ 132 #endif 133 } 134 135 int syncprt = 0; 136 137 /* 138 * Print out statistics on the current allocation of the buffer pool. 139 * Can be enabled to print out on every ``sync'' by setting "syncprt" 140 * above. 141 */ 142 void 143 ufs_bufstats() 144 { 145 int s, i, j, count; 146 register struct buf *bp, *dp; 147 int counts[MAXBSIZE/CLBYTES+1]; 148 static char *bname[BQUEUES] = { "LOCKED", "LRU", "AGE", "EMPTY" }; 149 150 for (bp = bfreelist, i = 0; bp < &bfreelist[BQUEUES]; bp++, i++) { 151 count = 0; 152 for (j = 0; j <= MAXBSIZE/CLBYTES; j++) 153 counts[j] = 0; 154 s = splbio(); 155 for (dp = bp->av_forw; dp != bp; dp = dp->av_forw) { 156 counts[dp->b_bufsize/CLBYTES]++; 157 count++; 158 } 159 splx(s); 160 printf("%s: total-%d", bname[i], count); 161 for (j = 0; j <= MAXBSIZE/CLBYTES; j++) 162 if (counts[j] != 0) 163 printf(", %d-%d", j * CLBYTES, counts[j]); 164 printf("\n"); 165 } 166 } 167