summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/mpremote/mpremote/pyboardextended.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/mpremote/mpremote/pyboardextended.py b/tools/mpremote/mpremote/pyboardextended.py
index 70e3748ec..41f360e5f 100644
--- a/tools/mpremote/mpremote/pyboardextended.py
+++ b/tools/mpremote/mpremote/pyboardextended.py
@@ -21,6 +21,8 @@ fs_hook_cmds = {
"CMD_SEEK": 8,
"CMD_REMOVE": 9,
"CMD_RENAME": 10,
+ "CMD_MKDIR": 11,
+ "CMD_RMDIR": 12,
}
fs_hook_code = """\
@@ -265,6 +267,24 @@ class RemoteFS:
if res < 0:
raise OSError(-res)
+ def mkdir(self, path):
+ c = self.cmd
+ c.begin(CMD_MKDIR)
+ c.wr_str(self.path + path)
+ res = c.rd_s32()
+ c.end()
+ if res < 0:
+ raise OSError(-res)
+
+ def rmdir(self, path):
+ c = self.cmd
+ c.begin(CMD_RMDIR)
+ c.wr_str(self.path + path)
+ res = c.rd_s32()
+ c.end()
+ if res < 0:
+ raise OSError(-res)
+
def stat(self, path):
c = self.cmd
c.begin(CMD_STAT)
@@ -501,6 +521,28 @@ class PyboardCommand:
ret = -abs(er.errno)
self.wr_s32(ret)
+ def do_mkdir(self):
+ path = self.root + self.rd_str()
+ # self.log_cmd(f"mkdir {path}")
+ try:
+ self.path_check(path)
+ os.mkdir(path)
+ ret = 0
+ except OSError as er:
+ ret = -abs(er.errno)
+ self.wr_s32(ret)
+
+ def do_rmdir(self):
+ path = self.root + self.rd_str()
+ # self.log_cmd(f"rmdir {path}")
+ try:
+ self.path_check(path)
+ os.rmdir(path)
+ ret = 0
+ except OSError as er:
+ ret = -abs(er.errno)
+ self.wr_s32(ret)
+
cmd_table = {
fs_hook_cmds["CMD_STAT"]: do_stat,
fs_hook_cmds["CMD_ILISTDIR_START"]: do_ilistdir_start,
@@ -512,6 +554,8 @@ class PyboardCommand:
fs_hook_cmds["CMD_SEEK"]: do_seek,
fs_hook_cmds["CMD_REMOVE"]: do_remove,
fs_hook_cmds["CMD_RENAME"]: do_rename,
+ fs_hook_cmds["CMD_MKDIR"]: do_mkdir,
+ fs_hook_cmds["CMD_RMDIR"]: do_rmdir,
}