summaryrefslogtreecommitdiff
path: root/minix/lib/libpuffs/mount.c
blob: c3d712f3db5e3d0636fb2cf637797760e4d2f0b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Created (MFS based):
 *   June 2011 (Evgeniy Ivanov)
 */

#include "fs.h"
#include <fcntl.h>
#include <minix/vfsif.h>

/*===========================================================================*
 *				fs_mount				     *
 *===========================================================================*/
int fs_mount(dev_t __unused dev, unsigned int flags,
	struct fsdriver_node *root_node, unsigned int *res_flags)
{
  struct vattr *root_va;

  is_readonly_fs = !!(flags & REQ_RDONLY);

  /* Open root pnode */
  global_pu->pu_pn_root->pn_count = 1;

  /* Root pnode properties */
  root_va = &global_pu->pu_pn_root->pn_va;
  root_node->fn_ino_nr = root_va->va_fileid;
  root_node->fn_mode = root_va->va_mode;
  root_node->fn_size = root_va->va_size;
  root_node->fn_uid = root_va->va_uid;
  root_node->fn_gid = root_va->va_gid;
  root_node->fn_dev = NO_DEV;

  *res_flags = RES_NOFLAGS;

  mounted = TRUE;

  return(OK);
}


/*===========================================================================*
 *				fs_mountpt				     *
 *===========================================================================*/
int fs_mountpt(ino_t ino_nr)
{
/* This function looks up the mount point, it checks the condition whether
 * the partition can be mounted on the pnode or not.
 */
  int r = OK;
  struct puffs_node *pn;
  mode_t bits;

  if ((pn = puffs_pn_nodewalk(global_pu, find_inode_cb, &ino_nr)) == NULL)
	return(EINVAL);

  if (pn->pn_mountpoint) r = EBUSY;

  /* It may not be special. */
  bits = pn->pn_va.va_mode & I_TYPE;
  if(bits == I_BLOCK_SPECIAL || bits == I_CHAR_SPECIAL) r = ENOTDIR;

  if (r == OK)
	pn->pn_mountpoint = TRUE;

  return(r);
}


/*===========================================================================*
 *				fs_unmount				     *
 *===========================================================================*/
void fs_unmount(void)
{
  int error;

  /* Always force unmounting, as VFS will not tolerate failure. */
  error = global_pu->pu_ops.puffs_fs_unmount(global_pu, MNT_FORCE);
  if (error) {
	lpuffs_debug("user handler failed to unmount filesystem!\
		Force unmount!\n");
  }

  fs_sync();

  /* Finish off the unmount. */
  PU_SETSTATE(global_pu, PUFFS_STATE_UNMOUNTED);
  mounted = FALSE;
  global_pu->pu_pn_root->pn_count--;
}