IO之Basic IO

一个人想着一个人 提交于 2020-08-04 11:21:04

欢迎关注VxWorks567

如转发,请标明出处!

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,...);

我是泰山 专注VX 0x10

一起学习 共同进步

本文分享自微信公众号 - 这里只有VxWorks(VxWorks567)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!