"Fossies" - the Fresh Open Source Software Archive

Member "quotactl-1.00/quotause/quotaio.h" (29 Sep 2005, 5126 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 "quotaio.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  *
    3  *  Header of IO operations for quota utilities
    4  *
    5  */
    6 
    7 #ifndef _QUOTAIO_H
    8 #define _QUOTAIO_H
    9 
   10 #include <stdbool.h>
   11 #include <limits.h>
   12 #include <sys/types.h>
   13 #include <sys/stat.h>
   14 
   15 #include "quota.h"
   16 #include "dqblk_v1.h"
   17 #include "dqblk_v2.h"
   18 #include "dqblk_rpc.h"
   19 
   20 #define QUOTAFORMATS 4
   21 
   22 #define INITQFBASENAMES {\
   23     "quota",\
   24         "aquota",\
   25         "",\
   26         ""\
   27         }
   28 
   29 enum quotaFileFmt {QF_VFSOLD, QF_VFSV0, QF_XFS};
   30 
   31 const char * const * const fmtnames;
   32 
   33 /*
   34  * Definitions for disk quotas imposed on the average user
   35  * (big brother finally hits Linux).
   36  *
   37  * The following constants define the default amount of time given a user
   38  * before the soft limits are treated as hard limits (usually resulting
   39  * in an allocation failure). The timer is started when the user crosses
   40  * their soft limit, it is reset when they go below their soft limit.
   41  */
   42 #define MAX_IQ_TIME  604800 /* (7*24*60*60) 1 week */
   43 #define MAX_DQ_TIME  604800 /* (7*24*60*60) 1 week */
   44 
   45 #define IOFL_QUOTAON    0x01    /* Is quota enabled in kernel? */
   46 #define IOFL_INFODIRTY  0x02    /* Did info change? */
   47 #define IOFL_RO     0x04    /* Just RO access? */
   48 
   49 struct quotafile_ops;
   50 
   51 /* Generic information about quotafile */
   52 struct util_dqinfo {
   53     time_t dqi_bgrace;  /* Block grace time for given quotafile */
   54     time_t dqi_igrace;  /* Inode grace time for given quotafile */
   55     union {
   56         struct v2_mem_dqinfo v2_mdqi;
   57     } u;            /* Format specific info about quotafile */
   58 };
   59 
   60 /* Structure for one opened quota file */
   61 struct quota_handle {
   62     int qh_fd;      /* Handle of file (-1 when IOFL_QUOTAON) */
   63     int qh_io_flags;    /* IO flags for file */
   64     char qh_quotadev[PATH_MAX]; /* Device file is for */
   65     int qh_type;        /* Type of quotafile */
   66     enum quotaFileFmt qh_fmt;     /* Quotafile format */
   67     struct stat qh_stat;    /* stat(2) for qh_quotadev */
   68     struct quotafile_ops *qh_ops;   /* Operations on quotafile */
   69     struct util_dqinfo qh_info;
   70         /* Generic quotafile info.  This is a cache of data in the
   71            quota file.
   72         */
   73 };
   74 
   75 /* Statistics gathered from kernel */
   76 struct util_dqstats {
   77     u_int32_t lookups;
   78     u_int32_t drops;
   79     u_int32_t reads;
   80     u_int32_t writes;
   81     u_int32_t cache_hits;
   82     u_int32_t allocated_dquots;
   83     u_int32_t free_dquots;
   84     u_int32_t syncs;
   85     u_int32_t version;
   86 };
   87 
   88 /* Utility quota block */
   89 struct util_dqblk {
   90     qsize_t dqb_ihardlimit;
   91     qsize_t dqb_isoftlimit;
   92     qsize_t dqb_curinodes;
   93     qsize_t dqb_bhardlimit;
   94     qsize_t dqb_bsoftlimit;
   95     qsize_t dqb_curspace;
   96     time_t dqb_btime;
   97     time_t dqb_itime;
   98 };
   99 
  100 #define DQ_FOUND 0x01       /* Dquot was found in the edquotas file */
  101 #define DQ_PRINTED 0x02     /* Dquota has been already printed by repquota */
  102 
  103 /* Structure for one loaded quota */
  104 struct dquot {
  105     struct dquot *dq_next;  /* Pointer to next dquot in the list */
  106     qid_t dq_id;        /* ID dquot belongs to */
  107     int dq_flags;       /* Some flags for utils */
  108     struct util_dqblk dq_dqb;   /* Parsed data of dquot */
  109 };
  110 
  111 /* Flags for commit function (have effect only when quota in kernel is
  112    turned on)
  113 */
  114 #define COMMIT_USAGE QIF_USAGE
  115 #define COMMIT_LIMITS QIF_LIMITS
  116 #define COMMIT_TIMES QIF_TIMES
  117 #define COMMIT_ALL (COMMIT_USAGE | COMMIT_LIMITS | COMMIT_TIMES)
  118 
  119 enum opentype {OPEN_NEW, OPEN_READ};
  120 
  121 typedef int (*dquotReportFn)(struct dquot * dquot, const char * dqname);
  122 
  123 /* Structure of quotafile operations */
  124 struct quotafile_ops {
  125     bool (*check_file) (int fd, int type);
  126         /* Check whether quotafile is in our format */
  127     int (*create_file) (struct quota_handle * h);
  128         /* Create new quota file */
  129     int (*init_read) (struct quota_handle * h);
  130         /* Initialize access of existing quota file */
  131     int (*end_io) (struct quota_handle * h);
  132         /* Write all changes and close quotafile */
  133     int (*write_info) (struct quota_handle * h);
  134         /* Write info about quotafile */
  135     struct dquot *(*read_dquot) (struct quota_handle * h, qid_t id);
  136         /* Read dquot into memory */
  137     int (*write_dquot) (struct quota_handle *, struct dquot *);
  138         /* Write given dquot to disk */
  139     int (*scan_dquots) (struct quota_handle * h, dquotReportFn dquotFn);
  140         /* Scan quotafile and call callback on every structure */
  141     int (*report) (struct quota_handle * h, bool verbose);
  142         /* Function called after 'repquota' to print format specific
  143            file information
  144         */
  145 };
  146 
  147 
  148 
  149 static inline void
  150 mark_quotafile_info_dirty(struct quota_handle * const h) {
  151     h->qh_io_flags |= IOFL_INFODIRTY;
  152 }
  153 
  154 #define QIO_ENABLED(h)  ((h)->qh_io_flags & IOFL_QUOTAON)
  155 #define QIO_RO(h)   ((h)->qh_io_flags & IOFL_RO)
  156 
  157 void
  158 new_io(enum opentype          const opentype,
  159        const char *           const qfname,
  160        int                    const type,
  161        enum quotaFileFmt      const fmt,
  162        struct quota_handle ** const quotaFilePP,
  163        const char **          const errorP);
  164 
  165 int
  166 end_io(struct quota_handle * const h);
  167 
  168 /* Get empty quota structure */
  169 struct dquot *get_empty_dquot(void);
  170 
  171 #endif /* _QUOTAIO_H */