2012-09-15 5 views
11

나는 리눅스 커널에 대해 공부에서 "현재"무엇이며, 전류 -> 파일이 나는는 리눅스 커널 소스

내가 많은 리눅스 커널 소스 파일을 볼 문제가 있습니다. 그래서 "현재"는 무엇입니까?

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; 
} 
+0

예? 'current'는 정말로 일반적인 변수 이름입니다. – nneonneo

답변

20

이것은 현재 프로세스 (즉, 시스템 호출을 실행 한 프로세스)에 대한 포인터입니다.

x86의 경우 arch/x86/include/current.h (다른 아치의 경우 유사한 파일)에 정의되어 있습니다. Linux Device Drivers 제 2

#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 */ 

추가 정보 :

현재 포인터는 현재 실행중인 프로세스의 사용자를 의미한다. 열기 또는 읽기와 같은 시스템 호출의 실행 중 현재 프로세스는 호출을 호출 한 프로세스입니다. 커널 코드는 필요한 경우 현재를 사용하여 프로세스 특정 정보를 사용할 수 있습니다. [...]

0

struct task_struct의 전역 변수입니다. [1]에서 그 정의를 찾을 수 있습니다.

Filesstruct files_struct이며 현재 프로세스에서 사용되는 파일의 정보를 포함합니다.

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

+0

'current'는 변수가 아니라'struct task_struct *'를 반환하는 함수에 대한'#define'입니다. – Quaker