免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
device_attribe
sysfs - _The_ filesystem for exporting kernel objects.Patrick Mochel	<mochel@osdl.org>Mike Murphy <mamurph@cs.clemson.edu>Revised:    15 July 2010Original:   10 January 2003What it is:~~~~~~~~~~~sysfs is a ram-based filesystem initially based on ramfs. It providesa means to export kernel data structures, their attributes, and thelinkages between them to userspace.sysfs is tied inherently to the kobject infrastructure. Please readDocumentation/kobject.txt for more information concerning the kobjectinterface.Using sysfs~~~~~~~~~~~sysfs is always compiled in if CONFIG_SYSFS is defined. You can accessit by doing:mount -t sysfs sysfs /sysDirectory Creation~~~~~~~~~~~~~~~~~~For every kobject that is registered with the system, a directory iscreated for it in sysfs. That directory is created as a subdirectoryof the kobject's parent, expressing internal object hierarchies touserspace. Top-level directories in sysfs represent the commonancestors of object hierarchies; i.e. the subsystems the objectsbelong to.Sysfs internally stores a pointer to the kobject that implements adirectory in the sysfs_dirent object associated with the directory. Inthe past this kobject pointer has been used by sysfs to do referencecounting directly on the kobject whenever the file is opened or closed.With the current sysfs implementation the kobject reference count isonly modified directly by the function sysfs_schedule_callback().Attributes~~~~~~~~~~Attributes can be exported for kobjects in the form of regular files inthe filesystem. Sysfs forwards file I/O operations to methods definedfor the attributes, providing a means to read and write kernelattributes.Attributes should be ASCII text files, preferably with only one valueper file. It is noted that it may not be efficient to contain only onevalue per file, so it is socially acceptable to express an array ofvalues of the same type.Mixing types, expressing multiple lines of data, and doing fancyformatting of data is heavily frowned upon. Doing these things may getyou publicly humiliated and your code rewritten without notice.An attribute definition is simply:struct attribute {char                    * name;struct module		*owner;mode_t                  mode;};int sysfs_create_file(struct kobject * kobj, const struct attribute * attr);void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr);A bare attribute contains no means to read or write the value of theattribute. Subsystems are encouraged to define their own attributestructure and wrapper functions for adding and removing attributes fora specific object type.For example, the driver model defines struct device_attribute like:struct device_attribute {struct attribute	attr;ssize_t (*show)(struct device *dev, struct device_attribute *attr,char *buf);ssize_t (*store)(struct device *dev, struct device_attribute *attr,const char *buf, size_t count);};int device_create_file(struct device *, const struct device_attribute *);void device_remove_file(struct device *, const struct device_attribute *);It also defines this helper for defining device attributes:#define DEVICE_ATTR(_name, _mode, _show, _store) struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)For example, declaringstatic DEVICE_ATTR(foo, S_IWUSR | S_IRUGO, show_foo, store_foo);is equivalent to doing:static struct device_attribute dev_attr_foo = {.attr	= {.name = "foo",.mode = S_IWUSR | S_IRUGO,.show = show_foo,.store = store_foo,},};Subsystem-Specific Callbacks~~~~~~~~~~~~~~~~~~~~~~~~~~~~When a subsystem defines a new attribute type, it must implement aset of sysfs operations for forwarding read and write calls to theshow and store methods of the attribute owners.struct sysfs_ops {ssize_t (*show)(struct kobject *, struct attribute *, char *);ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);};[ Subsystems should have already defined a struct kobj_type as adescriptor for this type, which is where the sysfs_ops pointer isstored. See the kobject documentation for more information. ]When a file is read or written, sysfs calls the appropriate methodfor the type. The method then translates the generic struct kobjectand struct attribute pointers to the appropriate pointer types, andcalls the associated methods.To illustrate:#define to_dev(obj) container_of(obj, struct device, kobj)#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,char *buf){struct device_attribute *dev_attr = to_dev_attr(attr);struct device *dev = to_dev(kobj);ssize_t ret = -EIO;if (dev_attr->show)ret = dev_attr->show(dev, dev_attr, buf);if (ret >= (ssize_t)PAGE_SIZE) {print_symbol("dev_attr_show: %s returned bad count\n",(unsigned long)dev_attr->show);}return ret;}Reading/Writing Attribute Data~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~To read or write attributes, show() or store() methods must bespecified when declaring the attribute. The method types should be assimple as those defined for device attributes:ssize_t (*show)(struct device *dev, struct device_attribute *attr, char *buf);ssize_t (*store)(struct device *dev, struct device_attribute *attr,const char *buf, size_t count);IOW, they should take only an object, an attribute, and a buffer as parameters.sysfs allocates a buffer of size (PAGE_SIZE) and passes it to themethod. Sysfs will call the method exactly once for each read orwrite. This forces the following behavior on the methodimplementations:- On read(2), the show() method should fill the entire buffer.Recall that an attribute should only be exporting one value, or anarray of similar values, so this shouldn't be that expensive.This allows userspace to do partial reads and forward seeksarbitrarily over the entire file at will. If userspace seeks back tozero or does a pread(2) with an offset of '0' the show() method willbe called again, rearmed, to fill the buffer.- On write(2), sysfs expects the entire buffer to be passed during thefirst write. Sysfs then passes the entire buffer to the store()method.When writing sysfs files, userspace processes should first read theentire file, modify the values it wishes to change, then write theentire buffer back.Attribute method implementations should operate on an identicalbuffer when reading and writing values.Other notes:- Writing causes the show() method to be rearmed regardless of currentfile position.- The buffer will always be PAGE_SIZE bytes in length. On i386, thisis 4096.- show() methods should return the number of bytes printed into thebuffer. This is the return value of scnprintf().- show() should always use scnprintf().- store() should return the number of bytes used from the buffer. If theentire buffer has been used, just return the count argument.- show() or store() can always return errors. If a bad value comesthrough, be sure to return an error.- The object passed to the methods will be pinned in memory via sysfsreferencing counting its embedded object. However, the physicalentity (e.g. device) the object represents may not be present. Besure to have a way to check this, if necessary.A very simple (and naive) implementation of a device attribute is:static ssize_t show_name(struct device *dev, struct device_attribute *attr,char *buf){return scnprintf(buf, PAGE_SIZE, "%s\n", dev->name);}static ssize_t store_name(struct device *dev, struct device_attribute *attr,const char *buf, size_t count){snprintf(dev->name, sizeof(dev->name), "%.*s",(int)min(count, sizeof(dev->name) - 1), buf);return count;}static DEVICE_ATTR(name, S_IRUGO, show_name, store_name);(Note that the real implementation doesn't allow userspace to set thename for a device.)Top Level Directory Layout~~~~~~~~~~~~~~~~~~~~~~~~~~The sysfs directory arrangement exposes the relationship of kerneldata structures.The top level sysfs directory looks like:block/bus/class/dev/devices/firmware/net/fs/devices/ contains a filesystem representation of the device tree. It mapsdirectly to the internal kernel device tree, which is a hierarchy ofstruct device.bus/ contains flat directory layout of the various bus types in thekernel. Each bus's directory contains two subdirectories:devices/drivers/devices/ contains symlinks for each device discovered in the systemthat point to the device's directory under root/.drivers/ contains a directory for each device driver that is loadedfor devices on that particular bus (this assumes that drivers do notspan multiple bus types).fs/ contains a directory for some filesystems.  Currently eachfilesystem wanting to export attributes must create its own hierarchybelow fs/ (see ./fuse.txt for an example).dev/ contains two directories char/ and block/. Inside these twodirectories there are symlinks named <major>:<minor>.  These symlinkspoint to the sysfs directory for the given device.  /sys/dev provides aquick way to lookup the sysfs interface for a device from the result ofa stat(2) operation.More information can driver-model specific features can be found inDocumentation/driver-model/.TODO: Finish this section.Current Interfaces~~~~~~~~~~~~~~~~~~The following interface layers currently exist in sysfs:- devices (include/linux/device.h)----------------------------------Structure:struct device_attribute {struct attribute	attr;ssize_t (*show)(struct device *dev, struct device_attribute *attr,char *buf);ssize_t (*store)(struct device *dev, struct device_attribute *attr,const char *buf, size_t count);};Declaring:DEVICE_ATTR(_name, _mode, _show, _store);Creation/Removal:int device_create_file(struct device *dev, const struct device_attribute * attr);void device_remove_file(struct device *dev, const struct device_attribute * attr);- bus drivers (include/linux/device.h)--------------------------------------Structure:struct bus_attribute {struct attribute        attr;ssize_t (*show)(struct bus_type *, char * buf);ssize_t (*store)(struct bus_type *, const char * buf, size_t count);};Declaring:BUS_ATTR(_name, _mode, _show, _store)Creation/Removal:int bus_create_file(struct bus_type *, struct bus_attribute *);void bus_remove_file(struct bus_type *, struct bus_attribute *);- device drivers (include/linux/device.h)-----------------------------------------Structure:struct driver_attribute {struct attribute        attr;ssize_t (*show)(struct device_driver *, char * buf);ssize_t (*store)(struct device_driver *, const char * buf,size_t count);};Declaring:DRIVER_ATTR(_name, _mode, _show, _store)Creation/Removal:int driver_create_file(struct device_driver *, const struct driver_attribute *);void driver_remove_file(struct device_driver *, const struct driver_attribute *);
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Linux設(shè)備模型(5)_device和device driver
Linux RTC驅(qū)動(dòng)分析(三)
【原創(chuàng)】linux設(shè)備模型之kset/kobj/ktype分析
Linux 虛擬文件系統(tǒng)sysfs之屬性文件attribute 整理(一)
DEVICE
sysfs接口函數(shù)DEVICE
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服