lkml.org 
[lkml]   [2002]   [Jul]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectdriverfs updates, part 2

Ok, here is the next round of driverfs updates.

Short summary:

- move device and driver interface to driverfs into drivers/base/fs/*.c
- Implement bus_{create,remove}_file and driver_{create,remove}_file to
give people an interface to create files those object types in their
respective directories.

driver_{create,remove}_file are the simplest, and exist in
drivers/base/fs/driver.c. If people are feeling frisky, and want to
play, use that as an example on how to extend driverfs for other
subsystems and object types.

I'm also attaching an example 'subsystem' driver that exports
registration and unregistration functions that do creation and teardown
of driverfs directories.

- Remove references to struct device in driverfs, making it completely
independent of the device model core.

- Update documentation

-pat

Please pull from

bk://ldm.bkbits.net/linux-2.5-driverfs-2

Note that this tree includes all the changes that I posted earlier today.
bk://ldm.bkbits.net/linux-2.5-driverfs still exists, with only the earlier
changes.


This will update the following files:

drivers/base/fs.c | 216 ----------------
Documentation/filesystems/driverfs.txt | 443 ++++++++++++++++++++++++---------
drivers/base/Makefile | 6
drivers/base/base.h | 7
drivers/base/bus.c | 74 -----
drivers/base/driver.c | 23 -
drivers/base/fs/Makefile | 18 -
drivers/base/fs/bus.c | 199 ++++++++++----
drivers/base/fs/device.c | 145 ++++++++--
drivers/base/fs/driver.c | 48 +++
drivers/base/fs/fs.h | 7
drivers/base/fs/lib.c | 352 ++++++++++++++++++--------
fs/driverfs/inode.c | 19 -
fs/driverfs/lib.c | 28 +-
include/linux/device.h | 5
include/linux/driverfs_fs.h | 2
16 files changed, 938 insertions(+), 654 deletions(-)

through these ChangeSets:

<mochel@osdl.org> (02/07/18 1.755)
Update driverfs documentation

<mochel@osdl.org> (02/07/18 1.754)
driverfs:
Remove all struct device references.
Don't touch device's reference count on open() and close()

<mochel@osdl.org> (02/07/18 1.753)
add functions for creating/removing driverfs files for device drivers

<mochel@osdl.org> (02/07/18 1.752)
bus driver driverfs interface:
include fs.h
fix compile error

<mochel@osdl.org> (02/07/18 1.751)
Move driverfs directory creation for drivers to drivers/base/fs/driver.c

<mochel@osdl.org> (02/07/18 1.750)
Add helpers make_one_dir and remove_one_dir for ease of creating and removing driverfs directories

<mochel@osdl.org> (02/07/18 1.749)
fixup callers of driverfs_create_file to just pass template to it (and not do own duplication of the template)

<mochel@osdl.org> (02/07/18 1.748)
driverfs:
- make driverfs_create_file do duplication of driver_file_entry passed in (instead of making each caller do it)

<mochel@osdl.org> (02/07/18 1.747)
Implement bus_{create,remove}_file, to allow creation of files for bus drivers in the bus's driverfs directory

<mochel@osdl.org> (02/07/18 1.746)
Make root bus directory dynamically allocated, like the rest of the directories in the world...

<mochel@osdl.org> (02/07/18 1.745)
Make sure mode is set when creating bus directory

<mochel@osdl.org> (02/07/18 1.744)
Move functions for bus drivers interfacing with driverfs from drivers/base/bus.c to drivers/base/fs/bus.c

<mochel@osdl.org> (02/07/18 1.743)
Move interface for creating driverfs files for devices from drivers/base/fs/lib.c to drivers/base/fs/device.c

<mochel@osdl.org> (02/07/18 1.742)
Move drivers/base/fs.c to drivers/base/fs/lib.c

<mochel@osdl.org> (02/07/18 1.741)
driverfs:
- remove stray references to struct device


/*
* pubsys - exploting driverfs for fun and profit
*
* Copyright (c) 2002 Patrick Mochel
* Open Source Development Lab
*
* 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
*
* This is a sample subsystem to illustrate how easy it is to latch on to
* driverfs and exploit it. It is the 'pub' subsystem. Objects of type 'beer'
* can be registered and unregistered with the pub via beer_register and
* beer_unregister.
*
* Every time a beer is registered with the pub subsystem, a directory is
* created for it. The pub subsystem could then create files on behalf of
* the beer, in the beer's directory. Once the beer has registered, it
* can create files for itself in its directory. A second, more robust
* example will surely follow.
*
* Compiled with

CFLAGS = -Wall -O2 -fomit-frame-pointer -DMODULE -D__KERNEL__
IDIR = /home/mochel/src/kernel/devel/linux-2.5/include

pubsys.o:: pubsys.c
$(CC) $(CFLAGS) -I$(IDIR) -c -o $@ $<
*/

#include <linux/module.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/stat.h>
#include <linux/err.h>
#include <linux/driverfs_fs.h>

static LIST_HEAD(beer_list);
static struct driver_dir_entry * pub_dir;

struct beer {
char * name;
struct list_head node;
struct module * owner;
struct driver_dir_entry * dir;
};

int beer_create_file(struct beer * beer, struct driver_file_entry * entry)
{
int error = -EINVAL;
if (beer)
error = driverfs_create_file(entry,beer->dir);
return error;
}

void beer_remove_file(struct beer * beer, struct driver_file_entry * entry)
{
if (beer)
driverfs_remove_file(beer->dir,entry);
}

static int make_one_dir(char * name,
struct driver_dir_entry ** dir,
struct driver_dir_entry * parent,
void * object)
{
struct driver_dir_entry * d;
int error;

d = kmalloc(sizeof(struct driver_dir_entry),GFP_KERNEL);
if (!d)
return -ENOMEM;
memset(d,0,sizeof(struct driver_dir_entry));
d->name = name;
d->mode = (S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO);
INIT_LIST_HEAD(&d->files);
d->object = object;

if (!(error = driverfs_create_dir(d,parent)))
*dir = d;
else
kfree(d);
return error;
}

static int beer_make_dir(struct beer * beer)
{
return make_one_dir(beer->name,&beer->dir,pub_dir,beer);
}

static void beer_remove_dir(struct beer * beer)
{
struct driver_dir_entry * dir = beer->dir;
beer->dir = NULL;
driverfs_remove_dir(dir);
}

int beer_register(struct beer * beer)
{
int error;
MOD_INC_USE_COUNT;
error = beer_make_dir(beer);
if (!error)
list_add_tail(&beer->node,&beer_list);
else
MOD_DEC_USE_COUNT;
return error;
}

void beer_unregister(struct beer * beer)
{
beer_remove_dir(beer);
list_del(&beer->node);
MOD_DEC_USE_COUNT;
}

static int __init pub_init(void)
{
return make_one_dir("pub",&pub_dir,NULL,NULL);
}

static void __exit pub_exit(void)
{
driverfs_remove_dir(pub_dir);
}

module_init(pub_init);
module_exit(pub_exit);

\
 
 \ /
  Last update: 2005-03-22 13:27    [W:0.027 / U:0.140 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site