All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Frantisek Rysanek" <Frantisek.Rysanek@post.cz>
To: dwmw2@infradead.org
Cc: linux-mtd@lists.infradead.org
Subject: BLKRRPART bug + fix in mtd_blkdevs-24.c in mtd-snapshot-20040914.tar.bz2
Date: Thu, 16 Sep 2004 14:36:08 +0200	[thread overview]
Message-ID: <4149A4D8.29869.10649001@localhost> (raw)

[-- Attachment #1: Mail message body --]
[-- Type: text/plain, Size: 1087 bytes --]

Dear Mr. Woodhouse,

I've found a bug in the functions serving the BLKRRPART 
ioctl() in the 2.4 branch of MTD blkdevs. See the attached 
patch, I believe it contains a fix.

My DiskOnChip was detected just fine, but when I flushed the 
original partition and issued a BLKRRPART, the device would 
report half its original size. If I did it again, it would
report a quarter size... etc.

Seems like the driver would re-init device size to a size 
denominated in 1k blocks, rather than sectors (512B).

Attached are two simple proggies that I'm using in my 
partitioning scripts.


Otherwise the driver seems to work just fine.
Actually I also had to insert 

#ifndef CONFIG_MTD_CFI_GEOMETRY
#define CONFIG_MTD_MAP_BANK_WIDTH_1
#endif

at the beginning of $KERNEL/include/linux/mtd/map.h

to make it compile. Seems like a dependency mismatch between 
drivers/mtd/chips/Config.in and the headers/code. I don't have 
a CFI MTD, but I do need drivers/mtd/chips/chipreg.o even for 
my DiskOnChip (now a generic NFTL device).


Thanks for the great job you're doing on MTD :-)

Frank Rysanek


[-- Attachment #2: Text from file 'mtd_blkdevs-24.c.patch' --]
[-- Type: text/plain, Size: 284 bytes --]

--- mtd_blkdevs-24.old.c	2004-09-16 12:51:08.000000000 +0200
+++ mtd_blkdevs-24.c	2004-09-16 12:54:38.000000000 +0200
@@ -315,7 +315,7 @@
 	}
 
 	grok_partitions(gd, minor, 1 << tr->part_bits, 
-			tr->blkcore_priv->sizes[minor]);
+			dev->size);
 	up(&mtd_table_mutex);
 
 	return 0;

[-- Attachment #3: Attachment information. --]
[-- Type: text/plain, Size: 476 bytes --]

The following section of this message contains a file attachment
prepared for transmission using the Internet MIME message format.
If you are using Pegasus Mail, or any other MIME-compliant system,
you should be able to save it or view it from within your mailer.
If you cannot, please ask your system administrator for assistance.

   ---- File information -----------
     File:  reset_disk.c
     Date:  16 Sep 2004, 13:23
     Size:  989 bytes.
     Type:  Program-source

[-- Attachment #4: reset_disk.c --]
[-- Type: Application/Octet-stream, Size: 989 bytes --]

#include <stdio.h>         // general I/O
#include <fcntl.h>         // options for open()
#define O_LARGEFILE    0100000
#include <sys/ioctl.h>     // provides ioctl()
#include <linux/fs.h>      // BLKRRPART

int main(int argc, char** argv, char** env)
{
 int fd = -1;
 int err = 0;
 char* filename = NULL;

   if (argc > 1)
   {
      filename = argv[1];
   } 
   else
   {
      printf("Usage example: reset_disk /dev/hda\n");
      printf("Calls the BLKRRPART ioctl() to make kernel re-read and re-interpret partition table.\n");
      printf("This only works if no devices (filesystems) are currently mounted off that disk.\n");
      exit(1);
   }

   fd = open(filename, O_RDONLY|O_LARGEFILE);
   if (fd <= 0)
   {
      printf("Unable to open %s. Exiting\n", filename);
      exit(1);
   }

   err = ioctl(3, BLKRRPART, NULL);
   if (err)
   {
      printf("Error re-reading partition tables using the BLKRRPART ioctl().\n");
      exit(1);
   }

   close(fd);
   
   return(0);
}

[-- Attachment #5: Attachment information. --]
[-- Type: text/plain, Size: 471 bytes --]

The following section of this message contains a file attachment
prepared for transmission using the Internet MIME message format.
If you are using Pegasus Mail, or any other MIME-compliant system,
you should be able to save it or view it from within your mailer.
If you cannot, please ask your system administrator for assistance.

   ---- File information -----------
     File:  geom.c
     Date:  16 Sep 2004, 13:23
     Size:  1569 bytes.
     Type:  Program-source

[-- Attachment #6: geom.c --]
[-- Type: Application/Octet-stream, Size: 1569 bytes --]

#include <stdio.h>         // general I/O
#include <fcntl.h>         // options for open()
#define O_LARGEFILE    0100000
#include <sys/ioctl.h>     // provides ioctl()
#include <linux/fs.h>      // BLKGETSIZE
#include <linux/hdreg.h>   // HDIO_GETGEO_BIG

int main(int argc, char** argv, char** env)
{
 int fd = -1;
 int err = 0;
 struct hd_big_geometry big_geom;   // unsigned int cyls
 struct hd_geometry geom;           // unsigned short cyls
 unsigned int size = 0;
 char* filename = NULL;

   if (argc > 1)
   {
      filename = argv[1];
   } 
   else
   {
      printf("Usage example: geom /dev/hda\n");
      printf("Output:  Cylinders/Heads/Sectors_per_track/Capacity   (in sectors)\n");
      exit(1);
   }

      
   fd = open(filename, O_RDONLY|O_LARGEFILE);
   if (fd <= 0)
   {
      printf("Unable to open %s. Exiting\n", filename);
      exit(1);
   }

   err = ioctl(3, BLKGETSIZE, &size);
   if (err)
   {
      printf("Error getting capacity using BLKGETSIZE\n");
      exit(1);
   }

   geom.cylinders = 0;
   geom.heads = 0;
   geom.sectors = 0;
   err = ioctl(3, HDIO_GETGEO_BIG, &big_geom);
   if (err)
   {
      err = ioctl(3, HDIO_GETGEO, &geom);
      if (err)
      {
         printf("Error retrieving geometry - both HDIO_GETGEO_BIG and HDIO_GETGEO failed.\n");
         exit(1);
      }
      else
      {
         printf("%u/%u/%u/%u\n",geom.cylinders, geom.heads, geom.sectors, size);
      }
   }
   else
   {
      printf("%u/%u/%u/%u\n",big_geom.cylinders, big_geom.heads, big_geom.sectors, size);
   }

   close(fd);
   return(0);
}

                 reply	other threads:[~2004-09-16 12:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4149A4D8.29869.10649001@localhost \
    --to=frantisek.rysanek@post.cz \
    --cc=dwmw2@infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.