fs.h 109 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds's avatar
Linus Torvalds committed
2 3 4 5
#ifndef _LINUX_FS_H
#define _LINUX_FS_H

#include <linux/linkage.h>
6
#include <linux/wait_bit.h>
Linus Torvalds's avatar
Linus Torvalds committed
7 8
#include <linux/kdev_t.h>
#include <linux/dcache.h>
9
#include <linux/path.h>
Linus Torvalds's avatar
Linus Torvalds committed
10 11 12
#include <linux/stat.h>
#include <linux/cache.h>
#include <linux/list.h>
13
#include <linux/list_lru.h>
14
#include <linux/llist.h>
Linus Torvalds's avatar
Linus Torvalds committed
15
#include <linux/radix-tree.h>
16
#include <linux/rbtree.h>
Linus Torvalds's avatar
Linus Torvalds committed
17
#include <linux/init.h>
18
#include <linux/pid.h>
19
#include <linux/bug.h>
20
#include <linux/mutex.h>
21
#include <linux/rwsem.h>
22
#include <linux/mm_types.h>
23
#include <linux/capability.h>
24
#include <linux/semaphore.h>
25
#include <linux/fcntl.h>
Mark Fasheh's avatar
Mark Fasheh committed
26
#include <linux/fiemap.h>
27
#include <linux/rculist_bl.h>
28
#include <linux/atomic.h>
29
#include <linux/shrinker.h>
30
#include <linux/migrate_mode.h>
31
#include <linux/uidgid.h>
32
#include <linux/lockdep.h>
33
#include <linux/percpu-rwsem.h>
34
#include <linux/workqueue.h>
35
#include <linux/delayed_call.h>
36
#include <linux/uuid.h>
37
#include <linux/errseq.h>
Linus Torvalds's avatar
Linus Torvalds committed
38 39

#include <asm/byteorder.h>
40
#include <uapi/linux/fs.h>
Linus Torvalds's avatar
Linus Torvalds committed
41

42
struct backing_dev_info;
43
struct bdi_writeback;
44
struct bio;
45
struct export_operations;
46
struct hd_geometry;
Linus Torvalds's avatar
Linus Torvalds committed
47
struct iovec;
48
struct kiocb;
Alexey Dobriyan's avatar
Alexey Dobriyan committed
49
struct kobject;
Linus Torvalds's avatar
Linus Torvalds committed
50 51 52 53 54
struct pipe_inode_info;
struct poll_table_struct;
struct kstatfs;
struct vm_area_struct;
struct vfsmount;
55
struct cred;
56
struct swap_info_struct;
57
struct seq_file;
58
struct workqueue_struct;
59
struct iov_iter;
60 61
struct fscrypt_info;
struct fscrypt_operations;
Linus Torvalds's avatar
Linus Torvalds committed
62

63
extern void __init inode_init(void);
Linus Torvalds's avatar
Linus Torvalds committed
64
extern void __init inode_init_early(void);
65 66
extern void __init files_init(void);
extern void __init files_maxfiles_init(void);
Linus Torvalds's avatar
Linus Torvalds committed
67

68
extern struct files_stat_struct files_stat;
69
extern unsigned long get_max_files(void);
70
extern unsigned int sysctl_nr_open;
71 72
extern struct inodes_stat_t inodes_stat;
extern int leases_enable, lease_break_time;
Kees Cook's avatar
Kees Cook committed
73 74
extern int sysctl_protected_symlinks;
extern int sysctl_protected_hardlinks;
75

Christoph Hellwig's avatar
Christoph Hellwig committed
76 77
typedef __kernel_rwf_t rwf_t;

Linus Torvalds's avatar
Linus Torvalds committed
78 79 80
struct buffer_head;
typedef int (get_block_t)(struct inode *inode, sector_t iblock,
			struct buffer_head *bh_result, int create);
81
typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
82
			ssize_t bytes, void *private);
Linus Torvalds's avatar
Linus Torvalds committed
83

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
#define MAY_EXEC		0x00000001
#define MAY_WRITE		0x00000002
#define MAY_READ		0x00000004
#define MAY_APPEND		0x00000008
#define MAY_ACCESS		0x00000010
#define MAY_OPEN		0x00000020
#define MAY_CHDIR		0x00000040
/* called from RCU mode, don't block */
#define MAY_NOT_BLOCK		0x00000080

/*
 * flags in file.f_mode.  Note that FMODE_READ and FMODE_WRITE must correspond
 * to O_WRONLY and O_RDWR via the strange trick in __dentry_open()
 */

/* file is open for reading */
#define FMODE_READ		((__force fmode_t)0x1)
/* file is open for writing */
#define FMODE_WRITE		((__force fmode_t)0x2)
/* file is seekable */
#define FMODE_LSEEK		((__force fmode_t)0x4)
/* file can be accessed using pread */
#define FMODE_PREAD		((__force fmode_t)0x8)
/* file can be accessed using pwrite */
#define FMODE_PWRITE		((__force fmode_t)0x10)
/* File is opened for execution with sys_execve / sys_uselib */
#define FMODE_EXEC		((__force fmode_t)0x20)
/* File is opened with O_NDELAY (only set for block devices) */
#define FMODE_NDELAY		((__force fmode_t)0x40)
/* File is opened with O_EXCL (only set for block devices) */
#define FMODE_EXCL		((__force fmode_t)0x80)
/* File is opened using open(.., 3, ..) and is writeable only for ioctls
   (specialy hack for floppy.c) */
#define FMODE_WRITE_IOCTL	((__force fmode_t)0x100)
/* 32bit hashes as llseek() offset (for directories) */
#define FMODE_32BITHASH         ((__force fmode_t)0x200)
/* 64bit hashes as llseek() offset (for directories) */
#define FMODE_64BITHASH         ((__force fmode_t)0x400)

/*
 * Don't update ctime and mtime.
 *
 * Currently a special hack for the XFS open_by_handle ioctl, but we'll
 * hopefully graduate it to a proper O_CMTIME flag supported by open(2) soon.
 */
#define FMODE_NOCMTIME		((__force fmode_t)0x800)

