Foma
asked on
How to get hard disk sector size in Linux?
Hello!
I would like to write to disk in atomic way to support transactions. To achive this, I have to write to disk in portions equal to the size of disk sector size. The problem is that it is srangely difficult to obtain the disk sector size in Linux. In Windows I use GetDiskFreeSpace call which returns me "bytes per sector" value. As I understand, for modern hard drivers (ATA and may be SCSI, I'm not sure) disk sector size is equal to 512bytes... But anyway, I'd like to be sure and ask Linux/device/controller/wh atevery-yo u-want, but I don't know how to do it
Thanks for attention to my question,
Foma
I would like to write to disk in atomic way to support transactions. To achive this, I have to write to disk in portions equal to the size of disk sector size. The problem is that it is srangely difficult to obtain the disk sector size in Linux. In Windows I use GetDiskFreeSpace call which returns me "bytes per sector" value. As I understand, for modern hard drivers (ATA and may be SCSI, I'm not sure) disk sector size is equal to 512bytes... But anyway, I'd like to be sure and ask Linux/device/controller/wh
Thanks for attention to my question,
Foma
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
BLKSSZGET ioctl fully fits my requirements. I’ve written a test program and it works fine. HDIO_GET_IDENTITY ioctl gives lots of information and can be useful too.
Concerning my task. I’m writing to disk using file system, but it doesn’t make sense because using portions of data equal to sector size, which are properly aligned I get atomicity of writes (with the one exception noted below). And of course, I use open with O_SYNC flag.
>Note that writing single sectors does not really guarantee atomicity. The disk driver is still free to reorder writes
Yes, modern hard disks are tooooo ‘smart’. As far as I know, this is the reason why SQL Server 7.0, for example, cannot _guarantee_ recovery in all cases on standard hardware. And we have to live with it… For critical tasks we have to use hard disks, which are capable of writing to disk everything they have in buffers in case of power off. And use RAID to save our data in case of disk breakage.