/* * spd@daphne.cps.unizar.es * IRIX 6.x * cc -n32 -mips3 -O -o lquot lquot.c -lrpcsvc */ #include #include #include #include #include #ifdef __linux__ # include # define dqb_curblocks dqb_curspace # define dqb_fhardlimit dqb_ihardlimit # define dqb_fsoftlimit dqb_isoftlimit # define dqb_curfiles dqb_curinodes # define dqb_btimelimit dqb_btime # define dqb_ftimelimit dqb_itime #endif #include #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif #include #ifdef __cplusplus } #endif #ifdef __linux__ # define gqr_status status # define gqr_rquota getquota_rslt_u.gqr_rquota #endif #include #include #include #include void usage(char *name) { fprintf(stderr, "usage: %s [-vq] path...\n",name); exit(-1); } int call_rpc( char *host, int prognum, int versnum, int procnum, xdrproc_t inproc, struct getquota_args *in, xdrproc_t outproc, struct getquota_rslt *out ); main (int argc, char **argv) { struct dqblk q; #ifdef __sgi struct fs_disk_quota f; #endif struct getquota_rslt gqr; FILE *mnt; struct mntent *mp; struct stat s,t; struct getquota_args gqa; uid_t euser_id; int option; int verbose=0; int quota=1; int i; while(( option = getopt(argc, argv, "vqh"))!=EOF ) { switch(option) { case 'v': verbose=1; break; case 'q': quota=0; break; default: usage(argv[0]); break; } } euser_id=geteuid(); if (quota) { struct passwd *pwd; char *user="\?\?\?"; if ( NULL == ( pwd = getpwuid ( euser_id ))) { perror("uid"); } else { user = pwd->pw_name; } printf("Disk quotas for %s (uid %d):\nFilesystem usage quota limit timeleft files quota limit timeleft\n", user, euser_id); } for (i=optind; imnt_dir,&t))) continue; if (t.st_dev == s.st_dev) break; } endmntent( mnt ); if (t.st_dev != s.st_dev) { exit(1); } if (verbose) { printf("file system name: %s\n", mp->mnt_fsname); printf("file system path prefix: %s\n", mp->mnt_dir); printf("type: dbg, efs, xfs, nfs: %s\n", mp->mnt_type); printf("options: ro, hide, etc.: %s\n", mp->mnt_opts); printf("dump frequency, in days: %d\n", mp->mnt_freq); printf("pass number on parallel fsck: %d\n", mp->mnt_passno); } if ( 0 == strcmp ( mp->mnt_type, "efs" )) { if ( -1 == quotactl ( Q_GETQUOTA, mp->mnt_fsname, getuid(), (caddr_t) &q) ) perror("Q_GETQUOTA"); if(verbose) { printf("absolute limit on disk blks: %d\n",q.dqb_bhardlimit); printf("preferred limit on disk blks: %d\n",q.dqb_bsoftlimit); printf("current block count: %d\n",q.dqb_curblocks); printf("maximum # allocated files + 1: %d\n",q.dqb_fhardlimit); printf("preferred file limit %d\n",q.dqb_fsoftlimit); printf("current # allocated files: %d\n",q.dqb_curfiles); printf("timer disk blks limit: %d\n",q.dqb_btimelimit); printf("timer file limit: %d\n",q.dqb_ftimelimit); } if (quota) { printf("%-11s%8d%8d%8d%12d%8d%8d%8d%12d\n", mp->mnt_dir, q.dqb_curblocks, q.dqb_bsoftlimit, q.dqb_bhardlimit, q.dqb_btimelimit, q.dqb_curfiles, q.dqb_fsoftlimit, q.dqb_fhardlimit, q.dqb_ftimelimit); } } #ifdef __sgi else if ( 0 == strcmp ( mp->mnt_type, "xfs" )) { if ( -1 == quotactl ( Q_XGETQUOTA, mp->mnt_fsname, getuid(), (caddr_t) &f) ) perror("Q_XGETQUOTA"); if(verbose) { printf("absolute limit on disk blks: %lld\n",f.d_blk_hardlimit); printf("preferred limit on disk blks: %lld\n",f.d_blk_softlimit); printf("current block count: %lld\n",f.d_bcount); printf("maximum # allocated inodes: %lld\n",f.d_ino_hardlimit); printf("preferred inode limit %lld\n",f.d_ino_softlimit); printf("inodes owned by the users: %lld\n",f.d_icount); } if (quota) { printf("%-11s%8lld%8lld%8lld%12d%8lld%8lld%8lld%12d\n", mp->mnt_dir, f.d_bcount, f.d_blk_softlimit, f.d_blk_hardlimit, 0, f.d_icount, f.d_ino_softlimit, f.d_ino_hardlimit, 0); } } #endif else if ( 0 == strncmp ( mp->mnt_type, "nfs", 3 )) { char *p; char *hostname; int blocks; p=strchr(mp->mnt_fsname, ':'); *p=0x00; gqa.gqa_pathp = p+1; gqa.gqa_uid = euser_id; hostname = mp->mnt_fsname; if ( 0!= call_rpc( hostname, RQUOTAPROG, RQUOTAVERS, RQUOTAPROC_GETQUOTA, (xdrproc_t)xdr_getquota_args, &gqa, (xdrproc_t)xdr_getquota_rslt, &gqr )) { perror("rpc"); } else { switch (gqr.gqr_status) { case Q_OK: blocks = gqr.gqr_rquota.rq_bsize / DEV_BSIZE; if(verbose) { printf("absolute limit on disk blks: %d\n", gqr.gqr_rquota.rq_bhardlimit * blocks); printf("preferred limit on disk blks: %d\n", gqr.gqr_rquota.rq_bsoftlimit * blocks); printf("disk blocks owned by the user: %d\n", gqr.gqr_rquota.rq_curblocks * blocks); printf("maximum # allocated inodes: %d\n",gqr.gqr_rquota.rq_fhardlimit); printf("preferred inode limit: %d\n",gqr.gqr_rquota.rq_fsoftlimit); printf("inodes owned by the user: %d\n",gqr.gqr_rquota.rq_curfiles); } if (quota) { printf("%-11s%8d%8d%8d%12d%8d%8d%8d%12d\n", mp->mnt_dir, gqr.gqr_rquota.rq_curblocks * blocks, gqr.gqr_rquota.rq_bsoftlimit * blocks, gqr.gqr_rquota.rq_bhardlimit * blocks, 0, gqr.gqr_rquota.rq_curfiles, gqr.gqr_rquota.rq_fsoftlimit, gqr.gqr_rquota.rq_fhardlimit, 0); } break; case Q_NOQUOTA: break; case Q_EPERM: fprintf(stderr, "quota permission error, host: %s\n", hostname); break; default: fprintf(stderr, "bad rpc result, host: %s\n", hostname); break; } } } } } } return(0); } int call_rpc( char *host, int prognum, int versnum, int procnum, xdrproc_t inproc, struct getquota_args *in, xdrproc_t outproc, struct getquota_rslt *out ) { struct sockaddr_in server_addr; enum clnt_stat clnt_stat; struct hostent *hp; struct timeval timeout, tottimeout; static CLIENT *client = NULL; static int socket = RPC_ANYSOCK; static int valid = 0; static int oldprognum, oldversnum; static char oldhost[256]; if (valid && oldprognum == prognum && oldversnum == versnum && strcmp(oldhost, host) == 0) { /* reuse old client */ } else { valid = 0; close(socket); socket = RPC_ANYSOCK; if (client) { clnt_destroy(client); client = NULL; } if ((hp = gethostbyname(host)) == NULL) return ((int) RPC_UNKNOWNHOST); timeout.tv_usec = 0; timeout.tv_sec = 6; /* bcopy(hp->h_addr, &server_addr.sin_addr, hp->h_length);*/ memcpy(&server_addr.sin_addr, hp->h_addr, hp->h_length); server_addr.sin_family = AF_INET; /* ping the remote end via tcp to see if it is up */ server_addr.sin_port = htons(PMAPPORT); if ((client = clnttcp_create(&server_addr, PMAPPROG, PMAPVERS, &socket, 0, 0)) == NULL) { return ((int) rpc_createerr.cf_stat); } else { /* the fact we succeeded means the machine is up */ close(socket); socket = RPC_ANYSOCK; clnt_destroy(client); client = NULL; } /* now really create a udp client handle */ server_addr.sin_port = 0; if ((client = clntudp_create(&server_addr, prognum, versnum, timeout, &socket)) == NULL) return ((int) rpc_createerr.cf_stat); client->cl_auth = authunix_create_default(); valid = 1; oldprognum = prognum; oldversnum = versnum; strcpy(oldhost, host); } tottimeout.tv_sec = 25; tottimeout.tv_usec = 0; clnt_stat = clnt_call(client, procnum, inproc, in, outproc, out, tottimeout); /* * if call failed, empty cache */ if (clnt_stat != RPC_SUCCESS) valid = 0; return ((int) clnt_stat); }