forked from namjaejeon/ksmbd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfh.h
199 lines (167 loc) · 5.37 KB
/
fh.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2016 Namjae Jeon <[email protected]>
* Copyright (C) 2018 Samsung Electronics Co., Ltd.
*/
#ifndef __CIFSD_FH_H
#define __CIFSD_FH_H
#include <linux/file.h>
#include <linux/fdtable.h>
#include <linux/fs.h>
#include "glob.h"
#include "vfs.h"
/* Windows style file permissions for extended response */
#define FILE_GENERIC_ALL 0x1F01FF
#define FILE_GENERIC_READ 0x120089
#define FILE_GENERIC_WRITE 0x120116
#define FILE_GENERIC_EXECUTE 0X1200a0
/* Max id limit is 0xFFFF, so create bitmap with only this size*/
#define CIFSD_BITMAP_SIZE 0xFFFF
#define CIFSD_START_FID 0
#define CIFSD_NO_FID (-1ULL)
#define cifsd_set_bit __set_bit_le
#define cifsd_test_and_set_bit __test_and_set_bit_le
#define cifsd_test_bit test_bit_le
#define cifsd_clear_bit __clear_bit_le
#define cifsd_test_and_clear_bit __test_and_clear_bit_le
#define cifsd_find_next_zero_bit find_next_zero_bit_le
#define cifsd_find_next_bit find_next_bit_le
#define FP_FILENAME(fp) fp->filp->f_path.dentry->d_name.name
#define FP_INODE(fp) fp->filp->f_path.dentry->d_inode
#define PARENT_INODE(fp) fp->filp->f_path.dentry->d_parent->d_inode
#define ATTR_FP(fp) (fp->attrib_only && \
(fp->cdoption != FILE_OVERWRITE_IF_LE && \
fp->cdoption != FILE_OVERWRITE_LE && \
fp->cdoption != FILE_SUPERSEDE_LE))
#define S_DEL_PENDING 1
#define S_DEL_ON_CLS 2
#define S_DEL_ON_CLS_STREAM 8
/* FP STATE */
#define FP_NEW 0
#define FP_FREEING 1
struct cifsd_tcp_conn;
struct cifsd_session;
struct cifsd_lock {
struct file_lock *fl;
struct list_head glist;
struct list_head llist;
unsigned int flags;
unsigned int cmd;
int zero_len;
unsigned long long start;
unsigned long long end;
};
struct stream {
char *name;
int type;
ssize_t size;
};
struct cifsd_inode {
spinlock_t m_lock;
atomic_t m_count;
atomic_t op_count;
struct inode *m_inode;
unsigned int m_flags;
struct hlist_node m_hash;
struct list_head m_fp_list;
struct list_head m_op_list;
struct oplock_info *m_opinfo;
char *stream_name;
};
struct cifsd_file {
struct file *filp;
char *filename;
uint64_t persistent_id;
unsigned int volatile_id;
spinlock_t f_lock;
struct cifsd_inode *f_ci;
struct cifsd_inode *f_parent_ci;
struct oplock_info *f_opinfo;
struct cifsd_tcp_conn *conn;
struct cifsd_session *sess;
struct cifsd_tree_connect *tcon;
int f_state;
__le32 daccess;
__le32 saccess;
__le32 coption;
__le32 cdoption;
__le32 fattr;
__u64 create_time;
bool is_durable;
bool is_resilient;
bool is_persistent;
bool is_nt_open;
bool delete_on_close;
bool attrib_only;
bool is_stream;
char client_guid[16];
char create_guid[16];
char app_instance_id[16];
struct stream stream;
struct list_head node;
struct list_head blocked_works;
int durable_timeout;
/* for SMB1 */
int pid;
/* conflict lock fail count for SMB1 */
unsigned int cflock_cnt;
/* last lock failure start offset for SMB1 */
unsigned long long llock_fstart;
/* if ls is happening on directory, below is valid*/
struct cifsd_readdir_data readdir_data;
int dot_dotdot[2];
int dirent_offset;
};
#define CIFSD_NR_OPEN_DEFAULT BITS_PER_LONG
/* fidtable structure */
struct fidtable {
unsigned int max_fids;
void **fileid;
unsigned int start_pos;
unsigned long *cifsd_bitmap;
};
struct fidtable_desc {
spinlock_t fidtable_lock;
struct fidtable *ftab;
};
int init_fidtable(struct fidtable_desc *ftab_desc);
void close_opens_from_fibtable(struct cifsd_session *sess,
struct cifsd_tree_connect *tcon);
void destroy_fidtable(struct cifsd_session *sess);
void free_fidtable(struct fidtable *ftab);
struct cifsd_file *
get_id_from_fidtable(struct cifsd_session *sess, uint64_t id);
int close_id(struct cifsd_session *sess, uint64_t id, uint64_t p_id);
int cifsd_get_unused_id(struct fidtable_desc *ftab_desc);
int cifsd_close_id(struct fidtable_desc *ftab_desc, int id);
struct cifsd_file *
insert_id_in_fidtable(struct cifsd_session *sess, struct cifsd_tree_connect *tcon,
unsigned int id, struct file *filp);
void delete_id_from_fidtable(struct cifsd_session *sess,
unsigned int id);
struct cifsd_file *get_fp(struct cifsd_work *work, int64_t req_vid,
int64_t req_pid);
void __init cifsd_inode_hash_init(void);
int cifsd_inode_init(struct cifsd_inode *ci, struct cifsd_file *fp);
void cifsd_inode_free(struct cifsd_inode *ci);
void cifsd_inode_hash(struct cifsd_inode *ci);
void cifsd_inode_unhash(struct cifsd_inode *ci);
struct cifsd_inode *cifsd_inode_lookup(struct cifsd_file *fp);
struct cifsd_inode *cifsd_inode_lookup_by_vfsinode(struct inode *inode);
struct cifsd_inode *cifsd_inode_get(struct cifsd_file *fp);
/* Persistent-ID operations */
int cifsd_insert_in_global_table(struct cifsd_session *sess,
struct cifsd_file *fp);
int close_persistent_id(uint64_t id);
void destroy_global_fidtable(void);
/* Durable handle functions */
struct cifsd_file *cifsd_get_global_fp(uint64_t pid);
int cifsd_reconnect_durable_fp(struct cifsd_session *sess, struct cifsd_file *fp,
struct cifsd_tree_connect *tcon);
struct cifsd_file *lookup_fp_clguid(char *createguid);
struct cifsd_file *lookup_fp_app_id(char *app_id);
struct cifsd_file *find_fp_using_filename(struct cifsd_session *sess,
char *filename);
struct cifsd_file *find_fp_using_inode(struct inode *inode);
int close_disconnected_handle(struct inode *inode);
#endif /* __CIFSD_FH_H */