1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2019 Samsung Electronics Co., Ltd.
6 #ifndef __VFS_CACHE_H__
7 #define __VFS_CACHE_H__
9 #include <linux/file.h>
11 #include <linux/rwsem.h>
12 #include <linux/spinlock.h>
13 #include <linux/idr.h>
14 #include <linux/workqueue.h>
18 /* Windows style file permissions for extended response */
19 #define FILE_GENERIC_ALL 0x1F01FF
20 #define FILE_GENERIC_READ 0x120089
21 #define FILE_GENERIC_WRITE 0x120116
22 #define FILE_GENERIC_EXECUTE 0X1200a0
24 #define KSMBD_START_FID 0
25 #define KSMBD_NO_FID (INT_MAX)
26 #define SMB2_NO_FID (0xFFFFFFFFFFFFFFFFULL)
33 struct list_head clist;
34 struct list_head flist;
35 struct list_head llist;
39 unsigned long long start;
40 unsigned long long end;
52 /* opinfo count for streams */
54 struct inode *m_inode;
56 struct hlist_node m_hash;
57 struct list_head m_fp_list;
58 struct list_head m_op_list;
59 struct oplock_info *m_opinfo;
70 struct ksmbd_inode *f_ci;
71 struct ksmbd_inode *f_parent_ci;
72 struct oplock_info __rcu *f_opinfo;
73 struct ksmbd_conn *conn;
74 struct ksmbd_tree_connect *tcon;
89 char app_instance_id[16];
92 struct list_head node;
93 struct list_head blocked_works;
94 struct list_head lock_list;
98 /* if ls is happening on directory, below is valid*/
99 struct ksmbd_readdir_data readdir_data;
103 static inline void set_ctx_actor(struct dir_context *ctx,
109 #define KSMBD_NR_OPEN_DEFAULT BITS_PER_LONG
111 struct ksmbd_file_table {
116 static inline bool has_file_id(u64 id)
118 return id < KSMBD_NO_FID;
121 static inline bool ksmbd_stream_fd(struct ksmbd_file *fp)
123 return fp->stream.name != NULL;
126 int ksmbd_init_file_table(struct ksmbd_file_table *ft);
127 void ksmbd_destroy_file_table(struct ksmbd_file_table *ft);
128 int ksmbd_close_fd(struct ksmbd_work *work, u64 id);
129 struct ksmbd_file *ksmbd_lookup_fd_fast(struct ksmbd_work *work, u64 id);
130 struct ksmbd_file *ksmbd_lookup_foreign_fd(struct ksmbd_work *work, u64 id);
131 struct ksmbd_file *ksmbd_lookup_fd_slow(struct ksmbd_work *work, u64 id,
133 void ksmbd_fd_put(struct ksmbd_work *work, struct ksmbd_file *fp);
134 struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id);
135 struct ksmbd_file *ksmbd_lookup_fd_cguid(char *cguid);
136 struct ksmbd_file *ksmbd_lookup_fd_inode(struct inode *inode);
137 unsigned int ksmbd_open_durable_fd(struct ksmbd_file *fp);
138 struct ksmbd_file *ksmbd_open_fd(struct ksmbd_work *work, struct file *filp);
139 void ksmbd_close_tree_conn_fds(struct ksmbd_work *work);
140 void ksmbd_close_session_fds(struct ksmbd_work *work);
141 int ksmbd_close_inode_fds(struct ksmbd_work *work, struct inode *inode);
142 int ksmbd_init_global_file_table(void);
143 void ksmbd_free_global_file_table(void);
144 void ksmbd_set_fd_limit(unsigned long limit);
149 int __init ksmbd_inode_hash_init(void);
150 void ksmbd_release_inode_hash(void);
152 enum KSMBD_INODE_STATUS {
153 KSMBD_INODE_STATUS_OK,
154 KSMBD_INODE_STATUS_UNKNOWN,
155 KSMBD_INODE_STATUS_PENDING_DELETE,
158 int ksmbd_query_inode_status(struct inode *inode);
159 bool ksmbd_inode_pending_delete(struct ksmbd_file *fp);
160 void ksmbd_set_inode_pending_delete(struct ksmbd_file *fp);
161 void ksmbd_clear_inode_pending_delete(struct ksmbd_file *fp);
162 void ksmbd_fd_set_delete_on_close(struct ksmbd_file *fp,
164 int ksmbd_init_file_cache(void);
165 void ksmbd_exit_file_cache(void);
166 #endif /* __VFS_CACHE_H__ */