2005-07-22 20:35:58 +04:00
/*
2008-09-10 04:40:42 +04:00
* Copyright ( C ) 2004 - 2008 Kay Sievers < kay . sievers @ vrfy . org >
2005-07-22 20:35:58 +04:00
*
2008-09-10 04:40:42 +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 , either version 2 of the License , or
* ( at your option ) any later version .
2005-07-22 20:35:58 +04:00
*
2008-09-10 04:40:42 +04:00
* 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 , see < http : //www.gnu.org/licenses/>.
2005-07-22 20:35:58 +04:00
*/
# include <stdlib.h>
# include <stdio.h>
# include <stddef.h>
# include <unistd.h>
# include <fcntl.h>
# include <errno.h>
# include <ctype.h>
2008-07-30 03:45:23 +04:00
# include <string.h>
2006-04-28 02:32:32 +04:00
# include <sys/ioctl.h>
# include <sys/socket.h>
2006-04-06 00:29:33 +04:00
# include <net/if.h>
# include <linux/sockios.h>
2006-01-09 23:18:00 +03:00
2005-07-22 20:35:58 +04:00
# include "udev.h"
2006-01-09 23:18:00 +03:00
# include "udev_rules.h"
2005-07-22 20:35:58 +04:00
2008-09-06 17:45:31 +04:00
struct udevice * udev_device_init ( struct udev * udev )
2005-07-22 20:35:58 +04:00
{
2008-09-06 17:45:31 +04:00
struct udevice * udevice ;
2008-09-01 22:59:09 +04:00
2008-09-06 17:45:31 +04:00
udevice = malloc ( sizeof ( struct udevice ) ) ;
if ( udevice = = NULL )
2006-01-09 23:18:00 +03:00
return NULL ;
2008-09-06 17:45:31 +04:00
memset ( udevice , 0x00 , sizeof ( struct udevice ) ) ;
2006-01-09 23:18:00 +03:00
2008-09-06 17:45:31 +04:00
udevice - > udev = udev ;
INIT_LIST_HEAD ( & udevice - > symlink_list ) ;
INIT_LIST_HEAD ( & udevice - > run_list ) ;
INIT_LIST_HEAD ( & udevice - > env_list ) ;
2005-07-22 20:35:58 +04:00
2006-01-09 23:18:00 +03:00
/* set sysfs device to local storage, can be overridden if needed */
2008-09-06 17:45:31 +04:00
udevice - > dev = & udevice - > dev_local ;
2005-07-22 20:35:58 +04:00
2006-01-09 23:18:00 +03:00
/* default node permissions */
2008-09-06 17:45:31 +04:00
udevice - > mode = 0660 ;
strcpy ( udevice - > owner , " root " ) ;
strcpy ( udevice - > group , " root " ) ;
2005-07-22 20:35:58 +04:00
2008-09-06 17:45:31 +04:00
udevice - > event_timeout = - 1 ;
return udevice ;
2005-07-22 20:35:58 +04:00
}
2008-09-06 17:45:31 +04:00
void udev_device_cleanup ( struct udevice * udevice )
2005-07-22 20:35:58 +04:00
{
2008-09-06 17:45:31 +04:00
if ( udevice = = NULL )
2008-09-01 22:59:09 +04:00
return ;
2008-09-06 17:45:31 +04:00
name_list_cleanup ( udevice - > udev , & udevice - > symlink_list ) ;
name_list_cleanup ( udevice - > udev , & udevice - > run_list ) ;
name_list_cleanup ( udevice - > udev , & udevice - > env_list ) ;
free ( udevice ) ;
2006-01-09 23:18:00 +03:00
}
2008-09-06 17:45:31 +04:00
dev_t udev_device_get_devt ( struct udevice * udevice )
2006-01-09 23:18:00 +03:00
{
const char * attr ;
2006-08-24 12:25:34 +04:00
unsigned int maj , min ;
2006-01-09 23:18:00 +03:00
/* read it from sysfs */
2008-09-06 17:45:31 +04:00
attr = sysfs_attr_get_value ( udevice - > udev , udevice - > dev - > devpath , " dev " ) ;
2006-01-09 23:18:00 +03:00
if ( attr ! = NULL ) {
2006-08-24 12:25:34 +04:00
if ( sscanf ( attr , " %u:%u " , & maj , & min ) = = 2 )
return makedev ( maj , min ) ;
2006-01-09 23:18:00 +03:00
}
return makedev ( 0 , 0 ) ;
}