[RFC][PATCH] block ioctl to read/write last sector (New! Improved!)

From: Michael E Brown (michael_e_brown@dell.com)
Date: Tue Feb 13 2001 - 12:57:43 EST

To address the concerns of Andi Kleen, with a good suggestion from Richard
Johnson, I have revised my previous patch attempt. Please check this out
and comment.

  1) use get_gendisk() instead of walking array manually
  2) pass in struct instead of guessing..
+ struct {
+ unsigned int block;
+ size_t content_length;
+ char *block_contents;
+ } blk_ioctl_parameter;

  3) On write, read in previous contents in case userspace doesn't modify
the whole block. (prevents garbage from being put in the remainder of the

On 7 Feb 2001, Andi Kleen wrote:
> But what happens when you e.g. run a software blocksize of 4096 and the device
> has >1 inaccessible 512 byte sector at the end?
> I think it would be better to pass in a offset in 512 byte units to a special
> ioctl (and do error checking in the driver for impossible requests)

This has been addressed in the new patch. The new patch takes in an LBA
offset and reads "LastLBA - offset" and returns the result to userspace.
Checks are done so that only normally inaccessable blocks are accessible
through this method. This is done to prevent any possible security
consequences from arising because of this patch.

Test code showing how to use this IOCTL have also been attached.
Michael Brown

------Original Message------
Problem Summary:
  There is no function exported to userspace to read or write the last
512-byte sector of an odd-size disk.

  The block device uses 1K blocksize, and will prevent userspace from
seeing the odd-block at the end of the disk, if the disk is odd-size.

  IA-64 architecture defines a new partitioning scheme where there is a
backup of the partition table header in the last sector of the disk. While
we can read and write to this sector in the kernel partition code, we have
no way for userspace to update this partition block.

  As an interim solution, I propose the following IOCTLs for the block
device layer: BLKGETLASTSECT and BLKSETLASTSECT. These ioctls will take a
userspace pointer to a char[512] and read/write the last sector. Below is
a patch to do this.

I have attached the patch as well, because I've heard that Pine will eat
patches. :-(

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

This archive was generated by hypermail 2b29 : Thu Feb 15 2001 - 21:00:22 EST