quotactl doesn't work with RH 9

quotactl doesn't work with RH 9

Post by John Hei » Sun, 22 Jun 2003 07:14:59



I'm not 100% sure of the sequence of events but I think a program I was
working on stopped working when I installed RH 9. The code is below.
Like I said, I was working on it right before I did the upgrade (from
RH 7.1) but I think it was working before the upgrade.

I know quotas are turned on on /dev/hda4 thusly:

$ quota
Disk quotas for user jhe (uid 500):
Filesystem  blocks   quota   limit   grace   files   quota   limit  
grace
/dev/hda4   50476  200000  204800               7       0       0

Yet the program below says "Invalid arguement".

$ gcc -o getQuota getQuota.c
$ getQuota
quotactl : Invalid argument

--- Begin code ----

#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <linux/quota.h>

int main (int argc, char **argv)
        {
        char special[MAXPATHLEN + 1];
        qid_t gid;
        struct mem_dqblk dq;

        strcpy ((char *)special, "/dev/hda4");
        gid = 500;

        if (quotactl (QCMD(Q_GETQUOTA, USRQUOTA), (char *)special, 500,
&dq) != 0)
                { perror("quotactl "); }
        else
                {
                printf ("%s %d\n", "Hard Limit:", dq.dqb_ihardlimit);
                printf ("%s %d\n", "Soft limit:", dq.dqb_isoftlimit);
                printf ("%s %d\n", "Current space:", dq.dqb_curspace);
                }

        }

 
 
 

quotactl doesn't work with RH 9

Post by Michael Kerris » Tue, 24 Jun 2003 16:57:41


On Fri, 20 Jun 2003 22:14:59 +0000 (UTC), John Heim


>I'm not 100% sure of the sequence of events but I think a program I was
>working on stopped working when I installed RH 9. The code is below.
>Like I said, I was working on it right before I did the upgrade (from
>RH 7.1) but I think it was working before the upgrade.

>I know quotas are turned on on /dev/hda4 thusly:

>$ quota
>Disk quotas for user jhe (uid 500):
>Filesystem  blocks   quota   limit   grace   files   quota   limit  
>grace
>/dev/hda4   50476  200000  204800               7       0       0

>Yet the program below says "Invalid arguement".

>$ gcc -o getQuota getQuota.c
>$ getQuota
>quotactl : Invalid argument

There are two types of quota system on Linux: old (vfsold), which is
what your program is using, and new (vfsv0).  Probably the switch from
one to the other occurred betw* RH 7.1 and 9.

See:
quuota(1)
convertquota(8)
http://www.veryComputer.com/

Cheers,

Michael

- Show quoted text -

Quote:

>--- Begin code ----

>#include <stdio.h>
>#include <sys/types.h>
>#include <sys/param.h>
>#include <linux/quota.h>

>int main (int argc, char **argv)
>    {
>    char special[MAXPATHLEN + 1];
>    qid_t gid;
>    struct mem_dqblk dq;

>    strcpy ((char *)special, "/dev/hda4");
>    gid = 500;

>    if (quotactl (QCMD(Q_GETQUOTA, USRQUOTA), (char *)special, 500,
>&dq) != 0)
>            { perror("quotactl "); }
>    else
>            {
>            printf ("%s %d\n", "Hard Limit:", dq.dqb_ihardlimit);
>            printf ("%s %d\n", "Soft limit:", dq.dqb_isoftlimit);
>            printf ("%s %d\n", "Current space:", dq.dqb_curspace);
>            }

>    }


 
 
 

quotactl doesn't work with RH 9

Post by Michael Kerris » Tue, 24 Jun 2003 17:15:11


Also see:

http://sourceforge.net/projects/linuxquota

 
 
 

quotactl doesn't work with RH 9

Post by John Hei » Thu, 26 Jun 2003 06:38:48


Quote:> There are two types of quota system on Linux: old (vfsold), which is
> what your program is using, and new (vfsv0).  Probably the switch
from
> one to the other occurred betw* RH 7.1 and 9.

But how do I query a vfsv0 quota in a C program then? The quotactl
function doesn't work anymore? Is there anotehr function?
Quote:>>--- Begin code ----

