IO之Basic IO
时间:2022-07-22
本文章向大家介绍IO之Basic IO,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
如转发,请标明出处!
Basic I/O system的7个函数:creat(), remove(), open(), close(), read(), write(), ioctl()。creat()与remove()主要用于文件系统。函数声明如下
int creat (char *name, int flag);
int remove(char *name);
/* flags */
#define O_RDONLY 0x0000 /* open for reading only */
#define O_WRONLY 0x0001 /* open for writing only */
#define O_RDWR 0x0002 /* open for reading and writing */
#define O_APPEND 0x0008 /* writes are guaranteed at file end */
#define O_CREAT 0x0200 /* create a file if not existing */
#define O_TRUNC 0x0400 /* open with truncation */
#define O_EXCL 0x0800 /* error on open if file exists and O_CREAT is also set */
#define O_SYNC 0x2000 /* do all writes synchronously on DosFs */
#define O_NONBLOCK 0x4000 /* non blocking I/O */
#define O_NOCTTY 0x8000 /* don't assign a controlling-terminal */
#define O_DSYNC 0x10000 /* file data only integrity while writing */
#define O_RSYNC 0x20000 /* sync read operations */
int open
(
char *name,
int flags,
int mode /* UNIX chmod-style file mode */
);
int close (int fd);
int read (int fd, char *buffer, int maxBytes);
int write (int fd, char *buffer, int nBytes);
/* ioctl function codes */
#define FIONREAD 1 /* get num chars available to read */
#define FIOFLUSH 2 /* flush any chars in buffers */
#define FIOOPTIONS 3 /* set options (FIOSETOPTIONS) */
#define FIOBAUDRATE 4 /* set serial baud rate */
#define FIODISKFORMAT 5 /* format disk */
#define FIODISKINIT 6 /* initialize disk directory */
#define FIOSEEK 7 /* set current file char position */
#define FIOWHERE 8 /* get current file char position */
#define FIODIRENTRY 9 /* return a directory entry (obsolete)*/
#define FIORENAME 10 /* rename a directory entry */
#define FIOREADYCHANGE 11 /* is there media change on the device? */
#define FIONWRITE 12 /* get num chars still to be written */
#define FIODISKCHANGE 13 /* set a media change on the device */
#define FIOCANCEL 14 /* cancel read or write on the device */
#define FIOSQUEEZE 15 /* OBSOLETED since RT11 is obsoleted */
#define FIONBIO 16 /* set non-blocking I/O; SOCKETS ONLY!*/
#define FIONMSGS 17 /* return num msgs in pipe */
#define FIOGETNAME 18 /* return file name in arg */
#define FIOGETOPTIONS 19 /* get options */
#define FIOSETOPTIONS FIOOPTIONS /* set options */
#define FIOISATTY 20 /* is a tty */
#define FIOSYNC 21 /* sync to disk */
#define FIOPROTOHOOK 22 /* specify protocol hook routine */
#define FIOPROTOARG 23 /* specify protocol argument */
#define FIORBUFSET 24 /* alter the size of read buffer */
#define FIOWBUFSET 25 /* alter the size of write buffer */
#define FIORFLUSH 26 /* flush any chars in read buffers */
#define FIOWFLUSH 27 /* flush any chars in write buffers */
#define FIOSELECT 28 /* wake up process in select on I/O */
#define FIOUNSELECT 29 /* wake up process in select on I/O */
#define FIONFREE 30 /* get free byte count on device */
#define FIOMKDIR 31 /* create a directory */
#define FIORMDIR 32 /* remove a directory */
#define FIOLABELGET 33 /* get volume label */
#define FIOLABELSET 34 /* set volume label */
#define FIOATTRIBSET 35 /* set file attribute */
#define FIOCONTIG 36 /* allocate contiguous space */
#define FIOREADDIR 37 /* read a directory entry (POSIX) */
#define FIOFSTATGET_OLD 38 /* get file status info - legacy */
#define FIOUNMOUNT 39 /* unmount disk volume */
#define FIOSCSICOMMAND 40 /* issue a SCSI command */
#define FIONCONTIG 41 /* get size of max contig area on dev */
#define FIOTRUNC 42 /* truncate file to specified length */
#define FIOGETFL 43 /* get file mode, like fcntl(F_GETFL) */
#define FIOTIMESET 44 /* change times on a file for utime() */
#define FIOINODETONAME 45 /* given inode number, return filename*/
#define FIOFSTATFSGET 46 /* get file system status info */
#define FIOMOVE 47 /* move file, ala mv, (mv not rename) */
/* 64-bit ioctl codes, "long long *" expected as 3rd argument */
#define FIOCHKDSK 48
#define FIOCONTIG64 49
#define FIONCONTIG64 50
#define FIONFREE64 51
#define FIONREAD64 52
#define FIOSEEK64 53
#define FIOWHERE64 54
#define FIOTRUNC64 55
#define FIOCOMMITFS 56
#define FIODATASYNC 57 /* sync to I/O data integrity */
#define FIOLINK 58 /* create a link */
#define FIOUNLINK 59 /* remove a link */
#define FIOACCESS 60 /* support POSIX access() */
#define FIOPATHCONF 61 /* support POSIX pathconf() */
#define FIOFCNTL 62 /* support POSIX fcntl() */
#define FIOCHMOD 63 /* support POSIX chmod() */
#define FIOFSTATGET 64 /* get stat info - POSIX */
#define FIOUPDATE 65 /* update dosfs default create option */
/* These are for HRFS but can be used for other future file systems */
#define FIOCOMMITPOLICYGETFS 66 /* get the file system commit policy */
#define FIOCOMMITPOLICYSETFS 67 /* set the file system commit policy */
#define FIOCOMMITPERIODGETFS 68 /* get periodic commit interval in ms */
#define FIOCOMMITPERIODSETFS 69 /* set the file system's periodic */
#define FIOFSTATFSGET64 70 /* get file system status info */
/* the next two ioctls are for block-type storage media (e.g., disks) */
#define FIODISCARDGET 70 /* does hardware want DISCARDs? - for xbdIoctl()*/
#define FIODISCARD 71 /* mark sectors (sectorRange) as deleted */
#define FIOREADDIRPLUS 72 /* read a directory entry extention */
int ioctl (int fd, int function,...);
一起学习 共同进步
- Session和Cookies的基本原理
- 浅析Numpy.genfromtxt及File I/O讲解
- 损失函数详解
- 排查Java的内存问题
- 使用两种方法让 ASP.NET Core 实现遵循 HATEOAS 结构的 RESTful API
- 设计模式六大原则(5):迪米特法则
- Selenium2+python自动化61-Chrome浏览器(chromedriver)
- 区块链可以减少社会不平等吗?
- 【干货】不止准确率:为分类任务选择正确的机器学习度量指标(附代码实现)
- python爬虫beautifulsoup4系列1
- 区块链入门教程
- python爬虫beautifulsoup4系列2
- python爬虫beautifulsoup4系列3
- 多元回归模型
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- C++核心准则T.84:使用非模板核心实现提供稳定的ABI接口
- C++核心准则T.120:只在确实有需要时使用模板元编程
- C++核心准则T.121:模板元编程主要用于模仿概念
- C++核心准则T.122:使用模板在编译时计算类型
- C++核心准则T.123:使用常量表达式函数在编译时求值
- Java基础 【类之间的关系】
- MySql 学习之路-基础
- (有趣的)项目实战:Java实现计算机自动关机
- 猜生日 Java小游戏
- KDD Cup 2020多模态召回比赛亚军方案与搜索业务应用
- 一文快速入门分库分表(必修课)
- MySQL · 物理备份 · XtraBackup备份原理
- Cortex: 高可用和水平扩展Prometheus监控系统
- 从0开始聊聊自动化静态代码审计工具
- WebSphere XXE 漏洞分析(CVE-2020-4643)