quot.c revision d1a180b0452ce86577a43be3245d2eacdeec1a34
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* quot
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <pwd.h>
#include <unistd.h>
#include <fcntl.h>
static union {
} sb_un;
struct du {
long blocks;
long blocks30;
long blocks60;
long blocks90;
long nfiles;
char *u_name;
};
#define UHASH 8209
static int ndu;
#define TSIZE 2048
static int nflg;
static int fflg;
static int cflg;
static int vflg;
static int hflg;
static int aflg;
static long now;
static unsigned ino;
static void usage(void);
static void quotall(void);
static void bread(int, diskaddr_t, char *, int);
static void report(void);
static int getdev(char **);
static int check(char *, char *);
static void sortprep(void);
static void cleanup(void);
static void
usage()
{
}
int
{
int opt;
int i;
if (argc == 1) {
"ufs Usage: quot [-nfcvha] [filesystem ...]\n");
return (32);
}
switch (opt) {
case 'n':
nflg++;
break;
case 'f':
fflg++;
break;
case 'c':
cflg++;
break;
case 'v':
vflg++;
break;
case 'h':
hflg++;
break;
case 'a':
aflg++;
break;
case 'V': /* Print command line */
{
char *opt_text;
int opt_count;
opt_count++) {
if (opt_text)
opt_text);
}
}
break;
case '?':
usage();
return (32);
}
}
if (aflg) {
quotall();
}
report();
cleanup();
}
}
return (0);
}
static void
quotall()
{
char *cp;
extern char *getfullrawname();
exit(32);
}
continue;
continue;
if (*cp == '\0')
continue;
report();
cleanup();
}
}
}
static int
{
int i, j;
int c, fd;
/*
* Initialize tables between checks;
* because of the qsort done in report()
* the hash tables must be rebuilt each time.
*/
for (i = 0; i < TSIZE; i++)
sizes[i] = 0;
ndu = 0;
if (fd < 0) {
exit(32);
}
exit(32);
}
continue;
break;
}
}
}
(void) printf(":\n");
sync();
if (nflg) {
else while (c != '\n' && c != EOF)
c = getchar();
}
"not enough memory to allocate tables\n");
return (1);
}
ino = 0;
(char *)itab,
if (ino < UFSROOTINO)
continue;
}
}
return (0);
}
static void
{
int n;
static int fino;
}
return;
/*
* By default, take block count in inode. Otherwise (-h),
* take the size field and estimate the blocks allocated.
* The latter does not account for holes in files.
*/
if (!hflg)
else {
/*
* Must cast to offset_t because for a large file,
* frags multiplied by sblock.fs_fsize will not fit in a long.
* However, when divided by 1024, the end result will fit in
* the 32 bit size variable (40 bit UFS).
*/
}
if (cflg) {
return;
}
return;
}
return;
while (nflg) {
if (fino == 0)
return;
return;
;
fino = 0;
continue;
}
else
;
(void) putchar(n);
while (n != EOF && n != '\n') {
n = getchar();
(void) putchar(n);
}
fino = 0;
break;
}
}
static void
{
int ret;
perror("llseek");
exit(32);
}
perror("read");
exit(32);
}
}
static int
{
return (-1);
return (1);
return (0);
return (0);
}
static void
report()
{
int i;
int cnt;
if (nflg)
return;
if (cflg) {
long t = 0;
for (i = 0; i < TSIZE - 1; i++)
if (sizes[i]) {
t += i*sizes[i];
(void) printf("%d %d %ld\n",
i, sizes[i], t);
}
return;
}
sortprep();
return;
if (fflg)
else
if (vflg)
(void) printf("\t%5ld\t%5ld\t%5ld",
(void) printf("\n");
}
}
static int
{
char *cp; /* Pointer to raw device name */
extern char *getfullrawname();
exit(32);
}
return (0);
/* If we can't get the raw name, keep the block name */
return (0);
}
exit(32);
}
"quot: %s not ufs filesystem\n",
*devpp);
exit(32);
}
/* If we can't get the raw name, use the block name */
return (0);
}
}
*devpp);
usage();
exit(32);
/* NOTREACHED */
}
static struct du *
{
return (up);
}
}
return (up);
}
static struct du *
{
"out of memory for du structures\n");
exit(32);
}
ndu++;
return (up);
}
static void
sortprep()
{
int i, cnt = 0;
"out of memory for du structures\n");
exit(32);
}
continue;
}
}
}
static void
cleanup()
{
int i;
/*
* Release memory from hash table and du
*/
if (du) {
}
for (i = 0; i != UHASH; i++) {
continue;
while (ep) {
}
}
}
}