小编Kah*_*Cse的帖子

linux内核源代码中的"当前"是什么

我正在研究Linux内核,我遇到了问题

我看到很多linux内核源文件都有current-> files.那么"当前"是什么?

struct file *fget(unsigned int fd)
{
     struct file *file;
     struct files_struct *files = current->files;

     rcu_read_lock();
     file = fcheck_files(files, fd);
     if (file) {
             /* File object ref couldn't be taken */
             if (file->f_mode & FMODE_PATH ||
                 !atomic_long_inc_not_zero(&file->f_count))
                     file = NULL;
     }
     rcu_read_unlock();

     return file;
 }
Run Code Online (Sandbox Code Playgroud)

linux kernel linux-kernel

23
推荐指数
1
解决办法
3万
查看次数

Linux中的fget_light有什么用?

我正在研究Linux中的系统调用,我读了read()系统调用.

SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
{
    struct file *file;
    ssize_t ret = -EBADF;
    int fput_needed;

    file = fget_light(fd, &fput_needed);
    if (file) {
        loff_t pos = file_pos_read(file);
        ret = vfs_read(file, buf, count, &pos);
        file_pos_write(file, pos);
        fput_light(file, fput_needed);
    }

    return ret;
}
Run Code Online (Sandbox Code Playgroud)

这是fget_light()的定义

struct file *fget_light(unsigned int fd, int *fput_needed)
 {
         struct file *file;
         struct files_struct *files = current->files;

         *fput_needed = 0;
         if (likely((atomic_read(&files->count) == 1))) {
                 file = fcheck_files(files, fd);
         } else {
                 rcu_read_lock();
                 file …
Run Code Online (Sandbox Code Playgroud)

linux system-calls

1
推荐指数
1
解决办法
3785
查看次数

标签 统计

linux ×2

kernel ×1

linux-kernel ×1

system-calls ×1