前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >IO之Basic IO

IO之Basic IO

作者头像
Taishan3721
发布2020-08-06 14:53:22
1K0
发布2020-08-06 14:53:22
举报
文章被收录于专栏:这里只有VxWorks这里只有VxWorks

如转发,请标明出处!

Basic I/O system的7个函数:creat(), remove(), open(), close(), read(), write(), ioctl()。creat()与remove()主要用于文件系统。函数声明如下

代码语言:javascript
复制
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,...);

一起学习 共同进步

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-08-03,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 这里只有VxWorks 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档