/* Expect random access pattern */
#define FMODE_RANDOM		((__force fmode_t)0x1000)

/* File is huge (eg. /dev/kmem): treat loff_t as unsigned */
#define FMODE_UNSIGNED_OFFSET	((__force fmode_t)0x2000)

/* File is opened with O_PATH; almost nothing can be done with it */
#define FMODE_PATH		((__force fmode_t)0x4000)

140 141
/* File needs atomic accesses to f_pos */
#define FMODE_ATOMIC_POS	((__force fmode_t)0x8000)
142 143
/* Write access to underlying fs */
#define FMODE_WRITER		((__force fmode_t)0x10000)
144 145 146 147
/* Has read method(s) */
#define FMODE_CAN_READ          ((__force fmode_t)0x20000)
/* Has write method(s) */
#define FMODE_CAN_WRITE         ((__force fmode_t)0x40000)
148

149
/* File was opened by fanotify and shouldn't generate fanotify events */
150
#define FMODE_NONOTIFY		((__force fmode_t)0x4000000)
151

152 153
/* File is capable of returning -EAGAIN if I/O will block */
#define FMODE_NOWAIT	((__force fmode_t)0x8000000)
154

155 156 157 158 159 160 161 162
/*
 * Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector
 * that indicates that they should check the contents of the iovec are
 * valid, but not check the memory that the iovec elements
 * points too.
 */
#define CHECK_IOVEC_ONLY -1

Linus Torvalds's avatar
Linus Torvalds committed
163 164 165 166
/*
 * Attribute flags.  These should be or-ed together to figure out what
 * has been changed!
 */
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
#define ATTR_MODE	(1 << 0)
#define ATTR_UID	(1 << 1)
#define ATTR_GID	(1 << 2)
#define ATTR_SIZE	(1 << 3)
#define ATTR_ATIME	(1 << 4)
#define ATTR_MTIME	(1 << 5)
#define ATTR_CTIME	(1 << 6)
#define ATTR_ATIME_SET	(1 << 7)
#define ATTR_MTIME_SET	(1 << 8)
#define ATTR_FORCE	(1 << 9) /* Not a change, but a change it */
#define ATTR_ATTR_FLAG	(1 << 10)
#define ATTR_KILL_SUID	(1 << 11)
#define ATTR_KILL_SGID	(1 << 12)
#define ATTR_FILE	(1 << 13)
#define ATTR_KILL_PRIV	(1 << 14)
#define ATTR_OPEN	(1 << 15) /* Truncating from open(O_TRUNC) */
#define ATTR_TIMES_SET	(1 << 16)
184
#define ATTR_TOUCH	(1 << 17)
Linus Torvalds's avatar
Linus Torvalds committed
185

Miklos Szeredi's avatar
Miklos Szeredi committed
186 187 188 189 190 191 192
/*
 * Whiteout is represented by a char device.  The following constants define the
 * mode and device number to use.
 */
#define WHITEOUT_MODE 0
#define WHITEOUT_DEV 0

Linus Torvalds's avatar
Linus Torvalds committed
193 194 195 196 197 198 199 200 201 202 203 204
/*
 * This is the Inode Attributes structure, used for notify_change().  It
 * uses the above definitions as flags, to know which values have changed.
 * Also, in this manner, a Filesystem can look at only the values it cares
 * about.  Basically, these are the attributes that the VFS layer can
 * request to change from the FS layer.
 *
 * Derek Atkins <warlord@MIT.EDU> 94-10-20
 */
struct iattr {
	unsigned int	ia_valid;
	umode_t		ia_mode;
205 206
	kuid_t		ia_uid;
	kgid_t		ia_gid;
Linus Torvalds's avatar
Linus Torvalds committed
207 208 209 210
	loff_t		ia_size;
	struct timespec	ia_atime;
	struct timespec	ia_mtime;
	struct timespec	ia_ctime;
211 212

	/*
Lucas De Marchi's avatar
Lucas De Marchi committed
213
	 * Not an attribute, but an auxiliary info for filesystems wanting to
214 215 216 217
	 * implement an ftruncate() like method.  NOTE: filesystem should
	 * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL).
	 */
	struct file	*ia_file;
Linus Torvalds's avatar
Linus Torvalds committed
218 219 220 221 222 223 224
};

/*
 * Includes for diskquotas.
 */
#include <linux/quota.h>

225 226 227 228 229 230
/*
 * Maximum number of layers of fs stack.  Needs to be limited to
 * prevent kernel stack overflow
 */
#define FILESYSTEM_MAX_STACK_DEPTH 2

231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
/** 
 * enum positive_aop_returns - aop return codes with specific semantics
 *
 * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has
 * 			    completed, that the page is still locked, and
 * 			    should be considered active.  The VM uses this hint
 * 			    to return the page to the active list -- it won't
 * 			    be a candidate for writeback again in the near
 * 			    future.  Other callers must be careful to unlock
 * 			    the page if they get this return.  Returned by
 * 			    writepage(); 
 *
 * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has
 *  			unlocked it and the page might have been truncated.
 *  			The caller should back up to acquiring a new page and
 *  			trying again.  The aop will be taking reasonable
 *  			precautions not to livelock.  If the caller held a page
 *  			reference, it should drop it before retrying.  Returned
249
 *  			by readpage().
250 251 252 253 254 255 256 257 258 259 260 261
 *
 * address_space_operation functions return these large constants to indicate
 * special semantics to the caller.  These are much larger than the bytes in a
 * page to allow for functions that return the number of bytes operated on in a
 * given page.
 */

enum positive_aop_returns {
	AOP_WRITEPAGE_ACTIVATE	= 0x80000,
	AOP_TRUNCATED_PAGE	= 0x80001,
};

262 263
#define AOP_FLAG_CONT_EXPAND		0x0001 /* called from cont_expand */
#define AOP_FLAG_NOFS			0x0002 /* used by filesystem to direct
264 265
						* helper code (eg buffer layer)
						* to clear GFP_FS from alloc */
266

Linus Torvalds's avatar
Linus Torvalds committed
267 268 269 270 271 272 273
/*
 * oh the beauties of C type declarations.
 */
