3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <partition.h>
26 extern dev_t dev_list
;
27 extern partition_t partition_list
;
28 extern char *argparse (char *cmd
);
30 int fdisk (char *parm
, unsigned len
)
40 memcpy (str
, parm
, len
);
43 char *a1
= argparse (str
);
44 char *a2
= argparse (a1
);
45 char *a3
= argparse (a2
);
48 for (i
= 0; i
< len
; i
++) {
56 printf ("fdisk: Device '%s' is not found\n", parm
);
62 if (id
< 0 || id
> 3) {
63 printf ("fdisk: Wrong partition ID, values 0-3 are correct\n");
67 int mbytes
= atoi (a3
);
70 printf ("fdisk: Wrong partition size, please set size in MBytes\n");
76 /*ntable[0] = (ptable_t *) kmalloc (sizeof (ptable_t));
77 ntable[1] = (ptable_t *) kmalloc (sizeof (ptable_t));
78 ntable[2] = (ptable_t *) kmalloc (sizeof (ptable_t));
79 ntable[3] = (ptable_t *) kmalloc (sizeof (ptable_t));
81 if (!ntable[0] || !ntable[1] || !ntable[2] || !ntable[3])
84 memset (&ntable
[0], 0, sizeof (ptable_t
));
85 memset (&ntable
[1], 0, sizeof (ptable_t
));
86 memset (&ntable
[2], 0, sizeof (ptable_t
));
87 memset (&ntable
[3], 0, sizeof (ptable_t
));
89 ntable
[id
].type
= strtol (a2
, 0, 16);
91 printf ("Partition %s%d (type: 0x%x; size: %dMBytes)\nDo you want to continue ? (y/N)\n", dev
->devname
, id
, ntable
[id
].type
, mbytes
);
96 if (c
== 'y' || c
== 'Y')
98 if (c
== 'n' || c
== 'N')
104 ntable
[id
].blocks
= (mbytes
* 1024 * 1024) / 512;
107 partition_table_new (dev
, (ptable_t
*) &ntable
);
109 printf ("fdisk: Partition %s%d (type: 0x%x; size: %dMBytes) was created\n", dev
->devname
, id
, ntable
[id
].type
, mbytes
);
114 for (dev
= dev_list
.next
; dev
!= &dev_list
; dev
= dev
->next
) {
115 if (dev
->attrib
== DEV_ATTR_BLOCK
) {
116 printf ("%s: %s\n", dev
->devname
, dev
->desc
);
118 unsigned l
= strlen (dev
->devname
);
121 for (p
= partition_list
.next
; p
!= &partition_list
; p
= p
->next
) {
122 if (!strncmp (p
->name
, dev
->devname
, l
))
123 printf (" %c %s : %s\n", 192, p
->name
, p
->fs
->name
);