3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <partition.h>
32 for (mnt
= mount_list
.next
; mnt
!= &mount_list
; mnt
= mnt
->next
)
33 kprintf ("%s on %s\n", mnt
->p
->name
, mnt
->mountpoint
);
36 partition_t
*mount_find (char *mountpoint
)
39 for (mnt
= mount_list
.next
; mnt
!= &mount_list
; mnt
= mnt
->next
)
40 if (!strcmp (mnt
->mountpoint
, mountpoint
))
46 unsigned mount_verify (partition_t
*p
, char *mountpoint
)
48 unsigned mp_len
= strlen (mountpoint
);
53 if (mount_find (mountpoint
))
56 if (!vfs_find (mountpoint
, mp_len
))
62 unsigned mount_register (partition_t
*p
, char *mountpoint
)
64 unsigned mp_len
= strlen (mountpoint
);
68 /* alloc and init context */
69 mnt
= (mount_t
*) kmalloc (sizeof (mount_t
));
74 memcpy (mnt
->mountpoint
, mountpoint
, mp_len
);
75 mnt
->mountpoint
[mp_len
] = '\0';
80 mnt
->next
= &mount_list
;
81 mnt
->prev
= mount_list
.prev
;
82 mnt
->prev
->next
= mnt
;
83 mnt
->next
->prev
= mnt
;
88 bool mount (partition_t
*p
, char *dir
, char *mountpoint
)
90 unsigned err
= mount_verify (p
, mountpoint
);
93 kprintf ("ERROR -> partition %s is already mounted to %s\n", p
->name
, mountpoint
);
97 kprintf ("ERROR -> mountpoint %s does not exists\n", mountpoint
);
101 dev_t
*dev
= (dev_t
*) dev_findbypartition (p
);
106 if (!dev
->handler (DEV_ACT_MOUNT
, p
, mountpoint
, dir
, NULL
)) {
107 kprintf ("ERROR -> mount failed: %s\n", p
->name
);
111 return mount_register (p
, mountpoint
);
114 bool umount (partition_t
*p
, char *mountpoint
)
119 unsigned mdir_len
= strlen (mountpoint
);
121 /* FIXME: you can umount wrong local directory */
122 if (mountpoint
[0] != '/') {
124 memcpy (mdir
+1, mountpoint
, mdir_len
);
127 memcpy (mdir
, mountpoint
, mdir_len
);
129 mdir
[mdir_len
] = '\0';
132 for (mnt
= mount_list
.next
; mnt
!= &mount_list
; mnt
= mnt
->next
) {
133 if (!strcmp (mnt
->mountpoint
, mdir
)) {
142 /*dev_t *dev = (dev_t *) dev_findbypartition (p);
147 if (!dev->handler (DEV_ACT_UMOUNT, p, mnt->mountpoint, dir, NULL)) {
148 kprintf ("ERROR -> umount failed: %s\n", p->name);
152 while (vfs_list_delbymp (mdir
))
155 mnt
->next
->prev
= mnt
->prev
;
156 mnt
->prev
->next
= mnt
->next
;