2003-07-17 15:24:51 +07:00
|
|
|
/*
|
|
|
|
* namedev.h
|
|
|
|
*
|
|
|
|
* Userspace devfs
|
|
|
|
*
|
2004-01-27 10:21:58 +07:00
|
|
|
* Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
|
2003-07-17 15:24:51 +07: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 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NAMEDEV_H
|
|
|
|
#define NAMEDEV_H
|
|
|
|
|
2003-08-06 13:57:23 +07:00
|
|
|
#include "udev.h"
|
2003-07-24 05:56:56 +07:00
|
|
|
#include "list.h"
|
|
|
|
|
2003-07-19 19:06:55 +07:00
|
|
|
struct sysfs_class_device;
|
|
|
|
|
2004-11-13 11:21:12 +07:00
|
|
|
#define BUS_SIZE 32
|
|
|
|
#define FILE_SIZE 64
|
|
|
|
#define VALUE_SIZE 128
|
|
|
|
#define ID_SIZE 64
|
|
|
|
#define PLACE_SIZE 64
|
|
|
|
#define DRIVER_SIZE 64
|
|
|
|
#define PROGRAM_SIZE 128
|
2004-02-17 12:44:28 +07:00
|
|
|
|
|
|
|
#define FIELD_BUS "BUS"
|
|
|
|
#define FIELD_SYSFS "SYSFS"
|
|
|
|
#define FIELD_ID "ID"
|
|
|
|
#define FIELD_PLACE "PLACE"
|
|
|
|
#define FIELD_PROGRAM "PROGRAM"
|
|
|
|
#define FIELD_RESULT "RESULT"
|
|
|
|
#define FIELD_KERNEL "KERNEL"
|
2004-11-12 12:52:55 +07:00
|
|
|
#define FIELD_SUBSYSTEM "SUBSYSTEM"
|
2004-11-13 11:21:12 +07:00
|
|
|
#define FIELD_DRIVER "DRIVER"
|
2004-02-17 12:44:28 +07:00
|
|
|
#define FIELD_NAME "NAME"
|
|
|
|
#define FIELD_SYMLINK "SYMLINK"
|
2004-03-11 13:35:37 +07:00
|
|
|
#define FIELD_OWNER "OWNER"
|
|
|
|
#define FIELD_GROUP "GROUP"
|
|
|
|
#define FIELD_MODE "MODE"
|
2004-02-17 12:44:28 +07:00
|
|
|
|
|
|
|
#define ATTR_PARTITIONS "all_partitions"
|
2004-11-13 20:43:24 +07:00
|
|
|
#define ATTR_IGNORE_REMOVE "ignore_remove"
|
2004-02-17 12:44:28 +07:00
|
|
|
#define PARTITIONS_COUNT 15
|
|
|
|
|
|
|
|
#define MAX_SYSFS_PAIRS 5
|
2003-12-23 13:31:35 +07:00
|
|
|
|
2004-03-27 16:21:46 +07:00
|
|
|
#define RULEFILE_SUFFIX ".rules"
|
|
|
|
#define PERMFILE_SUFFIX ".permissions"
|
2004-02-24 10:31:14 +07:00
|
|
|
|
2004-03-11 13:35:37 +07:00
|
|
|
#define set_empty_perms(dev, m, o, g) \
|
|
|
|
if (dev->mode == 0) \
|
|
|
|
dev->mode = m; \
|
|
|
|
if (dev->owner[0] == '\0') \
|
|
|
|
strfieldcpy(dev->owner, o); \
|
|
|
|
if (dev->group[0] == '\0') \
|
|
|
|
strfieldcpy(dev->group, g);
|
|
|
|
|
2003-12-23 13:31:35 +07:00
|
|
|
struct sysfs_pair {
|
|
|
|
char file[FILE_SIZE];
|
|
|
|
char value[VALUE_SIZE];
|
|
|
|
};
|
2003-07-24 05:56:56 +07:00
|
|
|
|
|
|
|
struct config_device {
|
|
|
|
struct list_head node;
|
|
|
|
|
|
|
|
char bus[BUS_SIZE];
|
|
|
|
char id[ID_SIZE];
|
|
|
|
char place[PLACE_SIZE];
|
[PATCH] udev - drop all methods :)
> Hi,
> as promised yesterday, here is a patch that drops the explicit methods
> given in the udev config and implement only one type of rule.
>
> A rule now consists only of a number of keys to match. All known keys
> are valid in any combination. The former configs should work with a few
> changes:
>
> o the "<METHOD>, " at the beginning of the line should be removed
>
> o the result of the externel program is matched with RESULT= instead if ID=
> the PROGRAM= key is only valid if the program exits with zero
> (just exit with nozero in a script if the rule should not match)
>
> o rules are processed in order they appear in the file, no priority
>
> o if NAME="" is given, udev is instructed to ignore this device,
> no node will be created
>
>
> EXAMPLE:
>
> # combined BUS, SYSFS and KERNEL
> BUS="usb", KERNEL="video*", SYSFS_model="Creative Labs WebCam*", NAME="test/webcam%n"
>
> # exec script only for the first ide drive (hda), all other will be skipped
> BUS="ide", KERNEL="hda*", PROGRAM="/home/kay/src/udev.kay/extras/ide-devfs.sh %k %b %n", RESULT="hd*", NAME="%1c", SYMLINK="%2c %3c"
>
>
> The udev-test.pl and test.block works fine here.
> Please adapt your config and give it a try.
>
Here is a slightly better version of the patch.
After a conversation with Patrick, we are now able to execute the PROGRAM
and also match in all following rules with the RESULT value from this exec.
EXAMPLE:
We have 7 rules with RESULT and 2 with PROGRAM.
Only the 5th rule matches with the callout result from the exec in the 4th rule.
RULES:
PROGRAM="/bin/echo abc", RESULT="no_match", NAME="web-no-2"
KERNEL="video*", RESULT="123", NAME="web-no-3"
KERNEL="video*", RESULT="123", NAME="web-no-4"
PROGRAM="/bin/echo 123", RESULT="no_match", NAME="web-no-5"
KERNEL="video*", RESULT="123", NAME="web-yes"
RESULT:
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo abc'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is 'abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo 123'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is '123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: found matching rule, 'video*' becomes ''
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: name, 'web-yes' is going to have owner='', group='', mode = 0600
2004-01-13 12:39:05 +07:00
|
|
|
char kernel[NAME_SIZE];
|
|
|
|
char program[PROGRAM_SIZE];
|
|
|
|
char result[PROGRAM_SIZE];
|
2004-11-12 12:52:55 +07:00
|
|
|
char subsystem[SUBSYSTEM_SIZE];
|
2004-11-13 11:21:12 +07:00
|
|
|
char driver[DRIVER_SIZE];
|
2003-12-04 09:33:58 +07:00
|
|
|
char name[NAME_SIZE];
|
2003-12-08 00:12:07 +07:00
|
|
|
char symlink[NAME_SIZE];
|
2003-12-23 13:31:35 +07:00
|
|
|
struct sysfs_pair sysfs_pair[MAX_SYSFS_PAIRS];
|
2004-03-11 13:35:37 +07:00
|
|
|
char owner[OWNER_SIZE];
|
|
|
|
char group[GROUP_SIZE];
|
|
|
|
unsigned int mode;
|
2004-02-17 12:44:28 +07:00
|
|
|
int partitions;
|
2004-11-13 20:43:24 +07:00
|
|
|
int ignore_remove;
|
2004-03-02 13:28:51 +07:00
|
|
|
char config_file[NAME_SIZE];
|
[PATCH] add udev logging to info log
On Thu, Jan 15, 2004 at 05:14:16AM +0100, Kay Sievers wrote:
> On Wed, Jan 14, 2004 at 01:10:43PM -0800, Greg KH wrote:
> > On Wed, Jan 14, 2004 at 02:34:26PM -0600, Clay Haapala wrote:
> > > On Wed, 14 Jan 2004, Chris Friesen spake thusly:
> > > >
> > > > Maybe for ones with a matching rule, you could print something like:
> > > >
> > > >
> > > Is the act of printing/syslogging a rule in an of itself?
> >
> > No, as currently the only way stuff ends up in the syslog is if
> > DEBUG=true is used on the build line.
> >
> > But it's sounding like we might want to change that... :)
>
> How about this in the syslog after connect/disconnect?
>
> Jan 15 05:07:45 pim udev[28007]: configured rule in '/etc/udev/udev.rules' at line 17 applied, 'video*' becomes 'video/webcam%n'
> Jan 15 05:07:45 pim udev[28007]: creating device node '/udev/video/webcam0'
> Jan 15 05:07:47 pim udev[28015]: removing device node '/udev/video/webcam0'
Here is a slightly better version. I've created a logging.h file and
moved the debug macros from udev.h in there.
If you type:
'make' - you will get a binary that prints one or two lines to syslog
if a device node is created or deleted
'make LOG=false' - you get a binary that prints asolutely nothing
'make DEBUG=true' - the same as today, it will print all debug lines
2004-01-16 12:53:20 +07:00
|
|
|
int config_line;
|
2003-12-04 09:33:58 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct perm_device {
|
|
|
|
struct list_head node;
|
2003-11-25 13:27:17 +07:00
|
|
|
|
2003-10-22 12:28:32 +07:00
|
|
|
char name[NAME_SIZE];
|
|
|
|
char owner[OWNER_SIZE];
|
|
|
|
char group[GROUP_SIZE];
|
2004-02-12 16:29:40 +07:00
|
|
|
unsigned int mode;
|
2003-07-24 05:56:56 +07:00
|
|
|
};
|
|
|
|
|
2003-12-03 09:38:30 +07:00
|
|
|
extern struct list_head config_device_list;
|
2003-12-04 09:33:58 +07:00
|
|
|
extern struct list_head perm_device_list;
|
2003-07-24 05:56:56 +07:00
|
|
|
|
2003-07-17 15:24:51 +07:00
|
|
|
extern int namedev_init(void);
|
2004-10-19 09:11:51 +07:00
|
|
|
extern int namedev_name_device(struct udevice *udev, struct sysfs_class_device *class_dev);
|
2003-12-03 09:38:30 +07:00
|
|
|
extern int namedev_init_permissions(void);
|
2003-12-03 16:08:46 +07:00
|
|
|
extern int namedev_init_rules(void);
|
2003-12-03 09:38:30 +07:00
|
|
|
|
|
|
|
extern void dump_config_dev(struct config_device *dev);
|
|
|
|
extern void dump_config_dev_list(void);
|
2003-12-04 09:33:58 +07:00
|
|
|
extern void dump_perm_dev(struct perm_device *dev);
|
|
|
|
extern void dump_perm_dev_list(void);
|
2003-07-17 15:24:51 +07:00
|
|
|
|
|
|
|
#endif
|