softlink
[sysadmin-cn.git] / quotasys.h
1 /*
2  *
3  *      Headerfile of quota interactions with system - filenames, fstab...
4  *
5  */
6
7 #ifndef _QUOTASYS_H
8 #define _QUOTASYS_H
9
10 #include <sys/types.h>
11 #include <mntopt.h>
12 #include "quota.h"
13
14 #define MAXNAMELEN 64           /* Maximal length of user/group name */
15 #define MAXTIMELEN 40           /* Maximal length of time string */
16 #define MAXNUMLEN 32            /* Maximal length of number */
17 #define MAXMNTPOINTS 256        /* Maximal number of mountpoints with quota */
18
19 /* Flags for formatting time */
20 #define TF_ROUND 0x1            /* Should be printed time rounded? */
21
22 /* Flags for IO initialization */
23 #define IOI_LOCALONLY   0x1     /* Operate only on local quota */
24 #define IOI_READONLY    0x2     /* Only readonly access */
25 #define IOI_OPENFILE    0x4     /* Open file even if kernel has quotas turned on */
26
27 #define KERN_KNOWN_QUOTA_VERSION (6*10000 + 5*100 + 1)
28
29 /* Interface versions */
30 #define IFACE_VFSOLD 1
31 #define IFACE_VFSV0 2
32 #define IFACE_GENERIC 3
33
34 /* Kernel quota format and supported interface */
35 extern int kernel_formats, kernel_iface;
36
37 /*
38  *      Exported functions
39  */
40 /* Convert quota type to written form */
41 char *type2name(int);
42
43 /* Convert username to uid */
44 uid_t user2uid(char *);
45
46 /* Convert groupname to gid */
47 gid_t group2gid(char *);
48
49 /* Convert user/groupname to id */
50 int name2id(char *name, int qtype);
51
52 /* Convert uid to username */
53 int uid2user(uid_t, char *);
54
55 /* Convert gid to groupname */
56 int gid2group(gid_t, char *);
57
58 /* Convert id to user/group name */
59 int id2name(int id, int qtype, char *buf);
60
61 /* Possible default passwd handling */
62 #define PASSWD_FILES 0
63 #define PASSWD_DB 1
64 /* Parse /etc/nsswitch.conf and return type of default passwd handling */
65 int passwd_handling(void);
66
67 /* Convert quota format name to number */
68 int name2fmt(char *str);
69
70 /* Convert quota format number to name */
71 char *fmt2name(int fmt);
72
73 /* Convert kernel to utility format numbers */
74 int kern2utilfmt(int fmt);
75
76 /* Convert utility to kernel format numbers */
77 int util2kernfmt(int fmt);
78
79 /* Convert time difference between given time and current time to printable form */
80 void difftime2str(time_t, char *);
81
82 /* Convert time to printable form */
83 void time2str(time_t, char *, int);
84
85 /* Convert number and units to time in seconds */
86 int str2timeunits(time_t, char *, time_t *);
87
88 /* Convert number in quota blocks to short printable form */
89 void space2str(qsize_t, char *, int);
90
91 /* Convert number to short printable form */
92 void number2str(unsigned long long, char *, int);
93
94 /* Check to see if particular quota is to be enabled */
95 int hasquota(struct mntent *mnt, int type);
96
97 /* Flags for get_qf_name() */
98 #define NF_EXIST  1     /* Check whether file exists */
99 #define NF_FORMAT 2     /* Check whether file is in proper format */
100 /* Get quotafile name for given entry */
101 int get_qf_name(struct mntent *mnt, int type, int fmt, int flags, char **filename);
102
103 /* Detect newest quota format with existing file */
104 int detect_quota_files(struct mntent *mnt, int type, int fmt);
105
106 /* Create NULL-terminated list of handles for quotafiles for given mountpoints */
107 struct quota_handle **create_handle_list(int count, char **mntpoints, int type, int fmt,
108                                          int ioflags, int mntflags);
109 /* Dispose given list of handles */
110 int dispose_handle_list(struct quota_handle **hlist);
111
112 /* Check whether given device name matches quota handle device */
113 int devcmp_handle(const char *dev, struct quota_handle *h);
114
115 /* Check whether two quota handles have same device */
116 int devcmp_handles(struct quota_handle *a, struct quota_handle *b);
117
118 /* Check kernel supported quotafile format */
119 void init_kernel_interface(void);
120
121 /* Check whether is quota turned on on given device for given type */
122 int kern_quota_on(const char *dev, int type, int fmt);
123
124 /* Flags for init_mounts_scan() */
125 #define MS_NO_MNTPOINT 0x01     /* Specified directory needn't be mountpoint */
126 #define MS_NO_AUTOFS 0x02       /* Ignore autofs mountpoints */
127 #define MS_QUIET 0x04           /* Be quiet with error reporting */
128 /* Initialize mountpoints scan */
129 int init_mounts_scan(int dcnt, char **dirs, int flags);
130
131 /* Return next mountpoint for scan */
132 struct mntent *get_next_mount(void);
133
134 /* Free all structures associated with mountpoints scan */
135 void end_mounts_scan(void);
136
137 #endif /* _QUOTASYS_H */