All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian Gmeiner" <christian@visual-page.de>
To: linux-hotplug@vger.kernel.org
Subject: Re: Coding problem with sysfs
Date: Sat, 05 Jun 2004 16:23:25 +0000	[thread overview]
Message-ID: <000201c44b1b$26a9d100$0600a8c0@blackbox> (raw)
In-Reply-To: <002c01c44883$2717bfc0$0600a8c0@blackbox>

[-- Attachment #1: Type: text/plain, Size: 3829 bytes --]

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

[-- Attachment #2: dvbdev.h --]
[-- Type: application/octet-stream, Size: 2542 bytes --]

/* 
 * dvbdev.h
 *
 * Copyright (C) 2000 Ralph Metzler & Marcus Metzler
 *                    for convergence integrated media GmbH
 * Copyright (C) 2004 Christian Gmeiner <christian@visual-page.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Lesser Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * 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 Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#ifndef _DVBDEV_H_
#define _DVBDEV_H_

#include <linux/types.h>
#include <linux/fs.h>
#include <linux/poll.h>
#include <linux/device.h>

#define DVB_MAJOR 250

#define DVB_DEVICE_VIDEO      0
#define DVB_DEVICE_AUDIO      1
#define DVB_DEVICE_SEC        2
#define DVB_DEVICE_FRONTEND   3
#define DVB_DEVICE_DEMUX      4
#define DVB_DEVICE_DVR        5
#define DVB_DEVICE_CA         6
#define DVB_DEVICE_NET        7
#define DVB_DEVICE_OSD        8


struct dvb_adapter {
	int num;
	struct list_head list_head;
	struct list_head device_list;
	const char *name;
	char frontend[64];
	u8 proposed_mac [6];

	struct module *module;

	// SysFs
	struct class_device class_dev;
};


struct dvb_device {
	struct list_head list_head;
	struct file_operations *fops;
	struct dvb_adapter *adapter;
	int type;
	u32 id;

	/* in theory, 'users' can vanish now,
	   but I don't want to change too much now... */
	int readers;
	int writers;
	int users;

        /* don't really need those !? -- FIXME: use video_usercopy  */
        int (*kernel_ioctl)(struct inode *inode, struct file *file,
			    unsigned int cmd, void *arg);

	void *priv;

	// SysFs
	struct class_device class_dev;
};

#include "dvb_registration.h"

// generic functions
extern int dvb_generic_open (struct inode *inode, struct file *file);
extern int dvb_generic_release (struct inode *inode, struct file *file);
extern int dvb_generic_ioctl (struct inode *inode, struct file *file,
			      unsigned int cmd, unsigned long arg);

#endif /* _DVBDEV_H_ */

[-- Attachment #3: dvb_sysfs.c --]
[-- Type: application/octet-stream, Size: 5159 bytes --]

/*
*
* dvb_sysfs.c -- interface to the sysfs filesystem
* Copyright (C) 2004 Christian Gmeiner <christian@visual-page.de>
* Copyright (C) 2004 Eric Donohue <epd3j@hotmail.com>
*
*  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.
*
*  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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include <linux/version.h>

#include "dvb_sysfs.h"

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,46)

#ifndef DVB_SYSFS_DIR
#define DVB_SYSFS_DIR "dvb"	//-> /sys/class/dvb/...
#endif

static struct class dvb_class = {
	.name = DVB_SYSFS_DIR
};

static ssize_t show_name(struct class_device *cd, char *buf)
{
	struct dvb_adapter *adap = container_of(cd, struct dvb_adapter, class_dev);
	sprintf(buf, "%s\n", adap->name);
	return strlen(buf) + 1;
}

static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);

static ssize_t show_frontend(struct class_device *cd, char *buf)
{
	struct dvb_adapter *adap = container_of(cd, struct dvb_adapter, class_dev);
	sprintf(buf, "%s\n", adap->frontend);
	return strlen(buf) + 1;
}

static CLASS_DEVICE_ATTR(frontend, S_IRUGO, show_frontend, NULL);

static ssize_t show_devnum(struct class_device *cd, char *buf)
{
	struct dvb_device *dvbdev = container_of(cd, struct dvb_device, class_dev);

	dev_t dev = MKDEV(DVB_MAJOR, nums2minor(dvbdev->adapter->num, dvbdev->type, dvbdev->id));
	return print_dev_t(buf, dev);
}

static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_devnum, NULL);

static ssize_t show_adap(struct class_device *cd, char *buf)
{
	struct dvb_device *dvbdev = container_of(cd, struct dvb_device, class_dev);
	sprintf(buf, "adapter%d\n", dvbdev->adapter->num);
	return strlen(buf) + 1;
}

static CLASS_DEVICE_ATTR(adap, S_IRUGO, show_adap, NULL);


static struct class_device_attribute *dvb_adapter_attrs[] = {
	&class_device_attr_name,
	&class_device_attr_frontend,
	NULL
};

static struct class_device_attribute *dvb_device_attrs[] = {
	&class_device_attr_dev,
	&class_device_attr_adap,
	NULL
};

static void dvb_sysfs_register_adapter(struct dvb_adapter *adap)
{
	char name[64] = "";
	int i;

	adap->class_dev.class = &dvb_class;
	adap->class_dev.dev = NULL;
	adap->class_dev.class_data = adap;

	sprintf(name,"adapter%d", adap->num);
	strcpy(adap->class_dev.class_id, name);

	if(class_device_register(&adap->class_dev))
		printk(KERN_ERR "Unable to register dvb class device\n");

	for(i = 0; dvb_adapter_attrs[i]; i++)
		class_device_create_file(&(adap->class_dev), dvb_adapter_attrs[i]);
}

static void dvb_sysfs_unregister_adapter(struct dvb_adapter *adap)
{
	class_device_unregister(&(adap->class_dev));
}

static void dvb_sysfs_register_device(struct dvb_device *dvbdev)
{
	int i;
	char name[64] = "";
	struct class_device *class_dev = &(dvbdev->class_dev);

	sprintf(name,"%s%d", dnames[dvbdev->type], dvbdev->adapter->num);

	class_dev->class = &dvb_class;
	class_dev->class_data = dvbdev;
	strcpy(class_dev->class_id, name);

	kobject_init(&class_dev->kobj);
	strcpy(class_dev->kobj.name, name);
	class_dev->kobj.parent = &dvbdev->adapter->class_dev.kobj;
	class_dev->kobj.kset = dvbdev->adapter->class_dev.kobj.kset;
	class_dev->kobj.ktype = dvbdev->adapter->class_dev.kobj.ktype;
	class_dev->kobj.dentry = dvbdev->adapter->class_dev.kobj.dentry;
	kobject_register(&class_dev->kobj);

	for (i = 0; dvb_device_attrs[i]; i++)
		class_device_create_file(class_dev, dvb_device_attrs[i]);

}

static void dvb_sysfs_unregister_device(struct dvb_device *dvbdev)
{
	kobject_unregister(&dvbdev->class_dev.kobj);
}

static int dvb_sysfs_init(void)
{
	printk("DVB: Using sysfs funtions\n");

	if (class_register(&dvb_class) != 0) {
		printk("DVB: adapter class failed to register properly");
		return -1;
	}

	return 0;
}

static void dvb_sysfs_exit(void)
{
	class_unregister(&dvb_class);
}

struct dvb_registrar_s dvb_sysfs_registrar =
{
	.register_adapter	= &dvb_sysfs_register_adapter,
	.unregister_adapter	= &dvb_sysfs_unregister_adapter,
	.register_device	= &dvb_sysfs_register_device,
	.unregister_device	= &dvb_sysfs_unregister_device,
	.dvbdev_init		= &dvb_sysfs_init,
	.dvbdev_exit		= &dvb_sysfs_exit,
};

#else /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,46) */

struct dvb_registrar_s dvb_sysfs_registrar =
{
	.register_adapter	= NULL,
	.unregister_adapter	= NULL,
	.register_device	= NULL,
	.unregister_device	= NULL,
	.dvbdev_init		= NULL,
	.dvbdev_exit		= NULL,
};

#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,46) */

  parent reply	other threads:[~2004-06-05 16:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-02  9:21 Coding problem with sysfs Christian Gmeiner
2004-06-04 21:05 ` Greg KH
2004-06-05  0:30 ` Christian Gmeiner
2004-06-05 15:40 ` Greg KH
2004-06-05 16:23 ` Christian Gmeiner [this message]
2004-06-07 23:38 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2004-06-01 22:19 Christian Gmeiner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000201c44b1b$26a9d100$0600a8c0@blackbox' \
    --to=christian@visual-page.de \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.