diff options
author | Kirk McKusick <mckusick@FreeBSD.org> | 2009-02-13 06:12:15 +0000 |
---|---|---|
committer | Kirk McKusick <mckusick@FreeBSD.org> | 2009-02-13 06:12:15 +0000 |
commit | 916e406eb5992cdb49a4c90f634e3aa398aaad6a (patch) | |
tree | 9ae3ac009f27dbb0491aa641ac8bf6c0e15aba8c /lib | |
parent | 581fce8e7df72f43c9aa9eb4b45815991911b0fb (diff) | |
download | src-916e406eb5992cdb49a4c90f634e3aa398aaad6a.tar.gz src-916e406eb5992cdb49a4c90f634e3aa398aaad6a.zip |
Move hasquota() function to libutil.
Notes
Notes:
svn path=/projects/quota64/; revision=188568
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libutil/libutil.h | 2 | ||||
-rw-r--r-- | lib/libutil/quotafile.c | 56 |
2 files changed, 56 insertions, 2 deletions
diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h index 48ab2188c358..7796de0ac788 100644 --- a/lib/libutil/libutil.h +++ b/lib/libutil/libutil.h @@ -142,11 +142,13 @@ int pidfile_remove(struct pidfh *pfh); #ifdef _UFS_UFS_QUOTA_H_ struct quotafile; +struct fstab; struct quotafile *quota_open(const char *); struct quotafile *quota_create(const char *); void quota_close(struct quotafile *); int quota_read(struct quotafile *, struct dqblk *, int); int quota_write(struct quotafile *, const struct dqblk *, int); +int hasquota(struct fstab *, int, char **); #endif __END_DECLS diff --git a/lib/libutil/quotafile.c b/lib/libutil/quotafile.c index c175df0b21ce..2520e9fcc640 100644 --- a/lib/libutil/quotafile.c +++ b/lib/libutil/quotafile.c @@ -29,16 +29,19 @@ #include <sys/types.h> #include <sys/endian.h> +#include <sys/mount.h> #include <sys/stat.h> #include <ufs/ufs/quota.h> #include <errno.h> #include <fcntl.h> +#include <fstab.h> #include <grp.h> #include <pwd.h> #include <libutil.h> #include <stdint.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -48,6 +51,8 @@ struct quotafile { int type; /* 32 or 64 */ }; +static const char *qfextension[] = INITQFNAMES; + struct quotafile * quota_open(const char *fn) { @@ -231,7 +236,7 @@ quota_write32(struct quotafile *qf, const struct dqblk *dqb, int id) off = id * sizeof(struct dqblk32); if (lseek(qf->fd, off, SEEK_SET) == -1) return (-1); - return (write(qf->fd, &dqb32, sizeof(dqb32)) == -1); + return (write(qf->fd, &dqb32, sizeof(dqb32)) == sizeof(dqb32)); } static int @@ -252,7 +257,7 @@ quota_write64(struct quotafile *qf, const struct dqblk *dqb, int id) off = sizeof(struct dqhdr64) + id * sizeof(struct dqblk64); if (lseek(qf->fd, off, SEEK_SET) == -1) return (-1); - return (write(qf->fd, &dqb64, sizeof(dqb64)) == -1); + return (write(qf->fd, &dqb64, sizeof(dqb64)) == sizeof(dqb64)); } int @@ -270,3 +275,50 @@ quota_write(struct quotafile *qf, const struct dqblk *dqb, int id) } /* not reached */ } + +/* + * Check to see if a particular quota is to be enabled. + */ +int +hasquota(struct fstab *fs, int type, char **qfnamep) +{ + char *opt; + char *cp; + struct statfs sfb; + static char initname, usrname[100], grpname[100]; + static char buf[BUFSIZ]; + + if (!initname) { + (void)snprintf(usrname, sizeof(usrname), "%s%s", + qfextension[USRQUOTA], QUOTAFILENAME); + (void)snprintf(grpname, sizeof(grpname), "%s%s", + qfextension[GRPQUOTA], QUOTAFILENAME); + initname = 1; + } + strcpy(buf, fs->fs_mntops); + for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) { + if ((cp = index(opt, '='))) + *cp++ = '\0'; + if (type == USRQUOTA && strcmp(opt, usrname) == 0) + break; + if (type == GRPQUOTA && strcmp(opt, grpname) == 0) + break; + } + if (!opt) + return (0); + if (cp) + *qfnamep = cp; + else { + (void)snprintf(buf, sizeof(buf), "%s/%s.%s", fs->fs_file, + QUOTAFILENAME, qfextension[type]); + *qfnamep = buf; + } + /* + * Ensure that the filesystem is mounted. + */ + if (statfs(fs->fs_file, &sfb) != 0 || + strcmp(fs->fs_file, sfb.f_mntonname)) { + return (0); + } + return (1); +} |