Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the "current" in Linux kernel source?

I'm studying about Linux kernel and I have a problem.

I see many Linux kernel source files have current->files. So what is the current?

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;
 }
like image 735
Kahn Cse Avatar asked Sep 15 '12 04:09

Kahn Cse


People also ask

What is current Linux kernel?

The current pointer refers to the user process currently executing. During the execution of a system call, such as open or read, the current process is the one that invoked the call. Kernel code can use process-specific information by using current, if it needs to do so.

What is the most current Linux kernel version?

The Linux kernel 5.7 is finally here as the latest stable version of kernel for Unix-like operating systems. The new kernel comes with many significant updates and new features.

How big is the Linux kernel source?

The Linux kernel has around 27.8 million lines of code in its Git repository, up from 26.1 million a year ago, while systemd now has nearly 1.3 million lines of code, according to GitHub stats analysed by Michael Larabel at Phoronix.

Where are Linux kernel sources?

After installation, the kernel sources are located in /usr/src/linux-<kernel-version>. If you plan to experiment with different kernels, unpack them in different subdirectories and create a symbolic link to the current kernel source.


2 Answers

It's a pointer to the current process (i.e. the process that issued the system call).

On x86, it's defined in arch/x86/include/asm/current.h (similar files for other archs).

#ifndef _ASM_X86_CURRENT_H #define _ASM_X86_CURRENT_H  #include <linux/compiler.h> #include <asm/percpu.h>  #ifndef __ASSEMBLY__ struct task_struct;  DECLARE_PER_CPU(struct task_struct *, current_task);  static __always_inline struct task_struct *get_current(void) {     return percpu_read_stable(current_task); }  #define current get_current()  #endif /* __ASSEMBLY__ */  #endif /* _ASM_X86_CURRENT_H */ 

More information in Linux Device Drivers chapter 2:

The current pointer refers to the user process currently executing. During the execution of a system call, such as open or read, the current process is the one that invoked the call. Kernel code can use process-specific information by using current, if it needs to do so. [...]

like image 161
Mat Avatar answered Oct 10 '22 05:10

Mat


Current is a global variable of type struct task_struct. You can find it's definition at [1].

Files is a struct files_struct and it contains information of the files used by the current process.

[1] http://students.mimuw.edu.pl/SO/LabLinux/PROCESY/ZRODLA/sched.h.html

like image 37
coredump Avatar answered Oct 10 '22 06:10

coredump