Changeset 6317b33 in mainline for uspace/app/hdisk/func_gpt.c
- Timestamp:
- 2013-06-25T00:29:00Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 52f2c89
- Parents:
- cb328ab (diff), 1c8bfe8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/hdisk/func_gpt.c
rcb328ab r6317b33 34 34 35 35 #include <stdio.h> 36 #include <str.h> 36 37 #include <errno.h> 37 38 #include <str_error.h> … … 43 44 static int set_gpt_partition(tinput_t *, gpt_part_t *); 44 45 45 int add_gpt_part(tinput_t * in, union label_data * data) 46 { 47 gpt_part_t * p = gpt_alloc_partition(data->gpt->parts); 46 47 int construct_gpt_label(label_t *this) 48 { 49 this->layout = LYT_GPT; 50 this->alignment = 1; 51 52 this->add_part = add_gpt_part; 53 this->delete_part = delete_gpt_part; 54 this->new_label = new_gpt_label; 55 this->print_parts = print_gpt_parts; 56 this->read_parts = read_gpt_parts; 57 this->write_parts = write_gpt_parts; 58 this->extra_funcs = extra_gpt_funcs; 59 60 return this->new_label(this); 61 } 62 63 int add_gpt_part(label_t *this, tinput_t *in) 64 { 65 gpt_part_t * p = gpt_get_partition(this->data.gpt); 48 66 if (p == NULL) { 49 67 return ENOMEM; 50 68 } 51 69 52 70 return set_gpt_partition(in, p); 53 71 } 54 72 55 int delete_gpt_part(tinput_t * in, union label_data * data) 56 { 73 int delete_gpt_part(label_t *this, tinput_t *in) 74 { 75 int rc; 57 76 size_t idx; 58 77 59 78 printf("Number of the partition to delete (counted from 0): "); 60 79 idx = get_input_size_t(in); 61 62 if (gpt_remove_partition(data->gpt->parts, idx) == -1) { 80 81 rc = gpt_remove_partition(this->data.gpt, idx); 82 if (rc != EOK) { 63 83 printf("Warning: running low on memory, not resizing...\n"); 64 } 65 66 return EOK; 67 } 68 69 int destroy_gpt_label(union label_data *data) 70 { 71 return EOK; 72 } 73 74 int new_gpt_label(union label_data *data) 75 { 76 data->gpt->gpt = gpt_alloc_gpt_header(); 77 data->gpt->parts = gpt_alloc_partitions(); 78 return EOK; 79 } 80 81 int print_gpt_parts(union label_data *data) 84 return rc; 85 } 86 87 return EOK; 88 } 89 90 int destroy_gpt_label(label_t *this) 91 { 92 gpt_free_label(this->data.gpt); 93 return EOK; 94 } 95 96 int new_gpt_label(label_t *this) 97 { 98 this->data.gpt = gpt_alloc_label(); 99 return EOK; 100 } 101 102 int print_gpt_parts(label_t *this) 82 103 { 83 104 //int rc; … … 87 108 size_t i = 0; 88 109 89 gpt_part_foreach(data->gpt->parts, iter) { 110 gpt_part_foreach(this->data.gpt, iter) { 111 i++; 112 //FIXMEE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 113 if (gpt_get_part_type(iter) == GPT_PTE_UNUSED) 114 continue; 115 116 if (i % 20 == 0) 117 printf("%15s %10s %10s Type: Name:\n", "Start:", "End:", "Length:"); 118 90 119 //printf("\t%10u %10u %10u %3d\n", iter->start_addr, iter->start_addr + iter->length, 91 120 // iter->length, gpt_get_part_type(iter), gpt_get_part_name(iter)); 92 printf("%3u \t%10llu %10llu %10llu %3d %s\n", i, gpt_get_start_lba(iter), gpt_get_end_lba(iter),121 printf("%3u %10llu %10llu %10llu %3d %s\n", i-1, gpt_get_start_lba(iter), gpt_get_end_lba(iter), 93 122 gpt_get_end_lba(iter) - gpt_get_start_lba(iter), gpt_get_part_type(iter), 94 123 gpt_get_part_name(iter)); 95 i++; 96 } 97 124 } 125 98 126 //return rc; 99 127 return EOK; 100 128 } 101 129 102 int read_gpt_parts(service_id_t dev_handle, union label_data *data) 103 { 104 return EOK; 105 } 106 107 int write_gpt_parts(service_id_t dev_handle, union label_data * data) 108 { 109 int rc; 110 111 rc = gpt_write_partitions(data->gpt->parts, data->gpt->gpt, dev_handle); 130 int read_gpt_parts(label_t *this, service_id_t dev_handle) 131 { 132 int rc; 133 134 rc = gpt_read_header(this->data.gpt, dev_handle); 135 if (rc != EOK) { 136 printf("Error: Reading header failed: %d (%s)\n", rc, str_error(rc)); 137 return rc; 138 } 139 140 rc = gpt_read_partitions(this->data.gpt); 141 if (rc != EOK) { 142 printf("Error: Reading partitions failed: %d (%s)\n", rc, str_error(rc)); 143 return rc; 144 } 145 146 return EOK; 147 } 148 149 int write_gpt_parts(label_t *this, service_id_t dev_handle) 150 { 151 int rc; 152 153 rc = gpt_write_partitions(this->data.gpt, dev_handle); 112 154 if (rc != EOK) { 113 155 printf("Error: Writing partitions failed: %d (%s)\n", rc, str_error(rc)); 114 156 return rc; 115 157 } 116 117 rc = gpt_write_ gpt_header(data->gpt->gpt, dev_handle);118 if (rc != EOK) { 119 printf("Error: Writing partitionsfailed: %d (%s)\n", rc, str_error(rc));120 return rc; 121 } 122 123 return EOK; 124 } 125 126 int extra_gpt_funcs( tinput_t * in, service_id_t dev_handle, union label_data * data)158 159 rc = gpt_write_header(this->data.gpt, dev_handle); 160 if (rc != EOK) { 161 printf("Error: Writing header failed: %d (%s)\n", rc, str_error(rc)); 162 return rc; 163 } 164 165 return EOK; 166 } 167 168 int extra_gpt_funcs(label_t *this, tinput_t *in, service_id_t dev_handle) 127 169 { 128 170 printf("Not implemented.\n"); … … 130 172 } 131 173 132 static int set_gpt_partition(tinput_t * in, gpt_part_t *p)133 { 134 //int rc;135 174 static int set_gpt_partition(tinput_t *in, gpt_part_t *p) 175 { 176 int rc; 177 136 178 uint64_t sa, ea; 137 179 138 180 printf("Set starting address (number): "); 139 181 sa = get_input_uint64(in); 140 182 141 183 printf("Set end addres (number): "); 142 184 ea = get_input_uint64(in); 143 185 144 186 if (ea <= sa) { 145 187 printf("Invalid value.\n"); 146 188 return EINVAL; 147 189 } 148 149 150 //p->start_addr = sa; 190 151 191 gpt_set_start_lba(p, sa); 152 //p->length = ea - sa;153 192 gpt_set_end_lba(p, ea); 154 155 return EOK; 156 } 157 193 194 195 char *name; 196 rc = get_input_line(in, &name); 197 if (rc != EOK) { 198 printf("Error reading name: %d (%s)\n", rc, str_error(rc)); 199 return rc; 200 } 201 202 gpt_set_part_name(p, name, str_size(name)); 203 204 return EOK; 205 } 206
Note:
See TracChangeset
for help on using the changeset viewer.