sys/class 下文件节点创建实例
2014-08-29 14:16
302 查看
1 创建读版本号节点
firmware_class = class_create(THIS_MODULE, "ms-touchscreen-msg20xx");
if (IS_ERR(firmware_class))
pr_err("Failed to create class(firmware)!\n");
firmware_cmd_dev = device_create(firmware_class, NULL, 0, NULL, "device");
if (IS_ERR(firmware_cmd_dev))
pr_err("Failed to create device(firmware_cmd_dev)!\n");
if (device_create_file(firmware_cmd_dev, &dev_attr_version) < 0)
pr_err("Failed to create device file(%s)!\n", dev_attr_version.attr.name);
static ssize_t firmware_version_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
_msg_GetVersion();
if(fw_version == NULL)
{
fw_version = kzalloc(sizeof(*fw_version)*8, GFP_KERNEL);
}
sprintf(fw_version, "%04d%04d", curr_ic_major, curr_ic_minor);
TPD_DEBUG_UPDATE("*** firmware_version_show fw_version = %s***\n", fw_version);
return sprintf(buf, "%s\n", fw_version);
}
static ssize_t firmware_version_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t size)
{
_msg_GetVersion();
if(fw_version == NULL)
{
fw_version = kzalloc(sizeof(*fw_version)*8, GFP_KERNEL);
}
sprintf(fw_version, "%04d%04d", curr_ic_major, curr_ic_minor);
TPD_DEBUG_UPDATE("*** fw_version = %s ***\n", fw_version);
#ifdef CONFIG_ENABLE_FIRMWARE_DATA_LOG
restore_firmware_mode_to_debug_mode();
#endif //CONFIG_ENABLE_FIRMWARE_DATA_LOG
if(buf != NULL)
TPD_DEBUG_UPDATE("buf = %c ***\n", buf[0]);
return size;
}
static DEVICE_ATTR(version,0664, firmware_version_show, firmware_version_store);
firmware_class = class_create(THIS_MODULE, "ms-touchscreen-msg20xx");
if (IS_ERR(firmware_class))
pr_err("Failed to create class(firmware)!\n");
firmware_cmd_dev = device_create(firmware_class, NULL, 0, NULL, "device");
if (IS_ERR(firmware_cmd_dev))
pr_err("Failed to create device(firmware_cmd_dev)!\n");
if (device_create_file(firmware_cmd_dev, &dev_attr_version) < 0)
pr_err("Failed to create device file(%s)!\n", dev_attr_version.attr.name);
static ssize_t firmware_version_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
_msg_GetVersion();
if(fw_version == NULL)
{
fw_version = kzalloc(sizeof(*fw_version)*8, GFP_KERNEL);
}
sprintf(fw_version, "%04d%04d", curr_ic_major, curr_ic_minor);
TPD_DEBUG_UPDATE("*** firmware_version_show fw_version = %s***\n", fw_version);
return sprintf(buf, "%s\n", fw_version);
}
static ssize_t firmware_version_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t size)
{
_msg_GetVersion();
if(fw_version == NULL)
{
fw_version = kzalloc(sizeof(*fw_version)*8, GFP_KERNEL);
}
sprintf(fw_version, "%04d%04d", curr_ic_major, curr_ic_minor);
TPD_DEBUG_UPDATE("*** fw_version = %s ***\n", fw_version);
#ifdef CONFIG_ENABLE_FIRMWARE_DATA_LOG
restore_firmware_mode_to_debug_mode();
#endif //CONFIG_ENABLE_FIRMWARE_DATA_LOG
if(buf != NULL)
TPD_DEBUG_UPDATE("buf = %c ***\n", buf[0]);
return size;
}
static DEVICE_ATTR(version,0664, firmware_version_show, firmware_version_store);
相关文章推荐
- Documentation:Linux/GPIO,应用层写/sys/class/gpio/export文件,创建gpio107 gpio108等
- linux下自动创建设备文件节点---class
- linux下自动创建设备文件节点---class
- 创建一个自定义类加载器实现class文件(字节码文件)的加密解密的实例
- 在/sys/class下创建访问节点
- 遍历 XML 文件所有节点的实例代码(递归调用)
- Tibco中文件的创建,超级简单实例
- 使用Properties文件配置实例的创建
- Java语言基础08-创建 class 的实例
- 实例讲解.NET中资源文件的创建与使用
- C# 用Linq的方式实现对Xml文件的基本操作(创建xml文件、增删改查xml文件节点信息)
- 实例讲解.NET中资源文件的创建与使用
- 实例讲解.NET中资源文件的创建与使用(转)
- C# 用Linq的方式实现对Xml文件的基本操作(创建xml文件、增删改查xml文件节点信息)zz
- Spring.net在.NET应用程序的标准配置文件中用一个自定义节点来配置容器实例
- 在内核中创建文件 filp_open/sys_open
- Tibco中文件的创建,超级简单实例
- 实例讲解.NET中资源文件的创建与使用
- 实例讲解.NET中资源文件的创建与使用
- 动态创建表格js文件,javascript,Ajax,DHTML动态实现表格的创建,动态读取XML中的文件,读取dom节点的例子。