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);
#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);
相关文章推荐
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之七 - 深入解析gtest
- Shell Test命令参数解析
- LaTeX Test
- Sicily: 打印客户账单(DSA test, 2017-11-3)
- Feelings after the test.
- test1
- Hard Drive Benchmark - How to Run a Hard Drive Speed Test
- springmvc 执行@Test报错
- 内置命令test与let
- ExcelSheetHelperTest
- POPTEST老李谈JVM、JRE、JDK、java ee sdk with jdk区别
- test CSDN image question
- 测试替身(Test Double)的定义
- SilkTest Q&A 5
- test
- shell学习笔记之i f-then -test命令学习
- Test King IBM LOT-737 software
- 【巧用test判断来写shell脚本】
- 移动測试技术保护源码!解码全球首款移动端白盒測试工具ThreadingTest (文章转自己主动点科技)
- Invalid bound statement (not found): com.yu.test.dao.TaskDao.findById