From d4a56045bacf31ec03cedbacb54f3060633367b8 Mon Sep 17 00:00:00 2001 From: Simone Piccardi Date: Wed, 9 Jun 2010 18:14:08 +0000 Subject: [PATCH] Programma per stampare le quote disco --- sources/mygetaddr.c | 4 +- sources/mygetquota.c | 110 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 sources/mygetquota.c diff --git a/sources/mygetaddr.c b/sources/mygetaddr.c index a6e9ecd..c34d15d 100644 --- a/sources/mygetaddr.c +++ b/sources/mygetaddr.c @@ -191,9 +191,9 @@ int main(int argc, char *argv[]) * routine to print usage info and exit */ void usage(void) { - printf("Program mygethost: do an hostname resolution \n"); + printf("Program mygetaddr: do an hostname resolution \n"); printf("Usage:\n"); - printf("mygethost [-h] [-p protocol] [-t socktype] hostname service\n"); + printf("mygetaddr [-h] [-p protocol] [-t socktype] hostname service\n"); printf(" -h print this help\n"); printf(" -p udp,tcp select a protocol\n"); printf(" -t dgram,stream select a socket type\n"); diff --git a/sources/mygetquota.c b/sources/mygetquota.c new file mode 100644 index 0000000..82e7e9e --- /dev/null +++ b/sources/mygetquota.c @@ -0,0 +1,110 @@ +/* mygetquota.c + * + * Copyright (C) 2010 Simone Piccardi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/***************************************************************************** + * + * File mygetquota.c: An example for quotactl function + * + * Author: S. Piccardi Jun. 2010 + * + *****************************************************************************/ +#include /* C strings library */ +#include /* primitive system data types */ +#include /* file characteristics constants and functions */ +#include /* unix standard library */ +#include /* C standard library */ +#include /* standard I/O library */ +#include + +/* + * Program mygetquota + * + * Use quotactl to get an user quota + */ + +/* Help printing routine */ +void usage(void); + +int main(int argc, char *argv[]) +{ +/* + * Variables definition + */ + int i,j,ret; + int who=USRQUOTA; + uid_t uid=0; + struct dqblk dq; + /* + * Input section: decode command line parameters + * Use getopt function + */ + opterr = 0; /* don't want writing to stderr */ + while ( (i = getopt(argc, argv, "hgu")) != -1) { + switch (i) { + /* + * Handling options + */ + case 'h': /* help option */ + usage(); + break; + case 'g': /* group option */ + who=GRPQUOTA; + break; + case 'u': /* user option */ + who=USRQUOTA; + break; + case '?': /* unrecognized options */ + printf("Unrecognized options -%c\n",optopt); + usage(); + default: /* should not reached */ + usage(); + } + } + /* *********************************************************** + * + * Options processing completed + * + * Main code beginning + * + * ***********************************************************/ + /* remaining argument check */ + if ((argc - optind) != 2) { + printf("Wrong number of arguments %d\n", argc - optind); + usage(); + } + /* main body */ + uid = atoi(argv[optind]); + ret = quotactl(QCMD(Q_GETQUOTA,who), argv[optind+1], uid, (caddr_t) &dq); + if (!ret) { + printf("Data:%7.1qu\n", dq.dqb_curspace); + printf("Soft:%7.1qu\tHard: %7.1qu\tGrace: %7.1qu\n", dq.dqb_bsoftlimit, dq.dqb_bhardlimit, dq.dqb_btime); + printf("Files: %7.1qu\n", dq.dqb_curinodes); + printf("Soft: %7.1qu\tHard: %7.1qu\tGrace: %7.1qu\n", dq.dqb_isoftlimit, dq.dqb_ihardlimit, dq.dqb_itime); + } else + perror("errore"); + exit(0); +} +/* + * routine to print usage info and exit + */ +void usage(void) { + printf("Program mygetquota: get an user quota \n"); + printf("Usage:\n"); + printf("mygetquota uid filesystem \n"); + exit(1); +} -- 2.30.2