2004-03-23 09:22:20 +03:00
/*
* udev_lib - generic stuff used by udev
*
* Copyright ( C ) 2004 Kay Sievers < kay . sievers @ vrfy . org >
*
*
* 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 .
*
*/
# ifndef _UDEV_LIB_H_
# define _UDEV_LIB_H_
# define strfieldcpy(to, from) \
do { \
to [ sizeof ( to ) - 1 ] = ' \0 ' ; \
strncpy ( to , from , sizeof ( to ) - 1 ) ; \
} while ( 0 )
# define strfieldcat(to, from) \
do { \
to [ sizeof ( to ) - 1 ] = ' \0 ' ; \
strncat ( to , from , sizeof ( to ) - strlen ( to ) - 1 ) ; \
} while ( 0 )
# define strfieldcpymax(to, from, maxsize) \
do { \
to [ maxsize - 1 ] = ' \0 ' ; \
strncpy ( to , from , maxsize - 1 ) ; \
} while ( 0 )
# define strfieldcatmax(to, from, maxsize) \
do { \
to [ maxsize - 1 ] = ' \0 ' ; \
strncat ( to , from , maxsize - strlen ( to ) - 1 ) ; \
} while ( 0 )
# define strintcat(to, i) \
do { \
to [ sizeof ( to ) - 1 ] = ' \0 ' ; \
snprintf ( ( to ) + strlen ( to ) , sizeof ( to ) - strlen ( to ) - 1 , " %u " , i ) ; \
} while ( 0 )
# define strintcatmax(to, i, maxsize) \
do { \
to [ maxsize - 1 ] = ' \0 ' ; \
snprintf ( ( to ) + strlen ( to ) , maxsize - strlen ( to ) - 1 , " %u " , i ) ; \
} while ( 0 )
# define foreach_strpart(str, separator, pos, len) \
for ( pos = str , len = 0 ; \
( pos ) < ( ( str ) + strlen ( str ) ) ; \
pos = pos + len + strspn ( pos , separator ) , len = strcspn ( pos , separator ) ) \
if ( len > 0 )
extern char * get_action ( void ) ;
extern char * get_devpath ( void ) ;
2004-03-25 08:11:36 +03:00
extern char * get_devnode ( void ) ;
2004-03-23 09:22:20 +03:00
extern char * get_seqnum ( void ) ;
extern char * get_subsystem ( char * subsystem ) ;
[PATCH] hmm, handle net devices with udev?
Hmm, Arndt Bergmann sent a patch like this one a few weeks ago and
I want to bring the question back, if we want to handle net device
naming with udev.
With this patch it is actually possible to specify something like this
in udev.rules:
KERNEL="dummy*", SYSFS{address}="00:00:00:00:00:00", SYSFS{features}="0x0", NAME="blind%n"
KERNEL="eth*", SYSFS{address}="00:0d:60:77:30:91", NAME="private"
and you will get:
[root@pim udev.kay]# cat /proc/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 1500 30 0 0 0 0 0 0 1500 30 0 0 0 0 0 0
private: 278393 1114 0 0 0 0 0 0 153204 1468 0 0 0 0 0 0
sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
blind0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The udevinfo program is also working:
[root@pim udev.kay]# ./udevinfo -a -p /sys/class/net/private
looking at class device '/sys/class/net/private':
SYSFS{addr_len}="6"
SYSFS{address}="00:0d:60:77:30:91"
SYSFS{broadcast}="ff:ff:ff:ff:ff:ff"
SYSFS{features}="0x3a9"
SYSFS{flags}="0x1003"
SYSFS{ifindex}="2"
SYSFS{iflink}="2"
SYSFS{mtu}="1500"
SYSFS{tx_queue_len}="1000"
SYSFS{type}="1"
follow the class device's "device"
looking at the device chain at '/sys/devices/pci0000:00/0000:00:1e.0/0000:02:01.0':
BUS="pci"
ID="0000:02:01.0"
SYSFS{class}="0x020000"
SYSFS{detach_state}="0"
SYSFS{device}="0x101e"
SYSFS{irq}="11"
SYSFS{subsystem_device}="0x0549"
SYSFS{subsystem_vendor}="0x1014"
SYSFS{vendor}="0x8086"
The matching device will be renamed to the given name. The device name
will not be put into the udev database, cause the kernel renames the
device and the sysfs name disappears.
I like it, cause it plugs in nicely. We have all the naming features
and sysfs queries and walks inside of udev. The sysfs timing races
are already solved and the management tools are working for net devices
too. nameif can only match the MAC address now. udev can match any sysfs
value of the device tree the net device is connected to.
But right, net devices do not have device nodes :)
2004-03-25 10:19:39 +03:00
extern char get_device_type ( const char * path , const char * subsystem ) ;
2004-03-23 09:22:20 +03:00
extern int file_map ( const char * filename , char * * buf , size_t * bufsize ) ;
extern void file_unmap ( char * buf , size_t bufsize ) ;
extern size_t buf_get_line ( char * buf , size_t buflen , size_t cur ) ;
2004-03-27 12:21:46 +03:00
extern int call_foreach_file ( int fnct ( char * f ) , char * filename , char * extension ) ;
2004-03-23 09:22:20 +03:00
# endif