static int fish_fh_open (struct vfs_class *me, struct vfs_s_fh *fh, int flags, int mode) { (void) mode; fh->u.fish.append = 0; /* File will be written only, so no need to retrieve it */ if (((flags & O_WRONLY) == O_WRONLY) && !(flags & (O_RDONLY | O_RDWR))) { fh->u.fish.append = flags & O_APPEND; if (!fh->ino->localname) { int tmp_handle = vfs_mkstemps (&fh->ino->localname, me->name, fh->ino->ent->name); if (tmp_handle == -1) return -1; close (tmp_handle); } return 0; } if (!fh->ino->localname) if (vfs_s_retrieve_file (me, fh->ino) == -1) return -1; if (!fh->ino->localname) vfs_die ("retrieve_file failed to fill in localname"); return 0; }
static const char * sfs_redirect (struct vfs_class *me, const char *name) { struct cachedfile *cur = head; char *cache; int handle; while (cur) { if (!strcmp (name, cur->name)) { vfs_stamp (&vfs_sfs_ops, cur); return cur->cache; } cur = cur->next; } handle = vfs_mkstemps (&cache, "sfs", name); if (handle == -1) { return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US"; } close (handle); if (!sfs_vfmake (me, name, cache)) { cur = g_new (struct cachedfile, 1); cur->name = g_strdup (name); cur->cache = cache; cur->next = head; head = cur; vfs_stamp_create (&vfs_sfs_ops, head); return cache; }
static vfs_path_t * mc_def_getlocalcopy (const vfs_path_t * filename_vpath) { vfs_path_t *tmp_vpath = NULL; int fdin = -1, fdout = -1; ssize_t i; char buffer[BUF_1K * 8]; struct stat mystat; fdin = mc_open (filename_vpath, O_RDONLY | O_LINEAR); if (fdin == -1) goto fail; fdout = vfs_mkstemps (&tmp_vpath, "vfs", vfs_path_get_last_path_str (filename_vpath)); if (fdout == -1) goto fail; while ((i = mc_read (fdin, buffer, sizeof (buffer))) > 0) { if (write (fdout, buffer, i) != i) goto fail; } if (i == -1) goto fail; i = mc_close (fdin); fdin = -1; if (i == -1) goto fail; i = close (fdout); fdout = -1; if (i == -1) { fdout = -1; goto fail; } if (mc_stat (filename_vpath, &mystat) != -1) mc_chmod (tmp_vpath, mystat.st_mode); return tmp_vpath; fail: vfs_path_free (tmp_vpath); if (fdout != -1) close (fdout); if (fdin != -1) mc_close (fdin); return NULL; }