mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
get rid of the otg-unlock helper
This commit is contained in:
@@ -71,7 +71,7 @@ def _rmdir(path: str) -> None:
|
||||
def _unlink(path: str, optional: bool=False) -> None:
|
||||
logger = get_logger()
|
||||
if optional and not os.access(path, os.F_OK):
|
||||
logger.info("SKIP-RM - %s", path)
|
||||
logger.info("RM ------ [SKIPPED] %s", path)
|
||||
return
|
||||
logger.info("RM ------ %s", path)
|
||||
os.unlink(path)
|
||||
@@ -185,6 +185,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)
|
||||
_symlink(func_path, join(self.__profile_path, func))
|
||||
name = ("Mass Storage Drive" if self.__msd_instance == 0 else f"Extra Drive #{self.__msd_instance}")
|
||||
self.__create_meta(func, name)
|
||||
@@ -269,8 +270,6 @@ def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements
|
||||
logger.info("Enabling the gadget ...")
|
||||
_write(join(gadget_path, "UDC"), udc)
|
||||
time.sleep(config.otg.init_delay)
|
||||
|
||||
logger.info("Setting up permissions ...")
|
||||
_chown(join(gadget_path, "UDC"), config.otg.user)
|
||||
_chown(profile_path, config.otg.user)
|
||||
|
||||
@@ -290,7 +289,7 @@ def _cmd_stop(config: Section) -> None:
|
||||
logger.info("Disabling gadget %r ...", config.otg.gadget)
|
||||
_write(join(gadget_path, "UDC"), "\n")
|
||||
|
||||
_unlink(join(gadget_path, "os_desc", usb.G_PROFILE_NAME), True)
|
||||
_unlink(join(gadget_path, "os_desc", usb.G_PROFILE_NAME), optional=True)
|
||||
|
||||
profile_path = join(gadget_path, usb.G_PROFILE)
|
||||
for func in os.listdir(profile_path):
|
||||
|
||||
@@ -21,15 +21,12 @@
|
||||
|
||||
|
||||
import os
|
||||
import signal
|
||||
import errno
|
||||
import argparse
|
||||
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
|
||||
import psutil
|
||||
|
||||
from ...validators.basic import valid_bool
|
||||
from ...validators.basic import valid_int_f0
|
||||
from ...validators.os import valid_abs_file
|
||||
@@ -59,21 +56,6 @@ def _set_param(gadget: str, instance: int, param: str, value: str) -> None:
|
||||
raise
|
||||
|
||||
|
||||
def _unlock() -> None:
|
||||
# https://github.com/torvalds/linux/blob/3039fad/drivers/usb/gadget/function/f_mass_storage.c#L2924
|
||||
found = False
|
||||
for proc in psutil.process_iter():
|
||||
attrs = proc.as_dict(attrs=["name", "exe", "pid"])
|
||||
if attrs.get("name") == "file-storage" and not attrs.get("exe"):
|
||||
try:
|
||||
proc.send_signal(signal.SIGUSR1)
|
||||
found = True
|
||||
except Exception as err:
|
||||
raise SystemExit(f"Can't send SIGUSR1 to MSD kernel thread with pid={attrs['pid']}: {err}")
|
||||
if not found:
|
||||
raise SystemExit("Can't find MSD kernel thread")
|
||||
|
||||
|
||||
# =====
|
||||
def main(argv: Optional[List[str]]=None) -> None:
|
||||
(parent_parser, argv, config) = init(
|
||||
@@ -88,8 +70,6 @@ def main(argv: Optional[List[str]]=None) -> None:
|
||||
)
|
||||
parser.add_argument("-i", "--instance", default=0, type=valid_int_f0,
|
||||
metavar="<N>", help="Drive instance (0 for KVMD drive)")
|
||||
parser.add_argument("--unlock", action="store_true",
|
||||
help="Send SIGUSR1 to MSD kernel thread")
|
||||
parser.add_argument("--set-cdrom", default=None, type=valid_bool,
|
||||
metavar="<1|0|yes|no>", help="Set CD-ROM flag")
|
||||
parser.add_argument("--set-rw", default=None, type=valid_bool,
|
||||
@@ -107,11 +87,8 @@ def main(argv: Optional[List[str]]=None) -> None:
|
||||
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.unlock:
|
||||
_unlock()
|
||||
|
||||
if options.eject:
|
||||
set_param("file", "")
|
||||
set_param("forced_eject", "")
|
||||
|
||||
if options.set_cdrom is not None:
|
||||
set_param("cdrom", str(int(options.set_cdrom)))
|
||||
|
||||
Reference in New Issue
Block a user