mirror of
https://github.com/bkerler/mtkclient.git
synced 2024-11-14 19:25:05 -05:00
Add write functionality
This commit is contained in:
parent
3661aaa6e5
commit
08b97560ad
1 changed files with 19 additions and 2 deletions
|
@ -7,6 +7,7 @@ from time import time
|
||||||
import mmap
|
import mmap
|
||||||
import errno
|
import errno
|
||||||
import debugpy
|
import debugpy
|
||||||
|
from tempfile import NamedTemporaryFile
|
||||||
|
|
||||||
class MtkDaFS(LoggingMixIn, Operations):
|
class MtkDaFS(LoggingMixIn, Operations):
|
||||||
def __init__(self, da_handler, rw=False):
|
def __init__(self, da_handler, rw=False):
|
||||||
|
@ -21,7 +22,7 @@ class MtkDaFS(LoggingMixIn, Operations):
|
||||||
st_atime=time(),
|
st_atime=time(),
|
||||||
st_nlink=2)
|
st_nlink=2)
|
||||||
self.files['/emmc_user.bin'] = dict(
|
self.files['/emmc_user.bin'] = dict(
|
||||||
st_mode=(S_IFREG | 0o555),
|
st_mode=(S_IFREG | 0o777) if self.rw else (S_IFREG | 0o555),
|
||||||
st_ctime=time(),
|
st_ctime=time(),
|
||||||
st_mtime=time(),
|
st_mtime=time(),
|
||||||
st_atime=time(),
|
st_atime=time(),
|
||||||
|
@ -36,7 +37,7 @@ class MtkDaFS(LoggingMixIn, Operations):
|
||||||
|
|
||||||
for part in self.da_handler.mtk.daloader.get_partition_data():
|
for part in self.da_handler.mtk.daloader.get_partition_data():
|
||||||
self.files[f'/partitions/{part.name}'] = dict(
|
self.files[f'/partitions/{part.name}'] = dict(
|
||||||
st_mode=(S_IFREG | 0o555),
|
st_mode=(S_IFREG | 0o777) if self.rw else (S_IFREG | 0o555),
|
||||||
st_ctime=time(),
|
st_ctime=time(),
|
||||||
st_mtime=time(),
|
st_mtime=time(),
|
||||||
st_atime=time(),
|
st_atime=time(),
|
||||||
|
@ -56,6 +57,22 @@ class MtkDaFS(LoggingMixIn, Operations):
|
||||||
data = self.da_handler.da_ro(start=file_offset+offset, length=size, filename='', parttype=None)
|
data = self.da_handler.da_ro(start=file_offset+offset, length=size, filename='', parttype=None)
|
||||||
return bytes(data)
|
return bytes(data)
|
||||||
|
|
||||||
|
def write(self, path, data, offset, fh):
|
||||||
|
if not self.rw:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if offset+len(data) > self.files[path]['st_size']:
|
||||||
|
return b''
|
||||||
|
|
||||||
|
file_offset = 0
|
||||||
|
if 'offset' in self.files[path]:
|
||||||
|
file_offset = self.files[path]['offset']
|
||||||
|
|
||||||
|
with NamedTemporaryFile('rb+', buffering=0) as f_write:
|
||||||
|
f_write.write(data)
|
||||||
|
self.da_handler.da_wo(start=file_offset+offset, length=len(data), filename=f_write.name, parttype=None)
|
||||||
|
return len(data)
|
||||||
|
|
||||||
def getattr(self, path, fh=None):
|
def getattr(self, path, fh=None):
|
||||||
if not self.rw:
|
if not self.rw:
|
||||||
self.files[path]['st_mode'] &= ~0o222
|
self.files[path]['st_mode'] &= ~0o222
|
||||||
|
|
Loading…
Reference in a new issue