mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 09:01:54 +08:00
MSD 支持运行目录存放镜像
This commit is contained in:
@@ -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}")
|
||||
|
||||
@@ -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)))
|
||||
|
||||
@@ -48,7 +48,11 @@ def find_pst() -> Partition:
|
||||
def _find_single(part_type: str) -> Partition:
|
||||
parts = _find_partitions(part_type, True)
|
||||
if len(parts) == 0:
|
||||
raise RuntimeError(f"Can't find {part_type!r} mountpoint")
|
||||
if os.path.exists('/var/lib/kvmd/msd'):
|
||||
#set default value
|
||||
parts = [Partition(mount_path='/var/lib/kvmd/msd', root_path='/var/lib/kvmd/msd', user='kvmd')]
|
||||
else:
|
||||
raise RuntimeError(f"Can't find {part_type!r} mountpoint")
|
||||
return parts[0]
|
||||
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class Drive:
|
||||
# =====
|
||||
|
||||
def set_image_path(self, path: str) -> None:
|
||||
if path:
|
||||
if path or not self.__has_param("forced_eject"):
|
||||
self.__set_param("file", path)
|
||||
else:
|
||||
self.__set_param("forced_eject", "")
|
||||
@@ -75,7 +75,9 @@ class Drive:
|
||||
return (not int(self.__get_param("ro")))
|
||||
|
||||
# =====
|
||||
|
||||
def __has_param(self, param: str) -> bool:
|
||||
return os.access(os.path.join(self.__lun_path, param), os.F_OK)
|
||||
|
||||
def __get_param(self, param: str) -> str:
|
||||
with open(os.path.join(self.__lun_path, param)) as file:
|
||||
return file.read().strip()
|
||||
|
||||
Reference in New Issue
Block a user