示例#1
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;
}
示例#2
0
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;
}
示例#3
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;
}
示例#4
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();
    }
示例#5
0
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;
}
示例#6
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);
}
示例#7
0
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;
}
示例#8
0
static void
putdiscq(uid_t uid)
{
	struct fsquot *fsqp;

	for (fsqp = fsqlist; fsqp; fsqp = fsqp->fsq_next) {
		if (quotactl(Q_SETQLIM, fsqp->fsq_dev, uid,
		    (caddr_t)&fsqp->fsq_dqb) != 0) {
			int fd;

			if ((fd = open64(fsqp->fsq_qfile, O_RDWR)) < 0) {
				(void) fprintf(stderr, "edquota: ");
				perror(fsqp->fsq_qfile);
				continue;
			}
			(void) llseek(fd, (offset_t)dqoff(uid), L_SET);
			if (write(fd, (char *)&fsqp->fsq_dqb,
			    sizeof (struct dqblk)) != sizeof (struct dqblk)) {
				(void) fprintf(stderr, "edquota: ");
				perror(fsqp->fsq_qfile);
			}
			(void) close(fd);
		}
	}
}
示例#9
0
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
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);
}
示例#11
0
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;
}
示例#12
0
/**
 * FSAL_get_quota :
 * Gets the quota for a given path.
 *
 * \param  pfsal_path
 *        path to the filesystem whose quota are requested
 * \param quota_type
 *         the kind of requested quota (user or group)
 * \param  fsal_uid
 * 	  uid for the user whose quota are requested
 * \param pquota (input):
 *        Parameter to the structure containing the requested quotas
 *
 * \return Major error codes :
 *        - ERR_FSAL_NO_ERROR     (no error)
 *        - Another error code if an error occured.
 */
fsal_status_t COMMON_get_quota(fsal_path_t * pfsal_path,       /* IN */
                                int quota_type, /* IN */
                                fsal_uid_t fsal_uid,    /* IN */
                                fsal_quota_t * pquota)  /* OUT */
{
  struct dqblk fs_quota;
  char fs_spec[MAXPATHLEN];

  if(!pfsal_path || !pquota)
    ReturnCode(ERR_FSAL_FAULT, 0);

  if(fsal_internal_path2fsname(pfsal_path->path, fs_spec) == -1)
    ReturnCode(ERR_FSAL_INVAL, 0);

  memset((char *)&fs_quota, 0, sizeof(struct dqblk));

  if(quotactl(FSAL_QCMD(Q_GETQUOTA, quota_type), fs_spec, fsal_uid, (caddr_t) & fs_quota)
     < 0)
    ReturnCode(posix2fsal_error(errno), errno);

  /* Convert XFS structure to FSAL one */
  pquota->bhardlimit = fs_quota.dqb_bhardlimit;
  pquota->bsoftlimit = fs_quota.dqb_bsoftlimit;
  pquota->curblocks = fs_quota.dqb_curspace;
  pquota->fhardlimit = fs_quota.dqb_ihardlimit;
  pquota->curfiles = fs_quota.dqb_curinodes;
  pquota->btimeleft = fs_quota.dqb_btime;
  pquota->ftimeleft = fs_quota.dqb_itime;
  pquota->bsize = DEV_BSIZE;

  ReturnCode(ERR_FSAL_NO_ERROR, 0);
}                               /*  FSAL_get_quota */
示例#13
0
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;
}
示例#14
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;
}
示例#15
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");
	}
}
示例#16
0
/*
 *  do_quotactl()
 *	do a quotactl command
 */
static void do_quotactl(
	const char *name,
	const int flag,
	const char *cmdname,
	int *tested,
	int *failed,
	int *enosys,
	int cmd,
	const char *special,
	int id,
	caddr_t addr)
{
	static int failed_mask = 0;
	int ret = quotactl(cmd, special, id, addr);

	(*tested)++;
	if (ret < 0) {
		if ((failed_mask & flag) == 0) {
			/* Just issue the warning once, reduce log spamming */
			failed_mask |= flag;
			pr_fail(stderr, "%s: quotactl command %s failed: errno=%d (%s)\n",
				name, cmdname, errno, strerror(errno));
		}
		if (errno == ENOSYS)
			(*enosys)++;
		else
			(*failed)++;
	}
}
示例#17
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);
}
示例#18
0
int
quota_on(struct quotafile *qf)
{
	int qcmd;

	qcmd = QCMD(Q_QUOTAON, qf->quotatype);
	return (quotactl(qf->fsname, qcmd, 0, qf->qfname));
}
示例#19
0
文件: sysquotas.c 项目: aosm/samba
 int autoconf_quota(void)
{
	int ret = -1;
	struct q_request request;

	ret = quotactl("/", Q_GETQUOTA, &request);

	return ret;
}
示例#20
0
文件: sysquotas.c 项目: aosm/samba
 int autoconf_quota(void)
{
	int ret = -1;
	struct dqblk D;

	ret = quotactl("/",Q_GETQUOTA,0,(char *) &D);

	return ret;
}
示例#21
0
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;
}
示例#22
0
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
文件: sysquotas.c 项目: aosm/samba
 int autoconf_quota(void)
{
	int ret = -1;
	struct SYS_DQBLK D;

	ret = quotactl(Q_GETQUOTA,"/dev/hda1",0,(void *)&D);
	
	return ret;
}
示例#24
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);
}
示例#25
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;
}
示例#26
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;
}
示例#27
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;
}
示例#28
0
文件: quotactl02.c 项目: bsbrp/ltp
static void verify_quota(unsigned int n)
{
    struct t_case *tc = &tcases[n];

    TEST(quotactl(tc->cmd, tst_device->dev, test_id, tc->addr));
    if (TEST_RETURN == -1) {
        tst_res(TFAIL | TTERRNO, "quotactl() failed to %s", tc->des);
        return;
    }

    tc->func_check(tc->des);
}
示例#29
0
文件: irix.c 项目: Fleurer/xfsprogs
int
xfsquotactl(
	int		command,
	const char	*device,
	uint		type,
	uint		id,
	void		*addr)
{
	int		qcommand;

	qcommand = xcommand_to_qcommand(command, type);
	return quotactl(qcommand, (char *)device, id, addr);
}
示例#30
0
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;
}