2 * Copyright (c) 2001-2002 International Business Machines Corp.
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
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.
23 #include "org_openafs_jafs_Partition.h"
25 #include <afs_vosAdmin.h>
26 #include <afs_AdminCommonErrors.h>
28 //// definitions in Internal.c //////////////////
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
;
38 extern jclass volumeCls
;
39 extern jfieldID volume_cachedInfoField
;
41 //////////////////////////////////////////////////////////
43 ///// definition in jafs_Volume.c /////////////////
45 extern void fillVolumeInfo
46 ( JNIEnv
*env
, jobject volume
, vos_volumeEntry_t volEntry
);
48 ///////////////////////////////////////////////////
52 * Extract the information from the given partition entry and populate the
55 * env the Java environment
56 * partition the Partition object to populate with the info
57 * partEntry the container of the partition's information
59 void fillPartitionInfo
60 (JNIEnv
*env
, jobject partition
, vos_partitionEntry_t partEntry
)
67 // get the class fields if need be
68 if( partitionCls
== 0 ) {
69 internal_getPartitionClass( env
, partition
);
72 // fill name and id in case it's a blank object
73 jpartition
= (*env
)->NewStringUTF(env
, partEntry
.name
);
75 if( !vos_PartitionNameToId( partEntry
.name
, (int *) &id
, &ast
) ) {
76 throwAFSException( env
, ast
);
79 (*env
)->SetObjectField(env
, partition
, partition_nameField
, jpartition
);
80 (*env
)->SetIntField(env
, partition
, partition_idField
, id
);
82 jdeviceName
= (*env
)->NewStringUTF(env
, partEntry
.deviceName
);
83 (*env
)->SetObjectField(env
, partition
, partition_deviceNameField
,
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
);
96 * Fills in the information fields of the provided Partition.
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
103 * partition the numeric id of the partition for which to get the
105 * jpartitionObject the Partition object in which to
106 * fill in the information
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
)
114 vos_partitionEntry_t partEntry
;
116 // get the partition entry
117 if ( !vos_PartitionGet( (void *) cellHandle
, (void *) serverHandle
, NULL
,
118 (unsigned int) partition
, &partEntry
, &ast
) ) {
119 throwAFSException( env
, ast
);
123 fillPartitionInfo( env
, jpartitionObject
, partEntry
);
128 * Translates a partition name into a partition id
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
135 JNIEXPORT jint JNICALL
136 Java_org_openafs_jafs_Partition_translateNameToID
137 (JNIEnv
*env
, jclass cls
, jstring jname
)
143 if( jname
!= NULL
) {
144 name
= (*env
)->GetStringUTFChars(env
, jname
, 0);
146 throwAFSException( env
, JAFSADMNOMEM
);
154 if( !vos_PartitionNameToId( name
, (unsigned int *) &id
, &ast
) ) {
156 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
158 throwAFSException( env
, ast
);
163 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
171 * Translates a partition id into a partition name
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
178 JNIEXPORT jstring JNICALL
179 Java_org_openafs_jafs_Partition_translateIDToName
180 (JNIEnv
*env
, jclass cls
, jint id
)
183 char *name
= malloc( sizeof(char)*VOS_MAX_PARTITION_NAME_LEN
);
187 throwAFSException( env
, JAFSADMNOMEM
);
192 if( !vos_PartitionIdToName( (unsigned int) id
, name
, &ast
) ) {
194 throwAFSException( env
, ast
);
198 jname
= (*env
)->NewStringUTF(env
, name
);
205 * Returns the total number of volumes hosted by this partition.
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
212 * partition the numeric id of the partition on which the volumes
214 * returns total number of volumes hosted by this partition
216 JNIEXPORT jint JNICALL
217 Java_org_openafs_jafs_Partition_getVolumeCount
218 (JNIEnv
*env
, jclass cls
, jlong cellHandle
, jlong serverHandle
, jint partition
)
222 vos_volumeEntry_t volEntry
;
225 if( !vos_VolumeGetBegin( (void *) cellHandle
, (void *) serverHandle
, NULL
,
226 (unsigned int) partition
, &iterationId
, &ast
) ) {
227 throwAFSException( env
, ast
);
231 while ( vos_VolumeGetNext( (void *) iterationId
, &volEntry
, &ast
) ) i
++;
233 if( ast
!= ADMITERATORDONE
) {
234 throwAFSException( env
, ast
);
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.
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
251 * partition the numeric id of the partition on which the volumes
253 * returns an iteration ID
255 JNIEXPORT jlong JNICALL
256 Java_org_openafs_jafs_Partition_getVolumesBegin
257 (JNIEnv
*env
, jclass cls
, jlong cellHandle
, jlong serverHandle
, jint partition
)
263 if( !vos_VolumeGetBegin( (void *) cellHandle
, (void *) serverHandle
, NULL
,
264 (unsigned int) partition
, &iterationId
, &ast
) ) {
265 throwAFSException( env
, ast
);
269 return (jlong
) iterationId
;
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.
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
282 * partition the numeric id of the partition on which the volumes
284 * returns an iteration ID
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
)
294 vos_volumeEntry_t volEntry
;
297 if( !vos_VolumeGetBegin( (void *) cellHandle
, (void *) serverHandle
, NULL
,
298 (unsigned int) partition
, &iterationId
, &ast
) ) {
299 throwAFSException( env
, ast
);
303 for ( i
= 1; i
< index
; i
++) {
304 if( !vos_VolumeGetNext( (void *) iterationId
, &volEntry
, &ast
) ) {
305 if( ast
== ADMITERATORDONE
) {
308 throwAFSException( env
, ast
);
314 return (jlong
) iterationId
;
319 * Returns the next volume of the partition. Returns null
320 * if there are no more volumes.
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
327 JNIEXPORT jstring JNICALL
328 Java_org_openafs_jafs_Partition_getVolumesNextString
329 (JNIEnv
*env
, jclass cls
, jlong iterationId
)
333 vos_volumeEntry_t volEntry
;
335 if( !vos_VolumeGetNext( (void *) iterationId
, &volEntry
, &ast
) ) {
336 if( ast
== ADMITERATORDONE
) {
339 throwAFSException( env
, ast
);
344 jvolume
= (*env
)->NewStringUTF(env
, volEntry
.name
);
350 * Fills the next volume object of the partition. Returns 0 if there
351 * are no more volumes, != 0 otherwise.
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
358 * returns 0 if there are no more volumes, != 0 otherwise
360 JNIEXPORT jint JNICALL
361 Java_org_openafs_jafs_Partition_getVolumesNext
362 (JNIEnv
*env
, jclass cls
, jlong iterationId
, jobject jvolumeObject
)
366 vos_volumeEntry_t volEntry
;
368 if( !vos_VolumeGetNext( (void *) iterationId
, &volEntry
, &ast
) ) {
369 if( ast
== ADMITERATORDONE
) {
372 throwAFSException( env
, ast
);
378 fillVolumeInfo( env
, jvolumeObject
, volEntry
);
380 // get the class fields if need be
381 if( volumeCls
== 0 ) {
382 internal_getVolumeClass( env
, jvolumeObject
);
384 (*env
)->SetBooleanField( env
, jvolumeObject
, volume_cachedInfoField
, TRUE
);
391 * Fills the next volume object of the partition. Returns 0 if there
392 * are no more volumes, != 0 otherwise.
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
399 * advanceCount the number of volumes to advance past
400 * returns 0 if there are no more volumes, != 0 otherwise
402 JNIEXPORT jint JNICALL
403 Java_org_openafs_jafs_Partition_getVolumesAdvanceTo
404 (JNIEnv
*env
, jclass cls
, jlong iterationId
, jobject jvolumeObject
,
409 vos_volumeEntry_t volEntry
;
412 for ( i
= 0; i
< advanceCount
; i
++) {
413 if( !vos_VolumeGetNext( (void *) iterationId
, &volEntry
, &ast
) ) {
414 if( ast
== ADMITERATORDONE
) {
417 throwAFSException( env
, ast
);
424 fillVolumeInfo( env
, jvolumeObject
, volEntry
);
426 // get the class fields if need be
427 if( volumeCls
== 0 ) {
428 internal_getVolumeClass( env
, jvolumeObject
);
430 (*env
)->SetBooleanField( env
, jvolumeObject
, volume_cachedInfoField
, TRUE
);
436 * Signals that the iteration is complete and will not be accessed anymore.
438 * env the Java environment
439 * cls the current Java class
440 * iterationId the iteration ID of this iteration
442 JNIEXPORT
void JNICALL
443 Java_org_openafs_jafs_Partition_getVolumesDone
444 (JNIEnv
*env
, jclass cls
, jlong iterationId
)
448 if( !vos_VolumeGetDone( (void *) iterationId
, &ast
) ) {
449 throwAFSException( env
, ast
);
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
)
460 (*env
)->DeleteGlobalRef(env
, partitionCls
);