2004-01-06 00:02:37 +03:00
/*
Unix SMB / CIFS implementation .
System QUOTA function wrappers for XFS
Copyright ( C ) Stefan ( metze ) Metzmacher 2003
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2004-01-06 00:02:37 +03:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2004-01-06 00:02:37 +03:00
*/
# include "includes.h"
2004-01-15 11:49:30 +03:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_QUOTA
2012-09-07 15:13:49 +04:00
# if defined(HAVE_SYS_QUOTAS) && defined(HAVE_XFS_QUOTAS)
# ifdef HAVE_SYS_QUOTA_H
# include <sys/quota.h>
# endif
/* this one should actually come from glibc: */
/* #include "samba_linux_quota.h" */
2004-01-06 00:02:37 +03:00
2012-09-06 19:26:55 +04:00
# ifdef HAVE_XFS_XQM_H
# include <xfs/xqm.h>
2007-07-10 05:15:57 +04:00
# endif
2012-09-06 19:26:55 +04:00
2004-01-06 21:13:32 +03:00
# define HAVE_GROUP_QUOTA
2004-01-06 00:02:37 +03:00
/* on IRIX */
# ifndef Q_XQUOTAON
# define Q_XQUOTAON Q_QUOTAON
# endif /* Q_XQUOTAON */
# ifndef Q_XQUOTAOFF
# define Q_XQUOTAOFF Q_QUOTAOFF
# endif /* Q_XQUOTAOFF */
# ifndef Q_XGETQSTAT
# define Q_XGETQSTAT Q_GETQSTAT
# endif /* Q_XGETQSTAT */
2004-01-06 21:13:32 +03:00
/* currently doesn't support Group and Project quotas on IRIX
*/
# ifndef QCMD
# define QCMD(x,y) x
# endif
2004-01-06 00:02:37 +03:00
2004-01-06 21:13:32 +03:00
/*
* IRIX has BBSIZE in < sys / param . h >
*/
2004-01-06 00:02:37 +03:00
# ifndef BBSHIFT
# define BBSHIFT 9
# endif /* BBSHIFT */
# ifndef BBSIZE
# define BBSIZE (1<<BBSHIFT)
# endif /* BBSIZE */
/****************************************************************************
Abstract out the XFS Quota Manager quota get call .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int sys_get_xfs_quota ( const char * path , const char * bdev , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
int ret = - 1 ;
uint32 qflags = 0 ;
2008-10-14 03:59:36 +04:00
uint64_t bsize = ( uint64_t ) BBSIZE ;
2004-01-06 00:02:37 +03:00
struct fs_disk_quota D ;
struct fs_quota_stat F ;
ZERO_STRUCT ( D ) ;
ZERO_STRUCT ( F ) ;
if ( ! bdev | | ! dp )
smb_panic ( " sys_get_xfs_quota: called with NULL pointer " ) ;
ZERO_STRUCT ( * dp ) ;
dp - > qtype = qtype ;
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_xfs_quota: path[%s] bdev[%s] SMB_USER_QUOTA_TYPE uid[%u] \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
if ( ( ret = quotactl ( QCMD ( Q_XGETQUOTA , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ) )
2004-01-06 00:02:37 +03:00
return ret ;
break ;
# ifdef HAVE_GROUP_QUOTA
case SMB_GROUP_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_xfs_quota: path[%s] bdev[%s] SMB_GROUP_QUOTA_TYPE gid[%u] \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
if ( ( ret = quotactl ( QCMD ( Q_XGETQUOTA , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ) )
2004-01-06 00:02:37 +03:00
return ret ;
break ;
# endif /* HAVE_GROUP_QUOTA */
2004-01-15 11:49:30 +03:00
case SMB_USER_FS_QUOTA_TYPE :
DEBUG ( 10 , ( " sys_get_xfs_quota: path[%s] bdev[%s] SMB_USER_FS_QUOTA_TYPE (uid[%u]) \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
quotactl ( QCMD ( Q_XGETQSTAT , USRQUOTA ) , bdev , - 1 , ( caddr_t ) & F ) ;
2004-01-06 00:02:37 +03:00
if ( F . qs_flags & XFS_QUOTA_UDQ_ENFD ) {
qflags | = QUOTAS_DENY_DISK ;
}
else if ( F . qs_flags & XFS_QUOTA_UDQ_ACCT ) {
qflags | = QUOTAS_ENABLED ;
}
ret = 0 ;
break ;
# ifdef HAVE_GROUP_QUOTA
2004-01-15 11:49:30 +03:00
case SMB_GROUP_FS_QUOTA_TYPE :
DEBUG ( 10 , ( " sys_get_xfs_quota: path[%s] bdev[%s] SMB_GROUP_FS_QUOTA_TYPE (gid[%u]) \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
quotactl ( QCMD ( Q_XGETQSTAT , GRPQUOTA ) , bdev , - 1 , ( caddr_t ) & F ) ;
2004-01-06 00:02:37 +03:00
2004-01-06 21:13:32 +03:00
if ( F . qs_flags & XFS_QUOTA_GDQ_ENFD ) {
2004-01-06 00:02:37 +03:00
qflags | = QUOTAS_DENY_DISK ;
}
2004-01-06 21:13:32 +03:00
else if ( F . qs_flags & XFS_QUOTA_GDQ_ACCT ) {
2004-01-06 00:02:37 +03:00
qflags | = QUOTAS_ENABLED ;
}
ret = 0 ;
break ;
# endif /* HAVE_GROUP_QUOTA */
default :
errno = ENOSYS ;
return - 1 ;
}
dp - > bsize = bsize ;
2008-10-14 03:59:36 +04:00
dp - > softlimit = ( uint64_t ) D . d_blk_softlimit ;
dp - > hardlimit = ( uint64_t ) D . d_blk_hardlimit ;
dp - > ihardlimit = ( uint64_t ) D . d_ino_hardlimit ;
dp - > isoftlimit = ( uint64_t ) D . d_ino_softlimit ;
dp - > curinodes = ( uint64_t ) D . d_icount ;
dp - > curblocks = ( uint64_t ) D . d_bcount ;
2004-01-06 00:02:37 +03:00
dp - > qflags = qflags ;
return ret ;
}
/****************************************************************************
Abstract out the XFS Quota Manager quota set call .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int sys_set_xfs_quota ( const char * path , const char * bdev , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
int ret = - 1 ;
uint32 qflags = 0 ;
2008-10-14 03:59:36 +04:00
uint64_t bsize = ( uint64_t ) BBSIZE ;
2004-01-06 00:02:37 +03:00
struct fs_disk_quota D ;
struct fs_quota_stat F ;
int q_on = 0 ;
int q_off = 0 ;
ZERO_STRUCT ( D ) ;
ZERO_STRUCT ( F ) ;
if ( ! bdev | | ! dp )
smb_panic ( " sys_set_xfs_quota: called with NULL pointer " ) ;
if ( bsize = = dp - > bsize ) {
D . d_blk_softlimit = dp - > softlimit ;
D . d_blk_hardlimit = dp - > hardlimit ;
D . d_ino_hardlimit = dp - > ihardlimit ;
D . d_ino_softlimit = dp - > isoftlimit ;
} else {
D . d_blk_softlimit = ( dp - > softlimit * dp - > bsize ) / bsize ;
D . d_blk_hardlimit = ( dp - > hardlimit * dp - > bsize ) / bsize ;
D . d_ino_hardlimit = ( dp - > ihardlimit * dp - > bsize ) / bsize ;
D . d_ino_softlimit = ( dp - > isoftlimit * dp - > bsize ) / bsize ;
}
qflags = dp - > qflags ;
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_xfs_quota: path[%s] bdev[%s] SMB_USER_QUOTA_TYPE uid[%u] \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-06 00:02:37 +03:00
D . d_fieldmask | = FS_DQ_LIMIT_MASK ;
2004-01-15 11:49:30 +03:00
ret = quotactl ( QCMD ( Q_XSETQLIM , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ;
2004-01-06 00:02:37 +03:00
break ;
# ifdef HAVE_GROUP_QUOTA
case SMB_GROUP_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_xfs_quota: path[%s] bdev[%s] SMB_GROUP_QUOTA_TYPE gid[%u] \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-06 00:02:37 +03:00
D . d_fieldmask | = FS_DQ_LIMIT_MASK ;
2004-01-15 11:49:30 +03:00
ret = quotactl ( QCMD ( Q_XSETQLIM , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ;
2004-01-06 00:02:37 +03:00
break ;
# endif /* HAVE_GROUP_QUOTA */
case SMB_USER_FS_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_xfs_quota: path[%s] bdev[%s] SMB_USER_FS_QUOTA_TYPE (uid[%u]) \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
quotactl ( QCMD ( Q_XGETQSTAT , USRQUOTA ) , bdev , - 1 , ( caddr_t ) & F ) ;
2004-01-06 00:02:37 +03:00
if ( qflags & QUOTAS_DENY_DISK ) {
if ( ! ( F . qs_flags & XFS_QUOTA_UDQ_ENFD ) )
q_on | = XFS_QUOTA_UDQ_ENFD ;
if ( ! ( F . qs_flags & XFS_QUOTA_UDQ_ACCT ) )
q_on | = XFS_QUOTA_UDQ_ACCT ;
if ( q_on ! = 0 ) {
2004-01-15 11:49:30 +03:00
ret = quotactl ( QCMD ( Q_XQUOTAON , USRQUOTA ) , bdev , - 1 , ( caddr_t ) & q_on ) ;
2004-01-06 00:02:37 +03:00
} else {
ret = 0 ;
}
} else if ( qflags & QUOTAS_ENABLED ) {
if ( F . qs_flags & XFS_QUOTA_UDQ_ENFD )
q_off | = XFS_QUOTA_UDQ_ENFD ;
if ( q_off ! = 0 ) {
2004-01-15 11:49:30 +03:00
ret = quotactl ( QCMD ( Q_XQUOTAOFF , USRQUOTA ) , bdev , - 1 , ( caddr_t ) & q_off ) ;
2004-01-06 00:02:37 +03:00
} else {
ret = 0 ;
}
if ( ! ( F . qs_flags & XFS_QUOTA_UDQ_ACCT ) )
q_on | = XFS_QUOTA_UDQ_ACCT ;
if ( q_on ! = 0 ) {
2004-01-15 11:49:30 +03:00
ret = quotactl ( QCMD ( Q_XQUOTAON , USRQUOTA ) , bdev , - 1 , ( caddr_t ) & q_on ) ;
2004-01-06 00:02:37 +03:00
} else {
ret = 0 ;
}
} else {
#if 0
/* Switch on XFS_QUOTA_UDQ_ACCT didn't work!
* only swittching off XFS_QUOTA_UDQ_ACCT work
*/
if ( F . qs_flags & XFS_QUOTA_UDQ_ENFD )
q_off | = XFS_QUOTA_UDQ_ENFD ;
if ( F . qs_flags & XFS_QUOTA_UDQ_ACCT )
q_off | = XFS_QUOTA_UDQ_ACCT ;
if ( q_off ! = 0 ) {
2004-01-15 11:49:30 +03:00
ret = quotactl ( QCMD ( Q_XQUOTAOFF , USRQUOTA ) , bdev , - 1 , ( caddr_t ) & q_off ) ;
2004-01-06 00:02:37 +03:00
} else {
ret = 0 ;
}
# else
ret = - 1 ;
# endif
}
break ;
# ifdef HAVE_GROUP_QUOTA
case SMB_GROUP_FS_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_xfs_quota: path[%s] bdev[%s] SMB_GROUP_FS_QUOTA_TYPE (gid[%u]) \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
quotactl ( QCMD ( Q_XGETQSTAT , GRPQUOTA ) , bdev , - 1 , ( caddr_t ) & F ) ;
2004-01-06 00:02:37 +03:00
if ( qflags & QUOTAS_DENY_DISK ) {
2004-01-06 21:13:32 +03:00
if ( ! ( F . qs_flags & XFS_QUOTA_GDQ_ENFD ) )
q_on | = XFS_QUOTA_GDQ_ENFD ;
if ( ! ( F . qs_flags & XFS_QUOTA_GDQ_ACCT ) )
q_on | = XFS_QUOTA_GDQ_ACCT ;
2004-01-06 00:02:37 +03:00
if ( q_on ! = 0 ) {
2004-01-15 11:49:30 +03:00
ret = quotactl ( QCMD ( Q_XQUOTAON , GRPQUOTA ) , bdev , - 1 , ( caddr_t ) & q_on ) ;
2004-01-06 00:02:37 +03:00
} else {
ret = 0 ;
}
} else if ( qflags & QUOTAS_ENABLED ) {
2004-01-06 21:13:32 +03:00
if ( F . qs_flags & XFS_QUOTA_GDQ_ENFD )
q_off | = XFS_QUOTA_GDQ_ENFD ;
2004-01-06 00:02:37 +03:00
if ( q_off ! = 0 ) {
2004-01-15 11:49:30 +03:00
ret = quotactl ( QCMD ( Q_XQUOTAOFF , GRPQUOTA ) , bdev , - 1 , ( caddr_t ) & q_off ) ;
2004-01-06 00:02:37 +03:00
} else {
ret = 0 ;
}
2004-01-06 21:13:32 +03:00
if ( ! ( F . qs_flags & XFS_QUOTA_GDQ_ACCT ) )
q_on | = XFS_QUOTA_GDQ_ACCT ;
2004-01-06 00:02:37 +03:00
if ( q_on ! = 0 ) {
2004-01-15 11:49:30 +03:00
ret = quotactl ( QCMD ( Q_XQUOTAON , GRPQUOTA ) , bdev , - 1 , ( caddr_t ) & q_on ) ;
2004-01-06 00:02:37 +03:00
} else {
ret = 0 ;
}
} else {
#if 0
/* Switch on XFS_QUOTA_UDQ_ACCT didn't work!
* only swittching off XFS_QUOTA_UDQ_ACCT work
*/
2004-01-06 21:13:32 +03:00
if ( F . qs_flags & XFS_QUOTA_GDQ_ENFD )
q_off | = XFS_QUOTA_GDQ_ENFD ;
if ( F . qs_flags & XFS_QUOTA_GDQ_ACCT )
q_off | = XFS_QUOTA_GDQ_ACCT ;
2004-01-06 00:02:37 +03:00
if ( q_off ! = 0 ) {
2004-01-15 11:49:30 +03:00
ret = quotactl ( QCMD ( Q_XQUOTAOFF , GRPQUOTA ) , bdev , - 1 , ( caddr_t ) & q_off ) ;
2004-01-06 00:02:37 +03:00
} else {
ret = 0 ;
}
# else
ret = - 1 ;
# endif
}
break ;
# endif /* HAVE_GROUP_QUOTA */
default :
errno = ENOSYS ;
return - 1 ;
}
return ret ;
}
2004-01-06 21:13:32 +03:00
# else /* HAVE_XFS_QUOTAS */
2005-05-02 21:49:43 +04:00
void dummy_sysquotas_xfs ( void ) ;
2004-01-06 21:13:32 +03:00
void dummy_sysquotas_xfs ( void ) { }
# endif /* HAVE_XFS_QUOTAS */