annotate src/solaris/native/java/io/UnixFileSystem_md.c @ 0:37a05a11f281

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children eac5c4ead3ca
rev   line source
duke@0 1 /*
duke@0 2 * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation. Sun designates this
duke@0 8 * particular file as subject to the "Classpath" exception as provided
duke@0 9 * by Sun in the LICENSE file that accompanied this code.
duke@0 10 *
duke@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 15 * accompanied this code).
duke@0 16 *
duke@0 17 * You should have received a copy of the GNU General Public License version
duke@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 20 *
duke@0 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 23 * have any questions.
duke@0 24 */
duke@0 25
duke@0 26 #include <assert.h>
duke@0 27 #include <sys/types.h>
duke@0 28 #include <sys/time.h>
duke@0 29 #include <sys/stat.h>
duke@0 30 #include <sys/statvfs.h>
duke@0 31 #include <string.h>
duke@0 32 #include <stdlib.h>
duke@0 33 #include <dlfcn.h>
duke@0 34 #include <limits.h>
duke@0 35
duke@0 36 #include "jni.h"
duke@0 37 #include "jni_util.h"
duke@0 38 #include "jlong.h"
duke@0 39 #include "jvm.h"
duke@0 40 #include "io_util.h"
duke@0 41 #include "java_io_FileSystem.h"
duke@0 42 #include "java_io_UnixFileSystem.h"
duke@0 43
duke@0 44
duke@0 45 /* -- Field IDs -- */
duke@0 46
duke@0 47 static struct {
duke@0 48 jfieldID path;
duke@0 49 } ids;
duke@0 50
duke@0 51
duke@0 52 JNIEXPORT void JNICALL
duke@0 53 Java_java_io_UnixFileSystem_initIDs(JNIEnv *env, jclass cls)
duke@0 54 {
duke@0 55 jclass fileClass = (*env)->FindClass(env, "java/io/File");
duke@0 56 if (!fileClass) return;
duke@0 57 ids.path = (*env)->GetFieldID(env, fileClass,
duke@0 58 "path", "Ljava/lang/String;");
duke@0 59 }
duke@0 60
duke@0 61
duke@0 62 /* -- Large-file support -- */
duke@0 63
duke@0 64 /* LINUX_FIXME: ifdef __solaris__ here is wrong. We need to move the
duke@0 65 * definition of stat64 into a solaris_largefile.h and create a
duke@0 66 * linux_largefile.h with a good stat64 structure to compile on
duke@0 67 * glibc2.0 based systems.
duke@0 68 */
duke@0 69 #if defined(__solaris__) && !defined(_LFS_LARGEFILE) || !_LFS_LARGEFILE
duke@0 70
duke@0 71 /* The stat64 structure must be provided for systems without large-file support
duke@0 72 (e.g., Solaris 2.5.1). These definitions are copied from the Solaris 2.6
duke@0 73 <sys/stat.h> and <sys/types.h> files.
duke@0 74 */
duke@0 75
duke@0 76 typedef longlong_t off64_t; /* offsets within files */
duke@0 77 typedef u_longlong_t ino64_t; /* expanded inode type */
duke@0 78 typedef longlong_t blkcnt64_t; /* count of file blocks */
duke@0 79
duke@0 80 struct stat64 {
duke@0 81 dev_t st_dev;
duke@0 82 long st_pad1[3];
duke@0 83 ino64_t st_ino;
duke@0 84 mode_t st_mode;
duke@0 85 nlink_t st_nlink;
duke@0 86 uid_t st_uid;
duke@0 87 gid_t st_gid;
duke@0 88 dev_t st_rdev;
duke@0 89 long st_pad2[2];
duke@0 90 off64_t st_size;
duke@0 91 timestruc_t st_atim;
duke@0 92 timestruc_t st_mtim;
duke@0 93 timestruc_t st_ctim;
duke@0 94 long st_blksize;
duke@0 95 blkcnt64_t st_blocks;
duke@0 96 char st_fstype[_ST_FSTYPSZ];
duke@0 97 long st_pad4[8];
duke@0 98 };
duke@0 99
duke@0 100 #endif /* !_LFS_LARGEFILE */
duke@0 101
duke@0 102 typedef int (*STAT64)(const char *, struct stat64 *);
duke@0 103
duke@0 104 #if defined(__linux__) && defined(_LARGEFILE64_SOURCE)
duke@0 105 static STAT64 stat64_ptr = &stat64;
duke@0 106 #else
duke@0 107 static STAT64 stat64_ptr = NULL;
duke@0 108 #endif
duke@0 109
duke@0 110 #ifndef __linux__
duke@0 111 #ifdef __GNUC__
duke@0 112 static void init64IO(void) __attribute__((constructor));
duke@0 113 #else
duke@0 114 #pragma init(init64IO)
duke@0 115 #endif
duke@0 116 #endif
duke@0 117
duke@0 118 static void init64IO(void) {
duke@0 119 void *handle = dlopen(0, RTLD_LAZY);
duke@0 120 stat64_ptr = (STAT64) dlsym(handle, "_stat64");
duke@0 121 dlclose(handle);
duke@0 122 }
duke@0 123
duke@0 124
duke@0 125 /* -- Path operations -- */
duke@0 126
duke@0 127 extern int canonicalize(char *path, const char *out, int len);
duke@0 128
duke@0 129 JNIEXPORT jstring JNICALL
duke@0 130 Java_java_io_UnixFileSystem_canonicalize0(JNIEnv *env, jobject this,
duke@0 131 jstring pathname)
duke@0 132 {
duke@0 133 jstring rv = NULL;
duke@0 134
duke@0 135 WITH_PLATFORM_STRING(env, pathname, path) {
duke@0 136 char canonicalPath[JVM_MAXPATHLEN];
duke@0 137 if (canonicalize(JVM_NativePath((char *)path),
duke@0 138 canonicalPath, JVM_MAXPATHLEN) < 0) {
duke@0 139 JNU_ThrowIOExceptionWithLastError(env, "Bad pathname");
duke@0 140 } else {
duke@0 141 rv = JNU_NewStringPlatform(env, canonicalPath);
duke@0 142 }
duke@0 143 } END_PLATFORM_STRING(env, path);
duke@0 144 return rv;
duke@0 145 }
duke@0 146
duke@0 147
duke@0 148 /* -- Attribute accessors -- */
duke@0 149
duke@0 150
duke@0 151 static jboolean
duke@0 152 statMode(const char *path, int *mode)
duke@0 153 {
duke@0 154 if (stat64_ptr) {
duke@0 155 struct stat64 sb;
duke@0 156 if (((*stat64_ptr)(path, &sb)) == 0) {
duke@0 157 *mode = sb.st_mode;
duke@0 158 return JNI_TRUE;
duke@0 159 }
duke@0 160 } else {
duke@0 161 struct stat sb;
duke@0 162 if (stat(path, &sb) == 0) {
duke@0 163 *mode = sb.st_mode;
duke@0 164 return JNI_TRUE;
duke@0 165 }
duke@0 166 }
duke@0 167 return JNI_FALSE;
duke@0 168 }
duke@0 169
duke@0 170
duke@0 171 JNIEXPORT jint JNICALL
duke@0 172 Java_java_io_UnixFileSystem_getBooleanAttributes0(JNIEnv *env, jobject this,
duke@0 173 jobject file)
duke@0 174 {
duke@0 175 jint rv = 0;
duke@0 176
duke@0 177 WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
duke@0 178 int mode;
duke@0 179 if (statMode(path, &mode)) {
duke@0 180 int fmt = mode & S_IFMT;
duke@0 181 rv = (jint) (java_io_FileSystem_BA_EXISTS
duke@0 182 | ((fmt == S_IFREG) ? java_io_FileSystem_BA_REGULAR : 0)
duke@0 183 | ((fmt == S_IFDIR) ? java_io_FileSystem_BA_DIRECTORY : 0));
duke@0 184 }
duke@0 185 } END_PLATFORM_STRING(env, path);
duke@0 186 return rv;
duke@0 187 }
duke@0 188
duke@0 189 JNIEXPORT jboolean JNICALL
duke@0 190 Java_java_io_UnixFileSystem_checkAccess(JNIEnv *env, jobject this,
duke@0 191 jobject file, jint a)
duke@0 192 {
duke@0 193 jboolean rv = JNI_FALSE;
duke@0 194 int mode;
duke@0 195 switch (a) {
duke@0 196 case java_io_FileSystem_ACCESS_READ:
duke@0 197 mode = R_OK;
duke@0 198 break;
duke@0 199 case java_io_FileSystem_ACCESS_WRITE:
duke@0 200 mode = W_OK;
duke@0 201 break;
duke@0 202 case java_io_FileSystem_ACCESS_EXECUTE:
duke@0 203 mode = X_OK;
duke@0 204 break;
duke@0 205 default: assert(0);
duke@0 206 }
duke@0 207 WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
duke@0 208 if (access(path, mode) == 0) {
duke@0 209 rv = JNI_TRUE;
duke@0 210 }
duke@0 211 } END_PLATFORM_STRING(env, path);
duke@0 212 return rv;
duke@0 213 }
duke@0 214
duke@0 215
duke@0 216 JNIEXPORT jboolean JNICALL
duke@0 217 Java_java_io_UnixFileSystem_setPermission(JNIEnv *env, jobject this,
duke@0 218 jobject file,
duke@0 219 jint access,
duke@0 220 jboolean enable,
duke@0 221 jboolean owneronly)
duke@0 222 {
duke@0 223 jboolean rv = JNI_FALSE;
duke@0 224
duke@0 225 WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
duke@0 226 int amode, mode;
duke@0 227 switch (access) {
duke@0 228 case java_io_FileSystem_ACCESS_READ:
duke@0 229 if (owneronly)
duke@0 230 amode = S_IRUSR;
duke@0 231 else
duke@0 232 amode = S_IRUSR | S_IRGRP | S_IROTH;
duke@0 233 break;
duke@0 234 case java_io_FileSystem_ACCESS_WRITE:
duke@0 235 if (owneronly)
duke@0 236 amode = S_IWUSR;
duke@0 237 else
duke@0 238 amode = S_IWUSR | S_IWGRP | S_IWOTH;
duke@0 239 break;
duke@0 240 case java_io_FileSystem_ACCESS_EXECUTE:
duke@0 241 if (owneronly)
duke@0 242 amode = S_IXUSR;
duke@0 243 else
duke@0 244 amode = S_IXUSR | S_IXGRP | S_IXOTH;
duke@0 245 break;
duke@0 246 default:
duke@0 247 assert(0);
duke@0 248 }
duke@0 249 if (statMode(path, &mode)) {
duke@0 250 if (enable)
duke@0 251 mode |= amode;
duke@0 252 else
duke@0 253 mode &= ~amode;
duke@0 254 if (chmod(path, mode) >= 0) {
duke@0 255 rv = JNI_TRUE;
duke@0 256 }
duke@0 257 }
duke@0 258 } END_PLATFORM_STRING(env, path);
duke@0 259 return rv;
duke@0 260 }
duke@0 261
duke@0 262 JNIEXPORT jlong JNICALL
duke@0 263 Java_java_io_UnixFileSystem_getLastModifiedTime(JNIEnv *env, jobject this,
duke@0 264 jobject file)
duke@0 265 {
duke@0 266 jlong rv = 0;
duke@0 267
duke@0 268 WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
duke@0 269 if (stat64_ptr) {
duke@0 270 struct stat64 sb;
duke@0 271 if (((*stat64_ptr)(path, &sb)) == 0) {
duke@0 272 rv = 1000 * (jlong)sb.st_mtime;
duke@0 273 }
duke@0 274 } else {
duke@0 275 struct stat sb;
duke@0 276 if (stat(path, &sb) == 0) {
duke@0 277 rv = 1000 * (jlong)sb.st_mtime;
duke@0 278 }
duke@0 279 }
duke@0 280 } END_PLATFORM_STRING(env, path);
duke@0 281 return rv;
duke@0 282 }
duke@0 283
duke@0 284
duke@0 285 JNIEXPORT jlong JNICALL
duke@0 286 Java_java_io_UnixFileSystem_getLength(JNIEnv *env, jobject this,
duke@0 287 jobject file)
duke@0 288 {
duke@0 289 jlong rv = 0;
duke@0 290
duke@0 291 WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
duke@0 292 if (stat64_ptr) {
duke@0 293 struct stat64 sb;
duke@0 294 if (((*stat64_ptr)(path, &sb)) == 0) {
duke@0 295 rv = sb.st_size;
duke@0 296 }
duke@0 297 } else {
duke@0 298 struct stat sb;
duke@0 299 if (stat(path, &sb) == 0) {
duke@0 300 rv = sb.st_size;
duke@0 301 }
duke@0 302 }
duke@0 303 } END_PLATFORM_STRING(env, path);
duke@0 304 return rv;
duke@0 305 }
duke@0 306
duke@0 307
duke@0 308 /* -- File operations -- */
duke@0 309
duke@0 310
duke@0 311 JNIEXPORT jboolean JNICALL
duke@0 312 Java_java_io_UnixFileSystem_createFileExclusively(JNIEnv *env, jclass cls,
duke@0 313 jstring pathname)
duke@0 314 {
duke@0 315 jboolean rv = JNI_FALSE;
duke@0 316
duke@0 317 WITH_PLATFORM_STRING(env, pathname, path) {
duke@0 318 int fd;
duke@0 319 if (!strcmp (path, "/")) {
duke@0 320 fd = JVM_EEXIST; /* The root directory always exists */
duke@0 321 } else {
duke@0 322 fd = JVM_Open(path, JVM_O_RDWR | JVM_O_CREAT | JVM_O_EXCL, 0666);
duke@0 323 }
duke@0 324 if (fd < 0) {
duke@0 325 if (fd != JVM_EEXIST) {
duke@0 326 JNU_ThrowIOExceptionWithLastError(env, path);
duke@0 327 }
duke@0 328 } else {
duke@0 329 JVM_Close(fd);
duke@0 330 rv = JNI_TRUE;
duke@0 331 }
duke@0 332 } END_PLATFORM_STRING(env, path);
duke@0 333 return rv;
duke@0 334 }
duke@0 335
duke@0 336
duke@0 337 JNIEXPORT jboolean JNICALL
duke@0 338 Java_java_io_UnixFileSystem_delete0(JNIEnv *env, jobject this,
duke@0 339 jobject file)
duke@0 340 {
duke@0 341 jboolean rv = JNI_FALSE;
duke@0 342
duke@0 343 WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
duke@0 344 if (remove(path) == 0) {
duke@0 345 rv = JNI_TRUE;
duke@0 346 }
duke@0 347 } END_PLATFORM_STRING(env, path);
duke@0 348 return rv;
duke@0 349 }
duke@0 350
duke@0 351
duke@0 352 JNIEXPORT jobjectArray JNICALL
duke@0 353 Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
duke@0 354 jobject file)
duke@0 355 {
duke@0 356 DIR *dir = NULL;
duke@0 357 struct dirent64 *ptr;
duke@0 358 struct dirent64 *result;
duke@0 359 int len, maxlen;
duke@0 360 jobjectArray rv, old;
duke@0 361
duke@0 362 WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
duke@0 363 dir = opendir(path);
duke@0 364 } END_PLATFORM_STRING(env, path);
duke@0 365 if (dir == NULL) return NULL;
duke@0 366
duke@0 367 ptr = malloc(sizeof(struct dirent64) + (PATH_MAX + 1));
duke@0 368 if (ptr == NULL) {
duke@0 369 JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
duke@0 370 closedir(dir);
duke@0 371 return NULL;
duke@0 372 }
duke@0 373
duke@0 374 /* Allocate an initial String array */
duke@0 375 len = 0;
duke@0 376 maxlen = 16;
duke@0 377 rv = (*env)->NewObjectArray(env, maxlen, JNU_ClassString(env), NULL);
duke@0 378 if (rv == NULL) goto error;
duke@0 379
duke@0 380 /* Scan the directory */
duke@0 381 while ((readdir64_r(dir, ptr, &result) == 0) && (result != NULL)) {
duke@0 382 jstring name;
duke@0 383 if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, ".."))
duke@0 384 continue;
duke@0 385 if (len == maxlen) {
duke@0 386 old = rv;
duke@0 387 rv = (*env)->NewObjectArray(env, maxlen <<= 1,
duke@0 388 JNU_ClassString(env), NULL);
duke@0 389 if (rv == NULL) goto error;
duke@0 390 if (JNU_CopyObjectArray(env, rv, old, len) < 0) goto error;
duke@0 391 (*env)->DeleteLocalRef(env, old);
duke@0 392 }
duke@0 393 name = JNU_NewStringPlatform(env, ptr->d_name);
duke@0 394 if (name == NULL) goto error;
duke@0 395 (*env)->SetObjectArrayElement(env, rv, len++, name);
duke@0 396 (*env)->DeleteLocalRef(env, name);
duke@0 397 }
duke@0 398 closedir(dir);
duke@0 399 free(ptr);
duke@0 400
duke@0 401 /* Copy the final results into an appropriately-sized array */
duke@0 402 old = rv;
duke@0 403 rv = (*env)->NewObjectArray(env, len, JNU_ClassString(env), NULL);
duke@0 404 if (rv == NULL) {
duke@0 405 return NULL;
duke@0 406 }
duke@0 407 if (JNU_CopyObjectArray(env, rv, old, len) < 0) {
duke@0 408 return NULL;
duke@0 409 }
duke@0 410 return rv;
duke@0 411
duke@0 412 error:
duke@0 413 closedir(dir);
duke@0 414 free(ptr);
duke@0 415 return NULL;
duke@0 416 }
duke@0 417
duke@0 418
duke@0 419 JNIEXPORT jboolean JNICALL
duke@0 420 Java_java_io_UnixFileSystem_createDirectory(JNIEnv *env, jobject this,
duke@0 421 jobject file)
duke@0 422 {
duke@0 423 jboolean rv = JNI_FALSE;
duke@0 424
duke@0 425 WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
duke@0 426 if (mkdir(path, 0777) == 0) {
duke@0 427 rv = JNI_TRUE;
duke@0 428 }
duke@0 429 } END_PLATFORM_STRING(env, path);
duke@0 430 return rv;
duke@0 431 }
duke@0 432
duke@0 433
duke@0 434 JNIEXPORT jboolean JNICALL
duke@0 435 Java_java_io_UnixFileSystem_rename0(JNIEnv *env, jobject this,
duke@0 436 jobject from, jobject to)
duke@0 437 {
duke@0 438 jboolean rv = JNI_FALSE;
duke@0 439
duke@0 440 WITH_FIELD_PLATFORM_STRING(env, from, ids.path, fromPath) {
duke@0 441 WITH_FIELD_PLATFORM_STRING(env, to, ids.path, toPath) {
duke@0 442 if (rename(fromPath, toPath) == 0) {
duke@0 443 rv = JNI_TRUE;
duke@0 444 }
duke@0 445 } END_PLATFORM_STRING(env, toPath);
duke@0 446 } END_PLATFORM_STRING(env, fromPath);
duke@0 447 return rv;
duke@0 448 }
duke@0 449
duke@0 450
duke@0 451 /* Bug in solaris /usr/include/sys/time.h? */
duke@0 452 #ifdef __solaris__
duke@0 453 extern int utimes(const char *, const struct timeval *);
duke@0 454 #elif defined(__linux___)
duke@0 455 extern int utimes(const char *, struct timeval *);
duke@0 456 #endif
duke@0 457
duke@0 458
duke@0 459 JNIEXPORT jboolean JNICALL
duke@0 460 Java_java_io_UnixFileSystem_setLastModifiedTime(JNIEnv *env, jobject this,
duke@0 461 jobject file, jlong time)
duke@0 462 {
duke@0 463 jboolean rv = JNI_FALSE;
duke@0 464
duke@0 465 WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
duke@0 466 struct timeval tv[2];
duke@0 467 #ifdef __solaris__
duke@0 468 timestruc_t ts;
duke@0 469
duke@0 470 if (stat64_ptr) {
duke@0 471 struct stat64 sb;
duke@0 472 if (((*stat64_ptr)(path, &sb)) == 0)
duke@0 473 ts = sb.st_atim;
duke@0 474 else
duke@0 475 goto error;
duke@0 476 } else {
duke@0 477 struct stat sb;
duke@0 478 if (stat(path, &sb) == 0)
duke@0 479 ts = sb.st_atim;
duke@0 480 else
duke@0 481 goto error;
duke@0 482 }
duke@0 483 #endif
duke@0 484
duke@0 485 /* Preserve access time */
duke@0 486 #ifdef __linux__
duke@0 487 struct stat sb;
duke@0 488
duke@0 489 if (stat(path, &sb) == 0) {
duke@0 490
duke@0 491 tv[0].tv_sec = sb.st_atime;
duke@0 492 tv[0].tv_usec = 0;
duke@0 493 }
duke@0 494 #else
duke@0 495 tv[0].tv_sec = ts.tv_sec;
duke@0 496 tv[0].tv_usec = ts.tv_nsec / 1000;
duke@0 497 #endif
duke@0 498
duke@0 499 /* Change last-modified time */
duke@0 500 tv[1].tv_sec = time / 1000;
duke@0 501 tv[1].tv_usec = (time % 1000) * 1000;
duke@0 502
duke@0 503 if (utimes(path, tv) >= 0)
duke@0 504 rv = JNI_TRUE;
duke@0 505
duke@0 506 error: ;
duke@0 507 } END_PLATFORM_STRING(env, path);
duke@0 508
duke@0 509 return rv;
duke@0 510 }
duke@0 511
duke@0 512
duke@0 513 JNIEXPORT jboolean JNICALL
duke@0 514 Java_java_io_UnixFileSystem_setReadOnly(JNIEnv *env, jobject this,
duke@0 515 jobject file)
duke@0 516 {
duke@0 517 jboolean rv = JNI_FALSE;
duke@0 518
duke@0 519 WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
duke@0 520 int mode;
duke@0 521 if (statMode(path, &mode)) {
duke@0 522 if (chmod(path, mode & ~(S_IWUSR | S_IWGRP | S_IWOTH)) >= 0) {
duke@0 523 rv = JNI_TRUE;
duke@0 524 }
duke@0 525 }
duke@0 526 } END_PLATFORM_STRING(env, path);
duke@0 527 return rv;
duke@0 528 }
duke@0 529
duke@0 530 JNIEXPORT jlong JNICALL
duke@0 531 Java_java_io_UnixFileSystem_getSpace(JNIEnv *env, jobject this,
duke@0 532 jobject file, jint t)
duke@0 533 {
duke@0 534 jlong rv = 0L;
duke@0 535
duke@0 536 WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
duke@0 537 struct statvfs fsstat;
duke@0 538 memset(&fsstat, 0, sizeof(struct statvfs));
duke@0 539 if (statvfs(path, &fsstat) == 0) {
duke@0 540 switch(t) {
duke@0 541 case java_io_FileSystem_SPACE_TOTAL:
duke@0 542 rv = jlong_mul(long_to_jlong(fsstat.f_frsize),
duke@0 543 long_to_jlong(fsstat.f_blocks));
duke@0 544 break;
duke@0 545 case java_io_FileSystem_SPACE_FREE:
duke@0 546 rv = jlong_mul(long_to_jlong(fsstat.f_frsize),
duke@0 547 long_to_jlong(fsstat.f_bfree));
duke@0 548 break;
duke@0 549 case java_io_FileSystem_SPACE_USABLE:
duke@0 550 rv = jlong_mul(long_to_jlong(fsstat.f_frsize),
duke@0 551 long_to_jlong(fsstat.f_bavail));
duke@0 552 break;
duke@0 553 default:
duke@0 554 assert(0);
duke@0 555 }
duke@0 556 }
duke@0 557 } END_PLATFORM_STRING(env, path);
duke@0 558 return rv;
duke@0 559 }