5——linux文件系统与设备文件系统
2010-06-06 08:51
387 查看
文件系统的相关调用:
int open(const char *pathname,int flags,mode_t mode)
路径名称,默认时认为在当前路径下面
int read(int fd,const void *buf,size_t length)读取fd文件length个字节
到所指的缓冲区buf中
int write(int fd,const void *buf,size_t legth) 读取缓冲区buf length个字节
到fd文件
int lseek(int fd,offset_t offset,int whence) 将文件读写指针相对whence移动offset个字节
返回文件指针相对于文件头的位置
SEEK_SET,相对文件开头
SEEK_CUR,相对文件读写指针的当前位置
SEEK_END;相对文件末尾
lseek(fd,0,SEEK_END) 返回值为文件相对于文件头的位置,返回值就是文件的长度
在开发板上的显示如下 在文件夹下,原先没有hello.txt文件,通过open函数建立
c库函数的文件操作
c库函数的文件操作实际上是独立于具体的操作系统平台的,不管是在DOS,windows,linux,VxWorks中,都是这些函数。
FILE *fopen()
int fgetc()
int fputc()
char *fgets().............
int open(const char *pathname,int flags,mode_t mode)
路径名称,默认时认为在当前路径下面
int read(int fd,const void *buf,size_t length)读取fd文件length个字节
到所指的缓冲区buf中
int write(int fd,const void *buf,size_t legth) 读取缓冲区buf length个字节
到fd文件
int lseek(int fd,offset_t offset,int whence) 将文件读写指针相对whence移动offset个字节
返回文件指针相对于文件头的位置
SEEK_SET,相对文件开头
SEEK_CUR,相对文件读写指针的当前位置
SEEK_END;相对文件末尾
lseek(fd,0,SEEK_END) 返回值为文件相对于文件头的位置,返回值就是文件的长度
#include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<stdio.h> #define LENGTH 100 main(void) { int fd,len; char str[LENGTH]; fd=open("hello.txt",O_CREAT|O_RDWR,S_IRUSR|S_IWUSR); if(fd) { write(fd,"hello world",strlen("hello world")); close(fd); } fd=open("hello.txt",O_RDWR); len=read(fd,str,LENGTH); str[len]='/0'; printf("%s/n",str); close(fd); }
在开发板上的显示如下 在文件夹下,原先没有hello.txt文件,通过open函数建立
[root@EmbedSky /xiangjie]# ls 4_book.ko hello [root@EmbedSky /xiangjie]# ls 4_book.ko hello [root@EmbedSky /xiangjie]# ./hello hello world [root@EmbedSky /xiangjie]# ls 4_book.ko hello hello.txt [root@EmbedSky /xiangjie]# [root@EmbedSky /xiangjie]#
c库函数的文件操作
c库函数的文件操作实际上是独立于具体的操作系统平台的,不管是在DOS,windows,linux,VxWorks中,都是这些函数。
FILE *fopen()
int fgetc()
int fputc()
char *fgets().............
相关文章推荐
- linux文件系统与设备文件系统的关系?
- 20150517 Linux文件系统与设备文件系统
- Linux文件系统(四) - 从文件系统到块设备/从page cache到bio, request, request_queue
- linux设备驱动学习第四天(linux文件系统与设备文件系统1)
- 第5章 Linux文件系统与设备文件系统
- linux设备驱动学习第四天(linux文件系统与设备文件系统2)
- Linux系列教程(十八)——Linux文件系统管理之文件系统常用命令
- vm错误:出现错误-未找到要在其中创建新文件系统的有效设备。请检查您的硬件以找到问题的起因
- Linux 文件系统与设备文件系统 (二)—— sysfs 文件系统与Linux设备模型
- 文件系统,块设备
- 关于文件系统设备堆栈的说明
- linux下,在挂载设备之前,如何知道设备的文件系统类型?
- VMware安装Linux,出现错误-未找到要在其中创建新文件系统的有效设备
- Linux 内核文件系统与设备操作流程分析
- Linux设备管理文件系统,mdev,热插拔
- linux常见设备类型及文件系统
- linux文件系统与物理文件系统
- vmware安装无法打开内核设备 \\.\Global\vmx86: 系统找不到指定的文件
- 嵌入式 ubuntu下修改网络设备名称以及hi3518c平台jffs2文件系统中获取当前无线网卡设备
- linux文件系统的系统分析--(十三)sysfs和设备模型--Device