summaryrefslogtreecommitdiff
path: root/quotasys.h
blob: 841251ec14cad42a55581b50bb08c4eece320bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
 *
 *	Headerfile of quota interactions with system - filenames, fstab...
 *
 */

#ifndef GUARD_QUOTASYS_H
#define GUARD_QUOTASYS_H

#include <sys/types.h>
#include <inttypes.h>
#include "mntopt.h"
#include "quota.h"
#include "common.h"

#define MAXNAMELEN 64		/* Maximal length of user/group name */
#define MAXTIMELEN 40		/* Maximal length of time string */
#define MAXNUMLEN 32		/* Maximal length of number */

/* Flags for formatting time */
#define TF_ROUND 0x1		/* Should be printed time rounded? */

/* Flags for IO initialization */
#define IOI_READONLY	0x1	/* Only readonly access */
#define IOI_INITSCAN	0x2	/* Prepare handle for scanning dquots */
#define IOI_NFS_MIXED_PATHS	0x4	/* Trim leading / from NFSv4 mountpoints */

/* Interface versions */
#define IFACE_VFSOLD 1
#define IFACE_VFSV0 2
#define IFACE_GENERIC 3

/* Path to export table of NFS daemon */
#define NFSD_XTAB_PATH "/var/lib/nfs/etab"

/* Supported kernel interface */
extern int kernel_iface;

struct mount_entry {
	char *me_type;		/* Type of filesystem for given entry */
	char *me_opts;		/* Options of filesystem */
	dev_t me_dev;		/* Device filesystem is mounted on */
	ino_t me_ino;		/* Inode number of root of filesystem */
	const char *me_devname;	/* Name of device (after pass through get_device_name()) */
	const char *me__dir;	/* One mountpoint of a filesystem (strdup()ed) */
	const char *me_dir;	/* Current mountpoint of a filesystem to process */
	int me_qfmt[MAXQUOTAS];	/* Detected quota formats */
};

struct fs_project {
	qid_t pr_id;
	char *pr_name;
};

/*
 *	Exported functions
 */
/* Check whether type is one of the NFS filesystems */
int nfs_fstype(char *);
/* Quota file is treated as metadata? */
int meta_qf_fstype(char *type);

/* Convert quota type to written form */
char *type2name(int);

/* Rewind /etc/projid to the beginning */
void setprent(void);

/* Close /etc/projid file */
void endprent(void);

/* Get next entry in /etc/projid */
struct fs_project *getprent(void);

/* Convert username to uid */
uid_t user2uid(char *, int flag, int *err);

/* Convert groupname to gid */
gid_t group2gid(char *, int flag, int *err);

/* Convert project name to project id */
qid_t project2pid(char *name, int flag, int *err);

/* Convert user/groupname to id */
int name2id(char *name, int qtype, int flag, int *err);

/* Convert uid to username */
int uid2user(uid_t, char *);

/* Convert gid to groupname */
int gid2group(gid_t, char *);

/* Convert project id to name */
int pid2project(qid_t, char *);

/* Convert id to user/group name */
int id2name(int id, int qtype, char *buf);

/* Possible default passwd handling */
#define PASSWD_FILES 0
#define PASSWD_DB 1
/* Parse /etc/nsswitch.conf and return type of default passwd handling */
int passwd_handling(void);

/* Convert quota format name to number */
int name2fmt(char *str);

/* Convert quota format number to name */
char *fmt2name(int fmt);

/* Convert output format name to number */
int name2ofmt(char *str);

/* Convert output format number to name */
char *ofmt2name(int fmt);

/* Convert utility to kernel format numbers */
int util2kernfmt(int fmt);

/* Convert time difference between given time and current time to printable form */
void difftime2str(time_t, char *);

/* Round difference of two time_t values into int32_t */
int32_t difftime2net(time_t later, time_t sooner);

/* Convert time to printable form */
void time2str(time_t, char *, int);

/* Convert number and units to time in seconds */
int str2timeunits(time_t, char *, time_t *);

/* Convert number in quota blocks to short printable form */
void space2str(qsize_t, char *, enum s2s_unit);

/* Convert block number with unit from string to quota blocks */
const char *str2space(const char *string, qsize_t *space);

/* Convert number to short printable form */
void number2str(long long, char *, enum s2s_unit);

/* Convert inode number with unit from string to quota inodes. */
const char *str2number(const char *string, qsize_t *inodes);

/* Return pointer to given mount option in mount option string */
char *str_hasmntopt(const char *optstring, const char *opt);

/* Check to see if particular quota type is configured */
static inline int me_hasquota(struct mount_entry *mnt, int type)
{
	return mnt->me_qfmt[type] >= 0;
}

/* Flags for get_qf_name() */
#define NF_EXIST  1	/* Check whether file exists */
#define NF_FORMAT 2	/* Check whether file is in proper format */
/* Get quotafile name for given entry */
int get_qf_name(struct mount_entry *mnt, int type, int fmt, int flags, char **filename);

/* Detect newest quota format with existing file */
int detect_quota_files(struct mount_entry *mnt, int type, int fmt);

/* Create NULL-terminated list of handles for quotafiles for given mountpoints */
struct quota_handle **create_handle_list(int count, char **mntpoints, int type, int fmt,
					 int ioflags, int mntflags);
/* Dispose given list of handles */
int dispose_handle_list(struct quota_handle **hlist);

/* Check whether given device name matches quota handle device */
int devcmp_handle(const char *dev, struct quota_handle *h);

/* Check whether two quota handles have same device */
int devcmp_handles(struct quota_handle *a, struct quota_handle *b);

/* Check kernel supported quotafile format */
void init_kernel_interface(void);

/*
 * Check whether is quota turned on on given device for given type. This
 * works for XFS for all kernels and for other filesystems since kernel 4.1.
 */
int kern_quota_state_xfs(const char *dev, int type);

/* Check whether is quota turned on on given device for given type */
int kern_quota_on(struct mount_entry *mnt, int type, int fmt);

/* Return whether kernel is able to handle given format */
int kern_qfmt_supp(int fmt);

/* Flags for init_mounts_scan() */
#define MS_NO_MNTPOINT 0x01	/* Specified directory needn't be mountpoint */
#define MS_NO_AUTOFS 0x02	/* Ignore autofs mountpoints */
#define MS_QUIET 0x04		/* Be quiet with error reporting */
#define MS_LOCALONLY 0x08	/* Ignore nfs mountpoints */
#define MS_XFS_DISABLED 0x10	/* Return also XFS mountpoints with quota disabled */
#define MS_NFS_ALL 0x20		/* Don't filter NFS mountpoints on the same device */

/* Initialize mountpoints scan */
int init_mounts_scan(int dcnt, char **dirs, int flags);

/* Return next mountpoint for scan */
struct mount_entry *get_next_mount(void);

/* Free all structures associated with mountpoints scan */
void end_mounts_scan(void);

/* Parse kernel version and return 1 if ext4 supports quota feature */
int ext4_supports_quota_feature(void);

/* Quota output formats */
#define QOF_ERROR	-1
#define QOF_DEFAULT	0
#define QOF_CSV		1
#define QOF_XML		2

#endif /* GUARD_QUOTASYS_H */