From 57e1c990a7121de6ba52602d7664620b6020070c Mon Sep 17 00:00:00 2001 From: hama Date: Wed, 3 Feb 2016 08:13:27 +0100 Subject: [PATCH] renamed to onAbout...() --- appl/rebackgui/osconnect.pl | 106 +++++++++++++++++++++++++++++ appl/rebackgui/rebackgui.pro | 3 +- appl/reimgconvert/mainwindow.cpp | 4 +- appl/reimgconvert/mainwindow.hpp | 4 +- appl/reimgconvert/reimgconvert.pro | 1 + 5 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 appl/rebackgui/osconnect.pl diff --git a/appl/rebackgui/osconnect.pl b/appl/rebackgui/osconnect.pl new file mode 100644 index 0000000..99c5700 --- /dev/null +++ b/appl/rebackgui/osconnect.pl @@ -0,0 +1,106 @@ +#! /usr/bin/perl + +use strict; + +my $mode = shift; +my %devs; +if ($mode eq "find-label"){ + my $targetPath = shift; + if (! -d $targetPath){ + &Usage("not a directory: $targetPath"); + } + %devs = &LabelOfDevs; + open($CMD, "mount|") || die "cannot execute mount: $!"; + my ($label, $relPath); + while(<$CMD>){ + # /dev/sdb1 on /media/src type vfat (rw,...) + if(/(\S+) on (\S+)/){ + my ($dev, $path) = ($1, $2); + if (index($targetPath, $path) == 0){ + if ($devs{$dev} ne ""){ + $label = $devs{$dev}; + $relPath = substr($targetPath, length($path) + 1); + } + } + } + } + close $CMD; + if ($label eq ""){ + &Usage("no mounted device found"); + } else { + print "L=\"$label\"\n$relPath\n"; + } +} elsif ($mode eq "search-target"){ + my $label = shift; + my $relPath = shift; + &Usage("missing label") unless $label; + &Usage("missing relative path") unless $relPath; + + %devs = &LabelOfDevs; + if ( + # /dev/sdb1: LABEL="EFI system" UUID="80F7-47BB" TYPE="vfat" ... + open(my $CMD, "blkid|") || die "cannot execute blkid: $!"; + while(<$CMD>){ + if(/(\S+): LABEL="(.*?)"/){ + $devs{$1} = $2; + } + } +close $CMD; +} else { + &Usage("unknown mode"); +} + + +sub Usage{ + my $msg = shift; + print < + Search the label of the device containing . + Output: + L=