]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/rquotad/hasquota.c
f93e90ab479189abf9422a0aa5ad7dce25504932
[nfs-utils.git] / utils / rquotad / hasquota.c
1 /*
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
8  *          group quota files.
9  *
10  *          Determines if a filesystem has quota enabled and how the quotafile
11  *          is named.
12  *
13  * Version: $Id: hasquota.c,v 2.6 1996/11/17 16:59:46 mvw Exp mvw $
14  *
15  * Author:  Marco van Wieringen <mvw@planets.elm.net>
16  *
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.
21  */
22 #include "config.h"
23 #define _LINUX_QUOTA_VERSION 1
24
25 #include <sys/types.h>
26 #include <sys/quota.h>
27 #include <limits.h>
28 #include <string.h>
29 #include "mntent.h"
30 #include "xmalloc.h"
31
32 #undef min
33 #define min(x,y) ((x) < (y)) ? (x) : (y)
34
35 #define CORRECT_FSTYPE(type) \
36 ((!strcmp(type,MNTTYPE_EXT2)) || (!strcmp(type,MNTTYPE_EXT3)))
37
38 char *qfextension[] = INITQFNAMES;
39
40 /*
41  * Check to see if a particular quota is to be enabled.
42  */
43 int
44 hasquota(struct mntent *mnt, int type, char **qfnamep)
45 {
46    char *qfname = QUOTAFILENAME;
47    char *option, *pathname;
48
49    if (!CORRECT_FSTYPE(mnt->mnt_type))
50       return (0);
51
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]);
59       } else {
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';
65          }
66          else {
67             *qfnamep=xstrdup(pathname);
68          }
69       }
70       return (1);
71    } else
72       return (0);
73 }