let open_partition name = let fd = handle_unix (Unix.openfile name [ Unix.O_RDWR ]) 0 in (* read the last 4 bytes *) ignore (Unix.lseek fd (-4) Unix.SEEK_END); let buffer = String.create 4 in really_read fd buffer 0 4; let size = (Unix.fstat fd).Unix.st_size in let block_size = read_int buffer 0 in assert ((size - 4) mod block_size = 0); (* compute some values *) let blocktbl_offset = 12 in let block_nb = size / block_size in let blocktbl_size = (block_size - blocktbl_offset) / 4 in let max_file_size = block_size * blocktbl_size in let block_word_size = block_size / 4 in (* read the superblock *) ignore (Unix.lseek fd 0 Unix.SEEK_SET); let buffer = String.create block_size in really_read fd buffer 0 block_size; let inode_nb = read_int buffer 0 in let last_free_inode = read_int buffer 4 in let free_block_list = read_int buffer 8 in let free_block_nb = read_int buffer 12 in let fstype = String.sub buffer (block_size - 4) 4 in let root_inode = 1 in (* generate the partition value *) { part_name = name; part_fd = fd; block_size = block_size; block_nb = block_nb; part_alive = true; block_word_size = block_word_size; blocktbl_offset = blocktbl_offset; blocktbl_size = blocktbl_size; max_file_size = max_file_size; inode_nb = inode_nb; last_free_inode = last_free_inode; free_block_list = free_block_list; free_block_nb = free_block_nb; fstype = fstype; root_inode = root_inode; } |