1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * VirtualBox Guest Shared Folders support: module header. 4 * 5 * Copyright (C) 2006-2018 Oracle Corporation 6 */ 7 8 #ifndef VFSMOD_H 9 #define VFSMOD_H 10 11 #include <linux/backing-dev.h> 12 #include <linux/idr.h> 13 #include "shfl_hostintf.h" 14 15 #define DIR_BUFFER_SIZE SZ_16K 16 17 /* The cast is to prevent assignment of void * to pointers of arbitrary type */ 18 #define VBOXSF_SBI(sb) ((struct vboxsf_sbi *)(sb)->s_fs_info) 19 #define VBOXSF_I(i) container_of(i, struct vboxsf_inode, vfs_inode) 20 21 struct vboxsf_handle; 22 23 struct vboxsf_options { 24 unsigned long ttl; 25 kuid_t uid; 26 kgid_t gid; 27 bool dmode_set; 28 bool fmode_set; 29 umode_t dmode; 30 umode_t fmode; 31 umode_t dmask; 32 umode_t fmask; 33 }; 34 35 struct vboxsf_fs_context { 36 struct vboxsf_options o; 37 char *nls_name; 38 }; 39 40 /* per-shared folder information */ 41 struct vboxsf_sbi { 42 struct vboxsf_options o; 43 struct shfl_fsobjinfo root_info; 44 struct idr ino_idr; 45 spinlock_t ino_idr_lock; /* This protects ino_idr */ 46 struct nls_table *nls; 47 u32 next_generation; 48 u32 root; 49 int bdi_id; 50 bool case_insensitive; 51 }; 52 53 /* per-inode information */ 54 struct vboxsf_inode { 55 /* some information was changed, update data on next revalidate */ 56 int force_restat; 57 /* list of open handles for this inode + lock protecting it */ 58 struct list_head handle_list; 59 /* This mutex protects handle_list accesses */ 60 struct mutex handle_list_mutex; 61 /* The VFS inode struct */ 62 struct inode vfs_inode; 63 }; 64 65 struct vboxsf_dir_info { 66 struct list_head info_list; 67 }; 68 69 struct vboxsf_dir_buf { 70 size_t entries; 71 size_t free; 72 size_t used; 73 void *buf; 74 struct list_head head; 75 }; 76 77 /* globals */ 78 extern const struct inode_operations vboxsf_dir_iops; 79 extern const struct inode_operations vboxsf_lnk_iops; 80 extern const struct inode_operations vboxsf_reg_iops; 81 extern const struct file_operations vboxsf_dir_fops; 82 extern const struct file_operations vboxsf_reg_fops; 83 extern const struct address_space_operations vboxsf_reg_aops; 84 extern const struct dentry_operations vboxsf_dentry_ops; 85 86 /* from file.c */ 87 struct vboxsf_handle *vboxsf_create_sf_handle(struct inode *inode, 88 u64 handle, u32 access_flags); 89 void vboxsf_release_sf_handle(struct inode *inode, struct vboxsf_handle *sf_handle); 90 91 /* from utils.c */ 92 struct inode *vboxsf_new_inode(struct super_block *sb); 93 int vboxsf_init_inode(struct vboxsf_sbi *sbi, struct inode *inode, 94 const struct shfl_fsobjinfo *info, bool reinit); 95 int vboxsf_create_at_dentry(struct dentry *dentry, 96 struct shfl_createparms *params); 97 int vboxsf_stat(struct vboxsf_sbi *sbi, struct shfl_string *path, 98 struct shfl_fsobjinfo *info); 99 int vboxsf_stat_dentry(struct dentry *dentry, struct shfl_fsobjinfo *info); 100 int vboxsf_inode_revalidate(struct dentry *dentry); 101 int vboxsf_getattr(struct mnt_idmap *idmap, const struct path *path, 102 struct kstat *kstat, u32 request_mask, 103 unsigned int query_flags); 104 int vboxsf_setattr(struct mnt_idmap *idmap, struct dentry *dentry, 105 struct iattr *iattr); 106 struct shfl_string *vboxsf_path_from_dentry(struct vboxsf_sbi *sbi, 107 struct dentry *dentry); 108 int vboxsf_nlscpy(struct vboxsf_sbi *sbi, char *name, size_t name_bound_len, 109 const unsigned char *utf8_name, size_t utf8_len); 110 struct vboxsf_dir_info *vboxsf_dir_info_alloc(void); 111 void vboxsf_dir_info_free(struct vboxsf_dir_info *p); 112 int vboxsf_dir_read_all(struct vboxsf_sbi *sbi, struct vboxsf_dir_info *sf_d, 113 u64 handle); 114 115 int vboxsf_query_case_sensitive(struct vboxsf_sbi *sbi); 116 117 struct file_kattr; 118 int vboxsf_fileattr_get(struct dentry *dentry, struct file_kattr *fa); 119 120 /* from vboxsf_wrappers.c */ 121 int vboxsf_connect(void); 122 void vboxsf_disconnect(void); 123 124 int vboxsf_create(u32 root, struct shfl_string *parsed_path, 125 struct shfl_createparms *create_parms); 126 127 int vboxsf_close(u32 root, u64 handle); 128 int vboxsf_remove(u32 root, struct shfl_string *parsed_path, u32 flags); 129 int vboxsf_rename(u32 root, struct shfl_string *src_path, 130 struct shfl_string *dest_path, u32 flags); 131 132 int vboxsf_read(u32 root, u64 handle, u64 offset, u32 *buf_len, u8 *buf); 133 int vboxsf_write(u32 root, u64 handle, u64 offset, u32 *buf_len, u8 *buf); 134 135 int vboxsf_dirinfo(u32 root, u64 handle, 136 struct shfl_string *parsed_path, u32 flags, u32 index, 137 u32 *buf_len, struct shfl_dirinfo *buf, u32 *file_count); 138 int vboxsf_fsinfo(u32 root, u64 handle, u32 flags, 139 u32 *buf_len, void *buf); 140 141 int vboxsf_map_folder(struct shfl_string *folder_name, u32 *root); 142 int vboxsf_unmap_folder(u32 root); 143 144 int vboxsf_readlink(u32 root, struct shfl_string *parsed_path, 145 u32 buf_len, u8 *buf); 146 int vboxsf_symlink(u32 root, struct shfl_string *new_path, 147 struct shfl_string *old_path, struct shfl_fsobjinfo *buf); 148 149 int vboxsf_set_utf8(void); 150 int vboxsf_set_symlinks(void); 151 152 #endif 153