コード例 #1
0
ファイル: quotas.c プロジェクト: hajuuk/R7000
static int get_smb_linux_gen_quota(char *path, uid_t euser_id, gid_t egrp_id, LINUX_SMB_DISK_QUOTA *dp)
{
	struct if_dqblk D;
	int ret;

	ZERO_STRUCT(D);

	ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), path, euser_id, (caddr_t)&D);

	if (ret && errno != EDQUOT)
		ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), path, egrp_id, (caddr_t)&D);

	if (ret && errno != EDQUOT)
		return ret;

	dp->bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
	dp->softlimit = (SMB_BIG_UINT)D.dqb_bsoftlimit;
	dp->hardlimit = (SMB_BIG_UINT)D.dqb_bhardlimit;
	dp->ihardlimit = (SMB_BIG_UINT)D.dqb_ihardlimit;
	dp->isoftlimit = (SMB_BIG_UINT)D.dqb_isoftlimit;
	dp->curinodes = (SMB_BIG_UINT)D.dqb_curinodes;
	dp->curblocks = ((SMB_BIG_UINT)D.dqb_curspace) / dp->bsize;

	return ret;
}
コード例 #2
0
ファイル: sysquotas_4B.c プロジェクト: Alexander--/samba
int sys_set_vfs_quota(const char *path, const char *bdev,
	enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
{
	struct dqblk qblk;

	xlate_smb_to_qblk(dp, &qblk);

	switch (qtype) {
	case SMB_USER_QUOTA_TYPE:
		/* Set quota for provided UID. */
		return sys_quotactl_4B(path, QCMD(Q_SETQUOTA, USRQUOTA),
					id.uid, &qblk);
	case SMB_USER_FS_QUOTA_TYPE:
		/* Set quota for current UID. */
		return sys_quotactl_4B(path, QCMD(Q_SETQUOTA, USRQUOTA),
					geteuid(), &qblk);
	case SMB_GROUP_QUOTA_TYPE:
		/* Set quota for provided GID. */
		return sys_quotactl_4B(path, QCMD(Q_SETQUOTA, GRPQUOTA),
					id.gid, &qblk);
	case SMB_GROUP_FS_QUOTA_TYPE:
		/* Set quota for current GID. */
		return sys_quotactl_4B(path, QCMD(Q_SETQUOTA, GRPQUOTA),
					getegid(), &qblk);
	default:
		DEBUG(0, ("cannot set unsupported quota type: %u\n",
			    (unsigned)qtype));
		errno = ENOSYS;
		return -1;
	}
}
コード例 #3
0
ファイル: quota.c プロジェクト: baszoetekouw/quotatool
static int generic_quota_get (quota_t *myquota) {
  struct if_dqblk sysquota;
  long retval;
  retval = quotactl(QCMD(Q_GETQUOTA,myquota->_id_type), myquota->_qfile,
		    myquota->_id, (caddr_t) &sysquota);
  if ( retval < 0 ) {
    output_error ("Failed fetching quotas (generic): %s", strerror(errno));
    return 0;
  }

  /* copy the linux-formatted quota info into our struct */
  myquota->block_hard = sysquota.dqb_bhardlimit;
  myquota->block_soft = sysquota.dqb_bsoftlimit;
  myquota->diskspace_used = sysquota.dqb_curspace;
  myquota->inode_hard = sysquota.dqb_ihardlimit;
  myquota->inode_soft = sysquota.dqb_isoftlimit;
  myquota->inode_used = sysquota.dqb_curinodes;
  myquota->block_time = sysquota.dqb_btime;
  myquota->inode_time = sysquota.dqb_itime;

  retval = quotactl(QCMD(Q_GETINFO,myquota->_id_type), myquota->_qfile,
		    myquota->_id, (caddr_t) myquota->_generic_quotainfo);
  if ( retval < 0 ) {
    output_error ("Failed fetching quotainfo (generic): %s", strerror(errno));
    return 0;
  }
  myquota->block_grace = ((struct if_dqinfo *) myquota->_generic_quotainfo)->dqi_bgrace;
  myquota->inode_grace = ((struct if_dqinfo *) myquota->_generic_quotainfo)->dqi_igrace;

  return 1;
}
コード例 #4
0
ファイル: quotas.c プロジェクト: hajuuk/R7000
static int get_smb_linux_xfs_quota(char *path, uid_t euser_id, gid_t egrp_id, LINUX_SMB_DISK_QUOTA *dp)
{
	struct fs_disk_quota D;
	int ret;

	ZERO_STRUCT(D);

	ret = quotactl(QCMD(Q_XGETQUOTA,USRQUOTA), path, euser_id, (caddr_t)&D);

	if (ret)
		ret = quotactl(QCMD(Q_XGETQUOTA,GRPQUOTA), path, egrp_id, (caddr_t)&D);

	if (ret)
		return ret;

	dp->bsize = (SMB_BIG_UINT)512;
	dp->softlimit = (SMB_BIG_UINT)D.d_blk_softlimit;
	dp->hardlimit = (SMB_BIG_UINT)D.d_blk_hardlimit;
	dp->ihardlimit = (SMB_BIG_UINT)D.d_ino_hardlimit;
	dp->isoftlimit = (SMB_BIG_UINT)D.d_ino_softlimit;
	dp->curinodes = (SMB_BIG_UINT)D.d_icount;
	dp->curblocks = (SMB_BIG_UINT)D.d_bcount;

	return ret;
}
コード例 #5
0
int quota_command (value v_user_or_group, int command) {
  if (v_user_or_group == caml_hash_variant("User"))
    return QCMD(command, USRQUOTA);

  if (v_user_or_group == caml_hash_variant("Group"))
    return QCMD(command, GRPQUOTA);

  caml_failwith("Unix.Quota: I only know about `User and `Group");
}
コード例 #6
0
ファイル: quota.c プロジェクト: Netatalk/Netatalk
static int getfsquota(const AFPObj *obj, struct vol *vol, const int uid, struct dqblk *dq)

{
	struct dqblk dqg;

#ifdef __svr4__
    struct quotctl      qc;
#endif

    memset(dq, 0, sizeof(struct dqblk));
    memset(&dqg, 0, sizeof(dqg));
	
#ifdef __svr4__
    qc.op = Q_GETQUOTA;
    qc.uid = uid;
    qc.addr = (caddr_t)dq;
    if ( ioctl( vol->v_qfd, Q_QUOTACTL, &qc ) < 0 ) {
        return( AFPERR_PARAM );
    }

#else /* __svr4__ */
#ifdef ultrix
    if ( quota( Q_GETDLIM, uid, vol->v_gvs, dq ) != 0 ) {
        return( AFPERR_PARAM );
    }
#else /* ultrix */

#ifndef USRQUOTA
#define USRQUOTA   0
#endif

#ifndef QCMD
#define QCMD(a,b)  (a)
#endif

#ifndef TRU64
    /* for group quotas. we only use these if the user belongs
    * to one group. */
#endif /* TRU64 */

#ifdef BSD4_4
    become_root();
        if ( quotactl( vol->v_path, QCMD(Q_GETQUOTA,USRQUOTA),
                       uid, (char *)dq ) != 0 ) {
            /* try group quotas */
            if (obj->ngroups >= 1) {
                if ( quotactl(vol->v_path, QCMD(Q_GETQUOTA, GRPQUOTA),
                              obj->groups[0], (char *) &dqg) != 0 ) {
                    unbecome_root();
                    return( AFPERR_PARAM );
                }
            }
        }
        unbecome_root();
    }
コード例 #7
0
ファイル: quota.c プロジェクト: baszoetekouw/quotatool
static int xfs_quota_get(quota_t *myquota) {
   fs_disk_quota_t sysquota;
   fs_quota_stat_t quotastat;
   int block_diff;	// XFS quota always uses BB (Basic Blocks = 512 bytes)
   int retval;

   block_diff = BLOCK_SIZE / 512;
   retval = quotactl(QCMD(Q_XGETQUOTA, myquota->_id_type), myquota->_qfile,
		     myquota->_id, (caddr_t) &sysquota);
   /*
      ** 2005-04-26  : [email protected] -
                        handling a non-set quota for a user/group
                                             who owns nothing here
   */
   if ( retval < 0 ) {
      // This error has to be explained :
      // if UID/GID has no quota defined, and owns no data, ENOENT error occures
      // but at this point of the code, whe know that this XFS has quotas.
      // We make the choice to produce a "0 0 0 0 0 0 0 0" line.
      if ( errno == ENOENT ) {
         myquota->block_hard 	 = 0;
         myquota->block_soft	 = 0;
         myquota->diskspace_used = 0;
         myquota->inode_hard     = 0;
         myquota->inode_soft     = 0;
         myquota->inode_used     = 0;
         myquota->block_grace	 = 0;
         myquota->inode_grace	 = 0;
         myquota->block_time	 = 0;
         myquota->inode_time	 = 0;
         return 1;
      }
      output_error ("Failed fetching quotas: errno=%d, %s", errno, strerror(errno));
      return 0;
   }

   retval = quotactl(QCMD(Q_XGETQSTAT, myquota->_id_type), myquota->_qfile,
		     myquota->_id, (caddr_t) &quotastat);

   /* copy the linux-xfs-formatted quota info into our struct */
   myquota->block_hard	=  sysquota.d_blk_hardlimit / block_diff;
   myquota->block_soft	=  sysquota.d_blk_softlimit / block_diff;
 // XFS really uses blocks, all other formats in this file use bytes
   myquota->diskspace_used = (sysquota.d_bcount * 1024) / block_diff;
   myquota->inode_hard  =  sysquota.d_ino_hardlimit;
   myquota->inode_soft  =  sysquota.d_ino_softlimit;
   myquota->inode_used  =  sysquota.d_icount;
   myquota->block_grace	=  quotastat.qs_btimelimit;
   myquota->inode_grace	=  quotastat.qs_itimelimit;
   myquota->block_time	=  sysquota.d_btimer;
   myquota->inode_time	=  sysquota.d_itimer;

   return 1;
}
コード例 #8
0
ファイル: feature.c プロジェクト: hyakki-/sgi
int
hasxfsquota(int type, int q, char *device)
{
    fs_quota_stat_t	qstat;
    int		qcmd;

    memset(&qstat, 0, sizeof(fs_quota_stat_t));
    qcmd = QCMD(Q_XGETQSTAT, type);
    if (quotactl(qcmd, device, 0, (caddr_t)&qstat) < 0) {
        if (verbose)
            perror("quotactl");
        return (1);
    }
    else if (q == 0)
        return (0);
    else if (q == XFS_QUOTA_UDQ_ENFD && qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)
        return (0);
    else if (q == XFS_QUOTA_GDQ_ENFD && qstat.qs_flags & XFS_QUOTA_GDQ_ENFD)
        return (0);
    else if (q == XFS_QUOTA_UDQ_ACCT && qstat.qs_flags & XFS_QUOTA_UDQ_ACCT)
        return (0);
    else if (q == XFS_QUOTA_GDQ_ACCT && qstat.qs_flags & XFS_QUOTA_GDQ_ACCT)
        return (0);
    if (verbose)
        fprintf(stderr, "quota type (%d) not available\n", q);
    return (1);
}
コード例 #9
0
ファイル: quota.c プロジェクト: baszoetekouw/quotatool
int quota_get (quota_t *myquota)
{
  struct dqblk sysquota;
  int retval;

  output_debug ("fetching quotas: device='%s',id='%d'",
               myquota->_qfile, myquota->_id);
  retval = quotactl (myquota->_qfile, QCMD(Q_GETQUOTA, myquota->_id_type),
                   myquota->_id, (caddr_t) &sysquota);
  if ( retval < 0 ) {
    output_error ("Failed fetching quotas: %s", strerror (errno));
    return 0;
  }

  /* here, linux.c does a memcpy(), it should also work for darwin,
   * but it's better to be on the safe side
   */
  myquota->block_hard  = sysquota.dqb_bhardlimit;
  myquota->block_soft  = sysquota.dqb_bsoftlimit;
  myquota->diskspace_used  = sysquota.dqb_curbytes;
  myquota->inode_hard  = sysquota.dqb_ihardlimit;
  myquota->inode_soft  = sysquota.dqb_isoftlimit;
  myquota->inode_used  = sysquota.dqb_curinodes ;
  myquota->block_time = (time_t) sysquota.dqb_btime;
  myquota->inode_time = (time_t) sysquota.dqb_itime;

// FIXME: remove debug
//output_info ("BLOCK_SIZE: %d\n", BLOCK_SIZE);
//output_info ("Getting quota soft/hard: %llu, %llu\n", myquota->block_soft, myquota->block_hard);

  return 1;
}
コード例 #10
0
ファイル: repquota.c プロジェクト: 54chen/warden
/**
 * Prints relevant quota information to stdout for the supplied uid.
 * On failure, will attempt to print a helpful error messge to stderr.
 *
 * @param filesystem  Filesystem to report quota information for
 * @param uid         Uid to report quota information for
 *
 * @return            -1 on error, 0 otherwise
 */
static int print_quota_usage(const char* filesystem, int uid) {
  assert(NULL != filesystem);

  char emsg[1024];
  struct dqblk quota_info;

  memset(&quota_info, 0, sizeof(quota_info));

  if (quotactl(QCMD(Q_GETQUOTA, USRQUOTA), filesystem, uid, (caddr_t) &quota_info) < 0) {
    sprintf(emsg, "Failed retrieving quota for uid=%d", uid);
    print_quotactl_error(emsg);
    return -1;
  }

  printf("%d ", uid);

  /* Block info */
  printf("%llu %llu %llu %llu ",
         (long long unsigned int) quota_info.dqb_curspace,
         (long long unsigned int) quota_info.dqb_bsoftlimit,
         (long long unsigned int) quota_info.dqb_bhardlimit,
         (long long unsigned int) quota_info.dqb_btime);

  /* Inode info */
  printf("%llu %llu %llu %llu\n",
         (long long unsigned int) quota_info.dqb_curinodes,
         (long long unsigned int) quota_info.dqb_isoftlimit,
         (long long unsigned int) quota_info.dqb_ihardlimit,
         (long long unsigned int) quota_info.dqb_itime);

  return 0;
}
コード例 #11
0
ファイル: quota.c プロジェクト: juanfra684/DragonFlyBSD
static int
getufsquota(struct fstab *fs, struct quotause *qup, long id, int quotatype)
{
	char *qfpathname;
	int fd, qcmd;

	qcmd = QCMD(Q_GETQUOTA, quotatype);
	if (!ufshasquota(fs, quotatype, &qfpathname))
		return (0);

	if (quotactl(fs->fs_file, qcmd, id, (char *)&qup->dqblk) != 0) {
		if ((fd = open(qfpathname, O_RDONLY)) < 0) {
			warn("%s", qfpathname);
			return (0);
		}
		lseek(fd, (off_t)(id * sizeof(struct ufs_dqblk)), L_SET);
		switch (read(fd, &qup->dqblk, sizeof(struct ufs_dqblk))) {
		case 0:				/* EOF */
			/*
			 * Convert implicit 0 quota (EOF)
			 * into an explicit one (zero'ed dqblk)
			 */
			bzero(&qup->dqblk, sizeof(struct ufs_dqblk));
			break;
		case sizeof(struct ufs_dqblk):	/* OK */
			break;
		default:		/* ERROR */
			warn("read error: %s", qfpathname);
			close(fd);
			return (0);
		}
		close(fd);
	}
	return (1);
}
コード例 #12
0
ファイル: quota.c プロジェクト: baszoetekouw/quotatool
static int old_quota_get (quota_t *myquota) {
  struct old_kern_dqblk sysquota;
  int retval;

  retval = quotactl(QCMD(Q_OLD_GETQUOTA,myquota->_id_type), myquota->_qfile,
		    myquota->_id, (caddr_t) &sysquota);
  if ( retval < 0 ) {
    output_error ("Failed fetching quotas (old): %s", strerror(errno));
    return 0;
  }

  /* copy the linux-formatted quota info into our struct */
  myquota->block_hard  = sysquota.dqb_bhardlimit;
  myquota->block_soft  = sysquota.dqb_bsoftlimit;
  myquota->diskspace_used  = sysquota.dqb_curblocks;
  myquota->inode_hard  = sysquota.dqb_ihardlimit;
  myquota->inode_soft  = sysquota.dqb_isoftlimit;
  myquota->inode_used  = sysquota.dqb_curinodes;
  myquota->block_time  = sysquota.dqb_btime;
  myquota->inode_time  = sysquota.dqb_itime;
  /* yes, something fishy here. quota old seems to lack separate fields
   for user grace times and global grace times.
  is it like XFS - root's limits sets global? */
  myquota->block_grace  = sysquota.dqb_btime;
  myquota->inode_grace  = sysquota.dqb_itime;

  return 1;
}
コード例 #13
0
ファイル: quotactl03.c プロジェクト: kraj/ltp
static void verify_quota(void)
{
	struct fs_disk_quota res_dquota;

	res_dquota.d_id = 1;

	TEST(quotactl(QCMD(Q_XGETNEXTQUOTA, USRQUOTA), tst_device->dev,
		test_id, (void *)&res_dquota));
	if (TST_RET != -1) {
		tst_res(TFAIL, "quotactl() found the next active ID:"
			" %u unexpectedly", res_dquota.d_id);
		return;
	}

	if (TST_ERR == EINVAL) {
		tst_brk(TCONF | TTERRNO,
			"Q_XGETNEXTQUOTA wasn't supported in quotactl()");
	}

	if (TST_ERR != ENOENT) {
		tst_res(TFAIL | TTERRNO, "quotactl() failed unexpectedly with"
			" %s expected ENOENT", tst_strerrno(TST_ERR));
	} else {
		tst_res(TPASS, "quotactl() failed with ENOENT as expected");
	}
}
コード例 #14
0
ファイル: quota.c プロジェクト: baszoetekouw/quotatool
static int old_quota_set(quota_t *myquota) {
   struct old_kern_dqblk sysquota;
   int retval;

  /* copy our data into the linux dqblk */
  sysquota.dqb_bhardlimit = myquota->block_hard;
  sysquota.dqb_bsoftlimit = myquota->block_soft;
  sysquota.dqb_curblocks  = myquota->diskspace_used;
  sysquota.dqb_ihardlimit = myquota->inode_hard;
  sysquota.dqb_isoftlimit = myquota->inode_soft;
  sysquota.dqb_curinodes  = myquota->inode_used;
  /* is old like xfs - global grace set by root's limits? */
  sysquota.dqb_btime      = myquota->block_grace;
  sysquota.dqb_itime      = myquota->inode_grace;

  /* make the syscall */
  retval = quotactl (QCMD(Q_OLD_SETQUOTA,myquota->_id_type),myquota->_qfile,
		     myquota->_id, (caddr_t) &sysquota);
  if ( retval < 0 ) {
    output_error ("Failed setting quota (old): %s", strerror(errno));
    return 0;
  }
  /* success */
  return 1;
}
コード例 #15
0
ファイル: quotactl02.c プロジェクト: sathnaga/ltp
static void check_qlim(int subcmd, char *desp)
{
	int res;
	static struct fs_disk_quota res_dquota;

	res_dquota.d_rtb_softlimit = 0;

	res = quotactl(QCMD(subcmd, USRQUOTA), tst_device->dev,
	               test_id, (void*) &res_dquota);
	if (res == -1) {
		if (errno == EINVAL) {
			tst_brk(TCONF | TERRNO,
				"%s wasn't supported in quotactl()", desp);
		}
		tst_res(TFAIL | TERRNO,
			"quotactl() failed to get xfs disk quota limits");
		return;
	}

	if (res_dquota.d_id != test_id) {
		tst_res(TFAIL, "quotactl() got unexpected user id %u,"
			" expected %u", res_dquota.d_id, test_id);
		return;
	}

	if (res_dquota.d_rtb_hardlimit != set_dquota.d_rtb_hardlimit) {
		tst_res(TFAIL, "quotactl() got unexpected rtb soft limit %llu,"
			" expected %llu", res_dquota.d_rtb_hardlimit,
			set_dquota.d_rtb_hardlimit);
		return;
	}

	tst_res(TPASS, "quoactl() succeeded to set and use %s to get xfs disk "
		"quota limits", desp);
}
コード例 #16
0
ファイル: quota.c プロジェクト: baszoetekouw/quotatool
static int xfs_quota_set(quota_t *myquota) {
   fs_disk_quota_t sysquota;
   int retval;
   int block_diff= BLOCK_SIZE / 512;

   memset(&sysquota, 0, sizeof(fs_disk_quota_t));
   /* copy our data into the linux dqblk */
   sysquota.d_blk_hardlimit = myquota->block_hard * block_diff;
   sysquota.d_blk_softlimit = myquota->block_soft * block_diff;
 // XFS really uses blocks, all other formats in this file use bytes
   sysquota.d_bcount	    = DIV_UP(myquota->diskspace_used * block_diff, 1024);
   sysquota.d_ino_hardlimit = myquota->inode_hard;
   sysquota.d_ino_softlimit = myquota->inode_soft;
   sysquota.d_icount        = myquota->inode_used;
/* For XFS, global grace time limits are set by the values set for root */
   sysquota.d_btimer        = myquota->block_grace;
   sysquota.d_itimer        = myquota->inode_grace;
   sysquota.d_fieldmask	    = FS_DQ_LIMIT_MASK;
   if (myquota->_do_set_global_block_gracetime || myquota->_do_set_global_inode_gracetime)
      sysquota.d_fieldmask |= FS_DQ_TIMER_MASK;

   retval = quotactl(QCMD(Q_XSETQLIM,myquota->_id_type), myquota->_qfile,
		     myquota->_id, (caddr_t) &sysquota);
   if (retval < 0) {
      output_error ("Failed setting quota (xfs): %s", strerror(errno));
      return(0);
   }

   /* success */
   return 1;
}
コード例 #17
0
ファイル: quotafile.c プロジェクト: edgar-pek/PerspicuOS
int
quota_on(struct quotafile *qf)
{
	int qcmd;

	qcmd = QCMD(Q_QUOTAON, qf->quotatype);
	return (quotactl(qf->fsname, qcmd, 0, qf->qfname));
}
コード例 #18
0
ファイル: aoe.c プロジェクト: andrewbasterfield/vblade
int
confcmd(Conf *p, int payload)	// process conf request
{
	int len;

	len = ntohs(p->len);
	if (QCMD(p) != Qread)
	if (len > Nconfig || len > payload)
		return 0;	// if you can't play nice ...
	switch (QCMD(p)) {
	case Qtest:
		if (len != nconfig)
			return 0;
		// fall thru
	case Qprefix:
		if (len > nconfig)
			return 0;
		if (memcmp(config, p->data, len))
			return 0;
		// fall thru
	case Qread:
		break;
	case Qset:
		if (nconfig)
		if (nconfig != len || memcmp(config, p->data, len)) {
			p->h.flags |= Error;
			p->h.error = ConfigErr;
			break;
		}
		// fall thru
	case Qfset:
		nconfig = len;
		memcpy(config, p->data, nconfig);
		break;
	default:
		p->h.flags |= Error;
		p->h.error = BadArg;
	}
	memmove(p->data, config, nconfig);
	p->len = htons(nconfig);
	p->bufcnt = htons(bufcnt);
	p->scnt = maxscnt = (getmtu(sfd, ifname) - sizeof (Ata)) / 512;
	p->firmware = htons(FWV);
	p->vercmd = 0x10 | QCMD(p);	// aoe v.1
	return nconfig + sizeof *p - sizeof p->data;
}
コード例 #19
0
ファイル: sysquotas_4B.c プロジェクト: Alexander--/samba
int sys_get_vfs_quota(const char *path, const char *bdev,
	enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
{
	int ret;
	struct dqblk qblk;

	ZERO_STRUCT(qblk);

	switch (qtype) {
	case SMB_USER_QUOTA_TYPE:
		/* Get quota for provided UID. */
		ret = sys_quotactl_4B(path, QCMD(Q_GETQUOTA, USRQUOTA),
					id.uid, &qblk);
		break;
	case SMB_USER_FS_QUOTA_TYPE:
		/* Get quota for current UID. */
		ret = sys_quotactl_4B(path, QCMD(Q_GETQUOTA, USRQUOTA),
					geteuid(), &qblk);
		break;
	case SMB_GROUP_QUOTA_TYPE:
		/* Get quota for provided GID. */
		ret = sys_quotactl_4B(path, QCMD(Q_GETQUOTA, GRPQUOTA),
					id.gid, &qblk);
		break;
	case SMB_GROUP_FS_QUOTA_TYPE:
		/* Get quota for current GID. */
		ret = sys_quotactl_4B(path, QCMD(Q_GETQUOTA, GRPQUOTA),
					getegid(), &qblk);
		break;
	default:
		DEBUG(0, ("cannot get unsupported quota type: %u\n",
			    (unsigned)qtype));
		errno = ENOSYS;
		return -1;
	}

	if (ret == -1) {
		return -1;
	}

	xlate_qblk_to_smb(&qblk, dp);
	dp->qtype = qtype;

	return ret;
}
コード例 #20
0
ファイル: mkquota.c プロジェクト: YANGYongqiang/e2fsprogs
int is_quota_on(ext2_filsys fs, int type)
{
	char tmp[1024];
	qid_t id = (type == USRQUOTA) ? getuid() : getgid();

	if (!quotactl(QCMD(Q_V2_GETQUOTA, type), fs->device_name, id, tmp))
		return 1;
	return 0;
}
コード例 #21
0
ファイル: quotas.c プロジェクト: livebox/livebox2
BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
{
  int r, save_errno;
  struct dqblk D;
  SMB_STRUCT_STAT S;
  uid_t euser_id;

  /*
   * This code presumes that OSF1 will only
   * give out quota info when the real uid 
   * matches the effective uid. JRA.
   */
  euser_id = geteuid();
  save_re_uid();
  if (set_re_uid() != 0) return False;

  r= quotactl(path,QCMD(Q_GETQUOTA, USRQUOTA),euser_id,(char *) &D);
  if (r) {
     save_errno = errno;
  }

  restore_re_uid();

  *bsize = DEV_BSIZE;

  if (r)
  {
      if (save_errno == EDQUOT)   /* disk quota exceeded */
      {
         *dfree = 0;
         *dsize = D.dqb_curblocks;
         return (True);
      }
      else
         return (False);  
  }

  /* If softlimit is zero, set it equal to hardlimit.
   */

  if (D.dqb_bsoftlimit==0)
    D.dqb_bsoftlimit = D.dqb_bhardlimit;

  /* Use softlimit to determine disk space, except when it has been exceeded */

  if (D.dqb_bsoftlimit==0)
    return(False);

  if ((D.dqb_curblocks>D.dqb_bsoftlimit)) {
    *dfree = 0;
    *dsize = D.dqb_curblocks;
  } else {
    *dfree = D.dqb_bsoftlimit - D.dqb_curblocks;
    *dsize = D.dqb_bsoftlimit;
  }
  return (True);
}
コード例 #22
0
ファイル: quotafile.c プロジェクト: edgar-pek/PerspicuOS
int
quota_write_limits(struct quotafile *qf, struct dqblk *dqb, int id)
{
	struct dqblk dqbuf;
	int qcmd;

	if (qf->fd == -1) {
		qcmd = QCMD(Q_SETQUOTA, qf->quotatype);
		return (quotactl(qf->fsname, qcmd, id, dqb));
	}
	/*
	 * Have to do read-modify-write of quota in file.
	 */
	if ((qf->accmode & O_RDWR) != O_RDWR) {
		errno = EBADF;
		return (-1);
	}
	if (quota_read(qf, &dqbuf, id) != 0)
		return (-1);
	/*
	 * Reset time limit if have a soft limit and were
	 * previously under it, but are now over it
	 * or if there previously was no soft limit, but
	 * now have one and are over it.
	 */
	if (dqbuf.dqb_bsoftlimit && id != 0 &&
	    dqbuf.dqb_curblocks < dqbuf.dqb_bsoftlimit &&
	    dqbuf.dqb_curblocks >= dqb->dqb_bsoftlimit)
		dqb->dqb_btime = 0;
	if (dqbuf.dqb_bsoftlimit == 0 && id != 0 &&
	    dqb->dqb_bsoftlimit > 0 &&
	    dqbuf.dqb_curblocks >= dqb->dqb_bsoftlimit)
		dqb->dqb_btime = 0;
	if (dqbuf.dqb_isoftlimit && id != 0 &&
	    dqbuf.dqb_curinodes < dqbuf.dqb_isoftlimit &&
	    dqbuf.dqb_curinodes >= dqb->dqb_isoftlimit)
		dqb->dqb_itime = 0;
	if (dqbuf.dqb_isoftlimit == 0 && id !=0 &&
	    dqb->dqb_isoftlimit > 0 &&
	    dqbuf.dqb_curinodes >= dqb->dqb_isoftlimit)
		dqb->dqb_itime = 0;
	dqb->dqb_curinodes = dqbuf.dqb_curinodes;
	dqb->dqb_curblocks = dqbuf.dqb_curblocks;
	/*
	 * Write it back.
	 */
	switch (qf->wordsize) {
	case 32:
		return (quota_write32(qf, dqb, id));
	case 64:
		return (quota_write64(qf, dqb, id));
	default:
		errno = EINVAL;
		return (-1);
	}
	/* not reached */
}
コード例 #23
0
/* Get dquot from kernel */
int vfs_get_dquot(struct dquot *dquot)
{
	struct if_dqblk kdqblk;

	if (quotactl(QCMD(Q_GETQUOTA, dquot->dq_h->qh_type), dquot->dq_h->qh_quotadev, dquot->dq_id, (void *)&kdqblk) < 0) {
		errstr(_("Cannot get quota for %s %d from kernel on %s: %s\n"), type2name(dquot->dq_h->qh_type), dquot->dq_id, dquot->dq_h->qh_quotadev, strerror(errno));
		return -1;
	}
	generic_kern2utildqblk(&dquot->dq_dqb, &kdqblk);
	return 0;
}
コード例 #24
0
ファイル: sysquotas_4B.c プロジェクト: Alexander--/samba
static int sys_quotactl_4B(const char * path, int cmd,
		int id, struct dqblk *qblk)
{
	int ret;

	/* NB: We must test GRPQUOTA here, because USRQUOTA is 0. */
	DEBUG(10, ("%s quota for %s ID %u on %s\n",
		    (cmd & QCMD(Q_GETQUOTA, 0)) ? "getting" : "setting",
		    (cmd & QCMD(0, GRPQUOTA)) ? "group" : "user",
		    (unsigned)id, path));

#ifdef HFS_QUOTACTL_WAR
	become_root();
#endif  /* HFS_QUOTACTL_WAR */

	ret = quotactl(path, cmd, id, qblk);
	if (ret == -1) {
		/* ENOTSUP means quota support is not compiled in. EINVAL
		 * means that quotas are not configured (commonly).
		 */
		if (errno != ENOTSUP && errno != EINVAL) {
			DEBUG(0, ("failed to %s quota for %s ID %u on %s: %s\n",
				    (cmd & QCMD(Q_GETQUOTA, 0)) ? "get" : "set",
				    (cmd & QCMD(0, GRPQUOTA)) ? "group" : "user",
				    (unsigned)id, path, strerror(errno)));
		}

#ifdef HFS_QUOTACTL_WAR
		unbecome_root();
#endif  /* HFS_QUOTACTL_WAR */


		return -1;
	}

#ifdef HFS_QUOTACTL_WAR
		unbecome_root();
#endif  /* HFS_QUOTACTL_WAR */

	return 0;
}
コード例 #25
0
/* Get info from kernel to handle */
int vfs_get_info(struct quota_handle *h)
{
	struct if_dqinfo kinfo;

	if (quotactl(QCMD(Q_GETINFO, h->qh_type), h->qh_quotadev, 0, (void *)&kinfo) < 0) {
		errstr(_("Cannot get info for %s quota file from kernel on %s: %s\n"), type2name(h->qh_type), h->qh_quotadev, strerror(errno));
		return -1;
	}
	h->qh_info.dqi_bgrace = kinfo.dqi_bgrace;
	h->qh_info.dqi_igrace = kinfo.dqi_igrace;
	return 0;
}
コード例 #26
0
/* Set dquot in kernel */
int vfs_set_dquot(struct dquot *dquot, int flags)
{
	struct if_dqblk kdqblk;

	generic_util2kerndqblk(&kdqblk, &dquot->dq_dqb);
	kdqblk.dqb_valid = flags;
	if (quotactl(QCMD(Q_SETQUOTA, dquot->dq_h->qh_type), dquot->dq_h->qh_quotadev, dquot->dq_id, (void *)&kdqblk) < 0) {
		errstr(_("Cannot set quota for %s %d from kernel on %s: %s\n"), type2name(dquot->dq_h->qh_type), dquot->dq_id, dquot->dq_h->qh_quotadev, strerror(errno));
		return -1;
	}
	return 0;
}
コード例 #27
0
ファイル: quota.c プロジェクト: baszoetekouw/quotatool
int quota_set (quota_t *myquota){
  struct dqblk sysquota;
  int retval;

  if ( geteuid() != 0 ) {
    output_error ("Only root can set quotas");
    return 0;
  }

// FIXME: remove debug
//output_info ("Setting quota soft/hard: %llu, %llu\n", myquota->block_soft, myquota->block_hard);

  sysquota.dqb_bhardlimit = myquota->block_hard;
  sysquota.dqb_bsoftlimit = myquota->block_soft;
  sysquota.dqb_curbytes   = myquota->diskspace_used;
  sysquota.dqb_ihardlimit = myquota->inode_hard;
  sysquota.dqb_isoftlimit = myquota->inode_soft;
  sysquota.dqb_curinodes  = myquota->inode_used;
  sysquota.dqb_btime      = (int32_t) myquota->block_grace;
  sysquota.dqb_itime      = (int32_t) myquota->inode_grace;

  /* make the syscall */
  retval = quotactl (myquota->_qfile, QCMD(Q_SETQUOTA, myquota->_id_type),
                       myquota->_id, (caddr_t) &sysquota);
  if ( retval < 0 ) {
    output_error ("Failed setting quota: %s", strerror (errno));
    return 0;
  }

  retval = quotactl (myquota->_qfile, QCMD(Q_SYNC, myquota->_id_type),
                       0, NULL);
  if ( retval < 0 ) {
    output_error ("Failed syncing quotas on %s: %s", myquota->_qfile,
                 strerror (errno));
    return 0;
  }

  return 1;
}
コード例 #28
0
ファイル: quota.c プロジェクト: baszoetekouw/quotatool
static int v0_quota_set(quota_t *myquota) {
   struct v0_kern_dqblk sysquota;
   int retval;

   /* copy our data into the linux dqblk */
   sysquota.dqb_bhardlimit = myquota->block_hard;
   sysquota.dqb_bsoftlimit = myquota->block_soft;
   sysquota.dqb_curspace   = myquota->diskspace_used;
   sysquota.dqb_ihardlimit = myquota->inode_hard;
   sysquota.dqb_isoftlimit = myquota->inode_soft;
   sysquota.dqb_curinodes  = myquota->inode_used;
//   sysquota.dqb_btime      = myquota->block_time;
//   sysquota.dqb_itime      = myquota->inode_time;

   /* make the syscall */
   retval = quotactl (QCMD(Q_V0_SETQUOTA,myquota->_id_type),myquota->_qfile,
		      myquota->_id, (caddr_t) &sysquota);
   if ( retval < 0 ) {
      output_error ("Failed setting quota (vfsv0): %s", strerror(errno));
      return 0;
   }

   /* update quotainfo (global gracetimes) */
   if (myquota->_do_set_global_block_gracetime || myquota->_do_set_global_inode_gracetime) {
      if (myquota->_do_set_global_block_gracetime)
	 ((struct v0_kern_dqinfo *) myquota->_v0_quotainfo)->dqi_bgrace = myquota->block_grace;
      if (myquota->_do_set_global_inode_gracetime)
	 ((struct v0_kern_dqinfo *) myquota->_v0_quotainfo)->dqi_igrace = myquota->inode_grace;
      retval = quotactl (QCMD(Q_V0_SETGRACE,myquota->_id_type),myquota->_qfile,
			 myquota->_id, (caddr_t) myquota->_v0_quotainfo);
      if ( retval < 0 ) {
	 output_error ("Failed setting gracetime: %s", strerror(errno));
	 return 0;
      }
   }
   /* success */
   return 1;
}
コード例 #29
0
/* Set info in kernel from handle */
int vfs_set_info(struct quota_handle *h, int flags)
{
	struct if_dqinfo kinfo;

	kinfo.dqi_bgrace = h->qh_info.dqi_bgrace;
	kinfo.dqi_igrace = h->qh_info.dqi_igrace;
	kinfo.dqi_valid = flags;

	if (quotactl(QCMD(Q_SETINFO, h->qh_type), h->qh_quotadev, 0, (void *)&kinfo) < 0) {
		errstr(_("Cannot set info for %s quota file from kernel on %s: %s\n"), type2name(h->qh_type), h->qh_quotadev, strerror(errno));
		return -1;
	}
	return 0;
}
コード例 #30
0
ファイル: linux.c プロジェクト: djwong/xfsprogs
int
xfsquotactl(
	int		command,
	const char	*device,
	uint		type,
	uint		id,
	void		*addr)
{
	int		qcommand, qtype;

	qtype = xtype_to_qtype(type);
	qcommand = xcommand_to_qcommand(command);

	return quotactl(QCMD(qcommand, qtype), device, id, addr);
}