日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

read函数头文件 window_of_property_read_string 剖析

發布時間:2025/3/15 windows 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 read函数头文件 window_of_property_read_string 剖析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

今天在一個群里面看到的一個朋友提交,說of_property_read_string 這個函數有兩個定義,到底是用了哪個呢?

所以這篇文章就說下這個函數。

函數引用的頭文件

引用的頭文件位置在

kernel-4.4includelinuxof.h

其中一個是

extern int of_property_read_string(struct device_node *np,const char *propname,const char **out_string);

還有一個是

static inline int of_property_read_string(struct device_node *np,const char *propname,const char **out_string) {return -ENOSYS; }

但是并不是兩個都用到,他們用了一個宏 CONFIG_OF 來選擇

CONFIG_OF 宏有什么用?

這個宏的解釋是

Open Firmware. This was invented long time ago when Apple was producing laptops based on PowerPC CPUs. Openfirmware provides a good description of the devices connected to the platform. In Linux kernel the part that works with device data is called Device Tree (DT). More details in theUsage model.

他的作用是

Openfirmware provides a good description of the devices connected to the platform

他提供了一種更好的方式來連接設備和驅動。

他是名字是

called Device Tree (DT)

DTS,那很明顯了,開了這個宏,就表示使用了DTS設備樹的方式來連接設備和驅動程序。

of_property_read_string 函數本體

函數位置

"./drivers/of/base.c"

函數原型

/*** of_property_read_string - Find and read a string from a property* @np: device node from which the property value is to be read.* @propname: name of the property to be searched.* @out_string: pointer to null terminated return string, modified only if* return value is 0.** Search for a property in a device tree node and retrieve a null* terminated string value (pointer to data, not a copy). Returns 0 on* success, -EINVAL if the property does not exist, -ENODATA if property* does not have a value, and -EILSEQ if the string is not null-terminated* within the length of the property data.** The out_string pointer is modified only if a valid string can be decoded.*/ int of_property_read_string(struct device_node *np, const char *propname,const char **out_string) {struct property *prop = of_find_property(np, propname, NULL);if (!prop)return -EINVAL;if (!prop->value)return -ENODATA;if (strnlen(prop->value, prop->length) >= prop->length)return -EILSEQ;*out_string = prop->value;return 0; } EXPORT_SYMBOL_GPL(of_property_read_string);

函數的作用:

返回propname對應dts節點對應的值。

使用方式:

傳入np,就是設備樹的節點,然后返回 "clock-output-names" 字符串對應的值,存入clk_name 里面。

of_property_read_string 函數剖析

int of_property_read_string(struct device_node *np, const char *propname,const char **out_string) {struct property *prop = of_find_property(np, propname, NULL);if (!prop)return -EINVAL;if (!prop->value)return -ENODATA;if (strnlen(prop->value, prop->length) >= prop->length)return -EILSEQ;*out_string = prop->value;return 0; } EXPORT_SYMBOL_GPL(of_property_read_string);
  • of_find_property 這個是找到這個dts節點,怎么找,可以再去這個函數分析一下。
  • strnlen功能「獲取字符串實際字符個數,不包括結尾的'0';如果實際個數 <= 第二個參數,則返回字符串實際字符個數,否則返回第二個參數。」
  • prop->length 是之前預設的一個值,strnlen正常情況返回的就是字符串的長度 減1「去掉n字符」。
  • *out_string = prop->value 這里就是二級指針起到作用了,沒有重新分配內存,直接把指針指向字符串位置。

我們再看看prop 的結構體,就一目了然了。

struct property {char *name;int length;void *value;struct property *next;unsigned long _flags;unsigned int unique_id;struct bin_attribute attr; };

總結

以上是生活随笔為你收集整理的read函数头文件 window_of_property_read_string 剖析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。