struct page;
struct address_space;
struct writeback_control;

274 275 276 277 278 279 280 281 282 283 284 285
/*
 * Write life time hint values.
 */
enum rw_hint {
	WRITE_LIFE_NOT_SET	= 0,
	WRITE_LIFE_NONE		= RWH_WRITE_LIFE_NONE,
	WRITE_LIFE_SHORT	= RWH_WRITE_LIFE_SHORT,
	WRITE_LIFE_MEDIUM	= RWH_WRITE_LIFE_MEDIUM,
	WRITE_LIFE_LONG		= RWH_WRITE_LIFE_LONG,
	WRITE_LIFE_EXTREME	= RWH_WRITE_LIFE_EXTREME,
};

286
#define IOCB_EVENTFD		(1 << 0)
287 288
#define IOCB_APPEND		(1 << 1)
#define IOCB_DIRECT		(1 << 2)
289
#define IOCB_HIPRI		(1 << 3)
290 291
#define IOCB_DSYNC		(1 << 4)
#define IOCB_SYNC		(1 << 5)
292
#define IOCB_WRITE		(1 << 6)
293
#define IOCB_NOWAIT		(1 << 7)
294 295 296 297 298 299 300

struct kiocb {
	struct file		*ki_filp;
	loff_t			ki_pos;
	void (*ki_complete)(struct kiocb *iocb, long ret, long ret2);
	void			*private;
	int			ki_flags;
301
	enum rw_hint		ki_hint;
302
} __randomize_layout;
303 304 305 306 307 308

static inline bool is_sync_kiocb(struct kiocb *kiocb)
{
	return kiocb->ki_complete == NULL;
}

309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
/*
 * "descriptor" for what we're up to with a read.
 * This allows us to use the same read code yet
 * have multiple different users of the data that
 * we read from a file.
 *
 * The simplest case just copies the data to user
 * mode.
 */
typedef struct {
	size_t written;
	size_t count;
	union {
		char __user *buf;
		void *data;
	} arg;
	int error;
} read_descriptor_t;

typedef int (*read_actor_t)(read_descriptor_t *, struct page *,
		unsigned long, unsigned long);
Nick Piggin's avatar
Nick Piggin committed
330

Linus Torvalds's avatar
Linus Torvalds committed
331 332 333 334 335 336 337
struct address_space_operations {
	int (*writepage)(struct page *page, struct writeback_control *wbc);
	int (*readpage)(struct file *, struct page *);

	/* Write back some dirty pages from this mapping. */
	int (*writepages)(struct address_space *, struct writeback_control *);

338
	/* Set a page dirty.  Return true if this dirtied it */
Linus Torvalds's avatar
Linus Torvalds committed
339 340 341 342 343
	int (*set_page_dirty)(struct page *page);

	int (*readpages)(struct file *filp, struct address_space *mapping,
			struct list_head *pages, unsigned nr_pages);

344 345 346 347 348 349 350
	int (*write_begin)(struct file *, struct address_space *mapping,
				loff_t pos, unsigned len, unsigned flags,
				struct page **pagep, void **fsdata);
	int (*write_end)(struct file *, struct address_space *mapping,
				loff_t pos, unsigned len, unsigned copied,
				struct page *page, void *fsdata);

Linus Torvalds's avatar
Linus Torvalds committed
351 352
	/* Unfortunately this kludge is needed for FIBMAP. Don't use it */
	sector_t (*bmap)(struct address_space *, sector_t);
353
	void (*invalidatepage) (struct page *, unsigned int, unsigned int);
Al Viro's avatar
Al Viro committed
354
	int (*releasepage) (struct page *, gfp_t);
355
	void (*freepage)(struct page *);
356
	ssize_t (*direct_IO)(struct kiocb *, struct iov_iter *iter);
357
	/*
358 359
	 * migrate the contents of a page to the specified target. If
	 * migrate_mode is MIGRATE_ASYNC, it must not block.
360
	 */
361
	int (*migratepage) (struct address_space *,
362
			struct page *, struct page *, enum migrate_mode);
363 364
	bool (*isolate_page)(struct page *, isolate_mode_t);
	void (*putback_page)(struct page *);
365
	int (*launder_page) (struct page *);
366
	int (*is_partially_uptodate) (struct page *, unsigned long,
367
					unsigned long);
368
	void (*is_dirty_writeback) (struct page *, bool *, bool *);
369
	int (*error_remove_page)(struct address_space *, struct page *);
370 371

	/* swapfile support */
372 373 374
	int (*swap_activate)(struct swap_info_struct *sis, struct file *file,
				sector_t *span);
	void (*swap_deactivate)(struct file *file);
Linus Torvalds's avatar
Linus Torvalds committed
375 376
};

Jens Axboe's avatar
Jens Axboe committed
377 378
extern const struct address_space_operations empty_aops;

379 380 381 382 383 384 385 386 387 388 389 390
/*
 * pagecache_write_begin/pagecache_write_end must be used by general code
 * to write into the pagecache.
 */
int pagecache_write_begin(struct file *, struct address_space *mapping,
				loff_t pos, unsigned len, unsigned flags,
				struct page **pagep, void **fsdata);

int pagecache_write_end(struct file *, struct address_space *mapping,
				loff_t pos, unsigned len, unsigned copied,
				struct page *page, void *fsdata);

