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