blob: 1c062f10dcb7ba9a67da914e75f0af022de4c458 [file] [log] [blame]
Aditya Kalif239fef2011-07-20 11:40:02 -07001/** 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 Kalif239fef2011-07-20 11:40:02 -070015#include "dqblk_v2.h"
16
Jan Kara2ae58b62012-06-04 12:51:55 -040017typedef 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 Kalif239fef2011-07-20 11:40:02 -070023/*
Jan Kara2ae58b62012-06-04 12:51:55 -040024 * 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 Kalif239fef2011-07-20 11:40:02 -070042 * 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 Kara2ae58b62012-06-04 12:51:55 -040050#define IOFL_INFODIRTY 0x01 /* Did info change? */
Aditya Kalif239fef2011-07-20 11:40:02 -070051
52struct quotafile_ops;
53
54/* Generic information about quotafile */
55struct 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
63struct 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 */
70struct 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'od6120a22011-10-04 11:46:21 -040075 unsigned int (*e2fs_read)(struct quota_file *qf, ext2_loff_t offset,
Aditya Kalif239fef2011-07-20 11:40:02 -070076 void *buf, unsigned int size);
Theodore Ts'od6120a22011-10-04 11:46:21 -040077 unsigned int (*e2fs_write)(struct quota_file *qf, ext2_loff_t offset,
Aditya Kalif239fef2011-07-20 11:40:02 -070078 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 Kalif239fef2011-07-20 11:40:02 -070083/* Utility quota block */
84struct 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 */
99struct 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 Kalif239fef2011-07-20 11:40:02 -0700107/* Structure of quotafile operations */
108struct 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'ob5ba6f52011-10-05 13:26:59 -0400122 int (*commit_dquot) (struct dquot *dquot);
Aditya Kalif239fef2011-07-20 11:40:02 -0700123 /* Scan quotafile and call callback on every structure */
124 int (*scan_dquots) (struct quota_handle *h,
125 int (*process_dquot) (struct dquot *dquot,
Niu198d20f2011-11-14 10:58:28 -0500126 void *data),
127 void *data);
Aditya Kalif239fef2011-07-20 11:40:02 -0700128 /* 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... */
133extern struct quotafile_ops quotafile_ops_meta;
134
Aditya Kalia86d55d2011-11-14 10:55:54 -0500135/* Open existing quotafile of given type (and verify its format) on given
136 * filesystem. */
137errcode_t quota_file_open(struct quota_handle *h, ext2_filsys fs,
Niu198d20f2011-11-14 10:58:28 -0500138 ext2_ino_t qf_ino, int type, int fmt, int flags);
139
Aditya Kalif239fef2011-07-20 11:40:02 -0700140
141/* Create new quotafile of specified format on given filesystem */
Aditya Kalia86d55d2011-11-14 10:55:54 -0500142errcode_t quota_file_create(struct quota_handle *h, ext2_filsys fs,
143 int type, int fmt);
Aditya Kalif239fef2011-07-20 11:40:02 -0700144
145/* Close quotafile */
Aditya Kalia86d55d2011-11-14 10:55:54 -0500146errcode_t quota_file_close(struct quota_handle *h);
Aditya Kalif239fef2011-07-20 11:40:02 -0700147
148/* Get empty quota structure */
149struct dquot *get_empty_dquot(void);
150
Aditya Kalia86d55d2011-11-14 10:55:54 -0500151errcode_t quota_inode_truncate(ext2_filsys fs, ext2_ino_t ino);
Aditya Kalif239fef2011-07-20 11:40:02 -0700152
153const char *type2name(int type);
154
Theodore Ts'oedbfd752011-10-04 11:20:50 -0400155void update_grace_times(struct dquot *q);
156
Theodore Ts'o2f7d8552011-11-27 20:31:36 -0500157/* 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
161const char *quota_get_qf_name(int type, int fmt, char *buf);
162const char *quota_get_qf_path(const char *mntpt, int qtype, int fmt,
163 char *path_buf, size_t path_buf_size);
164
Aditya Kalif239fef2011-07-20 11:40:02 -0700165#endif /* GUARD_QUOTAIO_H */