Commit d2f8eca7 authored by Patrick Mochel's avatar Patrick Mochel

Merge osdl.org:/home/mochel/src/kernel/devel/linux-2.5-virgin

into osdl.org:/home/mochel/src/kernel/devel/linux-2.5-kobject
parents d8c084f9 eda52025
This diff is collapsed.
/*
* kobject.h - generic kernel object infrastructure.
*
*/
#ifndef _KOBJECT_H_
#define _KOBJECT_H_
#include <linux/types.h>
#include <linux/list.h>
#include <linux/sysfs.h>
#include <asm/atomic.h>
struct kobject {
char name[16];
atomic_t refcount;
struct list_head entry;
struct kobject * parent;
struct sysfs_dir dir;
};
extern void kobject_init(struct kobject *);
extern int kobject_register(struct kobject *);
extern void kobject_unregister(struct kobject *);
extern struct kobject * kobject_get(struct kobject *);
extern void kobject_put(struct kobject *);
#endif /* _KOBJECT_H_ */
......@@ -11,18 +11,15 @@
struct driver_dir_entry;
struct attribute;
struct kobject;
struct sysfs_ops {
int (*open)(struct driver_dir_entry *);
int (*close)(struct driver_dir_entry *);
ssize_t (*show)(struct driver_dir_entry *, struct attribute *,char *, size_t, loff_t);
ssize_t (*store)(struct driver_dir_entry *,struct attribute *,const char *, size_t, loff_t);
ssize_t (*show)(struct kobject *, struct attribute *,char *, size_t, loff_t);
ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t, loff_t);
};
struct driver_dir_entry {
char * name;
struct sysfs_dir {
struct dentry * dentry;
mode_t mode;
struct sysfs_ops * ops;
};
......@@ -32,20 +29,21 @@ struct attribute {
};
extern int
sysfs_create_dir(struct driver_dir_entry *, struct driver_dir_entry *);
sysfs_create_dir(struct kobject *);
extern void
sysfs_remove_dir(struct driver_dir_entry * entry);
sysfs_remove_dir(struct kobject *);
extern int
sysfs_create_file(struct attribute * attr,
struct driver_dir_entry * parent);
sysfs_create_file(struct kobject *, struct attribute *);
extern void
sysfs_remove_file(struct kobject *, struct attribute *);
extern int
sysfs_create_symlink(struct driver_dir_entry * parent,
char * name, char * target);
sysfs_create_link(struct kobject * kobj, char * name, char * target);
extern void
sysfs_remove_file(struct driver_dir_entry *, const char * name);
sysfs_remove_link(struct kobject *, char * name);
#endif /* _SYSFS_H_ */
......@@ -9,10 +9,11 @@
L_TARGET := lib.a
export-objs := cmdline.o dec_and_lock.o rwsem-spinlock.o rwsem.o \
crc32.o rbtree.o radix-tree.o
crc32.o rbtree.o radix-tree.o kobject.o
obj-y := errno.o ctype.o string.o vsprintf.o brlock.o cmdline.o \
bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o
bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
kobject.o
obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
......
/*
* kobject.c - library routines for handling generic kernel objects
*/
#define DEBUG 1
#include <linux/kobject.h>
#include <linux/module.h>
#include <linux/stat.h>
/**
* kobject_init - initialize object.
* @kobj: object in question.
*/
void kobject_init(struct kobject * kobj)
{
atomic_set(&kobj->refcount,1);
INIT_LIST_HEAD(&kobj->entry);
}
/**
* kobject_register - register an object.
* @kobj: object in question.
*
* For now, fill in the replicated fields in the object's
* directory entry, and create a dir in sysfs.
* This stuff should go away in the future, as we move
* more implicit things to sysfs.
*/
int kobject_register(struct kobject * kobj)
{
pr_debug("kobject %s: registering\n",kobj->name);
if (kobj->parent)
kobject_get(kobj->parent);
return 0;
}
/**
* kobject_unregister - unlink an object.
* @kobj: object going away.
*
* The device has been told to be removed, but may
* not necessarily be disappearing from the kernel.
* So, we remove the directory and decrement the refcount
* that we set with kobject_register().
*
* Eventually (maybe now), the refcount will hit 0, and
* put_device() will clean the device up.
*/
void kobject_unregister(struct kobject * kobj)
{
pr_debug("kobject %s: unregistering\n",kobj->name);
kobject_put(kobj);
}
/**
* kobject_get - increment refcount for object.
* @kobj: object.
*/
struct kobject * kobject_get(struct kobject * kobj)
{
struct kobject * ret = kobj;
if (atomic_read(&kobj->refcount) > 0)
atomic_inc(&kobj->refcount);
else
ret = NULL;
return ret;
}
/**
* kobject_put - decrement refcount for object.
* @kobj: object.
*
* Decrement the refcount, and check if 0. If it is, then
* we're gonna need to clean it up, and decrement the refcount
* of its parent.
*/
void kobject_put(struct kobject * kobj)
{
struct kobject * parent = kobj->parent;
if (!atomic_dec_and_test(&kobj->refcount))
return;
pr_debug("kobject %s: cleaning up\n",kobj->name);
if (parent)
kobject_put(parent);
}
EXPORT_SYMBOL(kobject_init);
EXPORT_SYMBOL(kobject_register);
EXPORT_SYMBOL(kobject_unregister);
EXPORT_SYMBOL(kobject_get);
EXPORT_SYMBOL(kobject_put);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment