implemented microSD mount/unmount functions
This commit is contained in:
@@ -77,6 +77,8 @@ Exports the following functions:
|
|||||||
- `lock_rootfs()`: make the device root filesystem read-only (does nothing on desktop)
|
- `lock_rootfs()`: make the device root filesystem read-only (does nothing on desktop)
|
||||||
- `stat(path)` (aka `du(path)`): alias to `os.stat` but returning the stats as a dictionary
|
- `stat(path)` (aka `du(path)`): alias to `os.stat` but returning the stats as a dictionary
|
||||||
- `statvfs(path)` (aka `df(path)`): alias to `os.statvfs` but returning the stats as a dictionary
|
- `statvfs(path)` (aka `df(path)`): alias to `os.statvfs` but returning the stats as a dictionary
|
||||||
|
- `mount_sd(path='/sd', readonly=False)`: mount the inserted microSD card (T-Deck only, must be FAT32)
|
||||||
|
- `umount_sd(path='/sd')`: unmount the inserted microSD card (T-Deck only)
|
||||||
|
|
||||||
The following `deck.fs` functions are direct aliases to the corresponding `os` call counterparts:
|
The following `deck.fs` functions are direct aliases to the corresponding `os` call counterparts:
|
||||||
|
|
||||||
|
|||||||
+23
-1
@@ -5,7 +5,7 @@ import os
|
|||||||
|
|
||||||
MCU_STORAGE = False
|
MCU_STORAGE = False
|
||||||
try:
|
try:
|
||||||
import storage
|
import storage, sdcardio, board
|
||||||
MCU_STORAGE = True
|
MCU_STORAGE = True
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@@ -18,6 +18,28 @@ def lock_rootfs():
|
|||||||
if MCU_STORAGE:
|
if MCU_STORAGE:
|
||||||
storage.remount("/", readonly=True)
|
storage.remount("/", readonly=True)
|
||||||
|
|
||||||
|
def mount_sd(path='/sd', readonly=False):
|
||||||
|
sd_ok = True
|
||||||
|
if MCU_STORAGE:
|
||||||
|
try:
|
||||||
|
sdcard = sdcardio.SDCard(board.SPI(), board.SDCARD_CS)
|
||||||
|
vfs = storage.VfsFat(sdcard)
|
||||||
|
storage.mount(vfs, path, readonly=readonly)
|
||||||
|
sd_ok = True
|
||||||
|
except:
|
||||||
|
sd_ok = False
|
||||||
|
return sd_ok
|
||||||
|
|
||||||
|
def umount_sd(path='/sd'):
|
||||||
|
sd_ok = True
|
||||||
|
if MCU_STORAGE:
|
||||||
|
try:
|
||||||
|
storage.umount(path)
|
||||||
|
sd_ok = True
|
||||||
|
except:
|
||||||
|
sd_ok = False
|
||||||
|
return sd_ok
|
||||||
|
|
||||||
# TODO: switch to buffered copying to avoid RAM overflow
|
# TODO: switch to buffered copying to avoid RAM overflow
|
||||||
def copy(p1, p2):
|
def copy(p1, p2):
|
||||||
with open(p1, 'rb') as f1:
|
with open(p1, 'rb') as f1:
|
||||||
|
|||||||
+3
-2
@@ -3,10 +3,11 @@
|
|||||||
# Usage: from tdeckboot import *
|
# Usage: from tdeckboot import *
|
||||||
# Created by Luxferre in 2025, released into public domain
|
# Created by Luxferre in 2025, released into public domain
|
||||||
|
|
||||||
from deck.fs import unlock_rootfs, lock_rootfs, env, rnd, sync
|
from deck.fs import unlock_rootfs, lock_rootfs, mount_sd, umount_sd, env, rnd
|
||||||
from deck.fs import du, df, sep, pwd, ls, md, cd, rd, rm, mv, cp
|
from deck.fs import du, df, sep, pwd, ls, md, cd, rd, rm, mv, cp, sync
|
||||||
from deck.input import input, input_multi
|
from deck.input import input, input_multi
|
||||||
from deck.pager import print_paged, term_size
|
from deck.pager import print_paged, term_size
|
||||||
|
# from deck.hwinfo import
|
||||||
from app.ed import edit, view
|
from app.ed import edit, view
|
||||||
try:
|
try:
|
||||||
from deck import net
|
from deck import net
|
||||||
|
|||||||
Reference in New Issue
Block a user