Directly read and write hard disk sector [copy]

See answer in English> Direct access to hard disk with no FS from C program on Linuxbr> 3 special blocks Read a single sector from a disk Data storage. My data is a formatted data block with a size of 4096. For high efficiency, I want to directly manipulate the blocks on the hard disk sector, and do not want to treat the data block as a file. I think one way is to use the device Treat it as a file, such as /dev/sda1, and use lseek() read() and write() to read and write data. But I don’t know if the file header is the first sector of the hard disk. I also doubt this The efficiency of this method.

I am studying Linux OS and C programming language.

What is the most effective way to deal with hard disk sectors? I should write a block device module for linux. However, I don’t understand this. Which kernel functions should I use to read and write block devices?

“The block size is 4096” is not particularly necessary, and you didn’t mention anything that would break the kernel Access mode with built-in caching mechanism.

The most effective way to read and write data is to use files.

See the English answer> Direct access to hard disk with no FS from C program on Linux. The data is stored in a block of 3 blocks. I need to read a single sector from a disk. The size of the data is 4 blocks. 4096. For high efficiency, I want to directly manipulate the blocks on the hard disk sector, and do not want to treat the data block as a file. I think one way is to treat the device as a file, such as /dev/sda1, and use lseek() read() and write() to read and write data. But I don’t know whether the file header is the first sector of the hard disk. I also doubt the efficiency of this method.

I am studying Linux OS and C programming language.

What is the most effective way to deal with hard disk sectors? I should write a block device module for linux. However, I don’t understand this. Which kernel functions should I use to read and write block devices?

“The block size is 4096” is not particularly necessary, and you did not mention any access mode that would destroy the kernel’s built-in cache mechanism.

The most effective way to read and write data is to use files.

Leave a Comment

Your email address will not be published.