1.struct file_operations
struct file_operations
{
struct module *owner;//标示模块拥有者
loff_t (*llseek) (struct file *, loff_t, int); //loff_t是一个64位长偏移数,llseek方法标示当前文件的操作位置
ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);//ssize_t标示当前平台的固有整数类型。read是读函数
ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); //写函数
ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
ssize_t (*read_iter) (struct kiocb *, struct iov_iter *);
ssize_t (*write_iter) (struct kiocb *, struct iov_iter *);
int (*iterate) (struct file *, struct dir_context *);
unsigned int (*poll) (struct file *, struct poll_table_struct *);//该方法用于查询设备是否可读可写或者处于某种状态。当设备不可读写时它们可以被阻塞直至设备变为可读写。如果驱动程序中没有定义该方法则它驱动的设备就会被认为是可读写的。
long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);//ioctl是一个系统调用,他提供一个执行设备特定命令的方法
long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
int (*mmap) (struct file *, struct vm_area_struct *);//该方法请求把设备内存映射到进程地址空间
int (*open) (struct inode *, struct file *);//打开设备文件,它往往是设备文件执行的第一个操作
int (*flush) (struct file *, fl_owner_t id);//进程在关闭设备描述符副本之前会调用该方法,它会执行设备上尚未完成的操作
int (*release) (struct inode *, struct file *);//当file 结构被释放时就会调用该方法
int (*fsync) (struct file *, loff_t, loff_t, int datasync);//该方法用来刷新待处理的数据
int (*aio_fsync) (struct kiocb *, int datasync);//
int (*fasync) (int, struct file *, int);//即异步通知它是比较高级功能
int (*lock) (struct file *, int, struct file_lock *);//该方法用来实现文件锁定
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);
int (*check_flags)(int);
int (*flock) (struct file *, int, struct file_lock *);
ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
int (*setlease)(struct file *, long, struct file_lock **, void **);
long (*fallocate)(struct file *file, int mode, loff_t offset,
loff_t len);
int (*show_fdinfo)(struct seq_file *m, struct file *f);
};
2.struct socket
struct socket
{
socket_state state;
unsigned long flags;
const struct proto_ops *ops;
struct fasync_struct *fasync_list;
struct file *file;
struct sock *sk;
wait_queue_head_t wait;
short type;
};
3.ioctl
/* include/linux/sockios.h */
/* Socket configuration controls. */
#define SIOCGIFNAME 0x8910 /* get iface name */
#define SIOCSIFLINK 0x8911 /* set iface channel */
#define SIOCGIFCONF 0x8912 /* get iface list */
#define SIOCGIFFLAGS 0x8913 /* get flags */
#define SIOCSIFFLAGS 0x8914 /* set flags */
#define SIOCGIFADDR 0x8915 /* get PA address */
#define SIOCSIFADDR 0x8916 /* set PA address */
#define SIOCGIFDSTADDR 0x8917 /* get remote PA address */
#define SIOCSIFDSTADDR 0x8918 /* set remote PA address */
#define SIOCGIFBRDADDR 0x8919 /* get broadcast PA address*/
#define SIOCSIFBRDADDR 0x891a /* set broadcast PA address*/
#define SIOCGIFNETMASK 0x891b /* get network PA mask */
#define SIOCSIFNETMASK 0x891c /* set network PA mask */
#define SIOCGIFMETRIC 0x891d /* get metric */
#define SIOCSIFMETRIC 0x891e /* set metric */
#define SIOCGIFMEM 0x891f /* get memory address (BSD)*/
#define SIOCSIFMEM 0x8920 /* set memory address (BSD)*/
#define SIOCGIFMTU 0x8921 /* get MTU size */
#define SIOCSIFMTU 0x8922 /* set MTU size */
#define SIOCSIFNAME 0x8923 /* set interface name */
#define SIOCSIFHWADDR 0x8924 /* set hardware address */
#define SIOCGIFENCAP 0x8925 /* get/set encapsulations */
#define SIOCSIFENCAP 0x8926
#define SIOCGIFHWADDR 0x8927 /* Get hardware address */
#define SIOCGIFSLAVE 0x8929 /* Driver slaving support */
#define SIOCSIFSLAVE 0x8930
#define SIOCADDMULTI 0x8931 /* Multicast address lists */
#define SIOCDELMULTI 0x8932
#define SIOCGIFINDEX 0x8933 /* name -> if_index mapping */
#define SIOCSIFPFLAGS 0x8934 /* set/get extended flags set */
#define SIOCGIFPFLAGS 0x8935
#define SIOCDIFADDR 0x8936 /* delete PA address */
#define SIOCSIFHWBROADCAST 0x8937 /* set hardware broadcast addr*/
#define SIOCGIFCOUNT 0x8938 /* get number of devices */
...
#define SIOCETHTOOL 0x8946 /* Ethtool interface */
4.struct stat
struct stat
{
mode_t st_mode; //文件对应的模式,文件,目录等
ino_t st_ino; //inode节点号
dev_t st_dev; //设备号码
dev_t st_rdev; //特殊设备号码
nlink_t st_nlink; //文件的连接数
uid_t st_uid; //文件所有者
gid_t st_gid; //文件所有者对应的组
off_t st_size; //普通文件,对应的文件字节数
time_t st_atime; //文件最后被访问的时间
time_t st_mtime; //文件内容最后被修改的时间
time_t st_ctime; //文件状态改变时间
blksize_t st_blksize; //文件内容对应的块大小
blkcnt_t st_blocks; //文件内容对应的块数量
};
5.struct hostent
struct hostent
{
char *h_name; //主机的规范名
char **h_aliases; //主机的别名
int h_addrtype; //主机ip地址的类型
int h_length; //主机ip地址的长度
char **h_addr_list; //网络字节序存储的主机IP地址
#define h_addr h_addr_list[0]
};
6.struct termios
#include <termios.h>
#include <unistd.h>
struct termios
{
tcflag_t c_iflag; 输入模式标志,控制终端输入方式
tcflag_t c_oflag; 输出模式标志,控制终端输出方式
tcflag_t c_cflag; 控制模式标志,指定终端硬件控制信息
tcflag_t c_lflag; 本地模式标志,控制终端编辑功能
cc_t c_cc(NCCS); 控制字符,用于保存中断驱动程序中的特殊字符,如输入借宿字符等。
};
7.struct file
struct file
{
int f_oflags; /* Open mode flags */
FAR struct inode *f_inode; /* Driver interface */
loff_t f_pos; /* File position */
char *f_path; /* File fullpath */
void *f_priv; /* Per file driver private data */
const char *f_relpath; /* realpath */
};
|