Commit eda52025 authored by Patrick Mochel's avatar Patrick Mochel

sysfs: marry api with struct kobject.

This works on obviating the need for a separate data type to describe a sysfs
directory (which was renamed from struct driver_dir_entry to struct sysfs_dir).

All sysfs creation and removal functions now take a struct kobject, instead
of a struct sysfs_dir. This kobject is embedded in ->d_fsdata of the directory.

sysfs_create_dir() takes only 1 parameter now: the object that we're creating
the directory for. The parent dentry is derived by looking at the object's 
parent. 

sysfs_create_file() takes the object as the first parameter, and the attribute
as the second, which makes more sense from an API perspective. 

sysfs_remove_file() now takes an attribute as a second parameter, to be 
consistent with the creation function.

sysfs_remove_link() is created, which is basically the old sysfs_remove_file().
(symlinks don't have an attribute associated with them; only a name, which was
prohibiting the previous change). 

open() and close() look for a kobject now, and do refcounting directly on the
object. Because of that, we don't need the ->open() and ->close() callbacks
in struct sysfs_ops, so they've been removed. 

read() and write() also now look for a kobject now. 

The comments have been updated, too. 
parent c637d6b1
This diff is collapsed.
...@@ -16,6 +16,7 @@ struct kobject { ...@@ -16,6 +16,7 @@ struct kobject {
atomic_t refcount; atomic_t refcount;
struct list_head entry; struct list_head entry;
struct kobject * parent; struct kobject * parent;
struct sysfs_dir dir;
}; };
extern void kobject_init(struct kobject *); extern void kobject_init(struct kobject *);
......
...@@ -11,18 +11,15 @@ ...@@ -11,18 +11,15 @@
struct driver_dir_entry; struct driver_dir_entry;
struct attribute; struct attribute;
struct kobject;
struct sysfs_ops { struct sysfs_ops {
int (*open)(struct driver_dir_entry *); ssize_t (*show)(struct kobject *, struct attribute *,char *, size_t, loff_t);
int (*close)(struct driver_dir_entry *); ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t, loff_t);
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);
}; };
struct driver_dir_entry { struct sysfs_dir {
char * name;
struct dentry * dentry; struct dentry * dentry;
mode_t mode;
struct sysfs_ops * ops; struct sysfs_ops * ops;
}; };
...@@ -32,20 +29,21 @@ struct attribute { ...@@ -32,20 +29,21 @@ struct attribute {
}; };
extern int extern int
sysfs_create_dir(struct driver_dir_entry *, struct driver_dir_entry *); sysfs_create_dir(struct kobject *);
extern void extern void
sysfs_remove_dir(struct driver_dir_entry * entry); sysfs_remove_dir(struct kobject *);
extern int extern int
sysfs_create_file(struct attribute * attr, sysfs_create_file(struct kobject *, struct attribute *);
struct driver_dir_entry * parent);
extern void
sysfs_remove_file(struct kobject *, struct attribute *);
extern int extern int
sysfs_create_symlink(struct driver_dir_entry * parent, sysfs_create_link(struct kobject * kobj, char * name, char * target);
char * name, char * target);
extern void extern void
sysfs_remove_file(struct driver_dir_entry *, const char * name); sysfs_remove_link(struct kobject *, char * name);
#endif /* _SYSFS_H_ */ #endif /* _SYSFS_H_ */
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