xref: /linux/fs/smb/server/mgmt/share_config.h (revision ae22a94997b8a03dcb3c922857c203246711f9d4)
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_share_config {
15 	char			*name;
16 	char			*path;
17 
18 	unsigned int		path_sz;
19 	unsigned int		flags;
20 	struct list_head	veto_list;
21 
22 	struct path		vfs_path;
23 
24 	atomic_t		refcount;
25 	struct hlist_node	hlist;
26 	unsigned short		create_mask;
27 	unsigned short		directory_mask;
28 	unsigned short		force_create_mode;
29 	unsigned short		force_directory_mode;
30 	unsigned short		force_uid;
31 	unsigned short		force_gid;
32 };
33 
34 #define KSMBD_SHARE_INVALID_UID	((__u16)-1)
35 #define KSMBD_SHARE_INVALID_GID	((__u16)-1)
36 
37 static inline umode_t
38 share_config_create_mode(struct ksmbd_share_config *share,
39 			 umode_t posix_mode)
40 {
41 	umode_t mode = (posix_mode ?: (umode_t)-1) & share->create_mask;
42 
43 	return mode | share->force_create_mode;
44 }
45 
46 static inline umode_t
47 share_config_directory_mode(struct ksmbd_share_config *share,
48 			    umode_t posix_mode)
49 {
50 	umode_t mode = (posix_mode ?: (umode_t)-1) & share->directory_mask;
51 
52 	return mode | share->force_directory_mode;
53 }
54 
55 static inline int test_share_config_flag(struct ksmbd_share_config *share,
56 					 int flag)
57 {
58 	return share->flags & flag;
59 }
60 
61 void ksmbd_share_config_del(struct ksmbd_share_config *share);
62 void __ksmbd_share_config_put(struct ksmbd_share_config *share);
63 
64 static inline void ksmbd_share_config_put(struct ksmbd_share_config *share)
65 {
66 	if (!atomic_dec_and_test(&share->refcount))
67 		return;
68 	__ksmbd_share_config_put(share);
69 }
70 
71 struct ksmbd_share_config *ksmbd_share_config_get(struct unicode_map *um,
72 						  const char *name);
73 bool ksmbd_share_veto_filename(struct ksmbd_share_config *share,
74 			       const char *filename);
75 #endif /* __SHARE_CONFIG_MANAGEMENT_H__ */
76