~martijnbraam/thumbdrives

ref: 2024dbe250abc1533b29a0e9ce33ad7992ccf030 thumbdrives/src/vdisk.py -rw-r--r-- 728 bytes
2024dbe2Martijn Braam Patched up desktop file 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import subprocess

def mount(backing_file, cdimage=False):
    action = 'mount-mass-storage'
    if cdimage:
        action = 'mount-iso'

    subprocess.run(['pkexec', 'pk-thumbdrive-action', action, backing_file])

def unmount():
    subprocess.run(['pkexec', 'pk-thumbdrive-action', 'umount'])

def get_mounted():
    gadget = "/sys/kernel/config/usb_gadget/thumbdrives"
    if not os.path.isdir(gadget):
        return None

    with open(gadget + "/UDC") as handle:
        raw = handle.read()

    if raw.strip() == "":
        return None

    with open(gadget+"/functions/mass_storage.0/lun.0/file") as handle:
        raw = handle.read()

    if raw.strip() == "":
        return None

    return raw.strip()