2002-11-02 17:11:41

by Petr Baudis

[permalink] [raw]
Subject: [PATCH] [2.4.19] Extended /proc/partitions

Hello,

this patch (against 2.4.19) extends contents of /proc/partitions by starting
offset of each partition. This can be terribly useful if you (or someone who
then passed you the computer for a repair) by some mistake over-dd'd the
partition table on a disk, but the system is still up. I know that you can also
dig this out by some ioctl()s, but this can make life a lot easier for those
who don't know C or can't dig the ioctl codes from the kernel source code.

Note that it's possibly totally flawed (I don't know anything about this
piece of code), but it looks to work ok.

Kind regards,

--- linux-2.4.19/drivers/block/genhd.c Fri Nov 1 21:28:24 2002
+++ linux-2.4.19+pasky/drivers/block/genhd.c Fri Nov 1 21:27:41 2002
@@ -163,7 +163,7 @@
char buf[64];
int len, n;

- len = sprintf(page, "major minor #blocks name\n\n");
+ len = sprintf(page, "major minor startblock #blocks name\n\n");

read_lock(&gendisk_lock);
for (gp = gendisk_head; gp; gp = gp->next) {
@@ -173,8 +173,9 @@

hd = &gp->part[n]; disk_round_stats(hd);
len += sprintf(page + len,
- "%4d %4d %10d %s\n", gp->major,
- n, gp->sizes[n], disk_name(gp, n, buf));
+ "%4d %4d %10ld %10d %s\n", gp->major,
+ n, hd->start_sect, gp->sizes[n],
+ disk_name(gp, n, buf));

if (len < offset)
offset -= len, len = 0;

--

Petr "Pasky" Baudis

* ELinks maintainer * IPv6 guy (XS26 co-coordinator)
* IRCnet operator * FreeCiv AI occassional hacker
.
This host is a black hole at HTTP wavelengths. GETs go in, and nothing
comes out, not even Hawking radiation.
-- Graaagh the Mighty on rec.games.roguelike.angband
.
Public PGP key && geekcode && homepage: http://pasky.ji.cz/~pasky/


2002-11-02 19:13:42

by Andries E. Brouwer

[permalink] [raw]
Subject: Re: [PATCH] [2.4.19] Extended /proc/partitions

From [email protected] Sat Nov 2 18:18:06 2002
From: Petr Baudis <[email protected]>

This patch extends contents of /proc/partitions by starting
offset of each partition. This can be terribly useful if you
by some mistake over-dd'd the partition table on a disk,
but the system is still up. I know that you can also
dig this out by some ioctl()s, but this can make life a lot easier
for those who don't know C or can't dig the ioctl codes from
the kernel source code.

(0) When it is too late, many people realize that they could have
made a backup, either with dd to some file, or with
# sfdisk -d /dev/hda
both to file and printer.

(1) These ioctls are used by existing programs. So, for example,
# hdparm -g /dev/hda5
will give you the starting offset (in 512-byte sectors) of /dev/hda5.
Even better may be a command like
# blockdev --report

(2) Several programs, like mount, *fdisk, blockdev, read
/proc/partitions. Changing the format will break all of these.
So, it is best not to change anything, but if you do, only add
fields at the end.

(2a) Maybe /proc/partitions is already extended with disk statistics.
Certainly some vendors do so, and it is rumoured that stock 2.4.20
will (optionally) do so.

Given this uncertainty about what comes after the currently present
fields, it is now impossible to add anything new, unless all programs
using /proc/partitions also parse the header line.
It is best to consider /proc/partitions frozen. Linux 2.5 has
driverfs, and although "cat /proc/partitions" is much more convenient
than searching around in driverfs (sysfs), no doubt blockdev will be
changed so as to report on sysfs, when that exists and is mounted.

Andries

2002-11-02 19:47:49

by Petr Baudis

[permalink] [raw]
Subject: Re: [PATCH] [2.4.19] Extended /proc/partitions

Dear diary, on Sat, Nov 02, 2002 at 08:19:22PM CET, I got a letter,
where [email protected] told me, that...
> (1) These ioctls are used by existing programs. So, for example,
> # hdparm -g /dev/hda5
> will give you the starting offset (in 512-byte sectors) of /dev/hda5.
> Even better may be a command like
> # blockdev --report
>
> (2) Several programs, like mount, *fdisk, blockdev, read
> /proc/partitions. Changing the format will break all of these.
> So, it is best not to change anything, but if you do, only add
> fields at the end.
>
..snip..
>
> Given this uncertainty about what comes after the currently present
> fields, it is now impossible to add anything new, unless all programs
> using /proc/partitions also parse the header line.
> It is best to consider /proc/partitions frozen. Linux 2.5 has
> driverfs, and although "cat /proc/partitions" is much more convenient
> than searching around in driverfs (sysfs), no doubt blockdev will be
> changed so as to report on sysfs, when that exists and is mounted.

Ah.. I see, then please disregard the patches. Didn't realize that hdparm
already can do it nor that it's exported thru driverfs in 2.5, sorry.

--

Petr "Pasky" Baudis
.
This host is a black hole at HTTP wavelengths. GETs go in, and nothing
comes out, not even Hawking radiation.
-- Graaagh the Mighty on rec.games.roguelike.angband
.
Public PGP key && geekcode && homepage: http://pasky.ji.cz/~pasky/