Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/tcc -run
- /*
- * lbainfo.c -- print information about a given LBA
- * jrra 2012
- *
- * Usage: ./lbainfo.c <disk type> <LBA>
- *
- * Example run:
- * > ./lbainfo.c 3 833
- * Disk type: 3
- * LBA: 833
- * pzone: 2
- * vzone: 2
- * size: 17680 bytes
- * offset: 15472720 bytes
- */
- #include <stdio.h>
- #include <errno.h>
- int pzone_tbl1[7][16] = {
- /*disk type 0*/ {267, 559, 833, 1125, 1417, 1691, 1965, 2239, 2513, 2717, 2921, 3195, 3469, 3743, 4017, 4291,},
- /*disk type 1*/ {267, 559, 833, 1107, 1381, 1673, 1965, 2239, 2513, 2787, 2991, 3195, 3469, 3743, 4017, 4291,},
- /*disk type 2*/ {267, 559, 833, 1107, 1381, 1655, 1929, 2221, 2513, 2787, 3061, 3265, 3469, 3743, 4017, 4291,},
- /*disk type 3*/ {267, 559, 833, 1107, 1381, 1655, 1929, 2203, 2477, 2769, 3061, 3335, 3539, 3743, 4017, 4291,},
- /*disk type 4*/ {267, 559, 833, 1107, 1381, 1655, 1929, 2203, 2477, 2751, 3025, 3317, 3609, 3813, 4017, 4291,},
- /*disk type 5*/ {267, 559, 833, 1107, 1381, 1655, 1929, 2133, 2407, 2681, 2955, 3229, 3503, 3795, 4087, 4291,},
- /*disk type 6*/ {267, 559, 833, 1107, 1381, 1655, 1929, 2133, 2337, 2611, 2885, 3159, 3433, 3707, 3999, 4291,},
- };
- int pzone_tbl2[7][16] = {
- /*disk type 0*/ { 0, 1, 2, 14, 15, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,},
- /*disk type 1*/ { 0, 1, 2, 3, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 12,},
- /*disk type 2*/ { 0, 1, 2, 3, 4, 12, 13, 14, 15, 5, 6, 7, 8, 9, 10, 11,},
- /*disk type 3*/ { 0, 1, 2, 3, 4, 5, 11, 12, 13, 14, 15, 6, 7, 8, 9, 10,},
- /*disk type 4*/ { 0, 1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 7, 8, 9,},
- /*disk type 5*/ { 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 8,},
- /*disk type 6*/ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,},
- };
- int vzone_tbl[16] = {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1,
- };
- int block_size_per_vzone[9] = {
- 19720, 18360, 17680, 16320, 14960, 13600, 12240, 10880, 9520,
- };
- int lba_to_pzone( int type, int lba )
- {
- int pzone = 0;
- int i;
- for( i=15; i>=0; i-- )
- if( lba <= pzone_tbl1[type][i] )
- pzone = pzone_tbl2[type][i];
- else
- break;
- return pzone;
- }
- int pzone_to_vzone( int pzone )
- {
- return vzone_tbl[ pzone ];
- }
- int size_of_lba( int type, int lba )
- {
- return block_size_per_vzone[ pzone_to_vzone( lba_to_pzone( type, lba ) ) ];
- }
- int size_of_sectors( int type, int lba )
- {
- return size_of_lba( type, lba ) / 85;
- }
- int lba_to_offset( int type, int lba )
- {
- int offset = 0;
- int i;
- for( i = 0; i<lba; i++ )
- offset += size_of_lba( type, i );
- return offset;
- }
- int main( int argc, char* argv[] )
- {
- if( argc < 3 )
- {
- printf("Usage: lbainfo <disk type> <LBA>\n");
- return 1;
- }
- errno = 0;
- int type = (int)strtol( argv[1], NULL, 0 );
- if( type > 6 || type < 0 || errno != 0 )
- {
- printf("Disk type must be between 0 and 6\n");
- return 2;
- }
- errno = 0;
- int lba = (int)strtol( argv[2], NULL, 0 );
- if( lba > 4291 || lba < 0 || errno != 0 )
- {
- printf("LBA must be between 0 and 4291\n");
- return 3;
- }
- printf("Disk type: %d\n", type);
- printf("LBA: %d\n", lba);
- int pzone;
- int vzone;
- int size;
- int secsize;
- int offset;
- // First, let's figure out the pzone.
- pzone = lba_to_pzone( type, lba );
- printf("pzone: %d\n", pzone);
- // Let's figure out the vzone.
- vzone = pzone_to_vzone( pzone );
- printf("vzone: %d\n", vzone);
- // Size of this block.
- size = size_of_lba( type, lba );
- printf("block size: %d bytes\n", size);
- // Size of sectors in this block.
- secsize = size_of_sectors( type, lba );
- printf("sector size: %d bytes\n", secsize);
- // Let's figure out the offset.
- offset = lba_to_offset( type, lba );
- printf("offset: %d bytes\n", offset);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement