"Fossies" - the Fresh Open Source Software Archive

Member "quotactl-1.00/quotause/quotause_v1.c" (9 Oct 2005, 2874 Bytes) of package /linux/privat/old/quotactl-1.00.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "quotause_v1.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  *
    3  *  Checking routines for old VFS quota format
    4  *
    5  */
    6 
    7 #include <stdio.h>
    8 #include <unistd.h>
    9 #include <string.h>
   10 #include <errno.h>
   11 
   12 #include <giraffe/fatal.h>
   13 
   14 #include "quotaio.h"
   15 #include "quotaio_v1.h"
   16 #include "quotacheck.h"
   17 #include "quotause_v1.h"
   18 #include "dquothash.h"
   19 #include "misc.h"
   20 
   21 
   22 
   23 /* Load all other dquot structures */
   24 static void
   25 load_dquots(const char * const filename,
   26             int          const fd,
   27             int          const type) {
   28 
   29     struct v1_disk_dqblk ddqblk;
   30     struct util_dqblk * udq;
   31     struct dquot * dquotP;
   32     int err;
   33     qid_t id = 0;
   34 
   35     lseek(fd, 0, SEEK_SET);
   36     while ((err = read(fd, &ddqblk, sizeof(ddqblk)))) {
   37         if (err < 0)
   38             fatal("Can't read entry for id %u from quotafile %s.  "
   39                   "errno=%d (%s)",
   40                   (uint) id, filename, errno, strerror(errno));
   41         if (err != sizeof(ddqblk)) {
   42             msg("Entry for id %u is truncated.", (uint) id);
   43             break;
   44         }
   45         if (ddqblk.dqb_bhardlimit == 0
   46             && ddqblk.dqb_bsoftlimit == 0
   47             && ddqblk.dqb_ihardlimit == 0
   48             && ddqblk.dqb_isoftlimit == 0) {
   49             id++;
   50             continue;
   51         }
   52         dquotP = create_dquot(id);
   53         add_dquot(dquotP, type);
   54         udq = &dquotP->dq_dqb;
   55         udq->dqb_bhardlimit = ddqblk.dqb_bhardlimit;
   56         udq->dqb_bsoftlimit = ddqblk.dqb_bsoftlimit;
   57         udq->dqb_ihardlimit = ddqblk.dqb_ihardlimit;
   58         udq->dqb_isoftlimit = ddqblk.dqb_isoftlimit;
   59         udq->dqb_btime = ddqblk.dqb_btime;
   60         udq->dqb_itime = ddqblk.dqb_itime;
   61         ++id;
   62     }
   63 }
   64 
   65 
   66 
   67 /* Load first structure - get grace times */
   68 static int
   69 check_info(const char * const filename,
   70            int          const fd,
   71            int          const type) {
   72 
   73     struct v1_disk_dqblk ddqblk;
   74     int err;
   75 
   76     debug("Loading first quota entry with grace times.");
   77     lseek(fd, 0, SEEK_SET);
   78     err = read(fd, &ddqblk, sizeof(ddqblk));
   79     if (err < 0)
   80         fatal("Can't read first entry from quotafile '%s'.  errno=%d (%s)",
   81               filename, errno, strerror(errno));
   82     if (err != sizeof(ddqblk)) {
   83         msg("WARNING - Quotafile %s was probably truncated.  "
   84             "Can't save quota settings...",
   85             filename);
   86         return -1;
   87     }
   88     old_info[type].dqi_bgrace = ddqblk.dqb_btime;
   89     old_info[type].dqi_igrace = ddqblk.dqb_itime;
   90     debug("First entry loaded.");
   91     return 0;
   92 }
   93 
   94 
   95 
   96 int
   97 v1_buffer_file(const char * const filename,
   98                int          const fd,
   99                int          const type) {
  100 
  101     old_info[type].dqi_bgrace = MAX_DQ_TIME;
  102     old_info[type].dqi_igrace = MAX_IQ_TIME;
  103 
  104     if (flags & FL_NEWFILE) {
  105     } else {
  106         int rc;
  107         rc = check_info(filename, fd, type);
  108         if (rc >= 0)
  109             load_dquots(filename, fd, type);
  110     }
  111     return 0;
  112 }