Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6185:685a6f165193 HEAD
Code cleanups.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 06 Aug 2007 22:14:16 +0300 |
parents | cacb72a465c1 |
children | 9a3a7ad297cf |
files | src/plugins/quota/quota-fs.c src/plugins/quota/quota-fs.h |
diffstat | 2 files changed, 73 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/quota/quota-fs.c Mon Aug 06 21:57:06 2007 +0300 +++ b/src/plugins/quota/quota-fs.c Mon Aug 06 22:14:16 2007 +0300 @@ -48,7 +48,7 @@ char *device_path; char *type; -#ifdef HAVE_Q_QUOTACTL +#ifdef FS_QUOTA_SOLARIS int fd; char *path; #endif @@ -76,7 +76,7 @@ static void fs_quota_mountpoint_free(struct fs_quota_mountpoint *mount) { -#ifdef HAVE_Q_QUOTACTL +#ifdef FS_QUOTA_SOLARIS if (mount->fd != -1) { if (close(mount->fd) < 0) i_error("close(%s) failed: %m", mount->path); @@ -181,7 +181,7 @@ strcmp(storage->name, "maildir") == 0 || strcmp(storage->name, "cydir") == 0; -#ifdef HAVE_Q_QUOTACTL +#ifdef FS_QUOTA_SOLARIS if (mount->path == NULL) { mount->path = i_strconcat(mount->mount_path, "/quotas", NULL); mount->fd = open(mount->path, O_RDONLY); @@ -313,39 +313,13 @@ } #endif +#ifdef FS_QUOTA_LINUX static int -fs_quota_get_resource(struct quota_root *_root, const char *name, - uint64_t *value_r, uint64_t *limit_r) +fs_quota_get_linux(struct fs_quota_root *root, bool bytes, + uint64_t *value_r, uint64_t *limit_r) { - struct fs_quota_root *root = (struct fs_quota_root *)_root; struct dqblk dqblk; -#ifdef HAVE_Q_QUOTACTL - struct quotctl ctl; -#endif - bool bytes; - - *value_r = 0; - *limit_r = 0; - if (root->mount == NULL || - (strcasecmp(name, QUOTA_NAME_STORAGE_BYTES) != 0 && - strcasecmp(name, QUOTA_NAME_MESSAGES) != 0)) - return 0; - bytes = strcasecmp(name, QUOTA_NAME_STORAGE_BYTES) == 0; - -#ifdef HAVE_RQUOTA - if (strcmp(root->mount->type, "nfs") == 0) { - int ret; - - t_push(); - ret = do_rquota(root, bytes, value_r, limit_r); - t_pop(); - return ret; - } -#endif - -#if defined (HAVE_QUOTACTL) && defined(HAVE_SYS_QUOTA_H) - /* Linux */ #ifdef HAVE_XFS_QUOTA if (strcmp(root->mount->type, "xfs") == 0) { /* XFS */ @@ -397,8 +371,17 @@ *value_r = dqblk.dqb_isoftlimit; } } -#elif defined(HAVE_QUOTACTL) - /* BSD, AIX */ + return 1; +} +#endif + +#ifdef FS_QUOTA_BSDAIX +static int +fs_quota_get_bsdaix(struct fs_quota_root *root, bool bytes, + uint64_t *value_r, uint64_t *limit_r) +{ + struct dqblk dqblk; + if (quotactl(root->mount->mount_path, QCMD(Q_GETQUOTA, USRQUOTA), root->uid, (void *)&dqblk) < 0) { i_error("quotactl(Q_GETQUOTA, %s) failed: %m", @@ -412,8 +395,18 @@ *value_r = dqblk.dqb_curinodes; *value_r = dqblk.dqb_isoftlimit; } -#else - /* Solaris */ + return 1; +} +#endif + +#ifdef FS_QUOTA_SOLARIS +static int +fs_quota_get_solaris(struct fs_quota_root *root, bool bytes, + uint64_t *value_r, uint64_t *limit_r) +{ + struct dqblk dqblk; + struct quotctl ctl; + if (root->mount->fd == -1) return 0; @@ -431,8 +424,44 @@ *value_r = dqblk.dqb_curfiles; *value_r = dqblk.dqb_fsoftlimit; } + return 1; +} #endif - return 1; + +static int +fs_quota_get_resource(struct quota_root *_root, const char *name, + uint64_t *value_r, uint64_t *limit_r) +{ + struct fs_quota_root *root = (struct fs_quota_root *)_root; + bool bytes; + + *value_r = 0; + *limit_r = 0; + + if (root->mount == NULL || + (strcasecmp(name, QUOTA_NAME_STORAGE_BYTES) != 0 && + strcasecmp(name, QUOTA_NAME_MESSAGES) != 0)) + return 0; + bytes = strcasecmp(name, QUOTA_NAME_STORAGE_BYTES) == 0; + +#ifdef HAVE_RQUOTA + if (strcmp(root->mount->type, "nfs") == 0) { + int ret; + + t_push(); + ret = do_rquota(root, bytes, value_r, limit_r); + t_pop(); + return ret; + } +#endif + +#ifdef FS_QUOTA_LINUX + return fs_quota_get_linux(root, bytes, value_r, limit_r); +#elif defined (FS_QUOTA_BSDAIX) + return fs_quota_get_bsdaix(root, bytes, value_r, limit_r); +#else + return fs_quota_get_solaris(root, bytes, value_r, limit_r); +#endif } static int
--- a/src/plugins/quota/quota-fs.h Mon Aug 06 21:57:06 2007 +0300 +++ b/src/plugins/quota/quota-fs.h Mon Aug 06 22:14:16 2007 +0300 @@ -18,7 +18,13 @@ # undef HAVE_FS_QUOTA #endif -#if !defined(HAVE_QUOTACTL) && !defined(HAVE_Q_QUOTACTL) +#if defined (HAVE_QUOTACTL) && defined(HAVE_SYS_QUOTA_H) +# define FS_QUOTA_LINUX +#elif defined(HAVE_QUOTACTL) +# define FS_QUOTA_BSDAIX +#elif defined (HAVE_Q_QUOTACTL) +# define FS_QUOTA_SOLARIS +#else # undef HAVE_FS_QUOTA #endif