您的位置:首页 > 其它

test

2010-10-18 17:27 316 查看
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>

MODULE_LICENSE("Dual BSD/GPL");

typedef struct zte_storage_entry_s zte_storage_entry_t;

struct zte_storage_entry_s
{
struct attribute attr;
ssize_t (*show)(char *page);
ssize_t (*store)(const char *page, size_t len);
};

static ssize_t level_show()
{
return 1;
}

static ssize_t level_store()
{

return len;
}

static dg_sys_entry_t level =
__ATTR(level, S_IRUGO | S_IWUSR, level_show, level_store);

static struct attribute *pd_attrs[] =
{
&level.attr,
NULL,
}

static ssize_t pd_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
{
zte_storage_entry_s *entry = container_of(attr, zte_storage_entry_s, attr);

if (!entry->show)
return -EIO;

rv = entry->show();

return rv;
}

static ssize_t pd_attr_store(struct kobject *kobj, struct attribute *attr,
const char *page, size_t length)
{
zte_storage_entry_s *entry = container_of(attr, zte_storage_entry_s, attr);
dg_t *dg = container_of(kobj, dg_t, kobj);
ssize_t rv;

if (!entry->store)
return -EIO;
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
rv = entry->store();
return length;
}

static void pd_free(struct kobject *ko)
{
return ;
}

static struct sysfs_ops pd_ops =
{
.show = pd_attr_show,
.store = pd_attr_store,
};

static struct kobj_type pd_ktype =
{
.release = pd_free,
.sysfs_ops = &pd_ops,
.default_attrs = pd_attrs,
};

typedef struct zte_storage_s
{
struct kobject kobj;
}pd_t;

pd_t zs_obj;

static int hello_init(void)
{

zs_obj->kobj.parent = NULL;
zs_obj->kobj.kset = NULL;
zs_obj->kobj.k_name = NULL;
snprintf(zs_obj->kobj.name, KOBJ_NAME_LEN, "%s", "zte");

zs_obj->kobj.ktype = &pd_ktype;
if (kobject_register(&zs_obj->kobj))
{
printk(KERN_WARNING "vds_pd:%s: cannot register !/n", zs_obj->kobj.name);
return - 1;
}

printk(KERN_ALERT "Hello, world/n");
return 0;
}

static void hello_exit(void)
{

printk(KERN_ALERT "Goodbye, cruel world/n");
}

module_init(hello_init);
module_exit(hello_exit);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: