Commit | Line | Data |
---|---|---|
805e021f CE |
1 | /* |
2 | * Copyright (c) 2001-2002 International Business Machines Corp. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This software has been released under the terms of the IBM Public | |
6 | * License. For details, see the LICENSE file in the top-level source | |
7 | * directory or online at http://www.openafs.org/dl/license10.html | |
8 | * | |
9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR | |
13 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
14 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
15 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
16 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
17 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
18 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
19 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
20 | */ | |
21 | ||
22 | #include "Internal.h" | |
23 | #include "org_openafs_jafs_Partition.h" | |
24 | ||
25 | #include <afs_vosAdmin.h> | |
26 | #include <afs_AdminCommonErrors.h> | |
27 | ||
28 | //// definitions in Internal.c ////////////////// | |
29 | ||
30 | extern jclass partitionCls; | |
31 | extern jfieldID partition_nameField; | |
32 | extern jfieldID partition_idField; | |
33 | extern jfieldID partition_deviceNameField; | |
34 | extern jfieldID partition_lockFileDescriptorField; | |
35 | extern jfieldID partition_totalSpaceField; | |
36 | extern jfieldID partition_totalFreeSpaceField; | |
37 | ||
38 | extern jclass volumeCls; | |
39 | extern jfieldID volume_cachedInfoField; | |
40 | ||
41 | ////////////////////////////////////////////////////////// | |
42 | ||
43 | ///// definition in jafs_Volume.c ///////////////// | |
44 | ||
45 | extern void fillVolumeInfo | |
46 | ( JNIEnv *env, jobject volume, vos_volumeEntry_t volEntry ); | |
47 | ||
48 | /////////////////////////////////////////////////// | |
49 | ||
50 | ||
51 | /** | |
52 | * Extract the information from the given partition entry and populate the | |
53 | * given object | |
54 | * | |
55 | * env the Java environment | |
56 | * partition the Partition object to populate with the info | |
57 | * partEntry the container of the partition's information | |
58 | */ | |
59 | void fillPartitionInfo | |
60 | (JNIEnv *env, jobject partition, vos_partitionEntry_t partEntry) | |
61 | { | |
62 | jstring jdeviceName; | |
63 | jstring jpartition; | |
64 | jint id; | |
65 | afs_status_t ast; | |
66 | ||
67 | // get the class fields if need be | |
68 | if( partitionCls == 0 ) { | |
69 | internal_getPartitionClass( env, partition ); | |
70 | } | |
71 | ||
72 | // fill name and id in case it's a blank object | |
73 | jpartition = (*env)->NewStringUTF(env, partEntry.name); | |
74 | // get the id | |
75 | if( !vos_PartitionNameToId( partEntry.name, (int *) &id, &ast ) ) { | |
76 | throwAFSException( env, ast ); | |
77 | return; | |
78 | } | |
79 | (*env)->SetObjectField(env, partition, partition_nameField, jpartition); | |
80 | (*env)->SetIntField(env, partition, partition_idField, id); | |
81 | ||
82 | jdeviceName = (*env)->NewStringUTF(env, partEntry.deviceName); | |
83 | (*env)->SetObjectField(env, partition, partition_deviceNameField, | |
84 | jdeviceName); | |
85 | ||
86 | (*env)->SetIntField(env, partition, partition_lockFileDescriptorField, | |
87 | partEntry.lockFileDescriptor); | |
88 | (*env)->SetIntField(env, partition, partition_totalSpaceField, | |
89 | partEntry.totalSpace); | |
90 | (*env)->SetIntField(env, partition, partition_totalFreeSpaceField, | |
91 | partEntry.totalFreeSpace); | |
92 | ||
93 | } | |
94 | ||
95 | /** | |
96 | * Fills in the information fields of the provided Partition. | |
97 | * | |
98 | * env the Java environment | |
99 | * cls the current Java class | |
100 | * cellHandle the handle of the cell to which the partition belongs | |
101 | * serverHandle the vos handle of the server on which the | |
102 | * partition resides | |
103 | * partition the numeric id of the partition for which to get the | |
104 | * info | |
105 | * jpartitionObject the Partition object in which to | |
106 | * fill in the information | |
107 | */ | |
108 | JNIEXPORT void JNICALL | |
109 | Java_org_openafs_jafs_Partition_getPartitionInfo | |
110 | (JNIEnv *env, jclass cls, jlong cellHandle, jlong serverHandle, | |
111 | jint partition, jobject jpartitionObject) | |
112 | { | |
113 | afs_status_t ast; | |
114 | vos_partitionEntry_t partEntry; | |
115 | ||
116 | // get the partition entry | |
117 | if ( !vos_PartitionGet( (void *) cellHandle, (void *) serverHandle, NULL, | |
118 | (unsigned int) partition, &partEntry, &ast ) ) { | |
119 | throwAFSException( env, ast ); | |
120 | return; | |
121 | } | |
122 | ||
123 | fillPartitionInfo( env, jpartitionObject, partEntry ); | |
124 | ||
125 | } | |
126 | ||
127 | /** | |
128 | * Translates a partition name into a partition id | |
129 | * | |
130 | * env the Java environment | |
131 | * cls the current Java class | |
132 | * jname the name of the partition in question | |
133 | * returns the id of the partition in question | |
134 | */ | |
135 | JNIEXPORT jint JNICALL | |
136 | Java_org_openafs_jafs_Partition_translateNameToID | |
137 | (JNIEnv *env, jclass cls, jstring jname) | |
138 | { | |
139 | afs_status_t ast; | |
140 | jint id; | |
141 | const char *name; | |
142 | ||
143 | if( jname != NULL ) { | |
144 | name = (*env)->GetStringUTFChars(env, jname, 0); | |
145 | if( !name ) { | |
146 | throwAFSException( env, JAFSADMNOMEM ); | |
147 | return; | |
148 | } | |
149 | } else { | |
150 | name = NULL; | |
151 | } | |
152 | ||
153 | // get the id | |
154 | if( !vos_PartitionNameToId( name, (unsigned int *) &id, &ast ) ) { | |
155 | if( name != NULL ) { | |
156 | (*env)->ReleaseStringUTFChars(env, jname, name); | |
157 | } | |
158 | throwAFSException( env, ast ); | |
159 | return -1; | |
160 | } | |
161 | ||
162 | if( name != NULL ) { | |
163 | (*env)->ReleaseStringUTFChars(env, jname, name); | |
164 | } | |
165 | ||
166 | return id; | |
167 | ||
168 | } | |
169 | ||
170 | /** | |
171 | * Translates a partition id into a partition name | |
172 | * | |
173 | * env the Java environment | |
174 | * cls the current Java class | |
175 | * id the id of the partition in question | |
176 | * returns the name of the partition in question | |
177 | */ | |
178 | JNIEXPORT jstring JNICALL | |
179 | Java_org_openafs_jafs_Partition_translateIDToName | |
180 | (JNIEnv *env, jclass cls, jint id) | |
181 | { | |
182 | afs_status_t ast; | |
183 | char *name = malloc( sizeof(char)*VOS_MAX_PARTITION_NAME_LEN); | |
184 | jstring jname; | |
185 | ||
186 | if( !name ) { | |
187 | throwAFSException( env, JAFSADMNOMEM ); | |
188 | return NULL; | |
189 | } | |
190 | ||
191 | // get the name | |
192 | if( !vos_PartitionIdToName( (unsigned int) id, name, &ast ) ) { | |
193 | free(name); | |
194 | throwAFSException( env, ast ); | |
195 | return NULL; | |
196 | } | |
197 | ||
198 | jname = (*env)->NewStringUTF(env, name); | |
199 | free(name); | |
200 | return jname; | |
201 | ||
202 | } | |
203 | ||
204 | /** | |
205 | * Returns the total number of volumes hosted by this partition. | |
206 | * | |
207 | * env the Java environment | |
208 | * cls the current Java class | |
209 | * cellHandle the handle of the cell to which the partition belongs | |
210 | * serverHandle the vos handle of the server to which the partition | |
211 | * belongs | |
212 | * partition the numeric id of the partition on which the volumes | |
213 | * reside | |
214 | * returns total number of volumes hosted by this partition | |
215 | */ | |
216 | JNIEXPORT jint JNICALL | |
217 | Java_org_openafs_jafs_Partition_getVolumeCount | |
218 | (JNIEnv *env, jclass cls, jlong cellHandle, jlong serverHandle, jint partition) | |
219 | { | |
220 | afs_status_t ast; | |
221 | void *iterationId; | |
222 | vos_volumeEntry_t volEntry; | |
223 | int i = 0; | |
224 | ||
225 | if( !vos_VolumeGetBegin( (void *) cellHandle, (void *) serverHandle, NULL, | |
226 | (unsigned int) partition, &iterationId, &ast ) ) { | |
227 | throwAFSException( env, ast ); | |
228 | return -1; | |
229 | } | |
230 | ||
231 | while ( vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) i++; | |
232 | ||
233 | if( ast != ADMITERATORDONE ) { | |
234 | throwAFSException( env, ast ); | |
235 | return -1; | |
236 | } | |
237 | ||
238 | return i; | |
239 | } | |
240 | ||
241 | /** | |
242 | * Begin the process of getting the volumes on a partition. Returns | |
243 | * an iteration ID to be used by subsequent calls to | |
244 | * getVolumesNext and getVolumesDone. | |
245 | * | |
246 | * env the Java environment | |
247 | * cls the current Java class | |
248 | * cellHandle the handle of the cell to which the partition belongs | |
249 | * serverHandle the vos handle of the server to which the partition | |
250 | * belongs | |
251 | * partition the numeric id of the partition on which the volumes | |
252 | * reside | |
253 | * returns an iteration ID | |
254 | */ | |
255 | JNIEXPORT jlong JNICALL | |
256 | Java_org_openafs_jafs_Partition_getVolumesBegin | |
257 | (JNIEnv *env, jclass cls, jlong cellHandle, jlong serverHandle, jint partition) | |
258 | { | |
259 | ||
260 | afs_status_t ast; | |
261 | void *iterationId; | |
262 | ||
263 | if( !vos_VolumeGetBegin( (void *) cellHandle, (void *) serverHandle, NULL, | |
264 | (unsigned int) partition, &iterationId, &ast ) ) { | |
265 | throwAFSException( env, ast ); | |
266 | return; | |
267 | } | |
268 | ||
269 | return (jlong) iterationId; | |
270 | } | |
271 | ||
272 | /** | |
273 | * Begin the process of getting the volumes on a partition. Returns | |
274 | * an iteration ID to be used by subsequent calls to | |
275 | * getVolumesNext and getVolumesDone. | |
276 | * | |
277 | * env the Java environment | |
278 | * cls the current Java class | |
279 | * cellHandle the handle of the cell to which the partition belongs | |
280 | * serverHandle the vos handle of the server to which the partition | |
281 | * belongs | |
282 | * partition the numeric id of the partition on which the volumes | |
283 | * reside | |
284 | * returns an iteration ID | |
285 | */ | |
286 | JNIEXPORT jlong JNICALL | |
287 | Java_org_openafs_jafs_Partition_getVolumesBeginAt | |
288 | (JNIEnv *env, jclass cls, jlong cellHandle, jlong serverHandle, | |
289 | jint partition, jint index) | |
290 | { | |
291 | ||
292 | afs_status_t ast; | |
293 | void *iterationId; | |
294 | vos_volumeEntry_t volEntry; | |
295 | int i; | |
296 | ||
297 | if( !vos_VolumeGetBegin( (void *) cellHandle, (void *) serverHandle, NULL, | |
298 | (unsigned int) partition, &iterationId, &ast ) ) { | |
299 | throwAFSException( env, ast ); | |
300 | return; | |
301 | } | |
302 | ||
303 | for ( i = 1; i < index; i++) { | |
304 | if( !vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) { | |
305 | if( ast == ADMITERATORDONE ) { | |
306 | return 0; | |
307 | } else { | |
308 | throwAFSException( env, ast ); | |
309 | return 0; | |
310 | } | |
311 | } | |
312 | } | |
313 | ||
314 | return (jlong) iterationId; | |
315 | ||
316 | } | |
317 | ||
318 | /** | |
319 | * Returns the next volume of the partition. Returns null | |
320 | * if there are no more volumes. | |
321 | * | |
322 | * env the Java environment | |
323 | * cls the current Java class | |
324 | * iterationId the iteration ID of this iteration | |
325 | * returns the name of the next volume of the server | |
326 | */ | |
327 | JNIEXPORT jstring JNICALL | |
328 | Java_org_openafs_jafs_Partition_getVolumesNextString | |
329 | (JNIEnv *env, jclass cls, jlong iterationId) | |
330 | { | |
331 | afs_status_t ast; | |
332 | jstring jvolume; | |
333 | vos_volumeEntry_t volEntry; | |
334 | ||
335 | if( !vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) { | |
336 | if( ast == ADMITERATORDONE ) { | |
337 | return NULL; | |
338 | } else { | |
339 | throwAFSException( env, ast ); | |
340 | return; | |
341 | } | |
342 | } | |
343 | ||
344 | jvolume = (*env)->NewStringUTF(env, volEntry.name); | |
345 | return jvolume; | |
346 | ||
347 | } | |
348 | ||
349 | /** | |
350 | * Fills the next volume object of the partition. Returns 0 if there | |
351 | * are no more volumes, != 0 otherwise. | |
352 | * | |
353 | * env the Java environment | |
354 | * cls the current Java class | |
355 | * iterationId the iteration ID of this iteration | |
356 | * jvolumeObject the Volume object in which to fill the values | |
357 | * of the next volume | |
358 | * returns 0 if there are no more volumes, != 0 otherwise | |
359 | */ | |
360 | JNIEXPORT jint JNICALL | |
361 | Java_org_openafs_jafs_Partition_getVolumesNext | |
362 | (JNIEnv *env, jclass cls, jlong iterationId, jobject jvolumeObject) | |
363 | { | |
364 | afs_status_t ast; | |
365 | jstring jvolume; | |
366 | vos_volumeEntry_t volEntry; | |
367 | ||
368 | if( !vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) { | |
369 | if( ast == ADMITERATORDONE ) { | |
370 | return 0; | |
371 | } else { | |
372 | throwAFSException( env, ast ); | |
373 | return 0; | |
374 | } | |
375 | } | |
376 | ||
377 | ||
378 | fillVolumeInfo( env, jvolumeObject, volEntry ); | |
379 | ||
380 | // get the class fields if need be | |
381 | if( volumeCls == 0 ) { | |
382 | internal_getVolumeClass( env, jvolumeObject ); | |
383 | } | |
384 | (*env)->SetBooleanField( env, jvolumeObject, volume_cachedInfoField, TRUE ); | |
385 | ||
386 | return 1; | |
387 | ||
388 | } | |
389 | ||
390 | /** | |
391 | * Fills the next volume object of the partition. Returns 0 if there | |
392 | * are no more volumes, != 0 otherwise. | |
393 | * | |
394 | * env the Java environment | |
395 | * cls the current Java class | |
396 | * iterationId the iteration ID of this iteration | |
397 | * jvolumeObject the Volume object in which to fill the values of the | |
398 | * next volume | |
399 | * advanceCount the number of volumes to advance past | |
400 | * returns 0 if there are no more volumes, != 0 otherwise | |
401 | */ | |
402 | JNIEXPORT jint JNICALL | |
403 | Java_org_openafs_jafs_Partition_getVolumesAdvanceTo | |
404 | (JNIEnv *env, jclass cls, jlong iterationId, jobject jvolumeObject, | |
405 | jint advanceCount) | |
406 | { | |
407 | afs_status_t ast; | |
408 | jstring jvolume; | |
409 | vos_volumeEntry_t volEntry; | |
410 | int i; | |
411 | ||
412 | for ( i = 0; i < advanceCount; i++) { | |
413 | if( !vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) { | |
414 | if( ast == ADMITERATORDONE ) { | |
415 | return 0; | |
416 | } else { | |
417 | throwAFSException( env, ast ); | |
418 | return 0; | |
419 | } | |
420 | } | |
421 | } | |
422 | ||
423 | ||
424 | fillVolumeInfo( env, jvolumeObject, volEntry ); | |
425 | ||
426 | // get the class fields if need be | |
427 | if( volumeCls == 0 ) { | |
428 | internal_getVolumeClass( env, jvolumeObject ); | |
429 | } | |
430 | (*env)->SetBooleanField( env, jvolumeObject, volume_cachedInfoField, TRUE ); | |
431 | ||
432 | return 1; | |
433 | } | |
434 | ||
435 | /** | |
436 | * Signals that the iteration is complete and will not be accessed anymore. | |
437 | * | |
438 | * env the Java environment | |
439 | * cls the current Java class | |
440 | * iterationId the iteration ID of this iteration | |
441 | */ | |
442 | JNIEXPORT void JNICALL | |
443 | Java_org_openafs_jafs_Partition_getVolumesDone | |
444 | (JNIEnv *env, jclass cls, jlong iterationId) | |
445 | { | |
446 | afs_status_t ast; | |
447 | ||
448 | if( !vos_VolumeGetDone( (void *) iterationId, &ast ) ) { | |
449 | throwAFSException( env, ast ); | |
450 | return; | |
451 | } | |
452 | } | |
453 | ||
454 | // reclaim global memory being used by this portion | |
455 | JNIEXPORT void JNICALL | |
456 | Java_org_openafs_jafs_Partition_reclaimPartitionMemory | |
457 | (JNIEnv *env, jclass cls) | |
458 | { | |
459 | if( partitionCls ) { | |
460 | (*env)->DeleteGlobalRef(env, partitionCls); | |
461 | partitionCls = 0; | |
462 | } | |
463 | } | |
464 | ||
465 | ||
466 | ||
467 | ||
468 | ||
469 | ||
470 | ||
471 | ||
472 | ||
473 | ||
474 | ||
475 | ||
476 | ||
477 | ||
478 | ||
479 | ||
480 | ||
481 | ||
482 |