한국어
Linux Programming
 

file_operations

makersweb 2014.02.27 14:52 조회 수 : 3284

file_operations

 

개요

  • 문자 디바이스 드라이버와 응용 프로그램을 연결하는 고리.
  • linux/fs.h에서 정의하는 이구조체는 함수 포인터 집합이다.
  • 지정하지 않으면 NULL로 남겨 두어야 한다.
  • 커널 2.6에서는 비동기 처리를 위한 필드 등이 늘어 났다.

 

/*
 * NOTE:
 * read, write, poll, fsync, readv, writev can be called
 *   without the big kernel lock held in all filesystems.
 */
struct file_operations {
	struct module *owner;
	loff_t (*llseek) (struct file *, loff_t, int);
	ssize_t (*read) (struct file *, char *, size_t, loff_t *);
	ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
	int (*readdir) (struct file *, void *, filldir_t);
	unsigned int (*poll) (struct file *, struct poll_table_struct *);
	int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
	int (*mmap) (struct file *, struct vm_area_struct *);
	int (*open) (struct inode *, struct file *);
	int (*flush) (struct file *);
	int (*release) (struct inode *, struct file *);
	int (*fsync) (struct file *, struct dentry *, int datasync);
	int (*fasync) (int, struct file *, int);
	int (*lock) (struct file *, int, struct file_lock *);
	ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
	ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
	ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
	unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
};


*참고 : 커널 버전이 증가하면서 file_operations의 개수가 늘어나고 있다.

 

file_operrations 구조체 필드

 

struct module *owner;
  • 파일 오퍼레이션의 소유자를 나타낸다. 보통 <linux/module.h>에 정의되어 있는 THIS_MODULE 매크로를 사용해 초기화 한다.
off_t(*llseek)(struct file *, loff_t, int);
  • 디바이스 드라이버의 파일 포인터 위치를 강제로 이동 시키는 함수를 지정한다.
ssize_t(*lead)(struct file *, char *, size_t, loff *);
  • 디바이스에서 자료를 읽는데 사용한다. NULL이면 -EINVAL 반환
ssize_t(*write)(struct file *, const char *, size_t, loff_t *);
  • 자료를 디바이스로 보낸다. NULL 이면 -EINVAL 반환
unsigned int(*poll)(struct file *, struct poll_table_struct*);
  • 다중 입출력 처리를 가능하게 해주는 poll, epoll, select의 백엔드이다.
int(*ioctl)(struct inode *, struct file *, unsigned int, unsigned long);
  • 디바이스 관련 명령들을 제어할 수 있다.

  

 

번호 제목 글쓴이 날짜 조회 수
4 리눅스 프레임버퍼(Linux Frame Buffer) file makersweb 2015.02.15 7372
» file_operations makersweb 2014.02.27 3284
2 ioctl() 함수 file makersweb 2014.02.27 13992
1 키패드 드라이버 pjk 2014.02.12 6496