Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * file.c - operations for regular (text) files. |
| 3 | */ |
| 4 | |
| 5 | #include <linux/module.h> |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 6 | #include <linux/fsnotify.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/kobject.h> |
Christoph Hellwig | 5f45f1a | 2005-06-23 00:09:12 -0700 | [diff] [blame] | 8 | #include <linux/namei.h> |
NeilBrown | 4508a7a | 2006-03-20 17:53:53 +1100 | [diff] [blame] | 9 | #include <linux/poll.h> |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 10 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <asm/uaccess.h> |
| 12 | #include <asm/semaphore.h> |
| 13 | |
| 14 | #include "sysfs.h" |
| 15 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 16 | #define to_sattr(a) container_of(a,struct subsys_attribute, attr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Martin Waitz | 3d41088 | 2005-06-23 22:05:21 -0700 | [diff] [blame] | 18 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * Subsystem file operations. |
| 20 | * These operations allow subsystems to have files that can be |
| 21 | * read/written. |
| 22 | */ |
| 23 | static ssize_t |
| 24 | subsys_attr_show(struct kobject * kobj, struct attribute * attr, char * page) |
| 25 | { |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 26 | struct kset *kset = to_kset(kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | struct subsys_attribute * sattr = to_sattr(attr); |
Dmitry Torokhov | c76d0ab | 2005-04-29 01:22:00 -0500 | [diff] [blame] | 28 | ssize_t ret = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | if (sattr->show) |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 31 | ret = sattr->show(kset, page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | return ret; |
| 33 | } |
| 34 | |
| 35 | static ssize_t |
| 36 | subsys_attr_store(struct kobject * kobj, struct attribute * attr, |
| 37 | const char * page, size_t count) |
| 38 | { |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 39 | struct kset *kset = to_kset(kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | struct subsys_attribute * sattr = to_sattr(attr); |
Dmitry Torokhov | c76d0ab | 2005-04-29 01:22:00 -0500 | [diff] [blame] | 41 | ssize_t ret = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | if (sattr->store) |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 44 | ret = sattr->store(kset, page, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | return ret; |
| 46 | } |
| 47 | |
| 48 | static struct sysfs_ops subsys_sysfs_ops = { |
| 49 | .show = subsys_attr_show, |
| 50 | .store = subsys_attr_store, |
| 51 | }; |
| 52 | |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 53 | /** |
| 54 | * add_to_collection - add buffer to a collection |
| 55 | * @buffer: buffer to be added |
Randy Dunlap | f95d882 | 2007-02-10 14:41:56 -0800 | [diff] [blame] | 56 | * @node: inode of set to add to |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 57 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 59 | static inline void |
| 60 | add_to_collection(struct sysfs_buffer *buffer, struct inode *node) |
| 61 | { |
| 62 | struct sysfs_buffer_collection *set = node->i_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 64 | mutex_lock(&node->i_mutex); |
| 65 | list_add(&buffer->associates, &set->associates); |
| 66 | mutex_unlock(&node->i_mutex); |
| 67 | } |
| 68 | |
| 69 | static inline void |
| 70 | remove_from_collection(struct sysfs_buffer *buffer, struct inode *node) |
| 71 | { |
| 72 | mutex_lock(&node->i_mutex); |
| 73 | list_del(&buffer->associates); |
| 74 | mutex_unlock(&node->i_mutex); |
| 75 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * fill_read_buffer - allocate and fill buffer from object. |
| 79 | * @dentry: dentry pointer. |
| 80 | * @buffer: data buffer for file. |
| 81 | * |
| 82 | * Allocate @buffer->page, if it hasn't been already, then call the |
| 83 | * kobject's show() method to fill the buffer with this attribute's |
| 84 | * data. |
Oliver Neukum | 82244b1 | 2007-01-02 08:48:08 +0100 | [diff] [blame] | 85 | * This is called only once, on the file's first read unless an error |
| 86 | * is returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | */ |
| 88 | static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer) |
| 89 | { |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 90 | struct sysfs_dirent *attr_sd = dentry->d_fsdata; |
| 91 | struct kobject *kobj = attr_sd->s_parent->s_elem.dir.kobj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | struct sysfs_ops * ops = buffer->ops; |
| 93 | int ret = 0; |
| 94 | ssize_t count; |
| 95 | |
| 96 | if (!buffer->page) |
| 97 | buffer->page = (char *) get_zeroed_page(GFP_KERNEL); |
| 98 | if (!buffer->page) |
| 99 | return -ENOMEM; |
| 100 | |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 101 | /* need attr_sd for attr and ops, its parent for kobj */ |
| 102 | if (!sysfs_get_active_two(attr_sd)) |
| 103 | return -ENODEV; |
| 104 | |
| 105 | buffer->event = atomic_read(&attr_sd->s_event); |
| 106 | count = ops->show(kobj, attr_sd->s_elem.attr.attr, buffer->page); |
| 107 | |
| 108 | sysfs_put_active_two(attr_sd); |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | BUG_ON(count > (ssize_t)PAGE_SIZE); |
Oliver Neukum | 82244b1 | 2007-01-02 08:48:08 +0100 | [diff] [blame] | 111 | if (count >= 0) { |
| 112 | buffer->needs_read_fill = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | buffer->count = count; |
Oliver Neukum | 82244b1 | 2007-01-02 08:48:08 +0100 | [diff] [blame] | 114 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | ret = count; |
Oliver Neukum | 82244b1 | 2007-01-02 08:48:08 +0100 | [diff] [blame] | 116 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | return ret; |
| 118 | } |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | /** |
| 121 | * sysfs_read_file - read an attribute. |
| 122 | * @file: file pointer. |
| 123 | * @buf: buffer to fill. |
| 124 | * @count: number of bytes to read. |
| 125 | * @ppos: starting offset in file. |
| 126 | * |
| 127 | * Userspace wants to read an attribute file. The attribute descriptor |
| 128 | * is in the file's ->d_fsdata. The target object is in the directory's |
| 129 | * ->d_fsdata. |
| 130 | * |
| 131 | * We call fill_read_buffer() to allocate and fill the buffer from the |
| 132 | * object's show() method exactly once (if the read is happening from |
| 133 | * the beginning of the file). That should fill the entire buffer with |
| 134 | * all the data the object has to offer for that attribute. |
| 135 | * We then call flush_read_buffer() to copy the buffer to userspace |
| 136 | * in the increments specified. |
| 137 | */ |
| 138 | |
| 139 | static ssize_t |
| 140 | sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos) |
| 141 | { |
| 142 | struct sysfs_buffer * buffer = file->private_data; |
| 143 | ssize_t retval = 0; |
| 144 | |
| 145 | down(&buffer->sem); |
| 146 | if (buffer->needs_read_fill) { |
Alan Stern | e7b0d26 | 2007-03-15 15:51:28 -0400 | [diff] [blame] | 147 | if (buffer->orphaned) |
| 148 | retval = -ENODEV; |
| 149 | else |
| 150 | retval = fill_read_buffer(file->f_path.dentry,buffer); |
| 151 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | goto out; |
| 153 | } |
Zach Brown | 5c1fdf4 | 2006-10-03 01:16:06 -0700 | [diff] [blame] | 154 | pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n", |
| 155 | __FUNCTION__, count, *ppos, buffer->page); |
Akinobu Mita | 92f4c70 | 2007-05-09 02:33:32 -0700 | [diff] [blame] | 156 | retval = simple_read_from_buffer(buf, count, ppos, buffer->page, |
| 157 | buffer->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | out: |
| 159 | up(&buffer->sem); |
| 160 | return retval; |
| 161 | } |
| 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | /** |
| 164 | * fill_write_buffer - copy buffer from userspace. |
| 165 | * @buffer: data buffer for file. |
Martin Waitz | 67be2dd | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 166 | * @buf: data from user. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | * @count: number of bytes in @userbuf. |
| 168 | * |
| 169 | * Allocate @buffer->page if it hasn't been already, then |
| 170 | * copy the user-supplied buffer into it. |
| 171 | */ |
| 172 | |
| 173 | static int |
| 174 | fill_write_buffer(struct sysfs_buffer * buffer, const char __user * buf, size_t count) |
| 175 | { |
| 176 | int error; |
| 177 | |
| 178 | if (!buffer->page) |
| 179 | buffer->page = (char *)get_zeroed_page(GFP_KERNEL); |
| 180 | if (!buffer->page) |
| 181 | return -ENOMEM; |
| 182 | |
| 183 | if (count >= PAGE_SIZE) |
Greg Kroah-Hartman | 6e0dd74 | 2006-03-31 15:37:06 -0800 | [diff] [blame] | 184 | count = PAGE_SIZE - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | error = copy_from_user(buffer->page,buf,count); |
| 186 | buffer->needs_read_fill = 1; |
Thomas Maier | 035ed7a | 2006-10-22 19:17:47 +0200 | [diff] [blame] | 187 | /* if buf is assumed to contain a string, terminate it by \0, |
| 188 | so e.g. sscanf() can scan the string easily */ |
| 189 | buffer->page[count] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | return error ? -EFAULT : count; |
| 191 | } |
| 192 | |
| 193 | |
| 194 | /** |
| 195 | * flush_write_buffer - push buffer to kobject. |
Martin Waitz | 3d41088 | 2005-06-23 22:05:21 -0700 | [diff] [blame] | 196 | * @dentry: dentry to the attribute |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | * @buffer: data buffer for file. |
Martin Waitz | 3d41088 | 2005-06-23 22:05:21 -0700 | [diff] [blame] | 198 | * @count: number of bytes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | * |
| 200 | * Get the correct pointers for the kobject and the attribute we're |
| 201 | * dealing with, then call the store() method for the attribute, |
| 202 | * passing the buffer that we acquired in fill_write_buffer(). |
| 203 | */ |
| 204 | |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 205 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | flush_write_buffer(struct dentry * dentry, struct sysfs_buffer * buffer, size_t count) |
| 207 | { |
Tejun Heo | 3e51903 | 2007-06-14 03:45:15 +0900 | [diff] [blame] | 208 | struct sysfs_dirent *attr_sd = dentry->d_fsdata; |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 209 | struct kobject *kobj = attr_sd->s_parent->s_elem.dir.kobj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | struct sysfs_ops * ops = buffer->ops; |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 211 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 213 | /* need attr_sd for attr and ops, its parent for kobj */ |
| 214 | if (!sysfs_get_active_two(attr_sd)) |
| 215 | return -ENODEV; |
| 216 | |
| 217 | rc = ops->store(kobj, attr_sd->s_elem.attr.attr, buffer->page, count); |
| 218 | |
| 219 | sysfs_put_active_two(attr_sd); |
| 220 | |
| 221 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | |
| 225 | /** |
| 226 | * sysfs_write_file - write an attribute. |
| 227 | * @file: file pointer |
| 228 | * @buf: data to write |
| 229 | * @count: number of bytes |
| 230 | * @ppos: starting offset |
| 231 | * |
| 232 | * Similar to sysfs_read_file(), though working in the opposite direction. |
| 233 | * We allocate and fill the data from the user in fill_write_buffer(), |
| 234 | * then push it to the kobject in flush_write_buffer(). |
| 235 | * There is no easy way for us to know if userspace is only doing a partial |
| 236 | * write, so we don't support them. We expect the entire buffer to come |
| 237 | * on the first write. |
| 238 | * Hint: if you're writing a value, first read the file, modify only the |
| 239 | * the value you're changing, then write entire buffer back. |
| 240 | */ |
| 241 | |
| 242 | static ssize_t |
| 243 | sysfs_write_file(struct file *file, const char __user *buf, size_t count, loff_t *ppos) |
| 244 | { |
| 245 | struct sysfs_buffer * buffer = file->private_data; |
| 246 | ssize_t len; |
| 247 | |
| 248 | down(&buffer->sem); |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 249 | if (buffer->orphaned) { |
| 250 | len = -ENODEV; |
| 251 | goto out; |
| 252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | len = fill_write_buffer(buffer, buf, count); |
| 254 | if (len > 0) |
Josef "Jeff" Sipek | f427f5d | 2006-12-08 02:36:36 -0800 | [diff] [blame] | 255 | len = flush_write_buffer(file->f_path.dentry, buffer, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | if (len > 0) |
| 257 | *ppos += len; |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 258 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | up(&buffer->sem); |
| 260 | return len; |
| 261 | } |
| 262 | |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 263 | static int sysfs_open_file(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
Tejun Heo | 3e51903 | 2007-06-14 03:45:15 +0900 | [diff] [blame] | 265 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; |
| 266 | struct attribute *attr = attr_sd->s_elem.attr.attr; |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 267 | struct kobject *kobj = attr_sd->s_parent->s_elem.dir.kobj; |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 268 | struct sysfs_buffer_collection *set; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | struct sysfs_buffer * buffer; |
| 270 | struct sysfs_ops * ops = NULL; |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 271 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 273 | /* need attr_sd for attr and ops, its parent for kobj */ |
| 274 | if (!sysfs_get_active_two(attr_sd)) |
| 275 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 277 | /* Grab the module reference for this attribute */ |
| 278 | error = -ENODEV; |
| 279 | if (!try_module_get(attr->owner)) |
| 280 | goto err_sput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | /* if the kobject has no ktype, then we assume that it is a subsystem |
| 283 | * itself, and use ops for it. |
| 284 | */ |
| 285 | if (kobj->kset && kobj->kset->ktype) |
| 286 | ops = kobj->kset->ktype->sysfs_ops; |
| 287 | else if (kobj->ktype) |
| 288 | ops = kobj->ktype->sysfs_ops; |
| 289 | else |
| 290 | ops = &subsys_sysfs_ops; |
| 291 | |
| 292 | /* No sysfs operations, either from having no subsystem, |
| 293 | * or the subsystem have no operations. |
| 294 | */ |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 295 | error = -EACCES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | if (!ops) |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 297 | goto err_mput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 299 | /* make sure we have a collection to add our buffers to */ |
| 300 | mutex_lock(&inode->i_mutex); |
| 301 | if (!(set = inode->i_private)) { |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 302 | error = -ENOMEM; |
| 303 | if (!(set = inode->i_private = kmalloc(sizeof(struct sysfs_buffer_collection), GFP_KERNEL))) |
| 304 | goto err_mput; |
| 305 | else |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 306 | INIT_LIST_HEAD(&set->associates); |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 307 | } |
| 308 | mutex_unlock(&inode->i_mutex); |
| 309 | |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 310 | error = -EACCES; |
| 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | /* File needs write support. |
| 313 | * The inode's perms must say it's ok, |
| 314 | * and we must have a store method. |
| 315 | */ |
| 316 | if (file->f_mode & FMODE_WRITE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | if (!(inode->i_mode & S_IWUGO) || !ops->store) |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 318 | goto err_mput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | /* File needs read support. |
| 322 | * The inode's perms must say it's ok, and we there |
| 323 | * must be a show method for it. |
| 324 | */ |
| 325 | if (file->f_mode & FMODE_READ) { |
| 326 | if (!(inode->i_mode & S_IRUGO) || !ops->show) |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 327 | goto err_mput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /* No error? Great, allocate a buffer for the file, and store it |
| 331 | * it in file->private_data for easy access. |
| 332 | */ |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 333 | error = -ENOMEM; |
Eric Sesterhenn | 58d4928 | 2006-02-22 11:18:15 +0100 | [diff] [blame] | 334 | buffer = kzalloc(sizeof(struct sysfs_buffer), GFP_KERNEL); |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 335 | if (!buffer) |
| 336 | goto err_mput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 338 | INIT_LIST_HEAD(&buffer->associates); |
| 339 | init_MUTEX(&buffer->sem); |
| 340 | buffer->needs_read_fill = 1; |
| 341 | buffer->ops = ops; |
| 342 | add_to_collection(buffer, inode); |
| 343 | file->private_data = buffer; |
| 344 | |
| 345 | /* open succeeded, put active references and pin attr_sd */ |
| 346 | sysfs_put_active_two(attr_sd); |
| 347 | sysfs_get(attr_sd); |
| 348 | return 0; |
| 349 | |
| 350 | err_mput: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | module_put(attr->owner); |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 352 | err_sput: |
| 353 | sysfs_put_active_two(attr_sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | return error; |
| 355 | } |
| 356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | static int sysfs_release(struct inode * inode, struct file * filp) |
| 358 | { |
Tejun Heo | 3e51903 | 2007-06-14 03:45:15 +0900 | [diff] [blame] | 359 | struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata; |
| 360 | struct attribute *attr = attr_sd->s_elem.attr.attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | struct sysfs_buffer * buffer = filp->private_data; |
| 362 | |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 363 | if (buffer) |
| 364 | remove_from_collection(buffer, inode); |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 365 | sysfs_put(attr_sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | /* After this point, attr should not be accessed. */ |
Tejun Heo | 3e51903 | 2007-06-14 03:45:15 +0900 | [diff] [blame] | 367 | module_put(attr->owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | if (buffer) { |
| 370 | if (buffer->page) |
| 371 | free_page((unsigned long)buffer->page); |
| 372 | kfree(buffer); |
| 373 | } |
| 374 | return 0; |
| 375 | } |
| 376 | |
NeilBrown | 4508a7a | 2006-03-20 17:53:53 +1100 | [diff] [blame] | 377 | /* Sysfs attribute files are pollable. The idea is that you read |
| 378 | * the content and then you use 'poll' or 'select' to wait for |
| 379 | * the content to change. When the content changes (assuming the |
| 380 | * manager for the kobject supports notification), poll will |
| 381 | * return POLLERR|POLLPRI, and select will return the fd whether |
| 382 | * it is waiting for read, write, or exceptions. |
| 383 | * Once poll/select indicates that the value has changed, you |
| 384 | * need to close and re-open the file, as simply seeking and reading |
| 385 | * again will not get new data, or reset the state of 'poll'. |
| 386 | * Reminder: this only works for attributes which actively support |
| 387 | * it, and it is not possible to test an attribute from userspace |
| 388 | * to see if it supports poll (Nether 'poll' or 'select' return |
| 389 | * an appropriate error code). When in doubt, set a suitable timeout value. |
| 390 | */ |
| 391 | static unsigned int sysfs_poll(struct file *filp, poll_table *wait) |
| 392 | { |
| 393 | struct sysfs_buffer * buffer = filp->private_data; |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 394 | struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata; |
| 395 | struct kobject *kobj = attr_sd->s_parent->s_elem.dir.kobj; |
| 396 | |
| 397 | /* need parent for the kobj, grab both */ |
| 398 | if (!sysfs_get_active_two(attr_sd)) |
| 399 | goto trigger; |
NeilBrown | 4508a7a | 2006-03-20 17:53:53 +1100 | [diff] [blame] | 400 | |
| 401 | poll_wait(filp, &kobj->poll, wait); |
| 402 | |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 403 | sysfs_put_active_two(attr_sd); |
NeilBrown | 4508a7a | 2006-03-20 17:53:53 +1100 | [diff] [blame] | 404 | |
Tejun Heo | 0ab6608 | 2007-06-14 03:45:16 +0900 | [diff] [blame^] | 405 | if (buffer->event != atomic_read(&attr_sd->s_event)) |
| 406 | goto trigger; |
| 407 | |
| 408 | return 0; |
| 409 | |
| 410 | trigger: |
| 411 | buffer->needs_read_fill = 1; |
| 412 | return POLLERR|POLLPRI; |
NeilBrown | 4508a7a | 2006-03-20 17:53:53 +1100 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | |
| 416 | static struct dentry *step_down(struct dentry *dir, const char * name) |
| 417 | { |
| 418 | struct dentry * de; |
| 419 | |
| 420 | if (dir == NULL || dir->d_inode == NULL) |
| 421 | return NULL; |
| 422 | |
| 423 | mutex_lock(&dir->d_inode->i_mutex); |
| 424 | de = lookup_one_len(name, dir, strlen(name)); |
| 425 | mutex_unlock(&dir->d_inode->i_mutex); |
| 426 | dput(dir); |
| 427 | if (IS_ERR(de)) |
| 428 | return NULL; |
| 429 | if (de->d_inode == NULL) { |
| 430 | dput(de); |
| 431 | return NULL; |
| 432 | } |
| 433 | return de; |
| 434 | } |
| 435 | |
| 436 | void sysfs_notify(struct kobject * k, char *dir, char *attr) |
| 437 | { |
| 438 | struct dentry *de = k->dentry; |
| 439 | if (de) |
| 440 | dget(de); |
| 441 | if (de && dir) |
| 442 | de = step_down(de, dir); |
| 443 | if (de && attr) |
| 444 | de = step_down(de, attr); |
| 445 | if (de) { |
| 446 | struct sysfs_dirent * sd = de->d_fsdata; |
| 447 | if (sd) |
| 448 | atomic_inc(&sd->s_event); |
| 449 | wake_up_interruptible(&k->poll); |
| 450 | dput(de); |
| 451 | } |
| 452 | } |
| 453 | EXPORT_SYMBOL_GPL(sysfs_notify); |
| 454 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 455 | const struct file_operations sysfs_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | .read = sysfs_read_file, |
| 457 | .write = sysfs_write_file, |
| 458 | .llseek = generic_file_llseek, |
| 459 | .open = sysfs_open_file, |
| 460 | .release = sysfs_release, |
NeilBrown | 4508a7a | 2006-03-20 17:53:53 +1100 | [diff] [blame] | 461 | .poll = sysfs_poll, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | }; |
| 463 | |
| 464 | |
| 465 | int sysfs_add_file(struct dentry * dir, const struct attribute * attr, int type) |
| 466 | { |
| 467 | struct sysfs_dirent * parent_sd = dir->d_fsdata; |
| 468 | umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; |
Tejun Heo | a26cd72 | 2007-06-14 03:45:14 +0900 | [diff] [blame] | 469 | struct sysfs_dirent *sd; |
| 470 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 472 | mutex_lock(&dir->d_inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
Tejun Heo | a26cd72 | 2007-06-14 03:45:14 +0900 | [diff] [blame] | 474 | if (sysfs_dirent_exist(parent_sd, attr->name)) { |
| 475 | error = -EEXIST; |
| 476 | goto out_unlock; |
| 477 | } |
| 478 | |
Tejun Heo | 3e51903 | 2007-06-14 03:45:15 +0900 | [diff] [blame] | 479 | sd = sysfs_new_dirent(attr->name, mode, type); |
Tejun Heo | a26cd72 | 2007-06-14 03:45:14 +0900 | [diff] [blame] | 480 | if (!sd) { |
| 481 | error = -ENOMEM; |
| 482 | goto out_unlock; |
| 483 | } |
Tejun Heo | 3e51903 | 2007-06-14 03:45:15 +0900 | [diff] [blame] | 484 | sd->s_elem.attr.attr = (void *)attr; |
Tejun Heo | a26cd72 | 2007-06-14 03:45:14 +0900 | [diff] [blame] | 485 | sysfs_attach_dirent(sd, parent_sd, NULL); |
| 486 | |
| 487 | out_unlock: |
| 488 | mutex_unlock(&dir->d_inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | return error; |
| 490 | } |
| 491 | |
| 492 | |
| 493 | /** |
| 494 | * sysfs_create_file - create an attribute file for an object. |
| 495 | * @kobj: object we're creating for. |
| 496 | * @attr: atrribute descriptor. |
| 497 | */ |
| 498 | |
| 499 | int sysfs_create_file(struct kobject * kobj, const struct attribute * attr) |
| 500 | { |
| 501 | BUG_ON(!kobj || !kobj->dentry || !attr); |
| 502 | |
| 503 | return sysfs_add_file(kobj->dentry, attr, SYSFS_KOBJ_ATTR); |
| 504 | |
| 505 | } |
| 506 | |
| 507 | |
| 508 | /** |
Alan Stern | dfa87c8 | 2007-02-20 15:02:44 -0500 | [diff] [blame] | 509 | * sysfs_add_file_to_group - add an attribute file to a pre-existing group. |
| 510 | * @kobj: object we're acting for. |
| 511 | * @attr: attribute descriptor. |
| 512 | * @group: group name. |
| 513 | */ |
| 514 | int sysfs_add_file_to_group(struct kobject *kobj, |
| 515 | const struct attribute *attr, const char *group) |
| 516 | { |
| 517 | struct dentry *dir; |
| 518 | int error; |
| 519 | |
| 520 | dir = lookup_one_len(group, kobj->dentry, strlen(group)); |
| 521 | if (IS_ERR(dir)) |
| 522 | error = PTR_ERR(dir); |
| 523 | else { |
| 524 | error = sysfs_add_file(dir, attr, SYSFS_KOBJ_ATTR); |
| 525 | dput(dir); |
| 526 | } |
| 527 | return error; |
| 528 | } |
| 529 | EXPORT_SYMBOL_GPL(sysfs_add_file_to_group); |
| 530 | |
| 531 | |
| 532 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | * sysfs_update_file - update the modified timestamp on an object attribute. |
| 534 | * @kobj: object we're acting for. |
| 535 | * @attr: attribute descriptor. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | */ |
| 537 | int sysfs_update_file(struct kobject * kobj, const struct attribute * attr) |
| 538 | { |
| 539 | struct dentry * dir = kobj->dentry; |
| 540 | struct dentry * victim; |
| 541 | int res = -ENOENT; |
| 542 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 543 | mutex_lock(&dir->d_inode->i_mutex); |
Christoph Hellwig | 5f45f1a | 2005-06-23 00:09:12 -0700 | [diff] [blame] | 544 | victim = lookup_one_len(attr->name, dir, strlen(attr->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | if (!IS_ERR(victim)) { |
| 546 | /* make sure dentry is really there */ |
| 547 | if (victim->d_inode && |
| 548 | (victim->d_parent->d_inode == dir->d_inode)) { |
| 549 | victim->d_inode->i_mtime = CURRENT_TIME; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 550 | fsnotify_modify(victim); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | res = 0; |
| 552 | } else |
| 553 | d_drop(victim); |
| 554 | |
| 555 | /** |
Hidetoshi Seto | 97a5018 | 2006-09-20 16:49:02 +0900 | [diff] [blame] | 556 | * Drop the reference acquired from lookup_one_len() above. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | */ |
| 558 | dput(victim); |
| 559 | } |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 560 | mutex_unlock(&dir->d_inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
| 562 | return res; |
| 563 | } |
| 564 | |
| 565 | |
| 566 | /** |
Kay Sievers | 31e5abe | 2005-04-18 21:57:32 -0700 | [diff] [blame] | 567 | * sysfs_chmod_file - update the modified mode value on an object attribute. |
| 568 | * @kobj: object we're acting for. |
| 569 | * @attr: attribute descriptor. |
| 570 | * @mode: file permissions. |
| 571 | * |
| 572 | */ |
| 573 | int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode) |
| 574 | { |
| 575 | struct dentry *dir = kobj->dentry; |
| 576 | struct dentry *victim; |
Maneesh Soni | bc062b1 | 2005-07-29 12:13:35 -0700 | [diff] [blame] | 577 | struct inode * inode; |
| 578 | struct iattr newattrs; |
Kay Sievers | 31e5abe | 2005-04-18 21:57:32 -0700 | [diff] [blame] | 579 | int res = -ENOENT; |
| 580 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 581 | mutex_lock(&dir->d_inode->i_mutex); |
Christoph Hellwig | 5f45f1a | 2005-06-23 00:09:12 -0700 | [diff] [blame] | 582 | victim = lookup_one_len(attr->name, dir, strlen(attr->name)); |
Kay Sievers | 31e5abe | 2005-04-18 21:57:32 -0700 | [diff] [blame] | 583 | if (!IS_ERR(victim)) { |
| 584 | if (victim->d_inode && |
| 585 | (victim->d_parent->d_inode == dir->d_inode)) { |
Maneesh Soni | bc062b1 | 2005-07-29 12:13:35 -0700 | [diff] [blame] | 586 | inode = victim->d_inode; |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 587 | mutex_lock(&inode->i_mutex); |
Maneesh Soni | bc062b1 | 2005-07-29 12:13:35 -0700 | [diff] [blame] | 588 | newattrs.ia_mode = (mode & S_IALLUGO) | |
| 589 | (inode->i_mode & ~S_IALLUGO); |
| 590 | newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; |
| 591 | res = notify_change(victim, &newattrs); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 592 | mutex_unlock(&inode->i_mutex); |
Kay Sievers | 31e5abe | 2005-04-18 21:57:32 -0700 | [diff] [blame] | 593 | } |
Maneesh Soni | bc062b1 | 2005-07-29 12:13:35 -0700 | [diff] [blame] | 594 | dput(victim); |
Kay Sievers | 31e5abe | 2005-04-18 21:57:32 -0700 | [diff] [blame] | 595 | } |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 596 | mutex_unlock(&dir->d_inode->i_mutex); |
Kay Sievers | 31e5abe | 2005-04-18 21:57:32 -0700 | [diff] [blame] | 597 | |
| 598 | return res; |
| 599 | } |
| 600 | EXPORT_SYMBOL_GPL(sysfs_chmod_file); |
| 601 | |
| 602 | |
| 603 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | * sysfs_remove_file - remove an object attribute. |
| 605 | * @kobj: object we're acting for. |
| 606 | * @attr: attribute descriptor. |
| 607 | * |
| 608 | * Hash the attribute name and kill the victim. |
| 609 | */ |
| 610 | |
| 611 | void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr) |
| 612 | { |
Oliver Neukum | 94bebf4 | 2006-12-20 10:52:44 +0100 | [diff] [blame] | 613 | sysfs_hash_and_remove(kobj->dentry, attr->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | |
Alan Stern | dfa87c8 | 2007-02-20 15:02:44 -0500 | [diff] [blame] | 617 | /** |
| 618 | * sysfs_remove_file_from_group - remove an attribute file from a group. |
| 619 | * @kobj: object we're acting for. |
| 620 | * @attr: attribute descriptor. |
| 621 | * @group: group name. |
| 622 | */ |
| 623 | void sysfs_remove_file_from_group(struct kobject *kobj, |
| 624 | const struct attribute *attr, const char *group) |
| 625 | { |
| 626 | struct dentry *dir; |
| 627 | |
| 628 | dir = lookup_one_len(group, kobj->dentry, strlen(group)); |
| 629 | if (!IS_ERR(dir)) { |
| 630 | sysfs_hash_and_remove(dir, attr->name); |
| 631 | dput(dir); |
| 632 | } |
| 633 | } |
| 634 | EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group); |
| 635 | |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 636 | struct sysfs_schedule_callback_struct { |
| 637 | struct kobject *kobj; |
| 638 | void (*func)(void *); |
| 639 | void *data; |
Alan Stern | 523ded7 | 2007-04-26 00:12:04 -0700 | [diff] [blame] | 640 | struct module *owner; |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 641 | struct work_struct work; |
| 642 | }; |
| 643 | |
| 644 | static void sysfs_schedule_callback_work(struct work_struct *work) |
| 645 | { |
| 646 | struct sysfs_schedule_callback_struct *ss = container_of(work, |
| 647 | struct sysfs_schedule_callback_struct, work); |
| 648 | |
| 649 | (ss->func)(ss->data); |
| 650 | kobject_put(ss->kobj); |
Alan Stern | 523ded7 | 2007-04-26 00:12:04 -0700 | [diff] [blame] | 651 | module_put(ss->owner); |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 652 | kfree(ss); |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * sysfs_schedule_callback - helper to schedule a callback for a kobject |
| 657 | * @kobj: object we're acting for. |
| 658 | * @func: callback function to invoke later. |
| 659 | * @data: argument to pass to @func. |
Alan Stern | 523ded7 | 2007-04-26 00:12:04 -0700 | [diff] [blame] | 660 | * @owner: module owning the callback code |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 661 | * |
| 662 | * sysfs attribute methods must not unregister themselves or their parent |
| 663 | * kobject (which would amount to the same thing). Attempts to do so will |
| 664 | * deadlock, since unregistration is mutually exclusive with driver |
| 665 | * callbacks. |
| 666 | * |
| 667 | * Instead methods can call this routine, which will attempt to allocate |
| 668 | * and schedule a workqueue request to call back @func with @data as its |
| 669 | * argument in the workqueue's process context. @kobj will be pinned |
| 670 | * until @func returns. |
| 671 | * |
| 672 | * Returns 0 if the request was submitted, -ENOMEM if storage could not |
Alan Stern | 523ded7 | 2007-04-26 00:12:04 -0700 | [diff] [blame] | 673 | * be allocated, -ENODEV if a reference to @owner isn't available. |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 674 | */ |
| 675 | int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *), |
Alan Stern | 523ded7 | 2007-04-26 00:12:04 -0700 | [diff] [blame] | 676 | void *data, struct module *owner) |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 677 | { |
| 678 | struct sysfs_schedule_callback_struct *ss; |
| 679 | |
Alan Stern | 523ded7 | 2007-04-26 00:12:04 -0700 | [diff] [blame] | 680 | if (!try_module_get(owner)) |
| 681 | return -ENODEV; |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 682 | ss = kmalloc(sizeof(*ss), GFP_KERNEL); |
Alan Stern | 523ded7 | 2007-04-26 00:12:04 -0700 | [diff] [blame] | 683 | if (!ss) { |
| 684 | module_put(owner); |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 685 | return -ENOMEM; |
Alan Stern | 523ded7 | 2007-04-26 00:12:04 -0700 | [diff] [blame] | 686 | } |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 687 | kobject_get(kobj); |
| 688 | ss->kobj = kobj; |
| 689 | ss->func = func; |
| 690 | ss->data = data; |
Alan Stern | 523ded7 | 2007-04-26 00:12:04 -0700 | [diff] [blame] | 691 | ss->owner = owner; |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 692 | INIT_WORK(&ss->work, sysfs_schedule_callback_work); |
| 693 | schedule_work(&ss->work); |
| 694 | return 0; |
| 695 | } |
| 696 | EXPORT_SYMBOL_GPL(sysfs_schedule_callback); |
| 697 | |
Alan Stern | dfa87c8 | 2007-02-20 15:02:44 -0500 | [diff] [blame] | 698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | EXPORT_SYMBOL_GPL(sysfs_create_file); |
| 700 | EXPORT_SYMBOL_GPL(sysfs_remove_file); |
| 701 | EXPORT_SYMBOL_GPL(sysfs_update_file); |