Hi Pascal,

On Mon, Sep 03, 2007 at 12:06:51AM +0200, Pascal Terjan wrote:
> When editing a disk image, fdisk wants to ask the kernel to reread the
> partition table which is useless and provokes an error, a wrong exit
> code and some waiting. This annoys me as I can't check the return code
> in my script and because I have to wait a few seconds each time.
> 
> This trivial patch makes it only do the ioctl on block devices.

 Please, add "Signed-off-by:" to your patch.

> +     fstat(fd, &statbuf);

 rc = fstat(fd, &statbuf);
 if (rc == -1) {
    fprintf(stderr, _("re-read partition table: could not stat: %s\n",
        strerror(errno));
 } else if S_ISBLK(statbuf.st_mode)) {
 ....

 Be pedantic :-)

>  
> -     if (i) {
> -             printf(_("\nWARNING: Re-reading the partition table "
> -                      "failed with error %d: %s.\n"
> -                      "The kernel still uses the old table.\n"
> -                      "The new table will be used "
> -                      "at the next reboot.\n"),
> -                     error, strerror(error));
> -     }
> +     if(S_ISBLK(statbuf.st_mode)) { /* block device */
> +             printf(_("Calling ioctl() to re-read partition table.\n"));
> +             sync();
> +             sleep(2);
> +             if ((i = ioctl(fd, BLKRRPART)) != 0) {
> +                     error = errno;
> +             } else {
> +                     /* some kernel versions (1.2.x) seem to have trouble
> +                        rereading the partition table, but if asked to do it
> +                        twice, the second time works. - [EMAIL PROTECTED] */
> +                     sync();
> +                     sleep(2);
> +                     if ((i = ioctl(fd, BLKRRPART)) != 0)
> +                             error = errno;
> +             }

 I think we needn't this stupid code for 1.2.x kernels.

    Karel

-- 
 Karel Zak  <[EMAIL PROTECTED]>
-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to