[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
/*
* udev_volume_id - udev callout to read filesystem label and uuid
*
2005-02-10 11:35:52 +03:00
* Copyright ( C ) 2005 Kay Sievers < kay . sievers @ vrfy . org >
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
*
* sample udev rule for creation of a symlink with the filsystem uuid :
2005-02-10 11:35:52 +03:00
* KERNEL = " sd* " , PROGRAM = " /sbin/udev_volume_id -u %N " , SYMLINK = " %c "
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
*
* This program is free software ; you can redistribute it and / or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License .
*
* This program is distributed in the hope that it will be useful , but
* WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* General Public License for more details .
*
* You should have received a copy of the GNU General Public License along
* with this program ; if not , write to the Free Software Foundation , Inc . ,
* 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*
*/
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
2004-09-19 10:22:27 +04:00
# include <string.h>
2004-05-12 11:52:52 +04:00
# include <ctype.h>
2004-09-05 20:05:36 +04:00
# include <sys/ioctl.h>
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
2004-12-09 06:35:29 +03:00
# include "../../udev_utils.h"
2004-05-12 11:52:52 +04:00
# include "../../logging.h"
2005-01-31 07:28:44 +03:00
# include "volume_id/volume_id.h"
2005-02-23 04:58:31 +03:00
# include "volume_id/dasd.h"
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
2004-09-19 10:22:27 +04:00
# define BLKGETSIZE64 _IOR(0x12,114,size_t)
2004-05-12 11:52:52 +04:00
# ifdef LOG
void log_message ( int level , const char * format , . . . )
{
va_list args ;
va_start ( args , format ) ;
vsyslog ( level , format , args ) ;
va_end ( args ) ;
}
# endif
2005-02-10 11:35:52 +03:00
extern int optind ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
2004-05-12 11:52:52 +04:00
int main ( int argc , char * argv [ ] )
{
2005-02-10 11:35:52 +03:00
const char help [ ] = " usage: udev_volume_id [-t|-l|-u] <device> \n "
2004-05-12 11:52:52 +04:00
" -t filesystem type \n "
" -l filesystem label \n "
" -u filesystem uuid \n "
" \n " ;
2005-02-10 11:35:52 +03:00
static const char short_options [ ] = " htlu " ;
2004-05-12 11:52:52 +04:00
struct volume_id * vid = NULL ;
2005-02-10 11:35:52 +03:00
const char * device ;
2004-05-12 11:52:52 +04:00
char print = ' a ' ;
static char name [ VOLUME_ID_LABEL_SIZE ] ;
int len , i , j ;
2004-09-05 20:05:36 +04:00
unsigned long long size ;
2004-05-12 11:52:52 +04:00
int rc = 1 ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
2004-10-19 09:57:41 +04:00
logging_init ( " udev_volume_id " ) ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
while ( 1 ) {
2004-09-05 20:05:36 +04:00
int option ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
option = getopt ( argc , argv , short_options ) ;
if ( option = = - 1 )
break ;
switch ( option ) {
case ' t ' :
print = ' t ' ;
2004-05-12 11:52:52 +04:00
continue ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
case ' l ' :
print = ' l ' ;
2004-05-12 11:52:52 +04:00
continue ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
case ' u ' :
print = ' u ' ;
2004-05-12 11:52:52 +04:00
continue ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
case ' h ' :
case ' ? ' :
default :
printf ( help ) ;
exit ( 1 ) ;
}
}
2005-02-10 11:35:52 +03:00
device = argv [ optind ] ;
if ( device = = NULL ) {
printf ( help ) ;
exit ( 1 ) ;
2004-05-12 11:52:52 +04:00
}
2005-02-10 11:35:52 +03:00
vid = volume_id_open_node ( device ) ;
if ( vid = = NULL ) {
printf ( " error open volume \n " ) ;
2004-05-12 11:52:52 +04:00
goto exit ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
}
2005-02-10 11:35:52 +03:00
if ( ioctl ( vid - > fd , BLKGETSIZE64 , & size ) ! = 0 )
size = 0 ;
2004-09-05 20:05:36 +04:00
2005-02-10 11:35:52 +03:00
if ( volume_id_probe_all ( vid , 0 , size ) = = 0 )
goto print ;
2004-09-05 20:05:36 +04:00
2005-02-10 11:35:52 +03:00
if ( volume_id_probe_dasd ( vid ) = = 0 )
goto print ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
2004-05-12 11:52:52 +04:00
printf ( " unknown volume type \n " ) ;
goto exit ;
print :
2004-09-05 20:05:36 +04:00
len = strnlen ( vid - > label , VOLUME_ID_LABEL_SIZE ) ;
2004-05-12 11:52:52 +04:00
/* remove trailing spaces */
2004-09-05 20:05:36 +04:00
while ( len > 0 & & isspace ( vid - > label [ len - 1 ] ) )
2004-05-12 11:52:52 +04:00
len - - ;
name [ len ] = ' \0 ' ;
/* substitute chars */
i = 0 ;
j = 0 ;
while ( j < len ) {
2004-09-05 20:05:36 +04:00
switch ( vid - > label [ j ] ) {
2004-05-12 11:52:52 +04:00
case ' / ' :
break ;
case ' ' :
name [ i + + ] = ' _ ' ;
break ;
default :
2004-09-05 20:05:36 +04:00
name [ i + + ] = vid - > label [ j ] ;
2004-05-12 11:52:52 +04:00
}
j + + ;
}
name [ i ] = ' \0 ' ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
switch ( print ) {
case ' t ' :
2004-09-05 20:05:36 +04:00
printf ( " %s \n " , vid - > type ) ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
break ;
case ' l ' :
2005-02-09 03:15:35 +03:00
if ( name [ 0 ] = = ' \0 ' | |
( vid - > usage_id ! = VOLUME_ID_FILESYSTEM & & vid - > usage_id ! = VOLUME_ID_DISKLABEL ) ) {
2004-05-12 11:52:52 +04:00
rc = 2 ;
goto exit ;
}
printf ( " %s \n " , name ) ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
break ;
case ' u ' :
2004-09-05 20:05:36 +04:00
if ( vid - > uuid [ 0 ] = = ' \0 ' | | vid - > usage_id ! = VOLUME_ID_FILESYSTEM ) {
2004-05-12 11:52:52 +04:00
rc = 2 ;
goto exit ;
}
2004-09-05 20:05:36 +04:00
printf ( " %s \n " , vid - > uuid ) ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
break ;
2004-05-12 11:52:52 +04:00
case ' a ' :
2005-01-31 07:28:44 +03:00
printf ( " F:%s \n " , vid - > usage ) ;
2004-09-05 20:05:36 +04:00
printf ( " T:%s \n " , vid - > type ) ;
printf ( " V:%s \n " , vid - > type_version ) ;
printf ( " L:%s \n " , vid - > label ) ;
2004-05-12 11:52:52 +04:00
printf ( " N:%s \n " , name ) ;
2004-09-05 20:05:36 +04:00
printf ( " U:%s \n " , vid - > uuid ) ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
}
2004-05-12 11:52:52 +04:00
rc = 0 ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
2004-05-12 11:52:52 +04:00
exit :
if ( vid ! = NULL )
volume_id_close ( vid ) ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
2004-10-19 09:57:41 +04:00
logging_close ( ) ;
2004-05-12 11:52:52 +04:00
exit ( rc ) ;
[PATCH] udev callout for reading filesystem labels
here is a small udev toy, which enables udev to name partitions by
its filesystem label or uuid's.
The following udev rule:
KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
creates a symlink with the uuid read from the filesystem. If no label or
uuid is found the program exits with nonzero and the rule will fail.
ext2, ext3, reiserfs, xfs, jfs, vfat, msdos volume labels are supported,
ntfs and swap partitions can be recognized.
It's possible to compile with klibc and the static binary takes 13kb.
2004-05-01 10:26:33 +04:00
}