微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何读取/写入块设备?

如何读取/写入块设备? 我听说我像一个正常的文件读/写,所以我设置一个循环设备

sudo losetup /dev/loop4 ~/file

然后我运行该应用程序的文件,然后循环设备

sudo ./a.out file sudo ./a.out /dev/loop4

文件执行完美。 循环设备读取0个字节。 在这两种情况下,我得到FP == 3和closures== 0。 该文件正确获取string的长度和打印string,而循环让我0​​和打印什么都没有

如何读取/写入块设备?

如何将bcache设备还原为regulare文件系统

阻止未安装的设备信息(在Linux中)

文件级别的USB Mass Storrage

Linux块设备驱动程序请求sorting – RaW?

如何在Linux中以编程方式获取磁盘名称(如“/ dev / sda”或“/ dev / sdb”)?

#include <fcntl.h> #include <cstdio> #include <unistd.h> int main(int argc,char *argv[]) { char str[1000]; if(argc<2){ printf("Error argsn"); return 0; } int fp = open(argv[1],O_RDONLY); printf("FP=%dn",fp); if(fp<=0) { perror("Error opening file"); return(-1); } off_t off = lseek(fp,SEEK_SET); ssize_t len = read(fp,str,sizeof str); str[len]=0; printf("%d,%d=%sn",len,static_cast<int>(off),str); close(fp); }

使用O_DIRECT打开文件后,用户缓冲区被写入

并发使用多个线程写入文件

为什么内核使用认的块驱动而不是我的驱动代码

使用块特殊文件/设备来实现文件系统

如何使用Python获取原始磁盘或阻止设备大小

losetup似乎映射文件在512字节扇区。 如果文件大小不是512的倍数,则其余的将被截断。

当使用losetup将文件映射到/dev/loopX时,对于小于512字节的文件,会给出如下警告:

Warning: file is smaller than 512 bytes; the loop device may be useless or invisible for system tools.

对于大小不能被512除的文件

Warning: file does not fit into a 512-byte sector; the end of the file will be ignored

这个警告是从util-linux ver 2.22开始的

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