Changeset 1c8bfe8 in mainline
- Timestamp:
- 2013-06-25T00:27:47Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6317b33, 9256d093
- Parents:
- 6e8e4e19 (diff), cb328ab (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. - Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/hdisk/func_gpt.c
r6e8e4e19 r1c8bfe8 34 34 35 35 #include <stdio.h> 36 #include <str.h> 36 37 #include <errno.h> 37 38 #include <str_error.h> … … 60 61 } 61 62 62 int add_gpt_part(label_t *this, tinput_t * 63 { 64 gpt_part_t * p = gpt_ alloc_partition(this->data.gpt->parts);63 int add_gpt_part(label_t *this, tinput_t *in) 64 { 65 gpt_part_t * p = gpt_get_partition(this->data.gpt); 65 66 if (p == NULL) { 66 67 return ENOMEM; 67 68 } 68 69 69 70 return set_gpt_partition(in, p); 70 71 } 71 72 72 int delete_gpt_part(label_t *this, tinput_t * in) 73 { 73 int delete_gpt_part(label_t *this, tinput_t *in) 74 { 75 int rc; 74 76 size_t idx; 75 77 76 78 printf("Number of the partition to delete (counted from 0): "); 77 79 idx = get_input_size_t(in); 78 79 if (gpt_remove_partition(this->data.gpt->parts, idx) == -1) { 80 81 rc = gpt_remove_partition(this->data.gpt, idx); 82 if (rc != EOK) { 80 83 printf("Warning: running low on memory, not resizing...\n"); 81 } 82 84 return rc; 85 } 86 83 87 return EOK; 84 88 } … … 86 90 int destroy_gpt_label(label_t *this) 87 91 { 92 gpt_free_label(this->data.gpt); 88 93 return EOK; 89 94 } … … 91 96 int new_gpt_label(label_t *this) 92 97 { 93 this->data.gpt->gpt = gpt_alloc_gpt_header(); 94 this->data.gpt->parts = gpt_alloc_partitions(); 98 this->data.gpt = gpt_alloc_label(); 95 99 return EOK; 96 100 } … … 104 108 size_t i = 0; 105 109 106 gpt_part_foreach(this->data.gpt->parts, iter) { 110 gpt_part_foreach(this->data.gpt, iter) { 111 i++; 107 112 //FIXMEE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 108 if (gpt_get_part_type(iter) == 62)113 if (gpt_get_part_type(iter) == GPT_PTE_UNUSED) 109 114 continue; 115 116 if (i % 20 == 0) 117 printf("%15s %10s %10s Type: Name:\n", "Start:", "End:", "Length:"); 110 118 111 119 //printf("\t%10u %10u %10u %3d\n", iter->start_addr, iter->start_addr + iter->length, 112 120 // iter->length, gpt_get_part_type(iter), gpt_get_part_name(iter)); 113 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), 114 122 gpt_get_end_lba(iter) - gpt_get_start_lba(iter), gpt_get_part_type(iter), 115 123 gpt_get_part_name(iter)); 116 i++; 117 } 118 124 } 125 119 126 //return rc; 120 127 return EOK; … … 123 130 int read_gpt_parts(label_t *this, service_id_t dev_handle) 124 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 125 146 return EOK; 126 147 } … … 129 150 { 130 151 int rc; 131 132 rc = gpt_write_partitions(this->data.gpt ->parts, this->data.gpt->gpt, dev_handle);152 153 rc = gpt_write_partitions(this->data.gpt, dev_handle); 133 154 if (rc != EOK) { 134 155 printf("Error: Writing partitions failed: %d (%s)\n", rc, str_error(rc)); 135 156 return rc; 136 157 } 137 138 rc = gpt_write_ gpt_header(this->data.gpt->gpt, dev_handle);139 if (rc != EOK) { 140 printf("Error: Writing partitionsfailed: %d (%s)\n", rc, str_error(rc));141 return rc; 142 } 143 144 return EOK; 145 } 146 147 int extra_gpt_funcs(label_t *this, tinput_t * 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) 148 169 { 149 170 printf("Not implemented.\n"); … … 151 172 } 152 173 153 static int set_gpt_partition(tinput_t * in, gpt_part_t *p)154 { 155 //int rc;156 174 static int set_gpt_partition(tinput_t *in, gpt_part_t *p) 175 { 176 int rc; 177 157 178 uint64_t sa, ea; 158 179 159 180 printf("Set starting address (number): "); 160 181 sa = get_input_uint64(in); 161 182 162 183 printf("Set end addres (number): "); 163 184 ea = get_input_uint64(in); 164 185 165 186 if (ea <= sa) { 166 187 printf("Invalid value.\n"); 167 188 return EINVAL; 168 189 } 169 170 171 //p->start_addr = sa; 190 172 191 gpt_set_start_lba(p, sa); 173 //p->length = ea - sa;174 192 gpt_set_end_lba(p, ea); 175 176 return EOK; 177 } 178 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 -
uspace/lib/gpt/global.c
r6e8e4e19 r1c8bfe8 41 41 42 42 const struct partition_type gpt_ptypes[] = { 43 { "Unused entry", "00000000 -0000-0000-0000-000000000000" },44 { "MBR partition scheme", "024DEE41 -33E7-11D3-9D69-0008C781F39F" },45 { "EFI System", "C12A7328 -F81F-11D2-BA4B-00A0C93EC93B" },46 { "BIOS Boot", "21686148 -6449-6E6F-744E-656564454649" },47 { "Windows Reserved", "E3C9E316 -0B5C-4DB8-817D-F92DF00215AE" },48 { "Windows Basic data", "EBD0A0A2 -B9E5-4433-87C0-68B6B72699C7" },49 { "Windows LDM metadata", "5808C8AA -7E8F-42E0-85D2-E1E90434CFB3" },50 { "Windows LDM data", "AF9B60A0 -1431-4F62-BC68-3311714A69AD" },51 { "Windows Recovery Environment", "DE94BBA4 -06D1-4D40-A16A-BFD50179D6AC" },52 { "Windows IBM GPFS", "37AFFC90 -EF7D-4E96-91C3-2D7AE055B174" },53 { "Windows Cluster metadata", "DB97DBA9 -0840-4BAE-97F0-FFB9A327C7E1" },54 { "HP-UX Data", "75894C1E -3AEB-11D3-B7C1-7B03A0000000" },55 { "HP-UX Service", "E2A1E728 -32E3-11D6-A682-7B03A0000000" },56 { "Linux filesystem data", "EBD0A0A2 -B9E5-4433-87C0-68B6B72699C7" },57 { "Linux filesystem data", "0FC63DAF -8483-4772-8E79-3D69D8477DE4" },58 { "Linux RAID", "A19D880F -05FC-4D3B-A006-743F0F84911E" },59 { "Linux Swap", "0657FD6D -A4AB-43C4-84E5-0933C84B4F4F" },60 { "Linux LVM", "E6D6D379 -F507-44C2-A23C-238F2A3DF928" },61 { "Linux Reserved", "8DA63339 -0007-60C0-C436-083AC8230908" },62 { "FreeBSD Boot", "83BD6B9D -7F41-11DC-BE0B-001560B84F0F" },63 { "FreeBSD Data", "516E7CB4 -6ECF-11D6-8FF8-00022D09712B" },64 { "FreeBSD Swap", "516E7CB5 -6ECF-11D6-8FF8-00022D09712B" },65 { "FreeBSD UFS", "516E7CB6 -6ECF-11D6-8FF8-00022D09712B" },66 { "FreeBSD Vinum VM", "516E7CB8 -6ECF-11D6-8FF8-00022D09712B" },67 { "FreeBSD ZFS", "516E7CBA -6ECF-11D6-8FF8-00022D09712B" },68 { "Mac OS X HFS+", "48465300 -0000-11AA-AA11-00306543ECAC" },69 { "Mac OS X UFS", "55465300 -0000-11AA-AA11-00306543ECAC" },70 { "Mac OS X ZFS", "6A898CC3 -1DD2-11B2-99A6-080020736631" },71 { "Mac OS X RAID", "52414944 -0000-11AA-AA11-00306543ECAC" },72 { "Mac OS X RAID, offline", "52414944 -5F4F-11AA-AA11-00306543ECAC" },73 { "Mac OS X Boot", "426F6F74 -0000-11AA-AA11-00306543ECAC" },74 { "Mac OS X Label", "4C616265 -6C00-11AA-AA11-00306543ECAC" },75 { "Mac OS X TV Recovery", "5265636F -7665-11AA-AA11-00306543ECAC" },76 { "Mac OS X Core Storage", "53746F72 -6167-11AA-AA11-00306543ECAC" },77 { "Solaris Boot", "6A82CB45 -1DD2-11B2-99A6-080020736631" },78 { "Solaris Root", "6A85CF4D -1DD2-11B2-99A6-080020736631" },79 { "Solaris Swap", "6A87C46F -1DD2-11B2-99A6-080020736631" },80 { "Solaris Backup", "6A8B642B -1DD2-11B2-99A6-080020736631" },81 { "Solaris /usr", "6A898CC3 -1DD2-11B2-99A6-080020736631" },82 { "Solaris /var", "6A8EF2E9 -1DD2-11B2-99A6-080020736631" },83 { "Solaris /home", "6A90BA39 -1DD2-11B2-99A6-080020736631" },84 { "Solaris Alternate sector", "6A9283A5 -1DD2-11B2-99A6-080020736631" },85 { "Solaris Reserved", "6A945A3B -1DD2-11B2-99A6-080020736631" },86 { "Solaris Reserved", "6A9630D1 -1DD2-11B2-99A6-080020736631" },87 { "Solaris Reserved", "6A980767 -1DD2-11B2-99A6-080020736631" },88 { "Solaris Reserved", "6A96237F -1DD2-11B2-99A6-080020736631" },89 { "Solaris Reserved", "6A8D2AC7 -1DD2-11B2-99A6-080020736631" },90 { "NetBSD Swap", "49F48D32 -B10E-11DC-B99B-0019D1879648" },91 { "NetBSD FFS", "49F48D5A -B10E-11DC-B99B-0019D1879648" },92 { "NetBSD LFS", "49F48D82 -B10E-11DC-B99B-0019D1879648" },93 { "NetBSD RAID", "49F48DAA -B10E-11DC-B99B-0019D1879648" },94 { "NetBSD Concatenated", "2DB519C4 -B10F-11DC-B99B-0019D1879648" },95 { "NetBSD Encrypted", "2DB519EC -B10F-11DC-B99B-0019D1879648" },96 { "ChromeOS ChromeOS kernel", "FE3A2A5D -4F32-41A7-B725-ACCC3285A309" },97 { "ChromeOS rootfs", "3CB8E202 -3B7E-47DD-8A3C-7FF2A13CFCEC" },98 { "ChromeOS future use", "2E0A753D -9E48-43B0-8337-B15192CB1B5E" },99 { "MidnightBSD Boot", "85D5E45E -237C-11E1-B4B3-E89A8F7FC3A7" },100 { "MidnightBSD Data", "85D5E45A -237C-11E1-B4B3-E89A8F7FC3A7" },101 { "MidnightBSD Swap", "85D5E45B -237C-11E1-B4B3-E89A8F7FC3A7" },102 { "MidnightBSD UFS", "0394Ef8B -237E-11E1-B4B3-E89A8F7FC3A7" },103 { "MidnightBSD Vinum VM", "85D5E45C -237C-11E1-B4B3-E89A8F7FC3A7" },104 { "MidnightBSD ZFS", "85D5E45D -237C-11E1-B4B3-E89A8F7FC3A7" },105 { "Uknown", NULL} // keep this as the last one! gpt_get_part_type depends on it!43 { "Unused entry", "00000000" "0000" "0000" "0000" "000000000000" }, 44 { "MBR partition scheme", "024DEE41" "33E7" "11D3" "9D69" "0008C781F39F" }, 45 { "EFI System", "C12A7328" "F81F" "11D2" "BA4B" "00A0C93EC93B" }, 46 { "BIOS Boot", "21686148" "6449" "6E6F" "744E" "656564454649" }, 47 { "Windows Reserved", "E3C9E316" "0B5C" "4DB8" "817D" "F92DF00215AE" }, 48 { "Windows Basic data", "EBD0A0A2" "B9E5" "4433" "87C0" "68B6B72699C7" }, 49 { "Windows LDM metadata", "5808C8AA" "7E8F" "42E0" "85D2" "E1E90434CFB3" }, 50 { "Windows LDM data", "AF9B60A0" "1431" "4F62" "BC68" "3311714A69AD" }, 51 { "Windows Recovery Environment", "DE94BBA4" "06D1" "4D40" "A16A" "BFD50179D6AC" }, 52 { "Windows IBM GPFS", "37AFFC90" "EF7D" "4E96" "91C3" "2D7AE055B174" }, 53 { "Windows Cluster metadata", "DB97DBA9" "0840" "4BAE" "97F0" "FFB9A327C7E1" }, 54 { "HP-UX Data", "75894C1E" "3AEB" "11D3" "B7C1" "7B03A0000000" }, 55 { "HP-UX Service", "E2A1E728" "32E3" "11D6" "A682" "7B03A0000000" }, 56 { "Linux filesystem data", "EBD0A0A2" "B9E5" "4433" "87C0" "68B6B72699C7" }, 57 { "Linux filesystem data", "0FC63DAF" "8483" "4772" "8E79" "3D69D8477DE4" }, 58 { "Linux RAID", "A19D880F" "05FC" "4D3B" "A006" "743F0F84911E" }, 59 { "Linux Swap", "0657FD6D" "A4AB" "43C4" "84E5" "0933C84B4F4F" }, 60 { "Linux LVM", "E6D6D379" "F507" "44C2" "A23C" "238F2A3DF928" }, 61 { "Linux Reserved", "8DA63339" "0007" "60C0" "C436" "083AC8230908" }, 62 { "FreeBSD Boot", "83BD6B9D" "7F41" "11DC" "BE0B" "001560B84F0F" }, 63 { "FreeBSD Data", "516E7CB4" "6ECF" "11D6" "8FF8" "00022D09712B" }, 64 { "FreeBSD Swap", "516E7CB5" "6ECF" "11D6" "8FF8" "00022D09712B" }, 65 { "FreeBSD UFS", "516E7CB6" "6ECF" "11D6" "8FF8" "00022D09712B" }, 66 { "FreeBSD Vinum VM", "516E7CB8" "6ECF" "11D6" "8FF8" "00022D09712B" }, 67 { "FreeBSD ZFS", "516E7CBA" "6ECF" "11D6" "8FF8" "00022D09712B" }, 68 { "Mac OS X HFS+", "48465300" "0000" "11AA" "AA11" "00306543ECAC" }, 69 { "Mac OS X UFS", "55465300" "0000" "11AA" "AA11" "00306543ECAC" }, 70 { "Mac OS X ZFS", "6A898CC3" "1DD2" "11B2" "99A6" "080020736631" }, 71 { "Mac OS X RAID", "52414944" "0000" "11AA" "AA11" "00306543ECAC" }, 72 { "Mac OS X RAID, offline", "52414944" "5F4F" "11AA" "AA11" "00306543ECAC" }, 73 { "Mac OS X Boot", "426F6F74" "0000" "11AA" "AA11" "00306543ECAC" }, 74 { "Mac OS X Label", "4C616265" "6C00" "11AA" "AA11" "00306543ECAC" }, 75 { "Mac OS X TV Recovery", "5265636F" "7665" "11AA" "AA11" "00306543ECAC" }, 76 { "Mac OS X Core Storage", "53746F72" "6167" "11AA" "AA11" "00306543ECAC" }, 77 { "Solaris Boot", "6A82CB45" "1DD2" "11B2" "99A6" "080020736631" }, 78 { "Solaris Root", "6A85CF4D" "1DD2" "11B2" "99A6" "080020736631" }, 79 { "Solaris Swap", "6A87C46F" "1DD2" "11B2" "99A6" "080020736631" }, 80 { "Solaris Backup", "6A8B642B" "1DD2" "11B2" "99A6" "080020736631" }, 81 { "Solaris /usr", "6A898CC3" "1DD2" "11B2" "99A6" "080020736631" }, 82 { "Solaris /var", "6A8EF2E9" "1DD2" "11B2" "99A6" "080020736631" }, 83 { "Solaris /home", "6A90BA39" "1DD2" "11B2" "99A6" "080020736631" }, 84 { "Solaris Alternate sector", "6A9283A5" "1DD2" "11B2" "99A6" "080020736631" }, 85 { "Solaris Reserved", "6A945A3B" "1DD2" "11B2" "99A6" "080020736631" }, 86 { "Solaris Reserved", "6A9630D1" "1DD2" "11B2" "99A6" "080020736631" }, 87 { "Solaris Reserved", "6A980767" "1DD2" "11B2" "99A6" "080020736631" }, 88 { "Solaris Reserved", "6A96237F" "1DD2" "11B2" "99A6" "080020736631" }, 89 { "Solaris Reserved", "6A8D2AC7" "1DD2" "11B2" "99A6" "080020736631" }, 90 { "NetBSD Swap", "49F48D32" "B10E" "11DC" "B99B" "0019D1879648" }, 91 { "NetBSD FFS", "49F48D5A" "B10E" "11DC" "B99B" "0019D1879648" }, 92 { "NetBSD LFS", "49F48D82" "B10E" "11DC" "B99B" "0019D1879648" }, 93 { "NetBSD RAID", "49F48DAA" "B10E" "11DC" "B99B" "0019D1879648" }, 94 { "NetBSD Concatenated", "2DB519C4" "B10F" "11DC" "B99B" "0019D1879648" }, 95 { "NetBSD Encrypted", "2DB519EC" "B10F" "11DC" "B99B" "0019D1879648" }, 96 { "ChromeOS ChromeOS kernel", "FE3A2A5D" "4F32" "41A7" "B725" "ACCC3285A309" }, 97 { "ChromeOS rootfs", "3CB8E202" "3B7E" "47DD" "8A3C" "7FF2A13CFCEC" }, 98 { "ChromeOS future use", "2E0A753D" "9E48" "43B0" "8337" "B15192CB1B5E" }, 99 { "MidnightBSD Boot", "85D5E45E" "237C" "11E1" "B4B3" "E89A8F7FC3A7" }, 100 { "MidnightBSD Data", "85D5E45A" "237C" "11E1" "B4B3" "E89A8F7FC3A7" }, 101 { "MidnightBSD Swap", "85D5E45B" "237C" "11E1" "B4B3" "E89A8F7FC3A7" }, 102 { "MidnightBSD UFS", "0394Ef8B" "237E" "11E1" "B4B3" "E89A8F7FC3A7" }, 103 { "MidnightBSD Vinum VM", "85D5E45C" "237C" "11E1" "B4B3" "E89A8F7FC3A7" }, 104 { "MidnightBSD ZFS", "85D5E45D" "237C" "11E1" "B4B3" "E89A8F7FC3A7" }, 105 { "Uknown", NULL} /* keep this as the last one! gpt_get_part_type depends on it! */ 106 106 }; 107 108 109 -
uspace/lib/gpt/libgpt.c
r6e8e4e19 r1c8bfe8 51 51 #include "libgpt.h" 52 52 53 static int load_and_check_header(service_id_t handle, aoff64_t addr, size_t b_size, gpt_header_t * 53 static int load_and_check_header(service_id_t handle, aoff64_t addr, size_t b_size, gpt_header_t *header); 54 54 static gpt_partitions_t * alloc_part_array(uint32_t num); 55 static int extend_part_array(gpt_partitions_t * p);56 static int reduce_part_array(gpt_partitions_t * p);55 static int extend_part_array(gpt_partitions_t *); 56 static int reduce_part_array(gpt_partitions_t *); 57 57 static long long nearest_larger_int(double a); 58 static int gpt_memcmp(const void * a, const void * b, size_t len); 58 static uint8_t get_byte(const char *); 59 60 /** Allocate memory for gpt label */ 61 gpt_label_t * gpt_alloc_label(void) 62 { 63 gpt_label_t *label = malloc(sizeof(gpt_label_t)); 64 if (label == NULL) 65 return NULL; 66 67 label->gpt = NULL; 68 label->parts = NULL; 69 label->device = 0; 70 71 return label; 72 } 73 74 /** Free gpt_label_t structure */ 75 void gpt_free_label(gpt_label_t *label) 76 { 77 if (label->gpt != NULL) 78 gpt_free_gpt(label->gpt); 79 80 if (label->parts != NULL) 81 gpt_free_partitions(label->parts); 82 83 free(label); 84 } 59 85 60 86 /** Allocate memory for gpt header */ 61 gpt_t * gpt_alloc_gpt_header(void) 62 { 63 return malloc(sizeof(gpt_t)); 87 gpt_t * gpt_alloc_header(size_t size) 88 { 89 gpt_t *gpt = malloc(sizeof(gpt_t)); 90 if (gpt == NULL) 91 return NULL; 92 93 // We might need only sizeof(gpt_header_t), 94 // but we should follow specs and have 95 // zeroes through all the rest of the block 96 size_t final_size = size > sizeof(gpt_header_t) ? size : sizeof(gpt_header_t); 97 gpt->header = malloc(final_size); 98 if (gpt->header == NULL) { 99 free(gpt); 100 return NULL; 101 } 102 103 memset(gpt->header, 0, final_size); 104 105 return gpt; 106 } 107 108 /** free() GPT header including gpt->header_lba */ 109 void gpt_free_gpt(gpt_t *gpt) 110 { 111 free(gpt->header); 112 free(gpt); 64 113 } 65 114 66 115 /** Read GPT from specific device 67 * @param dev_handle device to read GPT from 68 * 69 * @return GPT record on success, NULL on error 70 */ 71 gpt_t * gpt_read_gpt_header(service_id_t dev_handle) 116 * @param label label structure to fill 117 * @param dev_handle device to read GPT from 118 * 119 * @return EOK on success, errorcode on error 120 */ 121 int gpt_read_header(gpt_label_t *label, service_id_t dev_handle) 72 122 { 73 123 int rc; … … 76 126 rc = block_init(EXCHANGE_ATOMIC, dev_handle, 512); 77 127 if (rc != EOK) 78 return NULL;128 return rc; 79 129 80 130 rc = block_get_bsize(dev_handle, &b_size); 81 if (rc != EOK) { 82 errno = rc; 83 return NULL; 84 } 85 86 gpt_t * gpt = malloc(sizeof(gpt_t)); 87 if (gpt == NULL) { 88 errno = ENOMEM; 89 return NULL; 90 } 91 92 gpt->raw_data = malloc(b_size); // We might need only sizeof(gpt_header_t), 93 if (gpt == NULL) { // but we should follow specs and have 94 free(gpt); // zeroes through all the rest of the block 95 errno = ENOMEM; 96 return NULL; 97 } 98 99 100 rc = load_and_check_header(dev_handle, GPT_HDR_BA, b_size, gpt->raw_data); 131 if (rc != EOK) 132 return rc; 133 134 if (label->gpt == NULL) { 135 label->gpt = gpt_alloc_header(b_size); 136 if (label->gpt == NULL) 137 return ENOMEM; 138 } 139 140 rc = load_and_check_header(dev_handle, GPT_HDR_BA, b_size, label->gpt->header); 101 141 if (rc == EBADCHECKSUM || rc == EINVAL) { 102 142 aoff64_t n_blocks; 103 143 rc = block_get_nblocks(dev_handle, &n_blocks); 104 if (rc != EOK) { 105 errno = rc; 144 if (rc != EOK) 106 145 goto fail; 107 } 108 109 rc = load_and_check_header(dev_handle, n_blocks - 1, b_size, gpt->raw_data); 110 if (rc == EBADCHECKSUM || rc == EINVAL) { 111 errno = rc; 146 147 rc = load_and_check_header(dev_handle, n_blocks - 1, b_size, label->gpt->header); 148 if (rc == EBADCHECKSUM || rc == EINVAL) 112 149 goto fail; 113 } 114 } 115 116 gpt->device = dev_handle; 150 } 151 152 label->device = dev_handle; 117 153 block_fini(dev_handle); 118 return gpt;154 return EOK; 119 155 120 156 fail: 121 157 block_fini(dev_handle); 122 gpt_free_gpt(gpt); 123 return NULL; 158 gpt_free_gpt(label->gpt); 159 label->gpt = NULL; 160 return rc; 124 161 } 125 162 126 163 /** Write GPT header to device 127 * @param header GPTheader to be written128 * @param dev_handle 129 * 130 * @return 0on success, libblock error code otherwise131 * 132 * Note: Firstly write partitions (if changed), then gpt header.133 */ 134 int gpt_write_ gpt_header(gpt_t * gpt, service_id_t dev_handle)164 * @param label GPT label header to be written 165 * @param dev_handle device handle to write the data to 166 * 167 * @return EOK on success, libblock error code otherwise 168 * 169 * Note: Firstly write partitions (if modified), then gpt header. 170 */ 171 int gpt_write_header(gpt_label_t *label, service_id_t dev_handle) 135 172 { 136 173 int rc; 137 174 size_t b_size; 138 175 139 gpt->raw_data->header_crc32 = 0;140 gpt->raw_data->header_crc32 = compute_crc32((uint8_t *) gpt->raw_data,141 uint32_t_le2host( gpt->raw_data->header_size));176 label->gpt->header->header_crc32 = 0; 177 label->gpt->header->header_crc32 = compute_crc32((uint8_t *) label->gpt->header, 178 uint32_t_le2host(label->gpt->header->header_size)); 142 179 143 180 rc = block_init(EXCHANGE_ATOMIC, dev_handle, b_size); 144 if (rc != EOK )181 if (rc != EOK && rc != EEXIST) 145 182 return rc; 146 183 … … 150 187 151 188 /* Write to main GPT header location */ 152 rc = block_write_direct(dev_handle, GPT_HDR_BA, GPT_HDR_BS, gpt->raw_data);153 if (rc != EOK) 189 rc = block_write_direct(dev_handle, GPT_HDR_BA, GPT_HDR_BS, label->gpt->header); 190 if (rc != EOK) { 154 191 block_fini(dev_handle); 155 192 return rc; 193 } 156 194 157 195 aoff64_t n_blocks; 158 196 rc = block_get_nblocks(dev_handle, &n_blocks); 159 if (rc != EOK) 160 return rc; 197 if (rc != EOK) { 198 block_fini(dev_handle); 199 return rc; 200 } 161 201 162 202 /* Write to backup GPT header location */ 163 203 //FIXME: those idiots thought it would be cool to have these fields in reverse order... 164 rc = block_write_direct(dev_handle, n_blocks - 1, GPT_HDR_BS, gpt->raw_data);204 rc = block_write_direct(dev_handle, n_blocks - 1, GPT_HDR_BS, label->gpt->header); 165 205 block_fini(dev_handle); 166 206 if (rc != EOK) … … 171 211 172 212 /** Alloc partition array */ 173 gpt_partitions_t * 213 gpt_partitions_t * gpt_alloc_partitions() 174 214 { 175 215 return alloc_part_array(128); … … 177 217 178 218 /** Parse partitions from GPT 179 * @param gpt GPT to be parsed 180 * 181 * @return partition linked list pointer or NULL on error 182 * error code is stored in errno 183 */ 184 gpt_partitions_t * gpt_read_partitions(gpt_t * gpt) 219 * @param label GPT label to be parsed 220 * 221 * @return EOK on success, errorcode otherwise 222 */ 223 int gpt_read_partitions(gpt_label_t *label) 185 224 { 186 225 int rc; 187 226 unsigned int i; 188 gpt_partitions_t * res;189 uint32_t fill = uint32_t_le2host(gpt->raw_data->fillries);190 uint 32_t ent_size = uint32_t_le2host(gpt->raw_data->entry_size);191 uint64_t ent_lba = uint64_t_le2host(gpt->raw_data->entry_lba);192 193 res = alloc_part_array(fill);194 if (res == NULL) {195 //errno = ENOMEM; // already set in alloc_part_array()196 return NULL;227 uint32_t fill = uint32_t_le2host(label->gpt->header->fillries); 228 uint32_t ent_size = uint32_t_le2host(label->gpt->header->entry_size); 229 uint64_t ent_lba = uint64_t_le2host(label->gpt->header->entry_lba); 230 231 if (label->parts == NULL) { 232 label->parts = alloc_part_array(fill); 233 if (label->parts == NULL) { 234 return ENOMEM; 235 } 197 236 } 198 237 … … 200 239 * - we don't need more bytes 201 240 * - the size of GPT partition entry can be different to 128 bytes */ 202 rc = block_init(EXCHANGE_SERIALIZE, gpt->device, sizeof(gpt_entry_t)); 203 if (rc != EOK) { 204 gpt_free_partitions(res); 205 errno = rc; 206 return NULL; 207 } 241 rc = block_init(EXCHANGE_SERIALIZE, label->device, sizeof(gpt_entry_t)); 242 if (rc != EOK) 243 goto fail; 208 244 209 245 size_t block_size; 210 rc = block_get_bsize(gpt->device, &block_size); 211 if (rc != EOK) { 212 gpt_free_partitions(res); 213 errno = rc; 214 return NULL; 215 } 246 rc = block_get_bsize(label->device, &block_size); 247 if (rc != EOK) 248 goto fail; 216 249 217 250 //size_t bufpos = 0; … … 226 259 for (i = 0; i < fill; ++i) { 227 260 //FIXME: this does bypass cache... 228 rc = block_read_bytes_direct( gpt->device, pos, sizeof(gpt_entry_t), res->part_array + i);261 rc = block_read_bytes_direct(label->device, pos, sizeof(gpt_entry_t), label->parts->part_array + i); 229 262 //FIXME: but seqread() is just too complex... 230 263 //rc = block_seqread(gpt->device, &bufpos, &buflen, &pos, res->part_array[i], sizeof(gpt_entry_t)); 231 264 pos += ent_size; 232 265 233 if (rc != EOK) { 234 gpt_free_partitions(res); 235 errno = rc; 236 return NULL; 237 } 266 if (rc != EOK) 267 goto fail; 238 268 } 239 269 … … 243 273 * on all of the partition entry array. 244 274 */ 245 uint32_t crc = compute_crc32((uint8_t *) res->part_array, res->fill * sizeof(gpt_entry_t));246 247 if(uint32_t_le2host( gpt->raw_data->pe_array_crc32) != crc)275 uint32_t crc = compute_crc32((uint8_t *) label->parts->part_array, label->parts->fill * sizeof(gpt_entry_t)); 276 277 if(uint32_t_le2host(label->gpt->header->pe_array_crc32) != crc) 248 278 { 249 gpt_free_partitions(res); 250 errno = EBADCHECKSUM; 251 return NULL; 252 } 253 254 return res; 279 rc = EBADCHECKSUM; 280 goto fail; 281 } 282 283 return EOK; 284 285 fail: 286 gpt_free_partitions(label->parts); 287 label->parts = NULL; 288 return rc; 255 289 } 256 290 257 291 /** Write GPT and partitions to device 258 * @param parts partition list to be written 259 * @param header GPT header belonging to the 'parts' partitions 260 * @param dev_handle device to write the data to 261 * 262 * @return returns EOK on succes, specific error code otherwise 263 */ 264 int gpt_write_partitions(gpt_partitions_t * parts, gpt_t * gpt, service_id_t dev_handle) 292 * @param label label to write 293 * @param dev_handle device to write the data to 294 * 295 * @return returns EOK on succes, errorcode otherwise 296 */ 297 int gpt_write_partitions(gpt_label_t *label, service_id_t dev_handle) 265 298 { 266 299 int rc; 267 300 size_t b_size; 268 269 gpt->raw_data->pe_array_crc32 = compute_crc32((uint8_t *) parts->part_array, parts->fill * gpt->raw_data->entry_size); 270 271 rc = block_init(EXCHANGE_ATOMIC, dev_handle, b_size); 272 if (rc != EOK) 273 return rc; 274 301 uint32_t e_size = uint32_t_le2host(label->gpt->header->entry_size); 302 size_t fill = label->parts->fill > GPT_MIN_PART_NUM ? label->parts->fill : GPT_MIN_PART_NUM; 303 304 label->gpt->header->pe_array_crc32 = compute_crc32( 305 (uint8_t *) label->parts->part_array, 306 fill * e_size); 307 308 /* comm_size of 4096 is ignored */ 309 rc = block_init(EXCHANGE_ATOMIC, dev_handle, 4096); 310 if (rc != EOK && rc != EEXIST) 311 return rc; 312 275 313 rc = block_get_bsize(dev_handle, &b_size); 276 314 if (rc != EOK) 277 return rc; 278 279 /* Write to main GPT partition array location */ 280 rc = block_write_direct(dev_handle, uint64_t_le2host(gpt->raw_data->entry_lba), 281 nearest_larger_int((uint64_t_le2host(gpt->raw_data->entry_size) * parts->fill) / b_size), 282 parts->part_array); 283 if (rc != EOK) 284 block_fini(dev_handle); 285 return rc; 286 315 goto fail; 316 287 317 aoff64_t n_blocks; 288 318 rc = block_get_nblocks(dev_handle, &n_blocks); 289 319 if (rc != EOK) 290 return rc;291 320 goto fail; 321 292 322 /* Write to backup GPT partition array location */ 293 323 //rc = block_write_direct(dev_handle, n_blocks - 1, GPT_HDR_BS, header->raw_data); 324 if (rc != EOK) 325 goto fail; 326 327 /* Write to main GPT partition array location */ 328 rc = block_write_direct(dev_handle, uint64_t_le2host(label->gpt->header->entry_lba), 329 nearest_larger_int((uint64_t_le2host(label->gpt->header->entry_size) * label->parts->fill) / b_size), 330 label->parts->part_array); 331 if (rc != EOK) 332 goto fail; 333 334 return gpt_write_header(label, dev_handle); 335 336 fail: 294 337 block_fini(dev_handle); 295 if (rc != EOK) 296 return rc; 297 298 299 return gpt_write_gpt_header(gpt, dev_handle); 338 return rc; 300 339 } 301 340 302 341 /** Alloc new partition 303 342 * 304 * @param parts partition table to carry new partition 305 * 306 * @return returns pointer to the new partition or NULL on ENOMEM 307 * 308 * Note: use either gpt_alloc_partition or gpt_add_partition. The first 309 * returns a pointer to write your data to, the second copies the data 310 * (and does not free the memory). 311 */ 312 gpt_part_t * gpt_alloc_partition(gpt_partitions_t * parts) 313 { 314 if (parts->fill == parts->arr_size) { 315 if (extend_part_array(parts) == -1) 316 return NULL; 317 } 318 319 return parts->part_array + parts->fill++; 343 * @return returns pointer to the new partition or NULL 344 * 345 * Note: use either gpt_alloc_partition or gpt_get_partition. 346 * This returns a memory block (zero-filled) and needs gpt_add_partition() 347 * to be called to insert it into a partition array. 348 * Requires you to call gpt_free_partition afterwards. 349 */ 350 gpt_part_t * gpt_alloc_partition(void) 351 { 352 gpt_part_t *p = malloc(sizeof(gpt_part_t)); 353 if (p == NULL) 354 return NULL; 355 356 memset(p, 0, sizeof(gpt_part_t)); 357 358 return p; 359 } 360 361 /** Alloc new partition already inside the label 362 * 363 * @param label label to carry new partition 364 * 365 * @return returns pointer to the new partition or NULL on ENOMEM 366 * 367 * Note: use either gpt_alloc_partition or gpt_get_partition. 368 * This one returns a pointer to the first empty structure already 369 * inside the array, so don't call gpt_add_partition() afterwards. 370 * This is the one you will usually want. 371 */ 372 gpt_part_t * gpt_get_partition(gpt_label_t *label) 373 { 374 gpt_part_t *p; 375 376 /* Find the first empty entry */ 377 do { 378 if (label->parts->fill == label->parts->arr_size) { 379 if (extend_part_array(label->parts) == -1) 380 return NULL; 381 } 382 383 p = label->parts->part_array + label->parts->fill++; 384 385 } while (gpt_get_part_type(p) != GPT_PTE_UNUSED); 386 387 return p; 388 } 389 390 /** Get partition already inside the label 391 * 392 * @param label label to carrying the partition 393 * @param idx index of the partition 394 * 395 * @return returns pointer to the partition 396 * or NULL when out of range 397 * 398 * Note: For new partitions use either gpt_alloc_partition or 399 * gpt_get_partition unless you want a partition at a specific place. 400 * This returns a pointer to a structure already inside the array, 401 * so don't call gpt_add_partition() afterwards. 402 * This function is handy when you want to change already existing 403 * partition or to simply write somewhere in the middle. This works only 404 * for indexes smaller than either 128 or the actual number of filled 405 * entries. 406 */ 407 gpt_part_t * gpt_get_partition_at(gpt_label_t *label, size_t idx) 408 { 409 return NULL; 410 411 if (idx >= GPT_MIN_PART_NUM && idx >= label->parts->fill) 412 return NULL; 413 414 return label->parts->part_array + idx; 320 415 } 321 416 322 417 /** Copy partition into partition array 323 418 * 324 * @param parts target partition array419 * @param parts target label 325 420 * @param partition source partition to copy 326 421 * 327 422 * @return -1 on error, 0 otherwise 328 423 * 329 * Note: use either gpt_alloc_partition or gpt_add_partition. The first 330 * returns a pointer to write your data to, the second copies the data 331 * (and does not free the memory). 332 */ 333 int gpt_add_partition(gpt_partitions_t * parts, gpt_part_t * partition) 334 { 335 if (parts->fill == parts->arr_size) { 336 if (extend_part_array(parts) == -1) 424 * Note: for use with gpt_alloc_partition() only. You will get 425 * duplicates with gpt_get_partition(). 426 */ 427 int gpt_add_partition(gpt_label_t *label, gpt_part_t *partition) 428 { 429 if (label->parts->fill == label->parts->arr_size) { 430 if (extend_part_array(label->parts) == -1) 337 431 return ENOMEM; 338 432 } 339 extend_part_array(parts); 340 return EOK;; 433 434 memcpy(label->parts->part_array + label->parts->fill++, 435 partition, sizeof(gpt_part_t)); 436 437 return EOK; 341 438 } 342 439 343 440 /** Remove partition from array 344 * 345 * @param idx 346 * 347 * @return -1 on error, 0 otherwise441 * @param label label to remove from 442 * @param idx index of the partition to remove 443 * 444 * @return EOK on success, ENOMEM on array reduction failure 348 445 * 349 446 * Note: even if it fails, the partition still gets removed. Only 350 447 * reducing the array failed. 351 448 */ 352 int gpt_remove_partition(gpt_partitions_t * parts, size_t idx) 353 { 354 if (idx != parts->fill - 1) { 355 memcpy(parts->part_array + idx, parts->part_array + parts->fill - 1, sizeof(gpt_entry_t)); 356 parts->fill -= 1; 357 } 358 359 if (parts->fill < (parts->arr_size / 2) - GPT_IGNORE_FILL_NUM) { 360 if (reduce_part_array(parts) == -1) 361 return -1; 362 } 363 364 return 0; 365 } 366 367 /** free() GPT header including gpt->header_lba */ 368 void gpt_free_gpt(gpt_t * gpt) 369 { 370 free(gpt->raw_data); 371 free(gpt); 449 int gpt_remove_partition(gpt_label_t *label, size_t idx) 450 { 451 if (idx >= label->parts->fill) 452 return EINVAL; 453 454 /* FIXME! 455 * If we allow blank spots, we break the array. If we have more than 456 * 128 partitions in the array and then remove something from 457 * the first 128 partitions, we would forget to write the last one.*/ 458 memset(label->parts->part_array + idx, 0, sizeof(gpt_entry_t)); 459 460 label->parts->fill -= 1; 461 462 /* FIXME! 463 * We cannot reduce the array so simply. We may have some partitions 464 * there since we allow blank spots.*/ 465 if (label->parts->fill < (label->parts->arr_size / 2) - GPT_IGNORE_FILL_NUM) { 466 if (reduce_part_array(label->parts) == ENOMEM) 467 return ENOMEM; 468 } 469 470 return EOK; 372 471 } 373 472 … … 388 487 { 389 488 size_t i; 489 390 490 for (i = 0; gpt_ptypes[i].guid != NULL; i++) { 391 if (gpt_memcmp(p->part_type, gpt_ptypes[i].guid, 16) == 0) { 392 break; 393 } 394 } 491 if (p->part_type[3] == get_byte(gpt_ptypes[i].guid +0) && 492 p->part_type[2] == get_byte(gpt_ptypes[i].guid +2) && 493 p->part_type[1] == get_byte(gpt_ptypes[i].guid +4) && 494 p->part_type[0] == get_byte(gpt_ptypes[i].guid +6) && 495 496 p->part_type[5] == get_byte(gpt_ptypes[i].guid +8) && 497 p->part_type[4] == get_byte(gpt_ptypes[i].guid +10) && 498 499 p->part_type[7] == get_byte(gpt_ptypes[i].guid +12) && 500 p->part_type[6] == get_byte(gpt_ptypes[i].guid +14) && 501 502 p->part_type[8] == get_byte(gpt_ptypes[i].guid +16) && 503 p->part_type[9] == get_byte(gpt_ptypes[i].guid +18) && 504 p->part_type[10] == get_byte(gpt_ptypes[i].guid +20) && 505 p->part_type[11] == get_byte(gpt_ptypes[i].guid +22) && 506 p->part_type[12] == get_byte(gpt_ptypes[i].guid +24) && 507 p->part_type[13] == get_byte(gpt_ptypes[i].guid +26) && 508 p->part_type[14] == get_byte(gpt_ptypes[i].guid +28) && 509 p->part_type[15] == get_byte(gpt_ptypes[i].guid +30)) 510 break; 511 } 512 395 513 return i; 396 514 } … … 449 567 } 450 568 451 569 /** Get partition name */ 452 570 unsigned char * gpt_get_part_name(gpt_part_t * p) 453 571 { … … 456 574 457 575 /** Copy partition name */ 458 void gpt_set_part_name(gpt_part_t * p, char * name[], size_t length)576 void gpt_set_part_name(gpt_part_t *p, char *name, size_t length) 459 577 { 460 578 if (length >= 72) … … 561 679 if(p->arr_size > GPT_MIN_PART_NUM) { 562 680 unsigned int nsize = p->arr_size / 2; 681 nsize = nsize > GPT_MIN_PART_NUM ? nsize : GPT_MIN_PART_NUM; 563 682 gpt_entry_t * tmp = malloc(nsize * sizeof(gpt_entry_t)); 564 if(tmp == NULL) { 565 errno = ENOMEM; 566 return -1; 567 } 683 if(tmp == NULL) 684 return ENOMEM; 568 685 569 686 memcpy(tmp, p->part_array, p->fill < nsize ? p->fill : nsize); … … 586 703 } 587 704 588 static int gpt_memcmp(const void * a, const void * b, size_t len) 589 { 590 size_t i; 591 int diff; 592 const unsigned char * x = a; 593 const unsigned char * y = b; 594 595 for (i = 0; i < len; i++) { 596 diff = (int)*(x++) - (int)*(y++); 597 if (diff != 0) { 598 return diff; 599 } 600 } 601 return 0; 602 } 603 604 605 606 705 static uint8_t get_byte(const char * c) 706 { 707 uint8_t val = 0; 708 char hex[3] = {*c, *(c+1), 0}; 709 710 errno = str_uint8_t(hex, NULL, 16, false, &val); 711 return val; 712 } 713 714 715 716 -
uspace/lib/gpt/libgpt.h
r6e8e4e19 r1c8bfe8 53 53 #define GPT_IGNORE_FILL_NUM 10 54 54 55 /** Unused partition entry */ 56 #define GPT_PTE_UNUSED 0 57 55 58 /** GPT header signature ("EFI PART" in ASCII) */ 56 59 extern const uint8_t efi_signature[8]; … … 86 89 typedef struct { 87 90 /** Raw header. Has more bytes alloced than sizeof(gpt_header_t)! 88 * See gpt_read_gpt_header() to know why. */ 89 gpt_header_t * raw_data; 90 /** Device where the data are from */ 91 service_id_t device; 92 /** Linked list of partitions (initially NULL) */ 91 * See gpt_alloc_header() to know why. */ 92 gpt_header_t *header; 93 93 } gpt_t; 94 94 … … 123 123 size_t arr_size; 124 124 /** Resizable partition array */ 125 gpt_entry_t * 125 gpt_entry_t *part_array; 126 126 } gpt_partitions_t; 127 127 128 128 129 129 typedef struct gpt_table { 130 gpt_t * gpt; 131 gpt_partitions_t * parts; 130 gpt_t *gpt; 131 gpt_partitions_t *parts; 132 service_id_t device; 132 133 } gpt_label_t; 133 134 134 135 struct partition_type { 135 const char * 136 const char * 136 const char *desc; 137 const char *guid; 137 138 }; 138 139 139 140 extern const struct partition_type gpt_ptypes[]; 140 141 142 extern gpt_label_t * gpt_alloc_label(void); 143 extern void gpt_free_label(gpt_label_t *); 141 144 142 extern gpt_t * gpt_alloc_ gpt_header(void);143 extern gpt_t * gpt_read_gpt_header(service_id_t dev_handle);144 extern int gpt_write_ gpt_header(gpt_t * header, service_id_t dev_handle);145 extern gpt_t * gpt_alloc_header(size_t); 146 extern int gpt_read_header(gpt_label_t *, service_id_t); 147 extern int gpt_write_header(gpt_label_t *, service_id_t); 145 148 146 149 extern gpt_partitions_t * gpt_alloc_partitions(void); 147 extern gpt_partitions_t * gpt_read_partitions(gpt_t * gpt); 148 extern int gpt_write_partitions(gpt_partitions_t * parts, gpt_t * header, service_id_t dev_handle); 149 extern gpt_part_t * gpt_alloc_partition (gpt_partitions_t * parts); 150 extern int gpt_add_partition (gpt_partitions_t * parts, gpt_part_t * partition); 151 extern int gpt_remove_partition(gpt_partitions_t * parts, size_t idx); 150 extern int gpt_read_partitions (gpt_label_t *); 151 extern int gpt_write_partitions(gpt_label_t *, service_id_t); 152 extern gpt_part_t * gpt_alloc_partition (void); 153 extern gpt_part_t * gpt_get_partition (gpt_label_t *); 154 extern gpt_part_t * gpt_get_partition_at(gpt_label_t *, size_t); 155 extern int gpt_add_partition (gpt_label_t *, gpt_part_t *); 156 extern int gpt_remove_partition(gpt_label_t *, size_t); 152 157 153 extern size_t gpt_get_part_type(gpt_part_t * p);154 extern void gpt_set_part_type(gpt_part_t * p, size_t type);155 extern void gpt_set_start_lba(gpt_part_t * p, uint64_t start);156 extern uint64_t gpt_get_start_lba(gpt_part_t * p);157 extern void gpt_set_end_lba (gpt_part_t * p, uint64_t end);158 extern uint64_t gpt_get_end_lba (gpt_part_t * p);159 extern unsigned char * gpt_get_part_name(gpt_part_t * p);160 extern void gpt_set_part_name(gpt_part_t * p, char * name[], size_t length);161 extern bool gpt_get_flag (gpt_part_t * p, GPT_ATTR flag);162 extern void gpt_set_flag (gpt_part_t * p, GPT_ATTR flag, bool value);158 extern size_t gpt_get_part_type(gpt_part_t *); 159 extern void gpt_set_part_type(gpt_part_t *, size_t); 160 extern void gpt_set_start_lba(gpt_part_t *, uint64_t); 161 extern uint64_t gpt_get_start_lba(gpt_part_t *); 162 extern void gpt_set_end_lba (gpt_part_t *, uint64_t); 163 extern uint64_t gpt_get_end_lba (gpt_part_t *); 164 extern unsigned char * gpt_get_part_name(gpt_part_t *); 165 extern void gpt_set_part_name(gpt_part_t *, char *, size_t); 166 extern bool gpt_get_flag (gpt_part_t *, GPT_ATTR); 167 extern void gpt_set_flag (gpt_part_t *, GPT_ATTR, bool); 163 168 164 169 165 170 166 #define gpt_part_foreach( parts, iterator) \167 for(gpt_part_t * iterator = ( parts)->part_array; \168 iterator < ( parts)->part_array + (parts)->fill; ++iterator)171 #define gpt_part_foreach(label, iterator) \ 172 for(gpt_part_t * iterator = (label)->parts->part_array; \ 173 iterator < (label)->parts->part_array + (label)->parts->fill; ++iterator) 169 174 170 extern void gpt_free_gpt(gpt_t * gpt);171 extern void gpt_free_partitions(gpt_partitions_t * parts);175 extern void gpt_free_gpt(gpt_t *); 176 extern void gpt_free_partitions(gpt_partitions_t *); 172 177 173 178 #endif -
uspace/lib/mbr/libmbr.c
r6e8e4e19 r1c8bfe8 94 94 */ 95 95 int mbr_read_mbr(mbr_label_t *label, service_id_t dev_handle) 96 { 97 if (label == NULL) 98 return EINVAL; 99 96 { 100 97 int rc; 101 98 … … 195 192 196 193 rc_ext = decode_part(&(label->mbr->raw_data.pte[i]), p, 0); 197 printf("p: %d %u %u\n", rc_ext, p->start_addr, p->length);198 194 mbr_set_flag(p, ST_LOGIC, false); 199 195 rc = mbr_add_partition(label, p); … … 207 203 if (rc_ext) { 208 204 ext = p; 209 printf("ext: %u %u\n", p->start_addr, p->length);210 205 label->parts->l_extended = &p->link; 211 206 } … … 231 226 int mbr_write_partitions(mbr_label_t *label, service_id_t dev_handle) 232 227 { 228 if (label->parts == NULL) 229 return EOK; 230 231 if (label->mbr == NULL) 232 label->mbr = mbr_alloc_mbr(); 233 233 234 int i = 0; 234 235 int rc; … … 248 249 for (i = 0; i < N_PRIMARY; i++) { 249 250 p = list_get_instance(l, mbr_part_t, link); 250 printf("status: %hu\n", p->status);251 251 encode_part(p, &(label->mbr->raw_data.pte[i]), 0, false); 252 252 l = l->next;
Note:
See TracChangeset
for help on using the changeset viewer.