mirror of
https://github.com/bkerler/mtkclient.git
synced 2024-12-02 12:16:52 -05:00
Add read-only implementation
This commit is contained in:
parent
27b831b32a
commit
caad63555b
3 changed files with 65 additions and 0 deletions
|
@ -9,6 +9,8 @@ from mtkclient.config.payloads import pathconfig
|
|||
from mtkclient.Library.error import ErrorHandler
|
||||
from mtkclient.Library.utils import progress
|
||||
from mtkclient.config.brom_config import efuse, damodes
|
||||
from mtkclient.Library.Filesystem.mtkdafs import MtkDaFS
|
||||
from fuse import FUSE
|
||||
|
||||
|
||||
class DA_handler(metaclass=LogBase):
|
||||
|
|
62
mtkclient/Library/Filesystem/mtkdafs.py
Normal file
62
mtkclient/Library/Filesystem/mtkdafs.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
from fuse import FuseOSError, Operations, LoggingMixIn
|
||||
from pathlib import Path
|
||||
import logging
|
||||
import os
|
||||
from stat import S_IFDIR, S_IFLNK, S_IFREG
|
||||
from time import time
|
||||
import mmap
|
||||
import errno
|
||||
import debugpy
|
||||
|
||||
class MtkDaFS(LoggingMixIn, Operations):
|
||||
def __init__(self, da_handler, rw=False):
|
||||
self.da_handler = da_handler
|
||||
self.rw = rw
|
||||
self.files = {}
|
||||
|
||||
self.files['/'] = dict(
|
||||
st_mode=(S_IFDIR | 0o555),
|
||||
st_ctime=time(),
|
||||
st_mtime=time(),
|
||||
st_atime=time(),
|
||||
st_nlink=2)
|
||||
self.files['/emmc_user.bin'] = dict(
|
||||
st_mode=(S_IFREG | 0o555),
|
||||
st_ctime=time(),
|
||||
st_mtime=time(),
|
||||
st_atime=time(),
|
||||
st_nlink=2,
|
||||
st_size = self.da_handler.mtk.daloader.daconfig.flashsize)
|
||||
self.files['/partitions'] = dict(
|
||||
st_mode=(S_IFDIR | 0o555),
|
||||
st_ctime=time(),
|
||||
st_mtime=time(),
|
||||
st_atime=time(),
|
||||
st_nlink=2)
|
||||
|
||||
for part in self.da_handler.mtk.daloader.get_partition_data():
|
||||
self.files[f'/partitions/{part.name}'] = dict(
|
||||
st_mode=(S_IFREG | 0o555),
|
||||
st_ctime=time(),
|
||||
st_mtime=time(),
|
||||
st_atime=time(),
|
||||
st_nlink=2,
|
||||
st_size = part.sectors*self.da_handler.mtk.daloader.daconfig.pagesize,
|
||||
offset=part.sector*self.da_handler.mtk.daloader.daconfig.pagesize)
|
||||
|
||||
def readdir(self, path, fh):
|
||||
return ['.', '..'] + [ x.removeprefix(path).removeprefix('/') for x in self.files if x.startswith(path) and x != path]
|
||||
|
||||
def read(self, path, size, offset, fh):
|
||||
if size+offset > self.files[path]['st_size']:
|
||||
return b''
|
||||
file_offset = 0
|
||||
if 'offset' in self.files[path]:
|
||||
file_offset = self.files[path]['offset']
|
||||
data = self.da_handler.da_ro(start=file_offset+offset, length=size, filename='', parttype=None)
|
||||
return bytes(data)
|
||||
|
||||
def getattr(self, path, fh=None):
|
||||
if not self.rw:
|
||||
self.files[path]['st_mode'] &= ~0o222
|
||||
return self.files[path]
|
|
@ -8,3 +8,4 @@ pyside6 >= 6.4.0.1
|
|||
mock >= 4.0.3
|
||||
pyserial >= 3.5
|
||||
flake8
|
||||
fusepy
|
||||
|
|
Loading…
Reference in a new issue