I'm working on Pintos part 4, specifically indirect blocks for the inode data structure. The block is supposed to have (512 / 4) = 128 integers referring to other disk sectors inside of it. I did a small mock up here in my c program to write mock sectors to a malloc'd mock sector and then read it back. Why are the keys so big? Why isn't it 0, 1, 2, 3, 4.
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
void *mock_sector = malloc(512);
for (uint32_t i = 0; i < 20; i++) {
memset(mock_sector + i * sizeof(uint32_t), i, sizeof(uint32_t));
}
uint32_t key;
for (uint32_t i = 0; i < 20; i++) {
memcpy(&key, mock_sector + i * sizeof(uint32_t), sizeof(uint32_t));
printf("Key is: %d\n", key);
}
return 0;
}
Result ->
Key is: 0
Key is: 16843009
Key is: 33686018
Key is: 50529027
Key is: 67372036
Key is: 84215045
Key is: 101058054
Key is: 117901063
Key is: 134744072
Key is: 151587081
Key is: 168430090
Key is: 185273099
Key is: 202116108
Key is: 218959117
Key is: 235802126
Key is: 252645135
Key is: 269488144
Key is: 286331153
Key is: 303174162
Key is: 320017171
I can even see the addresses I am calling memset on are increasing as they should.
0x18aa010 0x18aa014 0x18aa018 0x18aa01c 0x18aa020 0x18aa024 0x18aa028 0x18aa02c