Lines Matching full:buffer
58 static int fill_read_buffer(struct file *file, struct configfs_buffer *buffer) in fill_read_buffer() argument
63 if (!buffer->page) in fill_read_buffer()
64 buffer->page = (char *) get_zeroed_page(GFP_KERNEL); in fill_read_buffer()
65 if (!buffer->page) in fill_read_buffer()
70 count = buffer->attr->show(buffer->item, buffer->page); in fill_read_buffer()
77 buffer->needs_read_fill = 0; in fill_read_buffer()
78 buffer->count = count; in fill_read_buffer()
85 * @buf: buffer to fill.
93 * We call fill_read_buffer() to allocate and fill the buffer from the
95 * the beginning of the file). That should fill the entire buffer with
97 * We then call flush_read_buffer() to copy the buffer to userspace
104 struct configfs_buffer *buffer = file->private_data; in configfs_read_file() local
107 mutex_lock(&buffer->mutex); in configfs_read_file()
108 if (buffer->needs_read_fill) { in configfs_read_file()
109 retval = fill_read_buffer(file, buffer); in configfs_read_file()
114 __func__, count, *ppos, buffer->page); in configfs_read_file()
115 retval = simple_read_from_buffer(buf, count, ppos, buffer->page, in configfs_read_file()
116 buffer->count); in configfs_read_file()
118 mutex_unlock(&buffer->mutex); in configfs_read_file()
125 * @buf: buffer to fill.
133 * We check whether we need to refill the buffer. If so we will
135 * will pass a NULL as a buffer pointer, which the attributes' method
136 * will use to return the size of the buffer required. If no error
137 * occurs we will allocate the buffer using vmalloc and call
138 * attr->read() again passing that buffer as an argument.
147 struct configfs_buffer *buffer = file->private_data; in configfs_read_bin_file() local
151 mutex_lock(&buffer->mutex); in configfs_read_bin_file()
154 if (buffer->write_in_progress) { in configfs_read_bin_file()
158 buffer->read_in_progress = true; in configfs_read_bin_file()
160 if (buffer->needs_read_fill) { in configfs_read_bin_file()
164 len = buffer->bin_attr->read(buffer->item, NULL, 0); in configfs_read_bin_file()
174 if (buffer->cb_max_size && len > buffer->cb_max_size) { in configfs_read_bin_file()
179 buffer->bin_buffer = vmalloc(len); in configfs_read_bin_file()
180 if (buffer->bin_buffer == NULL) { in configfs_read_bin_file()
184 buffer->bin_buffer_size = len; in configfs_read_bin_file()
186 /* perform second read to fill buffer */ in configfs_read_bin_file()
189 len = buffer->bin_attr->read(buffer->item, in configfs_read_bin_file()
190 buffer->bin_buffer, len); in configfs_read_bin_file()
196 vfree(buffer->bin_buffer); in configfs_read_bin_file()
197 buffer->bin_buffer_size = 0; in configfs_read_bin_file()
198 buffer->bin_buffer = NULL; in configfs_read_bin_file()
202 buffer->needs_read_fill = 0; in configfs_read_bin_file()
205 retval = simple_read_from_buffer(buf, count, ppos, buffer->bin_buffer, in configfs_read_bin_file()
206 buffer->bin_buffer_size); in configfs_read_bin_file()
208 mutex_unlock(&buffer->mutex); in configfs_read_bin_file()
214 * fill_write_buffer - copy buffer from userspace.
215 * @buffer: data buffer for file.
219 * Allocate @buffer->page if it hasn't been already, then
220 * copy the user-supplied buffer into it.
224 fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size_t count) in fill_write_buffer() argument
228 if (!buffer->page) in fill_write_buffer()
229 buffer->page = (char *)__get_free_pages(GFP_KERNEL, 0); in fill_write_buffer()
230 if (!buffer->page) in fill_write_buffer()
235 error = copy_from_user(buffer->page,buf,count); in fill_write_buffer()
236 buffer->needs_read_fill = 1; in fill_write_buffer()
239 buffer->page[count] = 0; in fill_write_buffer()
244 flush_write_buffer(struct file *file, struct configfs_buffer *buffer, size_t count) in flush_write_buffer() argument
251 res = buffer->attr->store(buffer->item, buffer->page, count); in flush_write_buffer()
268 * write, so we don't support them. We expect the entire buffer to come
271 * the value you're changing, then write entire buffer back.
277 struct configfs_buffer *buffer = file->private_data; in configfs_write_file() local
280 mutex_lock(&buffer->mutex); in configfs_write_file()
281 len = fill_write_buffer(buffer, buf, count); in configfs_write_file()
283 len = flush_write_buffer(file, buffer, len); in configfs_write_file()
286 mutex_unlock(&buffer->mutex); in configfs_write_file()
298 * We buffer the consecutive writes (binary attribute files do not
299 * support lseek) in a continuously growing buffer, but we don't
307 struct configfs_buffer *buffer = file->private_data; in configfs_write_bin_file() local
311 mutex_lock(&buffer->mutex); in configfs_write_bin_file()
314 if (buffer->read_in_progress) { in configfs_write_bin_file()
318 buffer->write_in_progress = true; in configfs_write_bin_file()
320 /* buffer grows? */ in configfs_write_bin_file()
321 if (*ppos + count > buffer->bin_buffer_size) { in configfs_write_bin_file()
323 if (buffer->cb_max_size && in configfs_write_bin_file()
324 *ppos + count > buffer->cb_max_size) { in configfs_write_bin_file()
336 if (buffer->bin_buffer) { in configfs_write_bin_file()
337 memcpy(tbuf, buffer->bin_buffer, in configfs_write_bin_file()
338 buffer->bin_buffer_size); in configfs_write_bin_file()
339 vfree(buffer->bin_buffer); in configfs_write_bin_file()
343 memset(tbuf + buffer->bin_buffer_size, 0, in configfs_write_bin_file()
344 *ppos + count - buffer->bin_buffer_size); in configfs_write_bin_file()
345 buffer->bin_buffer = tbuf; in configfs_write_bin_file()
346 buffer->bin_buffer_size = *ppos + count; in configfs_write_bin_file()
349 len = simple_write_to_buffer(buffer->bin_buffer, in configfs_write_bin_file()
350 buffer->bin_buffer_size, ppos, buf, count); in configfs_write_bin_file()
352 mutex_unlock(&buffer->mutex); in configfs_write_bin_file()
361 struct configfs_buffer *buffer; in __configfs_open_file() local
365 buffer = kzalloc(sizeof(struct configfs_buffer), GFP_KERNEL); in __configfs_open_file()
366 if (!buffer) in __configfs_open_file()
375 buffer->item = to_item(dentry->d_parent); in __configfs_open_file()
376 if (!buffer->item) in __configfs_open_file()
384 buffer->bin_attr = to_bin_attr(dentry); in __configfs_open_file()
385 buffer->cb_max_size = buffer->bin_attr->cb_max_size; in __configfs_open_file()
387 buffer->attr = attr; in __configfs_open_file()
390 buffer->owner = attr->ca_owner; in __configfs_open_file()
393 if (!try_module_get(buffer->owner)) in __configfs_open_file()
397 if (!buffer->item->ci_type) in __configfs_open_file()
400 buffer->ops = buffer->item->ci_type->ct_item_ops; in __configfs_open_file()
411 if ((type & CONFIGFS_ITEM_BIN_ATTR) && !buffer->bin_attr->write) in __configfs_open_file()
424 if ((type & CONFIGFS_ITEM_BIN_ATTR) && !buffer->bin_attr->read) in __configfs_open_file()
428 mutex_init(&buffer->mutex); in __configfs_open_file()
429 buffer->needs_read_fill = 1; in __configfs_open_file()
430 buffer->read_in_progress = false; in __configfs_open_file()
431 buffer->write_in_progress = false; in __configfs_open_file()
432 file->private_data = buffer; in __configfs_open_file()
437 module_put(buffer->owner); in __configfs_open_file()
439 config_item_put(buffer->item); in __configfs_open_file()
442 kfree(buffer); in __configfs_open_file()
449 struct configfs_buffer *buffer = filp->private_data; in configfs_release() local
451 module_put(buffer->owner); in configfs_release()
452 if (buffer->page) in configfs_release()
453 free_page((unsigned long)buffer->page); in configfs_release()
454 mutex_destroy(&buffer->mutex); in configfs_release()
455 kfree(buffer); in configfs_release()
471 struct configfs_buffer *buffer = file->private_data; in configfs_release_bin_file() local
473 buffer->read_in_progress = false; in configfs_release_bin_file()
475 if (buffer->write_in_progress) { in configfs_release_bin_file()
477 buffer->write_in_progress = false; in configfs_release_bin_file()
482 buffer->bin_attr->write(buffer->item, in configfs_release_bin_file()
483 buffer->bin_buffer, in configfs_release_bin_file()
484 buffer->bin_buffer_size); in configfs_release_bin_file()
488 vfree(buffer->bin_buffer); in configfs_release_bin_file()
489 buffer->bin_buffer = NULL; in configfs_release_bin_file()
490 buffer->bin_buffer_size = 0; in configfs_release_bin_file()
491 buffer->needs_read_fill = 1; in configfs_release_bin_file()