xref: /openbmc/linux/fs/smb/server/mgmt/share_config.h (revision 2ae1beb3)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *   Copyright (C) 2018 Samsung Electronics Co., Ltd.
4  */
5 
6 #ifndef __SHARE_CONFIG_MANAGEMENT_H__
7 #define __SHARE_CONFIG_MANAGEMENT_H__
8 
9 #include <linux/workqueue.h>
10 #include <linux/hashtable.h>
11 #include <linux/path.h>
12 #include <linux/unicode.h>
13 
14 struct ksmbd_work;
15 
16 struct ksmbd_share_config {
17 	char			*name;
18 	char			*path;
19 
20 	unsigned int		path_sz;
21 	unsigned int		flags;
22 	struct list_head	veto_list;
23 
24 	struct path		vfs_path;
25 
26 	atomic_t		refcount;
27 	struct hlist_node	hlist;
28 	unsigned short		create_mask;
29 	unsigned short		directory_mask;
30 	unsigned short		force_create_mode;
31 	unsigned short		force_directory_mode;
32 	unsigned short		force_uid;
33 	unsigned short		force_gid;
34 };
35 
36 #define KSMBD_SHARE_INVALID_UID	((__u16)-1)
37 #define KSMBD_SHARE_INVALID_GID	((__u16)-1)
38 
39 static inline umode_t
40 share_config_create_mode(struct ksmbd_share_config *share,
41 			 umode_t posix_mode)
42 {
43 	umode_t mode = (posix_mode ?: (umode_t)-1) & share->create_mask;
44 
45 	return mode | share->force_create_mode;
46 }
47 
48 static inline umode_t
49 share_config_directory_mode(struct ksmbd_share_config *share,
50 			    umode_t posix_mode)
51 {
52 	umode_t mode = (posix_mode ?: (umode_t)-1) & share->directory_mask;
53 
54 	return mode | share->force_directory_mode;
55 }
56 
57 static inline int test_share_config_flag(struct ksmbd_share_config *share,
58 					 int flag)
59 {
60 	return share->flags & flag;
61 }
62 
63 void ksmbd_share_config_del(struct ksmbd_share_config *share);
64 void __ksmbd_share_config_put(struct ksmbd_share_config *share);
65 
66 static inline void ksmbd_share_config_put(struct ksmbd_share_config *share)
67 {
68 	if (!atomic_dec_and_test(&share->refcount))
69 		return;
70 	__ksmbd_share_config_put(share);
71 }
72 
73 struct ksmbd_share_config *ksmbd_share_config_get(struct ksmbd_work *work,
74 						  const char *name);
75 bool ksmbd_share_veto_filename(struct ksmbd_share_config *share,
76 			       const char *filename);
77 #endif /* __SHARE_CONFIG_MANAGEMENT_H__ */
78