Changeset e27b89a in mainline for uspace/srv/part/mbr_part/mbr_part.c
- Timestamp:
- 2009-09-01T21:27:41Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0712ff2, 9aa54d4a
- Parents:
- 440b0ce
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/part/mbr_part/mbr_part.c
r440b0ce re27b89a 59 59 #include <bool.h> 60 60 #include <byteorder.h> 61 #include <assert.h> 61 62 #include <macros.h> 62 63 #include <task.h> … … 70 71 /** Boot record signature */ 71 72 BR_SIGNATURE = 0xAA55, 72 73 /** Maximum number of partitions */74 MAX_PART = 6475 73 }; 76 74 … … 81 79 82 80 /** Partition */ 83 typedef struct {81 typedef struct part { 84 82 /** Primary partition entry is in use */ 85 83 bool present; … … 90 88 /** Device representing the partition (outbound device) */ 91 89 dev_handle_t dev; 90 /** Points to next partition structure. */ 91 struct part *next; 92 92 } part_t; 93 93 … … 130 130 static dev_handle_t indev_handle; 131 131 132 static part_t primary[MAX_PART]; 132 /** List of partitions. This structure is an empty head. */ 133 static part_t plist_head; 133 134 134 135 static int mbr_init(const char *dev_name); 135 136 static int mbr_part_read(void); 137 static part_t *mbr_part_new(void); 136 138 static void mbr_pte_to_part(uint32_t base, const pt_entry_t *pte, part_t *part); 137 139 static void mbr_connection(ipc_callid_t iid, ipc_call_t *icall); … … 140 142 static int mbr_bsa_translate(part_t *p, uint64_t ba, size_t cnt, uint64_t *gba); 141 143 142 /** Total number of partitions entries in @c primary (including non-present). */143 static int total_part;144 145 144 int main(int argc, char **argv) 146 145 { … … 170 169 dev_handle_t dev; 171 170 uint64_t size_mb; 171 part_t *part; 172 172 173 173 rc = devmap_device_get_handle(dev_name, &indev_handle, 0); … … 208 208 } 209 209 210 /* Create partition devices. */ 211 for (i = 0; i < total_part; ++i) { 210 /* 211 * Create partition devices. 212 */ 213 i = 0; 214 part = plist_head.next; 215 216 while (part != NULL) { 212 217 /* Skip absent partitions. */ 213 if (!primary[i].present) 218 if (!part->present) { 219 part = part->next; 220 ++i; 214 221 continue; 222 } 215 223 216 224 asprintf(&name, "%sp%d", dev_name, i); … … 225 233 } 226 234 227 size_mb = (p rimary[i].length * block_size + 1024 * 1024 - 1)235 size_mb = (part->length * block_size + 1024 * 1024 - 1) 228 236 / (1024 * 1024); 229 237 printf(NAME ": Registered device %s: %llu blocks %llu MB.\n", 230 name, p rimary[i].length, size_mb);231 232 p rimary[i].dev = dev;238 name, part->length, size_mb); 239 240 part->dev = dev; 233 241 free(name); 242 243 part = part->next; 244 ++i; 234 245 } 235 246 … … 246 257 part_t *ext_part, cp; 247 258 uint32_t base; 259 part_t *prev, *p; 248 260 249 261 brb = malloc(sizeof(br_block_t)); … … 270 282 271 283 ext_part = NULL; 284 plist_head.next = NULL; 285 prev = &plist_head; 272 286 273 287 for (i = 0; i < N_PRIMARY; ++i) { 274 mbr_pte_to_part(0, &brb->pte[i], &primary[i]); 288 p = mbr_part_new(); 289 if (p == NULL) 290 return ENOMEM; 291 292 mbr_pte_to_part(0, &brb->pte[i], p); 293 prev->next = p; 294 prev = p; 275 295 276 296 if (brb->pte[i].ptype == PT_EXTENDED) { 277 p rimary[i].present = false;278 ext_part = &primary[i];297 p->present = false; 298 ext_part = p; 279 299 } 280 300 } … … 312 332 } 313 333 334 p = mbr_part_new(); 335 if (p == NULL) 336 return ENOMEM; 337 314 338 /* First PTE is the logical partition itself. */ 315 mbr_pte_to_part(base, &brb->pte[0], &primary[i]); 316 ++i; 339 mbr_pte_to_part(base, &brb->pte[0], p); 340 prev->next = p; 341 prev = p; 317 342 318 343 /* Second PTE describes next chain element. */ 319 344 mbr_pte_to_part(base, &brb->pte[1], &cp); 320 } while (cp.present && i < MAX_PART); 321 322 total_part = i; 345 } while (cp.present); 323 346 324 347 return EOK; 348 } 349 350 /** Allocate a new @c part_t structure. */ 351 static part_t *mbr_part_new(void) 352 { 353 return malloc(sizeof(part_t)); 325 354 } 326 355 … … 338 367 part->present = (sa != 0 || len != 0) ? true : false; 339 368 part->dev = 0; 369 part->next = NULL; 340 370 } 341 371 … … 352 382 uint64_t ba; 353 383 size_t cnt; 354 int pidx, i;355 384 part_t *part; 356 385 … … 358 387 dh = IPC_GET_ARG1(*icall); 359 388 360 /* Determine which partition device is the client connecting to. */ 361 pidx = -1; 362 for (i = 0; i < total_part; i++) 363 if (primary[i].dev == dh) 364 pidx = i; 365 366 if (pidx < 0/* || disk[disk_id].present == false*/) { 389 /* 390 * Determine which partition device is the client connecting to. 391 * A linear search is not terribly fast, but we only do this 392 * once for each connection. 393 */ 394 part = plist_head.next; 395 while (part != NULL && part->dev != dh) 396 part = part->next; 397 398 if (part == NULL) { 367 399 ipc_answer_0(iid, EINVAL); 368 400 return; 369 401 } 370 402 371 part = &primary[pidx];403 assert(part->present == true); 372 404 373 405 /* Answer the IPC_M_CONNECT_ME_TO call. */
Note:
See TracChangeset
for help on using the changeset viewer.