mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
parent
de5cb73b93
commit
72dce4de89
@ -260,8 +260,8 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
|
||||
flags |= (os.O_RDWR if self.__read_size else os.O_WRONLY)
|
||||
self.__fd = os.open(self.__device_path, flags)
|
||||
except Exception as err:
|
||||
logger.error(self.gettext("Can't open HID-%s device %s: %s"),
|
||||
self.__name, self.__device_path, tools.efmt(err))
|
||||
#logger.error(self.gettext("Can't open HID-%s device %s: %s"),self.__name, self.__device_path, tools.efmt(err))
|
||||
pass
|
||||
|
||||
if self.__fd >= 0:
|
||||
try:
|
||||
|
||||
@ -25,6 +25,7 @@ import contextlib
|
||||
import dataclasses
|
||||
import functools
|
||||
import time
|
||||
import os
|
||||
|
||||
from typing import AsyncGenerator
|
||||
|
||||
@ -259,6 +260,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
||||
|
||||
@aiotools.atomic_fg
|
||||
async def set_connected(self, connected: bool) -> None:
|
||||
print(self.__drive)
|
||||
async with self.__state.busy():
|
||||
assert self.__state.vd
|
||||
if connected:
|
||||
@ -274,6 +276,15 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
||||
|
||||
self.__drive.set_rw_flag(self.__state.vd.rw)
|
||||
self.__drive.set_cdrom_flag(self.__state.vd.cdrom)
|
||||
#reboot UDC to fix otg cd-rom and flash switch
|
||||
udc_path = self.__drive.get_udc_path()
|
||||
with open(udc_path) as file:
|
||||
enabled = bool(file.read().strip())
|
||||
if enabled:
|
||||
with open(udc_path, "w") as file:
|
||||
file.write("\n")
|
||||
with open(udc_path, "w") as file:
|
||||
file.write(sorted(os.listdir("/sys/class/udc"))[0])
|
||||
if self.__state.vd.rw:
|
||||
await self.__state.vd.image.remount_rw(True)
|
||||
self.__drive.set_image_path(self.__state.vd.image.path)
|
||||
|
||||
@ -40,6 +40,7 @@ class MsdDriveLockedError(MsdOperationError):
|
||||
class Drive:
|
||||
def __init__(self, gadget: str, instance: int, lun: int) -> None:
|
||||
func = f"mass_storage.usb{instance}"
|
||||
self.__udc_path = os.path.join(f"/sys/kernel/config/usb_gadget", gadget, usb.G_UDC)
|
||||
self.__profile_func_path = usb.get_gadget_path(gadget, usb.G_PROFILE, func)
|
||||
self.__profile_path = usb.get_gadget_path(gadget, usb.G_PROFILE)
|
||||
self.__lun_path = usb.get_gadget_path(gadget, usb.G_FUNCTIONS, func, f"lun.{lun}")
|
||||
@ -49,6 +50,9 @@ class Drive:
|
||||
|
||||
def get_watchable_paths(self) -> list[str]:
|
||||
return [self.__lun_path, self.__profile_path]
|
||||
|
||||
def get_udc_path(self) -> str:
|
||||
return self.__udc_path
|
||||
|
||||
# =====
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user