3 Unix SMB/Netbios implementation.
6 Copyright (C) Andrew Tridgell 1992-1997
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * This is one of the most system dependent parts of Samba, and its
26 * done a litle differently. Each system has its own way of doing
32 extern int DEBUGLEVEL
;
36 #include <sys/types.h>
37 #include <asm/types.h>
38 #include <sys/quota.h>
41 #include <linux/unistd.h>
43 _syscall4(int, quotactl
, int, cmd
, const char *, special
, int, id
, caddr_t
, addr
);
45 /****************************************************************************
46 try to get the disk space from disk quotas (LINUX version)
47 ****************************************************************************/
49 BOOL
disk_quotas(char *path
, int *bsize
, int *dfree
, int *dsize
)
61 /* find the block device file */
63 if ( stat(path
, &S
) == -1 ) {
69 fp
= setmntent(MOUNTED
,"r");
72 while ((mnt
= getmntent(fp
))) {
73 if ( stat(mnt
->mnt_dir
,&S
) == -1 )
75 if (S
.st_dev
== devno
) {
88 r
=quotactl(QCMD(Q_GETQUOTA
,USRQUOTA
), mnt
->mnt_fsname
, euser_id
, (caddr_t
)&D
);
91 /* Use softlimit to determine disk space, except when it has been exceeded */
98 *dsize
=D
.dqb_curblocks
;
103 /* Use softlimit to determine disk space, except when it has been exceeded */
105 (D
.dqb_bsoftlimit
&& D
.dqb_curblocks
>=D
.dqb_bsoftlimit
) ||
106 (D
.dqb_bhardlimit
&& D
.dqb_curblocks
>=D
.dqb_bhardlimit
) ||
107 (D
.dqb_isoftlimit
&& D
.dqb_curinodes
>=D
.dqb_isoftlimit
) ||
108 (D
.dqb_ihardlimit
&& D
.dqb_curinodes
>=D
.dqb_ihardlimit
)
112 *dsize
= D
.dqb_curblocks
;
114 else if (D
.dqb_bsoftlimit
==0 && D
.dqb_bhardlimit
==0)
119 *dfree
= D
.dqb_bsoftlimit
- D
.dqb_curblocks
;
120 *dsize
= D
.dqb_bsoftlimit
;
127 #include <sys/quota.h>
130 /****************************************************************************
131 try to get the disk space from disk quotas (CRAY VERSION)
132 ****************************************************************************/
133 BOOL
disk_quotas(char *path
, int *bsize
, int *dfree
, int *dsize
)
139 static dev_t devno_cached
= 0 ;
140 static char name
[MNTMAXSTR
] ;
141 struct q_request request
;
142 struct qf_header header
;
143 static int quota_default
= 0 ;
146 if ( stat(path
,&sbuf
) == -1 )
149 devno
= sbuf
.st_dev
;
151 if ( devno
!= devno_cached
) {
153 devno_cached
= devno
;
155 if ((fd
= setmntent(KMTAB
)) == NULL
)
160 while ((mnt
= getmntent(fd
)) != NULL
) {
162 if ( stat(mnt
->mnt_dir
,&sbuf
) == -1 )
165 if (sbuf
.st_dev
== devno
) {
174 strcpy(name
,mnt
->mnt_dir
) ;
181 request
.qf_magic
= QF_MAGIC
;
182 request
.qf_entry
.id
= geteuid() ;
184 if (quotactl(name
, Q_GETQUOTA
, &request
) == -1)
187 if ( ! request
.user
)
190 if ( request
.qf_entry
.user_q
.f_quota
== QFV_DEFAULT
) {
192 if ( ! quota_default
) {
194 if ( quotactl(name
, Q_GETHEADER
, &header
) == -1 )
197 quota_default
= header
.user_h
.def_fq
;
200 *dfree
= quota_default
;
202 }else if ( request
.qf_entry
.user_q
.f_quota
== QFV_PREVENT
) {
208 *dfree
= request
.qf_entry
.user_q
.f_quota
;
212 *dsize
= request
.qf_entry
.user_q
.f_use
;
220 *bsize
= 4096 ; /* Cray blocksize */
227 #elif defined(SUNOS5) || defined(SUNOS4)
231 #include <sys/fs/ufs_quota.h>
232 #include <sys/mnttab.h>
233 #else /* defined(SUNOS4) */
234 #include <ufs/quota.h>
238 /****************************************************************************
239 try to get the disk space from disk quotas (solaris 2 version)
240 ****************************************************************************/
241 /* Quota code by Peter Urbanec (amiga@cse.unsw.edu.au) */
242 BOOL
disk_quotas(char *path
, int *bsize
, int *dfree
, int *dsize
)
244 uid_t user_id
, euser_id
;
248 struct quotctl command
;
251 static char name
[MNT_LINE_MAX
] ;
254 static char name
[MNTMAXSTR
] ;
259 static dev_t devno_cached
= 0 ;
262 if ( stat(path
,&sbuf
) == -1 )
265 devno
= sbuf
.st_dev
;
266 DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%o\n", path
,devno
));
267 if ( devno
!= devno_cached
) {
268 devno_cached
= devno
;
270 if ((fd
= fopen(MNTTAB
, "r")) == NULL
)
274 while (getmntent(fd
, &mnt
) == 0) {
275 if ( stat(mnt
.mnt_mountp
,&sbuf
) == -1 )
277 DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n",
278 mnt
.mnt_mountp
,sbuf
.st_dev
));
279 if (sbuf
.st_dev
== devno
) {
285 strcpy(name
,mnt
.mnt_mountp
) ;
286 strcat(name
,"/quotas") ;
289 if ((fd
= setmntent(MOUNTED
, "r")) == NULL
)
293 while ((mnt
= getmntent(fd
)) != NULL
) {
294 if ( stat(mnt
->mnt_dir
,&sbuf
) == -1 )
296 DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n",
297 mnt
->mnt_dir
,sbuf
.st_dev
));
298 if (sbuf
.st_dev
== devno
) {
304 strcpy(name
,mnt
->mnt_fsname
) ;
312 euser_id
= geteuid();
315 setuid(0); /* Solaris seems to want to give info only to super-user */
319 DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name
));
320 if((file
=open(name
, O_RDONLY
))<0) {
321 setuid(user_id
); /* Restore the original UID status */
325 command
.op
= Q_GETQUOTA
;
326 command
.uid
= euser_id
;
327 command
.addr
= (caddr_t
) &D
;
328 ret
= ioctl(file
, Q_QUOTACTL
, &command
);
331 DEBUG(5,("disk_quotas: trying quotactl on device \"%s\"\n", name
));
332 ret
= quotactl(Q_GETQUOTA
, name
, euser_id
, &D
);
335 setuid(user_id
); /* Restore the original UID status */
339 DEBUG(2,("disk_quotas ioctl (Solaris) failed\n"));
344 /* Use softlimit to determine disk space. A user exceeding the quota is told
345 * that there's no space left. Writes might actually work for a bit if the
346 * hardlimit is set higher than softlimit. Effectively the disk becomes
347 * made of rubber latex and begins to expand to accommodate the user :-)
350 if (D
.dqb_bsoftlimit
==0)
353 *dfree
= D
.dqb_bsoftlimit
- D
.dqb_curblocks
;
354 *dsize
= D
.dqb_bsoftlimit
;
358 *dsize
= D
.dqb_curblocks
;
361 DEBUG(5,("disk_quotas for path \"%s\" returning bsize %d, dfree %d, dsize %d\n",
362 path
,*bsize
,*dfree
,*dsize
));
370 #include <ufs/ufs/quota.h>
372 #include <sys/quota.h>
376 /****************************************************************************
377 try to get the disk space from disk quotas - default version
378 ****************************************************************************/
379 BOOL
disk_quotas(char *path
, int *bsize
, int *dfree
, int *dsize
)
381 uid_t user_id
, euser_id
;
387 /* find the block device file */
388 if ((stat(path
, &S
)<0) ||
389 (devnm(S_IFBLK
, S
.st_dev
, dev_disk
, 256, 0)<0)) return (False
);
392 euser_id
= geteuid();
395 /* for HPUX, real uid must be same as euid to execute quotactl for euid */
397 setresuid(euser_id
,-1,-1);
398 r
=quotactl(Q_GETQUOTA
, dev_disk
, euser_id
, &D
);
399 if (setresuid(user_id
,-1,-1))
400 DEBUG(5,("Unable to reset uid to %d\n", user_id
));
402 #if defined(__FreeBSD__)
403 r
= quotactl(path
,Q_GETQUOTA
,euser_id
,(char *) &D
);
405 r
=quotactl(Q_GETQUOTA
, dev_disk
, euser_id
, &D
);
409 /* Use softlimit to determine disk space, except when it has been exceeded */
416 *dsize
=D
.dqb_curblocks
;
421 if (D
.dqb_bsoftlimit
==0)
423 /* Use softlimit to determine disk space, except when it has been exceeded */
424 if ((D
.dqb_curblocks
>D
.dqb_bsoftlimit
)
425 #if !defined(__FreeBSD__)
426 ||(D
.dqb_curfiles
>D
.dqb_fsoftlimit
)
430 *dsize
= D
.dqb_curblocks
;
433 *dfree
= D
.dqb_bsoftlimit
- D
.dqb_curblocks
;
434 *dsize
= D
.dqb_bsoftlimit
;
442 /* this keeps fussy compilers happy */
443 void quotas_dummy(void) {}