0

I have a SATA block device that reports a capacity that is smaller than its accessible space, and I would like to read and write to it past the reported capacity using the file created by Linux for block devices. So I hope to operate using the descriptor returned from open({"/dev/sda", O_RDWR). However, when I try to use lseek to seek past the capacity of the device, I get an error and errno gets set to EINVAL (22). Is there a way to access the data past the capacity of the device without modifying the device drivers and while still using the file descriptor returned by open()?

My Linux release is CentOS 7 with kernel 3.10.0-514.21.1.el7.x86_64, although I'd be interested in solutions even if they involve other Linux distributions.

Edit: The drive I am working with is a FLEX protocol drive that reports the conventional capacity of the drive, but also has shingled magnetic recording available at an offset above the reported capacity of the drive. If you are interested, the details of this protocol can be found on the T13 website.

trinof
  • 1
  • 2
  • 1
    How do you know its reported capacity is smaller than its accessible space? What counts as accessible space? – user253751 Feb 08 '18 at 00:16
  • How did "the data past the capacity of the device" even get there? – Andrew Henle Feb 08 '18 at 13:25
  • @immibis The device has readable/writable areas on the drive level that are past the reported capacity which can accessed at the interface level. For instance, I can use sg_raw from sg3_utils to formulate my own byte packets to read and write past the capacity. – trinof Feb 08 '18 at 17:36
  • You would probably have to modify the driver (or use a special modified driver that someone else has made already) – user253751 Feb 08 '18 at 21:53

1 Answers1

1

If I remember correctly, that error is caused because the device itself wasn't able to read or write that cylinder, indicating it likely does not exist. Note that many manufacturers use 1000B = 1KB and the likes, and that file systems reserve their own space as well.

The short answer is, you don't. The device will only report the space you can use, and will not report cache sizes either. This misreporting isn't at the OS level, but at the device.

phyrrus9
  • 1,441
  • 11
  • 26
  • 1
    This device I have is intentionally misreporting its capacity. I understand that in general trying to access past the reported capacity of a device is a mistake, but I'm trying to find out if it would be possible to still use the file-like interface Linux provides to block devices to access this bizarre area without making any driver changes. – trinof Feb 08 '18 at 17:53