2002-11-02 17:14:15

by Petr Baudis

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

Hello,

this patch (against 2.5.45) 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.5.45/drivers/block/genhd.c Sat Nov 2 17:43:41 2002
+++ linux-2.5.45+pasky/drivers/block/genhd.c Sat Nov 2 16:26:51 2002
@@ -218,23 +218,24 @@
char buf[64];

if (&sgp->full_list == gendisk_list.next)
- seq_puts(part, "major minor #blocks name\n\n");
+ seq_puts(part, "major minor startblock #blocks name\n\n");

/* Don't show non-partitionable devices or empty devices */
if (!get_capacity(sgp) || sgp->minors == 1)
return 0;

/* show the full disk and all non-0 size partitions of it */
- seq_printf(part, "%4d %4d %10llu %s\n",
+ seq_printf(part, "%4d %4d %10llu %10llu %s\n",
sgp->major, sgp->first_minor,
- (unsigned long long)get_capacity(sgp) >> 1,
+ 0LL, (unsigned long long) get_capacity(sgp) >> 1,
disk_name(sgp, 0, buf));
for (n = 0; n < sgp->minors - 1; n++) {
if (sgp->part[n].nr_sects == 0)
continue;
- seq_printf(part, "%4d %4d %10llu %s\n",
+ seq_printf(part, "%4d %4d %10llu %10llu %s\n",
sgp->major, n + 1 + sgp->first_minor,
- (unsigned long long)sgp->part[n].nr_sects >> 1 ,
+ (unsigned long long) sgp->part[n].start_sect,
+ (unsigned long long) sgp->part[n].nr_sects >> 1,
disk_name(sgp, n + 1, buf));
}

--

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 17:34:03

by Alexander Viro

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



On Sat, 2 Nov 2002, Petr Baudis wrote:

> Hello,
>
> this patch (against 2.5.45) 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.

It's already exported in files in driverfs. No need to duplicate in
/proc/partitions.