2 Unix SMB/CIFS implementation.
3 System QUOTA function wrappers for QUOTACTL_4A
4 Copyright (C) Stefan (metze) Metzmacher 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #define DBGC_CLASS DBGC_QUOTA
26 #ifndef HAVE_SYS_QUOTAS
27 #ifdef HAVE_QUOTACTL_4A
28 #undef HAVE_QUOTACTL_4A
32 #ifdef HAVE_QUOTACTL_4A
33 /* long quotactl(int cmd, char *special, qid_t id, caddr_t addr) */
34 /* this is used by: HPUX,IRIX */
36 #ifdef HAVE_SYS_TYPES_H
37 #include <sys/types.h>
40 #ifdef HAVE_ASM_TYPES_H
41 #include <asm/types.h>
44 #ifdef HAVE_SYS_QUOTA_H
45 #include <sys/quota.h>
49 #define Q_SETQLIM Q_SETQUOTA
61 #define HAVE_GROUP_QUOTA
64 #ifndef QUOTABLOCK_SIZE
65 #define QUOTABLOCK_SIZE DEV_BSIZE
68 #ifdef HAVE_DQB_FSOFTLIMIT
69 #define dqb_isoftlimit dqb_fsoftlimit
70 #define dqb_ihardlimit dqb_fhardlimit
71 #define dqb_curinodes dqb_curfiles
75 #define USERQUOTAFILE_EXTENSION ".user"
77 #define USERQUOTAFILE_EXTENSION ""
80 #if !defined(QUOTAFILENAME) && defined(QFILENAME)
81 #define QUOTAFILENAME QFILENAME
84 /****************************************************************************
85 Abstract out the quotactl_4A get calls.
86 ****************************************************************************/
87 int sys_get_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
92 uint64_t bsize = (uint64_t)QUOTABLOCK_SIZE;
99 case SMB_USER_QUOTA_TYPE:
100 DEBUG(10,("sys_get_vfs_quota: path[%s] bdev[%s] SMB_USER_QUOTA_TYPE uid[%u]\n",
101 path, bdev, (unsigned)id.uid));
103 if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), (caddr_t)bdev, id.uid, (void *)&D))&&errno != EDQUOT) {
109 #ifdef HAVE_GROUP_QUOTA
110 case SMB_GROUP_QUOTA_TYPE:
111 DEBUG(10,("sys_get_vfs_quota: path[%s] bdev[%s] SMB_GROUP_QUOTA_TYPE gid[%u]\n",
112 path, bdev, (unsigned)id.gid));
114 if ((ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), (caddr_t)bdev, id.gid, (void *)&D))&&errno != EDQUOT) {
120 #endif /* HAVE_GROUP_QUOTA */
121 case SMB_USER_FS_QUOTA_TYPE:
124 DEBUG(10,("sys_get_vfs_quota: path[%s] bdev[%s] SMB_USER_FS_QUOTA_TYPE (uid[%u])\n",
125 path, (caddr_t)bdev, (unsigned)id.uid));
127 if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), (caddr_t)bdev, id.uid, (void *)&D))==0) {
128 qflags |= QUOTAS_DENY_DISK;
133 #ifdef HAVE_GROUP_QUOTA
134 case SMB_GROUP_FS_QUOTA_TYPE:
137 DEBUG(10,("sys_get_vfs_quota: path[%s] bdev[%s] SMB_GROUP_FS_QUOTA_TYPE (gid[%u])\n",
138 path, bdev, (unsigned)id.gid));
140 if ((ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), (caddr_t)bdev, id.gid, (void *)&D))==0) {
141 qflags |= QUOTAS_DENY_DISK;
146 #endif /* HAVE_GROUP_QUOTA */
153 dp->softlimit = (uint64_t)D.dqb_bsoftlimit;
154 dp->hardlimit = (uint64_t)D.dqb_bhardlimit;
155 dp->ihardlimit = (uint64_t)D.dqb_ihardlimit;
156 dp->isoftlimit = (uint64_t)D.dqb_isoftlimit;
157 dp->curinodes = (uint64_t)D.dqb_curinodes;
158 dp->curblocks = (uint64_t)D.dqb_curblocks;
166 /****************************************************************************
167 Abstract out the quotactl_4A set calls.
168 ****************************************************************************/
169 int sys_set_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
173 uint32_t oldqflags = 0;
175 uint64_t bsize = (uint64_t)QUOTABLOCK_SIZE;
179 if (bsize == dp->bsize) {
180 D.dqb_bsoftlimit = dp->softlimit;
181 D.dqb_bhardlimit = dp->hardlimit;
182 D.dqb_ihardlimit = dp->ihardlimit;
183 D.dqb_isoftlimit = dp->isoftlimit;
185 D.dqb_bsoftlimit = (dp->softlimit*dp->bsize)/bsize;
186 D.dqb_bhardlimit = (dp->hardlimit*dp->bsize)/bsize;
187 D.dqb_ihardlimit = (dp->ihardlimit*dp->bsize)/bsize;
188 D.dqb_isoftlimit = (dp->isoftlimit*dp->bsize)/bsize;
194 case SMB_USER_QUOTA_TYPE:
195 DEBUG(10,("sys_set_vfs_quota: path[%s] bdev[%s] SMB_USER_QUOTA_TYPE uid[%u]\n",
196 path, bdev, (unsigned)id.uid));
198 ret = quotactl(QCMD(Q_SETQLIM,USRQUOTA), (caddr_t)bdev, id.uid, (void *)&D);
200 #ifdef HAVE_GROUP_QUOTA
201 case SMB_GROUP_QUOTA_TYPE:
202 DEBUG(10,("sys_set_vfs_quota: path[%s] bdev[%s] SMB_GROUP_QUOTA_TYPE gid[%u]\n",
203 path, bdev, (unsigned)id.gid));
205 ret = quotactl(QCMD(Q_SETQLIM,GRPQUOTA), (caddr_t)bdev, id.gid, (void *)&D);
207 #endif /* HAVE_GROUP_QUOTA */
208 case SMB_USER_FS_QUOTA_TYPE:
209 /* this stuff didn't work as it should:
210 * switching on/off quota via quotactl()
212 * So we just return 0
215 * On HPUX we didn't have the mount path,
216 * we need to fix sys_path_to_bdev()
220 DEBUG(10,("sys_set_vfs_quota: path[%s] bdev[%s] SMB_USER_FS_QUOTA_TYPE (uid[%u])\n",
221 path, bdev, (unsigned)id.uid));
224 ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), (caddr_t)bdev, id.uid, (void *)&D);
226 if ((qflags"AS_DENY_DISK)||(qflags"AS_ENABLED)) {
228 char *quota_file = NULL;
230 asprintf("a_file,"/%s/%s%s",path, QUOTAFILENAME,USERQUOTAFILE_EXTENSION);
231 if (quota_file == NULL) {
232 DEBUG(0,("asprintf() failed!\n"));
237 ret = quotactl(QCMD(Q_QUOTAON,USRQUOTA), (caddr_t)bdev, -1,(void *)quota_file);
244 ret = quotactl(QCMD(Q_QUOTAOFF,USRQUOTA), (caddr_t)bdev, -1, (void *)0);
250 DEBUG(0,("sys_set_vfs_quota: ret(%d) errno(%d)[%s] uid(%d) bdev[%s]\n",
251 ret,errno,strerror(errno),id.uid,bdev));
253 if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), (caddr_t)bdev, id.uid, (void *)&D))==0) {
254 oldqflags |= QUOTAS_DENY_DISK;
257 if (oldqflags == qflags) {
264 #ifdef HAVE_GROUP_QUOTA
265 case SMB_GROUP_FS_QUOTA_TYPE:
266 /* this stuff didn't work as it should:
267 * switching on/off quota via quotactl()
269 * So we just return 0
272 * On HPUX we didn't have the mount path,
273 * we need to fix sys_path_to_bdev()
277 DEBUG(10,("sys_set_vfs_quota: path[%s] bdev[%s] SMB_GROUP_FS_QUOTA_TYPE (gid[%u])\n",
278 path, bdev, (unsigned)id.gid));
281 ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), bdev, id, (void *)&D);
283 if ((qflags"AS_DENY_DISK)||(qflags"AS_ENABLED)) {
285 char *quota_file = NULL;
287 asprintf("a_file,"/%s/%s%s",path, QUOTAFILENAME,GROUPQUOTAFILE_EXTENSION);
288 if (quota_file == NULL) {
289 DEBUG(0,("asprintf() failed!\n"));
294 ret = quotactl(QCMD(Q_QUOTAON,GRPQUOTA), (caddr_t)bdev, -1,(void *)quota_file);
301 ret = quotactl(QCMD(Q_QUOTAOFF,GRPQUOTA), (caddr_t)bdev, -1, (void *)0);
307 DEBUG(0,("sys_set_vfs_quota: ret(%d) errno(%d)[%s] uid(%d) bdev[%s]\n",
308 ret,errno,strerror(errno),id.gid,bdev));
310 if ((ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), (caddr_t)bdev, id.gid, (void *)&D))==0) {
311 oldqflags |= QUOTAS_DENY_DISK;
314 if (oldqflags == qflags) {
321 #endif /* HAVE_GROUP_QUOTA */
330 #else /* HAVE_QUOTACTL_4A */
331 void dummy_sysquotas_4A(void);
333 void dummy_sysquotas_4A(void){}
334 #endif /* HAVE_QUOTACTL_4A */