我正在使用 sun.nio.ch.FileChannelImpl.read
在我的 java 项目中读取 Linux 环境中的文件,我在我的一个环境中遇到权限被拒绝的情况,该文件已读取每个人都有/write/execute 权限,但在我的环境中,我们有严格的策略来允许某些命令,因此我需要找出此方法使用哪些命令在我的计算机上启用此命令。
为了找到命令,我跟踪了代码,直到我遇到了里面的一些 native 方法
sun.nio.ch.FileDispatcherImpl
方法是
static native int read0(FileDescriptor fd, long address, int len)
throws IOException;
我跟踪了一下,发现明显是用C写的实现,你可以在这个link中找到它
native 实现是
JNIEXPORT jint JNICALL
Java_sun_nio_ch_FileDispatcherImpl_read0(JNIEnv *env, jclass clazz,
jobject fdo, jlong address, jint len)
{
jint fd = fdval(env, fdo);
void *buf = (void *)jlong_to_ptr(address);
return convertReturnVal(env, read(fd, buf, len), JNI_TRUE);
}
现在我需要打开 read 函数来弄清楚它到底做了什么,但我无法找到实现,甚至无法找到声明该函数的头文件(在包含的头文件之后)
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "jlong.h"
#include "sun_nio_ch_FileDispatcherImpl.h"
#include "java_lang_Long.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <unistd.h>
#if defined(__linux__)
#include <linux/fs.h>
#include <sys/ioctl.h>
#endif
#include "nio.h"
#include "nio_util.h"
感谢任何帮助。
最佳答案
read()
是 POSIX standard function从打开的文件描述符中读取。如果动态链接,它通常由您的系统 libc.so
提供;如果静态链接,则通常由 libc.a
提供。
可以在此处找到一个实现:https://www.gnu.org/software/libc/
关于java - 找不到 sun.nio.ch.FileChannelImpl.read 的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49793324/