linux-mmap-antirecursion-avoid-spurious-eio-20090526
[openafs.git] / src / JAVA / libjafs / Internal.c
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
24 #ifdef DMALLOC
25 #include "dmalloc.h"
26 #endif
27
28 extern int errno;
29
30 #ifndef LIBJUAFS
31 // user class and fields //
32 jclass userCls = 0;
33 jfieldID user_ptsField = 0;
34 jfieldID user_kasField = 0;
35 jfieldID user_nameField = 0;
36 //jfieldID user_cellHandleField = 0;
37 jfieldID user_cachedInfoField = 0;
38 //pts fields
39 jfieldID user_nameUidField = 0;
40 jfieldID user_ownerUidField = 0;
41 jfieldID user_creatorUidField = 0;
42 jfieldID user_listStatusField = 0;
43 jfieldID user_listGroupsOwnedField = 0;
44 jfieldID user_listMembershipField = 0;
45 jfieldID user_groupCreationQuotaField = 0;
46 jfieldID user_groupMembershipCountField = 0;
47 jfieldID user_ownerField = 0;
48 jfieldID user_creatorField = 0;
49 // kas fields
50 jfieldID user_adminSettingField = 0;
51 jfieldID user_tgsSettingField = 0;
52 jfieldID user_encSettingField = 0;
53 jfieldID user_cpwSettingField = 0;
54 jfieldID user_rpwSettingField = 0;
55 jfieldID user_userExpirationField = 0;
56 jfieldID user_lastModTimeField = 0;
57 jfieldID user_lastModNameField = 0;
58 jfieldID user_lastChangePasswordTimeField = 0;
59 jfieldID user_maxTicketLifetimeField = 0;
60 jfieldID user_keyVersionField = 0;
61 jfieldID user_encryptionKeyField = 0;
62 jfieldID user_keyCheckSumField = 0;
63 jfieldID user_daysToPasswordExpireField = 0;
64 jfieldID user_failLoginCountField = 0;
65 jfieldID user_lockTimeField = 0;
66 jfieldID user_lockedUntilField = 0;
67
68 // group class and fields //
69 jclass groupCls = 0;
70 jfieldID group_nameField = 0;
71 //jfieldID group_cellHandleField = 0;
72 jfieldID group_cachedInfoField = 0;
73 jfieldID group_nameUidField = 0;
74 jfieldID group_ownerUidField = 0;
75 jfieldID group_creatorUidField = 0;
76 jfieldID group_listStatusField = 0;
77 jfieldID group_listGroupsOwnedField = 0;
78 jfieldID group_listMembershipField = 0;
79 jfieldID group_listAddField = 0;
80 jfieldID group_listDeleteField = 0;
81 jfieldID group_membershipCountField = 0;
82 jfieldID group_ownerField = 0;
83 jfieldID group_creatorField = 0;
84
85 // server class and fields //
86 jclass serverCls = 0;
87 jfieldID server_nameField = 0;
88 //jfieldID server_cellHandleField = 0;
89 jfieldID server_cachedInfoField = 0;
90 jfieldID server_databaseField = 0;
91 jfieldID server_fileServerField = 0;
92 jfieldID server_badDatabaseField = 0;
93 jfieldID server_badFileServerField = 0;
94 jfieldID server_IPAddressField = 0;
95
96 // executable time class and fields //
97 jclass exectimeCls = 0;
98 jfieldID exectime_HourField = 0;
99 jfieldID exectime_MinField = 0;
100 jfieldID exectime_SecField = 0;
101 jfieldID exectime_DayField = 0;
102 jfieldID exectime_NowField = 0;
103 jfieldID exectime_NeverField = 0;
104
105 // partition class and fields //
106 jclass partitionCls = 0;
107 jfieldID partition_nameField = 0;
108 jfieldID partition_cachedInfoField = 0;
109 jfieldID partition_idField = 0;
110 jfieldID partition_deviceNameField = 0;
111 jfieldID partition_lockFileDescriptorField = 0;
112 jfieldID partition_totalSpaceField = 0;
113 jfieldID partition_totalFreeSpaceField = 0;
114
115 // volume class and fields //
116 jclass volumeCls = 0;
117 jfieldID volume_nameField = 0;
118 jfieldID volume_cachedInfoField = 0;
119 jfieldID volume_idField = 0;
120 jfieldID volume_readWriteIdField = 0;
121 jfieldID volume_readOnlyIdField = 0;
122 jfieldID volume_backupIdField = 0;
123 jfieldID volume_creationDateField = 0;
124 jfieldID volume_lastAccessDateField = 0;
125 jfieldID volume_lastUpdateDateField = 0;
126 jfieldID volume_lastBackupDateField = 0;
127 jfieldID volume_copyCreationDateField = 0;
128 jfieldID volume_accessesSinceMidnightField = 0;
129 jfieldID volume_fileCountField = 0;
130 jfieldID volume_maxQuotaField = 0;
131 jfieldID volume_currentSizeField = 0;
132 jfieldID volume_statusField = 0;
133 jfieldID volume_dispositionField = 0;
134 jfieldID volume_typeField = 0;
135
136 // key class and fields //
137 jclass keyCls = 0;
138 jfieldID key_cachedInfoField = 0;
139 jfieldID key_versionField = 0;
140 jfieldID key_encryptionKeyField = 0;
141 jfieldID key_lastModDateField = 0;
142 jfieldID key_lastModMsField = 0;
143 jfieldID key_checkSumField = 0;
144
145 // process class and fields //
146 jclass processCls = 0;
147 jfieldID process_cachedInfoField = 0;
148 jfieldID process_nameField = 0;
149 //jfieldID process_serverHandleField = 0;
150 jfieldID process_typeField = 0;
151 jfieldID process_stateField = 0;
152 jfieldID process_goalField = 0;
153 jfieldID process_startTimeField = 0;
154 jfieldID process_numberStartsField = 0;
155 jfieldID process_exitTimeField = 0;
156 jfieldID process_exitErrorTimeField = 0;
157 jfieldID process_errorCodeField = 0;
158 jfieldID process_errorSignalField = 0;
159 jfieldID process_stateOkField = 0;
160 jfieldID process_stateTooManyErrorsField = 0;
161 jfieldID process_stateBadFileAccessField = 0;
162 #endif /* !LIBJUAFS */
163
164 /**
165  * Throws an exception up to the Java layer, using ast as the error code
166  * for the exception.  See Exceptions.h for the available
167  * exceptions.
168  */
169 void throwException
170   (JNIEnv *env, jclass *excCls, char *excClsName, jmethodID *initID, int code)
171 {
172   jobject exc;
173   if( *excCls == 0 ) {
174     *excCls = (*env)->NewGlobalRef(env, (*env)->FindClass(env, excClsName ));
175     if( !*excCls ) {
176       fprintf(stderr, "ERROR: Internal::throwException()\n Cannot find class: %s\n", excClsName);
177         return;
178     }
179     *initID = (*env)->GetMethodID( env, *excCls, "<init>", "(I)V" );
180     if( !*initID ) {
181       fprintf(stderr, "ERROR: Internal::throwException()\n Cannot find construction method: %s\n",
182               excClsName);
183         return;
184     }
185   }
186   
187   exc = (*env)->NewObject( env, *excCls, *initID, code );
188   if( !exc ) {
189     fprintf(stderr, "ERROR: Internal::throwException()\n Cannot construct new exception object: %s\n",
190                      excClsName);
191     return;
192   }
193   (*env)->Throw(env, exc);
194 }
195
196 /**
197  * Throws an exception up to the Java layer, constructing it with msg.
198  * This function should only be used when a valid AFS error number/code
199  * is unavailable and it is necessary to interrupt the Java call with an
200  * exception. See Exceptions.h for the available exceptions.
201  */
202 void throwMessageException( JNIEnv *env, char *msg )
203 {
204   jclass excCls = (*env)->FindClass(env, afsExceptionName);
205   if(excCls == 0) {
206     fprintf(stderr, "ERROR: Internal::throwMessageException()\n Cannot find class: %s\n", afsExceptionName);
207     return;
208   }
209   (*env)->ThrowNew(env, excCls, msg);
210 }
211
212 /**
213  * Throws an exception up to the Java layer, using ast as the error code
214  * for the exception.  See Exceptions.h for the available
215  * exceptions.
216  */
217 void throwAFSException( JNIEnv *env, int code )
218 {
219   jclass afsExceptionCls;
220   jmethodID afsExceptionInit;
221   jthrowable exc;
222
223   afsExceptionCls = (*env)->FindClass(env, afsExceptionName);
224   if( !afsExceptionCls ) {
225     fprintf(stderr, "ERROR: Internal::throwAFSException()\n Cannot find class: %s\n", afsExceptionName);
226     return;
227   }
228
229   afsExceptionInit = (*env)->GetMethodID( env, afsExceptionCls, 
230                              "<init>", "(I)V" );
231   if( !afsExceptionInit ) {
232     fprintf(stderr, "ERROR: Internal::throwAFSException()\n Cannot find construction method: %s\n",
233                      afsExceptionName);
234     return;
235   }
236   
237   exc = (*env)->NewObject( env, afsExceptionCls, afsExceptionInit, code );
238
239   if( !exc ) {
240     fprintf(stderr, "ERROR: Internal::throwAFSException()\n Cannot construct new exception object: %s\n",
241                      afsExceptionName);
242     return;
243   }
244   (*env)->Throw(env, exc);
245 }
246
247 /**
248  * Throws an exception up to the Java layer, using ast as the error code
249  * for the exception.  See Exceptions.h for the available
250  * exceptions.
251  */
252 void throwAFSFileException( JNIEnv *env, int code, char *msg )
253 {
254   jclass afsFileExceptionCls;
255   jmethodID afsFileExceptionInit;
256   jthrowable exc;
257
258   afsFileExceptionCls = (*env)->FindClass(env, afsFileExceptionName);
259   if( !afsFileExceptionCls ) {
260     fprintf(stderr, "ERROR: Internal::throwAFSFileException()\n Cannot find class: %s\n", afsFileExceptionName);
261     return;
262   }
263
264   afsFileExceptionInit = (*env)->GetMethodID( env, afsFileExceptionCls, 
265                          "<init>", "(Ljava/lang/String;I)V" );
266   if( !afsFileExceptionInit ) {
267     fprintf(stderr, "ERROR: Internal::throwAFSFileException()\n Cannot find construction method: %s\n",
268                      afsFileExceptionName);
269     return;
270   }
271   
272   exc = (*env)->NewObject( env, afsFileExceptionCls,
273                            afsFileExceptionInit, msg, code );
274   if( !exc ) {
275     fprintf(stderr, "ERROR: Internal::throwAFSFileException()\n Cannot construct new exception object: %s\n",
276                      afsFileExceptionName);
277     return;
278   }
279   (*env)->Throw(env, exc);
280 }
281
282 /**
283  * Throws an exception up to the Java layer, using ast as the error code
284  * for the exception.  See Exceptions.h for the available
285  * exceptions.
286  */
287 void throwAFSSecurityException( JNIEnv *env, int code )
288 {
289   jclass afsSecurityExceptionCls;
290   jmethodID afsSecurityExceptionInit;
291   jthrowable exc;
292
293   afsSecurityExceptionCls = (*env)->FindClass(env, afsSecurityExceptionName);
294   if( !afsSecurityExceptionCls ) {
295     fprintf(stderr, "ERROR: Internal::throwAFSSecurityException()\n Cannot find class: %s\n", afsSecurityExceptionName);
296     return;
297   }
298
299   afsSecurityExceptionInit = (*env)->GetMethodID( env, afsSecurityExceptionCls, 
300                              "<init>", "(I)V" );
301   if( !afsSecurityExceptionInit ) {
302     fprintf(stderr, "ERROR: Internal::throwAFSSecurityException()\n Cannot find construction method: %s\n",
303                      afsSecurityExceptionName);
304     return;
305   }
306   
307   exc = (*env)->NewObject( env, afsSecurityExceptionCls,
308                            afsSecurityExceptionInit, code );
309   if( !exc ) {
310     fprintf(stderr, "ERROR: Internal::throwAFSSecurityException()\n Cannot construct new exception object: %s\n",
311                      afsSecurityExceptionName);
312     return;
313   }
314   (*env)->Throw(env, exc);
315 }
316
317 int setError(JNIEnv *env, jobject *obj, int code)
318 {
319   jfieldID fid;
320   jclass cls = (*env)->GetObjectClass(env, *obj);
321   if (cls != NULL) {
322     fid = (*env)->GetFieldID(env, cls, "errno", "I");
323     if (fid)
324     {
325       (*env)->SetIntField(env, *obj, fid, code);
326       return 0;
327     }
328   }
329   return -1;
330 }
331
332 #ifdef LIBJUAFS
333
334 /**
335  * Opens an AFS file, with the specified name, using the specified flags
336  * with in the specified mode (permission mode).
337  * 
338  *  env         the Java environment
339  *  fileNameUTF name of file to be opened
340  *  flags               open mode: O_CREAT, O_APPEND
341  *  mode                UNIX permission mode mask
342  *  err         error variable
343  *
344  * @returns             file descriptor
345  */
346 int openAFSFile
347   (JNIEnv *env, jstring fileNameUTF, int flags, int mode, int *err)
348 {
349     char *fileName;
350     int fd = -1;
351
352     *err = 0;
353     errno = 0;
354     fileName=(char*) (*env)->GetStringUTFChars(env, fileNameUTF, 0);
355     if(fileName == NULL) {
356       fprintf(stderr, "Internal::openAFSFile(): failed to get fileName\n");
357       *err = -1;
358       return fd;
359     }
360     fd  = uafs_open(fileName, flags, mode);
361     *err = errno;
362     if (errno != 0) {
363       fprintf(stderr, "Internal::openAFSFile(): errno=%d\n", errno);
364       fprintf(stderr, "Internal::openAFSFile(): fd=%d\n", fd);
365     }
366     (*env)->ReleaseStringUTFChars(env, fileNameUTF, fileName);
367     if (fd < 0) {
368       fprintf(stderr, "Internal::openAFSFile(): failed to open fileName\n");
369       fprintf(stderr, "Internal::openAFSFile(): fd=%d\n", fd);
370       return -1;
371     }
372     return fd;
373 }
374
375 int readCacheParms(char *afsMountPoint, char *afsConfDir, char *afsCacheDir,
376                    int *cacheBlocks, int *cacheFiles, int *cacheStatEntries,
377                    int *dCacheSize, int *vCacheSize, int *chunkSize,
378                    int *closeSynch, int *debug, int *nDaemons, int *cacheFlags,
379                    char *logFile)
380 {
381   FILE *f;
382   char line[100];
383   char *p;
384   int len1, len2, n;
385   char cacheConfigFile[100];
386   
387   p = (char *)getenv("LIBJAFS_CACHE_CONFIG");
388   if (p) {
389     strcpy(cacheConfigFile, p);
390   } else {
391     strcpy(cacheConfigFile, "/usr/afswsp/etc/CacheConfig");
392   }
393
394   f = fopen(cacheConfigFile, "r");
395   if (!f) {
396     fprintf(stderr, "Could not open cache config file: %s\n",
397             cacheConfigFile);
398     return -1;
399   }
400
401   while (1) {
402     fgets(line, 100, f);
403     if (feof(f)) break;
404     p = (char *)strchr(line, '\n');
405     if (p) *p = '\0';
406     if (strncmp(line, "#", 1) == 0) continue;  /* comment */
407
408     p = (char *)strchr(line, ' ');
409     if (!p) continue;
410     len1 = p - line;
411     p++; len2 = strlen(p);
412
413     if (strncmp(line, "MountPoint", len1) == 0)
414        strcpy(afsMountPoint, p);
415     else if (strncmp(line, "ConfDir", len1) == 0)
416        strcpy(afsConfDir, p);
417     else if (strncmp(line, "CacheDir", len1) == 0)
418        strcpy(afsCacheDir, p);
419     else if (strncmp(line, "CacheBlocks", len1) == 0)
420        *cacheBlocks = atoi(p);
421     else if (strncmp(line, "CacheFiles", len1) == 0)
422        *cacheFiles = atoi(p);
423     else if (strncmp(line, "CacheStatEntries", len1) == 0)
424        *cacheStatEntries = atoi(p);
425     else if (strncmp(line, "DCacheSize", len1) == 0)
426        *dCacheSize = atoi(p);
427     else if (strncmp(line, "VCacheSize", len1) == 0)
428        *vCacheSize = atoi(p);
429     else if (strncmp(line, "ChunkSize", len1) == 0)
430        *chunkSize = atoi(p);
431     else if (strncmp(line, "CloseSynch", len1) == 0)
432        *closeSynch = atoi(p);
433     else if (strncmp(line, "Debug", len1) == 0)
434        *debug = atoi(p);
435     else if (strncmp(line, "NDaemons", len1) == 0)
436        *nDaemons = atoi(p);
437     else if (strncmp(line, "CacheFlags", len1) == 0)
438        *cacheFlags = atoi(p);
439     else if (strncmp(line, "LogFile", len1) == 0)
440        strcpy(logFile, p);
441   }
442   return 0;
443 }
444
445 int setString(JNIEnv *env, jobject *obj, char *field, char *string)
446 {
447   jclass cls;
448   jstring jstr;
449   jfieldID fid;
450
451   cls = (*env)->GetObjectClass(env, *obj);
452   /*fprintf(stderr, "setString: env=0x%x, obj=0x%x, cls=0x%x\n", env, obj, cls);*/
453   if (cls != NULL) {
454     fid = (*env)->GetFieldID(env, cls, field, "Ljava/lang/String;");
455     /*fprintf(stderr, "setString: field=%s, fid=0x%x\n", field, fid);*/
456     if (fid) {
457       jstr = (*env)->NewStringUTF(env, (string));
458       /*fprintf(stderr, "jstr = 0x%x\n", jstr);*/
459       (*env)->SetObjectField(env, *obj, fid, jstr);
460       return 0;
461     }
462   }
463   return -1;
464 }
465
466 #else
467
468 /**
469  * Makes a kas identity given the full name of a kas user.  If the
470  * name contains a period, everything after the first period is
471  * considered to be the instance of that name, otherwise
472  * the instance is the empty string.  The memory for who 
473  * that's passed in should be fully allocated in advance.
474  */
475 void internal_makeKasIdentity( const char *fullName, 
476                                        kas_identity_p who ) {
477
478   char *period;
479
480   if( (period = (char *) strchr( fullName, '.' )) != NULL ) {
481     strncpy( who->principal, fullName, period - fullName );
482     who->principal[period - fullName] = '\0';
483     strncpy( who->instance, period + 1, 
484              strlen(fullName) - (period - fullName) );
485   } else {
486     strcpy( who->principal, fullName);
487     strcpy( who->instance, "" );
488   }
489
490 }
491
492 /**
493  * Given a Java environment and an instance of a user, gets the object and
494  * field information for the user object from the Java environment.
495  */
496 void internal_getUserClass( JNIEnv *env, jobject user ) {
497   if( userCls == 0 ) {
498     userCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, user) );
499     if( !userCls ) {
500         throwAFSException( env, JAFSADMCLASSNOTFOUND );
501         return;
502     }
503     user_ptsField = (*env)->GetFieldID( env, userCls, "pts", "Z" );
504     user_kasField = (*env)->GetFieldID( env, userCls, "kas", "Z" );
505     user_nameField = (*env)->GetFieldID( env, userCls, "name", 
506                                          "Ljava/lang/String;" );
507     user_cachedInfoField = (*env)->GetFieldID( env, userCls, "cachedInfo", 
508                                                "Z" );
509     // pts fields
510     user_nameUidField = (*env)->GetFieldID( env, userCls, "nameUID", "I" );
511     user_ownerUidField = (*env)->GetFieldID( env, userCls, "ownerUID", "I" );
512     user_creatorUidField = (*env)->GetFieldID( env, userCls, "creatorUID", 
513                                                "I" );
514     user_listStatusField = (*env)->GetFieldID( env, userCls, "listStatus", 
515                                                "I" );
516     user_listGroupsOwnedField = (*env)->GetFieldID( env, userCls, 
517                                                     "listGroupsOwned", "I" );
518     user_listMembershipField = (*env)->GetFieldID( env, userCls, 
519                                                    "listMembership", "I" );
520     user_groupCreationQuotaField = (*env)->GetFieldID( env, userCls, 
521                                                        "groupCreationQuota", 
522                                                        "I" );
523     user_groupMembershipCountField = (*env)->GetFieldID( env, userCls, 
524                                                         "groupMembershipCount",
525                                                          "I" );
526     user_ownerField = (*env)->GetFieldID( env, userCls, "owner", 
527                                           "Ljava/lang/String;" );
528     user_creatorField = (*env)->GetFieldID( env, userCls, "creator", 
529                                             "Ljava/lang/String;" );
530     // kas fields
531     user_adminSettingField = (*env)->GetFieldID( env, userCls, "adminSetting",
532                                                  "I" );
533     user_tgsSettingField = (*env)->GetFieldID( env, userCls, "tgsSetting", 
534                                                "I" );
535     user_encSettingField = (*env)->GetFieldID( env, userCls, "encSetting", 
536                                                "I" );
537     user_cpwSettingField = (*env)->GetFieldID( env, userCls, "cpwSetting", 
538                                                "I" );
539     user_rpwSettingField = (*env)->GetFieldID( env, userCls, "rpwSetting", 
540                                                "I" );
541     user_userExpirationField = (*env)->GetFieldID( env, userCls, 
542                                                    "userExpiration", "I" );
543     user_lastModTimeField = (*env)->GetFieldID( env, userCls, "lastModTime", 
544                                                 "I" );
545     user_lastModNameField = (*env)->GetFieldID( env, userCls, "lastModName", 
546                                                 "Ljava/lang/String;" );
547     user_lastChangePasswordTimeField = (*env)->GetFieldID( env, userCls, 
548                                                       "lastChangePasswordTime",
549                                                            "I" );
550     user_maxTicketLifetimeField = (*env)->GetFieldID( env, userCls, 
551                                                       "maxTicketLifetime", 
552                                                       "I" );
553     user_keyVersionField = (*env)->GetFieldID( env, userCls, "keyVersion", 
554                                                "I" );
555     user_encryptionKeyField = (*env)->GetFieldID( env, userCls, 
556                                                   "encryptionKey", 
557                                                   "Ljava/lang/String;" );
558     user_keyCheckSumField = (*env)->GetFieldID( env, userCls, "keyCheckSum", 
559                                                 "J" );
560     user_daysToPasswordExpireField = (*env)->GetFieldID( env, userCls, 
561                                                         "daysToPasswordExpire",
562                                                          "I" );
563     user_failLoginCountField = (*env)->GetFieldID( env, userCls, 
564                                                    "failLoginCount", "I" );
565     user_lockTimeField = (*env)->GetFieldID( env, userCls, "lockTime", "I" );
566     user_lockedUntilField = (*env)->GetFieldID( env, userCls, "lockedUntil", 
567                                                 "I" );
568     if( !user_ptsField || !user_kasField || !user_nameField || 
569         !user_cachedInfoField || !user_nameUidField || !user_ownerUidField || 
570         !user_creatorUidField || !user_listStatusField || 
571         !user_listGroupsOwnedField || !user_listMembershipField || 
572         !user_groupCreationQuotaField || !user_groupMembershipCountField || 
573         !user_ownerField || !user_creatorField || !user_adminSettingField || 
574         !user_tgsSettingField || !user_encSettingField || 
575         !user_cpwSettingField || !user_rpwSettingField || 
576         !user_userExpirationField || !user_lastModTimeField || 
577         !user_lastModNameField || !user_lastChangePasswordTimeField || 
578         !user_maxTicketLifetimeField || !user_keyVersionField || 
579         !user_encryptionKeyField || !user_keyCheckSumField || 
580         !user_daysToPasswordExpireField || !user_failLoginCountField || 
581         !user_lockTimeField || !user_lockedUntilField ) {
582
583         throwAFSException( env, JAFSADMFIELDNOTFOUND );
584         return;
585
586     }
587   } 
588 }
589
590 /**
591  * Given a Java environment and an instance of a group, gets the object and
592  * field information for the group object from the Java environment.
593  */
594 void internal_getGroupClass( JNIEnv *env, jobject group ) {
595   if( groupCls == 0 ) {
596     groupCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, group) );
597     if( !groupCls ) {
598         throwAFSException( env, JAFSADMCLASSNOTFOUND );
599         return;
600     }
601     group_nameField = (*env)->GetFieldID( env, groupCls, "name", 
602                                           "Ljava/lang/String;" );
603     group_cachedInfoField = (*env)->GetFieldID( env, groupCls, "cachedInfo", 
604                                                 "Z" );
605     group_nameUidField = (*env)->GetFieldID( env, groupCls, "nameUID", "I" );
606     group_ownerUidField = (*env)->GetFieldID( env, groupCls, "ownerUID", "I" );
607     group_creatorUidField = (*env)->GetFieldID( env, groupCls, "creatorUID", 
608                                                 "I" );
609     group_listStatusField = (*env)->GetFieldID( env, groupCls, "listStatus", 
610                                                 "I" );
611     group_listGroupsOwnedField = (*env)->GetFieldID( env, groupCls, 
612                                                      "listGroupsOwned", "I" );
613     group_listMembershipField = (*env)->GetFieldID( env, groupCls, 
614                                                     "listMembership", "I" );
615     group_listAddField = (*env)->GetFieldID( env, groupCls, "listAdd", "I" );
616     group_listDeleteField = (*env)->GetFieldID( env, groupCls, "listDelete", 
617                                                 "I" );
618     group_membershipCountField = (*env)->GetFieldID( env, groupCls, 
619                                                      "membershipCount", "I" );
620     group_ownerField = (*env)->GetFieldID( env, groupCls, "owner", 
621                                            "Ljava/lang/String;" );
622     group_creatorField = (*env)->GetFieldID( env, groupCls, "creator", 
623                                              "Ljava/lang/String;" );
624     if( !group_nameField || !group_cachedInfoField || !group_nameUidField || 
625         !group_ownerUidField || !group_creatorUidField || 
626         !group_listStatusField || !group_listGroupsOwnedField || 
627         !group_listMembershipField || !group_listAddField || 
628         !group_listDeleteField || !group_membershipCountField || 
629         !group_ownerField || !group_creatorField ) {
630
631         throwAFSException( env, JAFSADMFIELDNOTFOUND );
632         return;
633
634     }
635   }
636 }
637
638 /**
639  * Given a Java environment and an instance of a server, gets the object and
640  * field information for the server object from the Java environment.
641  */
642 void internal_getServerClass( JNIEnv *env, jobject server ) {
643   if( serverCls == 0 ) {
644     serverCls = (*env)->NewGlobalRef( env,
645                                       (*env)->GetObjectClass(env, server) );
646     if( !serverCls ) {
647         throwAFSException( env, JAFSADMCLASSNOTFOUND );
648         return;
649     }
650     server_nameField = (*env)->GetFieldID( env, serverCls, "name", 
651                                            "Ljava/lang/String;" );
652     server_cachedInfoField = (*env)->GetFieldID( env, serverCls, "cachedInfo",
653                                                  "Z" );
654     server_databaseField = (*env)->GetFieldID( env, serverCls, "database", 
655                                                "Z" );
656     server_fileServerField = (*env)->GetFieldID( env, serverCls, "fileServer", 
657                                                  "Z" );
658     server_badDatabaseField = (*env)->GetFieldID( env, serverCls, 
659                                                   "badDatabase", "Z" );
660     server_badFileServerField = (*env)->GetFieldID( env, serverCls, 
661                                                     "badFileServer", "Z" );
662     server_IPAddressField = (*env)->GetFieldID( env, serverCls, "ipAddresses",
663                                                 "[Ljava/lang/String;" );
664     if( !server_nameField || !server_cachedInfoField || !server_databaseField 
665         || !server_fileServerField || !server_badDatabaseField || 
666         !server_badFileServerField || !server_IPAddressField ) {
667
668         throwAFSException( env, JAFSADMFIELDNOTFOUND );
669         return;
670
671     }
672   }
673 }
674
675 /**
676  * Given a Java environment and an instance of an executableTime, gets the 
677  * object and field information for the executableTime object from the 
678  * Java environment.
679  */
680 void internal_getExecTimeClass( JNIEnv *env, jobject exectime ) {
681   if( exectimeCls == 0 ) {
682     exectimeCls = (*env)->NewGlobalRef( env, 
683                                        (*env)->GetObjectClass(env, exectime) );
684     if( !exectimeCls ) {
685         throwAFSException( env, JAFSADMCLASSNOTFOUND );
686         return;
687     }
688     exectime_HourField  = (*env)->GetFieldID( env, exectimeCls, "hour", "S" );
689     exectime_MinField   = (*env)->GetFieldID( env, exectimeCls, "minute", 
690                                               "S" );
691     exectime_SecField   = (*env)->GetFieldID( env, exectimeCls, "second", 
692                                               "S" );
693     exectime_DayField   = (*env)->GetFieldID( env, exectimeCls, "day", "S" );
694     exectime_NowField   = (*env)->GetFieldID( env, exectimeCls, "now", "Z" );
695     exectime_NeverField = (*env)->GetFieldID( env, exectimeCls, "never", "Z" );
696     if( !exectime_HourField || !exectime_MinField || !exectime_SecField || 
697         !exectime_DayField || !exectime_NowField || !exectime_NeverField ) {
698
699         throwAFSException( env, JAFSADMFIELDNOTFOUND );
700         return;
701
702     }
703   }
704 }
705
706 /**
707  * Given a Java environment and an instance of a partition, gets the object and
708  * field information for the partition object from the Java environment.
709  */
710 void internal_getPartitionClass( JNIEnv *env, jobject partition ) {
711   if( partitionCls == 0 ) {
712     partitionCls = (*env)->NewGlobalRef( env, 
713                                       (*env)->GetObjectClass(env, partition) );
714     if( !partitionCls ) {
715         throwAFSException( env, JAFSADMCLASSNOTFOUND );
716         return;
717     }
718     partition_nameField = (*env)->GetFieldID( env, partitionCls, "name", 
719                                               "Ljava/lang/String;" );
720     partition_deviceNameField = (*env)->GetFieldID( env, partitionCls, 
721                                                     "deviceName", 
722                                                     "Ljava/lang/String;" );
723     partition_idField = (*env)->GetFieldID( env, partitionCls, "id", "I" );
724     partition_cachedInfoField = (*env)->GetFieldID( env, partitionCls, 
725                                                     "cachedInfo", "Z" );
726     partition_lockFileDescriptorField = (*env)->GetFieldID( env, partitionCls,
727                                                           "lockFileDescriptor",
728                                                             "I" );
729     partition_totalSpaceField = (*env)->GetFieldID( env, partitionCls, 
730                                                     "totalSpace", "I" );
731     partition_totalFreeSpaceField = (*env)->GetFieldID( env, partitionCls, 
732                                                         "totalFreeSpace", "I");
733     if( !partition_nameField || !partition_cachedInfoField || 
734         !partition_idField || !partition_deviceNameField || 
735         !partition_lockFileDescriptorField || !partition_totalSpaceField || 
736         !partition_totalFreeSpaceField ) {
737
738         throwAFSException( env, JAFSADMFIELDNOTFOUND );
739         return;
740
741     }
742   }
743 }
744
745 /**
746  * Given a Java environment and an instance of a volume, gets the object and
747  * field information for the volume object from the Java environment.
748  */
749 void internal_getVolumeClass( JNIEnv *env, jobject volume ) {
750   if( volumeCls == 0 ) {
751     volumeCls = (*env)->NewGlobalRef( env, 
752                                       (*env)->GetObjectClass(env, volume) );
753     if( !volumeCls ) {
754         throwAFSException( env, JAFSADMCLASSNOTFOUND );
755         return;
756     }
757     volume_nameField = (*env)->GetFieldID( env, volumeCls, "name", 
758                                            "Ljava/lang/String;" );
759     volume_cachedInfoField = (*env)->GetFieldID( env, volumeCls, "cachedInfo", 
760                                                  "Z" );
761     volume_idField = (*env)->GetFieldID( env, volumeCls, "id", "I" );
762     volume_readWriteIdField = (*env)->GetFieldID( env, volumeCls, 
763                                                   "readWriteID", "I" );
764     volume_readOnlyIdField = (*env)->GetFieldID( env, volumeCls, "readOnlyID", 
765                                                  "I" );
766     volume_backupIdField = (*env)->GetFieldID( env, volumeCls, "backupID", 
767                                                "I" );
768     volume_creationDateField = (*env)->GetFieldID( env, volumeCls, 
769                                                    "creationDate", "J" );
770     volume_lastAccessDateField = (*env)->GetFieldID( env, volumeCls, 
771                                                      "lastAccessDate", "J" );
772     volume_lastUpdateDateField = (*env)->GetFieldID( env, volumeCls, 
773                                                      "lastUpdateDate", "J" );
774     volume_lastBackupDateField = (*env)->GetFieldID( env, volumeCls, 
775                                                      "lastBackupDate", "J" );
776     volume_copyCreationDateField = (*env)->GetFieldID( env, volumeCls, 
777                                                        "copyCreationDate", 
778                                                        "J" );
779     volume_accessesSinceMidnightField = (*env)->GetFieldID( env, volumeCls, 
780                                                        "accessesSinceMidnight",
781                                                             "I" );
782     volume_fileCountField = (*env)->GetFieldID( env, volumeCls, "fileCount", 
783                                                 "I" );
784     volume_maxQuotaField = (*env)->GetFieldID( env, volumeCls, "maxQuota", 
785                                                "I" );
786     volume_currentSizeField = (*env)->GetFieldID( env, volumeCls, 
787                                                   "currentSize", "I" );
788     volume_statusField = (*env)->GetFieldID( env, volumeCls, "status", "I" );
789     volume_dispositionField = (*env)->GetFieldID( env, volumeCls, 
790                                                   "disposition", "I" );
791     volume_typeField = (*env)->GetFieldID( env, volumeCls, "type", "I" );
792     if( !volume_nameField || !volume_cachedInfoField || !volume_idField || 
793         !volume_readWriteIdField || !volume_readOnlyIdField || 
794         !volume_backupIdField || !volume_creationDateField || 
795         !volume_lastAccessDateField || !volume_lastUpdateDateField || 
796         !volume_lastBackupDateField || !volume_copyCreationDateField || 
797         !volume_accessesSinceMidnightField || !volume_fileCountField || 
798         !volume_maxQuotaField || !volume_currentSizeField || 
799         !volume_statusField || !volume_dispositionField || 
800         !volume_typeField ) {
801
802         throwAFSException( env, JAFSADMFIELDNOTFOUND );
803         return;
804
805     }
806   }
807 }
808
809 /**
810  * Given a Java environment and an instance of a key, gets the object and
811  * field information for the key object from the Java environment.
812  */
813 void internal_getKeyClass( JNIEnv *env, jobject key ) {
814   if( keyCls == 0 ) {
815     keyCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, key) );
816     if( !keyCls ) {
817         throwAFSException( env, JAFSADMCLASSNOTFOUND );
818         return;
819     }
820     key_encryptionKeyField = (*env)->GetFieldID( env, keyCls, 
821                                                  "encryptionKey", 
822                                                  "Ljava/lang/String;" );
823     key_cachedInfoField = (*env)->GetFieldID( env, keyCls, "cachedInfo", "Z" );
824     key_versionField = (*env)->GetFieldID( env, keyCls, "version", "I" );
825     key_lastModDateField = (*env)->GetFieldID( env, keyCls, "lastModDate", 
826                                                "I" );
827     key_lastModMsField = (*env)->GetFieldID( env, keyCls, "lastModMs", "I" );
828     key_checkSumField = (*env)->GetFieldID( env, keyCls, "checkSum", "J" );
829     if( !key_cachedInfoField || !key_versionField || !key_encryptionKeyField 
830         || !key_lastModDateField || !key_lastModMsField || 
831         !key_checkSumField ) {
832
833         throwAFSException( env, JAFSADMFIELDNOTFOUND );
834         return;
835
836     }
837   }
838 }
839
840 /**
841  * Given a Java environment and an instance of a process, gets the object and
842  * field information for the process object from the Java environment.
843  */
844 void internal_getProcessClass( JNIEnv *env, jobject process ) {
845   if( processCls == 0 ) {
846     processCls = (*env)->NewGlobalRef( env, 
847                                        (*env)->GetObjectClass(env, process) );
848     if( !processCls ) {
849         throwAFSException( env, JAFSADMCLASSNOTFOUND );
850         return;
851     }
852     process_cachedInfoField = (*env)->GetFieldID( env, processCls, 
853                                                   "cachedInfo", "Z" );
854     process_nameField = (*env)->GetFieldID( env, processCls, "name", 
855                                             "Ljava/lang/String;" );
856     process_typeField = (*env)->GetFieldID( env, processCls, "type", "I" );
857     process_stateField = (*env)->GetFieldID( env, processCls, "state", "I" );
858     process_goalField = (*env)->GetFieldID( env, processCls, "goal", "I" );
859     process_startTimeField = (*env)->GetFieldID( env, processCls, "startTime", 
860                                                  "J" ); 
861     process_numberStartsField = (*env)->GetFieldID( env, processCls, 
862                                                     "numberStarts", "J" ); 
863     process_exitTimeField = (*env)->GetFieldID( env, processCls, "exitTime", 
864                                                 "J" ); 
865     process_exitErrorTimeField = (*env)->GetFieldID( env, processCls, 
866                                                      "exitErrorTime", "J" ); 
867     process_errorCodeField = (*env)->GetFieldID( env, processCls, "errorCode", 
868                                                  "J" ); 
869     process_errorSignalField = (*env)->GetFieldID( env, processCls, 
870                                                    "errorSignal", "J" ); 
871     process_stateOkField = (*env)->GetFieldID( env, processCls, "stateOk", 
872                                                "Z" ); 
873     process_stateTooManyErrorsField = (*env)->GetFieldID( env, processCls, 
874                                                           "stateTooManyErrors",
875                                                           "Z" ); 
876     process_stateBadFileAccessField = (*env)->GetFieldID( env, processCls, 
877                                                           "stateBadFileAccess",
878                                                           "Z" ); 
879     if( !process_cachedInfoField || !process_nameField || !process_typeField 
880         || !process_stateField || !process_goalField || 
881         !process_startTimeField || !process_numberStartsField || 
882         !process_exitTimeField || !process_exitErrorTimeField || 
883         !process_errorCodeField || !process_errorSignalField || 
884         !process_stateOkField || !process_stateTooManyErrorsField || 
885         !process_stateBadFileAccessField ) {
886
887         throwAFSException( env, JAFSADMFIELDNOTFOUND );
888         return;
889
890     }
891   }
892 }
893
894 #endif /* LIBJUAFS */
895
896