summaryrefslogtreecommitdiff
path: root/sysutils/ruby-quota/patches/patch-ab
blob: e7ff1c51f79de6fbf0ba8d37b00495a69478fa98 (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
216
217
218
219
$NetBSD: patch-ab,v 1.9 2010/09/10 07:58:45 taca Exp $

--- quota.c.orig	2002-03-30 14:59:12.000000000 +0000
+++ quota.c
@@ -5,9 +5,13 @@
 
 #include "ruby.h"
 
-#define RUBY_QUOTA_VERSION "0.4.1"
+#define RUBY_QUOTA_VERSION "0.5.1"
 
-#ifdef HAVE_LINUX_QUOTA_H       /* for linux-2.4.x */
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_LINUX_QUOTA_H       /* for linux */
 # define USE_LINUX_QUOTA
 #endif
 #ifdef HAVE_SYS_FS_UFS_QUOTA_H  /* for Solaris-2.6,7,8 */
@@ -29,10 +33,16 @@
 #  include <sys/quota.h>
 #endif
 #include <linux/version.h>
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
+#  define USE_LINUX_QUOTA_26
+#  define qid_t uid_t
+#  define dqblk if_dqblk
+#else
+# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
 #  define USE_LINUX_QUOTA_24
 #  define uid_t qid_t
 #  define dqblk disk_dqblk
+# endif
 #endif
 #endif
 
@@ -51,6 +61,12 @@
 #if defined(SYS_UCRED_H)
 # include <sys/ucred.h>  /* required by NetBSD,FreeBSD */
 #endif
+#if defined(__DragonFly__)
+#  include <sys/param.h>
+#  if __DragonFly_version >= 160000
+#    define dqblk ufs_dqblk
+#  endif
+#endif
 #endif
 
 static VALUE rb_mQuota;
@@ -144,7 +160,6 @@ rb_quotactl(int cmd, char *dev, VALUE vu
   uid_t uid;
 
   get_uid(vuid, &uid, &is_gid);
-  printf("cmd = %d, dev = %s, uid = %d, gid? = %d\n", cmd, dev, uid, is_gid);
   if( is_gid ){
     return quotactl(QCMD(cmd,GRPQUOTA),dev,(qid_t)uid,addr);
   }
@@ -159,7 +174,11 @@ rb_quotactl(int cmd, char *dev, VALUE vu
   char *path;
   int is_gid;
   uid_t uid;
+#if defined(HAVE_SYS_STATVFS_H) && !defined(__DragonFly__)
+  struct statvfs *buff;
+#else
   struct statfs *buff;
+#endif
   int i, count, ret;
   
   buff = 0;
@@ -187,12 +206,16 @@ rb_quotactl(int cmd, char *dev, VALUE vu
 static int
 rb_quotactl(int cmd, char *dev, VALUE vuid, caddr_t addr)
 {
-  struct quotctl qctl = {cmd, uid, addr};
+  struct quotctl qctl;
   int fd;
   uid_t uid;
 
   get_uid(vuid, &uid, 0);
 
+  qctl.op = cmd;
+  qctl.uid = uid;
+  qctl.addr = addr;
+
   switch( cmd ){
   case Q_QUOTAON:
   case Q_QUOTAOFF:
@@ -230,12 +253,20 @@ rb_diskquota_get(VALUE dqb, struct dqblk
 {
   VALUE v;
 
+#if defined(USE_LINUX_QUOTA) && \
+	(defined(USE_LINUX_QUOTA_24) || defined(USE_LINUX_QUOTA_26))
+#define GetMember(mem) \
+        ((v = rb_struct_getmember(dqb,rb_intern(mem))) == Qnil) ? 0 : (NUM2ULL(v))
+#else
 #define GetMember(mem) \
         ((v = rb_struct_getmember(dqb,rb_intern(mem))) == Qnil) ? 0 : (NUM2UINT(v))
+#endif
 #if defined(USE_LINUX_QUOTA)
   c_dqb->dqb_bhardlimit = GetMember("bhardlimit");
   c_dqb->dqb_bsoftlimit = GetMember("bsoftlimit");
-#if !defined(USE_LINUX_QUOTA_24)
+#if defined(USE_LINUX_QUOTA_24) || defined(USE_LINUX_QUOTA_26)
+  c_dqb->dqb_curspace  = GetMember("curspace");
+#else
   c_dqb->dqb_curblocks  = GetMember("curblocks");
 #endif
   c_dqb->dqb_ihardlimit = GetMember("ihardlimit");
@@ -271,20 +302,29 @@ rb_diskquota_new(struct dqblk *c_dqb)
   VALUE dqb;
 
 #if defined(USE_LINUX_QUOTA)
+#if defined(USE_LINUX_QUOTA_24) || defined(USE_LINUX_QUOTA_26)
+  dqb = rb_struct_new(rb_sDiskQuota,
+		      ULL2NUM(c_dqb->dqb_bhardlimit),
+		      ULL2NUM(c_dqb->dqb_bsoftlimit),
+		      ULL2NUM(c_dqb->dqb_curspace),
+		      ULL2NUM(c_dqb->dqb_ihardlimit),
+		      ULL2NUM(c_dqb->dqb_isoftlimit),
+		      ULL2NUM(c_dqb->dqb_curinodes),
+		      ULL2NUM(c_dqb->dqb_btime),
+		      ULL2NUM(c_dqb->dqb_itime),
+		      0);
+#else
   dqb = rb_struct_new(rb_sDiskQuota,
 		      UINT2NUM(c_dqb->dqb_bhardlimit),
 		      UINT2NUM(c_dqb->dqb_bsoftlimit),
-#if defined(USE_LINUX_QUOTA_24)
-		      UINT2NUM(c_dqb->dqb_curspace),
-#else
 		      UINT2NUM(c_dqb->dqb_curblocks),
-#endif
 		      UINT2NUM(c_dqb->dqb_ihardlimit),
 		      UINT2NUM(c_dqb->dqb_isoftlimit),
 		      UINT2NUM(c_dqb->dqb_curinodes),
 		      UINT2NUM(c_dqb->dqb_btime),
 		      UINT2NUM(c_dqb->dqb_itime),
 		      0);
+#endif
 #elif defined(USE_BSD_QUOTA)
   dqb = rb_struct_new(rb_sDiskQuota,
 		      UINT2NUM(c_dqb->dqb_bhardlimit),
@@ -314,7 +354,7 @@ rb_diskquota_new(struct dqblk *c_dqb)
 static VALUE
 rb_quota_getquota(VALUE self, VALUE dev, VALUE uid)
 {
-  char *c_dev = STR2CSTR(dev);
+  char *c_dev = StringValuePtr(dev);
   struct dqblk c_dqb;
   VALUE dqb = Qnil;
 
@@ -330,7 +370,7 @@ rb_quota_getquota(VALUE self, VALUE dev,
 VALUE
 rb_quota_quotaoff(VALUE self, VALUE dev)
 {
-  char *c_dev = STR2CSTR(dev);
+  char *c_dev = StringValuePtr(dev);
 
   if( rb_quotactl(Q_QUOTAOFF,c_dev,Qnil,NULL) == -1 ){
     rb_sys_fail("quotactl");
@@ -342,8 +382,8 @@ rb_quota_quotaoff(VALUE self, VALUE dev)
 VALUE
 rb_quota_quotaon(VALUE self, VALUE dev, VALUE quotas)
 {
-  char *c_dev = STR2CSTR(dev);
-  char *c_quotas = STR2CSTR(quotas);
+  char *c_dev = StringValuePtr(dev);
+  char *c_quotas = StringValuePtr(quotas);
 
   if( rb_quotactl(Q_QUOTAON,c_dev,Qnil,(caddr_t)c_quotas) == -1 ){
     rb_sys_fail("quotactl");
@@ -355,7 +395,7 @@ rb_quota_quotaon(VALUE self, VALUE dev, 
 VALUE
 rb_quota_setquota(VALUE self, VALUE dev, VALUE uid, VALUE dqb)
 {
-  char *c_dev = STR2CSTR(dev);
+  char *c_dev = StringValuePtr(dev);
   struct dqblk c_dqb;
 
   rb_diskquota_get(dqb, &c_dqb);
@@ -371,7 +411,7 @@ VALUE
 rb_quota_setqlim(VALUE self, VALUE dev, VALUE uid, VALUE dqb)
 {
 #ifdef Q_SETQLIM
-  char *c_dev = STR2CSTR(dev);
+  char *c_dev = StringValuePtr(dev);
   struct dqblk c_dqb;
 
   rb_diskquota_get(dqb, &c_dqb);
@@ -398,7 +438,7 @@ rb_quota_sync(VALUE self, VALUE dev)
     c_dev = NULL;
   }
   else{
-    c_dev = STR2CSTR(dev);
+    c_dev = StringValuePtr(dev);
   };
 
   if( rb_quotactl(Q_SYNC,c_dev,Qnil,NULL) == -1 ){ /* uid and addr are ignored */
@@ -442,7 +482,7 @@ Init_quota()
 				   "curinodes",
 				   "btimelimit",
 				   "itimelimit",
-				   0);
+				   NULL);
 
   /* for compatibility */
 #define DQ_ALIAS(a,b) rb_alias(rb_sDiskQuota,rb_intern(#a),rb_intern(#b))
@@ -454,7 +494,7 @@ Init_quota()
   DQ_ALIAS(fsoftlimit=, isoftlimit=);
   DQ_ALIAS(curfiles=,   curinodes=);
   DQ_ALIAS(ftimelimit=, itimelimit=);
-#if defined(USE_LINUX_QUOTA_24)
+#if defined(USE_LINUX_QUOTA_24) || defined(USE_LINUX_QUOTA_26)
   DQ_ALIAS(curspace, curblocks);
   DQ_ALIAS(curspace=, curblocks=);
 #endif