aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPapoteur <papoteur@mageialinux-online.org>2015-10-08 22:32:37 +0200
committerPapoteur <papoteur@mageialinux-online.org>2015-10-08 22:32:37 +0200
commitebb2d8e4f763dfaac8b2c13ca0fce5880ed4f3d8 (patch)
tree611615a541ce12fc83396a5297c05cbfbdb961d0
parent8ea718ffcc274502c7e0d7f60ee1b6477f153a9a (diff)
downloadisodumper-ebb2d8e4f763dfaac8b2c13ca0fce5880ed4f3d8.tar
isodumper-ebb2d8e4f763dfaac8b2c13ca0fce5880ed4f3d8.tar.gz
isodumper-ebb2d8e4f763dfaac8b2c13ca0fce5880ed4f3d8.tar.bz2
isodumper-ebb2d8e4f763dfaac8b2c13ca0fce5880ed4f3d8.tar.xz
isodumper-ebb2d8e4f763dfaac8b2c13ca0fce5880ed4f3d8.zip
Better management of device busy
-rw-r--r--lib/isodumper.py40
1 files changed, 20 insertions, 20 deletions
diff --git a/lib/isodumper.py b/lib/isodumper.py
index 6dd3647..23a84d2 100644
--- a/lib/isodumper.py
+++ b/lib/isodumper.py
@@ -155,11 +155,6 @@ class UDisks2(object):
list.append(item)
return list
- def unmount(self, device_node_path):
- d = self.device(device_node_path)
- d.Unmount({'force':False, 'auth.no_user_interaction':True},
- dbus_interface=self.FILESYSTEM)
-
def drive_for_device(self, device):
drive = device.Get(self.BLOCK, 'Drive',
dbus_interface='org.freedesktop.DBus.Properties')
@@ -338,14 +333,17 @@ class IsoDumper(object):
self.ima.setDisabled()
self.writebt.setDisabled()
self.do_umount(target)
- # Writing step
- #Dump mode
- self.returncode=0
- b=os.path.getsize(source)
- self.raw_write(source, target, b)
- self.check_write(target, b)
- if self.returncode == 0:
- self.success()
+ if self.returncode != 1:
+ # Writing step
+ #Dump mode
+ self.returncode=0
+ b=os.path.getsize(source)
+ self.raw_write(source, target, b)
+ self.check_write(target, b)
+ if self.returncode == 0:
+ self.success()
+ else:
+ self.restore()
else:
self.restore()
def do_umount(self, target):
@@ -355,16 +353,18 @@ class IsoDumper(object):
for mount in mounts:
self.logger(_('Trying to unmount ')+mount[0]+'...')
try:
- #retcode = call('umount '+mount[0], shell=True)
- retcode = self.u.unmount(mount[0])
- if retcode < 0:
+ retcode = call('umount '+mount[0], shell=True)
+ if retcode == 32:
+ message = _('Partition %s is busy')%mount[0]
+ self.logger(message)
+ self.emergency(message)
+ elif retcode< 0:
message = _('Error, umount ')+mount[0]+_(' was terminated by signal ')+str(retcode)
self.logger(message)
self.emergency(message)
- else:
- if retcode == 0:
+ elif retcode == 0:
self.logger(mount[0]+_(' successfully unmounted'))
- else:
+ else:
message = _('Error, umount ')+mount[0]+_(' returned ')+str(retcode)
self.logger(message)
self.emergency(message)
@@ -396,7 +396,7 @@ class IsoDumper(object):
try:
ofc= io.open(target, 'wb',0)
except:
- message = _('You have not the rights for writing on the device')
+ message = _('You have not the rights for writing on the device') +" "+ target
self.logger(message)
self.emergency(message)
self.close()
> 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
package partition_table_mac; # $Id$

use diagnostics;
#use strict;   - fixed other PPC code to comply, but program bails on empty partition table - sbenedict
use vars qw(@ISA $freepart_device $bootstrap_part $freepart_start $freepart_size $freepart_part $macos_part);

@ISA = qw(partition_table_raw);

use common;
use partition_table_raw;
use partition_table;
use c;

my %typeToDos = (
  "Apple_partition_map" => 0x401,
  "Apple_Bootstrap"	=> 0x401,
  "Apple_Driver43"	=> 0x401,
  "Apple_Driver_IOKit"	=> 0x401,
  "Apple_Patches"	=> 0x401,
  "Apple_HFS"		=> 0x402,
  "Apple_UNIX_SVR2"	=> 0x83,
  "Apple_UNIX_SVR2"     => 0x183,
  "Apple_UNIX_SVR2"     => 0x283,
  "Apple_UNIX_SVR2"     => 0x383,
  "Apple_UNIX_SVR2"     => 0x483,
  "Apple_Free"		=> 0x0,
);
my %typeFromDos = reverse %typeToDos;


my ($bz_format, $bz_fields) = list2kv(
  n	=> 'bzSig',
  n	=> 'bzBlkSize',
  N	=> 'bzBlkCnt',
  n	=> 'bzDevType',
  n	=> 'bzDevID',
  N	=> 'bzReserved',
  n	=> 'bzDrvrCnt',
);
$bz_format = join '', @$bz_format;


my ($dd_format, $dd_fields) = list2kv(
  N	=> 'ddBlock',
  n	=> 'ddSize',
  n	=> 'ddType',
);
$dd_format = join '', @$dd_format;


my ($p_format, $p_fields) = list2kv(
  n	=> 'pSig',
  n	=> 'pSigPad',
  N	=> 'pMapEntry',
  N	=> 'pPBlockStart',
  N	=> 'pPBlocks',

  a32	=> 'pName',
  a32	=> 'pType',

  N	=> 'pLBlockStart',
  N	=> 'pLBlocks',
  N	=> 'pFlags',
  N	=> 'pBootBlock',
  N	=> 'pBootBytes',

  N	=> 'pAddrs1',
  N	=> 'pAddrs2',
  N	=> 'pAddrs3',
  N	=> 'pAddrs4',
  N	=> 'pChecksum',

  a16	=> 'pProcID',
  a128	=> 'pBootArgs',
  a248	=> 'pReserved',
);
$p_format = join '', @$p_format;

my $magic = 0x4552;
my $pmagic = 0x504D;

sub first_usable_sector { 1 }

sub adjustStart($$) {
    my ($hd, $part) = @_;
    my $end = $part->{start} + $part->{size};
    my $partmap_end = $hd->{primary}{raw}[0]{size};

    if ($part->{start} <= $partmap_end) {
        $part->{start} = $partmap_end + 1;
        $part->{size} = $end - $part->{start};
    }
}

sub adjustEnd($$) {
    my ($hd, $part) = @_;
}

sub read($$) {
    my ($hd, $sector) = @_;
    my $tmp;

    local *F; partition_table_raw::openit($hd, *F) or die "failed to open device";
    c::lseek_sector(fileno(F), $sector, 0) or die "reading of partition in sector $sector failed";

    sysread F, $tmp, psizeof($bz_format) or die "error while reading bz \(Block Zero\) in sector $sector";
    my %info; @info{@$bz_fields} = unpack $bz_format, $tmp;
    my $i;

    foreach $i (0 .. $info{bzDrvrCnt}-1) {
        sysread F, $tmp, psizeof($dd_format) or die "error while reading driver data in sector $sector";
        my %dd; @dd{@$dd_fields} = unpack $dd_format, $tmp;
        push @{$info{ddMap}}, \%dd;
    }

    #- check magic number
    $info{bzSig}  == $magic or die "bad magic number";

    my $numparts;
    c::lseek_sector(fileno(F), $sector, 516) or die "reading of partition in sector $sector failed";
    sysread F, $tmp, 4 or die "error while reading partition info in sector $sector";
    $numparts = unpack "N", $tmp;

    my $partmapsize;
    c::lseek_sector(fileno(F), $sector, 524) or die "reading of partition in sector $sector failed";
    sysread F, $tmp, 4 or die "error while reading partition info in sector $sector";
    $partmapsize = ((unpack "N", $tmp) * $info{bzBlkSize}) / psizeof($p_format);

    c::lseek_sector(fileno(F), $sector, 512) or die "reading of partition in sector $sector failed";

    my @pt;
    for ($i=0;$i<$partmapsize;$i++) {
    	my $part;
        sysread F, $part, psizeof($p_format) or die "error while reading partition info in sector $sector";

        push @pt, map {
            my %h; @h{@$p_fields} = unpack $p_format, $part;
            if ($i < $numparts && $h{pSig} eq $pmagic) {

                $h{size} = ($h{pPBlocks} * $info{bzBlkSize}) / 512;
                $h{start} = ($h{pPBlockStart} * $info{bzBlkSize}) / 512;

                if ($h{pType} =~ /^Apple_UNIX_SVR2/i) {
                    $h{pName} =~ /swap/i ? ($h{type} = 0x82) : ($h{type} = 0x83);
                } elsif ($h{pType} =~ /^Apple_Free/i) {
                	#- need to locate a 1MB partition to setup a bootstrap on
                	if (defined $freepart_start && $freepart_size >= 1) {
                		#- already found a suitable partition
                	} else {
                		$freepart_start = $h{start};
                		$freepart_size = $h{size}/2048;
                		$freepart_device = $hd;
                		$freepart_part = "/dev/" . $hd->{device} . ($i+1);
                		log::l("free apple partition found on drive /dev/$freepart_device->{device}, block $freepart_start, size $freepart_size");
                	}
			$h{type} = 0x0;
			$h{pName} = 'Extra';                    
                } elsif ($h{pType} =~ /^Apple_HFS/i) {
                 	$h{type} = 0x402;
                 	if (defined $macos_part) {		
                 		#- swag at identifying MacOS - 1st HFS partition
                 	} else {	
                 		$macos_part = "/dev/" . $hd->{device} . ($i+1);
                 		log::l("found MacOS at partition $macos_part");
                 	}
                } elsif ($h{pType} =~ /^Apple_Partition_Map/i) {
                 	$h{type} = 0x401;
                 	$h{isMap} = 1;
                } elsif ($h{pType} =~ /^Apple_Bootstrap/i) {
                 	$h{type} = 0x401;
                 	$h{isBoot} = 1;
                 	if (defined $bootstrap_part) {
                 		#found a bootstrap already - use it, but log the find
                 		log::l("found another apple bootstrap at partition /dev/$hd->{device}" . ($i+1));
                 	} else {
                 		$bootstrap_part = "/dev/" . $hd->{device} . ($i+1);
                 		log::l("found apple bootstrap at partition $bootstrap_part");
                 	}
                } else {
                 	$h{type} = 0x401;
                     $h{isDriver} = 1;
                };

                # Let's see if this partition is a driver.
                foreach (@{$info{ddMap}}) {
                    $_->{ddBlock} == $h{pPBlockStart} and $h{isDriver} = 1;
                }

            }
            \%h;
        } [ $part ];
    };

    [ @pt ], \%info;
}

