--- linux-1.6.12.c 2004-08-15 14:34:25.000000000 +0200 +++ linux.c 2004-08-16 15:35:10.000000000 +0200 @@ -1464,6 +1464,55 @@ return result; } +/*Returns partitionname as described in /proc/partitions */ +static char* +linux_partition_get_short_part_path (const PedPartition* part) +{ + char* complete_path ;//[512]; + + PED_ASSERT (part != NULL, return NULL); + + if (part->num == -1) + return NULL; + + //get major and minor from device this partition exists on + struct stat dev_stat; + + _device_stat( part->disk->dev, &dev_stat ); + int device_major = major (dev_stat.st_rdev); + int device_minor = minor (dev_stat.st_rdev) + part->num ; + + //walk trough /proc/partitions till major and minor match, then construct the proper part_path + char temp[512]; + char part_name[512]; + int major_temp, minor_temp, size_temp; + FILE* proc_part_file; + + proc_part_file = fopen ("/proc/partitions", "r"); + if (!proc_part_file) + return 0; + + //skip first 2 useless rules of /proc/partitions + fgets (temp, 256, proc_part_file); + fgets (temp, 256, proc_part_file); + + while (fgets (temp, 512, proc_part_file) && sscanf (temp, "%d %d %d %255s", &major_temp, &minor_temp, &size_temp, part_name) == 4) + if ( major_temp == device_major && minor_temp == device_minor ) + { + complete_path = (char*) ped_malloc ( strlen(part_name) + 16 );//6 should be fine (but... safe side story ;) ) + if (!complete_path) + break; + + strcpy( complete_path, "/dev/" ); + strcat( complete_path, part_name ); + break; + } + + fclose (proc_part_file); + + return complete_path ; +} + static char* linux_partition_get_path (const PedPartition* part) { @@ -1475,25 +1524,35 @@ static int _partition_is_root_device (const char* part_name) { - unsigned int root_dev; struct stat part_stat; - FILE* proc_real_root_dev; - + /* even though this is an error, it probably means the partition * doesn't exist, etc., and therefore isn't root ;) */ if (stat (part_name, &part_stat)) return 0; - - proc_real_root_dev = fopen ("/proc/sys/kernel/real-root-dev", "r"); - if (!proc_real_root_dev) - goto error; - fscanf (proc_real_root_dev, "%d", &root_dev); - fclose (proc_real_root_dev); - return root_dev == part_stat.st_rdev; - -error: - return -1; + + //====kernel 2.4 check... + unsigned int root_dev; + FILE* proc_real_root_dev = fopen ("/proc/sys/kernel/real-root-dev", "r"); + + if (proc_real_root_dev) + { + fscanf (proc_real_root_dev, "%d", &root_dev); + fclose (proc_real_root_dev); + if ( root_dev == part_stat.st_rdev ) + return 1; + } + + + //====kernel 2.6 check... (in this kernelseries /dev/root is a symlink to the real rootpartitionpath + char real_root_path[4096]; + char real_part_path[4096]; + + realpath( "/dev/root", real_root_path ); + realpath( part_name, real_part_path ); + + return ! strcmp(real_part_path, real_root_path); } /* returns: @@ -1549,29 +1608,32 @@ { static int can_probe = 1; - if (!can_probe) - return 0; - - switch (_partition_is_root_device (path)) { - case 1: return 1; - case -1: goto unknown; + switch ( _mount_table_search ("/proc/mounts", path) ) { + case 1: return 1; + case -1: can_probe = 0; } - switch (_mount_table_search ("/proc/mounts", path)) { - case 1: return 1; - case -1: - switch (_mount_table_search ("/etc/mtab", path)) { - case 1: return 1; - case -1: goto unknown; - } + + switch ( _mount_table_search ("/etc/mtab", path) ) { + case 1: return 1; + case -1: can_probe = 0; } + switch (_mount_table_search ("/proc/swaps", path)) { case 1: return 1; - case -1: goto unknown; + case -1: can_probe = 0; } + + if ( _partition_is_root_device (path)) + return 1; + + + if ( ! can_probe ) + goto unknown; + + return 0; unknown: - can_probe = 0; return ped_exception_throw ( PED_EXCEPTION_WARNING, PED_EXCEPTION_IGNORE_CANCEL, @@ -1593,12 +1655,24 @@ if (part->num == -1) return 0; - part_name = _device_get_part_path (part->geom.dev, part->num); + //short path first (most likely match) + part_name = linux_partition_get_short_part_path( part ) ; if (!part_name) - return 0; - + return 0; + status = _partition_is_mounted_by_path (part_name); ped_free (part_name); + + if ( ! status ) + { + part_name = _device_get_part_path (part->geom.dev, part->num); + if (!part_name) + return 0; + + status = _partition_is_mounted_by_path (part_name); + ped_free (part_name); + } + return status; }