+/* Opens a file for the given INODE, of which it takes ownership,
+ and returns the new file. Returns a null pointer if an
+ allocation fails or if INODE is null. */
+struct file *
+file_open (struct inode *inode)
+{
+ struct file *file = calloc (1, sizeof *file);
+ if (inode != NULL && file != NULL)
+ {
+ file->inode = inode;
+ file->pos = 0;
+ file->deny_write = false;
+ return file;
+ }
+ else
+ {
+ inode_close (inode);
+ free (file);
+ return NULL;
+ }
+}
+
+/* Opens and returns a new file for the same inode as FILE.
+ Returns a null pointer if unsuccessful. */
+struct file *
+file_reopen (struct file *file)
+{
+ return file_open (inode_reopen (file->inode));
+}
+
+/* Closes FILE. */