From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Christian Gmeiner" Date: Sat, 05 Jun 2004 16:23:25 +0000 Subject: Re: Coding problem with sysfs Message-Id: <000201c44b1b$26a9d100$0600a8c0@blackbox> MIME-Version: 1 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0018_01C44B2A.30CF7B30" List-Id: References: <002c01c44883$2717bfc0$0600a8c0@blackbox> In-Reply-To: <002c01c44883$2717bfc0$0600a8c0@blackbox> To: linux-hotplug@vger.kernel.org This is a multi-part message in MIME format. ------=_NextPart_000_0018_01C44B2A.30CF7B30 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi Greg, > On Sat, Jun 05, 2004 at 02:30:33AM +0200, Christian Gmeiner wrote: > > Hi Greg, > > > > > On Wed, Jun 02, 2004 at 11:21:53AM +0200, Christian Gmeiner wrote: > > > > /sys/class/dvb/adapter0: > > > > demux0 dvr0 frontend frontend0 name net0 > > > > > > The 'dev' file needs to be here. That's the problem. > > Oh i forgot something - my fault: > > > > vdr root # ls -Rl /sys/class/dvb > > /sys/class/dvb: > > total 0 > > drwxr-xr-x 5 root root 0 Jun 5 02:22 adapter0 > > > > /sys/class/dvb/adapter0: > > total 0 > > drwxr-xr-x 2 root root 0 Jun 5 02:22 demux0 > > drwxr-xr-x 2 root root 0 Jun 5 02:22 dvr0 > > -r--r--r-- 1 root root 4096 Jun 5 02:22 frontend > > -r--r--r-- 1 root root 4096 Jun 5 02:22 name > > drwxr-xr-x 2 root root 0 Jun 5 02:22 net0 > > > > /sys/class/dvb/adapter0/demux0: > > total 0 > > -r--r--r-- 1 root root 4096 Jun 5 02:22 adap > > -r--r--r-- 1 root root 4096 Jun 5 02:22 dev > > > > /sys/class/dvb/adapter0/dvr0: > > total 0 > > -r--r--r-- 1 root root 4096 Jun 5 02:22 adap > > -r--r--r-- 1 root root 4096 Jun 5 02:22 dev > > > > /sys/class/dvb/adapter0/net0: > > total 0 > > -r--r--r-- 1 root root 4096 Jun 5 02:22 adap > > -r--r--r-- 1 root root 4096 Jun 5 02:22 dev > > > > Hm, how about using 'tree' instead, it's much easier to show the > heirchey with it :) Sure, but i also want to show as much as possible infos (owner, group,..). > > Anyway, how are you putting struct class_device structures into such a > tree? We don't currently allow parents of them in the kernel. Are you > using basic kobjects here? Yep i am using kobjects to this. I need this structure, because there can be more than one adapter. At the moment i able to get some infos like: vdr root # cat /sys/class/dvb/adapter0/name KNC1 DVB-S vdr root # cat /sys/class/dvb/adapter0/frontend STV0299/TSA5059/SL1935 based > > What hotplug events get generated when you create your "demux0" and > others devices? How can i check the hotplug events? I have here an PCI-DVB card. > The solution is for you to put everything under the /sys/class/dvb/ > directory, and not go one level deeper. > > Care to post your code? I have postes some the whole source in my first mail for this topic, but i will send it again. > > > > What happens if you run > > > udevtest /sys/class/dvb/adapter0 > > > > vdr root # udevtest /sys/class/dvb/adapter0 > > version 025 > > looking at '/class/dvb/adapter0' > > configured rule in '/etc/udev/rules.d//10-myrule.rules' at line 2 applied, > > 'adapter0' becomes 'dvb/adapter%n/%k' > > creating device node '/dev/dvb/adapter0/adapter0', major = '250', minor = > > '7', mode = '020660', uid = '0', gid = '27' > > Ok, so that works :) > > > > > > > > This is my udev rule: > > # dvb devices > > SYSFS{adap}="adapter[0-9]*", NAME="dvb/adapter%n/%k" > > > > And this is the result in /dev: > > > > vdr root # ls -Rl /dev/dvb > > /dev/dvb: > > total 0 > > drwxr-xr-x 2 root root 0 Jun 5 02:22 adapter0 > > > > /dev/dvb/adapter0: > > total 0 > > crw-rw---- 1 root video 250, 7 Jun 5 02:22 adapter0 > > crw-rw---- 1 root video 250, 4 Jun 5 02:22 demux0 > > crw-rw---- 1 root video 250, 5 Jun 5 02:22 dvr0 > > crw-rw---- 1 root video 250, 7 Jun 5 02:22 net0 > > > > > > And here is the problem: > > vdr root # ls /dev/dvb/adapter0/demux0 > > /dev/dvb/adapter0/demux0 > > vdr root # cat /dev/dvb/adapter0/demux0 > > cat: /dev/dvb/adapter0/demux0: No such device or address > > Ok, that's your kernel driver problem, not a udev issue :) Sure? I have taken the devfs code, wrote an abstract interface for it and added sysfs support, based on the devfs code. > > Are you sure 250:4 is the proper major:minor assigned to your kernel > object? I hope, i will ask the dvb maillinglist. > > Again, code would help here. Is attached! Thanks, Christian ------=_NextPart_000_0018_01C44B2A.30CF7B30 Content-Type: application/octet-stream; name="dvbdev.h" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="dvbdev.h" /* =0A= * dvbdev.h=0A= *=0A= * Copyright (C) 2000 Ralph Metzler & Marcus Metzler=0A= * for convergence integrated media GmbH=0A= * Copyright (C) 2004 Christian Gmeiner =0A= *=0A= * This program is free software; you can redistribute it and/or=0A= * modify it under the terms of the GNU General Lesser Public License=0A= * as published by the Free Software Foundation; either version 2.1=0A= * of the License, or (at your option) any later version.=0A= *=0A= * This program is distributed in the hope that it will be useful,=0A= * but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= * GNU General Public License for more details.=0A= *=0A= * You should have received a copy of the GNU Lesser General Public = License=0A= * along with this program; if not, write to the Free Software=0A= * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA = 02111-1307, USA.=0A= *=0A= */=0A= =0A= #ifndef _DVBDEV_H_=0A= #define _DVBDEV_H_=0A= =0A= #include =0A= #include =0A= #include =0A= #include =0A= =0A= #define DVB_MAJOR 250=0A= =0A= #define DVB_DEVICE_VIDEO 0=0A= #define DVB_DEVICE_AUDIO 1=0A= #define DVB_DEVICE_SEC 2=0A= #define DVB_DEVICE_FRONTEND 3=0A= #define DVB_DEVICE_DEMUX 4=0A= #define DVB_DEVICE_DVR 5=0A= #define DVB_DEVICE_CA 6=0A= #define DVB_DEVICE_NET 7=0A= #define DVB_DEVICE_OSD 8=0A= =0A= =0A= struct dvb_adapter {=0A= int num;=0A= struct list_head list_head;=0A= struct list_head device_list;=0A= const char *name;=0A= char frontend[64];=0A= u8 proposed_mac [6];=0A= =0A= struct module *module;=0A= =0A= // SysFs=0A= struct class_device class_dev;=0A= };=0A= =0A= =0A= struct dvb_device {=0A= struct list_head list_head;=0A= struct file_operations *fops;=0A= struct dvb_adapter *adapter;=0A= int type;=0A= u32 id;=0A= =0A= /* in theory, 'users' can vanish now,=0A= but I don't want to change too much now... */=0A= int readers;=0A= int writers;=0A= int users;=0A= =0A= /* don't really need those !? -- FIXME: use video_usercopy */=0A= int (*kernel_ioctl)(struct inode *inode, struct file *file,=0A= unsigned int cmd, void *arg);=0A= =0A= void *priv;=0A= =0A= // SysFs=0A= struct class_device class_dev;=0A= };=0A= =0A= #include "dvb_registration.h"=0A= =0A= // generic functions=0A= extern int dvb_generic_open (struct inode *inode, struct file *file);=0A= extern int dvb_generic_release (struct inode *inode, struct file *file);=0A= extern int dvb_generic_ioctl (struct inode *inode, struct file *file,=0A= unsigned int cmd, unsigned long arg);=0A= =0A= #endif /* _DVBDEV_H_ */=0A= ------=_NextPart_000_0018_01C44B2A.30CF7B30 Content-Type: application/octet-stream; name="dvb_sysfs.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="dvb_sysfs.c" /*=0A= *=0A= * dvb_sysfs.c -- interface to the sysfs filesystem=0A= * Copyright (C) 2004 Christian Gmeiner =0A= * Copyright (C) 2004 Eric Donohue =0A= *=0A= * This program is free software; you can redistribute it and/or=0A= * modify it under the terms of the GNU General Public License=0A= * as published by the Free Software Foundation; either version 2=0A= * of the License, or (at your option) any later version.=0A= *=0A= * This program is distributed in the hope that it will be useful,=0A= * but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= * GNU General Public License for more details.=0A= *=0A= * You should have received a copy of the GNU General Public License=0A= * along with this program; if not, write to the Free Software=0A= * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA = 02111-1307, USA.=0A= */=0A= =0A= #include =0A= =0A= #include "dvb_sysfs.h"=0A= =0A= #if LINUX_VERSION_CODE >=3D KERNEL_VERSION(2,5,46)=0A= =0A= #ifndef DVB_SYSFS_DIR=0A= #define DVB_SYSFS_DIR "dvb" //-> /sys/class/dvb/...=0A= #endif=0A= =0A= static struct class dvb_class =3D {=0A= .name =3D DVB_SYSFS_DIR=0A= };=0A= =0A= static ssize_t show_name(struct class_device *cd, char *buf)=0A= {=0A= struct dvb_adapter *adap =3D container_of(cd, struct dvb_adapter, = class_dev);=0A= sprintf(buf, "%s\n", adap->name);=0A= return strlen(buf) + 1;=0A= }=0A= =0A= static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);=0A= =0A= static ssize_t show_frontend(struct class_device *cd, char *buf)=0A= {=0A= struct dvb_adapter *adap =3D container_of(cd, struct dvb_adapter, = class_dev);=0A= sprintf(buf, "%s\n", adap->frontend);=0A= return strlen(buf) + 1;=0A= }=0A= =0A= static CLASS_DEVICE_ATTR(frontend, S_IRUGO, show_frontend, NULL);=0A= =0A= static ssize_t show_devnum(struct class_device *cd, char *buf)=0A= {=0A= struct dvb_device *dvbdev =3D container_of(cd, struct dvb_device, = class_dev);=0A= =0A= dev_t dev =3D MKDEV(DVB_MAJOR, nums2minor(dvbdev->adapter->num, = dvbdev->type, dvbdev->id));=0A= return print_dev_t(buf, dev);=0A= }=0A= =0A= static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_devnum, NULL);=0A= =0A= static ssize_t show_adap(struct class_device *cd, char *buf)=0A= {=0A= struct dvb_device *dvbdev =3D container_of(cd, struct dvb_device, = class_dev);=0A= sprintf(buf, "adapter%d\n", dvbdev->adapter->num);=0A= return strlen(buf) + 1;=0A= }=0A= =0A= static CLASS_DEVICE_ATTR(adap, S_IRUGO, show_adap, NULL);=0A= =0A= =0A= static struct class_device_attribute *dvb_adapter_attrs[] =3D {=0A= &class_device_attr_name,=0A= &class_device_attr_frontend,=0A= NULL=0A= };=0A= =0A= static struct class_device_attribute *dvb_device_attrs[] =3D {=0A= &class_device_attr_dev,=0A= &class_device_attr_adap,=0A= NULL=0A= };=0A= =0A= static void dvb_sysfs_register_adapter(struct dvb_adapter *adap)=0A= {=0A= char name[64] =3D "";=0A= int i;=0A= =0A= adap->class_dev.class =3D &dvb_class;=0A= adap->class_dev.dev =3D NULL;=0A= adap->class_dev.class_data =3D adap;=0A= =0A= sprintf(name,"adapter%d", adap->num);=0A= strcpy(adap->class_dev.class_id, name);=0A= =0A= if(class_device_register(&adap->class_dev))=0A= printk(KERN_ERR "Unable to register dvb class device\n");=0A= =0A= for(i =3D 0; dvb_adapter_attrs[i]; i++)=0A= class_device_create_file(&(adap->class_dev), dvb_adapter_attrs[i]);=0A= }=0A= =0A= static void dvb_sysfs_unregister_adapter(struct dvb_adapter *adap)=0A= {=0A= class_device_unregister(&(adap->class_dev));=0A= }=0A= =0A= static void dvb_sysfs_register_device(struct dvb_device *dvbdev)=0A= {=0A= int i;=0A= char name[64] =3D "";=0A= struct class_device *class_dev =3D &(dvbdev->class_dev);=0A= =0A= sprintf(name,"%s%d", dnames[dvbdev->type], dvbdev->adapter->num);=0A= =0A= class_dev->class =3D &dvb_class;=0A= class_dev->class_data =3D dvbdev;=0A= strcpy(class_dev->class_id, name);=0A= =0A= kobject_init(&class_dev->kobj);=0A= strcpy(class_dev->kobj.name, name);=0A= class_dev->kobj.parent =3D &dvbdev->adapter->class_dev.kobj;=0A= class_dev->kobj.kset =3D dvbdev->adapter->class_dev.kobj.kset;=0A= class_dev->kobj.ktype =3D dvbdev->adapter->class_dev.kobj.ktype;=0A= class_dev->kobj.dentry =3D dvbdev->adapter->class_dev.kobj.dentry;=0A= kobject_register(&class_dev->kobj);=0A= =0A= for (i =3D 0; dvb_device_attrs[i]; i++)=0A= class_device_create_file(class_dev, dvb_device_attrs[i]);=0A= =0A= }=0A= =0A= static void dvb_sysfs_unregister_device(struct dvb_device *dvbdev)=0A= {=0A= kobject_unregister(&dvbdev->class_dev.kobj);=0A= }=0A= =0A= static int dvb_sysfs_init(void)=0A= {=0A= printk("DVB: Using sysfs funtions\n");=0A= =0A= if (class_register(&dvb_class) !=3D 0) {=0A= printk("DVB: adapter class failed to register properly");=0A= return -1;=0A= }=0A= =0A= return 0;=0A= }=0A= =0A= static void dvb_sysfs_exit(void)=0A= {=0A= class_unregister(&dvb_class);=0A= }=0A= =0A= struct dvb_registrar_s dvb_sysfs_registrar =3D=0A= {=0A= .register_adapter =3D &dvb_sysfs_register_adapter,=0A= .unregister_adapter =3D &dvb_sysfs_unregister_adapter,=0A= .register_device =3D &dvb_sysfs_register_device,=0A= .unregister_device =3D &dvb_sysfs_unregister_device,=0A= .dvbdev_init =3D &dvb_sysfs_init,=0A= .dvbdev_exit =3D &dvb_sysfs_exit,=0A= };=0A= =0A= #else /* LINUX_VERSION_CODE >=3D KERNEL_VERSION(2,5,46) */=0A= =0A= struct dvb_registrar_s dvb_sysfs_registrar =3D=0A= {=0A= .register_adapter =3D NULL,=0A= .unregister_adapter =3D NULL,=0A= .register_device =3D NULL,=0A= .unregister_device =3D NULL,=0A= .dvbdev_init =3D NULL,=0A= .dvbdev_exit =3D NULL,=0A= };=0A= =0A= #endif /* LINUX_VERSION_CODE >=3D KERNEL_VERSION(2,5,46) */=0A= ------=_NextPart_000_0018_01C44B2A.30CF7B30-- ------------------------------------------------------- This SF.Net email is sponsored by the new InstallShield X. >From Windows to Linux, servers to mobile, InstallShield X is the one installation-authoring solution that does it all. Learn more and evaluate today! http://www.installshield.com/Dev2Dev/0504 _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel