source: mainline/uspace/app/hdisk/func_mbr.c@ ec50ac4a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ec50ac4a was ec50ac4a, checked in by Dominik Taborsky (AT DOT) <brembyseznamcz>, 13 years ago

initial hdisk

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2012, 2013 Dominik Taborsky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /** @addtogroup hdisk
30 * @{
31 */
32/** @file
33 */
34
35#include "func_mbr.h"
36
37int add_mbr_part(tinput_t * in, mbr_parts_t * parts)
38{
39 part_t * part = mbr_alloc_partition();
40
41 printf("Primary (p) or logical (l): ");
42 int input = getchar();
43
44 switch(input) {
45 case 'p':
46 mbr_set_flag(parts, ST_LOGIC, false);
47 case 'l':
48 mbr_set_flag(parts, ST_LOGIC, false);
49 default:
50 printf("Invalid type. Cancelled.");
51 return EINVAL;
52 }
53
54 set_mbr_partition(in, part);
55
56 mbr_add_partition(parts, part);
57}
58
59int delete_mbr_part(tinput_t * in, part_t * parts)
60{
61 char * str;
62 int rc;
63 part_t * temp = NULL;
64 part_t * p = parts;
65 uint32_t i, input = 0;
66 char * endptr;
67
68 printf("Number of the partition to delete (counted from 0): ");
69
70 if((rc = get_input(in, &str)) != EOK)
71 return rc;
72
73 //convert from string to base 10 number
74 if(str_uint32_t(str, &endptr, 10, true, &input) != EOK) {
75 printf("Invalid value. Canceled.\n");
76 return EINVAL;
77 }
78
79 free(str);
80
81 rc = mbr_remove_partition(parts, input);
82 if(rc != EOK) {
83 printf("Error: something.\n");
84 }
85
86 return EOK;
87}
88
89/** Print current partition scheme */
90void print_mbr_partitions(mbr_parts_t * parts)
91{
92 int num = 0;
93
94 printf("Current partition scheme:\n");
95 printf("\t\tBootable:\tStart:\tEnd:\tLength:\tType:\n");
96
97 mbr_part_foreach(parts, it) {
98 if (it->type == PT_UNUSED)
99 continue;
100
101 printf("\t P%d:\t", i);
102 if (p->bootable)
103 printf("*");
104 else
105 printf(" ");
106
107 printf("\t\t%llu\t%llu\t%llu\t%d\n", p->start_addr, p->start_addr + p->length, p->length, p->type);
108
109 ++num;
110 }*/
111
112 printf("%d partitions found.\n", num);
113}
114
115void write_mbr_parts(mbr_parts_t * parts, mbr_t * mbr, service_id_t dev_handle)
116{
117 int rc = mbr_write_partitions(parts, mbr, dev_handle);
118 if (rc != EOK) {
119 printf("Error occured during writing. (ERR: %d)\n", rc);
120 }
121}
Note: See TracBrowser for help on using the repository browser.