1
2#ifndef _LINUX_FS_H
3#define _LINUX_FS_H
4
5#include <linux/linkage.h>
6#include <linux/wait_bit.h>
7#include <linux/kdev_t.h>
8#include <linux/dcache.h>
9#include <linux/path.h>
10#include <linux/stat.h>
11#include <linux/cache.h>
12#include <linux/list.h>
13#include <linux/list_lru.h>
14#include <linux/llist.h>
15#include <linux/radix-tree.h>
16#include <linux/xarray.h>
17#include <linux/rbtree.h>
18#include <linux/init.h>
19#include <linux/pid.h>
20#include <linux/bug.h>
21#include <linux/mutex.h>
22#include <linux/rwsem.h>
23#include <linux/mm_types.h>
24#include <linux/capability.h>
25#include <linux/semaphore.h>
26#include <linux/fcntl.h>
27#include <linux/fiemap.h>
28#include <linux/rculist_bl.h>
29#include <linux/atomic.h>
30#include <linux/shrinker.h>
31#include <linux/migrate_mode.h>
32#include <linux/uidgid.h>
33#include <linux/lockdep.h>
34#include <linux/percpu-rwsem.h>
35#include <linux/workqueue.h>
36#include <linux/delayed_call.h>
37#include <linux/uuid.h>
38#include <linux/errseq.h>
39#include <linux/ioprio.h>
40
41#include <asm/byteorder.h>
42#include <uapi/linux/fs.h>
43
44struct backing_dev_info;
45struct bdi_writeback;
46struct bio;
47struct export_operations;
48struct hd_geometry;
49struct iovec;
50struct kiocb;
51struct kobject;
52struct pipe_inode_info;
53struct poll_table_struct;
54struct kstatfs;
55struct vm_area_struct;
56struct vfsmount;
57struct cred;
58struct swap_info_struct;
59struct seq_file;
60struct workqueue_struct;
61struct iov_iter;
62struct fscrypt_info;
63struct fscrypt_operations;
64
65extern void __init inode_init(void);
66extern void __init inode_init_early(void);
67extern void __init files_init(void);
68extern void __init files_maxfiles_init(void);
69
70extern struct files_stat_struct files_stat;
71extern unsigned long get_max_files(void);
72extern unsigned int sysctl_nr_open;
73extern struct inodes_stat_t inodes_stat;
74extern int leases_enable, lease_break_time;
75extern int sysctl_protected_symlinks;
76extern int sysctl_protected_hardlinks;
77extern int sysctl_protected_fifos;
78extern int sysctl_protected_regular;
79
80typedef __kernel_rwf_t rwf_t;
81
82struct buffer_head;
83typedef int (get_block_t)(struct inode *inode, sector_t iblock,
84 struct buffer_head *bh_result, int create);
85typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
86 ssize_t bytes, void *private);
87
88#define MAY_EXEC 0x00000001
89#define MAY_WRITE 0x00000002
90#define MAY_READ 0x00000004
91#define MAY_APPEND 0x00000008
92#define MAY_ACCESS 0x00000010
93#define MAY_OPEN 0x00000020
94#define MAY_CHDIR 0x00000040
95
96#define MAY_NOT_BLOCK 0x00000080
97
98
99
100
101
102
103
104#define FMODE_READ ((__force fmode_t)0x1)
105
106#define FMODE_WRITE ((__force fmode_t)0x2)
107
108#define FMODE_LSEEK ((__force fmode_t)0x4)
109
110#define FMODE_PREAD ((__force fmode_t)0x8)
111
112#define FMODE_PWRITE ((__force fmode_t)0x10)
113
114#define FMODE_EXEC ((__force fmode_t)0x20)
115
116#define FMODE_NDELAY ((__force fmode_t)0x40)
117
118#define FMODE_EXCL ((__force fmode_t)0x80)
119
120
121#define FMODE_WRITE_IOCTL ((__force fmode_t)0x100)
122
123#define FMODE_32BITHASH ((__force fmode_t)0x200)
124
125#define FMODE_64BITHASH ((__force fmode_t)0x400)
126
127
128
129
130
131
132
133#define FMODE_NOCMTIME ((__force fmode_t)0x800)
134
135
136#define FMODE_RANDOM ((__force fmode_t)0x1000)
137
138
139#define FMODE_UNSIGNED_OFFSET ((__force fmode_t)0x2000)
140
141
142#define FMODE_PATH ((__force fmode_t)0x4000)
143
144
145#define FMODE_ATOMIC_POS ((__force fmode_t)0x8000)
146
147#define FMODE_WRITER ((__force fmode_t)0x10000)
148
149#define FMODE_CAN_READ ((__force fmode_t)0x20000)
150
151#define FMODE_CAN_WRITE ((__force fmode_t)0x40000)
152
153#define FMODE_OPENED ((__force fmode_t)0x80000)
154#define FMODE_CREATED ((__force fmode_t)0x100000)
155
156
157#define FMODE_NONOTIFY ((__force fmode_t)0x4000000)
158
159
160#define FMODE_NOWAIT ((__force fmode_t)0x8000000)
161
162
163#define FMODE_NOACCOUNT ((__force fmode_t)0x20000000)
164
165
166
167
168
169
170
171#define CHECK_IOVEC_ONLY -1
172
173
174
175
176
177#define ATTR_MODE (1 << 0)
178#define ATTR_UID (1 << 1)
179#define ATTR_GID (1 << 2)
180#define ATTR_SIZE (1 << 3)
181#define ATTR_ATIME (1 << 4)
182#define ATTR_MTIME (1 << 5)
183#define ATTR_CTIME (1 << 6)
184#define ATTR_ATIME_SET (1 << 7)
185#define ATTR_MTIME_SET (1 << 8)
186#define ATTR_FORCE (1 << 9)
187#define ATTR_KILL_SUID (1 << 11)
188#define ATTR_KILL_SGID (1 << 12)
189#define ATTR_FILE (1 << 13)
190#define ATTR_KILL_PRIV (1 << 14)
191#define ATTR_OPEN (1 << 15)
192#define ATTR_TIMES_SET (1 << 16)
193#define ATTR_TOUCH (1 << 17)
194
195
196
197
198
199#define WHITEOUT_MODE 0
200#define WHITEOUT_DEV 0
201
202
203
204
205
206
207
208
209
210
211struct iattr {
212 unsigned int ia_valid;
213 umode_t ia_mode;
214 kuid_t ia_uid;
215 kgid_t ia_gid;
216 loff_t ia_size;
217 struct timespec64 ia_atime;
218 struct timespec64 ia_mtime;
219 struct timespec64 ia_ctime;
220
221
222
223
224
225
226 struct file *ia_file;
227};
228
229
230
231
232#include <linux/quota.h>
233
234
235
236
237
238#define FILESYSTEM_MAX_STACK_DEPTH 2
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266enum positive_aop_returns {
267 AOP_WRITEPAGE_ACTIVATE = 0x80000,
268 AOP_TRUNCATED_PAGE = 0x80001,
269};
270
271#define AOP_FLAG_CONT_EXPAND 0x0001
272#define AOP_FLAG_NOFS 0x0002
273
274
275
276
277
278
279struct page;
280struct address_space;
281struct writeback_control;
282
283
284
285
286
287enum rw_hint {
288 WRITE_LIFE_NOT_SET = 0,
289 WRITE_LIFE_NONE = RWH_WRITE_LIFE_NONE,
290 WRITE_LIFE_SHORT = RWH_WRITE_LIFE_SHORT,
291 WRITE_LIFE_MEDIUM = RWH_WRITE_LIFE_MEDIUM,
292 WRITE_LIFE_LONG = RWH_WRITE_LIFE_LONG,
293 WRITE_LIFE_EXTREME = RWH_WRITE_LIFE_EXTREME,
294};
295
296#define IOCB_EVENTFD (1 << 0)
297#define IOCB_APPEND (1 << 1)
298#define IOCB_DIRECT (1 << 2)
299#define IOCB_HIPRI (1 << 3)
300#define IOCB_DSYNC (1 << 4)
301#define IOCB_SYNC (1 << 5)
302#define IOCB_WRITE (1 << 6)
303#define IOCB_NOWAIT (1 << 7)
304
305struct kiocb {
306 struct file *ki_filp;
307 loff_t ki_pos;
308 void (*ki_complete)(struct kiocb *iocb, long ret, long ret2);
309 void *private;
310 int ki_flags;
311 u16 ki_hint;
312 u16 ki_ioprio;
313} __randomize_layout;
314
315static inline bool is_sync_kiocb(struct kiocb *kiocb)
316{
317 return kiocb->ki_complete == NULL;
318}
319
320
321
322
323
324
325
326
327
328
329typedef struct {
330 size_t written;
331 size_t count;
332 union {
333 char __user *buf;
334 void *data;
335 } arg;
336 int error;
337} read_descriptor_t;
338
339typedef int (*read_actor_t)(read_descriptor_t *, struct page *,
340 unsigned long, unsigned long);
341
342struct address_space_operations {
343 int (*writepage)(struct page *page, struct writeback_control *wbc);
344 int (*readpage)(struct file *, struct page *);
345
346
347 int (*writepages)(struct address_space *, struct writeback_control *);
348
349
350 int (*set_page_dirty)(struct page *page);
351
352
353
354
355
356 int (*readpages)(struct file *filp, struct address_space *mapping,
357 struct list_head *pages, unsigned nr_pages);
358
359 int (*write_begin)(struct file *, struct address_space *mapping,
360 loff_t pos, unsigned len, unsigned flags,
361 struct page **pagep, void **fsdata);
362 int (*write_end)(struct file *, struct address_space *mapping,
363 loff_t pos, unsigned len, unsigned copied,
364 struct page *page, void *fsdata);
365
366
367 sector_t (*bmap)(struct address_space *, sector_t);
368 void (*invalidatepage) (struct page *, unsigned int, unsigned int);
369 int (*releasepage) (struct page *, gfp_t);
370 void (*freepage)(struct page *);
371 ssize_t (*direct_IO)(struct kiocb *, struct iov_iter *iter);
372
373
374
375
376 int (*migratepage) (struct address_space *,
377 struct page *, struct page *, enum migrate_mode);
378 bool (*isolate_page)(struct page *, isolate_mode_t);
379 void (*putback_page)(struct page *);
380 int (*launder_page) (struct page *);
381 int (*is_partially_uptodate) (struct page *, unsigned long,
382 unsigned long);
383 void (*is_dirty_writeback) (struct page *, bool *, bool *);
384 int (*error_remove_page)(struct address_space *, struct page *);
385
386
387 int (*swap_activate)(struct swap_info_struct *sis, struct file *file,
388 sector_t *span);
389 void (*swap_deactivate)(struct file *file);
390};
391
392extern const struct address_space_operations empty_aops;
393
394
395
396
397
398int pagecache_write_begin(struct file *, struct address_space *mapping,
399 loff_t pos, unsigned len, unsigned flags,
400 struct page **pagep, void **fsdata);
401
402int pagecache_write_end(struct file *, struct address_space *mapping,
403 loff_t pos, unsigned len, unsigned copied,
404 struct page *page, void *fsdata);
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424struct address_space {
425 struct inode *host;
426 struct xarray i_pages;
427 gfp_t gfp_mask;
428 atomic_t i_mmap_writable;
429 struct rb_root_cached i_mmap;
430 struct rw_semaphore i_mmap_rwsem;
431 unsigned long nrpages;
432 unsigned long nrexceptional;
433 pgoff_t writeback_index;
434 const struct address_space_operations *a_ops;
435 unsigned long flags;
436 errseq_t wb_err;
437 spinlock_t private_lock;
438 struct list_head private_list;
439 void *private_data;
440} __attribute__((aligned(sizeof(long)))) __randomize_layout;
441
442
443
444
445
446struct request_queue;
447
448struct block_device {
449 dev_t bd_dev;
450 int bd_openers;
451 struct inode * bd_inode;
452 struct super_block * bd_super;
453 struct mutex bd_mutex;
454 void * bd_claiming;
455 void * bd_holder;
456 int bd_holders;
457 bool bd_write_holder;
458#ifdef CONFIG_SYSFS
459 struct list_head bd_holder_disks;
460#endif
461 struct block_device * bd_contains;
462 unsigned bd_block_size;
463 u8 bd_partno;
464 struct hd_struct * bd_part;
465
466 unsigned bd_part_count;
467 int bd_invalidated;
468 struct gendisk * bd_disk;
469 struct request_queue * bd_queue;
470 struct backing_dev_info *bd_bdi;
471 struct list_head bd_list;
472
473
474
475
476
477
478 unsigned long bd_private;
479
480
481 int bd_fsfreeze_count;
482
483 struct mutex bd_fsfreeze_mutex;
484} __randomize_layout;
485
486
487#define PAGECACHE_TAG_DIRTY XA_MARK_0
488#define PAGECACHE_TAG_WRITEBACK XA_MARK_1
489#define PAGECACHE_TAG_TOWRITE XA_MARK_2
490
491
492
493
494static inline bool mapping_tagged(struct address_space *mapping, xa_mark_t tag)
495{
496 return xa_marked(&mapping->i_pages, tag);
497}
498
499static inline void i_mmap_lock_write(struct address_space *mapping)
500{
501 down_write(&mapping->i_mmap_rwsem);
502}
503
504static inline void i_mmap_unlock_write(struct address_space *mapping)
505{
506 up_write(&mapping->i_mmap_rwsem);
507}
508
509static inline void i_mmap_lock_read(struct address_space *mapping)
510{
511 down_read(&mapping->i_mmap_rwsem);
512}
513
514static inline void i_mmap_unlock_read(struct address_space *mapping)
515{
516 up_read(&mapping->i_mmap_rwsem);
517}
518
519
520
521
522static inline int mapping_mapped(struct address_space *mapping)
523{
524 return !RB_EMPTY_ROOT(&mapping->i_mmap.rb_root);
525}
526
527
528
529
530
531
532
533
534
535
536static inline int mapping_writably_mapped(struct address_space *mapping)
537{
538 return atomic_read(&mapping->i_mmap_writable) > 0;
539}
540
541static inline int mapping_map_writable(struct address_space *mapping)
542{
543 return atomic_inc_unless_negative(&mapping->i_mmap_writable) ?
544 0 : -EPERM;
545}
546
547static inline void mapping_unmap_writable(struct address_space *mapping)
548{
549 atomic_dec(&mapping->i_mmap_writable);
550}
551
552static inline int mapping_deny_writable(struct address_space *mapping)
553{
554 return atomic_dec_unless_positive(&mapping->i_mmap_writable) ?
555 0 : -EBUSY;
556}
557
558static inline void mapping_allow_writable(struct address_space *mapping)
559{
560 atomic_inc(&mapping->i_mmap_writable);
561}
562
563
564
565
566#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
567#include <linux/seqlock.h>
568#define __NEED_I_SIZE_ORDERED
569#define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount)
570#else
571#define i_size_ordered_init(inode) do { } while (0)
572#endif
573
574struct posix_acl;
575#define ACL_NOT_CACHED ((void *)(-1))
576#define ACL_DONT_CACHE ((void *)(-3))
577
578static inline struct posix_acl *
579uncached_acl_sentinel(struct task_struct *task)
580{
581 return (void *)task + 1;
582}
583
584static inline bool
585is_uncached_acl(struct posix_acl *acl)
586{
587 return (long)acl & 1;
588}
589
590#define IOP_FASTPERM 0x0001
591#define IOP_LOOKUP 0x0002
592#define IOP_NOFOLLOW 0x0004
593#define IOP_XATTR 0x0008
594#define IOP_DEFAULT_READLINK 0x0010
595
596struct fsnotify_mark_connector;
597
598
599
600
601
602
603struct inode {
604 umode_t i_mode;
605 unsigned short i_opflags;
606 kuid_t i_uid;
607 kgid_t i_gid;
608 unsigned int i_flags;
609
610#ifdef CONFIG_FS_POSIX_ACL
611 struct posix_acl *i_acl;
612 struct posix_acl *i_default_acl;
613#endif
614
615 const struct inode_operations *i_op;
616 struct super_block *i_sb;
617 struct address_space *i_mapping;
618
619#ifdef CONFIG_SECURITY
620 void *i_security;
621#endif
622
623
624 unsigned long i_ino;
625
626
627
628
629
630
631
632 union {
633 const unsigned int i_nlink;
634 unsigned int __i_nlink;
635 };
636 dev_t i_rdev;
637 loff_t i_size;
638 struct timespec64 i_atime;
639 struct timespec64 i_mtime;
640 struct timespec64 i_ctime;
641 spinlock_t i_lock;
642 unsigned short i_bytes;
643 u8 i_blkbits;
644 u8 i_write_hint;
645 blkcnt_t i_blocks;
646
647#ifdef __NEED_I_SIZE_ORDERED
648 seqcount_t i_size_seqcount;
649#endif
650
651
652 unsigned long i_state;
653 struct rw_semaphore i_rwsem;
654
655 unsigned long dirtied_when;
656 unsigned long dirtied_time_when;
657
658 struct hlist_node i_hash;
659 struct list_head i_io_list;
660#ifdef CONFIG_CGROUP_WRITEBACK
661 struct bdi_writeback *i_wb;
662
663
664 int i_wb_frn_winner;
665 u16 i_wb_frn_avg_time;
666 u16 i_wb_frn_history;
667#endif
668 struct list_head i_lru;
669 struct list_head i_sb_list;
670 struct list_head i_wb_list;
671 union {
672 struct hlist_head i_dentry;
673 struct rcu_head i_rcu;
674 };
675 atomic64_t i_version;
676 atomic_t i_count;
677 atomic_t i_dio_count;
678 atomic_t i_writecount;
679#ifdef CONFIG_IMA
680 atomic_t i_readcount;
681#endif
682 const struct file_operations *i_fop;
683 struct file_lock_context *i_flctx;
684 struct address_space i_data;
685 struct list_head i_devices;
686 union {
687 struct pipe_inode_info *i_pipe;
688 struct block_device *i_bdev;
689 struct cdev *i_cdev;
690 char *i_link;
691 unsigned i_dir_seq;
692 };
693
694 __u32 i_generation;
695
696#ifdef CONFIG_FSNOTIFY
697 __u32 i_fsnotify_mask;
698 struct fsnotify_mark_connector __rcu *i_fsnotify_marks;
699#endif
700
701#if IS_ENABLED(CONFIG_FS_ENCRYPTION)
702 struct fscrypt_info *i_crypt_info;
703#endif
704
705 void *i_private;
706} __randomize_layout;
707
708static inline unsigned int i_blocksize(const struct inode *node)
709{
710 return (1 << node->i_blkbits);
711}
712
713static inline int inode_unhashed(struct inode *inode)
714{
715 return hlist_unhashed(&inode->i_hash);
716}
717
718
719
720
721
722
723
724static inline void inode_fake_hash(struct inode *inode)
725{
726 hlist_add_fake(&inode->i_hash);
727}
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745enum inode_i_mutex_lock_class
746{
747 I_MUTEX_NORMAL,
748 I_MUTEX_PARENT,
749 I_MUTEX_CHILD,
750 I_MUTEX_XATTR,
751 I_MUTEX_NONDIR2,
752 I_MUTEX_PARENT2,
753};
754
755static inline void inode_lock(struct inode *inode)
756{
757 down_write(&inode->i_rwsem);
758}
759
760static inline void inode_unlock(struct inode *inode)
761{
762 up_write(&inode->i_rwsem);
763}
764
765static inline void inode_lock_shared(struct inode *inode)
766{
767 down_read(&inode->i_rwsem);
768}
769
770static inline void inode_unlock_shared(struct inode *inode)
771{
772 up_read(&inode->i_rwsem);
773}
774
775static inline int inode_trylock(struct inode *inode)
776{
777 return down_write_trylock(&inode->i_rwsem);
778}
779
780static inline int inode_trylock_shared(struct inode *inode)
781{
782 return down_read_trylock(&inode->i_rwsem);
783}
784
785static inline int inode_is_locked(struct inode *inode)
786{
787 return rwsem_is_locked(&inode->i_rwsem);
788}
789
790static inline void inode_lock_nested(struct inode *inode, unsigned subclass)
791{
792 down_write_nested(&inode->i_rwsem, subclass);
793}
794
795static inline void inode_lock_shared_nested(struct inode *inode, unsigned subclass)
796{
797 down_read_nested(&inode->i_rwsem, subclass);
798}
799
800void lock_two_nondirectories(struct inode *, struct inode*);
801void unlock_two_nondirectories(struct inode *, struct inode*);
802
803
804
805
806
807
808
809
810
811
812
813static inline loff_t i_size_read(const struct inode *inode)
814{
815#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
816 loff_t i_size;
817 unsigned int seq;
818
819 do {
820 seq = read_seqcount_begin(&inode->i_size_seqcount);
821 i_size = inode->i_size;
822 } while (read_seqcount_retry(&inode->i_size_seqcount, seq));
823 return i_size;
824#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
825 loff_t i_size;
826
827 preempt_disable();
828 i_size = inode->i_size;
829 preempt_enable();
830 return i_size;
831#else
832 return inode->i_size;
833#endif
834}
835
836
837
838
839
840
841static inline void i_size_write(struct inode *inode, loff_t i_size)
842{
843#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
844 preempt_disable();
845 write_seqcount_begin(&inode->i_size_seqcount);
846 inode->i_size = i_size;
847 write_seqcount_end(&inode->i_size_seqcount);
848 preempt_enable();
849#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
850 preempt_disable();
851 inode->i_size = i_size;
852 preempt_enable();
853#else
854 inode->i_size = i_size;
855#endif
856}
857
858static inline unsigned iminor(const struct inode *inode)
859{
860 return MINOR(inode->i_rdev);
861}
862
863static inline unsigned imajor(const struct inode *inode)
864{
865 return MAJOR(inode->i_rdev);
866}
867
868extern struct block_device *I_BDEV(struct inode *inode);
869
870struct fown_struct {
871 rwlock_t lock;
872 struct pid *pid;
873 enum pid_type pid_type;
874 kuid_t uid, euid;
875 int signum;
876};
877
878
879
880
881struct file_ra_state {
882 pgoff_t start;
883 unsigned int size;
884 unsigned int async_size;
885
886
887 unsigned int ra_pages;
888 unsigned int mmap_miss;
889 loff_t prev_pos;
890};
891
892
893
894
895static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index)
896{
897 return (index >= ra->start &&
898 index < ra->start + ra->size);
899}
900
901struct file {
902 union {
903 struct llist_node fu_llist;
904 struct rcu_head fu_rcuhead;
905 } f_u;
906 struct path f_path;
907 struct inode *f_inode;
908 const struct file_operations *f_op;
909
910
911
912
913
914 spinlock_t f_lock;
915 enum rw_hint f_write_hint;
916 atomic_long_t f_count;
917 unsigned int f_flags;
918 fmode_t f_mode;
919 struct mutex f_pos_lock;
920 loff_t f_pos;
921 struct fown_struct f_owner;
922 const struct cred *f_cred;
923 struct file_ra_state f_ra;
924
925 u64 f_version;
926#ifdef CONFIG_SECURITY
927 void *f_security;
928#endif
929
930 void *private_data;
931
932#ifdef CONFIG_EPOLL
933
934 struct list_head f_ep_links;
935 struct list_head f_tfile_llink;
936#endif
937 struct address_space *f_mapping;
938 errseq_t f_wb_err;
939} __randomize_layout
940 __attribute__((aligned(4)));
941
942struct file_handle {
943 __u32 handle_bytes;
944 int handle_type;
945
946 unsigned char f_handle[0];
947};
948
949static inline struct file *get_file(struct file *f)
950{
951 atomic_long_inc(&f->f_count);
952 return f;
953}
954#define get_file_rcu(x) atomic_long_inc_not_zero(&(x)->f_count)
955#define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1)
956#define file_count(x) atomic_long_read(&(x)->f_count)
957
958#define MAX_NON_LFS ((1UL<<31) - 1)
959
960
961
962#if BITS_PER_LONG==32
963#define MAX_LFS_FILESIZE ((loff_t)ULONG_MAX << PAGE_SHIFT)
964#elif BITS_PER_LONG==64
965#define MAX_LFS_FILESIZE ((loff_t)LLONG_MAX)
966#endif
967
968#define FL_POSIX 1
969#define FL_FLOCK 2
970#define FL_DELEG 4
971#define FL_ACCESS 8
972#define FL_EXISTS 16
973#define FL_LEASE 32
974#define FL_CLOSE 64
975#define FL_SLEEP 128
976#define FL_DOWNGRADE_PENDING 256
977#define FL_UNLOCK_PENDING 512
978#define FL_OFDLCK 1024
979#define FL_LAYOUT 2048
980
981#define FL_CLOSE_POSIX (FL_POSIX | FL_CLOSE)
982
983
984
985
986
987#define FILE_LOCK_DEFERRED 1
988
989
990typedef void *fl_owner_t;
991
992struct file_lock;
993
994struct file_lock_operations {
995 void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
996 void (*fl_release_private)(struct file_lock *);
997};
998
999struct lock_manager_operations {
1000 int (*lm_compare_owner)(struct file_lock *, struct file_lock *);
1001 unsigned long (*lm_owner_key)(struct file_lock *);
1002 fl_owner_t (*lm_get_owner)(fl_owner_t);
1003 void (*lm_put_owner)(fl_owner_t);
1004 void (*lm_notify)(struct file_lock *);
1005 int (*lm_grant)(struct file_lock *, int);
1006 bool (*lm_break)(struct file_lock *);
1007 int (*lm_change)(struct file_lock *, int, struct list_head *);
1008 void (*lm_setup)(struct file_lock *, void **);
1009};
1010
1011struct lock_manager {
1012 struct list_head list;
1013
1014
1015
1016
1017 bool block_opens;
1018};
1019
1020struct net;
1021void locks_start_grace(struct net *, struct lock_manager *);
1022void locks_end_grace(struct lock_manager *);
1023bool locks_in_grace(struct net *);
1024bool opens_in_grace(struct net *);
1025
1026
1027#include <linux/nfs_fs_i.h>
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046struct file_lock {
1047 struct file_lock *fl_blocker;
1048 struct list_head fl_list;
1049 struct hlist_node fl_link;
1050 struct list_head fl_blocked_requests;
1051
1052
1053 struct list_head fl_blocked_member;
1054
1055
1056 fl_owner_t fl_owner;
1057 unsigned int fl_flags;
1058 unsigned char fl_type;
1059 unsigned int fl_pid;
1060 int fl_link_cpu;
1061 wait_queue_head_t fl_wait;
1062 struct file *fl_file;
1063 loff_t fl_start;
1064 loff_t fl_end;
1065
1066 struct fasync_struct * fl_fasync;
1067
1068 unsigned long fl_break_time;
1069 unsigned long fl_downgrade_time;
1070
1071 const struct file_lock_operations *fl_ops;
1072 const struct lock_manager_operations *fl_lmops;
1073 union {
1074 struct nfs_lock_info nfs_fl;
1075 struct nfs4_lock_info nfs4_fl;
1076 struct {
1077 struct list_head link;
1078 int state;
1079 } afs;
1080 } fl_u;
1081} __randomize_layout;
1082
1083struct file_lock_context {
1084 spinlock_t flc_lock;
1085 struct list_head flc_flock;
1086 struct list_head flc_posix;
1087 struct list_head flc_lease;
1088};
1089
1090
1091#ifndef OFFSET_MAX
1092#define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
1093#define OFFSET_MAX INT_LIMIT(loff_t)
1094#define OFFT_OFFSET_MAX INT_LIMIT(off_t)
1095#endif
1096
1097extern void send_sigio(struct fown_struct *fown, int fd, int band);
1098
1099#define locks_inode(f) file_inode(f)
1100
1101#ifdef CONFIG_FILE_LOCKING
1102extern int fcntl_getlk(struct file *, unsigned int, struct flock *);
1103extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
1104 struct flock *);
1105
1106#if BITS_PER_LONG == 32
1107extern int fcntl_getlk64(struct file *, unsigned int, struct flock64 *);
1108extern int fcntl_setlk64(unsigned int, struct file *, unsigned int,
1109 struct flock64 *);
1110#endif
1111
1112extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
1113extern int fcntl_getlease(struct file *filp);
1114
1115
1116void locks_free_lock_context(struct inode *inode);
1117void locks_free_lock(struct file_lock *fl);
1118extern void locks_init_lock(struct file_lock *);
1119extern struct file_lock * locks_alloc_lock(void);
1120extern void locks_copy_lock(struct file_lock *, struct file_lock *);
1121extern void locks_copy_conflock(struct file_lock *, struct file_lock *);
1122extern void locks_remove_posix(struct file *, fl_owner_t);
1123extern void locks_remove_file(struct file *);
1124extern void locks_release_private(struct file_lock *);
1125extern void posix_test_lock(struct file *, struct file_lock *);
1126extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *);
1127extern int locks_delete_block(struct file_lock *);
1128extern int vfs_test_lock(struct file *, struct file_lock *);
1129extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *);
1130extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
1131extern int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl);
1132extern int __break_lease(struct inode *inode, unsigned int flags, unsigned int type);
1133extern void lease_get_mtime(struct inode *, struct timespec64 *time);
1134extern int generic_setlease(struct file *, long, struct file_lock **, void **priv);
1135extern int vfs_setlease(struct file *, long, struct file_lock **, void **);
1136extern int lease_modify(struct file_lock *, int, struct list_head *);
1137struct files_struct;
1138extern void show_fd_locks(struct seq_file *f,
1139 struct file *filp, struct files_struct *files);
1140#else
1141static inline int fcntl_getlk(struct file *file, unsigned int cmd,
1142 struct flock __user *user)
1143{
1144 return -EINVAL;
1145}
1146
1147static inline int fcntl_setlk(unsigned int fd, struct file *file,
1148 unsigned int cmd, struct flock __user *user)
1149{
1150 return -EACCES;
1151}
1152
1153#if BITS_PER_LONG == 32
1154static inline int fcntl_getlk64(struct file *file, unsigned int cmd,
1155 struct flock64 __user *user)
1156{
1157 return -EINVAL;
1158}
1159
1160static inline int fcntl_setlk64(unsigned int fd, struct file *file,
1161 unsigned int cmd, struct flock64 __user *user)
1162{
1163 return -EACCES;
1164}
1165#endif
1166static inline int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
1167{
1168 return -EINVAL;
1169}
1170
1171static inline int fcntl_getlease(struct file *filp)
1172{
1173 return F_UNLCK;
1174}
1175
1176static inline void
1177locks_free_lock_context(struct inode *inode)
1178{
1179}
1180
1181static inline void locks_init_lock(struct file_lock *fl)
1182{
1183 return;
1184}
1185
1186static inline void locks_copy_conflock(struct file_lock *new, struct file_lock *fl)
1187{
1188 return;
1189}
1190
1191static inline void locks_copy_lock(struct file_lock *new, struct file_lock *fl)
1192{
1193 return;
1194}
1195
1196static inline void locks_remove_posix(struct file *filp, fl_owner_t owner)
1197{
1198 return;
1199}
1200
1201static inline void locks_remove_file(struct file *filp)
1202{
1203 return;
1204}
1205
1206static inline void posix_test_lock(struct file *filp, struct file_lock *fl)
1207{
1208 return;
1209}
1210
1211static inline int posix_lock_file(struct file *filp, struct file_lock *fl,
1212 struct file_lock *conflock)
1213{
1214 return -ENOLCK;
1215}
1216
1217static inline int locks_delete_block(struct file_lock *waiter)
1218{
1219 return -ENOENT;
1220}
1221
1222static inline int vfs_test_lock(struct file *filp, struct file_lock *fl)
1223{
1224 return 0;
1225}
1226
1227static inline int vfs_lock_file(struct file *filp, unsigned int cmd,
1228 struct file_lock *fl, struct file_lock *conf)
1229{
1230 return -ENOLCK;
1231}
1232
1233static inline int vfs_cancel_lock(struct file *filp, struct file_lock *fl)
1234{
1235 return 0;
1236}
1237
1238static inline int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl)
1239{
1240 return -ENOLCK;
1241}
1242
1243static inline int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
1244{
1245 return 0;
1246}
1247
1248static inline void lease_get_mtime(struct inode *inode,
1249 struct timespec64 *time)
1250{
1251 return;
1252}
1253
1254static inline int generic_setlease(struct file *filp, long arg,
1255 struct file_lock **flp, void **priv)
1256{
1257 return -EINVAL;
1258}
1259
1260static inline int vfs_setlease(struct file *filp, long arg,
1261 struct file_lock **lease, void **priv)
1262{
1263 return -EINVAL;
1264}
1265
1266static inline int lease_modify(struct file_lock *fl, int arg,
1267 struct list_head *dispose)
1268{
1269 return -EINVAL;
1270}
1271
1272struct files_struct;
1273static inline void show_fd_locks(struct seq_file *f,
1274 struct file *filp, struct files_struct *files) {}
1275#endif
1276
1277static inline struct inode *file_inode(const struct file *f)
1278{
1279 return f->f_inode;
1280}
1281
1282static inline struct dentry *file_dentry(const struct file *file)
1283{
1284 return d_real(file->f_path.dentry, file_inode(file));
1285}
1286
1287static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl)
1288{
1289 return locks_lock_inode_wait(locks_inode(filp), fl);
1290}
1291
1292struct fasync_struct {
1293 rwlock_t fa_lock;
1294 int magic;
1295 int fa_fd;
1296 struct fasync_struct *fa_next;
1297 struct file *fa_file;
1298 struct rcu_head fa_rcu;
1299};
1300
1301#define FASYNC_MAGIC 0x4601
1302
1303
1304extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
1305extern struct fasync_struct *fasync_insert_entry(int, struct file *, struct fasync_struct **, struct fasync_struct *);
1306extern int fasync_remove_entry(struct file *, struct fasync_struct **);
1307extern struct fasync_struct *fasync_alloc(void);
1308extern void fasync_free(struct fasync_struct *);
1309
1310
1311extern void kill_fasync(struct fasync_struct **, int, int);
1312
1313extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
1314extern int f_setown(struct file *filp, unsigned long arg, int force);
1315extern void f_delown(struct file *filp);
1316extern pid_t f_getown(struct file *filp);
1317extern int send_sigurg(struct fown_struct *fown);
1318
1319
1320
1321
1322
1323#define SB_RDONLY 1
1324#define SB_NOSUID 2
1325#define SB_NODEV 4
1326#define SB_NOEXEC 8
1327#define SB_SYNCHRONOUS 16
1328#define SB_MANDLOCK 64
1329#define SB_DIRSYNC 128
1330#define SB_NOATIME 1024
1331#define SB_NODIRATIME 2048
1332#define SB_SILENT 32768
1333#define SB_POSIXACL (1<<16)
1334#define SB_KERNMOUNT (1<<22)
1335#define SB_I_VERSION (1<<23)
1336#define SB_LAZYTIME (1<<25)
1337
1338
1339#define SB_SUBMOUNT (1<<26)
1340#define SB_NOSEC (1<<28)
1341#define SB_BORN (1<<29)
1342#define SB_ACTIVE (1<<30)
1343#define SB_NOUSER (1<<31)
1344
1345
1346
1347
1348
1349#define MNT_FORCE 0x00000001
1350#define MNT_DETACH 0x00000002
1351#define MNT_EXPIRE 0x00000004
1352#define UMOUNT_NOFOLLOW 0x00000008
1353#define UMOUNT_UNUSED 0x80000000
1354
1355
1356#define SB_I_CGROUPWB 0x00000001
1357#define SB_I_NOEXEC 0x00000002
1358#define SB_I_NODEV 0x00000004
1359#define SB_I_MULTIROOT 0x00000008
1360
1361
1362#define SB_I_USERNS_VISIBLE 0x00000010
1363#define SB_I_IMA_UNVERIFIABLE_SIGNATURE 0x00000020
1364#define SB_I_UNTRUSTED_MOUNTER 0x00000040
1365
1366
1367enum {
1368 SB_UNFROZEN = 0,
1369 SB_FREEZE_WRITE = 1,
1370 SB_FREEZE_PAGEFAULT = 2,
1371 SB_FREEZE_FS = 3,
1372
1373 SB_FREEZE_COMPLETE = 4,
1374};
1375
1376#define SB_FREEZE_LEVELS (SB_FREEZE_COMPLETE - 1)
1377
1378struct sb_writers {
1379 int frozen;
1380 wait_queue_head_t wait_unfrozen;
1381 struct percpu_rw_semaphore rw_sem[SB_FREEZE_LEVELS];
1382};
1383
1384struct super_block {
1385 struct list_head s_list;
1386 dev_t s_dev;
1387 unsigned char s_blocksize_bits;
1388 unsigned long s_blocksize;
1389 loff_t s_maxbytes;
1390 struct file_system_type *s_type;
1391 const struct super_operations *s_op;
1392 const struct dquot_operations *dq_op;
1393 const struct quotactl_ops *s_qcop;
1394 const struct export_operations *s_export_op;
1395 unsigned long s_flags;
1396 unsigned long s_iflags;
1397 unsigned long s_magic;
1398 struct dentry *s_root;
1399 struct rw_semaphore s_umount;
1400 int s_count;
1401 atomic_t s_active;
1402#ifdef CONFIG_SECURITY
1403 void *s_security;
1404#endif
1405 const struct xattr_handler **s_xattr;
1406#if IS_ENABLED(CONFIG_FS_ENCRYPTION)
1407 const struct fscrypt_operations *s_cop;
1408#endif
1409 struct hlist_bl_head s_roots;
1410 struct list_head s_mounts;
1411 struct block_device *s_bdev;
1412 struct backing_dev_info *s_bdi;
1413 struct mtd_info *s_mtd;
1414 struct hlist_node s_instances;
1415 unsigned int s_quota_types;
1416 struct quota_info s_dquot;
1417
1418 struct sb_writers s_writers;
1419
1420
1421
1422
1423
1424
1425 void *s_fs_info;
1426
1427
1428 u32 s_time_gran;
1429#ifdef CONFIG_FSNOTIFY
1430 __u32 s_fsnotify_mask;
1431 struct fsnotify_mark_connector __rcu *s_fsnotify_marks;
1432#endif
1433
1434 char s_id[32];
1435 uuid_t s_uuid;
1436
1437 unsigned int s_max_links;
1438 fmode_t s_mode;
1439
1440
1441
1442
1443
1444 struct mutex s_vfs_rename_mutex;
1445
1446
1447
1448
1449
1450 char *s_subtype;
1451
1452 const struct dentry_operations *s_d_op;
1453
1454
1455
1456
1457 int cleancache_poolid;
1458
1459 struct shrinker s_shrink;
1460
1461
1462 atomic_long_t s_remove_count;
1463
1464
1465 atomic_long_t s_fsnotify_inode_refs;
1466
1467
1468 int s_readonly_remount;
1469
1470
1471 struct workqueue_struct *s_dio_done_wq;
1472 struct hlist_head s_pins;
1473
1474
1475
1476
1477
1478
1479 struct user_namespace *s_user_ns;
1480
1481
1482
1483
1484
1485
1486 struct list_lru s_dentry_lru;
1487 struct list_lru s_inode_lru;
1488 struct rcu_head rcu;
1489 struct work_struct destroy_work;
1490
1491 struct mutex s_sync_lock;
1492
1493
1494
1495
1496 int s_stack_depth;
1497
1498
1499 spinlock_t s_inode_list_lock ____cacheline_aligned_in_smp;
1500 struct list_head s_inodes;
1501
1502 spinlock_t s_inode_wblist_lock;
1503 struct list_head s_inodes_wb;
1504} __randomize_layout;
1505
1506
1507
1508
1509
1510
1511static inline uid_t i_uid_read(const struct inode *inode)
1512{
1513 return from_kuid(inode->i_sb->s_user_ns, inode->i_uid);
1514}
1515
1516static inline gid_t i_gid_read(const struct inode *inode)
1517{
1518 return from_kgid(inode->i_sb->s_user_ns, inode->i_gid);
1519}
1520
1521static inline void i_uid_write(struct inode *inode, uid_t uid)
1522{
1523 inode->i_uid = make_kuid(inode->i_sb->s_user_ns, uid);
1524}
1525
1526static inline void i_gid_write(struct inode *inode, gid_t gid)
1527{
1528 inode->i_gid = make_kgid(inode->i_sb->s_user_ns, gid);
1529}
1530
1531extern struct timespec64 timespec64_trunc(struct timespec64 t, unsigned gran);
1532extern struct timespec64 current_time(struct inode *inode);
1533
1534
1535
1536
1537
1538void __sb_end_write(struct super_block *sb, int level);
1539int __sb_start_write(struct super_block *sb, int level, bool wait);
1540
1541#define __sb_writers_acquired(sb, lev) \
1542 percpu_rwsem_acquire(&(sb)->s_writers.rw_sem[(lev)-1], 1, _THIS_IP_)
1543#define __sb_writers_release(sb, lev) \
1544 percpu_rwsem_release(&(sb)->s_writers.rw_sem[(lev)-1], 1, _THIS_IP_)
1545
1546
1547
1548
1549
1550
1551
1552
1553static inline void sb_end_write(struct super_block *sb)
1554{
1555 __sb_end_write(sb, SB_FREEZE_WRITE);
1556}
1557
1558
1559
1560
1561
1562
1563
1564
1565static inline void sb_end_pagefault(struct super_block *sb)
1566{
1567 __sb_end_write(sb, SB_FREEZE_PAGEFAULT);
1568}
1569
1570
1571
1572
1573
1574
1575
1576
1577static inline void sb_end_intwrite(struct super_block *sb)
1578{
1579 __sb_end_write(sb, SB_FREEZE_FS);
1580}
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601static inline void sb_start_write(struct super_block *sb)
1602{
1603 __sb_start_write(sb, SB_FREEZE_WRITE, true);
1604}
1605
1606static inline int sb_start_write_trylock(struct super_block *sb)
1607{
1608 return __sb_start_write(sb, SB_FREEZE_WRITE, false);
1609}
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630static inline void sb_start_pagefault(struct super_block *sb)
1631{
1632 __sb_start_write(sb, SB_FREEZE_PAGEFAULT, true);
1633}
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648static inline void sb_start_intwrite(struct super_block *sb)
1649{
1650 __sb_start_write(sb, SB_FREEZE_FS, true);
1651}
1652
1653static inline int sb_start_intwrite_trylock(struct super_block *sb)
1654{
1655 return __sb_start_write(sb, SB_FREEZE_FS, false);
1656}
1657
1658
1659extern bool inode_owner_or_capable(const struct inode *inode);
1660
1661
1662
1663
1664extern int vfs_create(struct inode *, struct dentry *, umode_t, bool);
1665extern int vfs_mkdir(struct inode *, struct dentry *, umode_t);
1666extern int vfs_mknod(struct inode *, struct dentry *, umode_t, dev_t);
1667extern int vfs_symlink(struct inode *, struct dentry *, const char *);
1668extern int vfs_link(struct dentry *, struct inode *, struct dentry *, struct inode **);
1669extern int vfs_rmdir(struct inode *, struct dentry *);
1670extern int vfs_unlink(struct inode *, struct dentry *, struct inode **);
1671extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *, struct inode **, unsigned int);
1672extern int vfs_whiteout(struct inode *, struct dentry *);
1673
1674extern struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode,
1675 int open_flag);
1676
1677int vfs_mkobj(struct dentry *, umode_t,
1678 int (*f)(struct dentry *, umode_t, void *),
1679 void *);
1680
1681extern long vfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1682
1683
1684
1685
1686extern void inode_init_owner(struct inode *inode, const struct inode *dir,
1687 umode_t mode);
1688extern bool may_open_dev(const struct path *path);
1689
1690
1691
1692struct fiemap_extent_info {
1693 unsigned int fi_flags;
1694 unsigned int fi_extents_mapped;
1695 unsigned int fi_extents_max;
1696 struct fiemap_extent __user *fi_extents_start;
1697
1698};
1699int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
1700 u64 phys, u64 len, u32 flags);
1701int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags);
1702
1703
1704
1705
1706
1707
1708
1709#define DT_UNKNOWN 0
1710#define DT_FIFO 1
1711#define DT_CHR 2
1712#define DT_DIR 4
1713#define DT_BLK 6
1714#define DT_REG 8
1715#define DT_LNK 10
1716#define DT_SOCK 12
1717#define DT_WHT 14
1718
1719
1720
1721
1722
1723
1724
1725struct dir_context;
1726typedef int (*filldir_t)(struct dir_context *, const char *, int, loff_t, u64,
1727 unsigned);
1728
1729struct dir_context {
1730 filldir_t actor;
1731 loff_t pos;
1732};
1733
1734struct block_device_operations;
1735
1736
1737
1738
1739#define HAVE_COMPAT_IOCTL 1
1740#define HAVE_UNLOCKED_IOCTL 1
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752#define NOMMU_MAP_COPY 0x00000001
1753#define NOMMU_MAP_DIRECT 0x00000008
1754#define NOMMU_MAP_READ VM_MAYREAD
1755#define NOMMU_MAP_WRITE VM_MAYWRITE
1756#define NOMMU_MAP_EXEC VM_MAYEXEC
1757
1758#define NOMMU_VMFLAGS \
1759 (NOMMU_MAP_READ | NOMMU_MAP_WRITE | NOMMU_MAP_EXEC)
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769#define REMAP_FILE_DEDUP (1 << 0)
1770#define REMAP_FILE_CAN_SHORTEN (1 << 1)
1771
1772
1773
1774
1775
1776
1777
1778
1779#define REMAP_FILE_ADVISORY (REMAP_FILE_CAN_SHORTEN)
1780
1781struct iov_iter;
1782
1783struct file_operations {
1784 struct module *owner;
1785 loff_t (*llseek) (struct file *, loff_t, int);
1786 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
1787 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
1788 ssize_t (*read_iter) (struct kiocb *, struct iov_iter *);
1789 ssize_t (*write_iter) (struct kiocb *, struct iov_iter *);
1790 int (*iterate) (struct file *, struct dir_context *);
1791 int (*iterate_shared) (struct file *, struct dir_context *);
1792 __poll_t (*poll) (struct file *, struct poll_table_struct *);
1793 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
1794 long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
1795 int (*mmap) (struct file *, struct vm_area_struct *);
1796 unsigned long mmap_supported_flags;
1797 int (*open) (struct inode *, struct file *);
1798 int (*flush) (struct file *, fl_owner_t id);
1799 int (*release) (struct inode *, struct file *);
1800 int (*fsync) (struct file *, loff_t, loff_t, int datasync);
1801 int (*fasync) (int, struct file *, int);
1802 int (*lock) (struct file *, int, struct file_lock *);
1803 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
1804 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
1805 int (*check_flags)(int);
1806 int (*flock) (struct file *, int, struct file_lock *);
1807 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
1808 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
1809 int (*setlease)(struct file *, long, struct file_lock **, void **);
1810 long (*fallocate)(struct file *file, int mode, loff_t offset,
1811 loff_t len);
1812 void (*show_fdinfo)(struct seq_file *m, struct file *f);
1813#ifndef CONFIG_MMU
1814 unsigned (*mmap_capabilities)(struct file *);
1815#endif
1816 ssize_t (*copy_file_range)(struct file *, loff_t, struct file *,
1817 loff_t, size_t, unsigned int);
1818 loff_t (*remap_file_range)(struct file *file_in, loff_t pos_in,
1819 struct file *file_out, loff_t pos_out,
1820 loff_t len, unsigned int remap_flags);
1821 int (*fadvise)(struct file *, loff_t, loff_t, int);
1822} __randomize_layout;
1823
1824struct inode_operations {
1825 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
1826 const char * (*get_link) (struct dentry *, struct inode *, struct delayed_call *);
1827 int (*permission) (struct inode *, int);
1828 struct posix_acl * (*get_acl)(struct inode *, int);
1829
1830 int (*readlink) (struct dentry *, char __user *,int);
1831
1832 int (*create) (struct inode *,struct dentry *, umode_t, bool);
1833 int (*link) (struct dentry *,struct inode *,struct dentry *);
1834 int (*unlink) (struct inode *,struct dentry *);
1835 int (*symlink) (struct inode *,struct dentry *,const char *);
1836 int (*mkdir) (struct inode *,struct dentry *,umode_t);
1837 int (*rmdir) (struct inode *,struct dentry *);
1838 int (*mknod) (struct inode *,struct dentry *,umode_t,dev_t);
1839 int (*rename) (struct inode *, struct dentry *,
1840 struct inode *, struct dentry *, unsigned int);
1841 int (*setattr) (struct dentry *, struct iattr *);
1842 int (*getattr) (const struct path *, struct kstat *, u32, unsigned int);
1843 ssize_t (*listxattr) (struct dentry *, char *, size_t);
1844 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
1845 u64 len);
1846 int (*update_time)(struct inode *, struct timespec64 *, int);
1847 int (*atomic_open)(struct inode *, struct dentry *,
1848 struct file *, unsigned open_flag,
1849 umode_t create_mode);
1850 int (*tmpfile) (struct inode *, struct dentry *, umode_t);
1851 int (*set_acl)(struct inode *, struct posix_acl *, int);
1852} ____cacheline_aligned;
1853
1854static inline ssize_t call_read_iter(struct file *file, struct kiocb *kio,
1855 struct iov_iter *iter)
1856{
1857 return file->f_op->read_iter(kio, iter);
1858}
1859
1860static inline ssize_t call_write_iter(struct file *file, struct kiocb *kio,
1861 struct iov_iter *iter)
1862{
1863 return file->f_op->write_iter(kio, iter);
1864}
1865
1866static inline int call_mmap(struct file *file, struct vm_area_struct *vma)
1867{
1868 return file->f_op->mmap(file, vma);
1869}
1870
1871ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
1872 unsigned long nr_segs, unsigned long fast_segs,
1873 struct iovec *fast_pointer,
1874 struct iovec **ret_pointer);
1875
1876extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
1877extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
1878extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
1879extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
1880 unsigned long, loff_t *, rwf_t);
1881extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *,
1882 loff_t, size_t, unsigned int);
1883extern int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
1884 struct file *file_out, loff_t pos_out,
1885 loff_t *count,
1886 unsigned int remap_flags);
1887extern loff_t do_clone_file_range(struct file *file_in, loff_t pos_in,
1888 struct file *file_out, loff_t pos_out,
1889 loff_t len, unsigned int remap_flags);
1890extern loff_t vfs_clone_file_range(struct file *file_in, loff_t pos_in,
1891 struct file *file_out, loff_t pos_out,
1892 loff_t len, unsigned int remap_flags);
1893extern int vfs_dedupe_file_range(struct file *file,
1894 struct file_dedupe_range *same);
1895extern loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos,
1896 struct file *dst_file, loff_t dst_pos,
1897 loff_t len, unsigned int remap_flags);
1898
1899
1900struct super_operations {
1901 struct inode *(*alloc_inode)(struct super_block *sb);
1902 void (*destroy_inode)(struct inode *);
1903
1904 void (*dirty_inode) (struct inode *, int flags);
1905 int (*write_inode) (struct inode *, struct writeback_control *wbc);
1906 int (*drop_inode) (struct inode *);
1907 void (*evict_inode) (struct inode *);
1908 void (*put_super) (struct super_block *);
1909 int (*sync_fs)(struct super_block *sb, int wait);
1910 int (*freeze_super) (struct super_block *);
1911 int (*freeze_fs) (struct super_block *);
1912 int (*thaw_super) (struct super_block *);
1913 int (*unfreeze_fs) (struct super_block *);
1914 int (*statfs) (struct dentry *, struct kstatfs *);
1915 int (*remount_fs) (struct super_block *, int *, char *);
1916 void (*umount_begin) (struct super_block *);
1917
1918 int (*show_options)(struct seq_file *, struct dentry *);
1919 int (*show_devname)(struct seq_file *, struct dentry *);
1920 int (*show_path)(struct seq_file *, struct dentry *);
1921 int (*show_stats)(struct seq_file *, struct dentry *);
1922#ifdef CONFIG_QUOTA
1923 ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
1924 ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
1925 struct dquot **(*get_dquots)(struct inode *);
1926#endif
1927 int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
1928 long (*nr_cached_objects)(struct super_block *,
1929 struct shrink_control *);
1930 long (*free_cached_objects)(struct super_block *,
1931 struct shrink_control *);
1932};
1933
1934
1935
1936
1937#define S_SYNC 1
1938#define S_NOATIME 2
1939#define S_APPEND 4
1940#define S_IMMUTABLE 8
1941#define S_DEAD 16
1942#define S_NOQUOTA 32
1943#define S_DIRSYNC 64
1944#define S_NOCMTIME 128
1945#define S_SWAPFILE 256
1946#define S_PRIVATE 512
1947#define S_IMA 1024
1948#define S_AUTOMOUNT 2048
1949#define S_NOSEC 4096
1950#ifdef CONFIG_FS_DAX
1951#define S_DAX 8192
1952#else
1953#define S_DAX 0
1954#endif
1955#define S_ENCRYPTED 16384
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970#define __IS_FLG(inode, flg) ((inode)->i_sb->s_flags & (flg))
1971
1972static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags & SB_RDONLY; }
1973#define IS_RDONLY(inode) sb_rdonly((inode)->i_sb)
1974#define IS_SYNC(inode) (__IS_FLG(inode, SB_SYNCHRONOUS) || \
1975 ((inode)->i_flags & S_SYNC))
1976#define IS_DIRSYNC(inode) (__IS_FLG(inode, SB_SYNCHRONOUS|SB_DIRSYNC) || \
1977 ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
1978#define IS_MANDLOCK(inode) __IS_FLG(inode, SB_MANDLOCK)
1979#define IS_NOATIME(inode) __IS_FLG(inode, SB_RDONLY|SB_NOATIME)
1980#define IS_I_VERSION(inode) __IS_FLG(inode, SB_I_VERSION)
1981
1982#define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
1983#define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
1984#define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
1985#define IS_POSIXACL(inode) __IS_FLG(inode, SB_POSIXACL)
1986
1987#define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
1988#define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME)
1989#define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE)
1990#define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE)
1991#define IS_IMA(inode) ((inode)->i_flags & S_IMA)
1992#define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT)
1993#define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC)
1994#define IS_DAX(inode) ((inode)->i_flags & S_DAX)
1995#define IS_ENCRYPTED(inode) ((inode)->i_flags & S_ENCRYPTED)
1996
1997#define IS_WHITEOUT(inode) (S_ISCHR(inode->i_mode) && \
1998 (inode)->i_rdev == WHITEOUT_DEV)
1999
2000static inline bool HAS_UNMAPPED_ID(struct inode *inode)
2001{
2002 return !uid_valid(inode->i_uid) || !gid_valid(inode->i_gid);
2003}
2004
2005static inline enum rw_hint file_write_hint(struct file *file)
2006{
2007 if (file->f_write_hint != WRITE_LIFE_NOT_SET)
2008 return file->f_write_hint;
2009
2010 return file_inode(file)->i_write_hint;
2011}
2012
2013static inline int iocb_flags(struct file *file);
2014
2015static inline u16 ki_hint_validate(enum rw_hint hint)
2016{
2017 typeof(((struct kiocb *)0)->ki_hint) max_hint = -1;
2018
2019 if (hint <= max_hint)
2020 return hint;
2021 return 0;
2022}
2023
2024static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
2025{
2026 *kiocb = (struct kiocb) {
2027 .ki_filp = filp,
2028 .ki_flags = iocb_flags(filp),
2029 .ki_hint = ki_hint_validate(file_write_hint(filp)),
2030 .ki_ioprio = get_current_ioprio(),
2031 };
2032}
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097#define I_DIRTY_SYNC (1 << 0)
2098#define I_DIRTY_DATASYNC (1 << 1)
2099#define I_DIRTY_PAGES (1 << 2)
2100#define __I_NEW 3
2101#define I_NEW (1 << __I_NEW)
2102#define I_WILL_FREE (1 << 4)
2103#define I_FREEING (1 << 5)
2104#define I_CLEAR (1 << 6)
2105#define __I_SYNC 7
2106#define I_SYNC (1 << __I_SYNC)
2107#define I_REFERENCED (1 << 8)
2108#define __I_DIO_WAKEUP 9
2109#define I_DIO_WAKEUP (1 << __I_DIO_WAKEUP)
2110#define I_LINKABLE (1 << 10)
2111#define I_DIRTY_TIME (1 << 11)
2112#define __I_DIRTY_TIME_EXPIRED 12
2113#define I_DIRTY_TIME_EXPIRED (1 << __I_DIRTY_TIME_EXPIRED)
2114#define I_WB_SWITCH (1 << 13)
2115#define I_OVL_INUSE (1 << 14)
2116#define I_CREATING (1 << 15)
2117
2118#define I_DIRTY_INODE (I_DIRTY_SYNC | I_DIRTY_DATASYNC)
2119#define I_DIRTY (I_DIRTY_INODE | I_DIRTY_PAGES)
2120#define I_DIRTY_ALL (I_DIRTY | I_DIRTY_TIME)
2121
2122extern void __mark_inode_dirty(struct inode *, int);
2123static inline void mark_inode_dirty(struct inode *inode)
2124{
2125 __mark_inode_dirty(inode, I_DIRTY);
2126}
2127
2128static inline void mark_inode_dirty_sync(struct inode *inode)
2129{
2130 __mark_inode_dirty(inode, I_DIRTY_SYNC);
2131}
2132
2133extern void inc_nlink(struct inode *inode);
2134extern void drop_nlink(struct inode *inode);
2135extern void clear_nlink(struct inode *inode);
2136extern void set_nlink(struct inode *inode, unsigned int nlink);
2137
2138static inline void inode_inc_link_count(struct inode *inode)
2139{
2140 inc_nlink(inode);
2141 mark_inode_dirty(inode);
2142}
2143
2144static inline void inode_dec_link_count(struct inode *inode)
2145{
2146 drop_nlink(inode);
2147 mark_inode_dirty(inode);
2148}
2149
2150enum file_time_flags {
2151 S_ATIME = 1,
2152 S_MTIME = 2,
2153 S_CTIME = 4,
2154 S_VERSION = 8,
2155};
2156
2157extern bool atime_needs_update(const struct path *, struct inode *);
2158extern void touch_atime(const struct path *);
2159static inline void file_accessed(struct file *file)
2160{
2161 if (!(file->f_flags & O_NOATIME))
2162 touch_atime(&file->f_path);
2163}
2164
2165int sync_inode(struct inode *inode, struct writeback_control *wbc);
2166int sync_inode_metadata(struct inode *inode, int wait);
2167
2168struct file_system_type {
2169 const char *name;
2170 int fs_flags;
2171#define FS_REQUIRES_DEV 1
2172#define FS_BINARY_MOUNTDATA 2
2173#define FS_HAS_SUBTYPE 4
2174#define FS_USERNS_MOUNT 8
2175#define FS_RENAME_DOES_D_MOVE 32768
2176 struct dentry *(*mount) (struct file_system_type *, int,
2177 const char *, void *);
2178 void (*kill_sb) (struct super_block *);
2179 struct module *owner;
2180 struct file_system_type * next;
2181 struct hlist_head fs_supers;
2182
2183 struct lock_class_key s_lock_key;
2184 struct lock_class_key s_umount_key;
2185 struct lock_class_key s_vfs_rename_key;
2186 struct lock_class_key s_writers_key[SB_FREEZE_LEVELS];
2187
2188 struct lock_class_key i_lock_key;
2189 struct lock_class_key i_mutex_key;
2190 struct lock_class_key i_mutex_dir_key;
2191};
2192
2193#define MODULE_ALIAS_FS(NAME) MODULE_ALIAS("fs-" NAME)
2194
2195extern struct dentry *mount_ns(struct file_system_type *fs_type,
2196 int flags, void *data, void *ns, struct user_namespace *user_ns,
2197 int (*fill_super)(struct super_block *, void *, int));
2198#ifdef CONFIG_BLOCK
2199extern struct dentry *mount_bdev(struct file_system_type *fs_type,
2200 int flags, const char *dev_name, void *data,
2201 int (*fill_super)(struct super_block *, void *, int));
2202#else
2203static inline struct dentry *mount_bdev(struct file_system_type *fs_type,
2204 int flags, const char *dev_name, void *data,
2205 int (*fill_super)(struct super_block *, void *, int))
2206{
2207 return ERR_PTR(-ENODEV);
2208}
2209#endif
2210extern struct dentry *mount_single(struct file_system_type *fs_type,
2211 int flags, void *data,
2212 int (*fill_super)(struct super_block *, void *, int));
2213extern struct dentry *mount_nodev(struct file_system_type *fs_type,
2214 int flags, void *data,
2215 int (*fill_super)(struct super_block *, void *, int));
2216extern struct dentry *mount_subtree(struct vfsmount *mnt, const char *path);
2217void generic_shutdown_super(struct super_block *sb);
2218#ifdef CONFIG_BLOCK
2219void kill_block_super(struct super_block *sb);
2220#else
2221static inline void kill_block_super(struct super_block *sb)
2222{
2223 BUG();
2224}
2225#endif
2226void kill_anon_super(struct super_block *sb);
2227void kill_litter_super(struct super_block *sb);
2228void deactivate_super(struct super_block *sb);
2229void deactivate_locked_super(struct super_block *sb);
2230int set_anon_super(struct super_block *s, void *data);
2231int get_anon_bdev(dev_t *);
2232void free_anon_bdev(dev_t);
2233struct super_block *sget_userns(struct file_system_type *type,
2234 int (*test)(struct super_block *,void *),
2235 int (*set)(struct super_block *,void *),
2236 int flags, struct user_namespace *user_ns,
2237 void *data);
2238struct super_block *sget(struct file_system_type *type,
2239 int (*test)(struct super_block *,void *),
2240 int (*set)(struct super_block *,void *),
2241 int flags, void *data);
2242extern struct dentry *mount_pseudo_xattr(struct file_system_type *, char *,
2243 const struct super_operations *ops,
2244 const struct xattr_handler **xattr,
2245 const struct dentry_operations *dops,
2246 unsigned long);
2247
2248static inline struct dentry *
2249mount_pseudo(struct file_system_type *fs_type, char *name,
2250 const struct super_operations *ops,
2251 const struct dentry_operations *dops, unsigned long magic)
2252{
2253 return mount_pseudo_xattr(fs_type, name, ops, NULL, dops, magic);
2254}
2255
2256
2257#define fops_get(fops) \
2258 (((fops) && try_module_get((fops)->owner) ? (fops) : NULL))
2259#define fops_put(fops) \
2260 do { if (fops) module_put((fops)->owner); } while(0)
2261
2262
2263
2264
2265
2266#define replace_fops(f, fops) \
2267 do { \
2268 struct file *__file = (f); \
2269 fops_put(__file->f_op); \
2270 BUG_ON(!(__file->f_op = (fops))); \
2271 } while(0)
2272
2273extern int register_filesystem(struct file_system_type *);
2274extern int unregister_filesystem(struct file_system_type *);
2275extern struct vfsmount *kern_mount_data(struct file_system_type *, void *data);
2276#define kern_mount(type) kern_mount_data(type, NULL)
2277extern void kern_unmount(struct vfsmount *mnt);
2278extern int may_umount_tree(struct vfsmount *);
2279extern int may_umount(struct vfsmount *);
2280extern long do_mount(const char *, const char __user *,
2281 const char *, unsigned long, void *);
2282extern struct vfsmount *collect_mounts(const struct path *);
2283extern void drop_collected_mounts(struct vfsmount *);
2284extern int iterate_mounts(int (*)(struct vfsmount *, void *), void *,
2285 struct vfsmount *);
2286extern int vfs_statfs(const struct path *, struct kstatfs *);
2287extern int user_statfs(const char __user *, struct kstatfs *);
2288extern int fd_statfs(int, struct kstatfs *);
2289extern int freeze_super(struct super_block *super);
2290extern int thaw_super(struct super_block *super);
2291extern bool our_mnt(struct vfsmount *mnt);
2292extern __printf(2, 3)
2293int super_setup_bdi_name(struct super_block *sb, char *fmt, ...);
2294extern int super_setup_bdi(struct super_block *sb);
2295
2296extern int current_umask(void);
2297
2298extern void ihold(struct inode * inode);
2299extern void iput(struct inode *);
2300extern int generic_update_time(struct inode *, struct timespec64 *, int);
2301
2302
2303extern struct kobject *fs_kobj;
2304
2305#define MAX_RW_COUNT (INT_MAX & PAGE_MASK)
2306
2307#ifdef CONFIG_MANDATORY_FILE_LOCKING
2308extern int locks_mandatory_locked(struct file *);
2309extern int locks_mandatory_area(struct inode *, struct file *, loff_t, loff_t, unsigned char);
2310
2311
2312
2313
2314
2315
2316static inline int __mandatory_lock(struct inode *ino)
2317{
2318 return (ino->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID;
2319}
2320
2321
2322
2323
2324
2325
2326static inline int mandatory_lock(struct inode *ino)
2327{
2328 return IS_MANDLOCK(ino) && __mandatory_lock(ino);
2329}
2330
2331static inline int locks_verify_locked(struct file *file)
2332{
2333 if (mandatory_lock(locks_inode(file)))
2334 return locks_mandatory_locked(file);
2335 return 0;
2336}
2337
2338static inline int locks_verify_truncate(struct inode *inode,
2339 struct file *f,
2340 loff_t size)
2341{
2342 if (!inode->i_flctx || !mandatory_lock(inode))
2343 return 0;
2344
2345 if (size < inode->i_size) {
2346 return locks_mandatory_area(inode, f, size, inode->i_size - 1,
2347 F_WRLCK);
2348 } else {
2349 return locks_mandatory_area(inode, f, inode->i_size, size - 1,
2350 F_WRLCK);
2351 }
2352}
2353
2354#else
2355
2356static inline int locks_mandatory_locked(struct file *file)
2357{
2358 return 0;
2359}
2360
2361static inline int locks_mandatory_area(struct inode *inode, struct file *filp,
2362 loff_t start, loff_t end, unsigned char type)
2363{
2364 return 0;
2365}
2366
2367static inline int __mandatory_lock(struct inode *inode)
2368{
2369 return 0;
2370}
2371
2372static inline int mandatory_lock(struct inode *inode)
2373{
2374 return 0;
2375}
2376
2377static inline int locks_verify_locked(struct file *file)
2378{
2379 return 0;
2380}
2381
2382static inline int locks_verify_truncate(struct inode *inode, struct file *filp,
2383 size_t size)
2384{
2385 return 0;
2386}
2387
2388#endif
2389
2390
2391#ifdef CONFIG_FILE_LOCKING
2392static inline int break_lease(struct inode *inode, unsigned int mode)
2393{
2394
2395
2396
2397
2398
2399
2400 smp_mb();
2401 if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease))
2402 return __break_lease(inode, mode, FL_LEASE);
2403 return 0;
2404}
2405
2406static inline int break_deleg(struct inode *inode, unsigned int mode)
2407{
2408
2409
2410
2411
2412
2413
2414 smp_mb();
2415 if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease))
2416 return __break_lease(inode, mode, FL_DELEG);
2417 return 0;
2418}
2419
2420static inline int try_break_deleg(struct inode *inode, struct inode **delegated_inode)
2421{
2422 int ret;
2423
2424 ret = break_deleg(inode, O_WRONLY|O_NONBLOCK);
2425 if (ret == -EWOULDBLOCK && delegated_inode) {
2426 *delegated_inode = inode;
2427 ihold(inode);
2428 }
2429 return ret;
2430}
2431
2432static inline int break_deleg_wait(struct inode **delegated_inode)
2433{
2434 int ret;
2435
2436 ret = break_deleg(*delegated_inode, O_WRONLY);
2437 iput(*delegated_inode);
2438 *delegated_inode = NULL;
2439 return ret;
2440}
2441
2442static inline int break_layout(struct inode *inode, bool wait)
2443{
2444 smp_mb();
2445 if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease))
2446 return __break_lease(inode,
2447 wait ? O_WRONLY : O_WRONLY | O_NONBLOCK,
2448 FL_LAYOUT);
2449 return 0;
2450}
2451
2452#else
2453static inline int break_lease(struct inode *inode, unsigned int mode)
2454{
2455 return 0;
2456}
2457
2458static inline int break_deleg(struct inode *inode, unsigned int mode)
2459{
2460 return 0;
2461}
2462
2463static inline int try_break_deleg(struct inode *inode, struct inode **delegated_inode)
2464{
2465 return 0;
2466}
2467
2468static inline int break_deleg_wait(struct inode **delegated_inode)
2469{
2470 BUG();
2471 return 0;
2472}
2473
2474static inline int break_layout(struct inode *inode, bool wait)
2475{
2476 return 0;
2477}
2478
2479#endif
2480
2481
2482struct audit_names;
2483struct filename {
2484 const char *name;
2485 const __user char *uptr;
2486 int refcnt;
2487 struct audit_names *aname;
2488 const char iname[];
2489};
2490
2491extern long vfs_truncate(const struct path *, loff_t);
2492extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs,
2493 struct file *filp);
2494extern int vfs_fallocate(struct file *file, int mode, loff_t offset,
2495 loff_t len);
2496extern long do_sys_open(int dfd, const char __user *filename, int flags,
2497 umode_t mode);
2498extern struct file *file_open_name(struct filename *, int, umode_t);
2499extern struct file *filp_open(const char *, int, umode_t);
2500extern struct file *file_open_root(struct dentry *, struct vfsmount *,
2501 const char *, int, umode_t);
2502extern struct file * dentry_open(const struct path *, int, const struct cred *);
2503extern struct file * open_with_fake_path(const struct path *, int,
2504 struct inode*, const struct cred *);
2505static inline struct file *file_clone_open(struct file *file)
2506{
2507 return dentry_open(&file->f_path, file->f_flags, file->f_cred);
2508}
2509extern int filp_close(struct file *, fl_owner_t id);
2510
2511extern struct filename *getname_flags(const char __user *, int, int *);
2512extern struct filename *getname(const char __user *);
2513extern struct filename *getname_kernel(const char *);
2514extern void putname(struct filename *name);
2515
2516extern int finish_open(struct file *file, struct dentry *dentry,
2517 int (*open)(struct inode *, struct file *));
2518extern int finish_no_open(struct file *file, struct dentry *dentry);
2519
2520
2521
2522extern int ioctl_preallocate(struct file *filp, void __user *argp);
2523
2524
2525extern void __init vfs_caches_init_early(void);
2526extern void __init vfs_caches_init(void);
2527
2528extern struct kmem_cache *names_cachep;
2529
2530#define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL)
2531#define __putname(name) kmem_cache_free(names_cachep, (void *)(name))
2532
2533#ifdef CONFIG_BLOCK
2534extern int register_blkdev(unsigned int, const char *);
2535extern void unregister_blkdev(unsigned int, const char *);
2536extern void bdev_unhash_inode(dev_t dev);
2537extern struct block_device *bdget(dev_t);
2538extern struct block_device *bdgrab(struct block_device *bdev);
2539extern void bd_set_size(struct block_device *, loff_t size);
2540extern void bd_forget(struct inode *inode);
2541extern void bdput(struct block_device *);
2542extern void invalidate_bdev(struct block_device *);
2543extern void iterate_bdevs(void (*)(struct block_device *, void *), void *);
2544extern int sync_blockdev(struct block_device *bdev);
2545extern void kill_bdev(struct block_device *);
2546extern struct super_block *freeze_bdev(struct block_device *);
2547extern void emergency_thaw_all(void);
2548extern void emergency_thaw_bdev(struct super_block *sb);
2549extern int thaw_bdev(struct block_device *bdev, struct super_block *sb);
2550extern int fsync_bdev(struct block_device *);
2551
2552extern struct super_block *blockdev_superblock;
2553
2554static inline bool sb_is_blkdev_sb(struct super_block *sb)
2555{
2556 return sb == blockdev_superblock;
2557}
2558#else
2559static inline void bd_forget(struct inode *inode) {}
2560static inline int sync_blockdev(struct block_device *bdev) { return 0; }
2561static inline void kill_bdev(struct block_device *bdev) {}
2562static inline void invalidate_bdev(struct block_device *bdev) {}
2563
2564static inline struct super_block *freeze_bdev(struct block_device *sb)
2565{
2566 return NULL;
2567}
2568
2569static inline int thaw_bdev(struct block_device *bdev, struct super_block *sb)
2570{
2571 return 0;
2572}
2573
2574static inline int emergency_thaw_bdev(struct super_block *sb)
2575{
2576 return 0;
2577}
2578
2579static inline void iterate_bdevs(void (*f)(struct block_device *, void *), void *arg)
2580{
2581}
2582
2583static inline bool sb_is_blkdev_sb(struct super_block *sb)
2584{
2585 return false;
2586}
2587#endif
2588extern int sync_filesystem(struct super_block *);
2589extern const struct file_operations def_blk_fops;
2590extern const struct file_operations def_chr_fops;
2591#ifdef CONFIG_BLOCK
2592extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
2593extern int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long);
2594extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
2595extern int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder);
2596extern struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
2597 void *holder);
2598extern struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode,
2599 void *holder);
2600extern void blkdev_put(struct block_device *bdev, fmode_t mode);
2601extern int __blkdev_reread_part(struct block_device *bdev);
2602extern int blkdev_reread_part(struct block_device *bdev);
2603
2604#ifdef CONFIG_SYSFS
2605extern int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
2606extern void bd_unlink_disk_holder(struct block_device *bdev,
2607 struct gendisk *disk);
2608#else
2609static inline int bd_link_disk_holder(struct block_device *bdev,
2610 struct gendisk *disk)
2611{
2612 return 0;
2613}
2614static inline void bd_unlink_disk_holder(struct block_device *bdev,
2615 struct gendisk *disk)
2616{
2617}
2618#endif
2619#endif
2620
2621
2622#define CHRDEV_MAJOR_MAX 512
2623
2624#define CHRDEV_MAJOR_DYN_END 234
2625
2626#define CHRDEV_MAJOR_DYN_EXT_START 511
2627#define CHRDEV_MAJOR_DYN_EXT_END 384
2628
2629extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *);
2630extern int register_chrdev_region(dev_t, unsigned, const char *);
2631extern int __register_chrdev(unsigned int major, unsigned int baseminor,
2632 unsigned int count, const char *name,
2633 const struct file_operations *fops);
2634extern void __unregister_chrdev(unsigned int major, unsigned int baseminor,
2635 unsigned int count, const char *name);
2636extern void unregister_chrdev_region(dev_t, unsigned);
2637extern void chrdev_show(struct seq_file *,off_t);
2638
2639static inline int register_chrdev(unsigned int major, const char *name,
2640 const struct file_operations *fops)
2641{
2642 return __register_chrdev(major, 0, 256, name, fops);
2643}
2644
2645static inline void unregister_chrdev(unsigned int major, const char *name)
2646{
2647 __unregister_chrdev(major, 0, 256, name);
2648}
2649
2650
2651#define BDEVNAME_SIZE 32
2652#define BDEVT_SIZE 10
2653
2654#ifdef CONFIG_BLOCK
2655#define BLKDEV_MAJOR_MAX 512
2656extern const char *__bdevname(dev_t, char *buffer);
2657extern const char *bdevname(struct block_device *bdev, char *buffer);
2658extern struct block_device *lookup_bdev(const char *);
2659extern void blkdev_show(struct seq_file *,off_t);
2660
2661#else
2662#define BLKDEV_MAJOR_MAX 0
2663#endif
2664
2665extern void init_special_inode(struct inode *, umode_t, dev_t);
2666
2667
2668extern void make_bad_inode(struct inode *);
2669extern bool is_bad_inode(struct inode *);
2670
2671#ifdef CONFIG_BLOCK
2672extern void check_disk_size_change(struct gendisk *disk,
2673 struct block_device *bdev, bool verbose);
2674extern int revalidate_disk(struct gendisk *);
2675extern int check_disk_change(struct block_device *);
2676extern int __invalidate_device(struct block_device *, bool);
2677extern int invalidate_partition(struct gendisk *, int);
2678#endif
2679unsigned long invalidate_mapping_pages(struct address_space *mapping,
2680 pgoff_t start, pgoff_t end);
2681
2682static inline void invalidate_remote_inode(struct inode *inode)
2683{
2684 if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
2685 S_ISLNK(inode->i_mode))
2686 invalidate_mapping_pages(inode->i_mapping, 0, -1);
2687}
2688extern int invalidate_inode_pages2(struct address_space *mapping);
2689extern int invalidate_inode_pages2_range(struct address_space *mapping,
2690 pgoff_t start, pgoff_t end);
2691extern int write_inode_now(struct inode *, int);
2692extern int filemap_fdatawrite(struct address_space *);
2693extern int filemap_flush(struct address_space *);
2694extern int filemap_fdatawait_keep_errors(struct address_space *mapping);
2695extern int filemap_fdatawait_range(struct address_space *, loff_t lstart,
2696 loff_t lend);
2697
2698static inline int filemap_fdatawait(struct address_space *mapping)
2699{
2700 return filemap_fdatawait_range(mapping, 0, LLONG_MAX);
2701}
2702
2703extern bool filemap_range_has_page(struct address_space *, loff_t lstart,
2704 loff_t lend);
2705extern int filemap_write_and_wait(struct address_space *mapping);
2706extern int filemap_write_and_wait_range(struct address_space *mapping,
2707 loff_t lstart, loff_t lend);
2708extern int __filemap_fdatawrite_range(struct address_space *mapping,
2709 loff_t start, loff_t end, int sync_mode);
2710extern int filemap_fdatawrite_range(struct address_space *mapping,
2711 loff_t start, loff_t end);
2712extern int filemap_check_errors(struct address_space *mapping);
2713extern void __filemap_set_wb_err(struct address_space *mapping, int err);
2714
2715extern int __must_check file_fdatawait_range(struct file *file, loff_t lstart,
2716 loff_t lend);
2717extern int __must_check file_check_and_advance_wb_err(struct file *file);
2718extern int __must_check file_write_and_wait_range(struct file *file,
2719 loff_t start, loff_t end);
2720
2721static inline int file_write_and_wait(struct file *file)
2722{
2723 return file_write_and_wait_range(file, 0, LLONG_MAX);
2724}
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740static inline void filemap_set_wb_err(struct address_space *mapping, int err)
2741{
2742
2743 if (unlikely(err))
2744 __filemap_set_wb_err(mapping, err);
2745}
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757static inline int filemap_check_wb_err(struct address_space *mapping,
2758 errseq_t since)
2759{
2760 return errseq_check(&mapping->wb_err, since);
2761}
2762
2763
2764
2765
2766
2767
2768
2769
2770static inline errseq_t filemap_sample_wb_err(struct address_space *mapping)
2771{
2772 return errseq_sample(&mapping->wb_err);
2773}
2774
2775extern int vfs_fsync_range(struct file *file, loff_t start, loff_t end,
2776 int datasync);
2777extern int vfs_fsync(struct file *file, int datasync);
2778
2779
2780
2781
2782
2783
2784static inline ssize_t generic_write_sync(struct kiocb *iocb, ssize_t count)
2785{
2786 if (iocb->ki_flags & IOCB_DSYNC) {
2787 int ret = vfs_fsync_range(iocb->ki_filp,
2788 iocb->ki_pos - count, iocb->ki_pos - 1,
2789 (iocb->ki_flags & IOCB_SYNC) ? 0 : 1);
2790 if (ret)
2791 return ret;
2792 }
2793
2794 return count;
2795}
2796
2797extern void emergency_sync(void);
2798extern void emergency_remount(void);
2799#ifdef CONFIG_BLOCK
2800extern sector_t bmap(struct inode *, sector_t);
2801#endif
2802extern int notify_change(struct dentry *, struct iattr *, struct inode **);
2803extern int inode_permission(struct inode *, int);
2804extern int generic_permission(struct inode *, int);
2805extern int __check_sticky(struct inode *dir, struct inode *inode);
2806
2807static inline bool execute_ok(struct inode *inode)
2808{
2809 return (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode);
2810}
2811
2812static inline void file_start_write(struct file *file)
2813{
2814 if (!S_ISREG(file_inode(file)->i_mode))
2815 return;
2816 __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, true);
2817}
2818
2819static inline bool file_start_write_trylock(struct file *file)
2820{
2821 if (!S_ISREG(file_inode(file)->i_mode))
2822 return true;
2823 return __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, false);
2824}
2825
2826static inline void file_end_write(struct file *file)
2827{
2828 if (!S_ISREG(file_inode(file)->i_mode))
2829 return;
2830 __sb_end_write(file_inode(file)->i_sb, SB_FREEZE_WRITE);
2831}
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849static inline int get_write_access(struct inode *inode)
2850{
2851 return atomic_inc_unless_negative(&inode->i_writecount) ? 0 : -ETXTBSY;
2852}
2853static inline int deny_write_access(struct file *file)
2854{
2855 struct inode *inode = file_inode(file);
2856 return atomic_dec_unless_positive(&inode->i_writecount) ? 0 : -ETXTBSY;
2857}
2858static inline void put_write_access(struct inode * inode)
2859{
2860 atomic_dec(&inode->i_writecount);
2861}
2862static inline void allow_write_access(struct file *file)
2863{
2864 if (file)
2865 atomic_inc(&file_inode(file)->i_writecount);
2866}
2867static inline bool inode_is_open_for_write(const struct inode *inode)
2868{
2869 return atomic_read(&inode->i_writecount) > 0;
2870}
2871
2872#ifdef CONFIG_IMA
2873static inline void i_readcount_dec(struct inode *inode)
2874{
2875 BUG_ON(!atomic_read(&inode->i_readcount));
2876 atomic_dec(&inode->i_readcount);
2877}
2878static inline void i_readcount_inc(struct inode *inode)
2879{
2880 atomic_inc(&inode->i_readcount);
2881}
2882#else
2883static inline void i_readcount_dec(struct inode *inode)
2884{
2885 return;
2886}
2887static inline void i_readcount_inc(struct inode *inode)
2888{
2889 return;
2890}
2891#endif
2892extern int do_pipe_flags(int *, int);
2893
2894#define __kernel_read_file_id(id) \
2895 id(UNKNOWN, unknown) \
2896 id(FIRMWARE, firmware) \
2897 id(FIRMWARE_PREALLOC_BUFFER, firmware) \
2898 id(MODULE, kernel-module) \
2899 id(KEXEC_IMAGE, kexec-image) \
2900 id(KEXEC_INITRAMFS, kexec-initramfs) \
2901 id(POLICY, security-policy) \
2902 id(X509_CERTIFICATE, x509-certificate) \
2903 id(MAX_ID, )
2904
2905#define __fid_enumify(ENUM, dummy) READING_ ## ENUM,
2906#define __fid_stringify(dummy, str) #str,
2907
2908enum kernel_read_file_id {
2909 __kernel_read_file_id(__fid_enumify)
2910};
2911
2912static const char * const kernel_read_file_str[] = {
2913 __kernel_read_file_id(__fid_stringify)
2914};
2915
2916static inline const char *kernel_read_file_id_str(enum kernel_read_file_id id)
2917{
2918 if ((unsigned)id >= READING_MAX_ID)
2919 return kernel_read_file_str[READING_UNKNOWN];
2920
2921 return kernel_read_file_str[id];
2922}
2923
2924extern int kernel_read_file(struct file *, void **, loff_t *, loff_t,
2925 enum kernel_read_file_id);
2926extern int kernel_read_file_from_path(const char *, void **, loff_t *, loff_t,
2927 enum kernel_read_file_id);
2928extern int kernel_read_file_from_fd(int, void **, loff_t *, loff_t,
2929 enum kernel_read_file_id);
2930extern ssize_t kernel_read(struct file *, void *, size_t, loff_t *);
2931extern ssize_t kernel_write(struct file *, const void *, size_t, loff_t *);
2932extern ssize_t __kernel_write(struct file *, const void *, size_t, loff_t *);
2933extern struct file * open_exec(const char *);
2934
2935
2936extern bool is_subdir(struct dentry *, struct dentry *);
2937extern bool path_is_under(const struct path *, const struct path *);
2938
2939extern char *file_path(struct file *, char *, int);
2940
2941#include <linux/err.h>
2942
2943
2944extern loff_t default_llseek(struct file *file, loff_t offset, int whence);
2945
2946extern loff_t vfs_llseek(struct file *file, loff_t offset, int whence);
2947
2948extern int inode_init_always(struct super_block *, struct inode *);
2949extern void inode_init_once(struct inode *);
2950extern void address_space_init_once(struct address_space *mapping);
2951extern struct inode * igrab(struct inode *);
2952extern ino_t iunique(struct super_block *, ino_t);
2953extern int inode_needs_sync(struct inode *inode);
2954extern int generic_delete_inode(struct inode *inode);
2955static inline int generic_drop_inode(struct inode *inode)
2956{
2957 return !inode->i_nlink || inode_unhashed(inode);
2958}
2959
2960extern struct inode *ilookup5_nowait(struct super_block *sb,
2961 unsigned long hashval, int (*test)(struct inode *, void *),
2962 void *data);
2963extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
2964 int (*test)(struct inode *, void *), void *data);
2965extern struct inode *ilookup(struct super_block *sb, unsigned long ino);
2966
2967extern struct inode *inode_insert5(struct inode *inode, unsigned long hashval,
2968 int (*test)(struct inode *, void *),
2969 int (*set)(struct inode *, void *),
2970 void *data);
2971extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *);
2972extern struct inode * iget_locked(struct super_block *, unsigned long);
2973extern struct inode *find_inode_nowait(struct super_block *,
2974 unsigned long,
2975 int (*match)(struct inode *,
2976 unsigned long, void *),
2977 void *data);
2978extern int insert_inode_locked4(struct inode *, unsigned long, int (*test)(struct inode *, void *), void *);
2979extern int insert_inode_locked(struct inode *);
2980#ifdef CONFIG_DEBUG_LOCK_ALLOC
2981extern void lockdep_annotate_inode_mutex_key(struct inode *inode);
2982#else
2983static inline void lockdep_annotate_inode_mutex_key(struct inode *inode) { };
2984#endif
2985extern void unlock_new_inode(struct inode *);
2986extern void discard_new_inode(struct inode *);
2987extern unsigned int get_next_ino(void);
2988extern void evict_inodes(struct super_block *sb);
2989
2990extern void __iget(struct inode * inode);
2991extern void iget_failed(struct inode *);
2992extern void clear_inode(struct inode *);
2993extern void __destroy_inode(struct inode *);
2994extern struct inode *new_inode_pseudo(struct super_block *sb);
2995extern struct inode *new_inode(struct super_block *sb);
2996extern void free_inode_nonrcu(struct inode *inode);
2997extern int should_remove_suid(struct dentry *);
2998extern int file_remove_privs(struct file *);
2999
3000extern void __insert_inode_hash(struct inode *, unsigned long hashval);
3001static inline void insert_inode_hash(struct inode *inode)
3002{
3003 __insert_inode_hash(inode, inode->i_ino);
3004}
3005
3006extern void __remove_inode_hash(struct inode *);
3007static inline void remove_inode_hash(struct inode *inode)
3008{
3009 if (!inode_unhashed(inode) && !hlist_fake(&inode->i_hash))
3010 __remove_inode_hash(inode);
3011}
3012
3013extern void inode_sb_list_add(struct inode *inode);
3014
3015#ifdef CONFIG_BLOCK
3016extern int bdev_read_only(struct block_device *);
3017#endif
3018extern int set_blocksize(struct block_device *, int);
3019extern int sb_set_blocksize(struct super_block *, int);
3020extern int sb_min_blocksize(struct super_block *, int);
3021
3022extern int generic_file_mmap(struct file *, struct vm_area_struct *);
3023extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
3024extern ssize_t generic_write_checks(struct kiocb *, struct iov_iter *);
3025extern int generic_remap_checks(struct file *file_in, loff_t pos_in,
3026 struct file *file_out, loff_t pos_out,
3027 loff_t *count, unsigned int remap_flags);
3028extern ssize_t generic_file_read_iter(struct kiocb *, struct iov_iter *);
3029extern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *);
3030extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *);
3031extern ssize_t generic_file_direct_write(struct kiocb *, struct iov_iter *);
3032extern ssize_t generic_perform_write(struct file *, struct iov_iter *, loff_t);
3033
3034ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos,
3035 rwf_t flags);
3036ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos,
3037 rwf_t flags);
3038
3039
3040extern ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to);
3041extern ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from);
3042extern int blkdev_fsync(struct file *filp, loff_t start, loff_t end,
3043 int datasync);
3044extern void block_sync_page(struct page *page);
3045
3046
3047extern ssize_t generic_file_splice_read(struct file *, loff_t *,
3048 struct pipe_inode_info *, size_t, unsigned int);
3049extern ssize_t iter_file_splice_write(struct pipe_inode_info *,
3050 struct file *, loff_t *, size_t, unsigned int);
3051extern ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe,
3052 struct file *out, loff_t *, size_t len, unsigned int flags);
3053extern long do_splice_direct(struct file *in, loff_t *ppos, struct file *out,
3054 loff_t *opos, size_t len, unsigned int flags);
3055
3056
3057extern void
3058file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping);
3059extern loff_t noop_llseek(struct file *file, loff_t offset, int whence);
3060extern loff_t no_llseek(struct file *file, loff_t offset, int whence);
3061extern loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize);
3062extern loff_t generic_file_llseek(struct file *file, loff_t offset, int whence);
3063extern loff_t generic_file_llseek_size(struct file *file, loff_t offset,
3064 int whence, loff_t maxsize, loff_t eof);
3065extern loff_t fixed_size_llseek(struct file *file, loff_t offset,
3066 int whence, loff_t size);
3067extern loff_t no_seek_end_llseek_size(struct file *, loff_t, int, loff_t);
3068extern loff_t no_seek_end_llseek(struct file *, loff_t, int);
3069extern int generic_file_open(struct inode * inode, struct file * filp);
3070extern int nonseekable_open(struct inode * inode, struct file * filp);
3071
3072#ifdef CONFIG_BLOCK
3073typedef void (dio_submit_t)(struct bio *bio, struct inode *inode,
3074 loff_t file_offset);
3075
3076enum {
3077
3078 DIO_LOCKING = 0x01,
3079
3080
3081 DIO_SKIP_HOLES = 0x02,
3082};
3083
3084void dio_end_io(struct bio *bio);
3085void dio_warn_stale_pagecache(struct file *filp);
3086
3087ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
3088 struct block_device *bdev, struct iov_iter *iter,
3089 get_block_t get_block,
3090 dio_iodone_t end_io, dio_submit_t submit_io,
3091 int flags);
3092
3093static inline ssize_t blockdev_direct_IO(struct kiocb *iocb,
3094 struct inode *inode,
3095 struct iov_iter *iter,
3096 get_block_t get_block)
3097{
3098 return __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, iter,
3099 get_block, NULL, NULL, DIO_LOCKING | DIO_SKIP_HOLES);
3100}
3101#endif
3102
3103void inode_dio_wait(struct inode *inode);
3104
3105
3106
3107
3108
3109
3110
3111
3112static inline void inode_dio_begin(struct inode *inode)
3113{
3114 atomic_inc(&inode->i_dio_count);
3115}
3116
3117
3118
3119
3120
3121
3122
3123
3124static inline void inode_dio_end(struct inode *inode)
3125{
3126 if (atomic_dec_and_test(&inode->i_dio_count))
3127 wake_up_bit(&inode->i_state, __I_DIO_WAKEUP);
3128}
3129
3130extern void inode_set_flags(struct inode *inode, unsigned int flags,
3131 unsigned int mask);
3132
3133extern const struct file_operations generic_ro_fops;
3134
3135#define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m))
3136
3137extern int readlink_copy(char __user *, int, const char *);
3138extern int page_readlink(struct dentry *, char __user *, int);
3139extern const char *page_get_link(struct dentry *, struct inode *,
3140 struct delayed_call *);
3141extern void page_put_link(void *);
3142extern int __page_symlink(struct inode *inode, const char *symname, int len,
3143 int nofs);
3144extern int page_symlink(struct inode *inode, const char *symname, int len);
3145extern const struct inode_operations page_symlink_inode_operations;
3146extern void kfree_link(void *);
3147extern void generic_fillattr(struct inode *, struct kstat *);
3148extern int vfs_getattr_nosec(const struct path *, struct kstat *, u32, unsigned int);
3149extern int vfs_getattr(const struct path *, struct kstat *, u32, unsigned int);
3150void __inode_add_bytes(struct inode *inode, loff_t bytes);
3151void inode_add_bytes(struct inode *inode, loff_t bytes);
3152void __inode_sub_bytes(struct inode *inode, loff_t bytes);
3153void inode_sub_bytes(struct inode *inode, loff_t bytes);
3154static inline loff_t __inode_get_bytes(struct inode *inode)
3155{
3156 return (((loff_t)inode->i_blocks) << 9) + inode->i_bytes;
3157}
3158loff_t inode_get_bytes(struct inode *inode);
3159void inode_set_bytes(struct inode *inode, loff_t bytes);
3160const char *simple_get_link(struct dentry *, struct inode *,
3161 struct delayed_call *);
3162extern const struct inode_operations simple_symlink_inode_operations;
3163
3164extern int iterate_dir(struct file *, struct dir_context *);
3165
3166extern int vfs_statx(int, const char __user *, int, struct kstat *, u32);
3167extern int vfs_statx_fd(unsigned int, struct kstat *, u32, unsigned int);
3168
3169static inline int vfs_stat(const char __user *filename, struct kstat *stat)
3170{
3171 return vfs_statx(AT_FDCWD, filename, AT_NO_AUTOMOUNT,
3172 stat, STATX_BASIC_STATS);
3173}
3174static inline int vfs_lstat(const char __user *name, struct kstat *stat)
3175{
3176 return vfs_statx(AT_FDCWD, name, AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT,
3177 stat, STATX_BASIC_STATS);
3178}
3179static inline int vfs_fstatat(int dfd, const char __user *filename,
3180 struct kstat *stat, int flags)
3181{
3182 return vfs_statx(dfd, filename, flags | AT_NO_AUTOMOUNT,
3183 stat, STATX_BASIC_STATS);
3184}
3185static inline int vfs_fstat(int fd, struct kstat *stat)
3186{
3187 return vfs_statx_fd(fd, stat, STATX_BASIC_STATS, 0);
3188}
3189
3190
3191extern const char *vfs_get_link(struct dentry *, struct delayed_call *);
3192extern int vfs_readlink(struct dentry *, char __user *, int);
3193
3194extern int __generic_block_fiemap(struct inode *inode,
3195 struct fiemap_extent_info *fieinfo,
3196 loff_t start, loff_t len,
3197 get_block_t *get_block);
3198extern int generic_block_fiemap(struct inode *inode,
3199 struct fiemap_extent_info *fieinfo, u64 start,
3200 u64 len, get_block_t *get_block);
3201
3202extern struct file_system_type *get_filesystem(struct file_system_type *fs);
3203extern void put_filesystem(struct file_system_type *fs);
3204extern struct file_system_type *get_fs_type(const char *name);
3205extern struct super_block *get_super(struct block_device *);
3206extern struct super_block *get_super_thawed(struct block_device *);
3207extern struct super_block *get_super_exclusive_thawed(struct block_device *bdev);
3208extern struct super_block *get_active_super(struct block_device *bdev);
3209extern void drop_super(struct super_block *sb);
3210extern void drop_super_exclusive(struct super_block *sb);
3211extern void iterate_supers(void (*)(struct super_block *, void *), void *);
3212extern void iterate_supers_type(struct file_system_type *,
3213 void (*)(struct super_block *, void *), void *);
3214
3215extern int dcache_dir_open(struct inode *, struct file *);
3216extern int dcache_dir_close(struct inode *, struct file *);
3217extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
3218extern int dcache_readdir(struct file *, struct dir_context *);
3219extern int simple_setattr(struct dentry *, struct iattr *);
3220extern int simple_getattr(const struct path *, struct kstat *, u32, unsigned int);
3221extern int simple_statfs(struct dentry *, struct kstatfs *);
3222extern int simple_open(struct inode *inode, struct file *file);
3223extern int simple_link(struct dentry *, struct inode *, struct dentry *);
3224extern int simple_unlink(struct inode *, struct dentry *);
3225extern int simple_rmdir(struct inode *, struct dentry *);
3226extern int simple_rename(struct inode *, struct dentry *,
3227 struct inode *, struct dentry *, unsigned int);
3228extern int noop_fsync(struct file *, loff_t, loff_t, int);
3229extern int noop_set_page_dirty(struct page *page);
3230extern void noop_invalidatepage(struct page *page, unsigned int offset,
3231 unsigned int length);
3232extern ssize_t noop_direct_IO(struct kiocb *iocb, struct iov_iter *iter);
3233extern int simple_empty(struct dentry *);
3234extern int simple_readpage(struct file *file, struct page *page);
3235extern int simple_write_begin(struct file *file, struct address_space *mapping,
3236 loff_t pos, unsigned len, unsigned flags,
3237 struct page **pagep, void **fsdata);
3238extern int simple_write_end(struct file *file, struct address_space *mapping,
3239 loff_t pos, unsigned len, unsigned copied,
3240 struct page *page, void *fsdata);
3241extern int always_delete_dentry(const struct dentry *);
3242extern struct inode *alloc_anon_inode(struct super_block *);
3243extern int simple_nosetlease(struct file *, long, struct file_lock **, void **);
3244extern const struct dentry_operations simple_dentry_operations;
3245
3246extern struct dentry *simple_lookup(struct inode *, struct dentry *, unsigned int flags);
3247extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *);
3248extern const struct file_operations simple_dir_operations;
3249extern const struct inode_operations simple_dir_inode_operations;
3250extern void make_empty_dir_inode(struct inode *inode);
3251extern bool is_empty_dir_inode(struct inode *inode);
3252struct tree_descr { const char *name; const struct file_operations *ops; int mode; };
3253struct dentry *d_alloc_name(struct dentry *, const char *);
3254extern int simple_fill_super(struct super_block *, unsigned long,
3255 const struct tree_descr *);
3256extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count);
3257extern void simple_release_fs(struct vfsmount **mount, int *count);
3258
3259extern ssize_t simple_read_from_buffer(void __user *to, size_t count,
3260 loff_t *ppos, const void *from, size_t available);
3261extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
3262 const void __user *from, size_t count);
3263
3264extern int __generic_file_fsync(struct file *, loff_t, loff_t, int);
3265extern int generic_file_fsync(struct file *, loff_t, loff_t, int);
3266
3267extern int generic_check_addressable(unsigned, u64);
3268
3269#ifdef CONFIG_MIGRATION
3270extern int buffer_migrate_page(struct address_space *,
3271 struct page *, struct page *,
3272 enum migrate_mode);
3273extern int buffer_migrate_page_norefs(struct address_space *,
3274 struct page *, struct page *,
3275 enum migrate_mode);
3276#else
3277#define buffer_migrate_page NULL
3278#define buffer_migrate_page_norefs NULL
3279#endif
3280
3281extern int setattr_prepare(struct dentry *, struct iattr *);
3282extern int inode_newsize_ok(const struct inode *, loff_t offset);
3283extern void setattr_copy(struct inode *inode, const struct iattr *attr);
3284
3285extern int file_update_time(struct file *file);
3286
3287static inline bool io_is_direct(struct file *filp)
3288{
3289 return (filp->f_flags & O_DIRECT) || IS_DAX(filp->f_mapping->host);
3290}
3291
3292static inline bool vma_is_dax(struct vm_area_struct *vma)
3293{
3294 return vma->vm_file && IS_DAX(vma->vm_file->f_mapping->host);
3295}
3296
3297static inline bool vma_is_fsdax(struct vm_area_struct *vma)
3298{
3299 struct inode *inode;
3300
3301 if (!vma->vm_file)
3302 return false;
3303 if (!vma_is_dax(vma))
3304 return false;
3305 inode = file_inode(vma->vm_file);
3306 if (S_ISCHR(inode->i_mode))
3307 return false;
3308 return true;
3309}
3310
3311static inline int iocb_flags(struct file *file)
3312{
3313 int res = 0;
3314 if (file->f_flags & O_APPEND)
3315 res |= IOCB_APPEND;
3316 if (io_is_direct(file))
3317 res |= IOCB_DIRECT;
3318 if ((file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host))
3319 res |= IOCB_DSYNC;
3320 if (file->f_flags & __O_SYNC)
3321 res |= IOCB_SYNC;
3322 return res;
3323}
3324
3325static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags)
3326{
3327 if (unlikely(flags & ~RWF_SUPPORTED))
3328 return -EOPNOTSUPP;
3329
3330 if (flags & RWF_NOWAIT) {
3331 if (!(ki->ki_filp->f_mode & FMODE_NOWAIT))
3332 return -EOPNOTSUPP;
3333 ki->ki_flags |= IOCB_NOWAIT;
3334 }
3335 if (flags & RWF_HIPRI)
3336 ki->ki_flags |= IOCB_HIPRI;
3337 if (flags & RWF_DSYNC)
3338 ki->ki_flags |= IOCB_DSYNC;
3339 if (flags & RWF_SYNC)
3340 ki->ki_flags |= (IOCB_DSYNC | IOCB_SYNC);
3341 if (flags & RWF_APPEND)
3342 ki->ki_flags |= IOCB_APPEND;
3343 return 0;
3344}
3345
3346static inline ino_t parent_ino(struct dentry *dentry)
3347{
3348 ino_t res;
3349
3350
3351
3352
3353
3354 spin_lock(&dentry->d_lock);
3355 res = dentry->d_parent->d_inode->i_ino;
3356 spin_unlock(&dentry->d_lock);
3357 return res;
3358}
3359
3360
3361
3362
3363
3364
3365
3366struct simple_transaction_argresp {
3367 ssize_t size;
3368 char data[0];
3369};
3370
3371#define SIMPLE_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct simple_transaction_argresp))
3372
3373char *simple_transaction_get(struct file *file, const char __user *buf,
3374 size_t size);
3375ssize_t simple_transaction_read(struct file *file, char __user *buf,
3376 size_t size, loff_t *pos);
3377int simple_transaction_release(struct inode *inode, struct file *file);
3378
3379void simple_transaction_set(struct file *file, size_t n);
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
3398static int __fops ## _open(struct inode *inode, struct file *file) \
3399{ \
3400 __simple_attr_check_format(__fmt, 0ull); \
3401 return simple_attr_open(inode, file, __get, __set, __fmt); \
3402} \
3403static const struct file_operations __fops = { \
3404 .owner = THIS_MODULE, \
3405 .open = __fops ## _open, \
3406 .release = simple_attr_release, \
3407 .read = simple_attr_read, \
3408 .write = simple_attr_write, \
3409 .llseek = generic_file_llseek, \
3410}
3411
3412static inline __printf(1, 2)
3413void __simple_attr_check_format(const char *fmt, ...)
3414{
3415
3416}
3417
3418int simple_attr_open(struct inode *inode, struct file *file,
3419 int (*get)(void *, u64 *), int (*set)(void *, u64),
3420 const char *fmt);
3421int simple_attr_release(struct inode *inode, struct file *file);
3422ssize_t simple_attr_read(struct file *file, char __user *buf,
3423 size_t len, loff_t *ppos);
3424ssize_t simple_attr_write(struct file *file, const char __user *buf,
3425 size_t len, loff_t *ppos);
3426
3427struct ctl_table;
3428int proc_nr_files(struct ctl_table *table, int write,
3429 void __user *buffer, size_t *lenp, loff_t *ppos);
3430int proc_nr_dentry(struct ctl_table *table, int write,
3431 void __user *buffer, size_t *lenp, loff_t *ppos);
3432int proc_nr_inodes(struct ctl_table *table, int write,
3433 void __user *buffer, size_t *lenp, loff_t *ppos);
3434int __init get_filesystem_list(char *buf);
3435
3436#define __FMODE_EXEC ((__force int) FMODE_EXEC)
3437#define __FMODE_NONOTIFY ((__force int) FMODE_NONOTIFY)
3438
3439#define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE])
3440#define OPEN_FMODE(flag) ((__force fmode_t)(((flag + 1) & O_ACCMODE) | \
3441 (flag & __FMODE_NONOTIFY)))
3442
3443static inline bool is_sxid(umode_t mode)
3444{
3445 return (mode & S_ISUID) || ((mode & S_ISGID) && (mode & S_IXGRP));
3446}
3447
3448static inline int check_sticky(struct inode *dir, struct inode *inode)
3449{
3450 if (!(dir->i_mode & S_ISVTX))
3451 return 0;
3452
3453 return __check_sticky(dir, inode);
3454}
3455
3456static inline void inode_has_no_xattr(struct inode *inode)
3457{
3458 if (!is_sxid(inode->i_mode) && (inode->i_sb->s_flags & SB_NOSEC))
3459 inode->i_flags |= S_NOSEC;
3460}
3461
3462static inline bool is_root_inode(struct inode *inode)
3463{
3464 return inode == inode->i_sb->s_root->d_inode;
3465}
3466
3467static inline bool dir_emit(struct dir_context *ctx,
3468 const char *name, int namelen,
3469 u64 ino, unsigned type)
3470{
3471 return ctx->actor(ctx, name, namelen, ctx->pos, ino, type) == 0;
3472}
3473static inline bool dir_emit_dot(struct file *file, struct dir_context *ctx)
3474{
3475 return ctx->actor(ctx, ".", 1, ctx->pos,
3476 file->f_path.dentry->d_inode->i_ino, DT_DIR) == 0;
3477}
3478static inline bool dir_emit_dotdot(struct file *file, struct dir_context *ctx)
3479{
3480 return ctx->actor(ctx, "..", 2, ctx->pos,
3481 parent_ino(file->f_path.dentry), DT_DIR) == 0;
3482}
3483static inline bool dir_emit_dots(struct file *file, struct dir_context *ctx)
3484{
3485 if (ctx->pos == 0) {
3486 if (!dir_emit_dot(file, ctx))
3487 return false;
3488 ctx->pos = 1;
3489 }
3490 if (ctx->pos == 1) {
3491 if (!dir_emit_dotdot(file, ctx))
3492 return false;
3493 ctx->pos = 2;
3494 }
3495 return true;
3496}
3497static inline bool dir_relax(struct inode *inode)
3498{
3499 inode_unlock(inode);
3500 inode_lock(inode);
3501 return !IS_DEADDIR(inode);
3502}
3503
3504static inline bool dir_relax_shared(struct inode *inode)
3505{
3506 inode_unlock_shared(inode);
3507 inode_lock_shared(inode);
3508 return !IS_DEADDIR(inode);
3509}
3510
3511extern bool path_noexec(const struct path *path);
3512extern void inode_nohighmem(struct inode *inode);
3513
3514
3515extern int vfs_fadvise(struct file *file, loff_t offset, loff_t len,
3516 int advice);
3517
3518#endif
3519