Linus Torvalds's avatar
Linus Torvalds committed
391 392 393
struct address_space {
	struct inode		*host;		/* owner: inode, block_device */
	struct radix_tree_root	page_tree;	/* radix tree of all pages */
Nick Piggin's avatar
Nick Piggin committed
394
	spinlock_t		tree_lock;	/* and lock protecting it */
395
	atomic_t		i_mmap_writable;/* count VM_SHARED mappings */
396
	struct rb_root_cached	i_mmap;		/* tree of private and shared mappings */
397
	struct rw_semaphore	i_mmap_rwsem;	/* protect tree, count, list */
398
	/* Protected by tree_lock together with the radix tree */
Linus Torvalds's avatar
Linus Torvalds committed
399
	unsigned long		nrpages;	/* number of total pages */
400 401
	/* number of shadow or DAX exceptional entries */
	unsigned long		nrexceptional;
Linus Torvalds's avatar
Linus Torvalds committed
402
	pgoff_t			writeback_index;/* writeback starts here */
403
	const struct address_space_operations *a_ops;	/* methods */
404
	unsigned long		flags;		/* error bits */
Linus Torvalds's avatar
Linus Torvalds committed
405
	spinlock_t		private_lock;	/* for use by the address_space */
406
	gfp_t			gfp_mask;	/* implicit gfp mask for allocations */
407
	struct list_head	private_list;	/* for use by the address_space */
408
	void			*private_data;	/* ditto */
409
	errseq_t		wb_err;
410
} __attribute__((aligned(sizeof(long)))) __randomize_layout;
Linus Torvalds's avatar
Linus Torvalds committed
411 412
	/*
	 * On most architectures that alignment is already the case; but
Lucas De Marchi's avatar
Lucas De Marchi committed
413
	 * must be enforced here for CRIS, to let the least significant bit
Linus Torvalds's avatar
Linus Torvalds committed
414 415
	 * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON.
	 */
416
struct request_queue;
Linus Torvalds's avatar
Linus Torvalds committed
417 418 419

struct block_device {
	dev_t			bd_dev;  /* not a kdev_t - it's a search key */
420
	int			bd_openers;
Linus Torvalds's avatar
Linus Torvalds committed
421
	struct inode *		bd_inode;	/* will die */
422
	struct super_block *	bd_super;
423
	struct mutex		bd_mutex;	/* open/close mutex */
424
	void *			bd_claiming;
Linus Torvalds's avatar
Linus Torvalds committed
425 426
	void *			bd_holder;
	int			bd_holders;
427
	bool			bd_write_holder;
428
#ifdef CONFIG_SYSFS
429
	struct list_head	bd_holder_disks;
430
#endif
Linus Torvalds's avatar
Linus Torvalds committed
431 432
	struct block_device *	bd_contains;
	unsigned		bd_block_size;
433
	u8			bd_partno;
Linus Torvalds's avatar
Linus Torvalds committed
434 435 436 437 438
	struct hd_struct *	bd_part;
	/* number of times partitions within this device have been opened. */
	unsigned		bd_part_count;
	int			bd_invalidated;
	struct gendisk *	bd_disk;
439
	struct request_queue *  bd_queue;
440
	struct backing_dev_info *bd_bdi;
Linus Torvalds's avatar
Linus Torvalds committed
441 442 443 444 445 446 447 448
	struct list_head	bd_list;
	/*
	 * Private data.  You must have bd_claim'ed the block_device
	 * to use this.  NOTE:  bd_claim allows an owner to claim
	 * the same device multiple times, the owner must take special
	 * care to not mess up bd_private for that case.
	 */
	unsigned long		bd_private;
449 450 451 452 453

	/* The counter of freeze processes */
	int			bd_fsfreeze_count;
	/* Mutex for freeze */
	struct mutex		bd_fsfreeze_mutex;
454
} __randomize_layout;
Linus Torvalds's avatar
Linus Torvalds committed
455 456 457 458 459 460 461

/*
 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
 * radix trees
 */
#define PAGECACHE_TAG_DIRTY	0
#define PAGECACHE_TAG_WRITEBACK	1
462
#define PAGECACHE_TAG_TOWRITE	2
Linus Torvalds's avatar
Linus Torvalds committed
463 464 465

int mapping_tagged(struct address_space *mapping, int tag);

466 467
static inline void i_mmap_lock_write(struct address_space *mapping)
{
468
	down_write(&mapping->i_mmap_rwsem);
469 470 471 472
}

static inline void i_mmap_unlock_write(struct address_space *mapping)
{
473
	up_write(&mapping->i_mmap_rwsem);
474 475
}

476 477 478 479 480 481 482 483 484 485
static inline void i_mmap_lock_read(struct address_space *mapping)
{
	down_read(&mapping->i_mmap_rwsem);
}

static inline void i_mmap_unlock_read(struct address_space *mapping)
{
	up_read(&mapping->i_mmap_rwsem);
}

Linus Torvalds's avatar
Linus Torvalds committed
486 487 488 489 490
/*
 * Might pages of this file be mapped into userspace?
 */
static inline int mapping_mapped(struct address_space *mapping)
{
491
	return	!RB_EMPTY_ROOT(&mapping->i_mmap.rb_root);
Linus Torvalds's avatar
Linus Torvalds committed
492 493 494 495 496 497 498
}

/*
 * Might pages of this file have been modified in userspace?
 * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff
 * marks vma as VM_SHARED if it is shared, and the file was opened for
 * writing i.e. vma may be mprotected writable even if now readonly.
499 500 501
 *
 * If i_mmap_writable is negative, no new writable mappings are allowed. You
 * can only deny writable mappings, if none exists right now.
Linus Torvalds's avatar
Linus Torvalds committed
502 503 504
 */
static inline int mapping_writably_mapped(struct address_space *mapping)
{
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
	return atomic_read(&mapping->i_mmap_writable) > 0;
}

static inline int mapping_map_writable(struct address_space *mapping)
{
	return atomic_inc_unless_negative(&mapping->i_mmap_writable) ?
		0 : -EPERM;
}

static inline void mapping_unmap_writable(struct address_space *mapping)
{
	atomic_dec(&mapping->i_mmap_writable);
}

static inline int mapping_deny_writable(struct address_space *mapping)
{
	return atomic_dec_unless_positive(&mapping->i_mmap_writable) ?
		0 : -EBUSY;
}

static inline void mapping_allow_writable(struct address_space *mapping)
{
	atomic_inc(&mapping->i_mmap_writable);
Linus Torvalds's avatar
Linus Torvalds committed
528 529 530 531 532 533 534 535 536 537 538 539 540
}

/*
 * Use sequence counter to get consistent i_size on 32-bit processors.
 */
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
#include <linux/seqlock.h>
#define __NEED_I_SIZE_ORDERED
#define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount)
#else
#define i_size_ordered_init(inode) do { } while (0)
#endif

Al Viro's avatar
Al Viro committed
541 542
struct posix_acl;
#define ACL_NOT_CACHED ((void *)(-1))
543
#define ACL_DONT_CACHE ((void *)(-3))
Al Viro's avatar
Al Viro committed
544

545 546 547 548 549 550 551 552 553 554 555 556
static inline struct posix_acl *
uncached_acl_sentinel(struct task_struct *task)
{
	return (void *)task + 1;
}

static inline bool
is_uncached_acl(struct posix_acl *acl)
{
	return (long)acl & 1;
}

557 558 559
#define IOP_FASTPERM	0x0001
#define IOP_LOOKUP	0x0002
#define IOP_NOFOLLOW	0x0004
560
#define IOP_XATTR	0x0008
561
#define IOP_DEFAULT_READLINK	0x0010
562

563 564
struct fsnotify_mark_connector;

565 566 567 568 569
/*
 * Keep mostly read-only and often accessed (especially for
 * the RCU path lookup and 'stat' data) fields at the beginning
 * of the 'struct inode'
 */
Linus Torvalds's avatar
Linus Torvalds committed
570
struct inode {
571
	umode_t			i_mode;
572
	unsigned short		i_opflags;
573 574
	kuid_t			i_uid;
	kgid_t			i_gid;
575 576 577 578 579 580 581
	unsigned int		i_flags;

#ifdef CONFIG_FS_POSIX_ACL
	struct posix_acl	*i_acl;
	struct posix_acl	*i_default_acl;
#endif

582 583
	const struct inode_operations	*i_op;
	struct super_block	*i_sb;
584
	struct address_space	*i_mapping;
585

586 587 588
#ifdef CONFIG_SECURITY
	void			*i_security;
#endif
589

590 591
	/* Stat data, not accessed from path walking */
	unsigned long		i_ino;
Miklos Szeredi's avatar
Miklos Szeredi committed
592 593 594 595 596 597 598 599 600 601 602
	/*
	 * Filesystems may only read i_nlink directly.  They shall use the
	 * following functions for modification:
	 *
	 *    (set|clear|inc|drop)_nlink
	 *    inode_(inc|dec)_link_count
	 */
	union {
		const unsigned int i_nlink;
		unsigned int __i_nlink;
	};
603
	dev_t			i_rdev;
604
	loff_t			i_size;
605 606 607
	struct timespec		i_atime;
	struct timespec		i_mtime;
	struct timespec		i_ctime;
608 609
	spinlock_t		i_lock;	/* i_blocks, i_bytes, maybe i_size */
	unsigned short          i_bytes;
610
	unsigned int		i_blkbits;
611
	enum rw_hint		i_write_hint;
612 613 614 615 616 617 618 619
	blkcnt_t		i_blocks;

#ifdef __NEED_I_SIZE_ORDERED
	seqcount_t		i_size_seqcount;
#endif

	/* Misc */
	unsigned long		i_state;
620
	struct rw_semaphore	i_rwsem;
621

622
	unsigned long		dirtied_when;	/* jiffies of first dirtying */
623
	unsigned long		dirtied_time_when;
624

Linus Torvalds's avatar
Linus Torvalds committed
625
	struct hlist_node	i_hash;
626
	struct list_head	i_io_list;	/* backing dev IO list */
627 628
#ifdef CONFIG_CGROUP_WRITEBACK
	struct bdi_writeback	*i_wb;		/* the associated cgroup wb */
629 630 631 632 633

	/* foreign inode detection, see wbc_detach_inode() */
	int			i_wb_frn_winner;
	u16			i_wb_frn_avg_time;
	u16			i_wb_frn_history;
634
#endif
Nick Piggin's avatar
Nick Piggin committed
635
	struct list_head	i_lru;		/* inode LRU list */
Linus Torvalds's avatar
Linus Torvalds committed
636
	struct list_head	i_sb_list;
637
	struct list_head	i_wb_list;	/* backing dev writeback list */
Nick Piggin's avatar
Nick Piggin committed
638
	union {
639
		struct hlist_head	i_dentry;
Nick Piggin's avatar
Nick Piggin committed
640 641
		struct rcu_head		i_rcu;
	};
642
	atomic64_t		i_version;
643
	atomic_t		i_count;
Christoph Hellwig's avatar
Christoph Hellwig committed
644
	atomic_t		i_dio_count;
645
	atomic_t		i_writecount;
Mimi Zohar's avatar
Mimi Zohar committed
646 647 648
#ifdef CONFIG_IMA
	atomic_t		i_readcount; /* struct files open RO */
#endif
649
	const struct file_operations	*i_fop;	/* former ->i_op->default_file_ops */
650
	struct file_lock_context	*i_flctx;
Linus Torvalds's avatar
Linus Torvalds committed
651 652
	struct address_space	i_data;
	struct list_head	i_devices;
653 654
	union {
		struct pipe_inode_info	*i_pipe;
655
		struct block_device	*i_bdev;
656
		struct cdev		*i_cdev;
Al Viro's avatar
Al Viro committed
657
		char			*i_link;
Al Viro's avatar
Al Viro committed
658
		unsigned		i_dir_seq;
659
	};
Linus Torvalds's avatar
Linus Torvalds committed
660 661 662

	__u32			i_generation;

663 664
#ifdef CONFIG_FSNOTIFY
	__u32			i_fsnotify_mask; /* all events this inode cares about */
665
	struct fsnotify_mark_connector __rcu	*i_fsnotify_marks;
Robert Love's avatar
Robert Love committed
666 667
#endif

668 669 670 671
#if IS_ENABLED(CONFIG_FS_ENCRYPTION)
	struct fscrypt_info	*i_crypt_info;
#endif

672
	void			*i_private; /* fs or device private pointer */
673
} __randomize_layout;
Linus Torvalds's avatar
Linus Torvalds committed
674

Fabian Frederick's avatar
Fabian Frederick committed
675 676 677 678 679
static inline unsigned int i_blocksize(const struct inode *node)
{
	return (1 << node->i_blkbits);
}

Al Viro's avatar
Al Viro committed
680 681 682 683 684
static inline int inode_unhashed(struct inode *inode)
{
	return hlist_unhashed(&inode->i_hash);
}

685 686 687 688 689 690
/*
 * inode->i_mutex nesting subclasses for the lock validator:
 *
 * 0: the object of the current VFS operation
 * 1: parent
 * 2: child/target
691 692
 * 3: xattr
 * 4: second non-directory
693 694 695
 * 5: second parent (when locking independent directories in rename)
 *
 * I_MUTEX_NONDIR2 is for certain operations (such as rename) which lock two
696
 * non-directories at once.
697 698
 *
 * The locking order between these classes is
699
 * parent[2] -> child -> grandchild -> normal -> xattr -> second non-directory
700 701 702 703 704 705
 */
enum inode_i_mutex_lock_class
{
	I_MUTEX_NORMAL,
	I_MUTEX_PARENT,
	I_MUTEX_CHILD,
706
	I_MUTEX_XATTR,
707 708
	I_MUTEX_NONDIR2,
	I_MUTEX_PARENT2,
709 710
};

Al Viro's avatar
Al Viro committed
711 712
static inline void inode_lock(struct inode *inode)
{
713
	down_write(&inode->i_rwsem);
Al Viro's avatar
Al Viro committed
714 715 716 717
}

static inline void inode_unlock(struct inode *inode)
{
718 719 720 721 722 723 724 725 726 727 728
	up_write(&inode->i_rwsem);
}

static inline void inode_lock_shared(struct inode *inode)
{
	down_read(&inode->i_rwsem);
}

static inline void inode_unlock_shared(struct inode *inode)
{
	up_read(&inode->i_rwsem);
Al Viro's avatar
Al Viro committed
729 730 731 732
}

static inline int inode_trylock(struct inode *inode)
{
733 734 735 736 737 738
	return down_write_trylock(&inode->i_rwsem);
}

static inline int inode_trylock_shared(struct inode *inode)
{
	return down_read_trylock(&inode->i_rwsem);
Al Viro's avatar
Al Viro committed
739 740 741 742
}

static inline int inode_is_locked(struct inode *inode)
{
743
	return rwsem_is_locked(&inode->i_rwsem);
Al Viro's avatar
Al Viro committed
744 745 746 747
}

static inline void inode_lock_nested(struct inode *inode, unsigned subclass)
{
748
	down_write_nested(&inode->i_rwsem, subclass);
Al Viro's avatar
Al Viro committed
749 750
}

751 752 753 754 755
static inline void inode_lock_shared_nested(struct inode *inode, unsigned subclass)
{
	down_read_nested(&inode->i_rwsem, subclass);
}

756 757 758
void lock_two_nondirectories(struct inode *, struct inode*);
void unlock_two_nondirectories(struct inode *, struct inode*);

Linus Torvalds's avatar
Linus Torvalds committed
759 760 761 762 763 764 765 766 767 768
/*
 * NOTE: in a 32bit arch with a preemptable kernel and
 * an UP compile the i_size_read/write must be atomic
 * with respect to the local cpu (unlike with preempt disabled),
 * but they don't need to be atomic with respect to other cpus like in
 * true SMP (so they need either to either locally disable irq around
 * the read or for example on x86 they can be still implemented as a
 * cmpxchg8b without the need of the lock prefix). For SMP compiles
 * and 64bit archs it makes no difference if preempt is enabled or not.
 */
769
static inline loff_t i_size_read(const struct inode *inode)
Linus Torvalds's avatar
Linus Torvalds committed
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
{
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
	loff_t i_size;
	unsigned int seq;

	do {
		seq = read_seqcount_begin(&inode->i_size_seqcount);
		i_size = inode->i_size;
	} while (read_seqcount_retry(&inode->i_size_seqcount, seq));
	return i_size;
#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
	loff_t i_size;

	preempt_disable();
	i_size = inode->i_size;
	preempt_enable();
	return i_size;
#else
	return inode->i_size;
#endif
}

792 793 794 795 796
/*
 * NOTE: unlike i_size_read(), i_size_write() does need locking around it
 * (normally i_mutex), otherwise on 32bit/SMP an update of i_size_seqcount
 * can be lost, resulting in subsequent i_size_read() calls spinning forever.
 */
Linus Torvalds's avatar
Linus Torvalds committed
797 798 799
static inline void i_size_write(struct inode *inode, loff_t i_size)
{
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
800
	preempt_disable();
Linus Torvalds's avatar
Linus Torvalds committed
801 802 803
	write_seqcount_begin(&inode->i_size_seqcount);
	inode->i_size = i_size;
	write_seqcount_end(&inode->i_size_seqcount);
804
	preempt_enable();
Linus Torvalds's avatar
Linus Torvalds committed
805 806 807 808 809 810 811 812 813
#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
	preempt_disable();
	inode->i_size = i_size;
	preempt_enable();
#else
	inode->i_size = i_size;
#endif
}

814
static inline unsigned iminor(const struct inode *inode)
Linus Torvalds's avatar
Linus Torvalds committed
815 816 817 818
{
	return MINOR(inode->i_rdev);
}

819
static inline unsigned imajor(const struct inode *inode)
Linus Torvalds's avatar
Linus Torvalds committed
820 821 822 823 824 825 826 827
{
	return MAJOR(inode->i_rdev);
}

extern struct block_device *I_BDEV(struct inode *inode);

struct fown_struct {
	rwlock_t lock;          /* protects pid, uid, euid fields */
828 829
	struct pid *pid;	/* pid or -pgrp where SIGIO should be sent */
	enum pid_type pid_type;	/* Kind of process group SIGIO should be sent to */
830
	kuid_t uid, euid;	/* uid/euid of process setting the owner */
Linus Torvalds's avatar
Linus Torvalds committed
831 832 833 834 835 836 837
	int signum;		/* posix.1b rt signal to be delivered on IO */
};

/*
 * Track a single file's readahead state
 */
struct file_ra_state {
838 839 840
	pgoff_t start;			/* where readahead started */
	unsigned int size;		/* # of readahead pages */
	unsigned int async_size;	/* do asynchronous readahead when
841
					   there are only # of pages ahead */
842

843
	unsigned int ra_pages;		/* Maximum readahead window */
844
	unsigned int mmap_miss;		/* Cache miss stat for mmap accesses */
845
	loff_t prev_pos;		/* Cache last read() position */
Linus Torvalds's avatar
Linus Torvalds committed
846 847
};

848 849 850 851 852
/*
 * Check if @index falls in the readahead windows.
 */
static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index)
{
853 854
	return (index >= ra->start &&
		index <  ra->start + ra->size);
855 856
}

Linus Torvalds's avatar
Linus Torvalds committed
857
struct file {
858
	union {
859
		struct llist_node	fu_llist;
860 861
		struct rcu_head 	fu_rcuhead;
	} f_u;
862
	struct path		f_path;
863
	struct inode		*f_inode;	/* cached value */
864
	const struct file_operations	*f_op;
865 866

	/*
867
	 * Protects f_ep_links, f_flags.
868 869 870
	 * Must not be taken from IRQ context.
	 */
	spinlock_t		f_lock;
871
	enum rw_hint		f_write_hint;
Al Viro's avatar
Al Viro committed
872
	atomic_long_t		f_count;
Linus Torvalds's avatar
Linus Torvalds committed
873
	unsigned int 		f_flags;
874
	fmode_t			f_mode;
875
	struct mutex		f_pos_lock;
Linus Torvalds's avatar
Linus Torvalds committed
876 877
	loff_t			f_pos;
	struct fown_struct	f_owner;
878
	const struct cred	*f_cred;
Linus Torvalds's avatar
Linus Torvalds committed
879 880
	struct file_ra_state	f_ra;

881
	u64			f_version;
882
#ifdef CONFIG_SECURITY
Linus Torvalds's avatar
Linus Torvalds committed
883
	void			*f_security;
884
#endif
Linus Torvalds's avatar
Linus Torvalds committed
885 886 887 888 889 890
	/* needed for tty driver, and maybe others */
	void			*private_data;

#ifdef CONFIG_EPOLL
	/* Used by fs/eventpoll.c to link all the hooks to this file */
	struct list_head	f_ep_links;
Jason Baron's avatar
Jason Baron committed
891
	struct list_head	f_tfile_llink;
Linus Torvalds's avatar
Linus Torvalds committed
892 893
#endif /* #ifdef CONFIG_EPOLL */
	struct address_space	*f_mapping;
894
	errseq_t		f_wb_err;
895 896
} __randomize_layout
  __attribute__((aligned(4)));	/* lest something weird decides that 2 is OK */
Linus Torvalds's avatar
Linus Torvalds committed
897

898 899 900 901 902 903 904
struct file_handle {
	__u32 handle_bytes;
	int handle_type;
	/* file identifier */
	unsigned char f_handle[0];
};

Al Viro's avatar
Al Viro committed
905 906 907 908 909
static inline struct file *get_file(struct file *f)
{
	atomic_long_inc(&f->f_count);
	return f;
}
910
#define get_file_rcu(x) atomic_long_inc_not_zero(&(x)->f_count)
911
#define fput_atomic(x)	atomic_long_add_unless(&(x)->f_count, -1, 1)
Al Viro's avatar
Al Viro committed
912
#define file_count(x)	atomic_long_read(&(x)->f_count)
Linus Torvalds's avatar
Linus Torvalds committed
913 914 915 916 917 918

#define	MAX_NON_LFS	((1UL<<31) - 1)

/* Page cache limit. The filesystems should put that into their s_maxbytes 
   limits, otherwise bad things can happen in VM. */ 
#if BITS_PER_LONG==32
919
#define MAX_LFS_FILESIZE	((loff_t)ULONG_MAX << PAGE_SHIFT)
Linus Torvalds's avatar
Linus Torvalds committed
920
#elif BITS_PER_LONG==64
921
#define MAX_LFS_FILESIZE 	((loff_t)LLONG_MAX)
Linus Torvalds's avatar
Linus Torvalds committed
922 923 924 925
#endif

#define FL_POSIX	1
#define FL_FLOCK	2
926
#define FL_DELEG	4	/* NFSv4 delegation */
Linus Torvalds's avatar
Linus Torvalds committed
927
#define FL_ACCESS	8	/* not trying to lock, just looking */
928
#define FL_EXISTS	16	/* when unlocking, test for existence */
Linus Torvalds's avatar
Linus Torvalds committed
929
#define FL_LEASE	32	/* lease held on this file */
930
#define FL_CLOSE	64	/* unlock on close */
Linus Torvalds's avatar
Linus Torvalds committed
931
#define FL_SLEEP	128	/* A blocking lock */
932 933
#define FL_DOWNGRADE_PENDING	256 /* Lease is being downgraded */
#define FL_UNLOCK_PENDING	512 /* Lease is being broken */
934
#define FL_OFDLCK	1024	/* lock is "owned" by struct file */
935
#define FL_LAYOUT	2048	/* outstanding pNFS layout */
Linus Torvalds's avatar
Linus Torvalds committed
936

937 938
#define FL_CLOSE_POSIX (FL_POSIX | FL_CLOSE)

939 940 941 942 943 944
/*
 * Special return value from posix_lock_file() and vfs_lock_file() for
 * asynchronous locking.
 */
#define FILE_LOCK_DEFERRED 1

945
/* legacy typedef, should eventually be removed */
946
typedef void *fl_owner_t;
Linus Torvalds's avatar
Linus Torvalds committed
947

948 949
struct file_lock;

Linus Torvalds's avatar
Linus Torvalds committed
950 951 952 953 954 955
struct file_lock_operations {
	void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
	void (*fl_release_private)(struct file_lock *);
};

struct lock_manager_operations {
956
	int (*lm_compare_owner)(struct file_lock *, struct file_lock *);
957
	unsigned long (*lm_owner_key)(struct file_lock *);
958 959
	fl_owner_t (*lm_get_owner)(fl_owner_t);
	void (*lm_put_owner)(fl_owner_t);
960
	void (*lm_notify)(struct file_lock *);	/* unblock callback */
961
	int (*lm_grant)(struct file_lock *, int);
962
	bool (*lm_break)(struct file_lock *);
963
	int (*lm_change)(struct file_lock *, int, struct list_head *);
964
	void (*lm_setup)(struct file_lock *, void **);
Linus Torvalds's avatar
Linus Torvalds committed
965 966
};

