| 1 | // SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-only |
| 4 | |
| 5 | #include "diskutil.h" |
| 6 | |
| 7 | #include <QThread> |
| 8 | |
| 9 | #include <XSys> |
| 10 | |
| 11 | namespace DiskUtil { |
| 12 | XSys::Result MountPartition(const QString &partition) |
| 13 | { |
| 14 | // mount |
| 15 | |
| 16 | QString mountPoint = XSys::DiskUtil::MountPoint(partition); |
| 17 | if (mountPoint.isEmpty()) { |
| 18 | mountPoint = QString("%1").arg(XSys::FS::TmpFilePath("deepin-boot-maker")); |
| 19 | } |
| 20 | |
| 21 | XSys::Result ret = XSys::SynExec("mkdir", QString(" -p %1").arg(mountPoint)); |
| 22 | if (!ret.isSuccess()) { |
| 23 | return ret; |
| 24 | } |
| 25 | |
| 26 | ret = XSys::SynExec("chmod", " a+wrx " + mountPoint); |
| 27 | if (!ret.isSuccess()) { |
| 28 | return ret; |
| 29 | } |
| 30 | |
| 31 | QString mountCmd = "%1 %2"; |
| 32 | QString remountCmd = "-o flush,rw,utf8=1,sync,nodev,nosuid, %1 %2"; |
| 33 | XSys::DiskUtil::UmountDisk(partition); |
| 34 | QThread::sleep(3); |
| 35 | XSys::SynExec("mount", mountCmd.arg(partition).arg(mountPoint)); |
| 36 | QThread::sleep(3); |
| 37 | XSys::SynExec("mount", remountCmd.arg(partition).arg(mountPoint)); |
| 38 | return XSys::Result(XSys::Result::Success, "", mountPoint); |
| 39 | } |
| 40 | } |
| 41 | //#include <libudev.h> |
| 42 | //#include <stdio.h> |
| 43 | |
| 44 | //static struct udev_device * |
| 45 | //get_child( |
| 46 | // struct udev *udev, struct udev_device *parent, const char *subsystem) |
| 47 | //{ |
| 48 | // struct udev_device *child = NULL; |
| 49 | // struct udev_enumerate *enumerate = udev_enumerate_new(udev); |
| 50 | |
| 51 | // udev_enumerate_add_match_parent(enumerate, parent); |
| 52 | // udev_enumerate_add_match_subsystem(enumerate, subsystem); |
| 53 | // udev_enumerate_scan_devices(enumerate); |
| 54 | |
| 55 | // struct udev_list_entry *devices = udev_enumerate_get_list_entry(enumerate); |
| 56 | // struct udev_list_entry *entry; |
| 57 | |
| 58 | // udev_list_entry_foreach(entry, devices) { |
| 59 | // const char *path = udev_list_entry_get_name(entry); |
| 60 | // child = udev_device_new_from_syspath(udev, path); |
| 61 | // break; |
| 62 | // } |
| 63 | |
| 64 | // udev_enumerate_unref(enumerate); |
| 65 | // return child; |
| 66 | //} |
| 67 | |
| 68 | //static void enumerate_usb_mass_storage(struct udev *udev) |
| 69 | //{ |
| 70 | // struct udev_enumerate *enumerate = udev_enumerate_new(udev); |
| 71 | |
| 72 | // udev_enumerate_add_match_subsystem(enumerate, "scsi"); |
| 73 | // udev_enumerate_add_match_property(enumerate, "DEVTYPE", "scsi_device"); |
| 74 | // udev_enumerate_scan_devices(enumerate); |
| 75 | |
| 76 | // struct udev_list_entry *devices = udev_enumerate_get_list_entry(enumerate); |
| 77 | // struct udev_list_entry *entry; |
| 78 | |
| 79 | // udev_list_entry_foreach(entry, devices) { |
| 80 | // const char *path = udev_list_entry_get_name(entry); |
| 81 | // struct udev_device *scsi = udev_device_new_from_syspath(udev, path); |
| 82 | |
| 83 | // struct udev_device *block = get_child(udev, scsi, "block"); |
| 84 | // struct udev_device *scsi_disk = get_child(udev, scsi, "scsi_disk"); |
| 85 | |
| 86 | // struct udev_device *usb |
| 87 | // = udev_device_get_parent_with_subsystem_devtype( |
| 88 | // scsi, "usb", "usb_device"); |
| 89 | |
| 90 | // if (block && scsi_disk && usb) { |
| 91 | // printf("block = %s, usb = %s:%s, scsi = %s\n", |
| 92 | // udev_device_get_devnode(block), |
| 93 | // udev_device_get_sysattr_value(usb, "idVendor"), |
| 94 | // udev_device_get_sysattr_value(usb, "idProduct"), |
| 95 | // udev_device_get_sysattr_value(scsi, "vendor")); |
| 96 | // } |
| 97 | |
| 98 | // if (block) { |
| 99 | // udev_device_unref(block); |
| 100 | // } |
| 101 | |
| 102 | // if (scsi_disk) { |
| 103 | // udev_device_unref(scsi_disk); |
| 104 | // } |
| 105 | |
| 106 | // udev_device_unref(scsi); |
| 107 | // } |
| 108 | |
| 109 | // udev_enumerate_unref(enumerate); |
| 110 | //} |
| 111 |