public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: block ioctl to read/write last sector
@ 2001-02-13 23:49 Andries.Brouwer
  2001-02-14 14:19 ` Michael E Brown
  0 siblings, 1 reply; 17+ messages in thread
From: Andries.Brouwer @ 2001-02-13 23:49 UTC (permalink / raw)
  To: michael_e_brown; +Cc: Matt_Domsch, linux-kernel

    From michael_e_brown@dell.com Wed Feb 14 00:37:25 2001

    > Look at the addpart utility in the util-linux package.
    > It will allow you to add a partition disjoint from
    > previously existing partitions.
    > And since a partition can start on an odd sector,
    > this should allow you to also read the last sector.
    >
    > Do I overlook something?

    Yes. The addpart utility just uses the block-layer ioctls to dynamically
    add and/or remove partitions. What this is doing is just adjusting the
    kernel's idea of what the current partition scheme is. This has _nothing_
    to do with actually reading or writing data from the disk.

But it changes the idea of odd and even.
A partition can start on an odd sector.

Andries

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: block ioctl to read/write last sector
@ 2001-02-14 15:43 Andries.Brouwer
  2001-02-14 15:56 ` Michael E Brown
  2001-02-14 15:59 ` Michael E Brown
  0 siblings, 2 replies; 17+ messages in thread
From: Andries.Brouwer @ 2001-02-14 15:43 UTC (permalink / raw)
  To: michael_e_brown; +Cc: Matt_Domsch, linux-kernel

> My patch has nothing to do with partitioning.

Yes, you already said that, and I understand you very well.
My suggestion, and I have not checked the code to make sure,
but off-hand it seems to me that it should work,
is to use a partition.

> Disk with 1001 blocks. Hardware 512-byte sector size.
> The block layer uses 1024-byte soft blocksize.
> This means that, at the _end_ of the disk there is a single sector
> that represents half of a software sector.

Maybe. I think that you'll find that these blocks are
relative to the start of the partition, not relative
to the start of the disk.

So if you add a 1-block partition that contains the last
sector of the disk, all should be fine.

Andries



^ permalink raw reply	[flat|nested] 17+ messages in thread
* RE: block ioctl to read/write last sector
@ 2001-02-14 13:26 Matt_Domsch
  0 siblings, 0 replies; 17+ messages in thread
From: Matt_Domsch @ 2001-02-14 13:26 UTC (permalink / raw)
  To: manfred, Michael_E_Brown; +Cc: Andries.Brouwer, linux-kernel, sct

> I have one additional user space only idea:
> have you tried raw-io? bind a raw device to the partition, IIRC raw-io
> is always in 512 byte units.

Steven Tweedie responded to my question about that:

> Raw IO is subject to the same limits as other IO, because
> ultimately it uses the same route through the kernel
> to get to the low-level disk IO drivers.

This was confirmed by my testing.  Reading/writing via /dev/raw/rawX fails
exactly the same way as for /dev/[sh]dX.

> Accessing /dev/sg ought to work fine, but of course it
> places much more load on the application programmer
> and removes a ton of kernel safety-nets.

I believe using ide-scsi would work, but you must pass "hdc=ide-scsi" at
boot time, which isn't a big deal for accessing CD-ROMs, but to be used for
arbitrary disks, makes life much more difficult.  Now all your IDE disks
need to think they're SCSI disks, at least for the boot in which you want to
change the partition table.  I wouldn't want to suggest to customers that
they run this additional layer of abstraction all the time just in case they
want to examine and/or change the partition table of just one disk at some
time.

Thanks,
Matt

-- 
Matt Domsch
Dell Linux Systems Group
Linux OS Development
www.dell.com/linux



^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: block ioctl to read/write last sector
@ 2001-02-14 12:31 David Balazic
  2001-02-14 14:10 ` Michael E Brown
  2001-02-17  7:29 ` Andre Hedrick
  0 siblings, 2 replies; 17+ messages in thread
From: David Balazic @ 2001-02-14 12:31 UTC (permalink / raw)
  To: Michael E Brown; +Cc: linux-kernel

Michael E Brown (michael_e_brown@dell.com) worte :

> On Wed, 14 Feb 2001, Manfred Spraul wrote:
>
> > I have one additional user space only idea: 
> > have you tried raw-io? bind a raw device to the partition, IIRC raw-io 
> > is always in 512 byte units. 
> 
> That has been tried. No, it does not work. :-) Using Scsi-Generic is the
> only way so far found, but of course, it only works on SCSI drives.

Did you try scsi-emulation on IDE disks ?
 
> > 
> > Probably an ioctl is the better idea, but I'd use absolute sector 
> > numbers (not relative to the end), and obviously 64-bit sector numbers - 
> > 2 TB isn't that far away. 
> > 
> 
> I was deliberately trying to limit the scope to avoid misuse. This is to
> work around a flaw in the current API, not to create a new API. Limiting
> access to only those blocks that would normally be inaccessible through
> the normal API seemed like the best bet to me.


-- 
David Balazic
--------------
"Be excellent to each other." - Bill & Ted
- - - - - - - - - - - - - - - - - - - - - -

^ permalink raw reply	[flat|nested] 17+ messages in thread
* RE: block ioctl to read/write last sector
@ 2001-02-14  1:00 Matt_Domsch
  0 siblings, 0 replies; 17+ messages in thread
From: Matt_Domsch @ 2001-02-14  1:00 UTC (permalink / raw)
  To: Andries.Brouwer, Michael_E_Brown
  Cc: Matt_Domsch, freitag, linux-kernel, aia21

> > 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.
> 
> Are you sure?

I'm not sure, but when I asked about this in January, I suggested having an
IOCTL that get/set blksize_size[MAJOR(dev)][MINOR(dev)], which didn't seem
to work for me.

> I need to read/write the last 512-byte
> sector on an odd-sized disk (IDE and/or SCSI) from user space.  Employing
> suggestions from you and l-k, I have implemented two IOCTLs that get/set
the
> blksize_size[MAJOR(dev)][MINOR(dev)] values (via set_blocksize()).  In my
> application, I read the hardsector size of a disk device (/dev/sdb) via an
> IOCTL, read the current blksize_size, set it to the hardsector size, and
> then continue, resetting blksize_size back to the original value when
done.
> 
> In between, I use fopen64() to open the device /dev/sdb (an odd-sized
disk),
> and lseek64()/fwrite64()/fread64() to write/read the last sector of the
disk
> as reported by the BLKGETSIZE ioctl.  The seek succeeds, however, the
> reads/writes fail.  Writes fail with "No space left on device".  Read
> returns 0, indicating EOF.   If I read/write the N-1th sector this way, it
> works just fine. On even-sized disks, this succeeds both with and
> without calling my new IOCTLs, as expected.  On odd-sized disks, it
> fails in both cases.

Anton Altaparmakov responded:

> I am sure Andries will correct me if I am wrong but here is 
> what I think of the situation at present:
> 
> I suspect that you will find the problem in 
> linux/fs/block_dev.c functions
> block_write() and block_read() which AFAIK only get called 
> when you use
> usermode to read a /dev/* blockdevice as you probably are 
> doing. From the
> kernel these functions AFAIK never get called and hence the problem
> doesn't exist (either way I am surprised that it works as looking at
> generic_make_request() there is a check of simillar type and AFAICS it
> would fail as well for the same reason. I probably don't understand
> something there and/or generic_make_request() is not being 
> called either,
> as it obviously works, since you have tried it).
> 
> In block_write() you find this (lines 58ff in the file in 2.4.0):
> [snip]
>         if (blk_size[MAJOR(dev)])
>                 size = ((loff_t) blk_size[MAJOR(dev)][MINOR(dev)] <<
> BLOCK_SIZE_BITS) >> blocksize_bits;
>         else
>                 size = INT_MAX;
>         while (count>0) {
>                 if (block >= size)
>                         return written ? written : -ENOSPC;
> [snip]
> 
> As you can see when size is calculated blk_size is multiplied 
> by 1024 and
> then divided by 512, effectively blk_size is multiplied by 2.
> 
> The effect of this is that size has the lowest bit always 
> equal to zero
> and hence it always will be even.
> 
> The subsequent check "if (block >= size)" of course is then 
> true and we
> return with -ENOSPC straight away.
> 
> In block_read() you find this (lines 195ff in the file in 2.4.0):
> [snip]
>         if (blk_size[MAJOR(dev)])
>                 size = (loff_t) blk_size[MAJOR(dev)][MINOR(dev)] <<
> BLOCK_SIZE_BITS;
>         else
>                 size = (loff_t) INT_MAX << BLOCK_SIZE_BITS;
> 
>         if (offset > size)
>                 left = 0;
> [snip]
>         if (left <= 0)
>                 return 0;
> [snip]
> 
> And again size is equal to blk_size multiplied by 1024 and 
> hence always
> will be even.

If this analysis is correct (and I think it is), changing the block size
doesn't actually solve the problem.

I've got no problems requiring any IOCTL (either block-size-changing or just
a read/write last sector) to check that a device isn't in use somehow prior
to making these calls.  Changing a disk's partition table while partitions
are actively in use on it isn't generally a good idea.  But, fdisk and other
partition table-changing apps don't do this kind of check now IIRC.


Thanks,
Matt


-- 
Matt Domsch
Dell Linux Systems Group
Linux OS Development
www.dell.com/linux



^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: block ioctl to read/write last sector
@ 2001-02-13 22:54 Andries.Brouwer
  2001-02-13 19:24 ` Martin K. Petersen
  2001-02-13 23:37 ` Michael E Brown
  0 siblings, 2 replies; 17+ messages in thread
From: Andries.Brouwer @ 2001-02-13 22:54 UTC (permalink / raw)
  To: michael_e_brown; +Cc: Matt_Domsch, freitag, linux-kernel

>   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.

Are you sure?

There may be no easy, convenient way right now, but
(without having checked anything) it seems to me
that you can, also today.
Look at the addpart utility in the util-linux package.
It will allow you to add a partition disjoint from
previously existing partitions.
And since a partition can start on an odd sector,
this should allow you to also read the last sector.

Do I overlook something?

Anyway, an ioctl just to read the last sector is too silly.
An ioctl to change the blocksize is more reasonable.
And I expect that this fixed blocksize will go soon.

Andries

[Sorry if precisely the same discussion has happened earlier -
I have no memory.]

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2001-02-17  7:31 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-02-13 23:49 block ioctl to read/write last sector Andries.Brouwer
2001-02-14 14:19 ` Michael E Brown
  -- strict thread matches above, loose matches on Subject: below --
2001-02-14 15:43 Andries.Brouwer
2001-02-14 15:56 ` Michael E Brown
2001-02-14 15:59 ` Michael E Brown
2001-02-14 13:26 Matt_Domsch
2001-02-14 12:31 David Balazic
2001-02-14 14:10 ` Michael E Brown
2001-02-17  7:29 ` Andre Hedrick
2001-02-14  1:00 Matt_Domsch
2001-02-13 22:54 Andries.Brouwer
2001-02-13 19:24 ` Martin K. Petersen
2001-02-14  5:51   ` Michael E Brown
2001-02-14 14:23     ` Martin K. Petersen
2001-02-13 23:37 ` Michael E Brown
2001-02-14  0:21   ` Manfred Spraul
2001-02-14  5:47     ` Michael E Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox