#ifndef _LINUX_FILELOCK_H
#define _LINUX_FILELOCK_H
#include <linux/fs.h>
#define FL_POSIX …
#define FL_FLOCK …
#define FL_DELEG …
#define FL_ACCESS …
#define FL_EXISTS …
#define FL_LEASE …
#define FL_CLOSE …
#define FL_SLEEP …
#define FL_DOWNGRADE_PENDING …
#define FL_UNLOCK_PENDING …
#define FL_OFDLCK …
#define FL_LAYOUT …
#define FL_RECLAIM …
#define FL_CLOSE_POSIX …
#define FILE_LOCK_DEFERRED …
struct file_lock;
struct file_lease;
struct file_lock_operations { … };
struct lock_manager_operations { … };
struct lease_manager_operations { … };
struct lock_manager { … };
struct net;
void locks_start_grace(struct net *, struct lock_manager *);
void locks_end_grace(struct lock_manager *);
bool locks_in_grace(struct net *);
bool opens_in_grace(struct net *);
#include <linux/nfs_fs_i.h>
struct file_lock_core { … };
struct file_lock { … } __randomize_layout;
struct file_lease { … } __randomize_layout;
struct file_lock_context { … };
#ifdef CONFIG_FILE_LOCKING
int fcntl_getlk(struct file *, unsigned int, struct flock *);
int fcntl_setlk(unsigned int, struct file *, unsigned int,
struct flock *);
#if BITS_PER_LONG == 32
int fcntl_getlk64(struct file *, unsigned int, struct flock64 *);
int fcntl_setlk64(unsigned int, struct file *, unsigned int,
struct flock64 *);
#endif
int fcntl_setlease(unsigned int fd, struct file *filp, int arg);
int fcntl_getlease(struct file *filp);
static inline bool lock_is_unlock(struct file_lock *fl)
{ … }
static inline bool lock_is_read(struct file_lock *fl)
{ … }
static inline bool lock_is_write(struct file_lock *fl)
{ … }
static inline void locks_wake_up(struct file_lock *fl)
{ … }
void locks_free_lock_context(struct inode *inode);
void locks_free_lock(struct file_lock *fl);
void locks_init_lock(struct file_lock *);
struct file_lock *locks_alloc_lock(void);
void locks_copy_lock(struct file_lock *, struct file_lock *);
void locks_copy_conflock(struct file_lock *, struct file_lock *);
void locks_remove_posix(struct file *, fl_owner_t);
void locks_remove_file(struct file *);
void locks_release_private(struct file_lock *);
void posix_test_lock(struct file *, struct file_lock *);
int posix_lock_file(struct file *, struct file_lock *, struct file_lock *);
int locks_delete_block(struct file_lock *);
int vfs_test_lock(struct file *, struct file_lock *);
int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *);
int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
bool vfs_inode_has_locks(struct inode *inode);
int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl);
void locks_init_lease(struct file_lease *);
void locks_free_lease(struct file_lease *fl);
struct file_lease *locks_alloc_lease(void);
int __break_lease(struct inode *inode, unsigned int flags, unsigned int type);
void lease_get_mtime(struct inode *, struct timespec64 *time);
int generic_setlease(struct file *, int, struct file_lease **, void **priv);
int kernel_setlease(struct file *, int, struct file_lease **, void **);
int vfs_setlease(struct file *, int, struct file_lease **, void **);
int lease_modify(struct file_lease *, int, struct list_head *);
struct notifier_block;
int lease_register_notifier(struct notifier_block *);
void lease_unregister_notifier(struct notifier_block *);
struct files_struct;
void show_fd_locks(struct seq_file *f,
struct file *filp, struct files_struct *files);
bool locks_owner_has_blockers(struct file_lock_context *flctx,
fl_owner_t owner);
static inline struct file_lock_context *
locks_inode_context(const struct inode *inode)
{ … }
#else
static inline int fcntl_getlk(struct file *file, unsigned int cmd,
struct flock __user *user)
{
return -EINVAL;
}
static inline int fcntl_setlk(unsigned int fd, struct file *file,
unsigned int cmd, struct flock __user *user)
{
return -EACCES;
}
#if BITS_PER_LONG == 32
static inline int fcntl_getlk64(struct file *file, unsigned int cmd,
struct flock64 *user)
{
return -EINVAL;
}
static inline int fcntl_setlk64(unsigned int fd, struct file *file,
unsigned int cmd, struct flock64 *user)
{
return -EACCES;
}
#endif
static inline int fcntl_setlease(unsigned int fd, struct file *filp, int arg)
{
return -EINVAL;
}
static inline int fcntl_getlease(struct file *filp)
{
return F_UNLCK;
}
static inline bool lock_is_unlock(struct file_lock *fl)
{
return false;
}
static inline bool lock_is_read(struct file_lock *fl)
{
return false;
}
static inline bool lock_is_write(struct file_lock *fl)
{
return false;
}
static inline void locks_wake_up(struct file_lock *fl)
{
}
static inline void
locks_free_lock_context(struct inode *inode)
{
}
static inline void locks_init_lock(struct file_lock *fl)
{
return;
}
static inline void locks_init_lease(struct file_lease *fl)
{
return;
}
static inline void locks_copy_conflock(struct file_lock *new, struct file_lock *fl)
{
return;
}
static inline void locks_copy_lock(struct file_lock *new, struct file_lock *fl)
{
return;
}
static inline void locks_remove_posix(struct file *filp, fl_owner_t owner)
{
return;
}
static inline void locks_remove_file(struct file *filp)
{
return;
}
static inline void posix_test_lock(struct file *filp, struct file_lock *fl)
{
return;
}
static inline int posix_lock_file(struct file *filp, struct file_lock *fl,
struct file_lock *conflock)
{
return -ENOLCK;
}
static inline int locks_delete_block(struct file_lock *waiter)
{
return -ENOENT;
}
static inline int vfs_test_lock(struct file *filp, struct file_lock *fl)
{
return 0;
}
static inline int vfs_lock_file(struct file *filp, unsigned int cmd,
struct file_lock *fl, struct file_lock *conf)
{
return -ENOLCK;
}
static inline int vfs_cancel_lock(struct file *filp, struct file_lock *fl)
{
return 0;
}
static inline bool vfs_inode_has_locks(struct inode *inode)
{
return false;
}
static inline int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl)
{
return -ENOLCK;
}
static inline int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
{
return 0;
}
static inline void lease_get_mtime(struct inode *inode,
struct timespec64 *time)
{
return;
}
static inline int generic_setlease(struct file *filp, int arg,
struct file_lease **flp, void **priv)
{
return -EINVAL;
}
static inline int kernel_setlease(struct file *filp, int arg,
struct file_lease **lease, void **priv)
{
return -EINVAL;
}
static inline int vfs_setlease(struct file *filp, int arg,
struct file_lease **lease, void **priv)
{
return -EINVAL;
}
static inline int lease_modify(struct file_lease *fl, int arg,
struct list_head *dispose)
{
return -EINVAL;
}
struct files_struct;
static inline void show_fd_locks(struct seq_file *f,
struct file *filp, struct files_struct *files) {}
static inline bool locks_owner_has_blockers(struct file_lock_context *flctx,
fl_owner_t owner)
{
return false;
}
static inline struct file_lock_context *
locks_inode_context(const struct inode *inode)
{
return NULL;
}
#endif
#define for_each_file_lock(_fl, _head) …
static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl)
{ … }
#ifdef CONFIG_FILE_LOCKING
static inline int break_lease(struct inode *inode, unsigned int mode)
{ … }
static inline int break_deleg(struct inode *inode, unsigned int mode)
{ … }
static inline int try_break_deleg(struct inode *inode, struct inode **delegated_inode)
{ … }
static inline int break_deleg_wait(struct inode **delegated_inode)
{ … }
static inline int break_layout(struct inode *inode, bool wait)
{ … }
#else
static inline int break_lease(struct inode *inode, unsigned int mode)
{
return 0;
}
static inline int break_deleg(struct inode *inode, unsigned int mode)
{
return 0;
}
static inline int try_break_deleg(struct inode *inode, struct inode **delegated_inode)
{
return 0;
}
static inline int break_deleg_wait(struct inode **delegated_inode)
{
BUG();
return 0;
}
static inline int break_layout(struct inode *inode, bool wait)
{
return 0;
}
#endif
#endif