From 7e753109cb6f312782ba459f40e90ecbe2a2e34c Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Wed, 13 Apr 2022 09:45:28 +0200 Subject: [PATCH] Fix file creation --- run/moros-fuse.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/run/moros-fuse.py b/run/moros-fuse.py index 065d77c59..b234cd297 100644 --- a/run/moros-fuse.py +++ b/run/moros-fuse.py @@ -143,15 +143,17 @@ def mkdir(self, path, mode): self.create(path, S_IFDIR | mode) def create(self, path, mode): - #print("\x1b[1;31m") - (path, _, filename) = path.rpartition("/") + (path, _, name) = path.rpartition("/") + entries = self.readdir(path + "/", 0) pos = self.image.tell() - self.readdir(path + "/", 0) - pos = self.image.tell() - #print("DEBUG: create('%s/%s', %o) -> pos=0x%x" % (path, filename, mode, pos)) - #print("mode=%d S_IFDIR=%s" % (mode, S_IFDIR)) + + # Update parent dir size + (_, _, parent_size, _, parent_name) = self.__scan(path) + parent_size = (1 + 4 + 4 + 8 + 1) * len(entries) + len("".join(entries)) + self.image.seek(-(4 + 8 + 1 + len(parent_name)), 1) + self.image.write(parent_size.to_bytes(4, "big")) + kind = int((mode & S_IFDIR) != S_IFDIR) - #print("DEBUG: kind=%s" % kind) size = 0 addr = self.__next_free_addr() self.__alloc(addr) @@ -161,13 +163,14 @@ def create(self, path, mode): self.image.write((addr // self.block_size).to_bytes(4, "big")) self.image.write(size.to_bytes(4, "big")) self.image.write(int(time()).to_bytes(8, "big")) - self.image.write(len(filename).to_bytes(1, "big")) - self.image.write(filename.encode("utf-8")) - #print("\x1b[0m") + self.image.write(len(name).to_bytes(1, "big")) + self.image.write(name.encode("utf-8")) return 0 def write(self, path, data, offset, fh): (_, addr, size, _, name) = self.__scan(path) + pos = self.image.tell() + print(" --> pos=%s addr=%s size=%d name='%s'" % (pos, addr, size, name)) n = self.block_size - 4 # Space available for data in blocks j = size % n # Start of space available in last block @@ -177,6 +180,10 @@ def write(self, path, data, offset, fh): size = max(size, offset + len(data)) self.image.write(size.to_bytes(4, "big")) + (_, addr, size, _, name) = self.__scan(path) + pos = self.image.tell() + print(" --> pos=%s addr=%s size=%d name='%s'" % (pos, addr, size, name)) + for i in range(0, offset, n): self.image.seek(addr) next_addr = int.from_bytes(self.image.read(4), "big") * self.block_size