man 2 open
int open(const char *pathname, int flags, mode_t mode);
SEE ALSO
read(2), write(2), fcntl(2), close(2), link(2), mknod(2), mount(2), stat(2),
umask(2), unlink(2), socket(2), fopen(3), fifo(4)
Linux 1999-06-03 OPEN(2)
-------------------------------------------------------------------------------
open函数用于打开、创建文件 POSIX 标准系统调用
#include <fcntl.h> ///usr/include/fcntl.h
返回值:成功则返回文件描述符,否则返回-1
对于open函数,第三个参数(…),仅当创建新文件时 才使用。
----------------------------------------------------------
理解从应用层到我们自己所写的驱动层的调用过程
asmlinkage long sys_readlink(const char __user *path,
char __user *buf, int bufsiz);
asmlinkage long sys_creat(const char __user *pathname, int mode);
asmlinkage long sys_open(const char __user *filename,
int flags, int mode);
asmlinkage long sys_close(unsigned int fd);
asmlinkage long sys_access(const char __user *filename, int mode);
asmlinkage long sys_vhangup(void);
asmlinkage long sys_chown(const char __user *filename,
uid_t user, gid_t group);
asmlinkage long sys_lchown(const char __user *filename,
sys_open()
定义:
fs/open.c
SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, int, mode)
{
long ret;
if (force_o_largefile())
flags |= O_LARGEFILE;
ret = do_sys_open(AT_FDCWD, filename, flags, mode);
/* avoid REGPARM breakage on x86: */
asmlinkage_protect(3, ret, filename, flags, mode);
return ret;
}