967 968
struct lock_manager {
	struct list_head list;
969 970 971 972 973
	/*
	 * NFSv4 and up also want opens blocked during the grace period;
	 * NLM doesn't care:
	 */
	bool block_opens;
974 975
};

976 977
struct net;
void locks_start_grace(struct net *, struct lock_manager *);
978
void locks_end_grace(struct lock_manager *);
979 980
bool locks_in_grace(struct net *);
bool opens_in_grace(struct net *);
981

Linus Torvalds's avatar
Linus Torvalds committed
982 983 984
/* that will die - we need it for nfs_lock_info */
#include <linux/nfs_fs_i.h>

985 986 987 988 989 990 991 992 993
/*
 * struct file_lock represents a generic "file lock". It's used to represent
 * POSIX byte range locks, BSD (flock) locks, and leases. It's important to
 * note that the same struct is used to represent both a request for a lock and
 * the lock itself, but the same object is never used for both.
 *
 * FIXME: should we create a separate "struct lock_request" to help distinguish
 * these two uses?
 *
994
 * The varous i_flctx lists are ordered by:
995
 *
996 997 998
 * 1) lock owner
 * 2) lock range start
 * 3) lock range end
999 1000 1001
 *
 * Obviously, the last two criteria only matter for POSIX locks.
 */
Linus Torvalds's avatar
Linus Torvalds committed
1002 1003
struct file_lock {
	struct file_lock *fl_next;	/* singly linked list for this inode  */
1004
	struct list_head fl_list;	/* link into file_lock_context */
1005
	struct hlist_node fl_link;	/* node in global lists */
Linus Torvalds's avatar
Linus Torvalds committed
1006 1007
	struct list_head fl_block;	/* circular list of blocked processes */
	fl_owner_t fl_owner;
1008
	unsigned int fl_flags;
1009
	unsigned char fl_type;
Linus Torvalds's avatar
Linus Torvalds committed
1010
	unsigned int fl_pid;
1011
	int fl_link_cpu;		/* what cpu's list is this on? */
Linus Torvalds's avatar
Linus Torvalds committed
1012 1013 1014 1015 1016 1017
	wait_queue_head_t fl_wait;
	struct file *fl_file;
	loff_t fl_start;
	loff_t fl_end;

	struct fasync_struct *	fl_fasync; /* for lease break notifications */
1018 1019 1020
	/* for lease breaks: */
	unsigned long fl_break_time;
	unsigned long fl_downgrade_time;
Linus Torvalds's avatar
Linus Torvalds committed
1021

1022
	const struct file_lock_operations *fl_ops;	/* Callbacks for filesystems */
1023
	const struct lock_manager_operations *fl_lmops;	/* Callbacks for lockmanagers */
Linus Torvalds's avatar
Linus Torvalds committed
1024 1025
	union {
		struct nfs_lock_info	nfs_fl;
1026
		struct nfs4_lock_info	nfs4_fl;
David Howells's avatar
David Howells committed
1027 1028 1029 1030
		struct {
			struct list_head link;	/* link in AFS vnode's pending_locks list */
			int state;		/* state of grant or error if -ve */
		} afs;
Linus Torvalds's avatar
Linus Torvalds committed
1031
	} fl_u;
1032
} __randomize_layout;
Linus Torvalds's avatar
Linus Torvalds committed
1033

1034
struct file_lock_context {
1035
	spinlock_t		flc_lock;
1036
	struct list_head	flc_flock;
1037
	struct list_head	flc_posix;
1038
	struct list_head	flc_lease;
1039 1040
};

Linus Torvalds's avatar
Linus Torvalds committed
1041 1042 1043 1044 1045 1046 1047
/* The following constant reflects the upper bound of the file/locking space */
#ifndef OFFSET_MAX
#define INT_LIMIT(x)	(~((x)1 << (sizeof(x)*8 - 1)))
#define OFFSET_MAX	INT_LIMIT(loff_t)
#define OFFT_OFFSET_MAX	INT_LIMIT(off_t)
#endif

1048 1049
extern void send_sigio(struct fown_struct *fown, int fd, int band);

1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
/*
 * Return the inode to use for locking
 *
 * For overlayfs this should be the overlay inode, not the real inode returned
 * by file_inode().  For any other fs file_inode(filp) and locks_inode(filp) are
 * equal.
 */
static inline struct inode *locks_inode(const struct file *f)
{
	return f->f_path.dentry->d_inode;
}

1062
#ifdef CONFIG_FILE_LOCKING
1063
extern int fcntl_getlk(struct file *, unsigned int, struct flock *);
1064
extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
1065
			struct flock *);
Linus Torvalds's avatar
Linus Torvalds committed
1066 1067

#if BITS_PER_LONG == 32
1068
extern int fcntl_getlk64(struct file *, unsigned int, struct flock64 *);
1069
extern int fcntl_setlk64(unsigned int, struct file *, unsigned int,
1070
			struct flock64 *);
Linus Torvalds's avatar
Linus Torvalds committed
1071 1072 1073 1074 1075 1076
#endif

extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
extern int fcntl_getlease(struct file *filp);

/* fs/locks.c */
1077
void locks_free_lock_context(struct inode *inode);
1078
void locks_free_lock(struct file_lock *fl);
Linus Torvalds's avatar
Linus Torvalds committed
1079
extern void locks_init_lock(struct file_lock *);
1080
extern struct file_lock * locks_alloc_lock(void);
Linus Torvalds's avatar
Linus Torvalds committed
1081
extern void locks_copy_lock(struct file_lock *, struct file_lock *);
1082
extern void locks_copy_conflock(struct file_lock *, struct file_lock *);
Linus Torvalds's avatar
Linus Torvalds committed
1083
extern void locks_remove_posix(struct file *, fl_owner_t);
1084
extern void locks_remove_file(struct file *);
1085
extern void locks_release_private(struct file_lock *);
1086
extern void posix_test_lock(struct file *, struct file_lock *);