fsetxattr got errno 95

300 views
Skip to first unread message

chenqi...@gmail.com

unread,
Nov 27, 2023, 2:37:59 PM11/27/23
to android-ndk
When I call fsetxattr on InternalStorage file, it works
but on AdoptableStorage file (my be externalStorage? connect by usb),  get errno 95


Here art my code
java side 
// File testFile = new File("/data/data/Android/data/com.xxx.xxx/files/test_attr.txt");
File testFile = new File("/storage/80E9-8A2E/Android/data/com.xxx.xxx/files/test_attr.txt");
testFile.createNewFile();
FileInputStream fis = new FileInputStream(testFile);
FileDescriptor fd = fis.getFD();
Field descriptor = ReflectionUtils.getDeclaredField(FileDescriptor.class, "descriptor");
descriptor.setAccessible(true);
int descriptorInt = (int) descriptor.get(fd);
Logger.info("testattr fd " + descriptorInt);
String setAttrRet = testSetAttr(descriptorInt);
Logger.info("testattr setAttrRet " + setAttrRet);
String getAttrRet = testGetAttr(descriptorInt);
Logger.info("testattr getAttrRet " + getAttrRet);

cpp side
jstring testSetAttr(JNIEnv *env, jclass clazz, jint fd) {
int ret = fsetxattr(fd, "user.test", "testjni", 8, XATTR_CREATE);
std::string str = std::to_string(ret);
LOGI("testSetAttr ret=%d", errno);
return env->NewStringUTF(str.c_str());
}
jstring testGetAttr(JNIEnv *env, jclass clazz, jint fd) {
char buf[1024];
int ret = fgetxattr(fd, "user.test", buf, 1024);
std::string str = std::string(buf, ret);
return env->NewStringUTF(str.c_str());
}





enh

unread,
Nov 27, 2023, 2:52:21 PM11/27/23
to andro...@googlegroups.com
yes, that's WAI. all will be clear if you use strerror(3) to turn that
errno value into the corresponding error string...

(which is what you should have done in the first place --- you never
want to log errno _integers_ because they aren't all the same for all
architectures. Android supports %m in format strings for this since
API level 29. API level 35 will add strerrorname_np() and
strerrordesc_np().
https://android.googlesource.com/platform/bionic/+/HEAD/docs/status.md)
> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/a7db8d7d-9ae5-4c52-a88b-35316b89e164n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages