Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 1 | /** quotaio.h |
| 2 | * |
| 3 | * Header of IO operations for quota utilities |
| 4 | * Jan Kara <jack@suse.cz> |
| 5 | */ |
| 6 | |
| 7 | #ifndef GUARD_QUOTAIO_H |
| 8 | #define GUARD_QUOTAIO_H |
| 9 | |
| 10 | #include <limits.h> |
| 11 | #include <sys/types.h> |
| 12 | #include <sys/stat.h> |
| 13 | |
| 14 | #include "ext2fs/ext2fs.h" |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 15 | #include "dqblk_v2.h" |
| 16 | |
Jan Kara | 2ae58b6 | 2012-06-04 12:51:55 -0400 | [diff] [blame] | 17 | typedef int64_t qsize_t; /* Type in which we store size limitations */ |
| 18 | |
| 19 | #define MAXQUOTAS 2 |
| 20 | #define USRQUOTA 0 |
| 21 | #define GRPQUOTA 1 |
| 22 | |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 23 | /* |
Jan Kara | 2ae58b6 | 2012-06-04 12:51:55 -0400 | [diff] [blame] | 24 | * Definitions of magics and versions of current quota files |
| 25 | */ |
| 26 | #define INITQMAGICS {\ |
| 27 | 0xd9c01f11, /* USRQUOTA */\ |
| 28 | 0xd9c01927 /* GRPQUOTA */\ |
| 29 | } |
| 30 | |
| 31 | /* Size of blocks in which are counted size limits in generic utility parts */ |
| 32 | #define QUOTABLOCK_BITS 10 |
| 33 | #define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS) |
| 34 | #define toqb(x) (((x) + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS) |
| 35 | |
| 36 | /* Quota format type IDs */ |
| 37 | #define QFMT_VFS_OLD 1 |
| 38 | #define QFMT_VFS_V0 2 |
| 39 | #define QFMT_VFS_V1 4 |
| 40 | |
| 41 | /* |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 42 | * The following constants define the default amount of time given a user |
| 43 | * before the soft limits are treated as hard limits (usually resulting |
| 44 | * in an allocation failure). The timer is started when the user crosses |
| 45 | * their soft limit, it is reset when they go below their soft limit. |
| 46 | */ |
| 47 | #define MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */ |
| 48 | #define MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */ |
| 49 | |
Jan Kara | 2ae58b6 | 2012-06-04 12:51:55 -0400 | [diff] [blame] | 50 | #define IOFL_INFODIRTY 0x01 /* Did info change? */ |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 51 | |
| 52 | struct quotafile_ops; |
| 53 | |
| 54 | /* Generic information about quotafile */ |
| 55 | struct util_dqinfo { |
| 56 | time_t dqi_bgrace; /* Block grace time for given quotafile */ |
| 57 | time_t dqi_igrace; /* Inode grace time for given quotafile */ |
| 58 | union { |
| 59 | struct v2_mem_dqinfo v2_mdqi; |
| 60 | } u; /* Format specific info about quotafile */ |
| 61 | }; |
| 62 | |
| 63 | struct quota_file { |
| 64 | ext2_filsys fs; |
| 65 | ext2_ino_t ino; |
| 66 | ext2_file_t e2_file; |
| 67 | }; |
| 68 | |
| 69 | /* Structure for one opened quota file */ |
| 70 | struct quota_handle { |
| 71 | int qh_type; /* Type of quotafile */ |
| 72 | int qh_fmt; /* Quotafile format */ |
| 73 | int qh_io_flags; /* IO flags for file */ |
| 74 | struct quota_file qh_qf; |
Theodore Ts'o | d6120a2 | 2011-10-04 11:46:21 -0400 | [diff] [blame] | 75 | unsigned int (*e2fs_read)(struct quota_file *qf, ext2_loff_t offset, |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 76 | void *buf, unsigned int size); |
Theodore Ts'o | d6120a2 | 2011-10-04 11:46:21 -0400 | [diff] [blame] | 77 | unsigned int (*e2fs_write)(struct quota_file *qf, ext2_loff_t offset, |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 78 | void *buf, unsigned int size); |
| 79 | struct quotafile_ops *qh_ops; /* Operations on quotafile */ |
| 80 | struct util_dqinfo qh_info; /* Generic quotafile info */ |
| 81 | }; |
| 82 | |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 83 | /* Utility quota block */ |
| 84 | struct util_dqblk { |
| 85 | qsize_t dqb_ihardlimit; |
| 86 | qsize_t dqb_isoftlimit; |
| 87 | qsize_t dqb_curinodes; |
| 88 | qsize_t dqb_bhardlimit; |
| 89 | qsize_t dqb_bsoftlimit; |
| 90 | qsize_t dqb_curspace; |
| 91 | time_t dqb_btime; |
| 92 | time_t dqb_itime; |
| 93 | union { |
| 94 | struct v2_mem_dqblk v2_mdqb; |
| 95 | } u; /* Format specific dquot information */ |
| 96 | }; |
| 97 | |
| 98 | /* Structure for one loaded quota */ |
| 99 | struct dquot { |
| 100 | struct dquot *dq_next; /* Pointer to next dquot in the list */ |
| 101 | qid_t dq_id; /* ID dquot belongs to */ |
| 102 | int dq_flags; /* Some flags for utils */ |
| 103 | struct quota_handle *dq_h; /* Handle of quotafile for this dquot */ |
| 104 | struct util_dqblk dq_dqb; /* Parsed data of dquot */ |
| 105 | }; |
| 106 | |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 107 | /* Structure of quotafile operations */ |
| 108 | struct quotafile_ops { |
| 109 | /* Check whether quotafile is in our format */ |
| 110 | int (*check_file) (struct quota_handle *h, int type, int fmt); |
| 111 | /* Open quotafile */ |
| 112 | int (*init_io) (struct quota_handle *h); |
| 113 | /* Create new quotafile */ |
| 114 | int (*new_io) (struct quota_handle *h); |
| 115 | /* Write all changes and close quotafile */ |
| 116 | int (*end_io) (struct quota_handle *h); |
| 117 | /* Write info about quotafile */ |
| 118 | int (*write_info) (struct quota_handle *h); |
| 119 | /* Read dquot into memory */ |
| 120 | struct dquot *(*read_dquot) (struct quota_handle *h, qid_t id); |
| 121 | /* Write given dquot to disk */ |
Theodore Ts'o | b5ba6f5 | 2011-10-05 13:26:59 -0400 | [diff] [blame] | 122 | int (*commit_dquot) (struct dquot *dquot); |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 123 | /* Scan quotafile and call callback on every structure */ |
| 124 | int (*scan_dquots) (struct quota_handle *h, |
| 125 | int (*process_dquot) (struct dquot *dquot, |
Niu | 198d20f | 2011-11-14 10:58:28 -0500 | [diff] [blame] | 126 | void *data), |
| 127 | void *data); |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 128 | /* Function to print format specific file information */ |
| 129 | int (*report) (struct quota_handle *h, int verbose); |
| 130 | }; |
| 131 | |
| 132 | /* This might go into a special header file but that sounds a bit silly... */ |
| 133 | extern struct quotafile_ops quotafile_ops_meta; |
| 134 | |
Aditya Kali | a86d55d | 2011-11-14 10:55:54 -0500 | [diff] [blame] | 135 | /* Open existing quotafile of given type (and verify its format) on given |
| 136 | * filesystem. */ |
| 137 | errcode_t quota_file_open(struct quota_handle *h, ext2_filsys fs, |
Niu | 198d20f | 2011-11-14 10:58:28 -0500 | [diff] [blame] | 138 | ext2_ino_t qf_ino, int type, int fmt, int flags); |
| 139 | |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 140 | |
| 141 | /* Create new quotafile of specified format on given filesystem */ |
Aditya Kali | a86d55d | 2011-11-14 10:55:54 -0500 | [diff] [blame] | 142 | errcode_t quota_file_create(struct quota_handle *h, ext2_filsys fs, |
| 143 | int type, int fmt); |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 144 | |
| 145 | /* Close quotafile */ |
Aditya Kali | a86d55d | 2011-11-14 10:55:54 -0500 | [diff] [blame] | 146 | errcode_t quota_file_close(struct quota_handle *h); |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 147 | |
| 148 | /* Get empty quota structure */ |
| 149 | struct dquot *get_empty_dquot(void); |
| 150 | |
Aditya Kali | a86d55d | 2011-11-14 10:55:54 -0500 | [diff] [blame] | 151 | errcode_t quota_inode_truncate(ext2_filsys fs, ext2_ino_t ino); |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 152 | |
| 153 | const char *type2name(int type); |
| 154 | |
Theodore Ts'o | edbfd75 | 2011-10-04 11:20:50 -0400 | [diff] [blame] | 155 | void update_grace_times(struct dquot *q); |
| 156 | |
Theodore Ts'o | 2f7d855 | 2011-11-27 20:31:36 -0500 | [diff] [blame] | 157 | /* size for the buffer returned by quota_get_qf_name(); must be greater |
| 158 | than maxlen of extensions[] and fmtnames[] (plus 2) found in quotaio.c */ |
| 159 | #define QUOTA_NAME_LEN 16 |
| 160 | |
| 161 | const char *quota_get_qf_name(int type, int fmt, char *buf); |
| 162 | const char *quota_get_qf_path(const char *mntpt, int qtype, int fmt, |
| 163 | char *path_buf, size_t path_buf_size); |
| 164 | |
Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 165 | #endif /* GUARD_QUOTAIO_H */ |