1 /* SPDX-License-Identifier: MIT */
3 * VirtualBox Shared Folders: host interface definition.
5 * Copyright (C) 2006-2018 Oracle Corporation
8 #ifndef SHFL_HOSTINTF_H
9 #define SHFL_HOSTINTF_H
11 #include <linux/vbox_vmmdev_types.h>
13 /* The max in/out buffer size for a FN_READ or FN_WRITE call */
14 #define SHFL_MAX_RW_COUNT (16 * SZ_1M)
17 * Structures shared between guest and the service
18 * can be relocated and use offsets to point to variable
21 * Shared folders protocol works with handles.
22 * Before doing any action on a file system object,
23 * one have to obtain the object handle via a SHFL_FN_CREATE
24 * request. A handle must be closed with SHFL_FN_CLOSE.
28 SHFL_FN_QUERY_MAPPINGS
= 1, /* Query mappings changes. */
29 SHFL_FN_QUERY_MAP_NAME
= 2, /* Query map name. */
30 SHFL_FN_CREATE
= 3, /* Open/create object. */
31 SHFL_FN_CLOSE
= 4, /* Close object handle. */
32 SHFL_FN_READ
= 5, /* Read object content. */
33 SHFL_FN_WRITE
= 6, /* Write new object content. */
34 SHFL_FN_LOCK
= 7, /* Lock/unlock a range in the object. */
35 SHFL_FN_LIST
= 8, /* List object content. */
36 SHFL_FN_INFORMATION
= 9, /* Query/set object information. */
37 /* Note function number 10 is not used! */
38 SHFL_FN_REMOVE
= 11, /* Remove object */
39 SHFL_FN_MAP_FOLDER_OLD
= 12, /* Map folder (legacy) */
40 SHFL_FN_UNMAP_FOLDER
= 13, /* Unmap folder */
41 SHFL_FN_RENAME
= 14, /* Rename object */
42 SHFL_FN_FLUSH
= 15, /* Flush file */
43 SHFL_FN_SET_UTF8
= 16, /* Select UTF8 filename encoding */
44 SHFL_FN_MAP_FOLDER
= 17, /* Map folder */
45 SHFL_FN_READLINK
= 18, /* Read symlink dest (as of VBox 4.0) */
46 SHFL_FN_SYMLINK
= 19, /* Create symlink (as of VBox 4.0) */
47 SHFL_FN_SET_SYMLINKS
= 20, /* Ask host to show symlinks (4.0+) */
50 /* Root handles for a mapping are of type u32, Root handles are unique. */
51 #define SHFL_ROOT_NIL UINT_MAX
53 /* Shared folders handle for an opened object are of type u64. */
54 #define SHFL_HANDLE_NIL ULLONG_MAX
56 /* Hardcoded maximum length (in chars) of a shared folder name. */
57 #define SHFL_MAX_LEN (256)
58 /* Hardcoded maximum number of shared folder mapping available to the guest. */
59 #define SHFL_MAX_MAPPINGS (64)
61 /** Shared folder string buffer structure. */
63 /** Allocated size of the string member in bytes. */
66 /** Length of string without trailing nul in bytes. */
69 /** UTF-8 or UTF-16 string. Nul terminated. */
73 u16 ucs2
[1]; /* misnomer, use utf16. */
76 VMMDEV_ASSERT_SIZE(shfl_string
, 6);
78 /* The size of shfl_string w/o the string part. */
79 #define SHFLSTRING_HEADER_SIZE 4
81 /* Calculate size of the string. */
82 static inline u32
shfl_string_buf_size(const struct shfl_string
*string
)
84 return string
? SHFLSTRING_HEADER_SIZE
+ string
->size
: 0;
87 /* Set user id on execution (S_ISUID). */
88 #define SHFL_UNIX_ISUID 0004000U
89 /* Set group id on execution (S_ISGID). */
90 #define SHFL_UNIX_ISGID 0002000U
91 /* Sticky bit (S_ISVTX / S_ISTXT). */
92 #define SHFL_UNIX_ISTXT 0001000U
94 /* Owner readable (S_IRUSR). */
95 #define SHFL_UNIX_IRUSR 0000400U
96 /* Owner writable (S_IWUSR). */
97 #define SHFL_UNIX_IWUSR 0000200U
98 /* Owner executable (S_IXUSR). */
99 #define SHFL_UNIX_IXUSR 0000100U
101 /* Group readable (S_IRGRP). */
102 #define SHFL_UNIX_IRGRP 0000040U
103 /* Group writable (S_IWGRP). */
104 #define SHFL_UNIX_IWGRP 0000020U
105 /* Group executable (S_IXGRP). */
106 #define SHFL_UNIX_IXGRP 0000010U
108 /* Other readable (S_IROTH). */
109 #define SHFL_UNIX_IROTH 0000004U
110 /* Other writable (S_IWOTH). */
111 #define SHFL_UNIX_IWOTH 0000002U
112 /* Other executable (S_IXOTH). */
113 #define SHFL_UNIX_IXOTH 0000001U
115 /* Named pipe (fifo) (S_IFIFO). */
116 #define SHFL_TYPE_FIFO 0010000U
117 /* Character device (S_IFCHR). */
118 #define SHFL_TYPE_DEV_CHAR 0020000U
119 /* Directory (S_IFDIR). */
120 #define SHFL_TYPE_DIRECTORY 0040000U
121 /* Block device (S_IFBLK). */
122 #define SHFL_TYPE_DEV_BLOCK 0060000U
123 /* Regular file (S_IFREG). */
124 #define SHFL_TYPE_FILE 0100000U
125 /* Symbolic link (S_IFLNK). */
126 #define SHFL_TYPE_SYMLINK 0120000U
127 /* Socket (S_IFSOCK). */
128 #define SHFL_TYPE_SOCKET 0140000U
129 /* Whiteout (S_IFWHT). */
130 #define SHFL_TYPE_WHITEOUT 0160000U
131 /* Type mask (S_IFMT). */
132 #define SHFL_TYPE_MASK 0170000U
134 /* Checks the mode flags indicate a directory (S_ISDIR). */
135 #define SHFL_IS_DIRECTORY(m) (((m) & SHFL_TYPE_MASK) == SHFL_TYPE_DIRECTORY)
136 /* Checks the mode flags indicate a symbolic link (S_ISLNK). */
137 #define SHFL_IS_SYMLINK(m) (((m) & SHFL_TYPE_MASK) == SHFL_TYPE_SYMLINK)
139 /** The available additional information in a shfl_fsobjattr object. */
140 enum shfl_fsobjattr_add
{
141 /** No additional information is available / requested. */
142 SHFLFSOBJATTRADD_NOTHING
= 1,
144 * The additional unix attributes (shfl_fsobjattr::u::unix_attr) are
145 * available / requested.
147 SHFLFSOBJATTRADD_UNIX
,
149 * The additional extended attribute size (shfl_fsobjattr::u::size) is
150 * available / requested.
152 SHFLFSOBJATTRADD_EASIZE
,
154 * The last valid item (inclusive).
155 * The valid range is SHFLFSOBJATTRADD_NOTHING thru
156 * SHFLFSOBJATTRADD_LAST.
158 SHFLFSOBJATTRADD_LAST
= SHFLFSOBJATTRADD_EASIZE
,
160 /** The usual 32-bit hack. */
161 SHFLFSOBJATTRADD_32BIT_SIZE_HACK
= 0x7fffffff
165 * Additional unix Attributes, these are available when
166 * shfl_fsobjattr.additional == SHFLFSOBJATTRADD_UNIX.
168 struct shfl_fsobjattr_unix
{
170 * The user owning the filesystem object (st_uid).
171 * This field is ~0U if not supported.
176 * The group the filesystem object is assigned (st_gid).
177 * This field is ~0U if not supported.
182 * Number of hard links to this filesystem object (st_nlink).
183 * This field is 1 if the filesystem doesn't support hardlinking or
184 * the information isn't available.
189 * The device number of the device which this filesystem object resides
190 * on (st_dev). This field is 0 if this information is not available.
195 * The unique identifier (within the filesystem) of this filesystem
196 * object (st_ino). Together with inode_id_device, this field can be
197 * used as a OS wide unique id, when both their values are not 0.
198 * This field is 0 if the information is not available.
203 * User flags (st_flags).
204 * This field is 0 if this information is not available.
209 * The current generation number (st_gen).
210 * This field is 0 if this information is not available.
215 * The device number of a char. or block device type object (st_rdev).
216 * This field is 0 if the file isn't a char. or block device or when
217 * the OS doesn't use the major+minor device idenfication scheme.
222 /** Extended attribute size. */
223 struct shfl_fsobjattr_easize
{
228 /** Shared folder filesystem object attributes. */
229 struct shfl_fsobjattr
{
230 /** Mode flags (st_mode). SHFL_UNIX_*, SHFL_TYPE_*, and SHFL_DOS_*. */
233 /** The additional attributes available. */
234 enum shfl_fsobjattr_add additional
;
237 * Additional attributes.
239 * Unless explicitly specified to an API, the API can provide additional
240 * data as it is provided by the underlying OS.
243 struct shfl_fsobjattr_unix unix_attr
;
244 struct shfl_fsobjattr_easize size
;
247 VMMDEV_ASSERT_SIZE(shfl_fsobjattr
, 44);
249 struct shfl_timespec
{
250 s64 ns_relative_to_unix_epoch
;
253 /** Filesystem object information structure. */
254 struct shfl_fsobjinfo
{
256 * Logical size (st_size).
257 * For normal files this is the size of the file.
258 * For symbolic links, this is the length of the path name contained
259 * in the symbolic link.
260 * For other objects this fields needs to be specified.
264 /** Disk allocation size (st_blocks * DEV_BSIZE). */
267 /** Time of last access (st_atime). */
268 struct shfl_timespec access_time
;
270 /** Time of last data modification (st_mtime). */
271 struct shfl_timespec modification_time
;
274 * Time of last status change (st_ctime).
275 * If not available this is set to modification_time.
277 struct shfl_timespec change_time
;
280 * Time of file birth (st_birthtime).
281 * If not available this is set to change_time.
283 struct shfl_timespec birth_time
;
286 struct shfl_fsobjattr attr
;
289 VMMDEV_ASSERT_SIZE(shfl_fsobjinfo
, 92);
292 * result of an open/create request.
293 * Along with handle value the result code
294 * identifies what has happened while
295 * trying to open the object.
297 enum shfl_create_result
{
299 /** Specified path does not exist. */
301 /** Path to file exists, but the last component does not. */
303 /** File already exists and either has been opened or not. */
305 /** New file was created. */
307 /** Existing file was replaced or overwritten. */
311 /* No flags. Initialization value. */
312 #define SHFL_CF_NONE (0x00000000)
315 * Only lookup the object, do not return a handle. When this is set all other
318 #define SHFL_CF_LOOKUP (0x00000001)
321 * Open parent directory of specified object.
322 * Useful for the corresponding Windows FSD flag
323 * and for opening paths like \\dir\\*.* to search the 'dir'.
325 #define SHFL_CF_OPEN_TARGET_DIRECTORY (0x00000002)
327 /* Create/open a directory. */
328 #define SHFL_CF_DIRECTORY (0x00000004)
331 * Open/create action to do if object exists
332 * and if the object does not exists.
333 * REPLACE file means atomically DELETE and CREATE.
334 * OVERWRITE file means truncating the file to 0 and
336 * When opening an existing directory REPLACE and OVERWRITE
337 * actions are considered invalid, and cause returning
338 * FILE_EXISTS with NIL handle.
340 #define SHFL_CF_ACT_MASK_IF_EXISTS (0x000000f0)
341 #define SHFL_CF_ACT_MASK_IF_NEW (0x00000f00)
343 /* What to do if object exists. */
344 #define SHFL_CF_ACT_OPEN_IF_EXISTS (0x00000000)
345 #define SHFL_CF_ACT_FAIL_IF_EXISTS (0x00000010)
346 #define SHFL_CF_ACT_REPLACE_IF_EXISTS (0x00000020)
347 #define SHFL_CF_ACT_OVERWRITE_IF_EXISTS (0x00000030)
349 /* What to do if object does not exist. */
350 #define SHFL_CF_ACT_CREATE_IF_NEW (0x00000000)
351 #define SHFL_CF_ACT_FAIL_IF_NEW (0x00000100)
353 /* Read/write requested access for the object. */
354 #define SHFL_CF_ACCESS_MASK_RW (0x00003000)
356 /* No access requested. */
357 #define SHFL_CF_ACCESS_NONE (0x00000000)
358 /* Read access requested. */
359 #define SHFL_CF_ACCESS_READ (0x00001000)
360 /* Write access requested. */
361 #define SHFL_CF_ACCESS_WRITE (0x00002000)
362 /* Read/Write access requested. */
363 #define SHFL_CF_ACCESS_READWRITE (0x00003000)
365 /* Requested share access for the object. */
366 #define SHFL_CF_ACCESS_MASK_DENY (0x0000c000)
368 /* Allow any access. */
369 #define SHFL_CF_ACCESS_DENYNONE (0x00000000)
370 /* Do not allow read. */
371 #define SHFL_CF_ACCESS_DENYREAD (0x00004000)
372 /* Do not allow write. */
373 #define SHFL_CF_ACCESS_DENYWRITE (0x00008000)
374 /* Do not allow access. */
375 #define SHFL_CF_ACCESS_DENYALL (0x0000c000)
377 /* Requested access to attributes of the object. */
378 #define SHFL_CF_ACCESS_MASK_ATTR (0x00030000)
380 /* No access requested. */
381 #define SHFL_CF_ACCESS_ATTR_NONE (0x00000000)
382 /* Read access requested. */
383 #define SHFL_CF_ACCESS_ATTR_READ (0x00010000)
384 /* Write access requested. */
385 #define SHFL_CF_ACCESS_ATTR_WRITE (0x00020000)
386 /* Read/Write access requested. */
387 #define SHFL_CF_ACCESS_ATTR_READWRITE (0x00030000)
390 * The file is opened in append mode.
391 * Ignored if SHFL_CF_ACCESS_WRITE is not set.
393 #define SHFL_CF_ACCESS_APPEND (0x00040000)
395 /** Create parameters buffer struct for SHFL_FN_CREATE call */
396 struct shfl_createparms
{
397 /** Returned handle of opened object. */
400 /** Returned result of the operation */
401 enum shfl_create_result result
;
407 * Attributes of object to create and
408 * returned actual attributes of opened/created object.
410 struct shfl_fsobjinfo info
;
413 /** Shared Folder directory information */
414 struct shfl_dirinfo
{
415 /** Full information about the object. */
416 struct shfl_fsobjinfo info
;
418 * The length of the short field (number of UTF16 chars).
419 * It is 16-bit for reasons of alignment.
423 * The short name for 8.3 compatibility.
424 * Empty string if not available.
427 struct shfl_string name
;
430 /** Shared folder filesystem properties. */
431 struct shfl_fsproperties
{
433 * The maximum size of a filesystem object name.
434 * This does not include the '\\0'.
436 u32 max_component_len
;
439 * True if the filesystem is remote.
440 * False if the filesystem is local.
445 * True if the filesystem is case sensitive.
446 * False if the filesystem is case insensitive.
451 * True if the filesystem is mounted read only.
452 * False if the filesystem is mounted read write.
457 * True if the filesystem can encode unicode object names.
460 bool supports_unicode
;
463 * True if the filesystem is compresses.
464 * False if it isn't or we don't know.
469 * True if the filesystem compresses of individual files.
470 * False if it doesn't or we don't know.
472 bool file_compression
;
474 VMMDEV_ASSERT_SIZE(shfl_fsproperties
, 12);
476 struct shfl_volinfo
{
477 s64 total_allocation_bytes
;
478 s64 available_allocation_bytes
;
479 u32 bytes_per_allocation_unit
;
480 u32 bytes_per_sector
;
482 struct shfl_fsproperties properties
;
486 /** SHFL_FN_MAP_FOLDER Parameters structure. */
487 struct shfl_map_folder
{
490 * Points to struct shfl_string buffer.
492 struct vmmdev_hgcm_function_parameter path
;
495 * pointer, out: SHFLROOT (u32)
496 * Root handle of the mapping which name is queried.
498 struct vmmdev_hgcm_function_parameter root
;
504 struct vmmdev_hgcm_function_parameter delimiter
;
507 * pointer, in: SHFLROOT (u32)
510 struct vmmdev_hgcm_function_parameter case_sensitive
;
514 /* Number of parameters */
515 #define SHFL_CPARMS_MAP_FOLDER (4)
518 /** SHFL_FN_UNMAP_FOLDER Parameters structure. */
519 struct shfl_unmap_folder
{
521 * pointer, in: SHFLROOT (u32)
522 * Root handle of the mapping which name is queried.
524 struct vmmdev_hgcm_function_parameter root
;
528 /* Number of parameters */
529 #define SHFL_CPARMS_UNMAP_FOLDER (1)
532 /** SHFL_FN_CREATE Parameters structure. */
535 * pointer, in: SHFLROOT (u32)
536 * Root handle of the mapping which name is queried.
538 struct vmmdev_hgcm_function_parameter root
;
542 * Points to struct shfl_string buffer.
544 struct vmmdev_hgcm_function_parameter path
;
548 * Points to struct shfl_createparms buffer.
550 struct vmmdev_hgcm_function_parameter parms
;
554 /* Number of parameters */
555 #define SHFL_CPARMS_CREATE (3)
558 /** SHFL_FN_CLOSE Parameters structure. */
561 * pointer, in: SHFLROOT (u32)
562 * Root handle of the mapping which name is queried.
564 struct vmmdev_hgcm_function_parameter root
;
568 * SHFLHANDLE (u64) of object to close.
570 struct vmmdev_hgcm_function_parameter handle
;
574 /* Number of parameters */
575 #define SHFL_CPARMS_CLOSE (2)
578 /** SHFL_FN_READ Parameters structure. */
581 * pointer, in: SHFLROOT (u32)
582 * Root handle of the mapping which name is queried.
584 struct vmmdev_hgcm_function_parameter root
;
588 * SHFLHANDLE (u64) of object to read from.
590 struct vmmdev_hgcm_function_parameter handle
;
594 * Offset to read from.
596 struct vmmdev_hgcm_function_parameter offset
;
600 * Bytes to read/How many were read.
602 struct vmmdev_hgcm_function_parameter cb
;
606 * Buffer to place data to.
608 struct vmmdev_hgcm_function_parameter buffer
;
612 /* Number of parameters */
613 #define SHFL_CPARMS_READ (5)
616 /** SHFL_FN_WRITE Parameters structure. */
619 * pointer, in: SHFLROOT (u32)
620 * Root handle of the mapping which name is queried.
622 struct vmmdev_hgcm_function_parameter root
;
626 * SHFLHANDLE (u64) of object to write to.
628 struct vmmdev_hgcm_function_parameter handle
;
632 * Offset to write to.
634 struct vmmdev_hgcm_function_parameter offset
;
638 * Bytes to write/How many were written.
640 struct vmmdev_hgcm_function_parameter cb
;
646 struct vmmdev_hgcm_function_parameter buffer
;
650 /* Number of parameters */
651 #define SHFL_CPARMS_WRITE (5)
656 * Listing information includes variable length RTDIRENTRY[EX] structures.
659 #define SHFL_LIST_NONE 0
660 #define SHFL_LIST_RETURN_ONE 1
662 /** SHFL_FN_LIST Parameters structure. */
665 * pointer, in: SHFLROOT (u32)
666 * Root handle of the mapping which name is queried.
668 struct vmmdev_hgcm_function_parameter root
;
672 * SHFLHANDLE (u64) of object to be listed.
674 struct vmmdev_hgcm_function_parameter handle
;
678 * List flags SHFL_LIST_*.
680 struct vmmdev_hgcm_function_parameter flags
;
684 * Bytes to be used for listing information/How many bytes were used.
686 struct vmmdev_hgcm_function_parameter cb
;
689 * pointer, in/optional
690 * Points to struct shfl_string buffer that specifies a search path.
692 struct vmmdev_hgcm_function_parameter path
;
696 * Buffer to place listing information to. (struct shfl_dirinfo)
698 struct vmmdev_hgcm_function_parameter buffer
;
702 * Indicates a key where the listing must be resumed.
703 * in: 0 means start from begin of object.
704 * out: 0 means listing completed.
706 struct vmmdev_hgcm_function_parameter resume_point
;
710 * Number of files returned
712 struct vmmdev_hgcm_function_parameter file_count
;
715 /* Number of parameters */
716 #define SHFL_CPARMS_LIST (8)
719 /** SHFL_FN_READLINK Parameters structure. */
720 struct shfl_readLink
{
722 * pointer, in: SHFLROOT (u32)
723 * Root handle of the mapping which name is queried.
725 struct vmmdev_hgcm_function_parameter root
;
729 * Points to struct shfl_string buffer.
731 struct vmmdev_hgcm_function_parameter path
;
735 * Buffer to place data to.
737 struct vmmdev_hgcm_function_parameter buffer
;
741 /* Number of parameters */
742 #define SHFL_CPARMS_READLINK (3)
745 /* SHFL_FN_INFORMATION */
747 /* Mask of Set/Get bit. */
748 #define SHFL_INFO_MODE_MASK (0x1)
749 /* Get information */
750 #define SHFL_INFO_GET (0x0)
751 /* Set information */
752 #define SHFL_INFO_SET (0x1)
754 /* Get name of the object. */
755 #define SHFL_INFO_NAME (0x2)
756 /* Set size of object (extend/trucate); only applies to file objects */
757 #define SHFL_INFO_SIZE (0x4)
758 /* Get/Set file object info. */
759 #define SHFL_INFO_FILE (0x8)
760 /* Get volume information. */
761 #define SHFL_INFO_VOLUME (0x10)
763 /** SHFL_FN_INFORMATION Parameters structure. */
764 struct shfl_information
{
766 * pointer, in: SHFLROOT (u32)
767 * Root handle of the mapping which name is queried.
769 struct vmmdev_hgcm_function_parameter root
;
773 * SHFLHANDLE (u64) of object to be listed.
775 struct vmmdev_hgcm_function_parameter handle
;
781 struct vmmdev_hgcm_function_parameter flags
;
785 * Bytes to be used for information/How many bytes were used.
787 struct vmmdev_hgcm_function_parameter cb
;
791 * Information to be set/get (shfl_fsobjinfo or shfl_string). Do not
792 * forget to set the shfl_fsobjinfo::attr::additional for a get
795 struct vmmdev_hgcm_function_parameter info
;
799 /* Number of parameters */
800 #define SHFL_CPARMS_INFORMATION (5)
805 #define SHFL_REMOVE_FILE (0x1)
806 #define SHFL_REMOVE_DIR (0x2)
807 #define SHFL_REMOVE_SYMLINK (0x4)
809 /** SHFL_FN_REMOVE Parameters structure. */
812 * pointer, in: SHFLROOT (u32)
813 * Root handle of the mapping which name is queried.
815 struct vmmdev_hgcm_function_parameter root
;
819 * Points to struct shfl_string buffer.
821 struct vmmdev_hgcm_function_parameter path
;
825 * remove flags (file/directory)
827 struct vmmdev_hgcm_function_parameter flags
;
831 #define SHFL_CPARMS_REMOVE (3)
836 #define SHFL_RENAME_FILE (0x1)
837 #define SHFL_RENAME_DIR (0x2)
838 #define SHFL_RENAME_REPLACE_IF_EXISTS (0x4)
840 /** SHFL_FN_RENAME Parameters structure. */
843 * pointer, in: SHFLROOT (u32)
844 * Root handle of the mapping which name is queried.
846 struct vmmdev_hgcm_function_parameter root
;
850 * Points to struct shfl_string src.
852 struct vmmdev_hgcm_function_parameter src
;
856 * Points to struct shfl_string dest.
858 struct vmmdev_hgcm_function_parameter dest
;
862 * rename flags (file/directory)
864 struct vmmdev_hgcm_function_parameter flags
;
868 #define SHFL_CPARMS_RENAME (4)
871 /** SHFL_FN_SYMLINK Parameters structure. */
872 struct shfl_symlink
{
874 * pointer, in: SHFLROOT (u32)
875 * Root handle of the mapping which name is queried.
877 struct vmmdev_hgcm_function_parameter root
;
881 * Points to struct shfl_string of path for the new symlink.
883 struct vmmdev_hgcm_function_parameter new_path
;
887 * Points to struct shfl_string of destination for symlink.
889 struct vmmdev_hgcm_function_parameter old_path
;
893 * Information about created symlink.
895 struct vmmdev_hgcm_function_parameter info
;
899 #define SHFL_CPARMS_SYMLINK (4)