java - 找不到 sun.nio.ch.FileChannelImpl.read 的实现

标签 java c

我正在使用 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/

相关文章:

c - 如何在 C 中生成对数间隔数组

声明日志文件路径时出现 java.io.IOException

java - Spring Boot 测试 - 没有 'com.example.MyService' 类型的合格 bean 可用

Java CodingBat 数组列表

java - 如何使用 Spark 的路由提供 json 服务?

c - 用 c 解析 csv

c - 为什么 more 命令不使用 stdin 来读取输入?

java - 视频聊天应用程序

c++ - 如何判断是否为 PE Win32 启用了 GS 编译器

c++ - 赋值 char ** 到 char * 中的类型不兼容