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