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.
26 #define _LINUX_QUOTA_VERSION 1
28 #include <sys/types.h>
29 #include <sys/quota.h>
36 #define min(x,y) ((x) < (y)) ? (x) : (y)
38 #define CORRECT_FSTYPE(type) \
39 ((!strcmp(type,MNTTYPE_EXT2)) || (!strcmp(type,MNTTYPE_EXT3)))
41 char *qfextension[] = INITQFNAMES;
44 * Check to see if a particular quota is to be enabled.
47 hasquota(struct mntent *mnt, int type, char **qfnamep)
49 char *qfname = QUOTAFILENAME;
50 char *option, *pathname;
52 if (!CORRECT_FSTYPE(mnt->mnt_type))
55 if (((type == USRQUOTA) && (option = hasmntopt(mnt, MNTOPT_USRQUOTA)) != (char *)0) ||
56 ((type == GRPQUOTA) && (option = hasmntopt(mnt, MNTOPT_GRPQUOTA)) != (char *)0)) {
57 if ((pathname = strchr(option, '=')) == (char *)0) {
58 *qfnamep=xmalloc(strlen(mnt->mnt_dir)+strlen(qfname)+strlen(qfextension[type])+3);
59 (void) sprintf(*qfnamep, "%s%s%s.%s", mnt->mnt_dir,
60 (mnt->mnt_dir[strlen(mnt->mnt_dir) - 1] == '/') ? "" : "/",
61 qfname, qfextension[type]);
63 if ((option = strchr(++pathname, ',')) != (char *)NULL) {
64 int len=option-pathname;
65 *qfnamep=xmalloc(len);
66 memcpy(*qfnamep, pathname, len-1);
67 (*qfnamep) [len-1] = '\0';
70 *qfnamep=xstrdup(pathname);