xref: /linux/fs/vboxsf/vfsmod.h (revision 0b8061c340b643e01da431dd60c75a41bb1d31ec)
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_options {
22 	unsigned long ttl;
23 	kuid_t uid;
24 	kgid_t gid;
25 	bool dmode_set;
26 	bool fmode_set;
27 	umode_t dmode;
28 	umode_t fmode;
29 	umode_t dmask;
30 	umode_t fmask;
31 };
32 
33 struct vboxsf_fs_context {
34 	struct vboxsf_options o;
35 	char *nls_name;
36 };
37 
38 /* per-shared folder information */
39 struct vboxsf_sbi {
40 	struct vboxsf_options o;
41 	struct shfl_fsobjinfo root_info;
42 	struct idr ino_idr;
43 	spinlock_t ino_idr_lock; /* This protects ino_idr */
44 	struct nls_table *nls;
45 	u32 next_generation;
46 	u32 root;
47 	int bdi_id;
48 };
49 
50 /* per-inode information */
51 struct vboxsf_inode {
52 	/* some information was changed, update data on next revalidate */
53 	int force_restat;
54 	/* list of open handles for this inode + lock protecting it */
55 	struct list_head handle_list;
56 	/* This mutex protects handle_list accesses */
57 	struct mutex handle_list_mutex;
58 	/* The VFS inode struct */
59 	struct inode vfs_inode;
60 };
61 
62 struct vboxsf_dir_info {
63 	struct list_head info_list;
64 };
65 
66 struct vboxsf_dir_buf {
67 	size_t entries;
68 	size_t free;
69 	size_t used;
70 	void *buf;
71 	struct list_head head;
72 };
73 
74 /* globals */
75 extern const struct inode_operations vboxsf_dir_iops;
76 extern const struct inode_operations vboxsf_lnk_iops;
77 extern const struct inode_operations vboxsf_reg_iops;
78 extern const struct file_operations vboxsf_dir_fops;
79 extern const struct file_operations vboxsf_reg_fops;
80 extern const struct address_space_operations vboxsf_reg_aops;
81 extern const struct dentry_operations vboxsf_dentry_ops;
82 
83 /* from utils.c */
84 struct inode *vboxsf_new_inode(struct super_block *sb);
85 void vboxsf_init_inode(struct vboxsf_sbi *sbi, struct inode *inode,
86 		       const struct shfl_fsobjinfo *info);
87 int vboxsf_create_at_dentry(struct dentry *dentry,
88 			    struct shfl_createparms *params);
89 int vboxsf_stat(struct vboxsf_sbi *sbi, struct shfl_string *path,
90 		struct shfl_fsobjinfo *info);
91 int vboxsf_stat_dentry(struct dentry *dentry, struct shfl_fsobjinfo *info);
92 int vboxsf_inode_revalidate(struct dentry *dentry);
93 int vboxsf_getattr(struct user_namespace *mnt_userns, const struct path *path,
94 		   struct kstat *kstat, u32 request_mask,
95 		   unsigned int query_flags);
96 int vboxsf_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
97 		   struct iattr *iattr);
98 struct shfl_string *vboxsf_path_from_dentry(struct vboxsf_sbi *sbi,
99 					    struct dentry *dentry);
100 int vboxsf_nlscpy(struct vboxsf_sbi *sbi, char *name, size_t name_bound_len,
101 		  const unsigned char *utf8_name, size_t utf8_len);
102 struct vboxsf_dir_info *vboxsf_dir_info_alloc(void);
103 void vboxsf_dir_info_free(struct vboxsf_dir_info *p);
104 int vboxsf_dir_read_all(struct vboxsf_sbi *sbi, struct vboxsf_dir_info *sf_d,
105 			u64 handle);
106 
107 /* from vboxsf_wrappers.c */
108 int vboxsf_connect(void);
109 void vboxsf_disconnect(void);
110 
111 int vboxsf_create(u32 root, struct shfl_string *parsed_path,
112 		  struct shfl_createparms *create_parms);
113 
114 int vboxsf_close(u32 root, u64 handle);
115 int vboxsf_remove(u32 root, struct shfl_string *parsed_path, u32 flags);
116 int vboxsf_rename(u32 root, struct shfl_string *src_path,
117 		  struct shfl_string *dest_path, u32 flags);
118 
119 int vboxsf_read(u32 root, u64 handle, u64 offset, u32 *buf_len, u8 *buf);
120 int vboxsf_write(u32 root, u64 handle, u64 offset, u32 *buf_len, u8 *buf);
121 
122 int vboxsf_dirinfo(u32 root, u64 handle,
123 		   struct shfl_string *parsed_path, u32 flags, u32 index,
124 		   u32 *buf_len, struct shfl_dirinfo *buf, u32 *file_count);
125 int vboxsf_fsinfo(u32 root, u64 handle, u32 flags,
126 		  u32 *buf_len, void *buf);
127 
128 int vboxsf_map_folder(struct shfl_string *folder_name, u32 *root);
129 int vboxsf_unmap_folder(u32 root);
130 
131 int vboxsf_readlink(u32 root, struct shfl_string *parsed_path,
132 		    u32 buf_len, u8 *buf);
133 int vboxsf_symlink(u32 root, struct shfl_string *new_path,
134 		   struct shfl_string *old_path, struct shfl_fsobjinfo *buf);
135 
136 int vboxsf_set_utf8(void);
137 int vboxsf_set_symlinks(void);
138 
139 #endif
140