目录
1、查看mount挂载情况2、挂载虚拟文件系统3、 文件从哪里来4、内核的 sys_open、sys_read 会做什么?5、app调用系统接口图6、字符设备节点介绍7、文件拷贝实例
1、查看mount挂载情况
```
go
cat
/proc
/mounts
2、挂载虚拟文件系统
mount
-t sysfs none
/mnt
3、 文件从哪里来
4、内核的 sys_open、sys_read 会做什么?
5、app调用系统接口图
6、字符设备节点介绍
7、文件拷贝实例
#include
<sys
/types
.h
>
#include
<sys
/stat
.h
>
#include
<fcntl
.h
>
#include
<unistd
.h
>
#include
<stdio
.h
>
#include
<sys
/mman
.h
>
int main(int argc
, char
**argv
)
{
int fd_old
, fd_new
;
struct stat stat
;
char
*buf
;
if (argc
!= 3)
{
printf("Usage: %s <old-file> <new-file>\n", argv
[0]);
return -1;
}
fd_old
= open(argv
[1], O_RDONLY
);
if (fd_old
== -1)
{
printf("can not open file %s\n", argv
[1]);
return -1;
}
if (fstat(fd_old
, &stat
) == -1)
{
printf("can not get stat of file %s\n", argv
[1]);
return -1;
}
buf
= mmap(NULL
, stat
.st_size
, PROT_READ
, MAP_SHARED
, fd_old
, 0);
if (buf
== MAP_FAILED
)
{
printf("can not mmap file %s\n", argv
[1]);
return -1;
}
fd_new
= open(argv
[2], O_WRONLY
| O_CREAT
| O_TRUNC
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
| S_IROTH
| S_IWOTH
);
if (fd_new
== -1)
{
printf("can not creat file %s\n", argv
[2]);
return -1;
}
if (write(fd_new
, buf
, stat
.st_size
) != stat
.st_size
)
{
printf("can not write %s\n", argv
[2]);
return -1;
}
close(fd_old
);
close(fd_new
);
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-2980.html