1 /* This file contains open file and directory handle management functions.
3 * The entry points into this file are:
4 * get_handle open a handle for an inode and store the handle
5 * put_handle close any handles associated with an inode
8 * April 2009 (D.C. van Moolenbroek)
15 /*===========================================================================*
17 *===========================================================================*/
18 PUBLIC
int get_handle(ino
)
21 /* Get an open file or directory handle for an inode.
26 /* If we don't have a file handle yet, try to open the file now. */
27 if (ino
->i_flags
& I_HANDLE
)
30 if ((r
= verify_inode(ino
, path
, NULL
)) != OK
)
34 r
= hgfs_opendir(path
, &ino
->i_dir
);
38 r
= hgfs_open(path
, O_RDWR
, 0, &ino
->i_file
);
40 /* Protection or mount status might prevent us from writing. With the
41 * information that we have available, this is the best we can do..
43 if (state
.read_only
|| r
!= OK
)
44 r
= hgfs_open(path
, O_RDONLY
, 0, &ino
->i_file
);
50 ino
->i_flags
|= I_HANDLE
;
55 /*===========================================================================*
57 *===========================================================================*/
58 PUBLIC
void put_handle(ino
)
61 /* Close an open file or directory handle associated with an inode.
65 if (!(ino
->i_flags
& I_HANDLE
))
68 /* We ignore any errors here, because we can't deal with them anyway. */
70 r
= hgfs_closedir(ino
->i_dir
);
72 r
= hgfs_close(ino
->i_file
);
75 printf("HGFS: put_handle: handle close operation returned %d\n", r
);
77 ino
->i_flags
&= ~I_HANDLE
;