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/>.
23 #include <partition.h>
27 partition_t partition_list
;
28 extern vfs_t vfs_list
;
30 partition_t
*partition_find (char *name
)
32 partition_t
*partition
;
33 for (partition
= partition_list
.next
; partition
!= &partition_list
; partition
= partition
->next
) {
34 if (!strcmp (partition
->name
, name
))
41 /* limited only for _one_ partition per device */
42 partition_t
*partition_findbydev (dev_t
*dev
)
44 unsigned l
= strlen (dev
->devname
);
46 partition_t
*partition
;
47 for (partition
= partition_list
.next
; partition
!= &partition_list
; partition
= partition
->next
) {
48 if (!strncmp (partition
->name
, dev
->devname
, l
))
55 /* find partition by file in current directory */
56 partition_t
*partition_findbyfile (char *file
)
59 strcpy (pwd
, (char *) env_get ("PWD"));
62 for (vfs
= vfs_list
.next
; vfs
!= &vfs_list
; vfs
= vfs
->next
)
63 if (!strcmp (vfs
->mountpoint
, pwd
) &&
64 !cstrcmp (file
, vfs
->name
)) {
65 if (vfs
->attrib
& VFS_FILEATTR_DIR
) {
66 printf ("ERROR -> this is a directory, not an file\n");
70 /* check permissions */
71 if (vfs
->attrib
& VFS_FILEATTR_SYSTEM
&& strcmp ((char *) env_get ("USER"), "root")) {
72 printf ("ERROR -> only root can do that\n");
77 if (vfs
->attrib
& VFS_FILEATTR_MOUNTED
) {
78 partition_t
*p
= (partition_t
*) mount_find ((char *) env_get ("PWD"));
83 printf ("ERROR -> device not respond\n");
93 printf ("No such file : %s\n", file
);
98 partition_t
*partition_add (dev_t
*dev
, fs_t
*fs
)
105 for (i
= 0; i
< 256; i
++) {
106 sprintf (name
, "%s%u", dev
->devname
, i
);
107 printf ("#name: %s\n", name
);
109 if (partition_find (name
) == 0)
113 partition_t
*partition
;
115 /* alloc and init context */
116 partition
= (partition_t
*) kmalloc (sizeof (partition_t
));
117 memset (partition
, 0, sizeof (partition_t
));
119 strcpy (partition
->name
, name
);
124 partition
->fs
= (fs_t
*) fs_detect (partition
);
132 partition
->next
= &partition_list
;
133 partition
->prev
= partition_list
.prev
;
134 partition
->prev
->next
= partition
;
135 partition
->next
->prev
= partition
;
140 bool partition_del (partition_t
*partition
)
143 partition
->next
->prev
= partition
->prev
;
144 partition
->prev
->next
= partition
->next
;
153 unsigned int init_partition ()
155 partition_list
.next
= &partition_list
;
156 partition_list
.prev
= &partition_list
;