17 #include <linux/errno.h>
19 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
26 #include <asm/uaccess.h>
43 const struct vm_operations_struct *
vm_ops;
62 rc = attr->
read(file, kobj, attr, buffer, off, count);
70 read(
struct file *file,
char __user *userbuf,
size_t bytes, loff_t *off)
73 int size = file->
f_path.dentry->d_inode->i_size;
84 if (offs + count > size)
94 count = fill_read(file, bb->
buffer, offs, count);
109 pr_debug(
"offs = %lld, *off = %lld, count = %d\n", offs, *off, count);
119 flush_write(
struct file *file,
char *buffer, loff_t
offset,
size_t count)
132 rc = attr->
write(file, kobj, attr, buffer, offset, count);
139 static ssize_t write(
struct file *file,
const char __user *userbuf,
140 size_t bytes, loff_t *off)
143 int size = file->
f_path.dentry->d_inode->i_size;
154 if (offs + count > size)
160 return PTR_ERR(temp);
166 count = flush_write(file, bb->
buffer, offs, count);
178 struct file *file = vma->
vm_file;
194 static int bin_fault(
struct vm_area_struct *vma,
struct vm_fault *vmf)
196 struct file *file = vma->
vm_file;
202 return VM_FAULT_SIGBUS;
205 return VM_FAULT_SIGBUS;
207 ret = VM_FAULT_SIGBUS;
209 ret = bb->
vm_ops->fault(vma, vmf);
215 static int bin_page_mkwrite(
struct vm_area_struct *vma,
struct vm_fault *vmf)
217 struct file *file = vma->
vm_file;
223 return VM_FAULT_SIGBUS;
226 return VM_FAULT_SIGBUS;
229 if (bb->
vm_ops->page_mkwrite)
230 ret = bb->
vm_ops->page_mkwrite(vma, vmf);
241 struct file *file = vma->
vm_file;
254 ret = bb->
vm_ops->access(vma, addr, buf, len, write);
263 struct file *file = vma->
vm_file;
275 if (bb->
vm_ops->set_policy)
276 ret = bb->
vm_ops->set_policy(vma,
new);
285 struct file *file = vma->
vm_file;
291 return vma->vm_policy;
294 return vma->vm_policy;
296 pol = vma->vm_policy;
297 if (bb->
vm_ops->get_policy)
298 pol = bb->
vm_ops->get_policy(vma, addr);
307 struct file *file = vma->
vm_file;
320 ret = bb->
vm_ops->migrate(vma, from, to, flags);
327 static const struct vm_operations_struct bin_vm_ops = {
328 .open = bin_vma_open,
330 .page_mkwrite = bin_page_mkwrite,
331 .access = bin_access,
333 .set_policy = bin_set_policy,
334 .get_policy = bin_get_policy,
335 .migrate = bin_migrate,
358 rc = attr->
mmap(file, kobj, attr, vma);
385 vma->
vm_ops = &bin_vm_ops;
438 static int release(
struct inode * inode,
struct file * file)
443 hlist_del(&bb->
list);
472 struct inode *inode = bb->
file->f_path.dentry->d_inode;
489 BUG_ON(!kobj || !kobj->
sd || !attr);