MSD 支持运行目录存放镜像

This commit is contained in:
mofeng-git
2024-10-05 14:31:23 +00:00
parent eca4167789
commit 507c46b986
9 changed files with 40 additions and 16 deletions

View File

@@ -52,8 +52,12 @@ def _mkdir(path: str) -> None:
os.mkdir(path)
def _chown(path: str, user: str) -> None:
get_logger().info("CHOWN --- %s - %s", user, path)
def _chown(path: str, user: str, optional: bool=False) -> None:
logger = get_logger()
if optional and not os.access(path, os.F_OK):
logger.info("CHOWN --- %s - [SKIPPED] %s", user, path)
return
logger.info("CHOWN --- %s - %s", user, path)
shutil.chown(path, user)
@@ -187,7 +191,7 @@ class _GadgetConfig:
_chown(join(func_path, "lun.0/cdrom"), user)
_chown(join(func_path, "lun.0/ro"), user)
_chown(join(func_path, "lun.0/file"), user)
_chown(join(func_path, "lun.0/forced_eject"), user)
_chown(join(func_path, "lun.0/forced_eject"), user, optional=True)
if start:
_symlink(func_path, join(self.__profile_path, func))
name = ("Mass Storage Drive" if self.__msd_instance == 0 else f"Extra Drive #{self.__msd_instance}")

View File

@@ -34,6 +34,9 @@ from .. import init
# =====
def _has_param(gadget: str, instance: int, param: str) -> bool:
return os.access(_get_param_path(gadget, instance, param), os.F_OK)
def _get_param_path(gadget: str, instance: int, param: str) -> str:
return usb.get_gadget_path(gadget, usb.G_FUNCTIONS, f"mass_storage.usb{instance}/lun.0", param)
@@ -83,12 +86,15 @@ def main(argv: (list[str] | None)=None) -> None:
if config.kvmd.msd.type != "otg":
raise SystemExit(f"Error: KVMD MSD not using 'otg'"
f" (now configured {config.kvmd.msd.type!r})")
has_param = (lambda param: _has_param(config.otg.gadget, options.instance, param))
set_param = (lambda param, value: _set_param(config.otg.gadget, options.instance, param, value))
get_param = (lambda param: _get_param(config.otg.gadget, options.instance, param))
if options.eject:
set_param("forced_eject", "")
if has_param("forced_eject"):
set_param("forced_eject", "")
else:
set_param("file", "")
if options.set_cdrom is not None:
set_param("cdrom", str(int(options.set_cdrom)))