From ff9475ffe49d4ff8bca2b7fc1b6f8105e5277745 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 6 Jul 2020 16:43:29 +0200 Subject: Changed mount function, since libc can't handle loop devices automatically without some how probing partitions? --- helpers/disk.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'helpers/disk.py') diff --git a/helpers/disk.py b/helpers/disk.py index ba7972eb..84a6c2e5 100644 --- a/helpers/disk.py +++ b/helpers/disk.py @@ -1,16 +1,14 @@ import glob, re, os, json from collections import OrderedDict -from helpers.general import sys_command +#import ctypes +#import ctypes.util from exceptions import * -import ctypes -import ctypes.util -import os +from helpers.general import sys_command ROOT_DIR_PATTERN = re.compile('^.*?/devices') GPT = 0b00000001 -libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True) -libc.mount.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_char_p) - +#libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True) +#libc.mount.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_char_p) class BlockDevice(): def __init__(self, path, info): @@ -109,13 +107,14 @@ class Partition(): if not fs: if not self.filesystem: raise DiskError(f'Need to format (or define) the filesystem on {self} before mounting.') fs = self.filesystem - # TODO: Move this to the BlockDevice or something. - ret = libc.mount(self.path.encode(), target.encode(), fs.encode(), 0, options.encode()) - if ret < 0: - errno = ctypes.get_errno() - raise OSError(errno, f"Error mounting {self.path} ({fs}) on {target} with options '{options}': {os.strerror(errno)}") - self.mountpoint = target - + ## libc has some issues with loop devices, defaulting back to sys calls + # ret = libc.mount(self.path.encode(), target.encode(), fs.encode(), 0, options.encode()) + # if ret < 0: + # errno = ctypes.get_errno() + # raise OSError(errno, f"Error mounting {self.path} ({fs}) on {target} with options '{options}': {os.strerror(errno)}") + if sys_command(f'/usr/bin/mount {self.path} {target}').exit_code == 0: + self.mountpoint = target + return True class luks2(): def __init__(self, filesystem): -- cgit v1.2.3-54-g00ecf