1995-11-03 15:06:04 +00: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.
|
|
|
|
*/
|
|
|
|
|
2003-05-03 21:06:42 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1995-11-03 15:06:04 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2002-05-15 08:01:31 +00:00
|
|
|
#include <sys/stdint.h>
|
1995-11-03 15:06:04 +00:00
|
|
|
#include <sys/mount.h>
|
2002-05-12 21:43:02 +00:00
|
|
|
#include <sys/disklabel.h>
|
1995-11-03 15:06:04 +00:00
|
|
|
#include <sys/time.h>
|
2002-06-21 06:18:05 +00:00
|
|
|
#include <ufs/ufs/dinode.h>
|
1995-11-03 15:06:04 +00:00
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
#include <err.h>
|
|
|
|
#include <fcntl.h>
|
2001-03-10 12:12:47 +00:00
|
|
|
#include <fstab.h>
|
1997-10-10 06:31:07 +00:00
|
|
|
#include <errno.h>
|
2000-12-09 09:35:55 +00:00
|
|
|
#include <paths.h>
|
1997-10-10 06:31:07 +00:00
|
|
|
#include <pwd.h>
|
1995-11-03 15:06:04 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1997-10-10 06:31:07 +00:00
|
|
|
#include <unistd.h>
|
1995-11-03 15:06:04 +00:00
|
|
|
|
|
|
|
/* some flags of what to do: */
|
|
|
|
static char estimate;
|
|
|
|
static char count;
|
|
|
|
static char unused;
|
2001-12-09 07:51:26 +00:00
|
|
|
static void (*func)(int, struct fs *, char *);
|
1995-11-03 15:06:04 +00:00
|
|
|
static long blocksize;
|
|
|
|
static char *header;
|
2002-12-30 18:21:47 +00:00
|
|
|
static int headerlen;
|
1995-11-03 15:06:04 +00:00
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
static union dinode *get_inode(int, struct fs *, ino_t);
|
|
|
|
static int virtualblocks(struct fs *, union dinode *);
|
|
|
|
static int isfree(struct fs *, union dinode *);
|
2001-12-09 07:51:26 +00:00
|
|
|
static void inituser(void);
|
|
|
|
static void usrrehash(void);
|
|
|
|
static struct user *user(uid_t);
|
|
|
|
static int cmpusers(const void *, const void *);
|
|
|
|
static void uses(uid_t, daddr_t, time_t);
|
|
|
|
static void initfsizes(void);
|
|
|
|
static void dofsizes(int, struct fs *, char *);
|
|
|
|
static void douser(int, struct fs *, char *);
|
|
|
|
static void donames(int, struct fs *, char *);
|
|
|
|
static void usage(void);
|
|
|
|
static void quot(char *, char *);
|
|
|
|
|
1995-11-03 15:06:04 +00: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.
|
|
|
|
* The new code always counts the number of 512 byte blocks
|
|
|
|
* instead of the number of kilobytes and converts them to
|
|
|
|
* kByte when done (on request).
|
1998-12-13 07:16:05 +00:00
|
|
|
*
|
|
|
|
* Due to the size of modern disks, we must cast intermediate
|
|
|
|
* values to 64 bits to prevent potential overflows.
|
1995-11-03 15:06:04 +00:00
|
|
|
*/
|
|
|
|
#ifdef COMPAT
|
|
|
|
#define SIZE(n) (n)
|
|
|
|
#else
|
1998-12-13 07:16:05 +00:00
|
|
|
#define SIZE(n) ((int)(((quad_t)(n) * 512 + blocksize - 1)/blocksize))
|
1995-11-03 15:06:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define INOCNT(fs) ((fs)->fs_ipg)
|
2002-06-21 06:18:05 +00:00
|
|
|
#define INOSZ(fs) \
|
|
|
|
(((fs)->fs_magic == FS_UFS1_MAGIC ? sizeof(struct ufs1_dinode) : \
|
|
|
|
sizeof(struct ufs2_dinode)) * INOCNT(fs))
|
1995-11-03 15:06:04 +00:00
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
union dinode {
|
|
|
|
struct ufs1_dinode dp1;
|
|
|
|
struct ufs2_dinode dp2;
|
|
|
|
};
|
|
|
|
#define DIP(fs, dp, field) \
|
|
|
|
(((fs)->fs_magic == FS_UFS1_MAGIC) ? \
|
|
|
|
(dp)->dp1.field : (dp)->dp2.field)
|
|
|
|
|
|
|
|
static union dinode *
|
1997-10-10 06:31:07 +00:00
|
|
|
get_inode(fd,super,ino)
|
2001-12-09 07:51:26 +00:00
|
|
|
int fd;
|
1995-11-03 15:06:04 +00:00
|
|
|
struct fs *super;
|
|
|
|
ino_t ino;
|
|
|
|
{
|
2002-06-21 06:18:05 +00:00
|
|
|
static caddr_t ipbuf;
|
2006-02-25 23:50:15 +00:00
|
|
|
static struct cg *cgp;
|
1995-11-03 15:06:04 +00:00
|
|
|
static ino_t last;
|
2006-02-25 23:50:15 +00:00
|
|
|
static int cg;
|
|
|
|
struct ufs2_dinode *di2;
|
1995-11-03 15:06:04 +00:00
|
|
|
|
|
|
|
if (fd < 0) { /* flush cache */
|
2002-06-21 06:18:05 +00:00
|
|
|
if (ipbuf) {
|
|
|
|
free(ipbuf);
|
|
|
|
ipbuf = 0;
|
2006-02-25 23:50:15 +00:00
|
|
|
if (super->fs_magic == FS_UFS2_MAGIC) {
|
|
|
|
free(cgp);
|
|
|
|
cgp = 0;
|
|
|
|
}
|
1995-11-03 15:06:04 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
if (!ipbuf || ino < last || ino >= last + INOCNT(super)) {
|
2006-02-25 23:50:15 +00:00
|
|
|
if (super->fs_magic == FS_UFS2_MAGIC &&
|
|
|
|
(!cgp || cg != ino_to_cg(super, ino))) {
|
|
|
|
cg = ino_to_cg(super, ino);
|
|
|
|
if (!cgp && !(cgp = malloc(super->fs_cgsize)))
|
|
|
|
errx(1, "allocate cg");
|
|
|
|
if (lseek(fd, (off_t)cgtod(super, cg) << super->fs_fshift, 0) < 0)
|
|
|
|
err(1, "lseek cg");
|
|
|
|
if (read(fd, cgp, super->fs_cgsize) != super->fs_cgsize)
|
|
|
|
err(1, "read cg");
|
|
|
|
if (!cg_chkmagic(cgp))
|
|
|
|
errx(1, "cg has bad magic");
|
|
|
|
}
|
2002-06-21 06:18:05 +00:00
|
|
|
if (!ipbuf
|
|
|
|
&& !(ipbuf = malloc(INOSZ(super))))
|
1997-10-10 06:31:07 +00:00
|
|
|
errx(1, "allocate inodes");
|
1995-11-03 15:06:04 +00:00
|
|
|
last = (ino / INOCNT(super)) * INOCNT(super);
|
1997-08-13 12:09:48 +00:00
|
|
|
if (lseek(fd, (off_t)ino_to_fsba(super, last) << super->fs_fshift, 0) < (off_t)0
|
2002-06-21 06:18:05 +00:00
|
|
|
|| read(fd, ipbuf, INOSZ(super)) != (ssize_t)INOSZ(super))
|
1997-10-10 06:31:07 +00:00
|
|
|
err(1, "read inodes");
|
1995-11-03 15:06:04 +00:00
|
|
|
}
|
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
if (super->fs_magic == FS_UFS1_MAGIC)
|
|
|
|
return ((union dinode *)
|
|
|
|
&((struct ufs1_dinode *)ipbuf)[ino % INOCNT(super)]);
|
2006-02-25 23:50:15 +00:00
|
|
|
di2 = &((struct ufs2_dinode *)ipbuf)[ino % INOCNT(super)];
|
|
|
|
/* If the inode is unused, it might be unallocated too, so zero it. */
|
|
|
|
if (isclr(cg_inosused(cgp), ino % super->fs_ipg))
|
|
|
|
bzero(di2, sizeof (*di2));
|
|
|
|
return ((union dinode *)di2);
|
1995-11-03 15:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef COMPAT
|
2002-06-21 06:18:05 +00:00
|
|
|
#define actualblocks(fs, dp) (DIP(fs, dp, di_blocks) / 2)
|
1995-11-03 15:06:04 +00:00
|
|
|
#else
|
2002-06-21 06:18:05 +00:00
|
|
|
#define actualblocks(fs, dp) DIP(fs, dp, di_blocks)
|
1995-11-03 15:06:04 +00:00
|
|
|
#endif
|
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
static int virtualblocks(super, dp)
|
1995-11-03 15:06:04 +00:00
|
|
|
struct fs *super;
|
2002-06-21 06:18:05 +00:00
|
|
|
union dinode *dp;
|
1995-11-03 15:06:04 +00:00
|
|
|
{
|
|
|
|
register off_t nblk, sz;
|
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
sz = DIP(super, dp, di_size);
|
1995-11-03 15:06:04 +00:00
|
|
|
#ifdef COMPAT
|
|
|
|
if (lblkno(super,sz) >= NDADDR) {
|
|
|
|
nblk = blkroundup(super,sz);
|
|
|
|
if (sz == nblk)
|
|
|
|
nblk += super->fs_bsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sz / 1024;
|
|
|
|
|
|
|
|
#else /* COMPAT */
|
|
|
|
|
|
|
|
if (lblkno(super,sz) >= NDADDR) {
|
|
|
|
nblk = blkroundup(super,sz);
|
|
|
|
sz = lblkno(super,nblk);
|
|
|
|
sz = (sz - NDADDR + NINDIR(super) - 1) / NINDIR(super);
|
|
|
|
while (sz > 0) {
|
|
|
|
nblk += sz * super->fs_bsize;
|
|
|
|
/* sz - 1 rounded up */
|
|
|
|
sz = (sz - 1 + NINDIR(super) - 1) / NINDIR(super);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
nblk = fragroundup(super,sz);
|
|
|
|
|
|
|
|
return nblk / 512;
|
|
|
|
#endif /* COMPAT */
|
|
|
|
}
|
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
static int
|
2002-06-21 06:18:05 +00:00
|
|
|
isfree(super, dp)
|
|
|
|
struct fs *super;
|
|
|
|
union dinode *dp;
|
1995-11-03 15:06:04 +00:00
|
|
|
{
|
|
|
|
#ifdef COMPAT
|
2002-06-21 06:18:05 +00:00
|
|
|
return (DIP(super, dp, di_mode) & IFMT) == 0;
|
1995-11-03 15:06:04 +00:00
|
|
|
#else /* COMPAT */
|
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
switch (DIP(super, dp, di_mode) & IFMT) {
|
1995-11-03 15:06:04 +00:00
|
|
|
case IFIFO:
|
|
|
|
case IFLNK: /* should check FASTSYMLINK? */
|
|
|
|
case IFDIR:
|
|
|
|
case IFREG:
|
|
|
|
return 0;
|
2006-02-25 23:50:15 +00:00
|
|
|
case IFCHR:
|
|
|
|
case IFBLK:
|
|
|
|
case IFSOCK:
|
|
|
|
case IFWHT:
|
|
|
|
case 0:
|
1995-11-03 15:06:04 +00:00
|
|
|
return 1;
|
2006-02-25 23:50:15 +00:00
|
|
|
default:
|
|
|
|
errx(1, "unknown IFMT 0%o", DIP(super, dp, di_mode) & IFMT);
|
1995-11-03 15:06:04 +00:00
|
|
|
}
|
|
|
|
#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;
|
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
static void
|
|
|
|
inituser()
|
1995-11-03 15:06:04 +00:00
|
|
|
{
|
2001-12-09 07:51:26 +00:00
|
|
|
register int i;
|
1995-11-03 15:06:04 +00:00
|
|
|
register struct user *usr;
|
|
|
|
|
|
|
|
if (!nusers) {
|
|
|
|
nusers = 8;
|
|
|
|
if (!(users =
|
1997-10-10 06:31:07 +00:00
|
|
|
(struct user *)calloc(nusers,sizeof(struct user))))
|
|
|
|
errx(1, "allocate users");
|
1995-11-03 15:06:04 +00:00
|
|
|
} else {
|
|
|
|
for (usr = users, i = nusers; --i >= 0; usr++) {
|
|
|
|
usr->space = usr->spc30 = usr->spc60 = usr->spc90 = 0;
|
|
|
|
usr->count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
static void
|
|
|
|
usrrehash()
|
1995-11-03 15:06:04 +00:00
|
|
|
{
|
2001-12-09 07:51:26 +00:00
|
|
|
register int i;
|
1995-11-03 15:06:04 +00:00
|
|
|
register struct user *usr, *usrn;
|
|
|
|
struct user *svusr;
|
|
|
|
|
|
|
|
svusr = users;
|
|
|
|
nusers <<= 1;
|
1997-10-10 06:31:07 +00:00
|
|
|
if (!(users = (struct user *)calloc(nusers,sizeof(struct user))))
|
|
|
|
errx(1, "allocate users");
|
1995-11-03 15:06:04 +00:00
|
|
|
for (usr = svusr, i = nusers >> 1; --i >= 0; usr++) {
|
|
|
|
for (usrn = users + (usr->uid&(nusers - 1)); usrn->name;
|
|
|
|
usrn--) {
|
|
|
|
if (usrn <= users)
|
|
|
|
usrn = users + nusers;
|
|
|
|
}
|
|
|
|
*usrn = *usr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
static struct user *
|
|
|
|
user(uid)
|
1995-11-03 15:06:04 +00:00
|
|
|
uid_t uid;
|
|
|
|
{
|
|
|
|
register struct user *usr;
|
2001-12-09 07:51:26 +00:00
|
|
|
register int i;
|
1995-11-03 15:06:04 +00:00
|
|
|
struct passwd *pwd;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
for (usr = users + (uid&(nusers - 1)), i = nusers; --i >= 0;
|
|
|
|
usr--) {
|
|
|
|
if (!usr->name) {
|
|
|
|
usr->uid = uid;
|
|
|
|
|
|
|
|
if (!(pwd = getpwuid(uid))) {
|
1997-10-10 06:31:07 +00:00
|
|
|
if ((usr->name = (char *)malloc(7)))
|
1995-11-03 15:06:04 +00:00
|
|
|
sprintf(usr->name,"#%d",uid);
|
|
|
|
} else {
|
1997-10-10 06:31:07 +00:00
|
|
|
if ((usr->name = (char *)
|
|
|
|
malloc(strlen(pwd->pw_name) + 1)))
|
1995-11-03 15:06:04 +00:00
|
|
|
strcpy(usr->name,pwd->pw_name);
|
|
|
|
}
|
1997-10-10 06:31:07 +00:00
|
|
|
if (!usr->name)
|
|
|
|
errx(1, "allocate users");
|
1995-11-03 15:06:04 +00:00
|
|
|
|
|
|
|
return usr;
|
|
|
|
|
|
|
|
} else if (usr->uid == uid)
|
|
|
|
return usr;
|
|
|
|
|
|
|
|
if (usr <= users)
|
|
|
|
usr = users + nusers;
|
|
|
|
}
|
|
|
|
usrrehash();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
static int
|
2001-12-09 07:51:26 +00:00
|
|
|
cmpusers(v1,v2)
|
|
|
|
const void *v1, *v2;
|
1995-11-03 15:06:04 +00:00
|
|
|
{
|
2001-12-09 07:51:26 +00:00
|
|
|
const struct user *u1, *u2;
|
|
|
|
u1 = (const struct user *)v1;
|
|
|
|
u2 = (const struct user *)v2;
|
|
|
|
|
1995-11-03 15:06:04 +00:00
|
|
|
return u2->space - u1->space;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define sortusers(users) (qsort((users),nusers,sizeof(struct user), \
|
|
|
|
cmpusers))
|
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
static void
|
|
|
|
uses(uid,blks,act)
|
1995-11-03 15:06:04 +00: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;
|
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
static void
|
|
|
|
initfsizes()
|
1995-11-03 15:06:04 +00:00
|
|
|
{
|
|
|
|
register struct fsizes *fp;
|
2001-12-09 07:51:26 +00:00
|
|
|
register int i;
|
1995-11-03 15:06:04 +00:00
|
|
|
|
|
|
|
for (fp = fsizes; fp; fp = fp->fsz_next) {
|
|
|
|
for (i = FSZCNT; --i >= 0;) {
|
|
|
|
fp->fsz_count[i] = 0;
|
|
|
|
fp->fsz_sz[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
static void
|
2002-06-21 06:18:05 +00:00
|
|
|
dofsizes(fd, super, name)
|
2001-12-09 07:51:26 +00:00
|
|
|
int fd;
|
1995-11-03 15:06:04 +00:00
|
|
|
struct fs *super;
|
|
|
|
char *name;
|
|
|
|
{
|
|
|
|
ino_t inode, maxino;
|
2002-06-21 06:18:05 +00:00
|
|
|
union dinode *dp;
|
1995-11-03 15:06:04 +00:00
|
|
|
daddr_t sz, ksz;
|
|
|
|
struct fsizes *fp, **fsp;
|
2001-12-09 07:51:26 +00:00
|
|
|
register int i;
|
1995-11-03 15:06:04 +00:00
|
|
|
|
|
|
|
maxino = super->fs_ncg * super->fs_ipg - 1;
|
|
|
|
#ifdef COMPAT
|
1997-10-10 06:31:07 +00:00
|
|
|
if (!(fsizes = (struct fsizes *)malloc(sizeof(struct fsizes))))
|
1999-11-27 17:05:08 +00:00
|
|
|
errx(1, "allocate fsize structure");
|
1995-11-03 15:06:04 +00:00
|
|
|
#endif /* COMPAT */
|
|
|
|
for (inode = 0; inode < maxino; inode++) {
|
|
|
|
errno = 0;
|
2002-06-21 06:18:05 +00:00
|
|
|
if ((dp = get_inode(fd,super,inode))
|
1995-11-03 15:06:04 +00:00
|
|
|
#ifdef COMPAT
|
2002-06-21 06:18:05 +00:00
|
|
|
&& ((DIP(super, dp, di_mode) & IFMT) == IFREG
|
|
|
|
|| (DIP(super, dp, di_mode) & IFMT) == IFDIR)
|
1995-11-03 15:06:04 +00:00
|
|
|
#else /* COMPAT */
|
2002-06-21 06:18:05 +00:00
|
|
|
&& !isfree(super, dp)
|
1995-11-03 15:06:04 +00:00
|
|
|
#endif /* COMPAT */
|
|
|
|
) {
|
2002-06-21 06:18:05 +00:00
|
|
|
sz = estimate ? virtualblocks(super, dp) :
|
|
|
|
actualblocks(super, dp);
|
1995-11-03 15:06:04 +00: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);
|
1997-10-10 06:31:07 +00:00
|
|
|
for (fsp = &fsizes; (fp = *fsp); fsp = &fp->fsz_next) {
|
1995-11-03 15:06:04 +00:00
|
|
|
if (ksz < fp->fsz_last)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!fp || ksz < fp->fsz_first) {
|
|
|
|
if (!(fp = (struct fsizes *)
|
1997-10-10 06:31:07 +00:00
|
|
|
malloc(sizeof(struct fsizes))))
|
1999-11-27 17:05:08 +00:00
|
|
|
errx(1, "allocate fsize structure");
|
1995-11-03 15:06:04 +00:00
|
|
|
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) {
|
1997-10-10 06:31:07 +00:00
|
|
|
err(1, "%s", name);
|
1995-11-03 15:06:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sz = 0;
|
|
|
|
for (fp = fsizes; fp; fp = fp->fsz_next) {
|
|
|
|
for (i = 0; i < FSZCNT; i++) {
|
|
|
|
if (fp->fsz_count[i])
|
2002-05-15 08:01:31 +00:00
|
|
|
printf("%jd\t%jd\t%d\n",
|
|
|
|
(intmax_t)(fp->fsz_first + i),
|
|
|
|
(intmax_t)fp->fsz_count[i],
|
1995-11-03 15:06:04 +00:00
|
|
|
SIZE(sz += fp->fsz_sz[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
static void
|
2002-06-21 06:18:05 +00:00
|
|
|
douser(fd, super, name)
|
2001-12-09 07:51:26 +00:00
|
|
|
int fd;
|
1995-11-03 15:06:04 +00:00
|
|
|
struct fs *super;
|
|
|
|
char *name;
|
|
|
|
{
|
|
|
|
ino_t inode, maxino;
|
|
|
|
struct user *usr, *usrs;
|
2002-06-21 06:18:05 +00:00
|
|
|
union dinode *dp;
|
2001-12-09 07:51:26 +00:00
|
|
|
register int n;
|
1995-11-03 15:06:04 +00:00
|
|
|
|
|
|
|
maxino = super->fs_ncg * super->fs_ipg - 1;
|
|
|
|
for (inode = 0; inode < maxino; inode++) {
|
|
|
|
errno = 0;
|
2002-06-21 06:18:05 +00:00
|
|
|
if ((dp = get_inode(fd,super,inode))
|
|
|
|
&& !isfree(super, dp))
|
|
|
|
uses(DIP(super, dp, di_uid),
|
|
|
|
estimate ? virtualblocks(super, dp) :
|
|
|
|
actualblocks(super, dp),
|
|
|
|
DIP(super, dp, di_atime));
|
1995-11-03 15:06:04 +00:00
|
|
|
else if (errno) {
|
1997-10-10 06:31:07 +00:00
|
|
|
err(1, "%s", name);
|
1995-11-03 15:06:04 +00:00
|
|
|
}
|
|
|
|
}
|
1997-10-10 06:31:07 +00:00
|
|
|
if (!(usrs = (struct user *)malloc(nusers * sizeof(struct user))))
|
|
|
|
errx(1, "allocate users");
|
1995-11-03 15:06:04 +00:00
|
|
|
bcopy(users,usrs,nusers * sizeof(struct user));
|
|
|
|
sortusers(usrs);
|
|
|
|
for (usr = usrs, n = nusers; --n >= 0 && usr->count; usr++) {
|
|
|
|
printf("%5d",SIZE(usr->space));
|
|
|
|
if (count)
|
2001-12-09 07:51:26 +00:00
|
|
|
printf("\t%5ld",usr->count);
|
1995-11-03 15:06:04 +00:00
|
|
|
printf("\t%-8s",usr->name);
|
|
|
|
if (unused)
|
|
|
|
printf("\t%5d\t%5d\t%5d",
|
|
|
|
SIZE(usr->spc30),
|
|
|
|
SIZE(usr->spc60),
|
|
|
|
SIZE(usr->spc90));
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
free(usrs);
|
|
|
|
}
|
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
static void
|
2002-06-21 06:18:05 +00:00
|
|
|
donames(fd, super, name)
|
2001-12-09 07:51:26 +00:00
|
|
|
int fd;
|
1995-11-03 15:06:04 +00:00
|
|
|
struct fs *super;
|
|
|
|
char *name;
|
|
|
|
{
|
|
|
|
int c;
|
2005-04-09 14:59:10 +00:00
|
|
|
ino_t inode;
|
1995-11-03 15:06:04 +00:00
|
|
|
ino_t maxino;
|
2002-06-21 06:18:05 +00:00
|
|
|
union dinode *dp;
|
1995-11-03 15:06:04 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
ungetc(c,stdin);
|
2001-12-09 07:51:26 +00:00
|
|
|
while (scanf("%u",&inode) == 1) {
|
|
|
|
if (inode > maxino) {
|
1997-10-10 06:31:07 +00:00
|
|
|
warnx("illegal inode %d",inode);
|
1995-11-03 15:06:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
errno = 0;
|
2002-06-21 06:18:05 +00:00
|
|
|
if ((dp = get_inode(fd,super,inode))
|
|
|
|
&& !isfree(super, dp)) {
|
|
|
|
printf("%s\t",user(DIP(super, dp, di_uid))->name);
|
1995-11-03 15:06:04 +00: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');
|
|
|
|
} else {
|
|
|
|
if (errno) {
|
1997-10-10 06:31:07 +00:00
|
|
|
err(1, "%s", name);
|
1995-11-03 15:06:04 +00:00
|
|
|
}
|
|
|
|
/* skip this line */
|
|
|
|
while ((c = getchar()) != EOF && c != '\n');
|
|
|
|
}
|
|
|
|
if (c == EOF)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
static void
|
|
|
|
usage()
|
1995-11-03 15:06:04 +00:00
|
|
|
{
|
|
|
|
#ifdef COMPAT
|
1997-10-10 06:31:07 +00:00
|
|
|
fprintf(stderr,"usage: quot [-nfcvha] [filesystem ...]\n");
|
1995-11-03 15:06:04 +00:00
|
|
|
#else /* COMPAT */
|
1999-11-27 17:05:08 +00:00
|
|
|
fprintf(stderr,"usage: quot [-acfhknv] [filesystem ...]\n");
|
1995-11-03 15:06:04 +00:00
|
|
|
#endif /* COMPAT */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
/*
|
|
|
|
* Possible superblock locations ordered from most to least likely.
|
|
|
|
*/
|
|
|
|
static int sblock_try[] = SBLOCKSEARCH;
|
|
|
|
static char superblock[SBLOCKSIZE];
|
1995-11-03 15:06:04 +00:00
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
void
|
1995-11-03 15:06:04 +00:00
|
|
|
quot(name,mp)
|
|
|
|
char *name, *mp;
|
|
|
|
{
|
2002-06-21 06:18:05 +00:00
|
|
|
int i, fd;
|
|
|
|
struct fs *fs;
|
1995-11-03 15:06:04 +00:00
|
|
|
|
2001-12-09 07:51:26 +00:00
|
|
|
get_inode(-1, NULL, 0); /* flush cache */
|
1995-11-03 15:06:04 +00:00
|
|
|
inituser();
|
|
|
|
initfsizes();
|
2002-06-21 06:18:05 +00:00
|
|
|
if ((fd = open(name,0)) < 0) {
|
1997-10-10 06:31:07 +00:00
|
|
|
warn("%s", name);
|
1995-11-03 15:06:04 +00:00
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
2002-06-21 06:18:05 +00:00
|
|
|
for (i = 0; sblock_try[i] != -1; i++) {
|
|
|
|
if (lseek(fd, sblock_try[i], 0) != sblock_try[i]) {
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (read(fd, superblock, SBLOCKSIZE) != SBLOCKSIZE) {
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fs = (struct fs *)superblock;
|
|
|
|
if ((fs->fs_magic == FS_UFS1_MAGIC ||
|
|
|
|
(fs->fs_magic == FS_UFS2_MAGIC &&
|
2003-04-25 10:07:50 +00:00
|
|
|
fs->fs_sblockloc == sblock_try[i])) &&
|
2002-06-21 06:18:05 +00:00
|
|
|
fs->fs_bsize <= MAXBSIZE &&
|
|
|
|
fs->fs_bsize >= sizeof(struct fs))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (sblock_try[i] == -1) {
|
1997-10-10 06:31:07 +00:00
|
|
|
warnx("%s: not a BSD filesystem",name);
|
1995-11-03 15:06:04 +00:00
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("%s:",name);
|
|
|
|
if (mp)
|
|
|
|
printf(" (%s)",mp);
|
|
|
|
putchar('\n');
|
2002-06-21 06:18:05 +00:00
|
|
|
(*func)(fd, fs, name);
|
1995-11-03 15:06:04 +00:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
1997-10-10 06:31:07 +00:00
|
|
|
int
|
|
|
|
main(argc,argv)
|
2001-12-09 07:51:26 +00:00
|
|
|
int argc;
|
1995-11-03 15:06:04 +00:00
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
char all = 0;
|
|
|
|
struct statfs *mp;
|
2001-03-10 12:12:47 +00:00
|
|
|
struct fstab *fs;
|
1995-11-03 15:06:04 +00:00
|
|
|
char dev[MNAMELEN + 1];
|
|
|
|
char *nm;
|
|
|
|
int cnt;
|
|
|
|
|
|
|
|
func = douser;
|
|
|
|
#ifndef COMPAT
|
|
|
|
header = getbsize(&headerlen,&blocksize);
|
|
|
|
#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) {
|
|
|
|
cnt = getmntinfo(&mp,MNT_NOWAIT);
|
|
|
|
for (; --cnt >= 0; mp++) {
|
1998-01-17 16:45:03 +00:00
|
|
|
if (!strncmp(mp->f_fstypename, "ufs", MFSNAMELEN)) {
|
1997-10-10 06:31:07 +00:00
|
|
|
if ((nm = strrchr(mp->f_mntfromname,'/'))) {
|
2000-12-09 09:35:55 +00:00
|
|
|
sprintf(dev,"%s%s",_PATH_DEV,nm + 1);
|
1995-11-03 15:06:04 +00:00
|
|
|
nm = dev;
|
|
|
|
} else
|
|
|
|
nm = mp->f_mntfromname;
|
|
|
|
quot(nm,mp->f_mntonname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-03-10 12:12:47 +00:00
|
|
|
while (--argc >= 0) {
|
|
|
|
if ((fs = getfsfile(*argv)) != NULL)
|
|
|
|
quot(fs->fs_spec, 0);
|
|
|
|
else
|
|
|
|
quot(*argv,0);
|
|
|
|
argv++;
|
|
|
|
}
|
1995-11-03 15:06:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|