test

#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);

 

 

在编程中,`void test` 通常表示一个返回值类型为 `void`(即不返回任何值)且函数名为 `test` 的函数。以下以几种常见编程语言为例介绍其含义及应用: ### C/C++ 在 C 和 C++ 中,`void` 用于表示函数不返回任何值。`void test()` 可以定义一个名为 `test` 的函数,这个函数不返回值,常用于执行一些操作,比如打印信息、修改全局变量等。 ```c #include <stdio.h> // 定义一个返回值为 void 的 test 函数 void test() { printf("This is a test function.\n"); } int main() { test(); return 0; } ``` ### Java 在 Java 中,`void` 同样用于表示方法不返回任何值。可以定义一个名为 `test` 的方法来执行特定任务。 ```java public class Main { // 定义一个返回值为 void 的 test 方法 public static void test() { System.out.println("This is a test method."); } public static void main(String[] args) { test(); } } ``` ### Python Python 没有显式的 `void` 类型,因为函数不返回值时默认返回 `None`。可以定义一个名为 `test` 的函数来执行特定操作。 ```python def test(): print("This is a test function.") test() ``` ### 错误处理 在使用 `void test` 函数时,错误处理也很重要。在 C++ 中,可以使用异常处理机制;在 Java 中,有 `try-catch` 语句;Python 则使用 `try-except` 语句。 以下是 Java 中 `void test` 函数的错误处理示例: ```java public class Main { public static void test() { try { int[] arr = new int[2]; arr[3] = 10; // 会引发数组越界异常 } catch (ArrayIndexOutOfBoundsException e) { System.out.println("An error occurred: " + e.getMessage()); } } public static void main(String[] args) { test(); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值