2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1992-1998
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/>.
22 * This is one of the most system dependent parts of Samba, and its
23 * done a litle differently. Each system has its own way of doing
28 #include "smbd/smbd.h"
29 #include "system/filesys.h"
32 #define DBGC_CLASS DBGC_QUOTA
34 #ifndef HAVE_SYS_QUOTAS
36 /* just a quick hack because sysquotas.h is included before linux/quota.h */
37 #ifdef QUOTABLOCK_SIZE
38 #undef QUOTABLOCK_SIZE
43 #if defined(VXFS_QUOTA)
46 * In addition to their native filesystems, some systems have Veritas VxFS.
47 * Declare here, define at end: reduces likely "include" interaction problems.
48 * David Lee <T.D.Lee@durham.ac.uk>
50 bool disk_quotas_vxfs(const char *name
, char *path
, uint64_t *bsize
, uint64_t *dfree
, uint64_t *dsize
);
52 #endif /* VXFS_QUOTA */
56 #include <sys/types.h>
60 * This shouldn't be neccessary - it should be /usr/include/sys/quota.h
61 * So we include all the files has *should* be in the system into a large,
62 * grungy samba_linux_quoatas.h Sometimes I *hate* Linux :-). JRA.
65 #include "samba_linux_quota.h"
67 typedef struct _LINUX_SMB_DISK_QUOTA
{
69 uint64_t hardlimit
; /* In bsize units. */
70 uint64_t softlimit
; /* In bsize units. */
71 uint64_t curblocks
; /* In bsize units. */
72 uint64_t ihardlimit
; /* inode hard limit. */
73 uint64_t isoftlimit
; /* inode soft limit. */
74 uint64_t curinodes
; /* Current used inodes. */
75 } LINUX_SMB_DISK_QUOTA
;
80 * (essentially taken from FreeBSD / SUNOS5 section)
83 #include <rpc/types.h>
84 #include <rpcsvc/rquota.h>
85 #ifdef HAVE_RPC_NETTYPE_H
86 #include <rpc/nettype.h>
90 static int my_xdr_getquota_args(XDR
*xdrsp
, struct getquota_args
*args
)
92 if (!xdr_string(xdrsp
, &args
->gqa_pathp
, RQ_PATHLEN
))
94 if (!xdr_int(xdrsp
, &args
->gqa_uid
))
99 static int my_xdr_getquota_rslt(XDR
*xdrsp
, struct getquota_rslt
*gqr
)
103 if (!xdr_int(xdrsp
, "astat
)) {
104 DEBUG(6,("nfs_quotas: Status bad or zero\n"));
107 gqr
->status
= quotastat
;
109 if (!xdr_int(xdrsp
, &gqr
->getquota_rslt_u
.gqr_rquota
.rq_bsize
)) {
110 DEBUG(6,("nfs_quotas: Block size bad or zero\n"));
113 if (!xdr_bool(xdrsp
, &gqr
->getquota_rslt_u
.gqr_rquota
.rq_active
)) {
114 DEBUG(6,("nfs_quotas: Active bad or zero\n"));
117 if (!xdr_int(xdrsp
, (int *)&gqr
->getquota_rslt_u
.gqr_rquota
.rq_bhardlimit
)) {
118 DEBUG(6,("nfs_quotas: Hardlimit bad or zero\n"));
121 if (!xdr_int(xdrsp
, (int *)&gqr
->getquota_rslt_u
.gqr_rquota
.rq_bsoftlimit
)) {
122 DEBUG(6,("nfs_quotas: Softlimit bad or zero\n"));
125 if (!xdr_int(xdrsp
, (int *)&gqr
->getquota_rslt_u
.gqr_rquota
.rq_curblocks
)) {
126 DEBUG(6,("nfs_quotas: Currentblocks bad or zero\n"));
132 static bool nfs_quotas(char *nfspath
, uid_t euser_id
, uint64_t *bsize
,
133 uint64_t *dfree
, uint64_t *dsize
)
135 uid_t uid
= euser_id
;
136 LINUX_SMB_DISK_QUOTA D
;
137 char *mnttype
= nfspath
;
139 struct getquota_rslt gqr
;
140 struct getquota_args args
;
141 char *cutstr
, *pathname
, *host
, *testpath
;
143 static struct timeval timeout
= {2,0};
144 enum clnt_stat clnt_stat
;
147 *bsize
= *dfree
= *dsize
= (uint64_t)0;
149 len
=strcspn(mnttype
, ":");
150 pathname
=strstr(mnttype
, ":");
151 cutstr
= (char *) SMB_MALLOC(len
+1);
155 memset(cutstr
, '\0', len
+1);
156 host
= strncat(cutstr
,mnttype
, sizeof(char) * len
);
157 DEBUG(5,("nfs_quotas: looking for mount on \"%s\"\n", cutstr
));
158 DEBUG(5,("nfs_quotas: of path \"%s\"\n", mnttype
));
159 testpath
=strchr_m(mnttype
, ':');
160 args
.gqa_pathp
= testpath
+1;
163 DEBUG(5, ("nfs_quotas: Asking for host \"%s\" rpcprog \"%i\" rpcvers "
164 "\"%i\" network \"%s\"\n", host
, RQUOTAPROG
, RQUOTAVERS
,
167 if ((clnt
= clnt_create(host
, RQUOTAPROG
, RQUOTAVERS
, "udp")) == NULL
) {
172 clnt
->cl_auth
= authunix_create_default();
173 DEBUG(9,("nfs_quotas: auth_success\n"));
175 clnt_stat
=clnt_call(clnt
,
177 (const xdrproc_t
)my_xdr_getquota_args
,
179 (const xdrproc_t
)my_xdr_getquota_rslt
,
180 (caddr_t
)&gqr
, timeout
);
182 if (clnt_stat
!= RPC_SUCCESS
) {
183 DEBUG(9,("nfs_quotas: clnt_call fail\n"));
189 * gqr.status returns 0 if the rpc call fails, 1 if quotas exist, 2 if there is
190 * no quota set, and 3 if no permission to get the quota. If 0 or 3 return
191 * something sensible.
194 switch (gqr
.status
) {
196 DEBUG(9, ("nfs_quotas: Remote Quotas Failed! Error \"%i\" \n",
202 DEBUG(9,("nfs_quotas: Good quota data\n"));
203 D
.softlimit
= gqr
.getquota_rslt_u
.gqr_rquota
.rq_bsoftlimit
;
204 D
.hardlimit
= gqr
.getquota_rslt_u
.gqr_rquota
.rq_bhardlimit
;
205 D
.curblocks
= gqr
.getquota_rslt_u
.gqr_rquota
.rq_curblocks
;
212 DEBUG(9, ("nfs_quotas: Remote Quotas returned \"%i\" \n",
217 DEBUG(9, ("nfs_quotas: Remote Quotas Questionable! "
218 "Error \"%i\" \n", gqr
.status
));
222 DEBUG(10, ("nfs_quotas: Let`s look at D a bit closer... "
223 "status \"%i\" bsize \"%i\" active? \"%i\" bhard "
224 "\"%i\" bsoft \"%i\" curb \"%i\" \n",
226 gqr
.getquota_rslt_u
.gqr_rquota
.rq_bsize
,
227 gqr
.getquota_rslt_u
.gqr_rquota
.rq_active
,
228 gqr
.getquota_rslt_u
.gqr_rquota
.rq_bhardlimit
,
229 gqr
.getquota_rslt_u
.gqr_rquota
.rq_bsoftlimit
,
230 gqr
.getquota_rslt_u
.gqr_rquota
.rq_curblocks
));
232 if (D
.softlimit
== 0)
233 D
.softlimit
= D
.hardlimit
;
234 if (D
.softlimit
== 0)
237 *bsize
= gqr
.getquota_rslt_u
.gqr_rquota
.rq_bsize
;
238 *dsize
= D
.softlimit
;
240 if (D
.curblocks
== 1)
243 if (D
.curblocks
> D
.softlimit
) {
245 *dsize
= D
.curblocks
;
247 *dfree
= D
.softlimit
- D
.curblocks
;
253 auth_destroy(clnt
->cl_auth
);
257 DEBUG(5, ("nfs_quotas: For path \"%s\" returning "
258 "bsize %.0f, dfree %.0f, dsize %.0f\n",
259 args
.gqa_pathp
, (double)*bsize
, (double)*dfree
,
263 DEBUG(10,("nfs_quotas: End of nfs_quotas\n" ));
267 /* end of nfs quota section */
269 #ifdef HAVE_LINUX_DQBLK_XFS_H
270 #include <linux/dqblk_xfs.h>
272 /****************************************************************************
273 Abstract out the XFS Quota Manager quota get call.
274 ****************************************************************************/
276 static int get_smb_linux_xfs_quota(char *path
, uid_t euser_id
, gid_t egrp_id
, LINUX_SMB_DISK_QUOTA
*dp
)
278 struct fs_disk_quota D
;
283 ret
= quotactl(QCMD(Q_XGETQUOTA
,USRQUOTA
), path
, euser_id
, (caddr_t
)&D
);
286 ret
= quotactl(QCMD(Q_XGETQUOTA
,GRPQUOTA
), path
, egrp_id
, (caddr_t
)&D
);
291 dp
->bsize
= (uint64_t)512;
292 dp
->softlimit
= (uint64_t)D
.d_blk_softlimit
;
293 dp
->hardlimit
= (uint64_t)D
.d_blk_hardlimit
;
294 dp
->ihardlimit
= (uint64_t)D
.d_ino_hardlimit
;
295 dp
->isoftlimit
= (uint64_t)D
.d_ino_softlimit
;
296 dp
->curinodes
= (uint64_t)D
.d_icount
;
297 dp
->curblocks
= (uint64_t)D
.d_bcount
;
302 static int get_smb_linux_xfs_quota(char *path
, uid_t euser_id
, gid_t egrp_id
, LINUX_SMB_DISK_QUOTA
*dp
)
304 DEBUG(0,("XFS quota support not available\n"));
311 /****************************************************************************
312 Abstract out the old and new Linux quota get calls.
313 ****************************************************************************/
315 static int get_smb_linux_v1_quota(char *path
, uid_t euser_id
, gid_t egrp_id
, LINUX_SMB_DISK_QUOTA
*dp
)
317 struct v1_kern_dqblk D
;
322 ret
= quotactl(QCMD(Q_V1_GETQUOTA
,USRQUOTA
), path
, euser_id
, (caddr_t
)&D
);
324 if (ret
&& errno
!= EDQUOT
)
325 ret
= quotactl(QCMD(Q_V1_GETQUOTA
,GRPQUOTA
), path
, egrp_id
, (caddr_t
)&D
);
327 if (ret
&& errno
!= EDQUOT
)
330 dp
->bsize
= (uint64_t)QUOTABLOCK_SIZE
;
331 dp
->softlimit
= (uint64_t)D
.dqb_bsoftlimit
;
332 dp
->hardlimit
= (uint64_t)D
.dqb_bhardlimit
;
333 dp
->ihardlimit
= (uint64_t)D
.dqb_ihardlimit
;
334 dp
->isoftlimit
= (uint64_t)D
.dqb_isoftlimit
;
335 dp
->curinodes
= (uint64_t)D
.dqb_curinodes
;
336 dp
->curblocks
= (uint64_t)D
.dqb_curblocks
;
341 static int get_smb_linux_v2_quota(char *path
, uid_t euser_id
, gid_t egrp_id
, LINUX_SMB_DISK_QUOTA
*dp
)
343 struct v2_kern_dqblk D
;
348 ret
= quotactl(QCMD(Q_V2_GETQUOTA
,USRQUOTA
), path
, euser_id
, (caddr_t
)&D
);
350 if (ret
&& errno
!= EDQUOT
)
351 ret
= quotactl(QCMD(Q_V2_GETQUOTA
,GRPQUOTA
), path
, egrp_id
, (caddr_t
)&D
);
353 if (ret
&& errno
!= EDQUOT
)
356 dp
->bsize
= (uint64_t)QUOTABLOCK_SIZE
;
357 dp
->softlimit
= (uint64_t)D
.dqb_bsoftlimit
;
358 dp
->hardlimit
= (uint64_t)D
.dqb_bhardlimit
;
359 dp
->ihardlimit
= (uint64_t)D
.dqb_ihardlimit
;
360 dp
->isoftlimit
= (uint64_t)D
.dqb_isoftlimit
;
361 dp
->curinodes
= (uint64_t)D
.dqb_curinodes
;
362 dp
->curblocks
= ((uint64_t)D
.dqb_curspace
) / dp
->bsize
;
367 /****************************************************************************
368 Brand-new generic quota interface.
369 ****************************************************************************/
371 static int get_smb_linux_gen_quota(char *path
, uid_t euser_id
, gid_t egrp_id
, LINUX_SMB_DISK_QUOTA
*dp
)
378 ret
= quotactl(QCMD(Q_GETQUOTA
,USRQUOTA
), path
, euser_id
, (caddr_t
)&D
);
380 if (ret
&& errno
!= EDQUOT
)
381 ret
= quotactl(QCMD(Q_GETQUOTA
,GRPQUOTA
), path
, egrp_id
, (caddr_t
)&D
);
383 if (ret
&& errno
!= EDQUOT
)
386 dp
->bsize
= (uint64_t)QUOTABLOCK_SIZE
;
387 dp
->softlimit
= (uint64_t)D
.dqb_bsoftlimit
;
388 dp
->hardlimit
= (uint64_t)D
.dqb_bhardlimit
;
389 dp
->ihardlimit
= (uint64_t)D
.dqb_ihardlimit
;
390 dp
->isoftlimit
= (uint64_t)D
.dqb_isoftlimit
;
391 dp
->curinodes
= (uint64_t)D
.dqb_curinodes
;
392 dp
->curblocks
= ((uint64_t)D
.dqb_curspace
) / dp
->bsize
;
397 /****************************************************************************
398 Try to get the disk space from disk quotas (LINUX version).
399 ****************************************************************************/
401 bool disk_quotas(const char *path
, uint64_t *bsize
, uint64_t *dfree
, uint64_t *dsize
)
406 LINUX_SMB_DISK_QUOTA D
;
415 euser_id
= geteuid();
418 /* find the block device file */
420 if (sys_stat(path
, &S
, false) == -1 )
423 devno
= S
.st_ex_dev
;
425 if ((fp
= setmntent(MOUNTED
,"r")) == NULL
)
430 while ((mnt
= getmntent(fp
))) {
431 if (sys_stat(mnt
->mnt_dir
, &S
, false) == -1)
434 if (S
.st_ex_dev
== devno
) {
447 if (strcmp(mnt
->mnt_type
, "nfs") == 0) {
449 retval
= nfs_quotas(mnt
->mnt_fsname
, euser_id
, bsize
, dfree
, dsize
);
454 if (strcmp(mnt
->mnt_type
, "xfs")==0) {
455 r
=get_smb_linux_xfs_quota(mnt
->mnt_fsname
, euser_id
, egrp_id
, &D
);
457 r
=get_smb_linux_gen_quota(mnt
->mnt_fsname
, euser_id
, egrp_id
, &D
);
458 if (r
== -1 && errno
!= EDQUOT
) {
459 r
=get_smb_linux_v2_quota(mnt
->mnt_fsname
, euser_id
, egrp_id
, &D
);
460 if (r
== -1 && errno
!= EDQUOT
)
461 r
=get_smb_linux_v1_quota(mnt
->mnt_fsname
, euser_id
, egrp_id
, &D
);
467 /* Use softlimit to determine disk space, except when it has been exceeded */
470 if (errno
== EDQUOT
) {
479 /* Use softlimit to determine disk space, except when it has been exceeded */
481 (D
.softlimit
&& D
.curblocks
>= D
.softlimit
) ||
482 (D
.hardlimit
&& D
.curblocks
>= D
.hardlimit
) ||
483 (D
.isoftlimit
&& D
.curinodes
>= D
.isoftlimit
) ||
484 (D
.ihardlimit
&& D
.curinodes
>=D
.ihardlimit
)
487 *dsize
= D
.curblocks
;
488 } else if (D
.softlimit
==0 && D
.hardlimit
==0) {
491 if (D
.softlimit
== 0)
492 D
.softlimit
= D
.hardlimit
;
493 *dfree
= D
.softlimit
- D
.curblocks
;
494 *dsize
= D
.softlimit
;
502 #include <sys/quota.h>
505 /****************************************************************************
506 try to get the disk space from disk quotas (CRAY VERSION)
507 ****************************************************************************/
509 bool disk_quotas(const char *path
, uint64_t *bsize
, uint64_t *dfree
, uint64_t *dsize
)
513 SMB_STRUCT_STAT sbuf
;
515 struct q_request request
;
516 struct qf_header header
;
517 int quota_default
= 0 ;
520 if (sys_stat(path
, &sbuf
, false) == -1) {
524 devno
= sbuf
.st_ex_dev
;
526 if ((fd
= setmntent(KMTAB
)) == NULL
) {
530 while ((mnt
= getmntent(fd
)) != NULL
) {
531 if (sys_stat(mnt
->mnt_dir
, &sbuf
, false) == -1) {
534 if (sbuf
.st_ex_dev
== devno
) {
540 name
= talloc_strdup(talloc_tos(), mnt
->mnt_dir
);
550 request
.qf_magic
= QF_MAGIC
;
551 request
.qf_entry
.id
= geteuid() ;
553 if (quotactl(name
, Q_GETQUOTA
, &request
) == -1) {
561 if (request
.qf_entry
.user_q
.f_quota
== QFV_DEFAULT
) {
562 if (!quota_default
) {
563 if (quotactl(name
, Q_GETHEADER
, &header
) == -1) {
566 quota_default
= header
.user_h
.def_fq
;
569 *dfree
= quota_default
;
570 } else if (request
.qf_entry
.user_q
.f_quota
== QFV_PREVENT
) {
573 *dfree
= request
.qf_entry
.user_q
.f_quota
;
576 *dsize
= request
.qf_entry
.user_q
.f_use
;
578 if (*dfree
< *dsize
) {
584 *bsize
= 4096 ; /* Cray blocksize */
589 #elif defined(SUNOS5) || defined(SUNOS4)
592 #include <sys/param.h>
594 #include <sys/fs/ufs_quota.h>
595 #include <sys/mnttab.h>
596 #include <sys/mntent.h>
597 #else /* defined(SUNOS4) */
598 #include <ufs/quota.h>
604 /****************************************************************************
605 Allows querying of remote hosts for quotas on NFS mounted shares.
606 Supports normal NFS and AMD mounts.
607 Alan Romeril <a.romeril@ic.ac.uk> July 2K.
608 ****************************************************************************/
611 #include <rpc/types.h>
612 #include <rpcsvc/rquota.h>
613 #include <rpc/nettype.h>
616 static int my_xdr_getquota_args(XDR
*xdrsp
, struct getquota_args
*args
)
618 if (!xdr_string(xdrsp
, &args
->gqa_pathp
, RQ_PATHLEN
))
620 if (!xdr_int(xdrsp
, &args
->gqa_uid
))
625 static int my_xdr_getquota_rslt(XDR
*xdrsp
, struct getquota_rslt
*gqr
)
629 if (!xdr_int(xdrsp
, "astat
)) {
630 DEBUG(6,("nfs_quotas: Status bad or zero\n"));
633 gqr
->status
= quotastat
;
635 if (!xdr_int(xdrsp
, &gqr
->getquota_rslt_u
.gqr_rquota
.rq_bsize
)) {
636 DEBUG(6,("nfs_quotas: Block size bad or zero\n"));
639 if (!xdr_bool(xdrsp
, &gqr
->getquota_rslt_u
.gqr_rquota
.rq_active
)) {
640 DEBUG(6,("nfs_quotas: Active bad or zero\n"));
643 if (!xdr_int(xdrsp
, &gqr
->getquota_rslt_u
.gqr_rquota
.rq_bhardlimit
)) {
644 DEBUG(6,("nfs_quotas: Hardlimit bad or zero\n"));
647 if (!xdr_int(xdrsp
, &gqr
->getquota_rslt_u
.gqr_rquota
.rq_bsoftlimit
)) {
648 DEBUG(6,("nfs_quotas: Softlimit bad or zero\n"));
651 if (!xdr_int(xdrsp
, &gqr
->getquota_rslt_u
.gqr_rquota
.rq_curblocks
)) {
652 DEBUG(6,("nfs_quotas: Currentblocks bad or zero\n"));
658 /* Restricted to SUNOS5 for the moment, I haven`t access to others to test. */
659 static bool nfs_quotas(char *nfspath
, uid_t euser_id
, uint64_t *bsize
, uint64_t *dfree
, uint64_t *dsize
)
661 uid_t uid
= euser_id
;
663 char *mnttype
= nfspath
;
665 struct getquota_rslt gqr
;
666 struct getquota_args args
;
667 char *cutstr
, *pathname
, *host
, *testpath
;
669 static struct timeval timeout
= {2,0};
670 enum clnt_stat clnt_stat
;
673 *bsize
= *dfree
= *dsize
= (uint64_t)0;
675 len
=strcspn(mnttype
, ":");
676 pathname
=strstr(mnttype
, ":");
677 cutstr
= (char *) SMB_MALLOC(len
+1);
681 memset(cutstr
, '\0', len
+1);
682 host
= strncat(cutstr
,mnttype
, sizeof(char) * len
);
683 DEBUG(5,("nfs_quotas: looking for mount on \"%s\"\n", cutstr
));
684 DEBUG(5,("nfs_quotas: of path \"%s\"\n", mnttype
));
685 testpath
=strchr_m(mnttype
, ':');
686 args
.gqa_pathp
= testpath
+1;
689 DEBUG(5,("nfs_quotas: Asking for host \"%s\" rpcprog \"%i\" rpcvers \"%i\" network \"%s\"\n", host
, RQUOTAPROG
, RQUOTAVERS
, "udp"));
691 if ((clnt
= clnt_create(host
, RQUOTAPROG
, RQUOTAVERS
, "udp")) == NULL
) {
696 clnt
->cl_auth
= authunix_create_default();
697 DEBUG(9,("nfs_quotas: auth_success\n"));
699 clnt_stat
=clnt_call(clnt
, RQUOTAPROC_GETQUOTA
, my_xdr_getquota_args
, (caddr_t
)&args
, my_xdr_getquota_rslt
, (caddr_t
)&gqr
, timeout
);
701 if (clnt_stat
!= RPC_SUCCESS
) {
702 DEBUG(9,("nfs_quotas: clnt_call fail\n"));
708 * gqr.status returns 0 if the rpc call fails, 1 if quotas exist, 2 if there is
709 * no quota set, and 3 if no permission to get the quota. If 0 or 3 return
710 * something sensible.
713 switch (gqr
.status
) {
715 DEBUG(9,("nfs_quotas: Remote Quotas Failed! Error \"%i\" \n", gqr
.status
));
720 DEBUG(9,("nfs_quotas: Good quota data\n"));
721 D
.dqb_bsoftlimit
= gqr
.getquota_rslt_u
.gqr_rquota
.rq_bsoftlimit
;
722 D
.dqb_bhardlimit
= gqr
.getquota_rslt_u
.gqr_rquota
.rq_bhardlimit
;
723 D
.dqb_curblocks
= gqr
.getquota_rslt_u
.gqr_rquota
.rq_curblocks
;
728 D
.dqb_bsoftlimit
= 1;
730 DEBUG(9,("nfs_quotas: Remote Quotas returned \"%i\" \n", gqr
.status
));
734 DEBUG(9,("nfs_quotas: Remote Quotas Questionable! Error \"%i\" \n", gqr
.status
));
738 DEBUG(10,("nfs_quotas: Let`s look at D a bit closer... status \"%i\" bsize \"%i\" active? \"%i\" bhard \"%i\" bsoft \"%i\" curb \"%i\" \n",
740 gqr
.getquota_rslt_u
.gqr_rquota
.rq_bsize
,
741 gqr
.getquota_rslt_u
.gqr_rquota
.rq_active
,
742 gqr
.getquota_rslt_u
.gqr_rquota
.rq_bhardlimit
,
743 gqr
.getquota_rslt_u
.gqr_rquota
.rq_bsoftlimit
,
744 gqr
.getquota_rslt_u
.gqr_rquota
.rq_curblocks
));
746 *bsize
= gqr
.getquota_rslt_u
.gqr_rquota
.rq_bsize
;
747 *dsize
= D
.dqb_bsoftlimit
;
749 if (D
.dqb_curblocks
> D
.dqb_bsoftlimit
) {
751 *dsize
= D
.dqb_curblocks
;
753 *dfree
= D
.dqb_bsoftlimit
- D
.dqb_curblocks
;
759 auth_destroy(clnt
->cl_auth
);
763 DEBUG(5,("nfs_quotas: For path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n",args
.gqa_pathp
,(double)*bsize
,(double)*dfree
,(double)*dsize
));
766 DEBUG(10,("nfs_quotas: End of nfs_quotas\n" ));
771 /****************************************************************************
772 try to get the disk space from disk quotas (SunOS & Solaris2 version)
773 Quota code by Peter Urbanec (amiga@cse.unsw.edu.au).
774 ****************************************************************************/
776 bool disk_quotas(const char *path
,
785 struct quotctl command
;
793 SMB_STRUCT_STAT sbuf
;
797 euser_id
= geteuid();
799 if (sys_stat(path
, &sbuf
, false) == -1) {
803 devno
= sbuf
.st_ex_dev
;
804 DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%x\n",
805 path
, (unsigned int)devno
));
807 if ((fd
= sys_fopen(MNTTAB
, "r")) == NULL
) {
811 while (getmntent(fd
, &mnt
) == 0) {
812 if (sys_stat(mnt
.mnt_mountp
, &sbuf
, false) == -1) {
816 DEBUG(5,("disk_quotas: testing \"%s\" devno=%x\n",
817 mnt
.mnt_mountp
, (unsigned int)devno
));
819 /* quotas are only on vxfs, UFS or NFS */
820 if ((sbuf
.st_ex_dev
== devno
) && (
821 strcmp( mnt
.mnt_fstype
, MNTTYPE_UFS
) == 0 ||
822 strcmp( mnt
.mnt_fstype
, "nfs" ) == 0 ||
823 strcmp( mnt
.mnt_fstype
, "vxfs" ) == 0 )) {
825 name
= talloc_asprintf(talloc_tos(),
834 if ((fd
= setmntent(MOUNTED
, "r")) == NULL
) {
838 while ((mnt
= getmntent(fd
)) != NULL
) {
839 if (sys_stat(mnt
->mnt_dir
, &sbuf
, false) == -1) {
842 DEBUG(5,("disk_quotas: testing \"%s\" devno=%x\n",
844 (unsigned int)sbuf
.st_ex_dev
));
845 if (sbuf
.st_ex_dev
== devno
) {
847 name
= talloc_strdup(talloc_tos(),
865 if (strcmp(mnt
.mnt_fstype
, "nfs") == 0) {
867 DEBUG(5,("disk_quotas: looking for mountpath (NFS) \"%s\"\n",
869 retval
= nfs_quotas(mnt
.mnt_special
,
870 euser_id
, bsize
, dfree
, dsize
);
875 DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name
));
876 if((file
=sys_open(name
, O_RDONLY
,0))<0) {
880 command
.op
= Q_GETQUOTA
;
881 command
.uid
= euser_id
;
882 command
.addr
= (caddr_t
) &D
;
883 ret
= ioctl(file
, Q_QUOTACTL
, &command
);
886 DEBUG(5,("disk_quotas: trying quotactl on device \"%s\"\n", name
));
887 ret
= quotactl(Q_GETQUOTA
, name
, euser_id
, &D
);
893 DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n",
896 #if defined(SUNOS5) && defined(VXFS_QUOTA)
897 /* If normal quotactl() fails, try vxfs private calls */
898 set_effective_uid(euser_id
);
899 DEBUG(5,("disk_quotas: mount type \"%s\"\n", mnt
.mnt_fstype
));
900 if ( 0 == strcmp ( mnt
.mnt_fstype
, "vxfs" )) {
902 retval
= disk_quotas_vxfs(name
, path
,
903 bsize
, dfree
, dsize
);
911 /* If softlimit is zero, set it equal to hardlimit.
914 if (D
.dqb_bsoftlimit
==0) {
915 D
.dqb_bsoftlimit
= D
.dqb_bhardlimit
;
918 /* Use softlimit to determine disk space. A user exceeding the quota
919 * is told that there's no space left. Writes might actually work for
920 * a bit if the hardlimit is set higher than softlimit. Effectively
921 * the disk becomes made of rubber latex and begins to expand to
922 * accommodate the user :-)
925 if (D
.dqb_bsoftlimit
==0)
928 *dsize
= D
.dqb_bsoftlimit
;
930 if (D
.dqb_curblocks
> D
.dqb_bsoftlimit
) {
932 *dsize
= D
.dqb_curblocks
;
934 *dfree
= D
.dqb_bsoftlimit
- D
.dqb_curblocks
;
937 DEBUG(5,("disk_quotas for path \"%s\" returning "
938 "bsize %.0f, dfree %.0f, dsize %.0f\n",
939 path
,(double)*bsize
,(double)*dfree
,(double)*dsize
));
946 #include <ufs/quota.h>
948 /****************************************************************************
949 try to get the disk space from disk quotas - OSF1 version
950 ****************************************************************************/
952 bool disk_quotas(const char *path
, uint64_t *bsize
, uint64_t *dfree
, uint64_t *dsize
)
960 * This code presumes that OSF1 will only
961 * give out quota info when the real uid
962 * matches the effective uid. JRA.
964 euser_id
= geteuid();
966 if (set_re_uid() != 0) return False
;
968 r
= quotactl(path
,QCMD(Q_GETQUOTA
, USRQUOTA
),euser_id
,(char *) &D
);
979 if (save_errno
== EDQUOT
) /* disk quota exceeded */
982 *dsize
= D
.dqb_curblocks
;
989 /* If softlimit is zero, set it equal to hardlimit.
992 if (D
.dqb_bsoftlimit
==0)
993 D
.dqb_bsoftlimit
= D
.dqb_bhardlimit
;
995 /* Use softlimit to determine disk space, except when it has been exceeded */
997 if (D
.dqb_bsoftlimit
==0)
1000 if ((D
.dqb_curblocks
>D
.dqb_bsoftlimit
)) {
1002 *dsize
= D
.dqb_curblocks
;
1004 *dfree
= D
.dqb_bsoftlimit
- D
.dqb_curblocks
;
1005 *dsize
= D
.dqb_bsoftlimit
;
1010 #elif defined (IRIX6)
1011 /****************************************************************************
1012 try to get the disk space from disk quotas (IRIX 6.2 version)
1013 ****************************************************************************/
1015 #include <sys/quota.h>
1018 bool disk_quotas(const char *path
, uint64_t *bsize
, uint64_t *dfree
, uint64_t *dsize
)
1023 struct fs_disk_quota F
;
1030 /* find the block device file */
1032 if ( sys_stat(path
, &S
, false) == -1 ) {
1036 devno
= S
.st_ex_dev
;
1038 fp
= setmntent(MOUNTED
,"r");
1041 while ((mnt
= getmntent(fp
))) {
1042 if ( sys_stat(mnt
->mnt_dir
, &S
, false) == -1 )
1044 if (S
.st_ex_dev
== devno
) {
1058 /* Use softlimit to determine disk space, except when it has been exceeded */
1062 if ( 0 == strcmp ( mnt
->mnt_type
, "efs" ))
1064 r
=quotactl (Q_GETQUOTA
, mnt
->mnt_fsname
, euser_id
, (caddr_t
) &D
);
1071 /* Use softlimit to determine disk space, except when it has been exceeded */
1073 (D
.dqb_bsoftlimit
&& D
.dqb_curblocks
>=D
.dqb_bsoftlimit
) ||
1074 (D
.dqb_bhardlimit
&& D
.dqb_curblocks
>=D
.dqb_bhardlimit
) ||
1075 (D
.dqb_fsoftlimit
&& D
.dqb_curfiles
>=D
.dqb_fsoftlimit
) ||
1076 (D
.dqb_fhardlimit
&& D
.dqb_curfiles
>=D
.dqb_fhardlimit
)
1080 *dsize
= D
.dqb_curblocks
;
1082 else if (D
.dqb_bsoftlimit
==0 && D
.dqb_bhardlimit
==0)
1088 *dfree
= D
.dqb_bsoftlimit
- D
.dqb_curblocks
;
1089 *dsize
= D
.dqb_bsoftlimit
;
1093 else if ( 0 == strcmp ( mnt
->mnt_type
, "xfs" ))
1095 r
=quotactl (Q_XGETQUOTA
, mnt
->mnt_fsname
, euser_id
, (caddr_t
) &F
);
1101 DEBUG(5, ("quotactl for uid=%u: %s", euser_id
, strerror(errno
)));
1105 /* No quota for this user. */
1106 if (F
.d_blk_softlimit
==0 && F
.d_blk_hardlimit
==0)
1111 /* Use softlimit to determine disk space, except when it has been exceeded */
1113 (F
.d_blk_softlimit
&& F
.d_bcount
>=F
.d_blk_softlimit
) ||
1114 (F
.d_blk_hardlimit
&& F
.d_bcount
>=F
.d_blk_hardlimit
) ||
1115 (F
.d_ino_softlimit
&& F
.d_icount
>=F
.d_ino_softlimit
) ||
1116 (F
.d_ino_hardlimit
&& F
.d_icount
>=F
.d_ino_hardlimit
)
1120 *dsize
= F
.d_bcount
;
1124 *dfree
= (F
.d_blk_softlimit
- F
.d_bcount
);
1125 *dsize
= F
.d_blk_softlimit
? F
.d_blk_softlimit
: F
.d_blk_hardlimit
;
1141 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
1142 #include <ufs/ufs/quota.h>
1143 #include <machine/param.h>
1145 /* AIX quota patch from Ole Holm Nielsen <ohnielse@fysik.dtu.dk> */
1146 #include <jfs/quota.h>
1147 /* AIX 4.X: Rename members of the dqblk structure (ohnielse@fysik.dtu.dk) */
1148 #define dqb_curfiles dqb_curinodes
1149 #define dqb_fhardlimit dqb_ihardlimit
1150 #define dqb_fsoftlimit dqb_isoftlimit
1151 #ifdef _AIXVERSION_530
1152 #include <sys/statfs.h>
1153 #include <sys/vmount.h>
1154 #endif /* AIX 5.3 */
1155 #else /* !__FreeBSD__ && !AIX && !__OpenBSD__ && !__DragonFly__ */
1156 #include <sys/quota.h>
1160 #if defined(__FreeBSD__) || defined(__DragonFly__)
1162 #include <rpc/rpc.h>
1163 #include <rpc/types.h>
1164 #include <rpcsvc/rquota.h>
1165 #ifdef HAVE_RPC_NETTYPE_H
1166 #include <rpc/nettype.h>
1168 #include <rpc/xdr.h>
1170 static int my_xdr_getquota_args(XDR
*xdrsp
, struct getquota_args
*args
)
1172 if (!xdr_string(xdrsp
, &args
->gqa_pathp
, RQ_PATHLEN
))
1174 if (!xdr_int(xdrsp
, &args
->gqa_uid
))
1179 static int my_xdr_getquota_rslt(XDR
*xdrsp
, struct getquota_rslt
*gqr
)
1183 if (!xdr_int(xdrsp
, "astat
)) {
1184 DEBUG(6,("nfs_quotas: Status bad or zero\n"));
1187 gqr
->status
= quotastat
;
1189 if (!xdr_int(xdrsp
, &gqr
->getquota_rslt_u
.gqr_rquota
.rq_bsize
)) {
1190 DEBUG(6,("nfs_quotas: Block size bad or zero\n"));
1193 if (!xdr_bool(xdrsp
, &gqr
->getquota_rslt_u
.gqr_rquota
.rq_active
)) {
1194 DEBUG(6,("nfs_quotas: Active bad or zero\n"));
1197 if (!xdr_int(xdrsp
, &gqr
->getquota_rslt_u
.gqr_rquota
.rq_bhardlimit
)) {
1198 DEBUG(6,("nfs_quotas: Hardlimit bad or zero\n"));
1201 if (!xdr_int(xdrsp
, &gqr
->getquota_rslt_u
.gqr_rquota
.rq_bsoftlimit
)) {
1202 DEBUG(6,("nfs_quotas: Softlimit bad or zero\n"));
1205 if (!xdr_int(xdrsp
, &gqr
->getquota_rslt_u
.gqr_rquota
.rq_curblocks
)) {
1206 DEBUG(6,("nfs_quotas: Currentblocks bad or zero\n"));
1212 /* Works on FreeBSD, too. :-) */
1213 static bool nfs_quotas(char *nfspath
, uid_t euser_id
, uint64_t *bsize
, uint64_t *dfree
, uint64_t *dsize
)
1215 uid_t uid
= euser_id
;
1217 char *mnttype
= nfspath
;
1219 struct getquota_rslt gqr
;
1220 struct getquota_args args
;
1221 char *cutstr
, *pathname
, *host
, *testpath
;
1223 static struct timeval timeout
= {2,0};
1224 enum clnt_stat clnt_stat
;
1227 *bsize
= *dfree
= *dsize
= (uint64_t)0;
1229 len
=strcspn(mnttype
, ":");
1230 pathname
=strstr(mnttype
, ":");
1231 cutstr
= (char *) SMB_MALLOC(len
+1);
1235 memset(cutstr
, '\0', len
+1);
1236 host
= strncat(cutstr
,mnttype
, sizeof(char) * len
);
1237 DEBUG(5,("nfs_quotas: looking for mount on \"%s\"\n", cutstr
));
1238 DEBUG(5,("nfs_quotas: of path \"%s\"\n", mnttype
));
1239 testpath
=strchr_m(mnttype
, ':');
1240 args
.gqa_pathp
= testpath
+1;
1243 DEBUG(5,("nfs_quotas: Asking for host \"%s\" rpcprog \"%i\" rpcvers \"%i\" network \"%s\"\n", host
, RQUOTAPROG
, RQUOTAVERS
, "udp"));
1245 if ((clnt
= clnt_create(host
, RQUOTAPROG
, RQUOTAVERS
, "udp")) == NULL
) {
1250 clnt
->cl_auth
= authunix_create_default();
1251 DEBUG(9,("nfs_quotas: auth_success\n"));
1253 clnt_stat
=clnt_call(clnt
, RQUOTAPROC_GETQUOTA
, (const xdrproc_t
) my_xdr_getquota_args
, (caddr_t
)&args
, (const xdrproc_t
) my_xdr_getquota_rslt
, (caddr_t
)&gqr
, timeout
);
1255 if (clnt_stat
!= RPC_SUCCESS
) {
1256 DEBUG(9,("nfs_quotas: clnt_call fail\n"));
1262 * gqr->status returns 0 if the rpc call fails, 1 if quotas exist, 2 if there is
1263 * no quota set, and 3 if no permission to get the quota. If 0 or 3 return
1264 * something sensible.
1267 switch (gqr
.status
) {
1269 DEBUG(9,("nfs_quotas: Remote Quotas Failed! Error \"%i\" \n", gqr
.status
));
1274 DEBUG(9,("nfs_quotas: Good quota data\n"));
1275 D
.dqb_bsoftlimit
= gqr
.getquota_rslt_u
.gqr_rquota
.rq_bsoftlimit
;
1276 D
.dqb_bhardlimit
= gqr
.getquota_rslt_u
.gqr_rquota
.rq_bhardlimit
;
1277 D
.dqb_curblocks
= gqr
.getquota_rslt_u
.gqr_rquota
.rq_curblocks
;
1282 D
.dqb_bsoftlimit
= 1;
1283 D
.dqb_curblocks
= 1;
1284 DEBUG(9,("nfs_quotas: Remote Quotas returned \"%i\" \n", gqr
.status
));
1288 DEBUG(9,("nfs_quotas: Remote Quotas Questionable! Error \"%i\" \n", gqr
.status
));
1292 DEBUG(10,("nfs_quotas: Let`s look at D a bit closer... status \"%i\" bsize \"%i\" active? \"%i\" bhard \"%i\" bsoft \"%i\" curb \"%i\" \n",
1294 gqr
.getquota_rslt_u
.gqr_rquota
.rq_bsize
,
1295 gqr
.getquota_rslt_u
.gqr_rquota
.rq_active
,
1296 gqr
.getquota_rslt_u
.gqr_rquota
.rq_bhardlimit
,
1297 gqr
.getquota_rslt_u
.gqr_rquota
.rq_bsoftlimit
,
1298 gqr
.getquota_rslt_u
.gqr_rquota
.rq_curblocks
));
1300 if (D
.dqb_bsoftlimit
== 0)
1301 D
.dqb_bsoftlimit
= D
.dqb_bhardlimit
;
1302 if (D
.dqb_bsoftlimit
== 0)
1305 *bsize
= gqr
.getquota_rslt_u
.gqr_rquota
.rq_bsize
;
1306 *dsize
= D
.dqb_bsoftlimit
;
1308 if (D
.dqb_curblocks
== 1)
1311 if (D
.dqb_curblocks
> D
.dqb_bsoftlimit
) {
1313 *dsize
= D
.dqb_curblocks
;
1315 *dfree
= D
.dqb_bsoftlimit
- D
.dqb_curblocks
;
1321 auth_destroy(clnt
->cl_auth
);
1325 DEBUG(5,("nfs_quotas: For path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n",args
.gqa_pathp
,(double)*bsize
,(double)*dfree
,(double)*dsize
));
1328 DEBUG(10,("nfs_quotas: End of nfs_quotas\n" ));
1334 /****************************************************************************
1335 try to get the disk space from disk quotas - default version
1336 ****************************************************************************/
1338 bool disk_quotas(const char *path
, uint64_t *bsize
, uint64_t *dfree
, uint64_t *dsize
)
1343 #if !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) && !defined(__DragonFly__)
1347 /* find the block device file */
1350 /* Need to set the cache flag to 1 for HPUX. Seems
1351 * to have a significant performance boost when
1352 * lstat calls on /dev access this function.
1354 if ((sys_stat(path
, &S
, false)<0)
1355 || (devnm(S_IFBLK
, S
.st_ex_dev
, dev_disk
, 256, 1)<0))
1357 if ((sys_stat(path
, &S
, false)<0)
1358 || (devnm(S_IFBLK
, S
.st_ex_dev
, dev_disk
, 256, 0)<0))
1360 #endif /* ifdef HPUX */
1362 #endif /* !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) && !defined(__DragonFly__) */
1364 euser_id
= geteuid();
1367 /* for HPUX, real uid must be same as euid to execute quotactl for euid */
1369 if (set_re_uid() != 0) return False
;
1371 r
=quotactl(Q_GETQUOTA
, dev_disk
, euser_id
, &D
);
1375 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
1377 /* FreeBSD patches from Marty Moll <martym@arbor.edu> */
1379 #if defined(__FreeBSD__) || defined(__DragonFly__)
1381 struct statfs
*mnts
;
1385 if (sys_stat(path
, &st
, false) < 0)
1387 devno
= st
.st_ex_dev
;
1389 mntsize
= getmntinfo(&mnts
,MNT_NOWAIT
);
1393 for (i
= 0; i
< mntsize
; i
++) {
1394 if (sys_stat(mnts
[i
].f_mntonname
, &st
, false) < 0)
1396 if (st
.st_ex_dev
== devno
)
1405 #if defined(__FreeBSD__) || defined(__DragonFly__)
1406 if (strcmp(mnts
[i
].f_fstypename
,"nfs") == 0) {
1408 retval
= nfs_quotas(mnts
[i
].f_mntfromname
,euser_id
,bsize
,dfree
,dsize
);
1414 egrp_id
= getegid();
1415 r
= quotactl(path
,QCMD(Q_GETQUOTA
,USRQUOTA
),euser_id
,(char *) &D
);
1417 /* As FreeBSD has group quotas, if getting the user
1418 quota fails, try getting the group instead. */
1420 r
= quotactl(path
,QCMD(Q_GETQUOTA
,GRPQUOTA
),egrp_id
,(char *) &D
);
1426 /* AIX has both USER and GROUP quotas:
1427 Get the USER quota (ohnielse@fysik.dtu.dk) */
1428 #ifdef _AIXVERSION_530
1430 struct statfs statbuf
;
1431 quota64_t user_quota
;
1432 if (statfs(path
,&statbuf
) != 0)
1434 if(statbuf
.f_vfstype
== MNT_J2
)
1436 /* For some reason we need to be root for jfs2 */
1438 r
= quotactl(path
,QCMD(Q_J2GETQUOTA
,USRQUOTA
),euser_id
,(char *) &user_quota
);
1440 /* Copy results to old struct to let the following code work as before */
1441 D
.dqb_curblocks
= user_quota
.bused
;
1442 D
.dqb_bsoftlimit
= user_quota
.bsoft
;
1443 D
.dqb_bhardlimit
= user_quota
.bhard
;
1444 D
.dqb_curfiles
= user_quota
.iused
;
1445 D
.dqb_fsoftlimit
= user_quota
.isoft
;
1446 D
.dqb_fhardlimit
= user_quota
.ihard
;
1448 else if(statbuf
.f_vfstype
== MNT_JFS
)
1450 #endif /* AIX 5.3 */
1452 if (set_re_uid() != 0)
1454 r
= quotactl(path
,QCMD(Q_GETQUOTA
,USRQUOTA
),euser_id
,(char *) &D
);
1456 #ifdef _AIXVERSION_530
1459 r
= 1; /* Fail for other FS-types */
1461 #endif /* AIX 5.3 */
1462 #else /* !__FreeBSD__ && !AIX && !__OpenBSD__ && !__DragonFly__ */
1463 r
=quotactl(Q_GETQUOTA
, dev_disk
, euser_id
, &D
);
1464 #endif /* !__FreeBSD__ && !AIX && !__OpenBSD__ && !__DragonFly__ */
1467 /* Use softlimit to determine disk space, except when it has been exceeded */
1468 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
1470 #else /* !__FreeBSD__ && !__OpenBSD__ && !__DragonFly__ */
1472 #endif /*!__FreeBSD__ && !__OpenBSD__ && !__DragonFly__ */
1476 if (errno
== EDQUOT
)
1479 *dsize
=D
.dqb_curblocks
;
1485 /* If softlimit is zero, set it equal to hardlimit.
1488 if (D
.dqb_bsoftlimit
==0)
1489 D
.dqb_bsoftlimit
= D
.dqb_bhardlimit
;
1491 if (D
.dqb_bsoftlimit
==0)
1493 /* Use softlimit to determine disk space, except when it has been exceeded */
1494 if ((D
.dqb_curblocks
>D
.dqb_bsoftlimit
)
1495 #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__)
1496 ||((D
.dqb_curfiles
>D
.dqb_fsoftlimit
) && (D
.dqb_fsoftlimit
!= 0))
1500 *dsize
= D
.dqb_curblocks
;
1503 *dfree
= D
.dqb_bsoftlimit
- D
.dqb_curblocks
;
1504 *dsize
= D
.dqb_bsoftlimit
;
1511 #if defined(VXFS_QUOTA)
1513 /****************************************************************************
1514 Try to get the disk space from Veritas disk quotas.
1515 David Lee <T.D.Lee@durham.ac.uk> August 1999.
1517 Background assumptions:
1518 Potentially under many Operating Systems. Initially Solaris 2.
1520 My guess is that Veritas is largely, though not entirely,
1521 independent of OS. So I have separated it out.
1523 There may be some details. For example, OS-specific "include" files.
1525 It is understood that HPUX 10 somehow gets Veritas quotas without
1526 any special effort; if so, this routine need not be compiled in.
1527 Dirk De Wachter <Dirk.DeWachter@rug.ac.be>
1530 It is understood that Veritas do not publicly support this ioctl interface.
1531 Rather their preference would be for the user (us) to call the native
1532 OS and then for the OS itself to call through to the VxFS filesystem.
1533 Presumably HPUX 10, see above, does this.
1536 Add your OS to "IFLIST" below.
1537 Get it to compile successfully:
1538 Almost certainly "include"s require attention: see SUNOS5.
1539 In the main code above, arrange for it to be called: see SUNOS5.
1542 ****************************************************************************/
1545 * This "if" is a list of ports:
1546 * if defined(OS1) || defined(OS2) || ...
1551 #include <sys/fs/vx_solaris.h>
1553 #include <sys/fs/vx_machdep.h>
1554 #include <sys/fs/vx_layout.h>
1555 #include <sys/fs/vx_quota.h>
1556 #include <sys/fs/vx_aioctl.h>
1557 #include <sys/fs/vx_ioctl.h>
1559 bool disk_quotas_vxfs(const char *name
, char *path
, uint64_t *bsize
, uint64_t *dfree
, uint64_t *dsize
)
1561 uid_t user_id
, euser_id
;
1564 struct vx_quotctl quotabuf
;
1565 struct vx_genioctl genbuf
;
1570 * "name" may or may not include a trailing "/quotas".
1571 * Arranging consistency of calling here in "quotas.c" may not be easy and
1572 * it might be easier to examine and adjust it here.
1573 * Fortunately, VxFS seems not to mind at present.
1575 qfname
= talloc_strdup(talloc_tos(), name
);
1579 /* pstrcat(qfname, "/quotas") ; */ /* possibly examine and adjust "name" */
1581 euser_id
= geteuid();
1582 set_effective_uid(0);
1584 DEBUG(5,("disk_quotas: looking for VxFS quotas file \"%s\"\n", qfname
));
1585 if((file
=sys_open(qfname
, O_RDONLY
,0))<0) {
1586 set_effective_uid(euser_id
);
1589 genbuf
.ioc_cmd
= VX_QUOTACTL
;
1590 genbuf
.ioc_up
= (void *) "abuf
;
1592 quotabuf
.cmd
= VX_GETQUOTA
;
1593 quotabuf
.uid
= euser_id
;
1594 quotabuf
.addr
= (caddr_t
) &D
;
1595 ret
= ioctl(file
, VX_ADMIN_IOCTL
, &genbuf
);
1598 set_effective_uid(euser_id
);
1601 DEBUG(5,("disk_quotas ioctl (VxFS) failed. Error = %s\n", strerror(errno
) ));
1605 /* If softlimit is zero, set it equal to hardlimit.
1608 if (D
.dqb_bsoftlimit
==0)
1609 D
.dqb_bsoftlimit
= D
.dqb_bhardlimit
;
1611 /* Use softlimit to determine disk space. A user exceeding the quota is told
1612 * that there's no space left. Writes might actually work for a bit if the
1613 * hardlimit is set higher than softlimit. Effectively the disk becomes
1614 * made of rubber latex and begins to expand to accommodate the user :-)
1616 DEBUG(5,("disk_quotas for path \"%s\" block c/s/h %ld/%ld/%ld; file c/s/h %ld/%ld/%ld\n",
1617 path
, D
.dqb_curblocks
, D
.dqb_bsoftlimit
, D
.dqb_bhardlimit
,
1618 D
.dqb_curfiles
, D
.dqb_fsoftlimit
, D
.dqb_fhardlimit
));
1620 if (D
.dqb_bsoftlimit
==0)
1623 *dsize
= D
.dqb_bsoftlimit
;
1625 if (D
.dqb_curblocks
> D
.dqb_bsoftlimit
) {
1627 *dsize
= D
.dqb_curblocks
;
1629 *dfree
= D
.dqb_bsoftlimit
- D
.dqb_curblocks
;
1631 DEBUG(5,("disk_quotas for path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n",
1632 path
,(double)*bsize
,(double)*dfree
,(double)*dsize
));
1637 #endif /* SUNOS5 || ... */
1639 #endif /* VXFS_QUOTA */
1641 #else /* WITH_QUOTAS */
1643 bool disk_quotas(const char *path
,uint64_t *bsize
,uint64_t *dfree
,uint64_t *dsize
)
1645 (*bsize
) = 512; /* This value should be ignored */
1647 /* And just to be sure we set some values that hopefully */
1648 /* will be larger that any possible real-world value */
1649 (*dfree
) = (uint64_t)-1;
1650 (*dsize
) = (uint64_t)-1;
1652 /* As we have select not to use quotas, allways fail */
1655 #endif /* WITH_QUOTAS */
1657 #else /* HAVE_SYS_QUOTAS */
1658 /* wrapper to the new sys_quota interface
1659 this file should be removed later
1661 bool disk_quotas(const char *path
,uint64_t *bsize
,uint64_t *dfree
,uint64_t *dsize
)
1670 r
=sys_get_quota(path
, SMB_USER_QUOTA_TYPE
, id
, &D
);
1672 /* Use softlimit to determine disk space, except when it has been exceeded */
1675 if (errno
== EDQUOT
) {
1677 *dsize
=D
.curblocks
;
1680 goto try_group_quota
;
1684 /* Use softlimit to determine disk space, except when it has been exceeded */
1686 (D
.softlimit
&& D
.curblocks
>= D
.softlimit
) ||
1687 (D
.hardlimit
&& D
.curblocks
>= D
.hardlimit
) ||
1688 (D
.isoftlimit
&& D
.curinodes
>= D
.isoftlimit
) ||
1689 (D
.ihardlimit
&& D
.curinodes
>=D
.ihardlimit
)
1692 *dsize
= D
.curblocks
;
1693 } else if (D
.softlimit
==0 && D
.hardlimit
==0) {
1694 goto try_group_quota
;
1696 if (D
.softlimit
== 0)
1697 D
.softlimit
= D
.hardlimit
;
1698 *dfree
= D
.softlimit
- D
.curblocks
;
1699 *dsize
= D
.softlimit
;
1708 r
=sys_get_quota(path
, SMB_GROUP_QUOTA_TYPE
, id
, &D
);
1710 /* Use softlimit to determine disk space, except when it has been exceeded */
1713 if (errno
== EDQUOT
) {
1715 *dsize
=D
.curblocks
;
1722 /* Use softlimit to determine disk space, except when it has been exceeded */
1724 (D
.softlimit
&& D
.curblocks
>= D
.softlimit
) ||
1725 (D
.hardlimit
&& D
.curblocks
>= D
.hardlimit
) ||
1726 (D
.isoftlimit
&& D
.curinodes
>= D
.isoftlimit
) ||
1727 (D
.ihardlimit
&& D
.curinodes
>=D
.ihardlimit
)
1730 *dsize
= D
.curblocks
;
1731 } else if (D
.softlimit
==0 && D
.hardlimit
==0) {
1734 if (D
.softlimit
== 0)
1735 D
.softlimit
= D
.hardlimit
;
1736 *dfree
= D
.softlimit
- D
.curblocks
;
1737 *dsize
= D
.softlimit
;
1742 #endif /* HAVE_SYS_QUOTAS */