]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/unix.h
Add support for new NetBSD quota subsystem, Bug ID 3249879.
[netatalk.git] / etc / afpd / unix.h
1 /*
2  * $Id: unix.h,v 1.23 2010-04-12 14:28:47 franklahm Exp $
3  */
4
5 #ifndef AFPD_UNIX_H
6 #define AFPD_UNIX_H
7
8 #ifdef HAVE_SYS_CDEFS_H
9 #include <sys/cdefs.h>
10 #endif /* HAVE_SYS_CDEFS_H */
11 #include <netatalk/endian.h>
12 #include "config.h"
13 #include "volume.h"
14
15 #if defined( sun ) && !defined( __svr4__ )
16 #ifdef i386
17 typedef int     mode_t;
18 #endif /*i386*/
19 #endif /*sun __svr4__*/
20
21 #if defined(HAVE_SYS_VFS_H) || defined( sun ) || defined( ibm032 ) 
22 #include <sys/vfs.h>
23 #endif /* HAVE_SYS_VFS_H || sun || ibm032 */
24
25 #if defined(_IBMR2) || defined(HAVE_STATFS_H) 
26 #include <sys/statfs.h>
27 /* this might not be right. */
28 #define f_mntfromname f_fname
29 #endif /* _IBMR2 || HAVE_STATFS_H */
30
31 #if defined(TRU64)
32 #define f_frsize f_fsize
33 #else /* TRU64 */
34 /* temp fix, was: defined(HAVE_SYS_STATVFS) || defined(__svr4__) */
35 #if defined(__svr4__) || (defined(__NetBSD__) && (__NetBSD_Version__ >= 200040000))
36 #include <sys/statvfs.h>
37 #define statfs statvfs
38 #else /* HAVE_SYS_STATVFS || __svr4__ */
39 #define f_frsize f_bsize
40 #endif /* USE_STATVFS_H */
41 #endif /* TRU64 */
42
43 #if defined(__svr4__) || defined(HAVE_SYS_MNTTAB_H)
44 #include <sys/mnttab.h>
45 #endif /* __svr4__ || HAVE_SYS_MNTTAB_H */
46
47 #if defined(__DragonFly__)
48 #define dqblk ufs_dqblk
49 #endif
50
51 #if defined(HAVE_SYS_MOUNT_H) || defined(BSD4_4) || \
52     defined(linux) || defined(ultrix)
53 #include <sys/mount.h>
54 #endif /* HAVE_SYS_MOUNT_H || BSD4_4 || linux || ultrix */
55
56 #if defined(linux) || defined(HAVE_MNTENT_H)
57 #include <mntent.h>
58 #endif /* linux || HAVE_MNTENT_H */
59
60
61 #ifndef NO_QUOTA_SUPPORT
62 #if !defined(HAVE_LIBQUOTA)
63
64 #if !(defined(__svr4__) || defined(HAVE_DQB_BTIMELIMIT))
65 #define dqb_btimelimit  dqb_btime
66 #endif /* ! __svr4__ || HAVE_DQB_BTIMELIMIT */
67
68 #if defined(linux) || defined(ultrix) || defined(HAVE_QUOTA_H)
69 #ifndef NEED_QUOTACTL_WRAPPER
70 /*#include <sys/quota.h>*/
71 /*long quotactl (int, const char *, unsigned int, caddr_t); */
72 /* extern long quotactl (int, const char *, long, caddr_t); */
73
74 #else /* ! NEED_QUOTACTL_WRAPPER */
75 #include <asm/types.h>
76 #include <asm/unistd.h>
77 #include <linux/quota.h>
78 #endif /* ! NEED_QUOTACTL_WRAPPER */
79 #endif /* linux || ultrix || HAVE_QUOTA_H */
80
81 #ifdef __svr4__ 
82 #include <sys/fs/ufs_quota.h>
83 #endif /* __svr4__ */
84
85 #ifdef BSD4_4
86 #include <ufs/ufs/quota.h>
87 #endif /* BSD4_4 */
88
89 #ifdef HAVE_UFS_QUOTA_H
90 #include <ufs/quota.h>
91 #endif /* HAVE_UFS_QUOTA_H */
92
93 #ifdef _IBMR2
94 #include <jfs/quota.h>
95 #endif /* _IBMR2 */
96
97 #include <unistd.h>
98 #include <sys/types.h>
99 #include <sys/stat.h>
100 #include "directory.h"
101
102
103 #if defined (linux)
104
105 #define MAXQUOTAS 2
106
107 /* definitions from sys/quota.h */
108 #define USRQUOTA  0             /* element used for user quotas */
109 #define GRPQUOTA  1             /* element used for group quotas */
110
111 /*
112  * Command definitions for the 'quotactl' system call.
113  * The commands are broken into a main command defined below
114  * and a subcommand that is used to convey the type of
115  * quota that is being manipulated (see above).
116  */
117 #define SUBCMDMASK  0x00ff
118 #define SUBCMDSHIFT 8
119 #define QCMD(cmd, type)  (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))
120
121 /* declare an internal version of the quota block struct */
122 typedef u_int64_t qsize_t;      /* Type in which we store size limitations */
123 typedef u_int32_t qid_t;        /* Type in which we store ids in memory */
124
125 struct dqblk {
126   qsize_t bsize;
127   qsize_t dqb_ihardlimit;   /* absolute limit on allocated inodes */
128   qsize_t dqb_isoftlimit;   /* preferred inode limit */
129   qsize_t dqb_curinodes;    /* current # allocated inodes */
130   qsize_t dqb_bhardlimit;   /* absolute limit on disk blks alloc */
131   qsize_t dqb_bsoftlimit;   /* preferred limit on disk blks */
132   qsize_t dqb_curblocks;    /* current block count */
133   time_t  dqb_btime;        /* time limit for excessive disk use */
134   time_t  dqb_itime;        /* time limit for excessive inode use */
135 };
136
137 /* API v1 command definitions */
138 #define Q_V1_GETQUOTA  0x0300
139 #define Q_V1_SYNC      0x0600
140 #define Q_V1_SETQLIM   0x0700
141 #define Q_V1_GETSTATS  0x0800
142 /* API v2 command definitions */
143 #define Q_V2_SYNC      0x0600
144 #define Q_V2_SETQLIM   0x0700
145 #define Q_V2_GETQUOTA  0x0D00
146 #define Q_V2_GETSTATS  0x1100
147 /* proc API command definitions */
148 #define Q_V3_SYNC      0x800001
149 #define Q_V3_GETQUOTA  0x800007
150 #define Q_V3_SETQUOTA  0x800008
151
152 /* Interface versions */
153 #define IFACE_UNSET 0
154 #define IFACE_VFSOLD 1
155 #define IFACE_VFSV0 2
156 #define IFACE_GENERIC 3
157
158 #define DEV_QBSIZE 1024
159
160 struct dqblk_v3 {
161   u_int64_t dqb_bhardlimit;
162   u_int64_t dqb_bsoftlimit;
163   u_int64_t dqb_curspace;
164   u_int64_t dqb_ihardlimit;
165   u_int64_t dqb_isoftlimit;
166   u_int64_t dqb_curinodes;
167   u_int64_t dqb_btime;
168   u_int64_t dqb_itime;
169   u_int32_t dqb_valid;
170 };
171
172 struct dqblk_v2 {
173   unsigned int dqb_ihardlimit;
174   unsigned int dqb_isoftlimit;
175   unsigned int dqb_curinodes;
176   unsigned int dqb_bhardlimit;
177   unsigned int dqb_bsoftlimit;
178   qsize_t dqb_curspace;
179   time_t dqb_btime;
180   time_t dqb_itime;
181 };
182
183 struct dqstats_v2 {
184   u_int32_t lookups;
185   u_int32_t drops;
186   u_int32_t reads;
187   u_int32_t writes;
188   u_int32_t cache_hits;
189   u_int32_t allocated_dquots;
190   u_int32_t free_dquots;
191   u_int32_t syncs;
192   u_int32_t version;
193 };
194
195 struct dqblk_v1 {
196   u_int32_t dqb_bhardlimit;
197   u_int32_t dqb_bsoftlimit;
198   u_int32_t dqb_curblocks;
199   u_int32_t dqb_ihardlimit;
200   u_int32_t dqb_isoftlimit;
201   u_int32_t dqb_curinodes;
202   time_t dqb_btime;
203   time_t dqb_itime;
204 };
205
206 extern long quotactl (unsigned int, const char *, int, caddr_t);
207
208
209
210 #endif /* linux */
211
212 extern int getnfsquota (struct vol *, const int, const u_int32_t,
213                                 struct dqblk *);
214
215 #endif /* ! HAVE_LIBQUOTA */
216 extern int uquota_getvolspace (struct vol *, VolSpace *, VolSpace *,
217                                        const u_int32_t);
218 #endif /* NO_QUOTA_SUPPORT */
219
220 extern struct afp_options default_options;
221
222 extern int gmem            (const gid_t);
223 extern int setdeskmode      (const mode_t);
224 extern int setdirunixmode   (const struct vol *, const char *, mode_t);
225 extern int setdirmode       (const struct vol *, const char *, mode_t);
226 extern int setdeskowner     (const uid_t, const gid_t);
227 extern int setdirowner      (const struct vol *, const char *, const uid_t, const gid_t);
228 extern int setfilunixmode   (const struct vol *, struct path*, const mode_t);
229 extern int setfilowner      (const struct vol *, const uid_t, const gid_t, struct path*);
230 extern void accessmode      (char *, struct maccess *, struct dir *, struct stat *);
231
232 #ifdef AFS      
233     #define accessmode afsmode
234 #endif 
235
236 #endif /* UNIX_H */