Changes in / [40240b1:b53e6d9] in mainline
- Location:
- uspace
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/bdd/bdd.c
r40240b1 rb53e6d9 42 42 #include <assert.h> 43 43 44 #define BLOCK_SIZE 512 45 #define BPR 16 44 enum { 45 /* Number of bytes per row */ 46 BPR = 16 47 }; 46 48 47 49 static const char *cmdname = "bdd"; … … 67 69 unsigned int i, j; 68 70 dev_handle_t handle; 69 block_t *block;70 71 uint8_t *blk; 71 72 size_t size, bytes, rows; 73 size_t block_size; 72 74 int rc; 73 bn_t b off;75 bn_t ba; 74 76 uint8_t b; 75 77 … … 83 85 84 86 if (argc >= 3) 85 b off= strtol(argv[2], NULL, 0);87 ba = strtol(argv[2], NULL, 0); 86 88 else 87 b off= 0;89 ba = 0; 88 90 89 91 if (argc >= 4) … … 94 96 rc = devmap_device_get_handle(argv[1], &handle, 0); 95 97 if (rc != EOK) { 96 printf(" Error: could not resolve device `%s'.\n", argv[1]);98 printf("%s: Error resolving device `%s'.\n", cmdname, argv[1]); 97 99 return CMD_FAILURE; 98 100 } 99 101 100 rc = block_init(handle, BLOCK_SIZE);102 rc = block_init(handle, 2048); 101 103 if (rc != EOK) { 102 printf(" Error: could not init libblock.\n");104 printf("%s: Error initializing libblock.\n", cmdname); 103 105 return CMD_FAILURE; 104 106 } 105 107 106 rc = block_ cache_init(handle, BLOCK_SIZE, 2, CACHE_MODE_WB);108 rc = block_get_bsize(handle, &block_size); 107 109 if (rc != EOK) { 108 printf("Error: could not init block cache.\n"); 110 printf("%s: Error determining device block size.\n", cmdname); 111 return CMD_FAILURE; 112 } 113 114 blk = malloc(block_size); 115 if (blk == NULL) { 116 printf("%s: Error allocating memory.\n", cmdname); 117 block_fini(handle); 109 118 return CMD_FAILURE; 110 119 } 111 120 112 121 while (size > 0) { 113 rc = block_ get(&block, handle, boff, 0);122 rc = block_read_direct(handle, ba, 1, blk); 114 123 if (rc != EOK) { 115 printf("Error: could not get block %u, device %u.\n", 116 boff, handle); 124 printf("%s: Error reading block %llu\n", cmdname, ba); 125 free(blk); 126 block_fini(handle); 117 127 return CMD_FAILURE; 118 128 } 119 blk = (uint8_t *) block->data;120 129 121 bytes = (size < BLOCK_SIZE) ? size : BLOCK_SIZE;130 bytes = (size < block_size) ? size : block_size; 122 131 rows = (bytes + BPR - 1) / BPR; 123 132 … … 145 154 } 146 155 147 rc = block_put(block);148 if (rc != EOK) {149 printf("Error: could not put block %p.\n",150 block);151 return CMD_FAILURE;152 }153 154 156 if (size > rows * BPR) 155 157 size -= rows * BPR; … … 157 159 size = 0; 158 160 159 boff += rows * BPR; 161 /* Next block */ 162 ba += 1; 160 163 } 161 164 165 free(blk); 162 166 block_fini(handle); 163 167 -
uspace/srv/part/mbr_part/mbr_part.c
r40240b1 rb53e6d9 39 39 * 40 40 * Limitations: 41 * 41 * 42 42 * Only works with boot records using LBA. CHS-only records are not 43 * supported. Maximum number of partitions is fixed. 43 * supported. 44 * 45 * Referemces: 46 * 47 * The source of MBR structures for this driver have been the following 48 * Wikipedia articles: 49 * - http://en.wikipedia.org/wiki/Master_Boot_Record 50 * - http://en.wikipedia.org/wiki/Extended_boot_record 51 * 52 * The fact that the extended partition has type 0x05 is pure observation. 53 * (TODO: can it have any other type number?) 44 54 */ 45 55 … … 70 80 71 81 /** Boot record signature */ 72 BR_SIGNATURE = 0xAA55 ,82 BR_SIGNATURE = 0xAA55 73 83 }; 74 84 75 85 enum ptype { 86 /** Unused partition entry */ 87 PT_UNUSED = 0x00, 76 88 /** Extended partition */ 77 PT_EXTENDED = 0x05 89 PT_EXTENDED = 0x05, 78 90 }; 79 91 … … 365 377 part->length = len; 366 378 367 part->present = (sa != 0 || len != 0) ? true : false; 379 part->present = (pte->ptype != PT_UNUSED) ? true : false; 380 368 381 part->dev = 0; 369 382 part->next = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.