comparison src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c @ 5299:37377dcd43d0

7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code Reviewed-by: andrew
author alanb
date Thu, 16 Aug 2012 11:14:42 +0100
parents a18d0a3ac45b
children fd940a08ec2d
comparison
equal deleted inserted replaced
9:5f044387106d 10:64f612cc2ddc
38 #include <sys/statvfs.h> 38 #include <sys/statvfs.h>
39 #include <sys/time.h> 39 #include <sys/time.h>
40 40
41 #ifdef __solaris__ 41 #ifdef __solaris__
42 #include <strings.h> 42 #include <strings.h>
43 #include <sys/mnttab.h>
44 #include <sys/mkdev.h>
45 #endif 43 #endif
46 44
47 #ifdef __linux__ 45 #ifdef __linux__
48 #include <string.h> 46 #include <string.h>
49 #include <mntent.h>
50 #endif 47 #endif
51 48
52 #ifdef _ALLBSD_SOURCE 49 #ifdef _ALLBSD_SOURCE
53 #include <string.h> 50 #include <string.h>
54 51
1081 1078
1082 } while (retry); 1079 } while (retry);
1083 1080
1084 return gid; 1081 return gid;
1085 } 1082 }
1086
1087 JNIEXPORT jint JNICALL
1088 Java_sun_nio_fs_UnixNativeDispatcher_getextmntent(JNIEnv* env, jclass this,
1089 jlong value, jobject entry)
1090 {
1091 #ifdef __solaris__
1092 struct extmnttab ent;
1093 #elif defined(_ALLBSD_SOURCE)
1094 char buf[1024];
1095 char *str;
1096 char *last;
1097 #else
1098 struct mntent ent;
1099 char buf[1024];
1100 int buflen = sizeof(buf);
1101 struct mntent* m;
1102 #endif
1103 FILE* fp = jlong_to_ptr(value);
1104 jsize len;
1105 jbyteArray bytes;
1106 char* name;
1107 char* dir;
1108 char* fstype;
1109 char* options;
1110 dev_t dev;
1111
1112 #ifdef __solaris__
1113 if (getextmntent(fp, &ent, 0))
1114 return -1;
1115 name = ent.mnt_special;
1116 dir = ent.mnt_mountp;
1117 fstype = ent.mnt_fstype;
1118 options = ent.mnt_mntopts;
1119 dev = makedev(ent.mnt_major, ent.mnt_minor);
1120 if (dev == NODEV) {
1121 /* possible bug on Solaris 8 and 9 */
1122 throwUnixException(env, errno);
1123 return -1;
1124 }
1125 #elif defined(_ALLBSD_SOURCE)
1126 again:
1127 if (!(str = fgets(buf, sizeof(buf), fp)))
1128 return -1;
1129
1130 name = strtok_r(str, " \t\n", &last);
1131 if (name == NULL)
1132 return -1;
1133
1134 // skip comments
1135 if (*name == '#')
1136 goto again;
1137
1138 dir = strtok_r((char *)NULL, " \t\n", &last);
1139 fstype = strtok_r((char *)NULL, " \t\n", &last);
1140 options = strtok_r((char *)NULL, " \t\n", &last);
1141 if (options == NULL)
1142 return -1;
1143 dev = 0;
1144 #else
1145 m = getmntent_r(fp, &ent, (char*)&buf, buflen);
1146 if (m == NULL)
1147 return -1;
1148 name = m->mnt_fsname;
1149 dir = m->mnt_dir;
1150 fstype = m->mnt_type;
1151 options = m->mnt_opts;
1152 dev = 0;
1153 #endif
1154
1155 len = strlen(name);
1156 bytes = (*env)->NewByteArray(env, len);
1157 if (bytes == NULL)
1158 return -1;
1159 (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)name);
1160 (*env)->SetObjectField(env, entry, entry_name, bytes);
1161
1162 len = strlen(dir);
1163 bytes = (*env)->NewByteArray(env, len);
1164 if (bytes == NULL)
1165 return -1;
1166 (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)dir);
1167 (*env)->SetObjectField(env, entry, entry_dir, bytes);
1168
1169 len = strlen(fstype);
1170 bytes = (*env)->NewByteArray(env, len);
1171 if (bytes == NULL)
1172 return -1;
1173 (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)fstype);
1174 (*env)->SetObjectField(env, entry, entry_fstype, bytes);
1175
1176 len = strlen(options);
1177 bytes = (*env)->NewByteArray(env, len);
1178 if (bytes == NULL)
1179 return -1;
1180 (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)options);
1181 (*env)->SetObjectField(env, entry, entry_options, bytes);
1182
1183 if (dev != 0)
1184 (*env)->SetLongField(env, entry, entry_dev, (jlong)dev);
1185
1186 return 0;
1187 }