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;
}
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/current.h
(similar files for other archs).More information in Linux Device Drivers chapter 2:
Current
is a global variable of typestruct task_struct
. You can find it's definition at [1].Files
is astruct 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