def makefs(root_path, verbose=False): """ Layout: Superblock All Inodes Inode Freelist Block Freelist Root Directory """ if verbose: print("Creating file system at {}".format(root_path)) bootstrap_data = bytes(ds.SuperBlock()) bootstrap_data += bytes(ds.BLOCK_SIZE * ds.NUM_INODES) bootstrap_data += bytes(ds.InodeFreeList()) bootstrap_data += bytes(ds.DataBlockFreeList()) # TODO: Update write a real root directory bootstrap_data += bytes(ds.DirectoryBlock()) bootstrap_data += bytes(ds.BLOCK_SIZE * ds.NUM_DATA_BLOCKS) disk = device_io.Disk(root_path) disk.open() disk.seek(0) disk.write(bootstrap_data) # TODO: remove this hack when real root directory is written ds.DataBlockFreeList(device=disk).allocate() disk.close()
def test_deallocate_with_device(self): input_data = bytes(self.cls.address * ds.BLOCK_SIZE) + \ b'\x00\x00\x00\x00\x01\x01\x01\x01\x01\x01' + \ b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' with open(PATH, 'wb') as f: f.write(input_data) self.cls = ds.InodeFreeList(device=device_io.Disk(PATH)) self.cls.deallocate(index=1) output = self.cls.list expected = [False, True, False, False] + [True] * 6 self.assertEqual(output, expected)
def test_allocate_with_device(self): input_data = bytes(self.cls.address * ds.BLOCK_SIZE) + \ b'\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01' + \ b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' with open(PATH, 'wb') as f: f.write(input_data) self.cls = ds.InodeFreeList(device=device_io.Disk(PATH)) for i in range(3): _ = self.cls.allocate(write_through=False) output = self.cls.list expected = [False] * 3 + [True] * 7 self.assertEqual(output, expected)
def test_allocate_with_device(self): input_data = bytes(ds.SuperBlock()) + \ bytes(ds.NUM_INODES * ds.BLOCK_SIZE) + \ bytes(ds.InodeFreeList()) with open(PATH, 'wb') as f: f.write(input_data) self.cls = ds.Inode(device=device_io.Disk(PATH)) # self.assertEqual(self.cls.index, None) # New inode should have a None index # self.cls.allocate() self.assertEqual(self.cls.index, 0) with self.assertRaises(Exception): self.cls.allocate()
def setUp(self): ds.BLOCK_SIZE = 20 device_io.BLOCK_SIZE = 20 ds.NUM_INODES = 10 self.cls = ds.InodeFreeList() open(PATH, 'a').close()