summaryrefslogtreecommitdiffstats
path: root/fuse/guestmount.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2010-12-07 14:49:34 +0000
committerRichard W.M. Jones <rjones@redhat.com>2010-12-07 14:49:34 +0000
commitde419e4bace5d5be58a87d76f0c63ec39f327d1a (patch)
tree0490fd8210de7cb34597656795e071736f03de7a /fuse/guestmount.c
parent97cbb842362e2548a59a1560c50e5f998fa5bda8 (diff)
downloadlibguestfs-de419e4bace5d5be58a87d76f0c63ec39f327d1a.tar.gz
libguestfs-de419e4bace5d5be58a87d76f0c63ec39f327d1a.tar.xz
libguestfs-de419e4bace5d5be58a87d76f0c63ec39f327d1a.zip
fuse: Fix emulation of open call.
We were being over-complex in this call. All the FUSE API requires this call to do is to check permissions.
Diffstat (limited to 'fuse/guestmount.c')
-rw-r--r--fuse/guestmount.c47
1 files changed, 5 insertions, 42 deletions
diff --git a/fuse/guestmount.c b/fuse/guestmount.c
index 1b3abf97..8fe91220 100644
--- a/fuse/guestmount.c
+++ b/fuse/guestmount.c
@@ -535,53 +535,16 @@ fg_utimens (const char *path, const struct timespec ts[2])
return 0;
}
-/* This call is quite hard to emulate through the guestfs(3) API. In
- * one sense it's a little like access (see above) because it tests
- * whether opening a file would succeed given the flags. But it also
- * has side effects such as truncating the file if O_TRUNC is given.
- * Therefore we need to emulate it ... painfully.
+/* All this function needs to do is to check that the requested open
+ * flags are valid. See the notes in <fuse/fuse.h>.
*/
static int
fg_open (const char *path, struct fuse_file_info *fi)
{
- int r, exists;
+ int flags = fi->flags & 3;
- if (fi->flags & O_WRONLY) {
- if (read_only)
- return -EROFS;
- }
-
- exists = guestfs_exists (g, path);
- if (exists == -1)
- return error ();
-
- if (fi->flags & O_CREAT) {
- if (read_only)
- return -EROFS;
-
- dir_cache_invalidate (path);
-
- /* Exclusive? File must not exist already. */
- if (fi->flags & O_EXCL) {
- if (exists)
- return -EEXIST;
- }
-
- /* Create? Touch it and optionally truncate it. */
- r = guestfs_touch (g, path);
- if (r == -1)
- return error ();
-
- if (fi->flags & O_TRUNC) {
- r = guestfs_truncate (g, path);
- if (r == -1)
- return error ();
- }
- } else {
- /* Not create, just check it exists. */
- if (!exists)
- return -ENOENT;
- }
+ if (read_only && flags != O_RDONLY)
+ return -EROFS;
return 0;
}