Fssysfsfilec

buffer = kzalloc(sizeof(struct sysfs_buffer), GFP_KERNEL);

mutex_init(&buffer->mutex); buffer->needs_read_fill = 1; buffer->ops = ops; file->private_data = buffer;

/* make sure we have open dirent struct */ error = sysfs_get_open_dirent(attr_sd, buffer);

/* open succeeded, put active references */

sysfs_put_active_two(attr_sd); return 0;

Finally, sysfs_get_open_dirent connects the freshly allocated buffer with the sysfs data structures via sysfs_open_dirent as shown in Figure 10-12. Note that since no further access to the kobjects associated with the sysfs entry is required anymore, the active references can (and need!) be dropped using sysfs_put_active_two.

Continue reading here: Reading and Writing File Contents

Was this article helpful?

0 0