[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-06-26 20:55:24 +04:00
* vol_id - udev callout to read filesystem label and 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
*
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
*
* 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 .
*
*/
2005-03-11 04:31:58 +03:00
# ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
# endif
[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
# 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"
[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)
2005-03-06 12:15:51 +03:00
# ifdef USE_LOG
2005-06-05 07:17:21 +04:00
void log_message ( int priority , const char * format , . . . )
2004-05-12 11:52:52 +04:00
{
va_list args ;
2005-06-05 07:17:21 +04:00
static int udev_log = - 1 ;
if ( udev_log = = - 1 ) {
const char * value ;
value = getenv ( " UDEV_LOG " ) ;
if ( value )
udev_log = log_priority ( value ) ;
else
udev_log = LOG_ERR ;
}
if ( priority > udev_log )
return ;
2004-05-12 11:52:52 +04:00
va_start ( args , format ) ;
2005-06-05 07:17:21 +04:00
vsyslog ( priority , format , args ) ;
2004-05-12 11:52:52 +04:00
va_end ( args ) ;
}
# endif
2005-08-01 03:33:36 +04:00
static void set_str ( char * to , const char * from , size_t count )
2005-06-26 03:54:47 +04:00
{
2005-08-01 03:33:36 +04:00
size_t i , j , len ;
2005-06-26 03:54:47 +04:00
2005-08-01 03:33:36 +04:00
/* strip trailing whitespace */
2005-06-26 03:54:47 +04:00
len = strnlen ( from , count ) ;
2005-08-22 13:37:12 +04:00
while ( len & & isspace ( from [ len - 1 ] ) )
2005-06-26 03:54:47 +04:00
len - - ;
2005-08-01 03:33:36 +04:00
/* strip leading whitespace */
2005-06-26 03:54:47 +04:00
i = 0 ;
while ( isspace ( from [ i ] ) & & ( i < len ) )
i + + ;
j = 0 ;
while ( i < len ) {
2005-08-01 03:33:36 +04:00
/* substitute multiple whitespace */
if ( isspace ( from [ i ] ) ) {
while ( isspace ( from [ i ] ) )
i + + ;
2005-06-26 03:54:47 +04:00
to [ j + + ] = ' _ ' ;
}
2005-08-01 03:33:36 +04:00
/* skip chars */
if ( from [ i ] = = ' / ' ) {
i + + ;
continue ;
}
to [ j + + ] = from [ i + + ] ;
2005-06-26 03:54:47 +04:00
}
to [ j ] = ' \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
int main ( int argc , char * argv [ ] )
{
2005-06-26 20:55:24 +04:00
const char help [ ] = " usage: vol_id [--export|-t|-l|-u] <device> \n "
2005-06-26 03:54:47 +04:00
" --export \n "
2004-05-12 11:52:52 +04:00
" -t filesystem type \n "
" -l filesystem label \n "
" -u filesystem uuid \n "
" \n " ;
2005-06-26 03:54:47 +04:00
enum print_type {
PRINT_EXPORT ,
PRINT_TYPE ,
PRINT_LABEL ,
PRINT_UUID ,
} print = PRINT_EXPORT ;
2004-05-12 11:52:52 +04:00
struct volume_id * vid = NULL ;
static char name [ VOLUME_ID_LABEL_SIZE ] ;
2005-06-26 03:54:47 +04:00
int i ;
2005-08-01 03:33:36 +04:00
uint64_t size ;
2005-06-26 03:54:47 +04:00
const char * node = NULL ;
int 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
2005-06-26 20:55:24 +04:00
logging_init ( " vol_id " ) ;
2004-10-19 09:57:41 +04:00
2005-06-26 03:54:47 +04:00
for ( i = 1 ; i < argc ; i + + ) {
char * arg = argv [ i ] ;
if ( strcmp ( arg , " --export " ) = = 0 ) {
print = PRINT_EXPORT ;
} else if ( strcmp ( arg , " -t " ) = = 0 ) {
print = PRINT_TYPE ;
} else if ( strcmp ( arg , " -l " ) = = 0 ) {
print = PRINT_LABEL ;
} else if ( strcmp ( arg , " -u " ) = = 0 ) {
print = PRINT_UUID ;
} else
node = arg ;
[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-06-26 03:54:47 +04:00
if ( ! node ) {
err ( " no node specified " ) ;
fprintf ( stderr , help ) ;
rc = 1 ;
goto exit ;
2004-05-12 11:52:52 +04:00
}
2005-06-26 03:54:47 +04:00
vid = volume_id_open_node ( node ) ;
2005-02-10 11:35:52 +03:00
if ( vid = = NULL ) {
2005-07-13 13:23:21 +04:00
fprintf ( stderr , " %s: error open volume \n " , node ) ;
2005-06-26 03:54:47 +04:00
rc = 2 ;
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 ;
2005-09-14 16:29:59 +04:00
dbg ( " BLKGETSIZE64=%llu " , size ) ;
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-07-13 13:23:21 +04:00
if ( print ! = PRINT_EXPORT )
fprintf ( stderr , " %s: unknown volume type \n " , node ) ;
2005-06-26 03:54:47 +04:00
rc = 3 ;
2004-05-12 11:52:52 +04:00
goto exit ;
print :
2005-06-26 03:54:47 +04:00
set_str ( name , vid - > label , sizeof ( vid - > label ) ) ;
2005-08-29 01:16:56 +04:00
replace_untrusted_chars ( name ) ;
2004-05-12 11:52:52 +04:00
[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 ) {
2005-06-26 03:54:47 +04:00
case PRINT_EXPORT :
printf ( " ID_FS_USAGE=%s \n " , vid - > usage ) ;
printf ( " ID_FS_TYPE=%s \n " , vid - > type ) ;
printf ( " ID_FS_VERSION=%s \n " , vid - > type_version ) ;
printf ( " ID_FS_UUID=%s \n " , vid - > uuid ) ;
printf ( " ID_FS_LABEL=%s \n " , vid - > label ) ;
printf ( " ID_FS_LABEL_SAFE=%s \n " , name ) ;
break ;
case PRINT_TYPE :
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 ;
2005-06-26 03:54:47 +04:00
case PRINT_LABEL :
2005-02-09 03:15:35 +03:00
if ( name [ 0 ] = = ' \0 ' | |
( vid - > usage_id ! = VOLUME_ID_FILESYSTEM & & vid - > usage_id ! = VOLUME_ID_DISKLABEL ) ) {
2005-06-26 03:54:47 +04:00
rc = 3 ;
2004-05-12 11:52:52 +04:00
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 ;
2005-06-26 03:54:47 +04:00
case PRINT_UUID :
2004-09-05 20:05:36 +04:00
if ( vid - > uuid [ 0 ] = = ' \0 ' | | vid - > usage_id ! = VOLUME_ID_FILESYSTEM ) {
2005-06-26 03:54:47 +04:00
rc = 4 ;
2004-05-12 11:52:52 +04:00
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
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 ( ) ;
2005-06-26 03:54:47 +04:00
return 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
}