Line data Source code
1 : /* $OpenBSD: fuse_file.c,v 1.9 2016/08/30 16:45:54 natano Exp $ */
2 : /*
3 : * Copyright (c) 2012-2013 Sylvestre Gallon <ccna.syl@gmail.com>
4 : *
5 : * Permission to use, copy, modify, and distribute this software for any
6 : * purpose with or without fee is hereby granted, provided that the above
7 : * copyright notice and this permission notice appear in all copies.
8 : *
9 : * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 : * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 : * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 : * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 : * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 : * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 : * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 : */
17 :
18 : #include <sys/param.h>
19 : #include <sys/systm.h>
20 : #include <sys/stat.h>
21 : #include <sys/statvfs.h>
22 : #include <sys/vnode.h>
23 : #include <sys/fusebuf.h>
24 :
25 : #include "fusefs_node.h"
26 : #include "fusefs.h"
27 :
28 : int
29 0 : fusefs_file_open(struct fusefs_mnt *fmp, struct fusefs_node *ip,
30 : enum fufh_type fufh_type, int flags, int isdir, struct proc *p)
31 : {
32 : struct fusebuf *fbuf;
33 : int error = 0;
34 :
35 0 : if (!fmp->sess_init)
36 0 : return (0);
37 :
38 0 : fbuf = fb_setup(0, ip->ufs_ino.i_number,
39 0 : ((isdir) ? FBT_OPENDIR : FBT_OPEN), p);
40 0 : fbuf->fb_io_flags = flags;
41 :
42 0 : error = fb_queue(fmp->dev, fbuf);
43 0 : if (error) {
44 0 : fb_delete(fbuf);
45 0 : return (error);
46 : }
47 :
48 0 : ip->fufh[fufh_type].fh_id = fbuf->fb_io_fd;
49 0 : ip->fufh[fufh_type].fh_type = fufh_type;
50 :
51 0 : fb_delete(fbuf);
52 0 : return (0);
53 0 : }
54 :
55 : int
56 0 : fusefs_file_close(struct fusefs_mnt *fmp, struct fusefs_node * ip,
57 : enum fufh_type fufh_type, int flags, int isdir, struct proc *p)
58 : {
59 : struct fusebuf *fbuf;
60 : int error = 0;
61 :
62 0 : if (fmp->sess_init) {
63 0 : fbuf = fb_setup(0, ip->ufs_ino.i_number,
64 0 : ((isdir) ? FBT_RELEASEDIR : FBT_RELEASE), p);
65 0 : fbuf->fb_io_fd = ip->fufh[fufh_type].fh_id;
66 0 : fbuf->fb_io_flags = flags;
67 :
68 0 : error = fb_queue(fmp->dev, fbuf);
69 0 : if (error && (error != ENOSYS))
70 0 : printf("fusefs: file error %d\n", error);
71 :
72 0 : fb_delete(fbuf);
73 0 : }
74 :
75 0 : ip->fufh[fufh_type].fh_id = (uint64_t)-1;
76 0 : ip->fufh[fufh_type].fh_type = FUFH_INVALID;
77 :
78 0 : return (error);
79 : }
80 :
81 : uint64_t
82 0 : fusefs_fd_get(struct fusefs_node *ip, enum fufh_type type)
83 : {
84 0 : if (ip->fufh[type].fh_type == FUFH_INVALID)
85 0 : type = FUFH_RDWR;
86 :
87 0 : return (ip->fufh[type].fh_id);
88 : }
|