From: syscrc@gsusgi1.gsu.edu (Randy Carpenter)
Subject: Re: Quotas: Pathname to block dev - how??
Organization: Georgia State University
Date: Sat, 10 Oct 1992 19:47:25 GMT

olson@anchor.esd.sgi.com (Dave Olson) writes:

>In <1992Oct9.100213.6272@ohm.york.ac.uk> lgt1@ohm.york.ac.uk (Laurence Tyler (Guest - CompServ)) writes:
>| I'm trying to write some tools for manipulating disk quotas using
>| the quotactl interface, so we can batch up modifications/updates -
>| we have a lot of users so edquota is not an appropriate way to do
>| things. I've hit a few programming problem with it and would
>| appreciate any suggestions:
>| 
>| 1) quotactl requires as a parameter the block special device name of
>| the filesystem whose quotas are to be modified. What is the
>| best/recommended way of translating a filesystem name (or in
>| general, a pathname in that filesystem) into the appropriate block
>| special device name? The 'devnm' command seems to do this but I
>| can't find a programming interface for such a function.
>
>That's because it is decidely non-trivial.  I wrote a library
>that does most of this for some tools we have, but it really
>isn't shippable quality (no documentation, and some clumsy
>interfaces).  I'd just use popen("devnm ...", "r"), if I were
>you.

I discoverd that the edquota(1) works fine if you set the EDITOR environment
variable to "/bin/ed".  This allows you to use a simple Bourne shell script
to add quotas to logins.  Consider the following Bourne shell psuedo-code:

for "Every login batched up" do
   EDITOR=/bin/ed
   export EDITOR
   edquota $login <<END  > /dev/null
   g/^fs /s/soft = [0-9]*/soft = $soft/
   g/^fs /s/hard = [0-9]*/hard = $hard/
   w
   q
END
done

-------------------------------------------------------------------------

That brings me to a question I asked the group last month (I didn't get any
response):

Is it documented anywhere the behavior of the disk quotas system when you
edit the /etc/passwd file?  I've looked and haven't found anything yet.

My only experience with disk quotas is on our SGI so I don't know how it
behaves on other vendor's systems.  The SGI quotas file is documented as
being non-BSD...I guess for efs support or something.

My observations have been the following:

  1. When you add a login to the /etc/passwd file, an entry in the quotas
     file is auto-magically made for the login and the lowest *existing*
     soft and hard limit is assigned.
     
     Can you add someone the system and not enforce quotas for the login?
     My only solution for removing a login from the quotas file without
     removing them from the /etc/passwd file is to use edquota(1) and give
     them a proto-type quota of a login currently without quotas.  For
     example,

	  % edquota -p adm fred

     ...where, adm, does not appear in the quotas file.

  2. When you delete a login from the /etc/passwd file, the entry in the
     quotas file is auto-magically removed for the login.

Can someone enlighten me with an explanation of the proper way to do
this stuff?

-------------------------------------------------------------------------

>| 2) On a similar note, how does one test to see if a filesystem (or
>| pathname in a filesystem) is local or remote? Again, I would like to
>| include such a test in my utility.
>
>There really isn't any way.  statfs and fstatfs will tell you the
>filesystem type, but, that isn't terribly reliable (the number is
>internally generated in the kernel, and doesn't match any defined
>constants anywhere).  You could stat the mount point and look at
>st_dev, and try to use some hacks to figure out that it is NFS,
>but even that isn't reliable (ISO-9660 and DOS filesystems go through
>the automount (i.e. NFS) interface currently).
>
>| 3) One other quotactl problem I need to solve: there is apparently no
>| program interface to read *all* the disk quota entries - only entries
>| for specified uids can be read. Obviously I could do a repquota and
>| then process the resulting file, but that's rather messy. Is there a
>| suppported interface to do what I want, or would I have to write
>| something to read the quota file directly?
>
>Can't help you there, I've never used quotas, and have no desire
>to look it up...

Seems like you could loop on the UID field of the /etc/passwd file and
feed it to the quotactl(2) system call to fill an array of quota values
for every login on the system.

Otherwise, a repquota(1) command piped through awk(1) will work nicely.

>--
>Let no one tell me that silence gives consent,  |   Dave Olson
>because whoever is silent dissents.             |   Silicon Graphics, Inc.
>    Maria Isabel Barreno                        |   olson@sgi.com
-- 
===========================================================================
Randy Carpenter            rcarpent@gsu.edu    $ mkdir matter; cat > matter
Georgia State University   (404) 651-2648      ksh: matter: cannot create  
Wells Computer Center                          $
Newsgroups: comp.sys.sgi