Lines Matching +full:guest +full:- +full:side
1 // SPDX-License-Identifier: MIT
3 * VirtualBox Guest Shared Folders support: Regular file inode and file ops.
5 * Copyright (C) 2006-2018 Oracle Corporation
9 #include <linux/page-flags.h>
31 return ERR_PTR(-ENOMEM); in vboxsf_create_sf_handle()
34 sf_i->force_restat = 1; in vboxsf_create_sf_handle()
37 sf_handle->handle = handle; in vboxsf_create_sf_handle()
38 sf_handle->root = VBOXSF_SBI(inode->i_sb)->root; in vboxsf_create_sf_handle()
39 sf_handle->access_flags = access_flags; in vboxsf_create_sf_handle()
40 kref_init(&sf_handle->refcount); in vboxsf_create_sf_handle()
42 mutex_lock(&sf_i->handle_list_mutex); in vboxsf_create_sf_handle()
43 list_add(&sf_handle->head, &sf_i->handle_list); in vboxsf_create_sf_handle()
44 mutex_unlock(&sf_i->handle_list_mutex); in vboxsf_create_sf_handle()
51 struct vboxsf_sbi *sbi = VBOXSF_SBI(inode->i_sb); in vboxsf_file_open()
66 if (file->f_flags & O_CREAT) { in vboxsf_file_open()
72 if (file->f_flags & O_TRUNC) in vboxsf_file_open()
78 if (file->f_flags & O_TRUNC) in vboxsf_file_open()
82 switch (file->f_flags & O_ACCMODE) { in vboxsf_file_open()
99 if (file->f_flags & O_APPEND) in vboxsf_file_open()
103 params.info.attr.mode = inode->i_mode; in vboxsf_file_open()
107 err = (params.result == SHFL_FILE_EXISTS) ? -EEXIST : -ENOENT; in vboxsf_file_open()
113 vboxsf_close(sbi->root, params.handle); in vboxsf_file_open()
117 file->private_data = sf_handle; in vboxsf_file_open()
126 vboxsf_close(sf_handle->root, sf_handle->handle); in vboxsf_handle_release()
134 mutex_lock(&sf_i->handle_list_mutex); in vboxsf_release_sf_handle()
135 list_del(&sf_handle->head); in vboxsf_release_sf_handle()
136 mutex_unlock(&sf_i->handle_list_mutex); in vboxsf_release_sf_handle()
138 kref_put(&sf_handle->refcount, vboxsf_handle_release); in vboxsf_release_sf_handle()
144 * When a file is closed on our (the guest) side, we want any subsequent in vboxsf_file_release()
145 * accesses done on the host side to see all changes done from our side. in vboxsf_file_release()
147 filemap_write_and_wait(inode->i_mapping); in vboxsf_file_release()
149 vboxsf_release_sf_handle(inode, file->private_data); in vboxsf_file_release()
159 filemap_write_and_wait(vma->vm_file->f_mapping); in vboxsf_vma_close()
174 vma->vm_ops = &vboxsf_file_vm_ops; in vboxsf_file_mmap()
183 * The vboxsf API between the guest and the host does not offer any functions
184 * to deal with this. There is no inode-generation to check for changes, no
187 * To avoid returning stale data when a file gets *opened* on our (the guest)
188 * side, we do a "stat" on the host side, then compare the mtime with the
189 * last known mtime and invalidate the page-cache if they differ.
198 * file->f_path.dentry and the stat will then fail if the file was unlinked
199 * or renamed (and there is no thing like NFS' silly-rename). So we get:
207 * This means that only data written on the host side before open() on
208 * the guest side is guaranteed to be seen by the guest. If necessary
209 * we may provide other read-cache strategies in the future and make this
231 struct vboxsf_handle *sf_handle = file->private_data; in vboxsf_read_folio()
239 err = vboxsf_read(sf_handle->root, sf_handle->handle, off, &nread, buf); in vboxsf_read_folio()
251 mutex_lock(&sf_i->handle_list_mutex); in vboxsf_get_write_handle()
252 list_for_each_entry(h, &sf_i->handle_list, head) { in vboxsf_get_write_handle()
253 if (h->access_flags == SHFL_CF_ACCESS_WRITE || in vboxsf_get_write_handle()
254 h->access_flags == SHFL_CF_ACCESS_READWRITE) { in vboxsf_get_write_handle()
255 kref_get(&h->refcount); in vboxsf_get_write_handle()
260 mutex_unlock(&sf_i->handle_list_mutex); in vboxsf_get_write_handle()
267 struct inode *inode = page->mapping->host; in vboxsf_writepage()
281 return -EBADF; in vboxsf_writepage()
284 err = vboxsf_write(sf_handle->root, sf_handle->handle, in vboxsf_writepage()
288 kref_put(&sf_handle->refcount, vboxsf_handle_release); in vboxsf_writepage()
292 sf_i->force_restat = 1; in vboxsf_writepage()
305 struct inode *inode = mapping->host; in vboxsf_write_end()
306 struct vboxsf_handle *sf_handle = file->private_data; in vboxsf_write_end()
314 folio_zero_range(folio, from + copied, len - copied); in vboxsf_write_end()
316 buf = kmap(&folio->page); in vboxsf_write_end()
317 err = vboxsf_write(sf_handle->root, sf_handle->handle, in vboxsf_write_end()
319 kunmap(&folio->page); in vboxsf_write_end()
327 VBOXSF_I(inode)->force_restat = 1; in vboxsf_write_end()
333 if (pos > inode->i_size) in vboxsf_write_end()
359 struct vboxsf_sbi *sbi = VBOXSF_SBI(inode->i_sb); in vboxsf_get_link()
365 return ERR_PTR(-ECHILD); in vboxsf_get_link()
374 return ERR_PTR(-ENOMEM); in vboxsf_get_link()
377 err = vboxsf_readlink(sbi->root, path, PATH_MAX, link); in vboxsf_get_link()