1996-12-12 03:43:28 +03:00
|
|
|
/* $NetBSD: quot.c,v 1.10 1996/12/12 00:43:28 mycroft Exp $ */
|
1996-05-24 16:51:23 +04:00
|
|
|
|
1994-02-10 20:58:38 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1991, 1994 Wolfgang Solfrank.
|
|
|
|
* Copyright (C) 1991, 1994 TooLs GmbH.
|
|
|
|
* 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 TooLs GmbH.
|
|
|
|
* 4. The name of TooLs GmbH may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
|
|
|
|
*/
|
1994-02-11 03:23:34 +03:00
|
|
|
|
|
|
|
#ifndef lint
|
1996-12-12 03:43:28 +03:00
|
|
|
static char rcsid[] = "$NetBSD: quot.c,v 1.10 1996/12/12 00:43:28 mycroft Exp $";
|
1994-02-11 03:23:34 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1994-02-10 20:58:38 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
1994-04-25 22:17:04 +04:00
|
|
|
#include <sys/time.h>
|
1994-06-14 00:50:48 +04:00
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
#include <ufs/ufs/quota.h>
|
|
|
|
#include <ufs/ufs/inode.h>
|
1994-02-10 20:58:38 +03:00
|
|
|
|
1994-04-25 22:17:04 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <pwd.h>
|
1996-05-24 12:52:41 +04:00
|
|
|
#include <unistd.h>
|
1994-04-25 22:17:04 +04:00
|
|
|
|
1994-02-10 20:58:38 +03:00
|
|
|
/* some flags of what to do: */
|
|
|
|
static char estimate;
|
|
|
|
static char count;
|
|
|
|
static char unused;
|
1996-05-24 16:51:23 +04:00
|
|
|
static void (*func)();
|
1994-02-10 20:58:38 +03:00
|
|
|
static long blocksize;
|
|
|
|
static char *header;
|
|
|
|
static int headerlen;
|
|
|
|
|
1994-02-11 03:23:34 +03:00
|
|
|
/*
|
|
|
|
* Original BSD quot doesn't round to number of frags/blocks,
|
|
|
|
* doesn't account for indirection blocks and gets it totally
|
|
|
|
* wrong if the size is a multiple of the blocksize.
|
1996-05-24 16:51:23 +04:00
|
|
|
* The new code always counts the number of DEV_BSIZE byte blocks
|
1994-02-11 03:23:34 +03:00
|
|
|
* instead of the number of kilobytes and converts them to
|
|
|
|
* kByte when done (on request).
|
|
|
|
*/
|
1994-02-10 20:58:38 +03:00
|
|
|
#ifdef COMPAT
|
|
|
|
#define SIZE(n) (n)
|
|
|
|
#else
|
1996-05-24 16:51:23 +04:00
|
|
|
#define SIZE(n) howmany((n) * DEV_BSIZE, blocksize)
|
1994-02-10 20:58:38 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define INOCNT(fs) ((fs)->fs_ipg)
|
|
|
|
#define INOSZ(fs) (sizeof(struct dinode) * INOCNT(fs))
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
static struct dinode *
|
|
|
|
get_inode(fd, super, ino)
|
|
|
|
int fd;
|
1994-02-10 20:58:38 +03:00
|
|
|
struct fs *super;
|
|
|
|
ino_t ino;
|
|
|
|
{
|
|
|
|
static struct dinode *ip;
|
|
|
|
static ino_t last;
|
|
|
|
|
|
|
|
if (fd < 0) { /* flush cache */
|
|
|
|
if (ip) {
|
|
|
|
free(ip);
|
|
|
|
ip = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ip || ino < last || ino >= last + INOCNT(super)) {
|
|
|
|
if (!ip
|
|
|
|
&& !(ip = (struct dinode *)malloc(INOSZ(super)))) {
|
|
|
|
perror("allocate inodes");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
last = (ino / INOCNT(super)) * INOCNT(super);
|
1996-05-24 16:51:23 +04:00
|
|
|
if (lseek(fd,
|
1996-12-12 03:43:28 +03:00
|
|
|
(off_t)ino_to_fsba(super, last) << super->fs_fshift,
|
|
|
|
0) < 0 ||
|
|
|
|
read(fd, ip, INOSZ(super)) != INOSZ(super)) {
|
1994-02-10 20:58:38 +03:00
|
|
|
perror("read inodes");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ip + ino % INOCNT(super);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef COMPAT
|
1996-05-24 16:51:23 +04:00
|
|
|
#define actualblocks(super, ip) ((ip)->di_blocks / 2)
|
1994-02-10 20:58:38 +03:00
|
|
|
#else
|
1996-05-24 16:51:23 +04:00
|
|
|
#define actualblocks(super, ip) ((ip)->di_blocks)
|
1994-02-10 20:58:38 +03:00
|
|
|
#endif
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
static int
|
|
|
|
virtualblocks(super, ip)
|
1994-02-10 20:58:38 +03:00
|
|
|
struct fs *super;
|
|
|
|
struct dinode *ip;
|
|
|
|
{
|
|
|
|
register off_t nblk, sz;
|
|
|
|
|
|
|
|
sz = ip->di_size;
|
|
|
|
#ifdef COMPAT
|
1996-05-24 16:51:23 +04:00
|
|
|
if (lblkno(super, sz) >= NDADDR) {
|
|
|
|
nblk = blkroundup(super, sz);
|
1994-02-10 20:58:38 +03:00
|
|
|
if (sz == nblk)
|
|
|
|
nblk += super->fs_bsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sz / 1024;
|
|
|
|
#else /* COMPAT */
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
if (lblkno(super, sz) >= NDADDR) {
|
|
|
|
nblk = blkroundup(super, sz);
|
|
|
|
sz = lblkno(super, nblk);
|
|
|
|
sz = howmany(sz - NDADDR, NINDIR(super));
|
1994-02-10 20:58:38 +03:00
|
|
|
while (sz > 0) {
|
|
|
|
nblk += sz * super->fs_bsize;
|
1996-05-24 16:51:23 +04:00
|
|
|
/* One block on this level is in the inode itself */
|
|
|
|
sz = howmany(sz - 1, NINDIR(super));
|
1994-02-10 20:58:38 +03:00
|
|
|
}
|
|
|
|
} else
|
1996-05-24 16:51:23 +04:00
|
|
|
nblk = fragroundup(super, sz);
|
1994-02-10 20:58:38 +03:00
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
return nblk / DEV_BSIZE;
|
1994-02-10 20:58:38 +03:00
|
|
|
#endif /* COMPAT */
|
|
|
|
}
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
static int
|
|
|
|
isfree(ip)
|
1994-02-10 20:58:38 +03:00
|
|
|
struct dinode *ip;
|
|
|
|
{
|
|
|
|
#ifdef COMPAT
|
|
|
|
return (ip->di_mode&IFMT) == 0;
|
|
|
|
#else /* COMPAT */
|
|
|
|
switch (ip->di_mode&IFMT) {
|
|
|
|
case IFIFO:
|
|
|
|
case IFLNK: /* should check FASTSYMLINK? */
|
|
|
|
case IFDIR:
|
|
|
|
case IFREG:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct user {
|
|
|
|
uid_t uid;
|
|
|
|
char *name;
|
|
|
|
daddr_t space;
|
|
|
|
long count;
|
|
|
|
daddr_t spc30;
|
|
|
|
daddr_t spc60;
|
|
|
|
daddr_t spc90;
|
|
|
|
} *users;
|
|
|
|
static int nusers;
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
static void
|
|
|
|
inituser()
|
1994-02-10 20:58:38 +03:00
|
|
|
{
|
|
|
|
register i;
|
|
|
|
register struct user *usr;
|
|
|
|
|
|
|
|
if (!nusers) {
|
|
|
|
nusers = 8;
|
1994-02-11 03:23:34 +03:00
|
|
|
if (!(users =
|
1996-05-24 16:51:23 +04:00
|
|
|
(struct user *)calloc(nusers, sizeof(struct user)))) {
|
1994-02-10 20:58:38 +03:00
|
|
|
perror("allocate users");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (usr = users, i = nusers; --i >= 0; usr++) {
|
|
|
|
usr->space = usr->spc30 = usr->spc60 = usr->spc90 = 0;
|
|
|
|
usr->count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
static void
|
|
|
|
usrrehash()
|
1994-02-10 20:58:38 +03:00
|
|
|
{
|
|
|
|
register i;
|
|
|
|
register struct user *usr, *usrn;
|
|
|
|
struct user *svusr;
|
|
|
|
|
|
|
|
svusr = users;
|
|
|
|
nusers <<= 1;
|
1996-05-24 16:51:23 +04:00
|
|
|
if (!(users = (struct user *)calloc(nusers, sizeof(struct user)))) {
|
1994-02-10 20:58:38 +03:00
|
|
|
perror("allocate users");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
for (usr = svusr, i = nusers >> 1; --i >= 0; usr++) {
|
1996-05-24 16:51:23 +04:00
|
|
|
for (usrn = users + (usr->uid&(nusers - 1));
|
|
|
|
usrn->name;
|
|
|
|
usrn--) {
|
1994-02-10 20:58:38 +03:00
|
|
|
if (usrn <= users)
|
|
|
|
usrn = users + nusers;
|
|
|
|
}
|
|
|
|
*usrn = *usr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
static struct user *
|
|
|
|
user(uid)
|
1994-02-10 20:58:38 +03:00
|
|
|
uid_t uid;
|
|
|
|
{
|
|
|
|
register struct user *usr;
|
|
|
|
register i;
|
|
|
|
struct passwd *pwd;
|
|
|
|
|
|
|
|
while (1) {
|
1996-05-24 16:51:23 +04:00
|
|
|
for (usr = users + (uid&(nusers - 1)), i = nusers;
|
|
|
|
--i >= 0;
|
|
|
|
usr--) {
|
1994-02-10 20:58:38 +03:00
|
|
|
if (!usr->name) {
|
|
|
|
usr->uid = uid;
|
|
|
|
|
|
|
|
if (!(pwd = getpwuid(uid))) {
|
|
|
|
if (usr->name = (char *)malloc(7))
|
1996-05-24 16:51:23 +04:00
|
|
|
sprintf(usr->name, "#%d", uid);
|
1994-02-10 20:58:38 +03:00
|
|
|
} else {
|
1994-02-11 03:23:34 +03:00
|
|
|
if (usr->name = (char *)
|
|
|
|
malloc(strlen(pwd->pw_name) + 1))
|
1996-05-24 16:51:23 +04:00
|
|
|
strcpy(usr->name, pwd->pw_name);
|
1994-02-10 20:58:38 +03:00
|
|
|
}
|
|
|
|
if (!usr->name) {
|
|
|
|
perror("allocate users");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return usr;
|
|
|
|
} else if (usr->uid == uid)
|
|
|
|
return usr;
|
|
|
|
|
|
|
|
if (usr <= users)
|
|
|
|
usr = users + nusers;
|
|
|
|
}
|
|
|
|
usrrehash();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
static int
|
|
|
|
cmpusers(u1, u2)
|
1994-02-10 20:58:38 +03:00
|
|
|
struct user *u1, *u2;
|
|
|
|
{
|
|
|
|
return u2->space - u1->space;
|
|
|
|
}
|
1994-02-11 03:23:34 +03:00
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
#define sortusers(users) (qsort((users), nusers, sizeof(struct user), \
|
|
|
|
cmpusers))
|
1994-02-10 20:58:38 +03:00
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
static void
|
|
|
|
uses(uid, blks, act)
|
1994-02-10 20:58:38 +03:00
|
|
|
uid_t uid;
|
|
|
|
daddr_t blks;
|
|
|
|
time_t act;
|
|
|
|
{
|
|
|
|
static time_t today;
|
|
|
|
register struct user *usr;
|
|
|
|
|
|
|
|
if (!today)
|
|
|
|
time(&today);
|
|
|
|
|
|
|
|
usr = user(uid);
|
|
|
|
usr->count++;
|
|
|
|
usr->space += blks;
|
|
|
|
|
|
|
|
if (today - act > 90L * 24L * 60L * 60L)
|
|
|
|
usr->spc90 += blks;
|
|
|
|
if (today - act > 60L * 24L * 60L * 60L)
|
|
|
|
usr->spc60 += blks;
|
|
|
|
if (today - act > 30L * 24L * 60L * 60L)
|
|
|
|
usr->spc30 += blks;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef COMPAT
|
|
|
|
#define FSZCNT 500
|
|
|
|
#else
|
|
|
|
#define FSZCNT 512
|
|
|
|
#endif
|
|
|
|
struct fsizes {
|
|
|
|
struct fsizes *fsz_next;
|
|
|
|
daddr_t fsz_first, fsz_last;
|
|
|
|
ino_t fsz_count[FSZCNT];
|
|
|
|
daddr_t fsz_sz[FSZCNT];
|
|
|
|
} *fsizes;
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
static void
|
|
|
|
initfsizes()
|
1994-02-10 20:58:38 +03:00
|
|
|
{
|
|
|
|
register struct fsizes *fp;
|
|
|
|
register i;
|
|
|
|
|
|
|
|
for (fp = fsizes; fp; fp = fp->fsz_next) {
|
|
|
|
for (i = FSZCNT; --i >= 0;) {
|
|
|
|
fp->fsz_count[i] = 0;
|
|
|
|
fp->fsz_sz[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
static void
|
|
|
|
dofsizes(fd, super, name)
|
|
|
|
int fd;
|
1994-02-10 20:58:38 +03:00
|
|
|
struct fs *super;
|
|
|
|
char *name;
|
|
|
|
{
|
|
|
|
ino_t inode, maxino;
|
|
|
|
struct dinode *ip;
|
|
|
|
daddr_t sz, ksz;
|
|
|
|
struct fsizes *fp, **fsp;
|
|
|
|
register i;
|
|
|
|
|
|
|
|
maxino = super->fs_ncg * super->fs_ipg - 1;
|
|
|
|
#ifdef COMPAT
|
|
|
|
if (!(fsizes = (struct fsizes *)malloc(sizeof(struct fsizes)))) {
|
|
|
|
perror("alloc fsize structure");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif /* COMPAT */
|
|
|
|
for (inode = 0; inode < maxino; inode++) {
|
|
|
|
errno = 0;
|
1996-05-24 16:51:23 +04:00
|
|
|
if ((ip = get_inode(fd, super, inode))
|
1994-02-10 20:58:38 +03:00
|
|
|
#ifdef COMPAT
|
|
|
|
&& ((ip->di_mode&IFMT) == IFREG
|
|
|
|
|| (ip->di_mode&IFMT) == IFDIR)
|
|
|
|
#else /* COMPAT */
|
|
|
|
&& !isfree(ip)
|
|
|
|
#endif /* COMPAT */
|
|
|
|
) {
|
1996-05-24 16:51:23 +04:00
|
|
|
sz = estimate ? virtualblocks(super, ip) :
|
|
|
|
actualblocks(super, ip);
|
1994-02-10 20:58:38 +03:00
|
|
|
#ifdef COMPAT
|
|
|
|
if (sz >= FSZCNT) {
|
|
|
|
fsizes->fsz_count[FSZCNT-1]++;
|
|
|
|
fsizes->fsz_sz[FSZCNT-1] += sz;
|
|
|
|
} else {
|
|
|
|
fsizes->fsz_count[sz]++;
|
|
|
|
fsizes->fsz_sz[sz] += sz;
|
|
|
|
}
|
|
|
|
#else /* COMPAT */
|
|
|
|
ksz = SIZE(sz);
|
|
|
|
for (fsp = &fsizes; fp = *fsp; fsp = &fp->fsz_next) {
|
|
|
|
if (ksz < fp->fsz_last)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!fp || ksz < fp->fsz_first) {
|
1994-02-11 03:23:34 +03:00
|
|
|
if (!(fp = (struct fsizes *)
|
1996-05-24 16:51:23 +04:00
|
|
|
malloc(sizeof(struct fsizes)))) {
|
1994-02-10 20:58:38 +03:00
|
|
|
perror("alloc fsize structure");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fp->fsz_next = *fsp;
|
|
|
|
*fsp = fp;
|
|
|
|
fp->fsz_first = (ksz / FSZCNT) * FSZCNT;
|
|
|
|
fp->fsz_last = fp->fsz_first + FSZCNT;
|
|
|
|
for (i = FSZCNT; --i >= 0;) {
|
|
|
|
fp->fsz_count[i] = 0;
|
|
|
|
fp->fsz_sz[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fp->fsz_count[ksz % FSZCNT]++;
|
|
|
|
fp->fsz_sz[ksz % FSZCNT] += sz;
|
|
|
|
#endif /* COMPAT */
|
|
|
|
} else if (errno) {
|
|
|
|
perror(name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sz = 0;
|
|
|
|
for (fp = fsizes; fp; fp = fp->fsz_next) {
|
|
|
|
for (i = 0; i < FSZCNT; i++) {
|
|
|
|
if (fp->fsz_count[i])
|
1996-05-24 16:51:23 +04:00
|
|
|
printf("%d\t%d\t%d\n",
|
1996-12-12 03:43:28 +03:00
|
|
|
fp->fsz_first + i, fp->fsz_count[i],
|
|
|
|
SIZE(sz += fp->fsz_sz[i]));
|
1994-02-10 20:58:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
static void
|
|
|
|
douser(fd, super, name)
|
|
|
|
int fd;
|
1994-02-10 20:58:38 +03:00
|
|
|
struct fs *super;
|
|
|
|
char *name;
|
|
|
|
{
|
|
|
|
ino_t inode, maxino;
|
|
|
|
struct user *usr, *usrs;
|
|
|
|
struct dinode *ip;
|
|
|
|
register n;
|
|
|
|
|
|
|
|
maxino = super->fs_ncg * super->fs_ipg - 1;
|
|
|
|
for (inode = 0; inode < maxino; inode++) {
|
|
|
|
errno = 0;
|
1996-05-24 16:51:23 +04:00
|
|
|
if ((ip = get_inode(fd, super, inode))
|
1994-02-10 20:58:38 +03:00
|
|
|
&& !isfree(ip))
|
1996-12-12 03:43:28 +03:00
|
|
|
uses(ip->di_uid, estimate ? virtualblocks(super, ip) :
|
|
|
|
actualblocks(super, ip), ip->di_atime);
|
1994-02-10 20:58:38 +03:00
|
|
|
else if (errno) {
|
|
|
|
perror(name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(usrs = (struct user *)malloc(nusers * sizeof(struct user)))) {
|
|
|
|
perror("allocate users");
|
|
|
|
exit(1);
|
|
|
|
}
|
1996-05-24 16:51:23 +04:00
|
|
|
bcopy(users, usrs, nusers * sizeof(struct user));
|
1994-02-10 20:58:38 +03:00
|
|
|
sortusers(usrs);
|
|
|
|
for (usr = usrs, n = nusers; --n >= 0 && usr->count; usr++) {
|
1996-05-24 16:51:23 +04:00
|
|
|
printf("%5d", SIZE(usr->space));
|
1994-02-10 20:58:38 +03:00
|
|
|
if (count)
|
1996-05-24 16:51:23 +04:00
|
|
|
printf("\t%5d", usr->count);
|
|
|
|
printf("\t%-8s", usr->name);
|
1994-02-10 20:58:38 +03:00
|
|
|
if (unused)
|
|
|
|
printf("\t%5d\t%5d\t%5d",
|
1996-12-12 03:43:28 +03:00
|
|
|
SIZE(usr->spc30), SIZE(usr->spc60),
|
|
|
|
SIZE(usr->spc90));
|
1994-02-10 20:58:38 +03:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
free(usrs);
|
|
|
|
}
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
static void
|
|
|
|
donames(fd, super, name)
|
|
|
|
int fd;
|
1994-02-10 20:58:38 +03:00
|
|
|
struct fs *super;
|
|
|
|
char *name;
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
ino_t inode, inode1;
|
|
|
|
ino_t maxino;
|
|
|
|
struct dinode *ip;
|
|
|
|
|
|
|
|
maxino = super->fs_ncg * super->fs_ipg - 1;
|
|
|
|
/* first skip the name of the filesystem */
|
|
|
|
while ((c = getchar()) != EOF && (c < '0' || c > '9'))
|
|
|
|
while ((c = getchar()) != EOF && c != '\n');
|
1996-05-24 16:51:23 +04:00
|
|
|
ungetc(c, stdin);
|
1994-02-10 20:58:38 +03:00
|
|
|
inode1 = -1;
|
1996-05-24 16:51:23 +04:00
|
|
|
while (scanf("%d", &inode) == 1) {
|
1994-02-10 20:58:38 +03:00
|
|
|
if (inode < 0 || inode > maxino) {
|
1996-05-24 16:51:23 +04:00
|
|
|
#ifndef COMPAT
|
|
|
|
fprintf(stderr, "invalid inode %d\n", inode);
|
|
|
|
#endif
|
1994-02-10 20:58:38 +03:00
|
|
|
return;
|
|
|
|
}
|
1996-05-24 16:51:23 +04:00
|
|
|
#ifdef COMPAT
|
|
|
|
if (inode < inode1)
|
|
|
|
continue;
|
|
|
|
#endif
|
1994-02-10 20:58:38 +03:00
|
|
|
errno = 0;
|
1996-05-24 16:51:23 +04:00
|
|
|
if ((ip = get_inode(fd, super, inode))
|
1994-02-10 20:58:38 +03:00
|
|
|
&& !isfree(ip)) {
|
1996-05-24 16:51:23 +04:00
|
|
|
printf("%s\t", user(ip->di_uid)->name);
|
1994-02-10 20:58:38 +03:00
|
|
|
/* now skip whitespace */
|
|
|
|
while ((c = getchar()) == ' ' || c == '\t');
|
|
|
|
/* and print out the remainder of the input line */
|
|
|
|
while (c != EOF && c != '\n') {
|
|
|
|
putchar(c);
|
|
|
|
c = getchar();
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
inode1 = inode;
|
|
|
|
} else {
|
|
|
|
if (errno) {
|
|
|
|
perror(name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/* skip this line */
|
|
|
|
while ((c = getchar()) != EOF && c != '\n');
|
|
|
|
}
|
|
|
|
if (c == EOF)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
static void
|
|
|
|
usage()
|
1994-02-10 20:58:38 +03:00
|
|
|
{
|
|
|
|
#ifdef COMPAT
|
1996-05-24 16:51:23 +04:00
|
|
|
fprintf(stderr, "Usage: quot [-nfcvha] [filesystem ...]\n");
|
1994-02-10 20:58:38 +03:00
|
|
|
#else /* COMPAT */
|
1996-05-24 16:51:23 +04:00
|
|
|
fprintf(stderr, "Usage: quot [ -acfhknv ] [ filesystem ... ]\n");
|
1994-02-10 20:58:38 +03:00
|
|
|
#endif /* COMPAT */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char superblock[SBSIZE];
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
#define max(a,b) MAX((a),(b))
|
|
|
|
/*
|
|
|
|
* Sanity checks for old file systems.
|
|
|
|
* Stolen from <sys/lib/libsa/ufs.c>
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ffs_oldfscompat(fs)
|
|
|
|
struct fs *fs;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fs->fs_npsect = max(fs->fs_npsect, fs->fs_nsect); /* XXX */
|
|
|
|
fs->fs_interleave = max(fs->fs_interleave, 1); /* XXX */
|
|
|
|
if (fs->fs_postblformat == FS_42POSTBLFMT) /* XXX */
|
|
|
|
fs->fs_nrpos = 8; /* XXX */
|
|
|
|
if (fs->fs_inodefmt < FS_44INODEFMT) { /* XXX */
|
|
|
|
quad_t sizepb = fs->fs_bsize; /* XXX */
|
|
|
|
/* XXX */
|
|
|
|
fs->fs_maxfilesize = fs->fs_bsize * NDADDR - 1; /* XXX */
|
|
|
|
for (i = 0; i < NIADDR; i++) { /* XXX */
|
|
|
|
sizepb *= NINDIR(fs); /* XXX */
|
|
|
|
fs->fs_maxfilesize += sizepb; /* XXX */
|
|
|
|
} /* XXX */
|
|
|
|
fs->fs_qbmask = ~fs->fs_bmask; /* XXX */
|
|
|
|
fs->fs_qfmask = ~fs->fs_fmask; /* XXX */
|
|
|
|
} /* XXX */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
quot(name, mp)
|
1994-02-10 20:58:38 +03:00
|
|
|
char *name, *mp;
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
get_inode(-1); /* flush cache */
|
|
|
|
inituser();
|
|
|
|
initfsizes();
|
1996-05-24 16:51:23 +04:00
|
|
|
if ((fd = open(name, 0)) < 0
|
|
|
|
|| lseek(fd, SBOFF, 0) != SBOFF
|
|
|
|
|| read(fd, superblock, SBSIZE) != SBSIZE) {
|
1994-02-10 20:58:38 +03:00
|
|
|
perror(name);
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
1996-05-24 16:51:23 +04:00
|
|
|
if (((struct fs *)superblock)->fs_magic != FS_MAGIC
|
|
|
|
|| ((struct fs *)superblock)->fs_bsize > MAXBSIZE
|
|
|
|
|| ((struct fs *)superblock)->fs_bsize < sizeof(struct fs)) {
|
|
|
|
fprintf(stderr, "%s: not a BSD filesystem\n", name);
|
1994-02-10 20:58:38 +03:00
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
1996-05-24 16:51:23 +04:00
|
|
|
ffs_oldfscompat(superblock);
|
|
|
|
printf("%s:", name);
|
1994-02-10 20:58:38 +03:00
|
|
|
if (mp)
|
1996-05-24 16:51:23 +04:00
|
|
|
printf(" (%s)", mp);
|
1994-02-10 20:58:38 +03:00
|
|
|
putchar('\n');
|
1996-05-24 16:51:23 +04:00
|
|
|
(*func)(fd, superblock, name);
|
1994-02-10 20:58:38 +03:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
1996-05-24 16:51:23 +04:00
|
|
|
int
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
1994-02-10 20:58:38 +03:00
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char all = 0;
|
|
|
|
FILE *fp;
|
|
|
|
struct statfs *mp;
|
|
|
|
char dev[MNAMELEN + 1];
|
|
|
|
char *nm;
|
|
|
|
int cnt;
|
|
|
|
|
|
|
|
func = douser;
|
|
|
|
#ifndef COMPAT
|
1996-05-24 16:51:23 +04:00
|
|
|
header = getbsize(&headerlen, &blocksize);
|
1994-02-10 20:58:38 +03:00
|
|
|
#endif
|
|
|
|
while (--argc > 0 && **++argv == '-') {
|
|
|
|
while (*++*argv) {
|
|
|
|
switch (**argv) {
|
|
|
|
case 'n':
|
|
|
|
func = donames;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
func = dofsizes;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
all = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
count = 1;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
estimate = 1;
|
|
|
|
break;
|
|
|
|
#ifndef COMPAT
|
|
|
|
case 'k':
|
|
|
|
blocksize = 1024;
|
|
|
|
break;
|
|
|
|
#endif /* COMPAT */
|
|
|
|
case 'v':
|
|
|
|
unused = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (all) {
|
1996-05-24 16:51:23 +04:00
|
|
|
cnt = getmntinfo(&mp, MNT_NOWAIT);
|
1994-02-10 20:58:38 +03:00
|
|
|
for (; --cnt >= 0; mp++) {
|
1995-11-28 22:43:04 +03:00
|
|
|
if (!strncmp(mp->f_fstypename, MOUNT_FFS, MFSNAMELEN)) {
|
1996-05-24 16:51:23 +04:00
|
|
|
if (nm = strrchr(mp->f_mntfromname, '/')) {
|
|
|
|
sprintf(dev, "/dev/r%s", nm + 1);
|
1994-02-10 20:58:38 +03:00
|
|
|
nm = dev;
|
|
|
|
} else
|
|
|
|
nm = mp->f_mntfromname;
|
1996-05-24 16:51:23 +04:00
|
|
|
quot(nm, mp->f_mntonname);
|
1994-02-10 20:58:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (--argc >= 0)
|
1996-05-24 16:51:23 +04:00
|
|
|
quot(*argv++, 0);
|
1994-02-10 20:58:38 +03:00
|
|
|
return 0;
|
|
|
|
}
|