bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 512b vs. 2048b problems on IBM Power LPAR (Debian/PPC)


From: Håkon Løvdal
Subject: Re: 512b vs. 2048b problems on IBM Power LPAR (Debian/PPC)
Date: Sun, 17 Feb 2013 15:07:32 +0100

On 16 February 2013 19:35, Frank Fegert <address@hidden> wrote:
> Hello all,
>
> come to think of it, exclusion of CD/DVD type devices by major number
> might be more reliable than simple device path string comparison. Please
> see the attached patch.

That seems like a much better way to exclude CD/DVD, especially since linux's
Documentation/devices.txt says "The prefix /dev/sr (instead of /dev/scd)
has been deprecated.".

Although using a magic number 11 like that is not the most readable way
to write the code. And looking through the devices.txt file, there are several
other possibilities for CD-ROMs. I suggest putting the decision of what is a
CD-ROM into a separate function, e.g.


         if (strstr(dev->path, "/dev/mtd") == dev->path)
             continue;
+        if (is_cdrom(dev->path))
+            continue;
         if (!ped_disk_probe(dev))
             continue;

....

/**
 * Determine if a device is a CD-ROM/DVD based on major/minor device
 * number. Based on information from Linux's Documentation/devices.txt.
 */
bool is_cdrom(const char * const device_name)
{
        struct stat st;

        if (stat(device_name, &st) != 0)
                return false;

        switch (major(st.st_rdev)) {
        case 11: /* SCSI CD-ROM devices */
        case 113: /* Parallel port ATAPI CD-ROM devices */
                return true;
        default:
                break;
        }

        if (minor(st.st_rdev) == 0) {
                switch (major(st.st_rdev)) {
                case 15: /* Sony CDU-31A/CDU-33A CD-ROM */
                case 16: /* GoldStar CD-ROM */
                case 17: /* Optics Storage CD-ROM */
                case 18: /* Sanyo CD-ROM */
                case 20: /* Hitachi CD-ROM */
                case 23: /* Mitsumi proprietary CD-ROM */
                case 24: /* Sony CDU-535 CD-ROM */
                case 29: /* Aztech/Orchid/Okano/Wearnes CD-ROM */
                case 30: /* Philips LMS CM-205 CD-ROM */
                case 32: /* Philips LMS CM-206 CD-ROM */
                        return true;
                default:
                        break;
                }
        }

        if (minor(st.st_rdev) >= 0 && minor(st.st_rdev) <= 3) {
                switch (major(st.st_rdev)) {
                case 25: /* First Matsushita (Panasonic/SoundBlaster: CD-ROM */
                case 26: /* Second Matsushita (Panasonic/SoundBlaster: CD-ROM */
                case 27: /* Fourth Matsushita (Panasonic/SoundBlaster: CD-ROM */
                case 27: /* Third Matsushita (Panasonic/SoundBlaster: CD-ROM */
                case 46: /* Parallel port ATAPI CD-ROM devices */
                        return true;
                default:
                        break;
                }
        }

        return false;
}

(The function above is only written directly in this email, not
compiled and tested.)

Many of these additional devices are dated and probably not in use
by anyone today, but there are no performance penalties in handling
everything in a function like that.

BR Håkon Løvdal



reply via email to

[Prev in Thread] Current Thread [Next in Thread]