from littlefs import LittleFS
import os
fs = LittleFS(block_size=512, block_count=256)
print("Initial used blocks: ", fs.used_block_count)
fs.makedirs("/a/b/c/d")

with fs.open("/a/b/file.bin", "wb") as f:
    f.write(os.urandom(1024*120))  # Write 120*1KB of random data

for root, dirs, files in fs.walk("."):
    print(f"root {root} dirs {dirs} files {files}")

print("Used blocks before rename: ", fs.used_block_count)

fs.rename("/a/b", "/a/b/c/d")
print("Used blocks after rename: ", fs.used_block_count)
print("file tree after rename:")
for root, dirs, files in fs.walk("."):
    print(f"root {root} dirs {dirs} files {files}")

fs.fs_mkconsistent()
fs.fs_gc()

print("Used blocks after gc: ", fs.used_block_count)

print("try to write another file /file.bin")
with fs.open("/file.bin", "wb") as f:
    f.write(os.urandom(1024*120))  # Fails do to no space left

