Initial commit to Gerrit
[profile/ivi/quota.git] / quotasys.h
1 /*
2  *
3  *      Headerfile of quota interactions with system - filenames, fstab...
4  *
5  */
6
7 #ifndef GUARD_QUOTASYS_H
8 #define GUARD_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
18 /* Flags for formatting time */
19 #define TF_ROUND 0x1            /* Should be printed time rounded? */
20
21 /* Flags for IO initialization */
22 #define IOI_READONLY    0x1     /* Only readonly access */
23 #define IOI_OPENFILE    0x2     /* Open file even if kernel has quotas turned on */
24 #define IOI_NFS_MIXED_PATHS     0x4     /* Trim leading / from NFSv4 mountpoints */
25
26 #define KERN_KNOWN_QUOTA_VERSION (6*10000 + 5*100 + 1)
27
28 /* Interface versions */
29 #define IFACE_VFSOLD 1
30 #define IFACE_VFSV0 2
31 #define IFACE_GENERIC 3
32
33 /* Path to export table of NFS daemon */
34 #define NFSD_XTAB_PATH "/var/lib/nfs/etab"
35
36 /* Supported kernel interface */
37 extern int kernel_iface;
38
39 /*
40  *      Exported functions
41  */
42 /* Check whether type is one of the NFS filesystems */
43 int nfs_fstype(char *);
44 /* Quota file is treated as metadata? */
45 int meta_qf_fstype(char *type);
46
47 /* Convert quota type to written form */
48 char *type2name(int);
49
50 /* Convert username to uid */
51 uid_t user2uid(char *, int flag, int *err);
52
53 /* Convert groupname to gid */
54 gid_t group2gid(char *, int flag, int *err);
55
56 /* Convert user/groupname to id */
57 int name2id(char *name, int qtype, int flag, int *err);
58
59 /* Convert uid to username */
60 int uid2user(uid_t, char *);
61
62 /* Convert gid to groupname */
63 int gid2group(gid_t, char *);
64
65 /* Convert id to user/group name */
66 int id2name(int id, int qtype, char *buf);
67
68 /* Possible default passwd handling */
69 #define PASSWD_FILES 0
70 #define PASSWD_DB 1
71 /* Parse /etc/nsswitch.conf and return type of default passwd handling */
72 int passwd_handling(void);
73
74 /* Convert quota format name to number */
75 int name2fmt(char *str);
76
77 /* Convert quota format number to name */
78 char *fmt2name(int fmt);
79
80 /* Convert utility to kernel format numbers */
81 int util2kernfmt(int fmt);
82
83 /* Convert time difference between given time and current time to printable form */
84 void difftime2str(time_t, char *);
85
86 /* Convert time to printable form */
87 void time2str(time_t, char *, int);
88
89 /* Convert number and units to time in seconds */
90 int str2timeunits(time_t, char *, time_t *);
91
92 /* Convert number in quota blocks to short printable form */
93 void space2str(qsize_t, char *, int);
94
95 /* Convert number to short printable form */
96 void number2str(unsigned long long, char *, int);
97
98 /* Check to see if particular quota is to be enabled */
99 /* Recognizes MS_XFS_DISABLED flag */
100 int hasquota(struct mntent *mnt, int type, int flags);
101
102 /* Flags for get_qf_name() */
103 #define NF_EXIST  1     /* Check whether file exists */
104 #define NF_FORMAT 2     /* Check whether file is in proper format */
105 /* Get quotafile name for given entry */
106 int get_qf_name(struct mntent *mnt, int type, int fmt, int flags, char **filename);
107
108 /* Detect newest quota format with existing file */
109 int detect_quota_files(struct mntent *mnt, int type, int fmt);
110
111 /* Create NULL-terminated list of handles for quotafiles for given mountpoints */
112 struct quota_handle **create_handle_list(int count, char **mntpoints, int type, int fmt,
113                                          int ioflags, int mntflags);
114 /* Dispose given list of handles */
115 int dispose_handle_list(struct quota_handle **hlist);
116
117 /* Check whether given device name matches quota handle device */
118 int devcmp_handle(const char *dev, struct quota_handle *h);
119
120 /* Check whether two quota handles have same device */
121 int devcmp_handles(struct quota_handle *a, struct quota_handle *b);
122
123 /* Check kernel supported quotafile format */
124 void init_kernel_interface(void);
125
126 /* Check whether is quota turned on on given device for given type */
127 int kern_quota_on(const char *dev, int type, int fmt);
128
129 /* Return whether kernel is able to handle given format */
130 int kern_qfmt_supp(int fmt);
131
132 /* Flags for init_mounts_scan() */
133 #define MS_NO_MNTPOINT 0x01     /* Specified directory needn't be mountpoint */
134 #define MS_NO_AUTOFS 0x02       /* Ignore autofs mountpoints */
135 #define MS_QUIET 0x04           /* Be quiet with error reporting */
136 #define MS_LOCALONLY 0x08       /* Ignore nfs mountpoints */
137 #define MS_XFS_DISABLED 0x10    /* Return also XFS mountpoints with quota disabled */
138 #define MS_NFS_ALL 0x20         /* Don't filter NFS mountpoints on the same device */
139
140 /* Initialize mountpoints scan */
141 int init_mounts_scan(int dcnt, char **dirs, int flags);
142
143 /* Return next mountpoint for scan */
144 struct mntent *get_next_mount(void);
145
146 /* Free all structures associated with mountpoints scan */
147 void end_mounts_scan(void);
148
149 #endif /* GUARD_QUOTASYS_H */