1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * fs/hmdfs/hmdfs_share.h 4 * 5 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 6 */ 7 8 #ifndef HMDFS_SHARE_H 9 #define HMDFS_SHARE_H 10 11 #include <linux/file.h> 12 #include <linux/slab.h> 13 #include <linux/namei.h> 14 15 #include "hmdfs_device_view.h" 16 #include "comm/connection.h" 17 18 #define HMDFS_SHARE_ITEM_TIMEOUT_S 120 19 #define HMDFS_SHARE_ITEMS_MAX 128 20 21 #define HMDFS_IOC 0xf2 22 #define HMDFS_IOC_SET_SHARE_PATH _IOW(HMDFS_IOC, 1, \ 23 struct hmdfs_share_control) 24 25 #define SHARE_RESERVED_DIR ".share" 26 #define SHARE_ALL_DEVICE "0" 27 28 struct hmdfs_share_control { 29 __u32 src_fd; 30 char cid[HMDFS_CID_SIZE]; 31 }; 32 33 struct hmdfs_share_item { 34 struct file *file; 35 struct qstr relative_path; 36 char cid[HMDFS_CID_SIZE]; 37 bool opened; 38 bool timeout; 39 struct list_head list; 40 struct delayed_work d_work; 41 struct hmdfs_share_table *hst; 42 }; 43 44 bool hmdfs_is_share_file(struct file *file); 45 struct hmdfs_share_item *hmdfs_lookup_share_item(struct hmdfs_share_table *st, 46 struct qstr *cur_relative_path); 47 int insert_share_item(struct hmdfs_share_table *st, struct qstr *relative_path, 48 struct file *file, char *cid); 49 void update_share_item(struct hmdfs_share_item *item, struct file *file, 50 char *cid); 51 bool in_share_dir(struct dentry *child_dentry); 52 inline bool is_share_dir(struct inode *inode, const char *name); 53 int get_path_from_share_table(struct hmdfs_sb_info *sbi, 54 struct dentry *cur_dentry, struct path *src_path); 55 56 void hmdfs_clear_share_item_offline(struct hmdfs_peer *conn); 57 void reset_item_opened_status(struct hmdfs_sb_info *sbi, const char *filename); 58 void hmdfs_close_share_item(struct hmdfs_sb_info *sbi, struct file *file, 59 char *cid); 60 int hmdfs_check_share_access_permission(struct hmdfs_sb_info *sbi, 61 const char *filename, char *cid); 62 63 int hmdfs_init_share_table(struct hmdfs_sb_info *sbi); 64 void hmdfs_clear_share_table(struct hmdfs_sb_info *sbi); 65 int hmdfs_clear_first_item(struct hmdfs_share_table *st); 66 67 #endif // HMDFS_SHARE_H 68