直接高效读写硬盘扇区 [英] Read and write hard disk sector directly and efficiently

查看:20
本文介绍了直接高效读写硬盘扇区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对块数据存储有特殊需求.我的数据是4096大小的格式化数据块.为了高效率,我想直接操作硬盘扇区上的块,不想把数据块当作文件来处理.我认为一种方法是将设备视为/dev/sda1 等文件,并使用 lseek() read() 和 write() 来读写数据.但是我不知道文件头是否是硬盘的第一个扇区.我也怀疑这个方法的效率.

I have a special need for block data storage. My data are formatted data blocks in size of 4096. For high efficiency, I want to directly manipulate the block on hard disk sector and do not want to treat the data block as file. I think one way is to treat the device as a file such as /dev/sda1 and to use lseek() read() and write() to read and write data. However I do not know the whether the head of the file is the first sector of hard disk. I also suspect the efficiency of this method.

我正在研究 Linux 操作系统和 C 编程语言.

I am working on Linux OS and C programming language.

处理硬盘扇区最有效的方法是什么?我应该写一个linux的块设备模块吗?但是,我对此知之甚少.我应该使用哪些内核函数来读写块设备?

What is the most efficient way to handle the sector of hard disk? Should I write an block device module of linux. However, I do not know much about it. What kernel functions should I use to read and write on block device?

推荐答案

Blocks in size of 4096"并不是特别需要,您也没有提到任何会破坏内核内置缓存机制的访问模式.

"Blocks in size of 4096" is not a special need, and you have not mentioned any access patterns that would break the kernel's built-in caching mechanisms.

读取和写入数据的最有效方法是使用文件.

The most efficient way to read and write your data is to use a file.

这篇关于直接高效读写硬盘扇区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