sub write($$$;$) {
    my ($hd, $sector, $pt, $info) = @_;

    #- handle testing for writing partition table on file only!
    local *F;
    if ($::testing) {
	my $file = "/tmp/partition_table_$hd->{device}";
	open F, ">$file" or die "error opening test file $file";
    } else {
	partition_table_raw::openit($hd, *F, 2) or die "error opening device $hd->{device} for writing";
        c::lseek_sector(fileno(F), $sector, 0) or return 0;
    }

    # Find the partition map.
    my @partstowrite;
    my $part = $pt->[0];
    (defined $part->{isMap}) or die "the first partition is not the partition map";
    push @partstowrite, $part;

    # Now go thru the partitions, sort and fill gaps.
    my $last;
    while ($part) {
        $last = $part;
        $part = &partition_table::next($hd, $part);
        $part or last;

        if ($last->{start} + $last->{size} < $part->{start}) {
            #There is a gap between partitions.  Fill it and move on.
            push @partstowrite, {
                type => 0x0,
                start => $last->{start} + $last->{size},
                size => $part->{start} - ($last->{start} + $last->{size}),
            };
        }
        push @partstowrite, $part;
    };

    # now, fill a gap at the end if there is one.
    if ($last->{start} + $last->{size} < $hd->{totalsectors}) {
        push @partstowrite, {
            type => 0x0,
            start => $last->{start} + $last->{size},
            size => $hd->{totalsectors} - ($last->{start} + $last->{size}),
     	};
    }

    # Since we didn't create any new drivers, let's try and match up our driver records with out partitons and see if any are missing.
    $info->{bzDrvrCnt} = 0;
    my @ddstowrite;
    my $dd;
    foreach $dd (@{$info->{ddMap}}) {
        foreach (@partstowrite) {
            if ($dd->{ddBlock} == $_->{pPBlockStart}) {
            	push @ddstowrite, $dd;
            	$info->{bzDrvrCnt}++;
            	last;
            }
        }
    }

    # Now let's write our first block.
    syswrite F, pack($bz_format, @$info{@$bz_fields}), psizeof($bz_format) or return 0;

    # ...and now the driver information.
    foreach (@ddstowrite) {
        syswrite F, pack($dd_format, @$_{@$dd_fields}), psizeof($dd_format) or return 0;
    }
    # zero the rest of the data in the first block.
    foreach ( 1 .. (494 - ((@ddstowrite) * 8))) {
     	syswrite F, "\0", 1 or return 0;
    }
    #c::lseek_sector(fileno(F), $sector, 512) or return 0;
    # Now, we iterate thru the partstowrite and write them.
    foreach (@partstowrite) {
        if (!defined $_->{pSig}) {
            # The values we need to write to disk are not defined.  Let's make them up.
            $_->{pSig} = $pmagic;
            $_->{pSigPad} = 0;
            $_->{pPBlockStart} = ($_->{start} * 512) / $info->{bzBlkSize};
            $_->{pPBlocks} = ($_->{size} * 512) / $info->{bzBlkSize};
            $_->{pLBlockStart} = 0;
            $_->{pLBlocks} = $_->{pPBlocks};
            $_->{pBootBlock} = 0;
            $_->{pBootBytes} = 0;
            $_->{pAddrs1} = 0;
            $_->{pAddrs2} = 0;
            $_->{pAddrs3} = 0;
            $_->{pAddrs4} = 0;
            $_->{pChecksum} = 0;
            $_->{pProcID} = "\0";
            $_->{pBootArgs} = "\0";
            $_->{pReserved} = "\0";

            if ($_->{type} == 0x402) {
                $_->{pType} = "Apple_HFS";
                $_->{pName} = "MacOS";
                $_->{pFlags} = 0x4000037F;
            } elsif ($_->{type} == 0x401 && $_->{start} == 1) {
                $_->{pType} = "Apple_Partition_Map";
                $_->{pName} = "Apple";
                $_->{pFlags} = 0x33;
            } elsif ($_->{type} == 0x401) {
                $_->{pType} = "Apple_Bootstrap";
                $_->{pName} = "bootstrap";