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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #ifdef HAVE_QUOTACTL_4A
25 /* long quotactl(int cmd, char *special, qid_t id, caddr_t addr) */
26 /* this is used by: HPUX,IRIX */
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
32 #ifdef HAVE_ASM_TYPES_H
33 #include <asm/types.h>
36 #ifdef HAVE_SYS_QUOTA_H
37 #include <sys/quota.h>
41 #define Q_SETQLIM Q_SETQUOTA
53 #define HAVE_GROUP_QUOTA
56 #ifndef QUOTABLOCK_SIZE
57 #define QUOTABLOCK_SIZE DEV_BSIZE
60 #ifdef HAVE_DQB_FSOFTLIMIT
61 #define dqb_isoftlimit dqb_fsoftlimit
62 #define dqb_ihardlimit dqb_fhardlimit
63 #define dqb_curinodes dqb_curfiles
67 #define USERQUOTAFILE_EXTENSION ".user"
69 #define USERQUOTAFILE_EXTENSION ""
72 #if !defined(QUOTAFILENAME) && defined(QFILENAME)
73 #define QUOTAFILENAME QFILENAME
76 /****************************************************************************
77 Abstract out the quotactl_4A get calls.
78 ****************************************************************************/
79 int sys_get_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
84 SMB_BIG_UINT bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
91 case SMB_USER_QUOTA_TYPE:
92 if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), bdev, id.uid, (void *)&D))&&errno != EDQUOT) {
96 if ((D.dqb_curblocks==0)&&
97 (D.dqb_bsoftlimit==0)&&
98 (D.dqb_bhardlimit==0)) {
99 /* the upper layer functions don't want empty quota records...*/
104 #ifdef HAVE_GROUP_QUOTA
105 case SMB_GROUP_QUOTA_TYPE:
106 if ((ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), bdev, id.gid, (void *)&D))&&errno != EDQUOT) {
110 if ((D.dqb_curblocks==0)&&
111 (D.dqb_bsoftlimit==0)&&
112 (D.dqb_bhardlimit==0)) {
113 /* the upper layer functions don't want empty quota records...*/
118 #endif /* HAVE_GROUP_QUOTA */
119 case SMB_USER_FS_QUOTA_TYPE:
122 if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), bdev, id.uid, (void *)&D))==0) {
123 qflags |= QUOTAS_DENY_DISK;
128 #ifdef HAVE_GROUP_QUOTA
129 case SMB_GROUP_FS_QUOTA_TYPE:
132 if ((ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), bdev, id.gid, (void *)&D))==0) {
133 qflags |= QUOTAS_DENY_DISK;
138 #endif /* HAVE_GROUP_QUOTA */
145 dp->softlimit = (SMB_BIG_UINT)D.dqb_bsoftlimit;
146 dp->hardlimit = (SMB_BIG_UINT)D.dqb_bhardlimit;
147 dp->ihardlimit = (SMB_BIG_UINT)D.dqb_ihardlimit;
148 dp->isoftlimit = (SMB_BIG_UINT)D.dqb_isoftlimit;
149 dp->curinodes = (SMB_BIG_UINT)D.dqb_curinodes;
150 dp->curblocks = (SMB_BIG_UINT)D.dqb_curblocks;
158 /****************************************************************************
159 Abstract out the quotactl_4A set calls.
160 ****************************************************************************/
161 int sys_set_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
165 uint32 oldqflags = 0;
167 SMB_BIG_UINT bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
171 if (bsize == dp->bsize) {
172 D.dqb_bsoftlimit = dp->softlimit;
173 D.dqb_bhardlimit = dp->hardlimit;
174 D.dqb_ihardlimit = dp->ihardlimit;
175 D.dqb_isoftlimit = dp->isoftlimit;
177 D.dqb_bsoftlimit = (dp->softlimit*dp->bsize)/bsize;
178 D.dqb_bhardlimit = (dp->hardlimit*dp->bsize)/bsize;
179 D.dqb_ihardlimit = (dp->ihardlimit*dp->bsize)/bsize;
180 D.dqb_isoftlimit = (dp->isoftlimit*dp->bsize)/bsize;
186 case SMB_USER_QUOTA_TYPE:
187 ret = quotactl(QCMD(Q_SETQLIM,USRQUOTA), bdev, id.uid, (void *)&D);
189 #ifdef HAVE_GROUP_QUOTA
190 case SMB_GROUP_QUOTA_TYPE:
191 ret = quotactl(QCMD(Q_SETQLIM,GRPQUOTA), bdev, id.gid, (void *)&D);
193 #endif /* HAVE_GROUP_QUOTA */
194 case SMB_USER_FS_QUOTA_TYPE:
195 /* this stuff didn't work as it should:
196 * switching on/off quota via quotactl()
198 * So we just return 0
201 * On HPUX we didn't have the mount path,
202 * we need to fix sys_path_to_bdev()
208 ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), bdev, id.uid, (void *)&D);
210 if ((qflags"AS_DENY_DISK)||(qflags"AS_ENABLED)) {
212 char *quota_file = NULL;
214 asprintf("a_file,"/%s/%s%s",path, QUOTAFILENAME,USERQUOTAFILE_EXTENSION);
215 if (quota_file == NULL) {
216 DEBUG(0,("asprintf() failed!\n"));
221 ret = quotactl(QCMD(Q_QUOTAON,USRQUOTA), bdev, -1,(void *)quota_file);
228 ret = quotactl(QCMD(Q_QUOTAOFF,USRQUOTA), bdev, -1, (void *)0);
234 DEBUG(0,("vfs_fs_quota: ret(%d) errno(%d)[%s] uid(%d) bdev[%s]\n",
235 ret,errno,strerror(errno),id.uid,bdev));
239 if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), bdev, id.uid, (void *)&D))==0) {
240 oldqflags |= QUOTAS_DENY_DISK;
243 if (oldqflags == qflags) {
250 #ifdef HAVE_GROUP_QUOTA
251 case SMB_GROUP_FS_QUOTA_TYPE:
252 /* this stuff didn't work as it should:
253 * switching on/off quota via quotactl()
255 * So we just return 0
258 * On HPUX we didn't have the mount path,
259 * we need to fix sys_path_to_bdev()
265 ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), bdev, id, (void *)&D);
267 if ((qflags"AS_DENY_DISK)||(qflags"AS_ENABLED)) {
269 char *quota_file = NULL;
271 asprintf("a_file,"/%s/%s%s",path, QUOTAFILENAME,GROUPQUOTAFILE_EXTENSION);
272 if (quota_file == NULL) {
273 DEBUG(0,("asprintf() failed!\n"));
278 ret = quotactl(QCMD(Q_QUOTAON,GRPQUOTA), bdev, -1,(void *)quota_file);
285 ret = quotactl(QCMD(Q_QUOTAOFF,GRPQUOTA), bdev, -1, (void *)0);
291 DEBUG(0,("vfs_fs_quota: ret(%d) errno(%d)[%s] uid(%d) bdev[%s]\n",
292 ret,errno,strerror(errno),id.gid,bdev));
296 if ((ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), bdev, id.gid, (void *)&D))==0) {
297 oldqflags |= QUOTAS_DENY_DISK;
300 if (oldqflags == qflags) {
307 #endif /* HAVE_GROUP_QUOTA */
316 #else /* HAVE_QUOTACTL_4A */
317 void dummy_sysquotas_4A(void){}
318 #endif /* HAVE_QUOTACTL_4A */