]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/rquotad/hasquota.c
1. Added nfs-utils.spec.in.
[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
24 #include <sys/types.h>
25 #include <sys/quota.h>
26 #include <limits.h>
27 #include <string.h>
28 #include "mntent.h"
29 #include "xmalloc.h"
30
31 #undef min
32 #define min(x,y) ((x) < (y)) ? (x) : (y)
33
34 #define CORRECT_FSTYPE(type) \
35 (!strcmp(type,MNTTYPE_EXT2))
36
37 char *qfextension[] = INITQFNAMES;
38
39 /*
40  * Check to see if a particular quota is to be enabled.
41  */
42 int
43 hasquota(struct mntent *mnt, int type, char **qfnamep)
44 {
45    char *qfname = QUOTAFILENAME;
46    char *option, *pathname;
47
48    if (!CORRECT_FSTYPE(mnt->mnt_type))
49       return (0);
50
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])+2);
55           (void) sprintf(*qfnamep, "%s%s%s.%s", mnt->mnt_dir,
56                         (mnt->mnt_dir[strlen(mnt->mnt_dir) - 1] == '/') ? "" : "/",
57                         qfname, qfextension[type]);
58       } else {
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';
64          }
65          else {
66             *qfnamep=xstrdup(pathname);
67          }
68       }
69       return (1);
70    } else
71       return (0);
72 }