1d2a9170aSFrançois Tigeot /*
21382b9d0SFrançois Tigeot * Copyright (c) 2015-2020 François Tigeot <ftigeot@wolfpond.org>
3d2a9170aSFrançois Tigeot * All rights reserved.
4d2a9170aSFrançois Tigeot *
5d2a9170aSFrançois Tigeot * Redistribution and use in source and binary forms, with or without
6d2a9170aSFrançois Tigeot * modification, are permitted provided that the following conditions
7d2a9170aSFrançois Tigeot * are met:
8d2a9170aSFrançois Tigeot * 1. Redistributions of source code must retain the above copyright
9d2a9170aSFrançois Tigeot * notice unmodified, this list of conditions, and the following
10d2a9170aSFrançois Tigeot * disclaimer.
11d2a9170aSFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright
12d2a9170aSFrançois Tigeot * notice, this list of conditions and the following disclaimer in the
13d2a9170aSFrançois Tigeot * documentation and/or other materials provided with the distribution.
14d2a9170aSFrançois Tigeot *
15d2a9170aSFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16d2a9170aSFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17d2a9170aSFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18d2a9170aSFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19d2a9170aSFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20d2a9170aSFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21d2a9170aSFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22d2a9170aSFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23d2a9170aSFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24d2a9170aSFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25d2a9170aSFrançois Tigeot */
26d2a9170aSFrançois Tigeot
27d2a9170aSFrançois Tigeot #ifndef _LINUX_FS_H_
28d2a9170aSFrançois Tigeot #define _LINUX_FS_H_
29d2a9170aSFrançois Tigeot
30*3f2dd94aSFrançois Tigeot #include <linux/wait_bit.h>
31d998b496SFrançois Tigeot #include <linux/cache.h>
3215dba7a9SFrançois Tigeot #include <linux/stat.h>
33d6aa1cc5SFrançois Tigeot #include <linux/list.h>
341382b9d0SFrançois Tigeot #include <linux/llist.h>
35a3a2f5cbSFrançois Tigeot #include <linux/radix-tree.h>
36d6aa1cc5SFrançois Tigeot #include <linux/rbtree.h>
37d6aa1cc5SFrançois Tigeot #include <linux/init.h>
38d6aa1cc5SFrançois Tigeot #include <linux/pid.h>
39d6aa1cc5SFrançois Tigeot #include <linux/bug.h>
40d6aa1cc5SFrançois Tigeot #include <linux/mutex.h>
41d6aa1cc5SFrançois Tigeot #include <linux/capability.h>
42d6aa1cc5SFrançois Tigeot #include <linux/atomic.h>
4380fbca37SFrançois Tigeot #include <linux/shrinker.h>
44961a6190SFrançois Tigeot #include <linux/lockdep.h>
45*3f2dd94aSFrançois Tigeot #include <linux/workqueue.h>
46*3f2dd94aSFrançois Tigeot #include <linux/uuid.h>
47d2a9170aSFrançois Tigeot
48c4bb8e01SFrançois Tigeot #include <sys/file.h> /* for struct file */
491dedbd3bSFrançois Tigeot #include <sys/vnode.h> /* for struct vnode */
50c4bb8e01SFrançois Tigeot
513306aed3SFrançois Tigeot struct address_space;
523306aed3SFrançois Tigeot
53565c8854SFrançois Tigeot struct poll_table_struct;
54565c8854SFrançois Tigeot struct vm_area_struct;
55565c8854SFrançois Tigeot
561dedbd3bSFrançois Tigeot struct inode;
571dedbd3bSFrançois Tigeot
imajor(const struct inode * inode)581dedbd3bSFrançois Tigeot static inline unsigned imajor(const struct inode *inode)
591dedbd3bSFrançois Tigeot {
601dedbd3bSFrançois Tigeot const struct vnode *vp = (const void *)inode;
611dedbd3bSFrançois Tigeot
621dedbd3bSFrançois Tigeot return vp->v_umajor;
631dedbd3bSFrançois Tigeot }
641dedbd3bSFrançois Tigeot
iminor(const struct inode * inode)651dedbd3bSFrançois Tigeot static inline unsigned iminor(const struct inode *inode)
661dedbd3bSFrançois Tigeot {
671dedbd3bSFrançois Tigeot const struct vnode *vp = (const void *)inode;
681dedbd3bSFrançois Tigeot
691dedbd3bSFrançois Tigeot return vp->v_uminor;
701dedbd3bSFrançois Tigeot }
71565c8854SFrançois Tigeot
72565c8854SFrançois Tigeot struct file_operations {
73565c8854SFrançois Tigeot struct module *owner;
74565c8854SFrançois Tigeot int (*open) (struct inode *, struct file *);
75565c8854SFrançois Tigeot int (*release) (struct inode *, struct file *);
76565c8854SFrançois Tigeot long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
77565c8854SFrançois Tigeot int (*mmap) (struct file *, struct vm_area_struct *);
78565c8854SFrançois Tigeot unsigned int (*poll) (struct file *, struct poll_table_struct *);
79565c8854SFrançois Tigeot ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
80565c8854SFrançois Tigeot loff_t (*llseek) (struct file *, loff_t, int);
81565c8854SFrançois Tigeot };
82565c8854SFrançois Tigeot
83565c8854SFrançois Tigeot extern loff_t noop_llseek(struct file *file, loff_t offset, int whence);
84565c8854SFrançois Tigeot
85c15ebf28SFrançois Tigeot static inline unsigned long
invalidate_mapping_pages(struct vm_object * obj,pgoff_t start,pgoff_t end)86c15ebf28SFrançois Tigeot invalidate_mapping_pages(struct vm_object *obj, pgoff_t start, pgoff_t end)
87c15ebf28SFrançois Tigeot {
88c15ebf28SFrançois Tigeot int start_count, end_count, clean_only = 1;
89c15ebf28SFrançois Tigeot
904bd76d06SMatthew Dillon /*
914bd76d06SMatthew Dillon * XXX - resident_page_count no longer represents the
924bd76d06SMatthew Dillon * number of pages that might be mapped.
934bd76d06SMatthew Dillon *
944bd76d06SMatthew Dillon * All current use cases ignore the return value.
954bd76d06SMatthew Dillon */
96c15ebf28SFrançois Tigeot VM_OBJECT_LOCK(obj);
97c15ebf28SFrançois Tigeot start_count = obj->resident_page_count;
98c15ebf28SFrançois Tigeot /* Only non-dirty pages must be freed or invalidated */
99c15ebf28SFrançois Tigeot vm_object_page_remove(obj, start, end, clean_only);
100c15ebf28SFrançois Tigeot end_count = obj->resident_page_count;
101c15ebf28SFrançois Tigeot VM_OBJECT_UNLOCK(obj);
102c15ebf28SFrançois Tigeot return (start_count - end_count);
103c15ebf28SFrançois Tigeot }
104c15ebf28SFrançois Tigeot
105*3f2dd94aSFrançois Tigeot int pagecache_write_begin(struct vm_object *obj, struct address_space *mapping,
106*3f2dd94aSFrançois Tigeot loff_t pos, unsigned len, unsigned flags, struct page **pagep, void **fsdata);
107*3f2dd94aSFrançois Tigeot
108*3f2dd94aSFrançois Tigeot int pagecache_write_end(struct vm_object *obj, struct address_space *mapping,
109*3f2dd94aSFrançois Tigeot loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata);
110*3f2dd94aSFrançois Tigeot
111d2a9170aSFrançois Tigeot #endif /* _LINUX_FS_H_ */
112