2 Unix SMB/CIFS implementation.
3 System QUOTA function wrappers
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_SYS_QUOTAS
26 #if defined(HAVE_QUOTACTL_4A)
28 /*#endif HAVE_QUOTACTL_4A */
29 #elif defined(HAVE_QUOTACTL_4B)
31 #error HAVE_QUOTACTL_4B not implemeted
33 /*#endif HAVE_QUOTACTL_4B */
34 #elif defined(HAVE_QUOTACTL_3)
36 #error HAVE_QUOTACTL_3 not implemented
38 /* #endif HAVE_QUOTACTL_3 */
39 #else /* NO_QUOTACTL_USED */
41 #endif /* NO_QUOTACTL_USED */
44 static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
52 /* find the block device file */
54 if (!path||!mntpath||!bdev||!fs)
55 smb_panic("sys_path_to_bdev: called with NULL pointer");
61 if ( sys_stat(path, &S) == -1 )
66 fp = setmntent(MOUNTED,"r");
68 while ((mnt = getmntent(fp))) {
69 if ( sys_stat(mnt->mnt_dir,&S) == -1 )
72 if (S.st_dev == devno) {
73 (*mntpath) = strdup(mnt->mnt_dir);
74 (*bdev) = strdup(mnt->mnt_fsname);
75 (*fs) = strdup(mnt->mnt_type);
76 if ((*mntpath)&&(*bdev)&&(*fs)) {
93 /* #endif HAVE_MNTENT */
94 #elif defined(HAVE_DEVNM)
96 /* we have this on HPUX, ... */
97 static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
103 if (!path||!mntpath||!bdev||!fs)
104 smb_panic("sys_path_to_bdev: called with NULL pointer");
110 /* find the block device file */
112 if ((ret=sys_stat(path, &S))!=0) {
116 if ((ret=devnm(S_IFBLK, S.st_dev, dev_disk, 256, 1))!=0) {
120 /* we should get the mntpath right...
121 * but I don't know how
124 (*mntpath) = strdup(path);
125 (*bdev) = strdup(dev_disk);
126 if ((*mntpath)&&(*bdev)) {
138 /* #endif HAVE_DEVNM */
140 /* we should fake this up...*/
141 static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
145 if (!path||!mntpath||!bdev||!fs)
146 smb_panic("sys_path_to_bdev: called with NULL pointer");
152 (*mntpath) = strdup(path);
164 /*********************************************************************
165 Now the list of all filesystem specific quota systems we have found
166 **********************************************************************/
169 int (*get_quota)(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
170 int (*set_quota)(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
171 } sys_quota_backends[] = {
172 #ifdef HAVE_XFS_QUOTAS
173 {"xfs", sys_get_xfs_quota, sys_set_xfs_quota},
174 #endif /* HAVE_XFS_QUOTAS */
178 static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
180 const char *get_quota_command;
182 get_quota_command = lp_get_quota_command();
183 if (get_quota_command && *get_quota_command) {
191 case SMB_USER_QUOTA_TYPE:
192 case SMB_USER_FS_QUOTA_TYPE:
195 case SMB_GROUP_QUOTA_TYPE:
196 case SMB_GROUP_FS_QUOTA_TYPE:
200 DEBUG(0,("invalid quota type.\n"));
204 slprintf(syscmd, sizeof(syscmd)-1,
206 get_quota_command, path, qtype, _id);
208 DEBUG (3, ("get_quota: Running command %s\n", syscmd));
210 lines = file_lines_pload(syscmd, NULL);
212 char *line = lines[0];
214 DEBUG (3, ("Read output from get_quota, \"%s\"\n", line));
216 /* we need to deal with long long unsigned here, if supported */
218 dp->qflags = (enum SMB_QUOTA_TYPE)strtoul(line, &p2, 10);
220 while (p && *p && isspace(*p))
223 dp->curblocks = STR_TO_SMB_BIG_UINT(p, &p);
226 while (p && *p && isspace(*p))
229 dp->softlimit = STR_TO_SMB_BIG_UINT(p, &p);
232 while (p && *p && isspace(*p))
235 dp->hardlimit = STR_TO_SMB_BIG_UINT(p, &p);
238 while (p && *p && isspace(*p))
241 dp->curinodes = STR_TO_SMB_BIG_UINT(p, &p);
244 while (p && *p && isspace(*p))
247 dp->isoftlimit = STR_TO_SMB_BIG_UINT(p, &p);
250 while (p && *p && isspace(*p))
253 dp->ihardlimit = STR_TO_SMB_BIG_UINT(p, &p);
256 while (p && *p && isspace(*p))
259 dp->bsize = STR_TO_SMB_BIG_UINT(p, NULL);
262 file_lines_free(lines);
263 DEBUG (3, ("Parsed output of get_quota, ...\n"));
265 #ifdef LARGE_SMB_OFF_T
267 "qflags:%u curblocks:%llu softlimit:%llu hardlimit:%llu\n"
268 "curinodes:%llu isoftlimit:%llu ihardlimit:%llu bsize:%llu\n",
269 dp->qflags,(long long unsigned)dp->curblocks,
270 (long long unsigned)dp->softlimit,(long long unsigned)dp->hardlimit,
271 (long long unsigned)dp->curinodes,
272 (long long unsigned)dp->isoftlimit,(long long unsigned)dp->ihardlimit,
273 (long long unsigned)dp->bsize));
274 #else /* LARGE_SMB_OFF_T */
276 "qflags:%u curblocks:%lu softlimit:%lu hardlimit:%lu\n"
277 "curinodes:%lu isoftlimit:%lu ihardlimit:%lu bsize:%lu\n",
278 dp->qflags,(long unsigned)dp->curblocks,
279 (long unsigned)dp->softlimit,(long unsigned)dp->hardlimit,
280 (long unsigned)dp->curinodes,
281 (long unsigned)dp->isoftlimit,(long unsigned)dp->ihardlimit,
282 (long unsigned)dp->bsize));
283 #endif /* LARGE_SMB_OFF_T */
287 DEBUG (0, ("get_quota_command failed!\n"));
295 DEBUG(0,("The output of get_quota_command is invalid!\n"));
299 static int command_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
301 const char *set_quota_command;
303 set_quota_command = lp_set_quota_command();
304 if (set_quota_command && *set_quota_command) {
310 case SMB_USER_QUOTA_TYPE:
311 case SMB_USER_FS_QUOTA_TYPE:
314 case SMB_GROUP_QUOTA_TYPE:
315 case SMB_GROUP_FS_QUOTA_TYPE:
322 #ifdef LARGE_SMB_OFF_T
323 slprintf(syscmd, sizeof(syscmd)-1,
327 set_quota_command, path, qtype, _id, dp->qflags,
328 (long long unsigned)dp->softlimit,(long long unsigned)dp->hardlimit,
329 (long long unsigned)dp->isoftlimit,(long long unsigned)dp->ihardlimit,
330 (long long unsigned)dp->bsize);
331 #else /* LARGE_SMB_OFF_T */
332 slprintf(syscmd, sizeof(syscmd)-1,
336 set_quota_command, path, qtype, _id, dp->qflags,
337 (long unsigned)dp->softlimit,(long unsigned)dp->hardlimit,
338 (long unsigned)dp->isoftlimit,(long unsigned)dp->ihardlimit,
339 (long unsigned)dp->bsize);
340 #endif /* LARGE_SMB_OFF_T */
344 DEBUG (3, ("get_quota: Running command %s\n", syscmd));
346 lines = file_lines_pload(syscmd, NULL);
348 char *line = lines[0];
350 DEBUG (3, ("Read output from set_quota, \"%s\"\n", line));
352 file_lines_free(lines);
356 DEBUG (0, ("set_quota_command failed!\n"));
364 int sys_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
369 char *mntpath = NULL;
374 smb_panic("sys_get_quota: called with NULL pointer");
376 if (command_get_quota(path, qtype, id, dp)==0) {
378 } else if (errno != ENOSYS) {
382 if ((ret=sys_path_to_bdev(path,&mntpath,&bdev,&fs))!=0) {
383 DEBUG(0,("sys_path_to_bdev() failed for path [%s]!\n",path));
387 for (i=0;(fs && sys_quota_backends[i].name && sys_quota_backends[i].get_quota);i++) {
388 if (strcmp(fs,sys_quota_backends[i].name)==0) {
389 ret = sys_quota_backends[i].get_quota(mntpath, bdev, qtype, id, dp);
391 DEBUG(10,("sys_get_%s_quota() failed for mntpath[%s] bdev[%s] qtype[%d] id[%d] ret[%d].\n",
392 fs,mntpath,bdev,qtype,(qtype==SMB_GROUP_QUOTA_TYPE?id.gid:id.uid),ret));
400 /* use the default vfs quota functions */
401 ret=sys_get_vfs_quota(mntpath, bdev, qtype, id, dp);
403 DEBUG(10,("sys_get_%s_quota() failed for mntpath[%s] bdev[%s] qtype[%d] id[%d] ret[%d].\n",
404 "vfs",mntpath,bdev,qtype,(qtype==SMB_GROUP_QUOTA_TYPE?id.gid:id.uid),ret));
412 if ((ret!=0)&& (errno == EDQUOT)) {
419 int sys_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
424 char *mntpath = NULL;
428 /* find the block device file */
431 smb_panic("get_smb_quota: called with NULL pointer");
433 if (command_set_quota(path, qtype, id, dp)==0) {
435 } else if (errno != ENOSYS) {
439 if ((ret=sys_path_to_bdev(path,&mntpath,&bdev,&fs))!=0) {
440 DEBUG(0,("sys_path_to_bdev() failed for path [%s]!\n",path));
444 for (i=0;(fs && sys_quota_backends[i].name && sys_quota_backends[i].set_quota);i++) {
445 if (strcmp(fs,sys_quota_backends[i].name)==0) {
446 ret = sys_quota_backends[i].set_quota(mntpath, bdev, qtype, id, dp);
448 DEBUG(10,("sys_set_%s_quota() failed for mntpath[%s] bdev[%s] qtype[%d] id[%d] ret[%d].\n",
449 fs,mntpath,bdev,qtype,(qtype==SMB_GROUP_QUOTA_TYPE?id.gid:id.uid),ret));
457 /* use the default vfs quota functions */
458 ret=sys_set_vfs_quota(mntpath, bdev, qtype, id, dp);
460 DEBUG(10,("sys_set_%s_quota() failed for mntpath[%s] bdev[%s] qtype[%d] id[%d] ret[%d].\n",
461 "vfs",mntpath,bdev,qtype,(qtype==SMB_GROUP_QUOTA_TYPE?id.gid:id.uid),ret));
469 if ((ret!=0)&& (errno == EDQUOT)) {
476 #else /* HAVE_SYS_QUOTAS */
477 void dummy_sysquotas_c(void)
481 #endif /* HAVE_SYS_QUOTAS */