static int init_file_system(void) { char super_block[BLOCK_SIZE]; int num_directory_blocks; int block_num; struct fs_header *header; // SDMMC not supported on FPGA currently. Fall back to ramdisk if it fails. if (init_sdmmc_device() < 0) { printf("init_file_system: SDMMC init failed, using ramdisk\n"); use_ramdisk = 1; } // Read directory if (read_block(0, super_block) <= 0) { printf("init_file_system: error reading directory\n"); return -1; } header = (struct fs_header*) super_block; if (memcmp(header->magic, FS_MAGIC, 4) != 0) { printf("init_file_system: invalid magic value\n"); return -1; } num_directory_blocks = ((header->num_directory_entries - 1) * sizeof(struct directory_entry) + sizeof(struct fs_header) + BLOCK_SIZE - 1) / BLOCK_SIZE; directory = (struct fs_header*) kmalloc((num_directory_blocks * BLOCK_SIZE + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)); memcpy(directory, super_block, BLOCK_SIZE); for (block_num = 1; block_num < num_directory_blocks; block_num++) { if (read_block(block_num, ((char*)directory) + BLOCK_SIZE * block_num) <= 0) return -1; } return 0; }
int main() { char *buf = (char*) 0x200000; if (init_sdmmc_device() < 0) { printf("error initializing card\n"); return -1; } // Read blocks in reverse order to verify address is set correctly. for (int i = TRANSFER_LENGTH - 1; i >= 0; i--) { if (read_sdmmc_device(i, buf + i * SDMMC_BLOCK_SIZE) < 0) { printf("read_sdmmc_device returned error\n"); return 1; } } return 0; }