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

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

问题描述

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

我正在使用Linux OS和C编程语言.

处理硬盘扇区的最有效方法是什么?我应该编写linux的块设备模块.但是,我对此并不了解.在块设备上读写时应使用哪些内核函数?

解决方案

大小为4096的块"不是特别需要,您也没有提到任何会破坏内核内置缓存机制的访问模式. /p>

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

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.

I am working on Linux OS and C programming language.

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" 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天全站免登陆