1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun===================================================== 4*4882a593Smuzhiyunsysfs - _The_ filesystem for exporting kernel objects 5*4882a593Smuzhiyun===================================================== 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunPatrick Mochel <mochel@osdl.org> 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunMike Murphy <mamurph@cs.clemson.edu> 10*4882a593Smuzhiyun 11*4882a593Smuzhiyun:Revised: 16 August 2011 12*4882a593Smuzhiyun:Original: 10 January 2003 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunWhat it is: 16*4882a593Smuzhiyun~~~~~~~~~~~ 17*4882a593Smuzhiyun 18*4882a593Smuzhiyunsysfs is a ram-based filesystem initially based on ramfs. It provides 19*4882a593Smuzhiyuna means to export kernel data structures, their attributes, and the 20*4882a593Smuzhiyunlinkages between them to userspace. 21*4882a593Smuzhiyun 22*4882a593Smuzhiyunsysfs is tied inherently to the kobject infrastructure. Please read 23*4882a593SmuzhiyunDocumentation/core-api/kobject.rst for more information concerning the kobject 24*4882a593Smuzhiyuninterface. 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunUsing sysfs 28*4882a593Smuzhiyun~~~~~~~~~~~ 29*4882a593Smuzhiyun 30*4882a593Smuzhiyunsysfs is always compiled in if CONFIG_SYSFS is defined. You can access 31*4882a593Smuzhiyunit by doing:: 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun mount -t sysfs sysfs /sys 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun 36*4882a593SmuzhiyunDirectory Creation 37*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~ 38*4882a593Smuzhiyun 39*4882a593SmuzhiyunFor every kobject that is registered with the system, a directory is 40*4882a593Smuzhiyuncreated for it in sysfs. That directory is created as a subdirectory 41*4882a593Smuzhiyunof the kobject's parent, expressing internal object hierarchies to 42*4882a593Smuzhiyunuserspace. Top-level directories in sysfs represent the common 43*4882a593Smuzhiyunancestors of object hierarchies; i.e. the subsystems the objects 44*4882a593Smuzhiyunbelong to. 45*4882a593Smuzhiyun 46*4882a593SmuzhiyunSysfs internally stores a pointer to the kobject that implements a 47*4882a593Smuzhiyundirectory in the kernfs_node object associated with the directory. In 48*4882a593Smuzhiyunthe past this kobject pointer has been used by sysfs to do reference 49*4882a593Smuzhiyuncounting directly on the kobject whenever the file is opened or closed. 50*4882a593SmuzhiyunWith the current sysfs implementation the kobject reference count is 51*4882a593Smuzhiyunonly modified directly by the function sysfs_schedule_callback(). 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun 54*4882a593SmuzhiyunAttributes 55*4882a593Smuzhiyun~~~~~~~~~~ 56*4882a593Smuzhiyun 57*4882a593SmuzhiyunAttributes can be exported for kobjects in the form of regular files in 58*4882a593Smuzhiyunthe filesystem. Sysfs forwards file I/O operations to methods defined 59*4882a593Smuzhiyunfor the attributes, providing a means to read and write kernel 60*4882a593Smuzhiyunattributes. 61*4882a593Smuzhiyun 62*4882a593SmuzhiyunAttributes should be ASCII text files, preferably with only one value 63*4882a593Smuzhiyunper file. It is noted that it may not be efficient to contain only one 64*4882a593Smuzhiyunvalue per file, so it is socially acceptable to express an array of 65*4882a593Smuzhiyunvalues of the same type. 66*4882a593Smuzhiyun 67*4882a593SmuzhiyunMixing types, expressing multiple lines of data, and doing fancy 68*4882a593Smuzhiyunformatting of data is heavily frowned upon. Doing these things may get 69*4882a593Smuzhiyunyou publicly humiliated and your code rewritten without notice. 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun 72*4882a593SmuzhiyunAn attribute definition is simply:: 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun struct attribute { 75*4882a593Smuzhiyun char * name; 76*4882a593Smuzhiyun struct module *owner; 77*4882a593Smuzhiyun umode_t mode; 78*4882a593Smuzhiyun }; 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun 81*4882a593Smuzhiyun int sysfs_create_file(struct kobject * kobj, const struct attribute * attr); 82*4882a593Smuzhiyun void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr); 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun 85*4882a593SmuzhiyunA bare attribute contains no means to read or write the value of the 86*4882a593Smuzhiyunattribute. Subsystems are encouraged to define their own attribute 87*4882a593Smuzhiyunstructure and wrapper functions for adding and removing attributes for 88*4882a593Smuzhiyuna specific object type. 89*4882a593Smuzhiyun 90*4882a593SmuzhiyunFor example, the driver model defines struct device_attribute like:: 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun struct device_attribute { 93*4882a593Smuzhiyun struct attribute attr; 94*4882a593Smuzhiyun ssize_t (*show)(struct device *dev, struct device_attribute *attr, 95*4882a593Smuzhiyun char *buf); 96*4882a593Smuzhiyun ssize_t (*store)(struct device *dev, struct device_attribute *attr, 97*4882a593Smuzhiyun const char *buf, size_t count); 98*4882a593Smuzhiyun }; 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun int device_create_file(struct device *, const struct device_attribute *); 101*4882a593Smuzhiyun void device_remove_file(struct device *, const struct device_attribute *); 102*4882a593Smuzhiyun 103*4882a593SmuzhiyunIt also defines this helper for defining device attributes:: 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun #define DEVICE_ATTR(_name, _mode, _show, _store) \ 106*4882a593Smuzhiyun struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) 107*4882a593Smuzhiyun 108*4882a593SmuzhiyunFor example, declaring:: 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun static DEVICE_ATTR(foo, S_IWUSR | S_IRUGO, show_foo, store_foo); 111*4882a593Smuzhiyun 112*4882a593Smuzhiyunis equivalent to doing:: 113*4882a593Smuzhiyun 114*4882a593Smuzhiyun static struct device_attribute dev_attr_foo = { 115*4882a593Smuzhiyun .attr = { 116*4882a593Smuzhiyun .name = "foo", 117*4882a593Smuzhiyun .mode = S_IWUSR | S_IRUGO, 118*4882a593Smuzhiyun }, 119*4882a593Smuzhiyun .show = show_foo, 120*4882a593Smuzhiyun .store = store_foo, 121*4882a593Smuzhiyun }; 122*4882a593Smuzhiyun 123*4882a593SmuzhiyunNote as stated in include/linux/kernel.h "OTHER_WRITABLE? Generally 124*4882a593Smuzhiyunconsidered a bad idea." so trying to set a sysfs file writable for 125*4882a593Smuzhiyuneveryone will fail reverting to RO mode for "Others". 126*4882a593Smuzhiyun 127*4882a593SmuzhiyunFor the common cases sysfs.h provides convenience macros to make 128*4882a593Smuzhiyundefining attributes easier as well as making code more concise and 129*4882a593Smuzhiyunreadable. The above case could be shortened to: 130*4882a593Smuzhiyun 131*4882a593Smuzhiyunstatic struct device_attribute dev_attr_foo = __ATTR_RW(foo); 132*4882a593Smuzhiyun 133*4882a593Smuzhiyunthe list of helpers available to define your wrapper function is: 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun__ATTR_RO(name): 136*4882a593Smuzhiyun assumes default name_show and mode 0444 137*4882a593Smuzhiyun__ATTR_WO(name): 138*4882a593Smuzhiyun assumes a name_store only and is restricted to mode 139*4882a593Smuzhiyun 0200 that is root write access only. 140*4882a593Smuzhiyun__ATTR_RO_MODE(name, mode): 141*4882a593Smuzhiyun fore more restrictive RO access currently 142*4882a593Smuzhiyun only use case is the EFI System Resource Table 143*4882a593Smuzhiyun (see drivers/firmware/efi/esrt.c) 144*4882a593Smuzhiyun__ATTR_RW(name): 145*4882a593Smuzhiyun assumes default name_show, name_store and setting 146*4882a593Smuzhiyun mode to 0644. 147*4882a593Smuzhiyun__ATTR_NULL: 148*4882a593Smuzhiyun which sets the name to NULL and is used as end of list 149*4882a593Smuzhiyun indicator (see: kernel/workqueue.c) 150*4882a593Smuzhiyun 151*4882a593SmuzhiyunSubsystem-Specific Callbacks 152*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 153*4882a593Smuzhiyun 154*4882a593SmuzhiyunWhen a subsystem defines a new attribute type, it must implement a 155*4882a593Smuzhiyunset of sysfs operations for forwarding read and write calls to the 156*4882a593Smuzhiyunshow and store methods of the attribute owners:: 157*4882a593Smuzhiyun 158*4882a593Smuzhiyun struct sysfs_ops { 159*4882a593Smuzhiyun ssize_t (*show)(struct kobject *, struct attribute *, char *); 160*4882a593Smuzhiyun ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t); 161*4882a593Smuzhiyun }; 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun[ Subsystems should have already defined a struct kobj_type as a 164*4882a593Smuzhiyundescriptor for this type, which is where the sysfs_ops pointer is 165*4882a593Smuzhiyunstored. See the kobject documentation for more information. ] 166*4882a593Smuzhiyun 167*4882a593SmuzhiyunWhen a file is read or written, sysfs calls the appropriate method 168*4882a593Smuzhiyunfor the type. The method then translates the generic struct kobject 169*4882a593Smuzhiyunand struct attribute pointers to the appropriate pointer types, and 170*4882a593Smuzhiyuncalls the associated methods. 171*4882a593Smuzhiyun 172*4882a593Smuzhiyun 173*4882a593SmuzhiyunTo illustrate:: 174*4882a593Smuzhiyun 175*4882a593Smuzhiyun #define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr) 176*4882a593Smuzhiyun 177*4882a593Smuzhiyun static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr, 178*4882a593Smuzhiyun char *buf) 179*4882a593Smuzhiyun { 180*4882a593Smuzhiyun struct device_attribute *dev_attr = to_dev_attr(attr); 181*4882a593Smuzhiyun struct device *dev = kobj_to_dev(kobj); 182*4882a593Smuzhiyun ssize_t ret = -EIO; 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun if (dev_attr->show) 185*4882a593Smuzhiyun ret = dev_attr->show(dev, dev_attr, buf); 186*4882a593Smuzhiyun if (ret >= (ssize_t)PAGE_SIZE) { 187*4882a593Smuzhiyun printk("dev_attr_show: %pS returned bad count\n", 188*4882a593Smuzhiyun dev_attr->show); 189*4882a593Smuzhiyun } 190*4882a593Smuzhiyun return ret; 191*4882a593Smuzhiyun } 192*4882a593Smuzhiyun 193*4882a593Smuzhiyun 194*4882a593Smuzhiyun 195*4882a593SmuzhiyunReading/Writing Attribute Data 196*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 197*4882a593Smuzhiyun 198*4882a593SmuzhiyunTo read or write attributes, show() or store() methods must be 199*4882a593Smuzhiyunspecified when declaring the attribute. The method types should be as 200*4882a593Smuzhiyunsimple as those defined for device attributes:: 201*4882a593Smuzhiyun 202*4882a593Smuzhiyun ssize_t (*show)(struct device *dev, struct device_attribute *attr, char *buf); 203*4882a593Smuzhiyun ssize_t (*store)(struct device *dev, struct device_attribute *attr, 204*4882a593Smuzhiyun const char *buf, size_t count); 205*4882a593Smuzhiyun 206*4882a593SmuzhiyunIOW, they should take only an object, an attribute, and a buffer as parameters. 207*4882a593Smuzhiyun 208*4882a593Smuzhiyun 209*4882a593Smuzhiyunsysfs allocates a buffer of size (PAGE_SIZE) and passes it to the 210*4882a593Smuzhiyunmethod. Sysfs will call the method exactly once for each read or 211*4882a593Smuzhiyunwrite. This forces the following behavior on the method 212*4882a593Smuzhiyunimplementations: 213*4882a593Smuzhiyun 214*4882a593Smuzhiyun- On read(2), the show() method should fill the entire buffer. 215*4882a593Smuzhiyun Recall that an attribute should only be exporting one value, or an 216*4882a593Smuzhiyun array of similar values, so this shouldn't be that expensive. 217*4882a593Smuzhiyun 218*4882a593Smuzhiyun This allows userspace to do partial reads and forward seeks 219*4882a593Smuzhiyun arbitrarily over the entire file at will. If userspace seeks back to 220*4882a593Smuzhiyun zero or does a pread(2) with an offset of '0' the show() method will 221*4882a593Smuzhiyun be called again, rearmed, to fill the buffer. 222*4882a593Smuzhiyun 223*4882a593Smuzhiyun- On write(2), sysfs expects the entire buffer to be passed during the 224*4882a593Smuzhiyun first write. Sysfs then passes the entire buffer to the store() method. 225*4882a593Smuzhiyun A terminating null is added after the data on stores. This makes 226*4882a593Smuzhiyun functions like sysfs_streq() safe to use. 227*4882a593Smuzhiyun 228*4882a593Smuzhiyun When writing sysfs files, userspace processes should first read the 229*4882a593Smuzhiyun entire file, modify the values it wishes to change, then write the 230*4882a593Smuzhiyun entire buffer back. 231*4882a593Smuzhiyun 232*4882a593Smuzhiyun Attribute method implementations should operate on an identical 233*4882a593Smuzhiyun buffer when reading and writing values. 234*4882a593Smuzhiyun 235*4882a593SmuzhiyunOther notes: 236*4882a593Smuzhiyun 237*4882a593Smuzhiyun- Writing causes the show() method to be rearmed regardless of current 238*4882a593Smuzhiyun file position. 239*4882a593Smuzhiyun 240*4882a593Smuzhiyun- The buffer will always be PAGE_SIZE bytes in length. On i386, this 241*4882a593Smuzhiyun is 4096. 242*4882a593Smuzhiyun 243*4882a593Smuzhiyun- show() methods should return the number of bytes printed into the 244*4882a593Smuzhiyun buffer. 245*4882a593Smuzhiyun 246*4882a593Smuzhiyun- show() should only use sysfs_emit() or sysfs_emit_at() when formatting 247*4882a593Smuzhiyun the value to be returned to user space. 248*4882a593Smuzhiyun 249*4882a593Smuzhiyun- store() should return the number of bytes used from the buffer. If the 250*4882a593Smuzhiyun entire buffer has been used, just return the count argument. 251*4882a593Smuzhiyun 252*4882a593Smuzhiyun- show() or store() can always return errors. If a bad value comes 253*4882a593Smuzhiyun through, be sure to return an error. 254*4882a593Smuzhiyun 255*4882a593Smuzhiyun- The object passed to the methods will be pinned in memory via sysfs 256*4882a593Smuzhiyun referencing counting its embedded object. However, the physical 257*4882a593Smuzhiyun entity (e.g. device) the object represents may not be present. Be 258*4882a593Smuzhiyun sure to have a way to check this, if necessary. 259*4882a593Smuzhiyun 260*4882a593Smuzhiyun 261*4882a593SmuzhiyunA very simple (and naive) implementation of a device attribute is:: 262*4882a593Smuzhiyun 263*4882a593Smuzhiyun static ssize_t show_name(struct device *dev, struct device_attribute *attr, 264*4882a593Smuzhiyun char *buf) 265*4882a593Smuzhiyun { 266*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%s\n", dev->name); 267*4882a593Smuzhiyun } 268*4882a593Smuzhiyun 269*4882a593Smuzhiyun static ssize_t store_name(struct device *dev, struct device_attribute *attr, 270*4882a593Smuzhiyun const char *buf, size_t count) 271*4882a593Smuzhiyun { 272*4882a593Smuzhiyun snprintf(dev->name, sizeof(dev->name), "%.*s", 273*4882a593Smuzhiyun (int)min(count, sizeof(dev->name) - 1), buf); 274*4882a593Smuzhiyun return count; 275*4882a593Smuzhiyun } 276*4882a593Smuzhiyun 277*4882a593Smuzhiyun static DEVICE_ATTR(name, S_IRUGO, show_name, store_name); 278*4882a593Smuzhiyun 279*4882a593Smuzhiyun 280*4882a593Smuzhiyun(Note that the real implementation doesn't allow userspace to set the 281*4882a593Smuzhiyunname for a device.) 282*4882a593Smuzhiyun 283*4882a593Smuzhiyun 284*4882a593SmuzhiyunTop Level Directory Layout 285*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~ 286*4882a593Smuzhiyun 287*4882a593SmuzhiyunThe sysfs directory arrangement exposes the relationship of kernel 288*4882a593Smuzhiyundata structures. 289*4882a593Smuzhiyun 290*4882a593SmuzhiyunThe top level sysfs directory looks like:: 291*4882a593Smuzhiyun 292*4882a593Smuzhiyun block/ 293*4882a593Smuzhiyun bus/ 294*4882a593Smuzhiyun class/ 295*4882a593Smuzhiyun dev/ 296*4882a593Smuzhiyun devices/ 297*4882a593Smuzhiyun firmware/ 298*4882a593Smuzhiyun net/ 299*4882a593Smuzhiyun fs/ 300*4882a593Smuzhiyun 301*4882a593Smuzhiyundevices/ contains a filesystem representation of the device tree. It maps 302*4882a593Smuzhiyundirectly to the internal kernel device tree, which is a hierarchy of 303*4882a593Smuzhiyunstruct device. 304*4882a593Smuzhiyun 305*4882a593Smuzhiyunbus/ contains flat directory layout of the various bus types in the 306*4882a593Smuzhiyunkernel. Each bus's directory contains two subdirectories:: 307*4882a593Smuzhiyun 308*4882a593Smuzhiyun devices/ 309*4882a593Smuzhiyun drivers/ 310*4882a593Smuzhiyun 311*4882a593Smuzhiyundevices/ contains symlinks for each device discovered in the system 312*4882a593Smuzhiyunthat point to the device's directory under root/. 313*4882a593Smuzhiyun 314*4882a593Smuzhiyundrivers/ contains a directory for each device driver that is loaded 315*4882a593Smuzhiyunfor devices on that particular bus (this assumes that drivers do not 316*4882a593Smuzhiyunspan multiple bus types). 317*4882a593Smuzhiyun 318*4882a593Smuzhiyunfs/ contains a directory for some filesystems. Currently each 319*4882a593Smuzhiyunfilesystem wanting to export attributes must create its own hierarchy 320*4882a593Smuzhiyunbelow fs/ (see ./fuse.txt for an example). 321*4882a593Smuzhiyun 322*4882a593Smuzhiyundev/ contains two directories char/ and block/. Inside these two 323*4882a593Smuzhiyundirectories there are symlinks named <major>:<minor>. These symlinks 324*4882a593Smuzhiyunpoint to the sysfs directory for the given device. /sys/dev provides a 325*4882a593Smuzhiyunquick way to lookup the sysfs interface for a device from the result of 326*4882a593Smuzhiyuna stat(2) operation. 327*4882a593Smuzhiyun 328*4882a593SmuzhiyunMore information can driver-model specific features can be found in 329*4882a593SmuzhiyunDocumentation/driver-api/driver-model/. 330*4882a593Smuzhiyun 331*4882a593Smuzhiyun 332*4882a593SmuzhiyunTODO: Finish this section. 333*4882a593Smuzhiyun 334*4882a593Smuzhiyun 335*4882a593SmuzhiyunCurrent Interfaces 336*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~ 337*4882a593Smuzhiyun 338*4882a593SmuzhiyunThe following interface layers currently exist in sysfs: 339*4882a593Smuzhiyun 340*4882a593Smuzhiyun 341*4882a593Smuzhiyundevices (include/linux/device.h) 342*4882a593Smuzhiyun-------------------------------- 343*4882a593SmuzhiyunStructure:: 344*4882a593Smuzhiyun 345*4882a593Smuzhiyun struct device_attribute { 346*4882a593Smuzhiyun struct attribute attr; 347*4882a593Smuzhiyun ssize_t (*show)(struct device *dev, struct device_attribute *attr, 348*4882a593Smuzhiyun char *buf); 349*4882a593Smuzhiyun ssize_t (*store)(struct device *dev, struct device_attribute *attr, 350*4882a593Smuzhiyun const char *buf, size_t count); 351*4882a593Smuzhiyun }; 352*4882a593Smuzhiyun 353*4882a593SmuzhiyunDeclaring:: 354*4882a593Smuzhiyun 355*4882a593Smuzhiyun DEVICE_ATTR(_name, _mode, _show, _store); 356*4882a593Smuzhiyun 357*4882a593SmuzhiyunCreation/Removal:: 358*4882a593Smuzhiyun 359*4882a593Smuzhiyun int device_create_file(struct device *dev, const struct device_attribute * attr); 360*4882a593Smuzhiyun void device_remove_file(struct device *dev, const struct device_attribute * attr); 361*4882a593Smuzhiyun 362*4882a593Smuzhiyun 363*4882a593Smuzhiyunbus drivers (include/linux/device.h) 364*4882a593Smuzhiyun------------------------------------ 365*4882a593SmuzhiyunStructure:: 366*4882a593Smuzhiyun 367*4882a593Smuzhiyun struct bus_attribute { 368*4882a593Smuzhiyun struct attribute attr; 369*4882a593Smuzhiyun ssize_t (*show)(struct bus_type *, char * buf); 370*4882a593Smuzhiyun ssize_t (*store)(struct bus_type *, const char * buf, size_t count); 371*4882a593Smuzhiyun }; 372*4882a593Smuzhiyun 373*4882a593SmuzhiyunDeclaring:: 374*4882a593Smuzhiyun 375*4882a593Smuzhiyun static BUS_ATTR_RW(name); 376*4882a593Smuzhiyun static BUS_ATTR_RO(name); 377*4882a593Smuzhiyun static BUS_ATTR_WO(name); 378*4882a593Smuzhiyun 379*4882a593SmuzhiyunCreation/Removal:: 380*4882a593Smuzhiyun 381*4882a593Smuzhiyun int bus_create_file(struct bus_type *, struct bus_attribute *); 382*4882a593Smuzhiyun void bus_remove_file(struct bus_type *, struct bus_attribute *); 383*4882a593Smuzhiyun 384*4882a593Smuzhiyun 385*4882a593Smuzhiyundevice drivers (include/linux/device.h) 386*4882a593Smuzhiyun--------------------------------------- 387*4882a593Smuzhiyun 388*4882a593SmuzhiyunStructure:: 389*4882a593Smuzhiyun 390*4882a593Smuzhiyun struct driver_attribute { 391*4882a593Smuzhiyun struct attribute attr; 392*4882a593Smuzhiyun ssize_t (*show)(struct device_driver *, char * buf); 393*4882a593Smuzhiyun ssize_t (*store)(struct device_driver *, const char * buf, 394*4882a593Smuzhiyun size_t count); 395*4882a593Smuzhiyun }; 396*4882a593Smuzhiyun 397*4882a593SmuzhiyunDeclaring:: 398*4882a593Smuzhiyun 399*4882a593Smuzhiyun DRIVER_ATTR_RO(_name) 400*4882a593Smuzhiyun DRIVER_ATTR_RW(_name) 401*4882a593Smuzhiyun 402*4882a593SmuzhiyunCreation/Removal:: 403*4882a593Smuzhiyun 404*4882a593Smuzhiyun int driver_create_file(struct device_driver *, const struct driver_attribute *); 405*4882a593Smuzhiyun void driver_remove_file(struct device_driver *, const struct driver_attribute *); 406*4882a593Smuzhiyun 407*4882a593Smuzhiyun 408*4882a593SmuzhiyunDocumentation 409*4882a593Smuzhiyun~~~~~~~~~~~~~ 410*4882a593Smuzhiyun 411*4882a593SmuzhiyunThe sysfs directory structure and the attributes in each directory define an 412*4882a593SmuzhiyunABI between the kernel and user space. As for any ABI, it is important that 413*4882a593Smuzhiyunthis ABI is stable and properly documented. All new sysfs attributes must be 414*4882a593Smuzhiyundocumented in Documentation/ABI. See also Documentation/ABI/README for more 415*4882a593Smuzhiyuninformation. 416