Hi,

sometimes I'm simply looking for the size (e.g. in GB) of the slices of
an i386 Harddisk. 
I can get it using the fdisk(8) inline editor with 'p g' but I haven't
found how do get it without starting the editor, so I've pached fdisk.

Maybe someone is interested in the patch or have a comment on it, so
here it is.
(The patch applies for OpenBSD 4.1)

Regards
   Dag
sbin/fdisk//fdisk.8.orig --> sbin/fdisk//fdisk.8
--- sbin/fdisk//fdisk.8.orig    Wed Feb 14 19:06:53 2007
+++ sbin/fdisk//fdisk.8 Sun Jun  3 13:24:46 2007
@@ -38,6 +38,7 @@
 .Fl s Ar sectors
 .Oc
 .Op Fl f Ar mbrfile
+.Op Fl p Ar unit
 .Ar device
 .Sh DESCRIPTION
 On the i386 and other architectures, sector 0 of a bootable hard disk
@@ -106,6 +107,19 @@
 MBR partition spanning from cylinder 0, head 1, sector 1, and extending
 to the end of the disk.
 This mode is designed to initialize the MBR the very first time.
+.It Fl p Ar unit
+Specifies the unit in which the size of slices should be shown. Legal
+values are 
+.Ql \&b
+(Bytes)
+.Ql \&K
+(Kilobytes)
+.Ql \&M
+(Megabytes) and
+.Ql \&G
+(Gigabytes). If 
+.Fl p
+is omitted the everything is printet in Sectors.
 .It Fl u
 Update MBR bootcode, preserving existing MBR partition table.
 The MBR bootcode extends from offset 0x000 to the start of the MBR partition 
table
sbin/fdisk//fdisk.c.orig --> sbin/fdisk//fdisk.c
--- sbin/fdisk//fdisk.c.orig    Mon Nov 20 09:18:21 2006
+++ sbin/fdisk//fdisk.c Sun Jun  3 13:27:07 2007
@@ -56,6 +56,7 @@
            "\t-e: edit MBRs on disk interactively\n"
            "\t-f: specify non-standard MBR template\n"
            "\t-chs: specify disk geometry\n"
+            "\t-p: specify units\n"
            "\t-y: do not ask questions\n"
            "`disk' may be of the forms: sd0 or /dev/rsd0c.\n",
            __progname);
@@ -79,8 +80,9 @@
 #endif
        mbr_t mbr;
        char mbr_buf[DEV_BSIZE];
+       char *unit=NULL;
 
-       while ((ch = getopt(argc, argv, "ieuf:c:h:s:y")) != -1) {
+       while ((ch = getopt(argc, argv, "ieuf:c:h:s:p:")) != -1) {
                const char *errstr;
 
                switch(ch) {
@@ -115,6 +117,9 @@
                case 'y':
                        y_flag = 1;
                        break;
+               case 'p':
+                       unit = optarg;
+                       break;
                default:
                        usage();
                }
@@ -151,7 +156,7 @@
 
        /* Print out current MBRs on disk */
        if ((i_flag + u_flag + m_flag) == 0)
-               exit(USER_print_disk(&disk));
+               exit(USER_print_disk(&disk, unit));
 
        /* Parse mbr template, to pass on later */
        if (mbrfile != NULL && (fd = open(mbrfile, O_RDONLY)) == -1) {
sbin/fdisk//user.c.orig --> sbin/fdisk//user.c
--- sbin/fdisk//user.c.orig     Tue Aug  1 12:12:35 2006
+++ sbin/fdisk//user.c  Sun Jun  3 13:24:46 2007
@@ -191,7 +191,7 @@
 }
 
 int
-USER_print_disk(disk_t *disk)
+USER_print_disk(disk_t *disk,  char *unit)
 {
        int fd, offset, firstoff, i;
        char mbr_buf[DEV_BSIZE];
@@ -200,14 +200,14 @@
        fd = DISK_open(disk->name, O_RDONLY);
        offset = firstoff = 0;
 
-       DISK_printmetrics(disk, NULL);
+       DISK_printmetrics(disk, unit);
 
        do {
                MBR_read(fd, (off_t)offset, mbr_buf);
                MBR_parse(disk, mbr_buf, offset, firstoff, &mbr);
 
                printf("Offset: %d\t", (int)offset);
-               MBR_print(&mbr, NULL);
+               MBR_print(&mbr, unit);
 
                /* Print out extended partitions too */
                for (offset = i = 0; i < 4; i++)
sbin/fdisk//user.h.orig --> sbin/fdisk//user.h
--- sbin/fdisk//user.h.orig     Tue Jun  3 03:13:19 2003
+++ sbin/fdisk//user.h  Sun Jun  3 13:24:46 2007
@@ -34,7 +34,7 @@
 /* Prototypes */
 int USER_init(disk_t *, mbr_t *, int);
 int USER_modify(disk_t *, mbr_t *, off_t, off_t);
-int USER_print_disk(disk_t *);
+int USER_print_disk(disk_t *, char *);
 
 #endif /* _USER_H */

Reply via email to