Skip to content

Commit

Permalink
storage/usbf: Remove and re-install storage when switching between ho…
Browse files Browse the repository at this point in the history
…st and target

This allows to replace the backing file while it is in host mode and
informs the USB gadget about changes to it. Also, the target will not be
able to access it anymore while it is in host mode.

Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
jan-kiszka authored and chombourger committed Apr 20, 2022
1 parent 68dea23 commit b92d55b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mtda/storage/usbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def to_host(self):
self.mtda.debug(3, "storage.usbf.to_host()")
self.lock.acquire()

Composite.remove()

self.mode = self.SD_ON_HOST
result = True

Expand All @@ -113,6 +115,13 @@ def to_target(self):
if result is True:
self.mode = self.SD_ON_TARGET

if self.file is not None:
if os.path.exists(self.file) is True:
result = Composite.install()
else:
self.mtda.debug(1, "storage.usbf.to_target(): "
"{} not found!".format(self.file))

self.lock.release()
self.mtda.debug(3, "storage.usbf.to_target(): {}".format(result))
return result
Expand Down

0 comments on commit b92d55b

Please sign in to comment.