>>#include <stdio.h>
>>#include <sys/types.h>
>>#include <sys/param.h>
>>#include <linux/quota.h>

>>int main (int argc, char **argv)
>>     {
>>     char special[MAXPATHLEN + 1];
>>     qid_t gid;
>>     struct mem_dqblk dq;

>>     strcpy ((char *)special, "/dev/hda4");
>>     gid = 500;

>>     if (quotactl (QCMD(Q_GETQUOTA, USRQUOTA), (char *)special, 500,
>>&dq) != 0)
>>          { perror("quotactl "); }
>>     else
>>          {
>>          printf ("%s %d\n", "Hard Limit:", dq.dqb_ihardlimit);
>>          printf ("%s %d\n", "Soft limit:", dq.dqb_isoftlimit);
>>          printf ("%s %d\n", "Current space:", dq.dqb_curspace);
>>          }

>>     }

 
 
 

quotactl doesn't work with RH 9

Post by Michael Kerris » Thu, 26 Jun 2003 15:57:40


On Tue, 24 Jun 2003 21:38:48 +0000 (UTC), John Heim


>> There are two types of quota system on Linux: old (vfsold), which is
>> what your program is using, and new (vfsv0).  Probably the switch
>from
>> one to the other occurred betw* RH 7.1 and 9.

>But how do I query a vfsv0 quota in a C program then? The quotactl
>function doesn't work anymore? Is there anotehr function?

You still use the quota funtion, bur different requests and arguments.
E.g., instead of Q_GETQUOTA, use Q_V2_GETQUOTA.

Try looking at the source of the various quota related programs
(quota1(1), edquota(8), etc.).

Cheers

Michael

 
 
 

quotactl doesn't work with RH 9

Post by John Hei » Fri, 27 Jun 2003 02:44:52



Quote:> You still use the quota funtion, bur different requests and
arguments.
> E.g., instead of Q_GETQUOTA, use Q_V2_GETQUOTA.

> Try looking at the source of the various quota related programs
> (quota1(1), edquota(8), etc.).

Holy cow! Man, this was like pulling teeth.  The docs and the the
linux/quota.h header file need to be updated. But, well, I got it to
work. I stole most of the code from the source for the perl Quota
module (which I already had on my system).  

I'll reproduce my code below for the benefit of anyone else who may
someday be searching usenet for a solution to this same problem. But
the Quota.pm perl module source code probably provides a better
example.

-- Begin code ----

#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <linux/quota.h>

#define DEV_QBSIZE 1024
#define Q_V3_GETQUOTA  0x800007

struct dqblk_v3
        {
        u_int64_t dqb_bhardlimit;
        u_int64_t dqb_bsoftlimit;
        u_int64_t dqb_curspace;
        u_int64_t dqb_ihardlimit;
        u_int64_t dqb_isoftlimit;
        u_int64_t dqb_curinodes;
        u_int64_t dqb_btime;
        u_int64_t dqb_itime;
        u_int32_t dqb_valid;
        };

int main (int argc, char **argv)
        {
        int ret;
        char dev[MAXPATHLEN];
        int gid;

    struct dqblk_v3 dqb3;

        strcpy ((char *)dev, "/dev/hda4");
        gid = 500;

    ret = quotactl (QCMD(Q_V3_GETQUOTA, GRPQUOTA), dev, gid, &dqb3);
    if (ret != 0)
                { perror("quotactl "); }
        else
        {
        printf ("Hard: %d\n", dqb3.dqb_bhardlimit);
        printf ("Soft: %d\n", dqb3.dqb_bsoftlimit);
        printf ("Curr: %d\n", dqb3.dqb_curspace / DEV_QBSIZE);
        printf ("Hard: %d\n", dqb3.dqb_ihardlimit);
        printf ("Soft: %d\n", dqb3.dqb_isoftlimit);
        printf ("Curr: %d\n", dqb3.dqb_curinodes);
        printf ("Time: %d\n", dqb3.dqb_btime);
        printf ("Item: %d\n", dqb3.dqb_itime);
        }

        }
        >