3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
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/>.
31 for (mnt
= mount_list
.next
; mnt
!= &mount_list
; mnt
= mnt
->next
)
32 kprintf ("%s on %s\n", mnt
->dev
->devname
, mnt
->mountpoint
);
35 dev_t
*mount_find (char *mountpoint
)
38 for (mnt
= mount_list
.next
; mnt
!= &mount_list
; mnt
= mnt
->next
) {
39 if (!strcmp (mnt
->mountpoint
, mountpoint
))
46 unsigned mount_list_add (dev_t
*dev
, char *mountpoint
)
48 unsigned mp_len
= strlen (mountpoint
);
53 if (mount_find (mountpoint
))
56 if (vfs_list_findbymp (mountpoint
))
61 /* alloc and init context */
62 mnt
= (mount_t
*) kmalloc (sizeof (mount_t
));
64 memcpy (mnt
->mountpoint
, mountpoint
, mp_len
);
65 mnt
->mountpoint
[mp_len
] = '\0';
70 mnt
->next
= &mount_list
;
71 mnt
->prev
= mount_list
.prev
;
72 mnt
->prev
->next
= mnt
;
73 mnt
->next
->prev
= mnt
;
78 bool mount (dev_t
*dev
, char *dir
, char *mountpoint
)
80 if (dev
->attrib
& DEV_ATTR_BLOCK
) {
81 unsigned err
= mount_list_add (dev
, mountpoint
);
84 kprintf ("ERROR -> device %s is already mounted to %s\n", dev
->devname
, mountpoint
);
88 kprintf ("ERROR -> mountpoint %s does not exists\n", mountpoint
);
92 if (!dev
->handler (DEV_ACT_MOUNT
, mountpoint
, dir
, NULL
)) {
93 kprintf ("ERROR -> mount failed: %s\n", dev
->devname
);
99 kprintf ("ERROR -> device %s (%s) is'nt block type\n", dev
->devname
, dev
->desc
);
103 bool umount (dev_t
*dev
, char *mountpoint
)
107 for (mnt
= mount_list
.next
; mnt
!= &mount_list
; mnt
= mnt
->next
) {
108 if (!strcmp (mnt
->mountpoint
, mountpoint
) &&
116 mnt
->next
->prev
= mnt
->prev
;
117 mnt
->prev
->next
= mnt
->next
;