Activity log for bug #69087

Date Who What changed Old value New value Message
2006-10-29 16:05:54 moma bug added bug
2006-10-29 16:07:04 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions on this Ubuntu (Eedgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. I studied the source code of "pmount" utility and found at least two erors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with number 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions on this Ubuntu (Eedgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. I studied the source code of "pmount" utility and found at least two erors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with number 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ----
2006-10-29 16:10:27 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions on this Ubuntu (Eedgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. I studied the source code of "pmount" utility and found at least two erors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with number 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. I studied the source code of "pmount" utility and found at least two erors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with number 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ----
2006-10-29 16:11:52 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. I studied the source code of "pmount" utility and found at least two erors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with number 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. I studied the source code of "pmount" utility and found at least two erors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. You can verify this by reading the manual page for pmount. $ man pmount This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with number 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ----
2006-10-29 16:16:42 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. I studied the source code of "pmount" utility and found at least two erors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. You can verify this by reading the manual page for pmount. $ man pmount This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with number 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two erors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. You can verify this by reading the manual page for pmount. $ man pmount This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with number 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ----
2006-10-29 16:16:42 moma name fixed-pmount
2006-10-29 16:17:09 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two erors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. You can verify this by reading the manual page for pmount. $ man pmount This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with number 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. You can verify this by reading the manual page for pmount. $ man pmount This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with number 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ----
2006-10-29 16:18:01 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. You can verify this by reading the manual page for pmount. $ man pmount This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with number 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with number 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ----
2006-10-29 16:19:23 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with number 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ----
2006-10-29 16:27:18 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } -------------------------------------------------------------- Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ----
2006-10-29 16:36:26 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount --- end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 16:46:27 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed so the case is solved correctly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 16:48:14 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed so the case is solved correctly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (owner root, group plugdev in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed so the case is solved correctly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 17:18:34 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed so the case is solved correctly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 17:19:44 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount You can set it like this (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 17:27:19 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 17:33:03 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. The code has no ability to resolve the actual device name via "/etc/blkid.tab" file. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 17:34:18 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. The code has no ability to resolve the actual device name via "/etc/blkid.tab" file. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to find the actual device name via "/etc/blkid.tab" file. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 17:49:58 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to find the actual device name via "/etc/blkid.tab" file. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 18:02:05 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 18:31:57 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet in GNOME and noticed that it was unable to mount any fixed (normal) harddrive partitions on this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 18:31:57 moma title Problem when mounting fixed harddrives (partitions) Problem when mounting fixed harddrives (partitions). Pmount issue.
2006-10-29 18:32:23 moma name fixed-pmount fix-pmount
2006-10-29 18:33:02 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet in GNOME and noticed that it was unable to mount any fixed (normal) harddrive partitions on this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet in GNOME and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 18:47:34 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet in GNOME and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is empty) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet in GNOME and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is not set) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 18:52:52 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet in GNOME and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is not set) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study "utils.c", get_root() function. void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet in GNOME and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is not set) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study pmount's "utils.c" file, function get_root(). void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 20:16:24 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet in GNOME and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that. I downloaded source code for "pmount" utlity from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is not set) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study pmount's "utils.c" file, function get_root(). void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet in GNOME and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that. I downloaded source code for "pmount" program from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is not set) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study pmount's "utils.c" file, function get_root(). void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ----
2006-10-29 20:18:47 moma description Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet in GNOME and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that. I downloaded source code for "pmount" program from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is not set) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study pmount's "utils.c" file, function get_root(). void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Binary package hint: pmount Problem when mounting fixed harddrives (partitions). Hello, I just started to use the "Disk Mounter" applet in GNOME and noticed that it was unable to mount any fixed (normal) harddrive partitions in this Ubuntu (Edgy Eft) PC. The "Disk Mounter" is an handy applet that lets you mount/open/unmount external devices such as external harddrives, USB cameras, USB memory sticks etc. Check this ( http://www.futuredesktop.org/images/Add-to-panel2.png ) picture if you do not know about "Disk Mounter" applet. It should also be able to mount and umount partitions of normal scsi and ide drives, but I noticed that it unmounts all partitions correctly but IT CANNOT remount them back. "Disk Mounter" applet uses GNOME's VFS (Virtual File System) to find information about the drives and their status. And it calls "pmount" and "pumount" utilites to perform the actual mount/umount jobs. When it comes to fixed harddrives and partitions (those that are not removable devices), pmount performs a normal "mount" or "umount" commands to do the job. You can verify this by reading the manual page for pmount. $ man pmount I studied the source code of "pmount" utility and found at least two errors or "lack of functionality". ========= Error 1: ========= Pmount fails to perform correct mount when there is UUID or LABEL in the first field in /etc/fstab. It cannot resolve the correct device name (eg. /dev/sda1) so the subsequent "mount" command fails. Pmount executes a normal "mount" command when it handles fixed harddrives and partitions. This my /etc/fstab. $ cat /etc/fstab # --------------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 /media/sda1 ext3 defaults 0 2 # /dev/sda5 LABEL=BIGGY /media/sda5 ext3 defaults 0 2 # /dev/sda8 UUID=4c6f9d6b-9dca-4ac6-bdb8-a1613e2580a9 /media/sda8 ext3 defaults,errors=remount-ro 0 1 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # --------------------------------------------------------------------------------------- As you can see, the volumes for /dev/sda1, sda5 and sda8 are identified by UUID or LABEL. "Disk Mounter" (I mean pmount) fails to perform correct mount when there is UUID or LABEL in the first field. Pmount has no ability to resolve device names via "/etc/blkid.tab" file. The libblkid-dev library has special functions to do that. I downloaded source code for "pmount" program from http://packages.debian.org/unstable/source/pmount It contains code for "pumount" as well. Of course I should have taken the source from Edgy Eft's repository but I wasn't able to find it. But I assume that the code in Debian and Edgy Eft is rather similar and the errors are present in both. Let's examine these errors: Download source code for "pmount". Open "pmount.c" file and stydy the code in "main()" function. The fstab_has_device(...) functions fails to return correct device name (fstab_device is not set) therefore the if statement ( if( mode == MOUNT && fstab_device ) fails and the program continues below it. That is wrong. ..... fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL ); if( mode == MOUNT && fstab_device ) { if( arg2 ) fprintf( stderr, _("Warning: device %s is already handled by /etc/fstab," " supplied label is ignored\n"), fstab_device ); do_mount_fstab( fstab_device ); <--- It should have done this return E_EXECMOUNT; } ..... ---------------------------------------------- Open "policy.c" file and study the fstab_has_device(...) function. I have added code that converts UUID= and LABEL= to the actual device name. Eg. "UUID=465f0fb2-f7c6-41e3-b35b-a4110adc3fc2" will resolve to "/dev/sda1" and "LABEL=BIGGY" will give device name "/dev/sda5". These changes reguire "libblkid-dev" library. $ sudo apt-get install libblkid-dev and include #include <blkid/blkid.h> Link the code with "-lblkid" library. Add "blkid" to the Makefile or configuration. I just modified the Makefile and changed LIBS = -lsysfs -lblkid --- All new lines are marked with numbers 1 - 50. const char *fstab_has_device( const char *fname, const char* device, char* mntpt, int *uid ) { FILE* f; struct mntent *entry; char pathbuf[PATH_MAX]; static char fstab_device[PATH_MAX]; char* realdev; char* uidopt; 1 blkid_cache blk_cache; 2 char *ret_type, *ret_val; 3 char *dev_name; 4 5 blkid_dev blk_dev; if( !( f = fopen( fname, "r" ) ) ) { perror( _("Error: could not open fstab-type file") ); exit( 100 ); } while( ( entry = getmntent( f ) ) != NULL ) { 6 /* Get blkid_cache handle for /etc/blkid.tab file */ 7 if (blkid_get_cache(&blk_cache, NULL) != 0) 8 { 9 fprintf( stderr, _("policy.c, blkid_get_cache: error creating cache for /etc/blkid.tab!\n") ); 10 } 11 12 ret_type = ret_val = NULL; 13 blkid_parse_tag_string(entry->mnt_fsname, &ret_type, &ret_val); 14 15 if (!ret_val) 16 { 17 /* Found device name in the 1.st column of the /etc/fstab file. OK. */ 18 /* Eg: /dev/sda5 /media/sda5 ext3 defaults 0 2 */ 19 snprintf( fstab_device, sizeof( fstab_device ), "%s", entry->mnt_fsname ); 20 } 21 else 22 { 23 /* The 1.st column in the /etc/fstab is a block device id (UUID) or LABEL. */ 24 /* Eg: UUID=160f3620-2f02-46e3-8a38-b9190679057a /media/sda5 ext3 defaults 0 2 */ 25 26 /* Convert UUID or LABEL to device name (blkid* functions that work on /etc/blkid.tab file). */ 27 28 debug("fstab_has_device: %s, converting %s=\"%s\" to device name.\n", fname, ret_type, ret_val); 29 30 blk_dev = NULL; 31 blk_dev = blkid_find_dev_with_tag(blk_cache, ret_type, ret_val); 32 33 /* blk_dev = blkid_verify(blk_cache, blk_dev); -- it's OK */ 34 35 if (blk_dev) 36 { 37 dev_name = blkid_dev_devname(blk_dev); 38 39 snprintf( fstab_device, sizeof( fstab_device ), "%s", dev_name); 40 41 debug("fstab_has_device: The device name is %s\n", fstab_device); 42 43 /* string_free(dev_name); --- Should we free this string ?? */ 44 } 45 } 46 47 48 /* if (blk_cache) --- Should we free this cache ?? 49 blkid_free_cache(blk_cache); 50 */ if( realpath( fstab_device, pathbuf ) ) realdev = pathbuf; else realdev = fstab_device; if( !strcmp( realdev, device ) ) { endmntent( f ); if( mntpt ) { snprintf( mntpt, MEDIA_STRING_SIZE-1, "%s", entry->mnt_dir ); } if( uid ) { uidopt = hasmntopt( entry, "uid" ); if( uidopt ) uidopt = strchr( uidopt, '=' ); if( uidopt ) { ++uidopt; /* skip the '=' */ /* FIXME: this probably needs more checking */ *uid = atoi( uidopt ); } else *uid = -1; } return fstab_device; } } /* just for safety */ if( mntpt ) *mntpt = 0; endmntent( f ); return NULL; } ------------------------------------------------------------- I uploaded the code to http://www.futuredesktop.org/tmp/changes_in_policy.c Now the function returns correct device name (eg. /dev/sda2 ) and the "mount" command succeeds. See do_mount_fstab( fstab_device ); in pmount.c, function main(). It performs the command similar to this: $ sudo mount /dev/sda1 Another (alternative) solution would be to pass UUID or LABEL to the "mount" command. These mounts are completly valid: $ sudo mount -U 465f0fb2-f7c6-41e3-b35b-a4110adc3fc2 and $ sudo mount -L BIGGY Of course the improvements should be done in Edgy Eft's version of pmount and more eyeballs are needed to solve this matter properly. -------------------------------------------------------------- ============== Possible error 2: ============== get_root() function does not give proper ROOT rights. Mount command fails due to lack of root privileges. That's my theory ;-) Study pmount's "utils.c" file, function get_root(). void get_root() { if( setreuid( -1, 0 ) ) { perror( _("Internal error: could not change to effective uid root") ); exit( 100 ); } } I think that it should be setresuid(0, 0, 0); or similar instead of setreuid(-1, 0); At least, I had to change my test-code to "setresuid(0, 0, 0)". Then the execl( MOUNTPROG, MOUNTPROG, device, NULL ) command in do_mount_fstab(...) function performs right. Without it, it just says "no rights..." ---- Anyway, I must study this issue more thoroughly. Notice that "pmount" must have setuid (s) bit set. The correct access rights are: $ ls -l /usr/bin/pmount -rwsr-xr-- 1 root plugdev 76183 2006-10-29 15:45 pmount This is how to set the rights (group plugdev is a must in Debian and Ubuntu). $ sudo chown root:plugdev pmount Setuid (s bit) $ sudo chmod 4754 pmount -------------------------------------------------------------------------- System information: $ cat /etc/*release* DISTRIB_ID=Ubuntu DISTRIB_RELEASE=6.10 DISTRIB_CODENAME=edgy DISTRIB_DESCRIPTION="Ubuntu 6.10" Ordninary 32 bits Edgy Eft. $ uname -a Linux moma-desktop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux --- the end ---- Related report: o--> https://launchpad.net/distros/ubuntu/+source/pmount/+bug/20178
2006-10-30 08:29:43 Martin Pitt pmount: status Unconfirmed In Progress
2006-10-30 08:29:43 Martin Pitt pmount: importance Undecided Medium
2006-10-30 08:29:43 Martin Pitt pmount: statusexplanation The problem that pmount does not find UUID/LABEL mounts is already known, as you pointed out. Thanks a lot for your code contribution to fix this! However, pmount is *designed* to not mount static fixed hard disk partitions for security reasons. It works pretty hard to ensure that the device to be mounted is indeed removable, otherwise the user could easily mess up system partitions, peek in other /home directories, etc. The latter problem needs to be addressed in a different way, we'll talk about this on the next conference: https://features.launchpad.net/distros/ubuntu/+spec/mount-all-local-filesystems
2006-10-30 08:29:43 Martin Pitt pmount: assignee pitti
2006-10-30 08:30:48 Martin Pitt name fix-pmount pmount-uuid
2006-10-30 08:30:48 Martin Pitt title Problem when mounting fixed harddrives (partitions). Pmount issue. does not find devices by label/uuid
2007-02-06 09:16:47 Martin Pitt pmount: status In Progress Confirmed
2007-02-06 09:16:47 Martin Pitt pmount: statusexplanation The problem that pmount does not find UUID/LABEL mounts is already known, as you pointed out. Thanks a lot for your code contribution to fix this! However, pmount is *designed* to not mount static fixed hard disk partitions for security reasons. It works pretty hard to ensure that the device to be mounted is indeed removable, otherwise the user could easily mess up system partitions, peek in other /home directories, etc. The latter problem needs to be addressed in a different way, we'll talk about this on the next conference: https://features.launchpad.net/distros/ubuntu/+spec/mount-all-local-filesystems Status update: This is not an issue in feisty any more. Feisty now uses gnome-mount and the hal mount backend, which does find devices by uuid/label.
2007-07-03 22:39:07 Vincent Fourmond pmount: status Confirmed Fix Released
2007-07-03 22:39:07 Vincent Fourmond pmount: assignee pitti fourmond
2007-07-03 22:39:07 Vincent Fourmond pmount: statusexplanation Status update: This is not an issue in feisty any more. Feisty now uses gnome-mount and the hal mount backend, which does find devices by uuid/label. This is completely fixed in version 0.9.16 of pmount. Just try out pmount LABEL=my_nice_label and pumount LABEL=my_nice_label Provided that you have the LABEL=my_nice_label entry in /etc/fstab, pmount will just forward the query to mount (without root privileges).