Changeset 3488 in MondoRescue for branches/3.2/MondoRescue/bin/mr-label
- Timestamp:
- Dec 3, 2015, 3:07:55 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/MondoRescue/bin/mr-label
r3486 r3488 27 27 =head1 SYNOPSIS 28 28 29 mr-label [-v][-h][- l label] device|file29 mr-label [-v][-h][-L LABEL|-U UUID] device|file 30 30 31 31 =head1 ARGUMENTS … … 55 55 Prints the manual page and exits. 56 56 57 =item B<- l label>57 =item B<-L LABEL> 58 58 59 This is the new label to put on the VFAT filesystem 59 This is the new LABEL to put on the VFAT filesystem 60 61 =item B<-U UUID> 62 63 This is the new UUID to put on the VFAT filesystem 60 64 61 65 =back … … 92 96 "man" => \$opts{'man'}, 93 97 "verbose|v+" => \$opts{'v'}, 94 "label|l=s" => \$opts{'l'}, 98 "label|L=s" => \$opts{'L'}, 99 "uuid|U=s" => \$opts{'U'}, 95 100 ) || pb_syntax(-1,0); 96 101 … … 107 112 pb_temp_init($pbdebug); 108 113 109 my $label=$opts{'l'}; 110 die "Unable no label defined, use -l label" if (not defined $label); 114 my $label=$opts{'L'}; 115 my $uuid=$opts{'U'}; 116 die "Unable no label/uuid defined" if ((not defined $label) && (not defined $uuid)); 111 117 112 118 my $inputf = $ARGV[0]; 113 119 die "$0: no input file defined" if (not defined $inputf); 114 120 115 my($inputfh, $buffer );121 my($inputfh, $buffer, $offset, $length, $hexlabel, $newbuf); 116 122 open($inputfh, "+< $inputf") || die "$0: cannot open $inputf for reading/writing: $!"; 117 123 binmode($inputfh) || die "binmode failed: $!"; 118 124 119 # 42 first bytes are untouched 120 if (! seek($inputfh, 43,0)) { 125 if (defined $label) { 126 # 42 first bytes are untouched 127 $offset = 43; 128 $length = 11; 129 } elsif (defined $uuid) { 130 # 38 first bytes are untouched 131 $offset = 39; 132 $length = 4; 133 $newbuf = ""; 134 } else { 135 die "Nothing to do no label/uuid defined"; 136 } 137 138 if (! seek($inputfh, $offset,0)) { 121 139 die "Unable to seek $inputf: $!"; 122 140 } 141 # then read the following bytes 142 my $size = read($inputfh, $buffer, $length); 143 if ($size != $length) { 144 die "Unable to read existing label/uuid: $!"; 145 } 123 146 124 # Label is then the 11 following bytes 125 my $size = read($inputfh, $buffer, 11); 126 if ($size != 11) { 127 die "Unable to read existing label: $!"; 147 if (defined $label) { 148 pb_log(1,"Previous label was ***$buffer***\n"); 149 } elsif (defined $uuid) { 150 my ($hex) = unpack( 'H*', $buffer ); 151 #for my $d (split('',$buffer)) { 152 #pb_log(1,"Char analyzed: ".hex($d)."\n"); 153 #$newbuf = $d.$newbuf; 154 #} 155 pb_log(1,"Previous hex was ***$hex***\n"); 156 my @loc = ($hex =~ m/../g); 157 print Dumper(@loc); 158 $hex = join('',reverse(@loc)); 159 pb_log(1,"Previous uuid was ***$hex***\n"); 160 } else { 161 die "Nothing to do no label/uuid defined"; 128 162 } 129 pb_log(1,"Previous label was ***$buffer***\n"); 130 my $hexlabel=sprintf("%-11s", uc($label)); 131 pb_log(1,"New label is ***$hexlabel***\n"); 163 164 if (defined $label) { 165 $hexlabel=sprintf("%-11s", uc($label)); 166 pb_log(1,"New label is ***$hexlabel***\n"); 167 } elsif (defined $uuid) { 168 pb_log(1,"New uuid is ***$uuid***\n"); 169 my @loc = ($uuid =~ m/../g); 170 my $hex = join('',reverse(@loc)); 171 ($hexlabel) = pack( 'H*', $hex ); 172 } else { 173 die "Nothing to do no label/uuid defined"; 174 } 132 175 # Go back 133 seek($inputfh, 43,0);176 seek($inputfh, $offset,0); 134 177 print $inputfh $hexlabel; 135 178 close($inputfh) || die "couldn't close $inputf: $!";
Note:
See TracChangeset
for help on using the changeset viewer.