Chinaunix首页 | 论坛 | 博客
  • 博客访问: 250501
  • 博文数量: 65
  • 博客积分: 2599
  • 博客等级: 少校
  • 技术积分: 710
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-04 10:49
文章分类

全部博文(65)

文章存档

2015年(4)

2013年(2)

2012年(4)

2011年(51)

2010年(4)

分类: LINUX

2011-12-16 14:43:16

File IO function List:

#include
#include
#include

int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
打开或者创建一个文件

int creat(const char *pathname, mode_t mode);创建一个文件,但是是write only。
______________________________________________________________
#include

int close(int fd);关闭一个文件描述符
______________________________________________________________
#include
#include

off_t lseek(int fd, off_t offset, int whence);移动文件当前读写位置,同时影响read和write
______________________________________________________________
#include

ssize_t read(int fd, void *buf, size_t count);从文件中读数据,注意buffer的大小,影响IO效率。
______________________________________________________________
#include

ssize_t write(int fd, const void *buf, size_t count);
______________________________________________________________
#include

int dup(int oldfd);
int dup2(int oldfd, int newfd);

#define _GNU_SOURCE
#include

int dup3(int oldfd, int newfd, int flags);
复制一个文件描述符,只是在进程之内创建文件描述符表项,并不改变system级别的打开文件表。
______________________________________________________________
#include

void sync(void);    将所有修改的块缓冲区排入写队列,然后返回,并不等待实际的写磁盘操作结束。
int fsync(int fd);  更新文件数据和属性,等待实际的写磁盘操作结束才返回。
int fdatasync(int fd);  更新文件数据,等待实际的写磁盘操作结束才返回,但不等待文件属性更行。
______________________________________________________________
#include
#include

int fcntl(int fd, int cmd, ... /* arg */ );
获取和设置文件相关的属性。
______________________________________________________________
#include

int ioctl(int d, int request, ...);
通用的io control。
==============================================================

File block IO efficiency
For all the file unbuffered function like read, buffer size choosen is very
important for disk io efficiency when handle big files.

We should choose buffer size according to struct stat.
struct stat {
               dev_t     st_dev;     /* ID of device containing file */
               ino_t     st_ino;     /* inode number */
               mode_t    st_mode;    /* protection */
               nlink_t   st_nlink;   /* number of hard links */
               uid_t     st_uid;     /* user ID of owner */
               gid_t     st_gid;     /* group ID of owner */
               dev_t     st_rdev;    /* device ID (if special file) */
               off_t     st_size;    /* total size, in bytes */
               blksize_t st_blksize; /* blocksize for file system I/O */
               blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
               time_t    st_atime;   /* time of last access */
               time_t    st_mtime;   /* time of last modification */
               time_t    st_ctime;   /* time of last status change */
};/* in Linux */
/* use stat() function to get it. */
see: blksize_t st_blksize; /* blocksize for file system I/O */
st_blksize is a good choose.
阅读(632) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~