Skip to content
Snippets Groups Projects
Commit eeff4e1e authored by David Grellscheid's avatar David Grellscheid
Browse files

Split library from main

parent ce8f6d43
No related branches found
No related tags found
No related merge requests found
myfilesystem.fs
__pycache__
main.py 0 → 100644
from myfs import format, save, load, copy, remove
import sys
if len(sys.argv) < 2:
# Missing filesystem name. Assuming default myfilesystem.fs
backingfile = 'myfilesystem.fs'
else:
backingfile = sys.argv[1]
# one could actually use a usb stick raw at "/dev/something"
# Data loss, and it'll need reformatting afterwards!
# create backingfile if needed
try:
with open(backingfile, 'x'): pass
except FileExistsError: pass
##########################################
##########################################
alice_sample = """Alice was beginning to get very tired of sitting by her sister on the
bank, and of having nothing to do: once or twice she had peeped into the
book her sister was reading, but it had no pictures or conversations in
it, 'and what is the use of a book,' thought Alice 'without pictures or
conversations?'
"""
print()
print("*" * 60)
print(f"* Use xxd {backingfile} to inspect contents")
print("*" * 60)
print()
with open(backingfile, 'r+b') as f:
format(f)
save(f, "hello.txt", "Hello")
save(f, "alice.txt", alice_sample)
alice_back = load(f, "alice.txt")
print(alice_back)
copy(f, "hello.txt", "clone.txt")
save(f, "bye.txt", "Bye Bye")
copy(f, "hello.txt", "clone2.txt")
remove(f, "bye.txt")
\ No newline at end of file
import sys
if len(sys.argv) < 2:
# Missing filesystem name. Assuming default myfilesystem.fs
backingfile = 'myfilesystem.fs'
else:
backingfile = sys.argv[1]
# one could actually use a usb stick raw at "/dev/something"
# Data loss, and it'll need reformatting afterwards!
# create backingfile if needed
try:
with open(backingfile, 'x'): pass
except FileExistsError: pass
##########################################
##########################################
# file system parameters
TOTAL_SIZE = 0x800 # 2kB
......@@ -115,34 +98,6 @@ def remove(f, filename):
##########################
##########################
alice_sample = """Alice was beginning to get very tired of sitting by her sister on the
bank, and of having nothing to do: once or twice she had peeped into the
book her sister was reading, but it had no pictures or conversations in
it, 'and what is the use of a book,' thought Alice 'without pictures or
conversations?'
"""
if __name__ == "__main__":
print()
print("*" * 60)
print(f"* Use xxd {backingfile} to inspect contents")
print("*" * 60)
print()
with open(backingfile, 'r+b') as f:
format(f)
save(f, "hello.txt", "Hello")
save(f, "alice.txt", alice_sample)
alice_back = load(f, "alice.txt")
print(alice_back)
copy(f, "hello.txt", "clone.txt")
save(f, "bye.txt", "Bye Bye")
copy(f, "hello.txt", "clone2.txt")
remove(f, "bye.txt")
# ls(f)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment