Skip to content

Commit

Permalink
Fix file creation
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc committed Apr 13, 2022
1 parent f833949 commit 7e75310
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions run/moros-fuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7e75310

Please sign in to comment.