SUMMARY: Setting quotas from a C program on Solaris 2.3

From: Marc Mazuhelli (mazu@dmi.usherb.ca)
Date: Wed Sep 14 1994 - 23:41:11 CDT


A few weeks ago I sent the following message:

===========================================================================

>On Solaris 1, we use the "quotactl" system call to maintain the quotas of
>our users. We have a new SPARCserver 20-612 which runs Solaris 2.3
>(we have to run Solaris 2 since it's a multi-processor), and we can't
>find a system call to do the same thing. quotactl doesn't exist anymore,
>and the transition guide talked about fcntl which doesn't seem to have
>anything to do with quotas. We're stuck! We need help!
>
>Thank you for any solution to this problem.

===========================================================================

I received 7 replies:

2 "me toos";

1 person told me that even though Sun doesn't like to admit it, Solaris
1.1.1B runs on a multi-processor SPARCstation 10-512 so it could work on
our 20-612 (but we don't want to take the chance!);

1 person tells me that he directly reads and writes the "quotas" file.
(although this could work, I think the next solution is more elegant and
it's less risky);

3 persons told me that although it's not documented, this can be done
with the "ioctl" system call. This ends up being the "right" way to do
it, and IT WORKS!

I ended up taking the "quotactl" function that
veronica@solution.maths.unsw.edu.au sent me (I modified it just a little
bit). This function imitates Solaris 1's quotactl system call. The only
difference is that on Solaris 1, you need to specify the name of the block
special device where the file system resides, whereas in Solaris 2, you
have to speficy a file residing on the file system. We chose to use the
"quotas" file which should exist if quotas are active on a partition.

This way we can use the same program as before, just by compiling with
-DSOLARIS2 (see below).

Contrary to what some people seem to think, the file can be opened READ
ONLY even if you want to MODIFY the quotas.

Thanks to the following 5 people who suggested ways to fix my problem.

        Mic Kaczmarczik <mic@uts.cc.utexas.edu>
        veronica@solution.maths.unsw.edu.au
        R S Haigh <ecl6rsh@gps1.leeds.ac.uk>
        Ian MacPhedran <Ian_MacPhedran@engr.usask.ca>
        Rob Norman <misran@stormy.santos.com.au>

Here's our "quotactl" function:

#ifdef SOLARIS2
 
#include <fcntl.h>
#include <sys/fs/ufs_quota.h>
 
/*
 * define the "quotactl" function as in Solaris 1, based on ioctl().
 * The "special" parameter is any file on the file system,
 * not the block special device name as in Solaris 1.
 * We use the "quotas" file at the top level of the file system.
 * Thanks to veronica@solution.maths.unsw.edu.au who provided
 * the idea and the basis for this function.
 */
 
int
quotactl(int cmd, char *special, uid_t uid, struct dqblk * addr)
{
    struct quotctl op;
    int fd = open(special, O_RDONLY);
 
    if (fd < 0)
        return -1;
 
    op.op = cmd;
    op.uid = uid;
    op.addr = (caddr_t) addr;
 
    if (ioctl(fd, Q_QUOTACTL, &op) < 0) {
        close(fd);
        return -1;
    }
    close(fd);
    return (0);
}
#endif /* SOLARIS2 */

Marc.

--
{  Marc Mazuhelli                 |  analyst in charge of computer labs     }
{  marc.mazuhelli@dmi.USherb.CA   |  Department of math and comp. science   }
{  <this space intentionally ...  |  Universite de Sherbrooke               }
{       ... left (almost) blank>  |  Sherbrooke, Quebec, Canada             }



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:09:09 CDT