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 int share_config_create_mode(struct ksmbd_share_config *share, 38 umode_t posix_mode) 39 { 40 if (!share->force_create_mode) { 41 if (!posix_mode) 42 return share->create_mask; 43 else 44 return posix_mode & share->create_mask; 45 } 46 return share->force_create_mode & share->create_mask; 47 } 48 49 static inline int share_config_directory_mode(struct ksmbd_share_config *share, 50 umode_t posix_mode) 51 { 52 if (!share->force_directory_mode) { 53 if (!posix_mode) 54 return share->directory_mask; 55 else 56 return posix_mode & share->directory_mask; 57 } 58 59 return share->force_directory_mode & share->directory_mask; 60 } 61 62 static inline int test_share_config_flag(struct ksmbd_share_config *share, 63 int flag) 64 { 65 return share->flags & flag; 66 } 67 68 void ksmbd_share_config_del(struct ksmbd_share_config *share); 69 void __ksmbd_share_config_put(struct ksmbd_share_config *share); 70 71 static inline void ksmbd_share_config_put(struct ksmbd_share_config *share) 72 { 73 if (!atomic_dec_and_test(&share->refcount)) 74 return; 75 __ksmbd_share_config_put(share); 76 } 77 78 struct ksmbd_share_config *ksmbd_share_config_get(struct unicode_map *um, 79 const char *name); 80 bool ksmbd_share_veto_filename(struct ksmbd_share_config *share, 81 const char *filename); 82 #endif /* __SHARE_CONFIG_MANAGEMENT_H__ */ 83