Last active
September 8, 2024 23:16
-
-
Save jakiki6/2cfc9e2d72ef27698e2e71d53214188b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fuse import FUSE, Operations, LoggingMixIn | |
import os | |
import stat | |
import obcb | |
class CHECKBOXESWOOHOOOO(LoggingMixIn, Operations): | |
def __init__(self, offset=0): | |
self.offset = offset | |
self.obcb = obcb.OBCB() | |
def getattr(self, path, fh=None): | |
if path == "/": | |
return { | |
'st_mode': (stat.S_IFDIR | 0o755), # Use stat.S_IFDIR | |
'st_nlink': 2 | |
} | |
elif path == f"/blob": | |
return { | |
'st_mode': (stat.S_IFREG | 0o755), # Use stat.S_IFREG | |
'st_nlink': 1, | |
'st_size': 134217728, | |
} | |
else: | |
return {} | |
def open(self, path, flags): | |
return 0 | |
def read(self, path, size, offset, fh): | |
offset += self.offset | |
content = b"" | |
page = None | |
page_id = -1 | |
while size: | |
pid = offset >> 16 | |
if pid != page_id: | |
page_id = pid | |
page = self.obcb.getPageState(pid + 1) | |
content += bytes([page[offset & 32767]]) | |
offset += 1 | |
size -= 1 | |
return content | |
def write(self, path, data, offset, fh): | |
offset += self.offset | |
page = None | |
page_id = -1 | |
for i in range(0, len(data)): | |
pid = offset >> 16 | |
if pid != page_id: | |
page_id = pid | |
page = self.obcb.getPageState(pid + 1) | |
c = page[offset & 32767] | |
for j in range(0, 8): | |
if ((c >> j) ^ (data[i] >> j)) & 1: | |
self.obcb.flip(pid + 1, ((offset & 32767) << 3) | j) | |
offset += 1 | |
return len(data) | |
def readdir(self, path, fh): | |
if path == "/": | |
return [".", "..", "blob"] | |
else: | |
return [".", ".."] | |
def truncate(self, path, length, fh=None): | |
return length | |
if __name__ == '__main__': | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('mountpoint') | |
parser.add_argument('offset') | |
args = parser.parse_args() | |
fuse = FUSE(CHECKBOXESWOOHOOOO(int(args.offset)), args.mountpoint, foreground=True, nothreads=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment