2 * QUOTA An implementation of the diskquota system for the LINUX
3 * operating system. QUOTA is implemented using the BSD systemcall
4 * interface as the means of communication with the user level.
5 * Should work for all filesystems because of integration into the
6 * VFS layer of the operating system.
7 * This is based on the Melbourne quota system wich uses both user and
10 * Determines if a filesystem has quota enabled and how the quotafile
13 * Version: $Id: hasquota.c,v 2.6 1996/11/17 16:59:46 mvw Exp mvw $
15 * Author: Marco van Wieringen <mvw@planets.elm.net>
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
24 #include <sys/types.h>
25 #include <sys/quota.h>
32 #define min(x,y) ((x) < (y)) ? (x) : (y)
34 #define CORRECT_FSTYPE(type) \
35 ((!strcmp(type,MNTTYPE_EXT2)) || (!strcmp(type,MNTTYPE_EXT3)))
37 char *qfextension[] = INITQFNAMES;
40 * Check to see if a particular quota is to be enabled.
43 hasquota(struct mntent *mnt, int type, char **qfnamep)
45 char *qfname = QUOTAFILENAME;
46 char *option, *pathname;
48 if (!CORRECT_FSTYPE(mnt->mnt_type))
51 if (((type == USRQUOTA) && (option = hasmntopt(mnt, MNTOPT_USRQUOTA)) != (char *)0) ||
52 ((type == GRPQUOTA) && (option = hasmntopt(mnt, MNTOPT_GRPQUOTA)) != (char *)0)) {
53 if ((pathname = strchr(option, '=')) == (char *)0) {
54 *qfnamep=xmalloc(strlen(mnt->mnt_dir)+strlen(qfname)+strlen(qfextension[type])+3);
55 (void) sprintf(*qfnamep, "%s%s%s.%s", mnt->mnt_dir,
56 (mnt->mnt_dir[strlen(mnt->mnt_dir) - 1] == '/') ? "" : "/",
57 qfname, qfextension[type]);
59 if ((option = strchr(++pathname, ',')) != (char *)NULL) {
60 int len=option-pathname;
61 *qfnamep=xmalloc(len);
62 memcpy(*qfnamep, pathname, len-1);
63 (*qfnamep) [len-1] = '\0';
66 *qfnamep=xstrdup(pathname);