1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
|
#!/usr/bin/env perl
#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
# Simple fixed media configurator. Designed to be architecture- and distribution independent.
#
# Copyright (C) 2000-2001 Ximian, Inc.
#
# Authors: Hans Petter Jansson <hpj@ximian.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
# Best viewed with 100 columns of width.
# Configuration files affected:
#
# /etc/fstab
# Running programs affected/used:
#
# fdisk
# mount
require "___scriptsdir___/general.pl";
require "___scriptsdir___/platform.pl";
require "___scriptsdir___/util.pl";
require "___scriptsdir___/file.pl";
require "___scriptsdir___/xml.pl";
# --- Tool information --- #
$name = "disks";
$version = "0.1.0";
@platforms = ("redhat-5.2", "redhat-6.0", "redhat-6.1", "redhat-6.2", "redhat-7.0");
$description =<<"end_of_description;";
Configures locally mounted partitioned media.
end_of_description;
$progress_max = 16;
# --- System config file locations --- #
# We list each config file type with as many alternate locations as possible.
# They are tried in array order. First found = used.
# Right now there's only one entry per array, as I couldn't find any
# typical deviations.
@fstab_names = ( "/etc/fstab" );
# --- Internal configuration variables --- #
# Configuration is parsed/read to, and printed/written from, these temporary variables.
@cf_disks = ();
# --- Backend-specific helper subs --- #
sub update_partition
{
my ($disk, $device, $point, $fs, $options, $check);
my ($listed, $bootable, $detected);
my ($disk_found, $point_found) = (0, 0);
($disk, $device, $point, $fs, $options, $check, $size, $listed,
$bootable, $detected) = @_;
if ($fs eq "auto") { $fs = ""; }
for ($i = 0; $cf_disks[$i]; $i++)
{
if (($cf_disks[$i])->{device} eq $disk)
{
# Found disk. Now look for partition.
for ($j = 0; $cf_disks[$i]->{partitions}[$j]; $j++)
{
if ($cf_disks[$i]->{partitions}[$j]->{device} eq $device)
{
# Found partition.
if ($options ne "")
{
if ($options =~ /noauto/)
{
$cf_disks[$i]->{partitions}[$j]->{mounted} = 0;
}
else
{
$cf_disks[$i]->{partitions}[$j]->{mounted} = 1;
}
}
if ($point ne "") { $cf_disks[$i]->{partitions}[$j]->{point} = $point; }
if ($fs) { $cf_disks[$i]->{partitions}[$j]->{type} = $fs; }
if ($listed) { $cf_disks[$i]->{partitions}[$j]->{listed} = 1; }
if ($bootable) { $cf_disks[$i]->{partitions}[$j]->{bootable} = 1; }
if ($detected) { $cf_disks[$i]->{partitions}[$j]->{detected} = 1; }
if ($check) { $cf_disks[$i]->{partitions}[$j]->{check} = 1; }
if ($size) { $cf_disks[$i]->{partitions}[$j]->{size} = $size; }
$point_found = 1; last;
}
}
if (!$point_found)
{
# Make new partition entry.
my %partition;
if ($options =~ /noauto/) { %partition->{mounted} = 0; }
else { %partition->{mounted} = 1; }
%partition->{device} = $device;
%partition->{point} = $point;
%partition->{type} = $fs;
%partition->{listed} = $listed;
if ($bootable) { %partition->{bootable} = 1; }
if ($detected) { %partition->{detected} = 1; }
if ($check) { %partition->{check} = 1; }
%partition->{size} = $size;
$bleh = $cf_disks[$i]->{partitions};
push(@$bleh, \%partition);
}
$disk_found = 1; last;
}
}
if (!$disk_found)
{
# Make new disk entry containing this partition.
my (%disk, %partition);
if ($options =~ /noauto/) { %partition->{mounted} = 0; }
else { %partition->{mounted} = 1; }
%partition->{device} = $device;
%partition->{point} = $point;
%partition->{type} = $fs;
%partition->{listed} = $listed;
if ($bootable) { %partition->{bootable} = 1; }
if ($detected) { %partition->{detected} = 1; }
if ($check) { %partition->{check} = 1; }
%partition->{size} = $size;
%disk->{device} = $disk;
%disk->{partitions} = [];
$bleh = %disk->{partitions};
push(@$bleh, \%partition);
push(@cf_disks, \%disk);
}
}
sub get_partition
{
my ($disk, $device) = @_;
my ($i, $j);
for ($i = 0; $cf_disks[$i]; $i++)
{
if (($cf_disks[$i])->{device} eq $disk)
{
# Found disk. Now look for partition.
for ($j = 0; $cf_disks[$i]->{partitions}[$j]; $j++)
{
if ($cf_disks[$i]->{partitions}[$j]->{device} eq $device)
{
# Found partition.
return ($cf_disks[$i]->{partitions}[$j]);
}
}
}
}
}
sub get_partition_data
{
my ($disk, $device, $point, $fs, $options, $check);
my ($listed, $bootable);
($disk, $device, $point, $fs, $options, $check, $size, $listed,
$bootable, $detected) = @_;
for ($i = 0; $cf_disks[$i]; $i++)
{
if (($cf_disks[$i])->{device} eq $disk)
{
# Found disk. Now look for partition.
for ($j = 0; $cf_disks[$i]->{partitions}[$j]; $j++)
{
if ($cf_disks[$i]->{partitions}[$j]->{device} eq $device)
{
# Found partition.
return ($cf_disks[$i]->{partitions}[$j]->{point},
$cf_disks[$i]->{partitions}[$j]->{type},
$cf_disks[$i]->{partitions}[$j]->{listed},
$cf_disks[$i]->{partitions}[$j]->{mounted},
$cf_disks[$i]->{partitions}[$j]->{bootable},
$cf_disks[$i]->{partitions}[$j]->{check});
}
}
}
}
}
sub update_disk_size
{
my ($disk, $size);
($disk, $size) = @_;
for ($i = 0; $cf_disks[$i]; $i++)
{
if (($cf_disks[$i])->{device} eq $disk)
{
# Found disk.
$cf_disks[$i]->{size} = $size;
last;
}
}
}
# --- Configuration file manipulation --- #
# /etc/fstab
#
# <device> <mount point> <filesystem> <option,option,...> <dump> <fsck>
# <device> <mount point> <filesystem> <option,option,...> <dump> <fsck>
# ...
#
# Exists: (Presumably everywhere)
#
# Absent: (Presumably nowhere)
sub read_fstab
{
my $fstab_file;
local *FSTAB_FILE;
# Find the file.
$fstab_file = &xst_open_read_from_names(@fstab_names);
if (not $fstab_file) { return; } # We didn't find it.
*FSTAB_FILE = $fstab_file;
# Parse the file.
while (<FSTAB_FILE>)
{
my ($disk, $device, $point, $fs, $options, $check);
@line = split(/[ \n\r\t]+/, $_);
if ($line[0] eq "") { shift @line; }
if ($line[0] eq "" || $line[0] =~ /$LABEL=.*/ || $line[0] =~ /$UUID=.*/) { next; }
if (&xst_ignore_line($line[0])) { next; }
($device, $point, $fs, $options, $dump, $check) = @line;
if ($fs eq "nfs" || $fs eq "smbfs" || $fs eq "proc" || $fs eq "devpts" ||
$fs eq "iso9660" || $fs eq "swap")
{
next; # We can skip these filesystems for sure.
}
if ($point eq "none") { $dir = ""; }
($disk) = ($device =~ /([a-zA-Z\/]+)/);
if ($disk eq "/dev/fd" || $disk eq $device)
{
next; # Skip floppies, CD-ROMs and those pesky LABEL= lines (to be fixed).
}
# (Find and update) or (add) our internal disk/partition record.
if ($disk ne "")
{
&update_partition($disk, $device, $point, $fs, $options, $check, "", 1, 0);
}
}
close(FILE);
}
sub write_fstab
{
my ($ifh, $ofh);
local (*INFILE, *OUTFILE);
($ifh, $ofh) = &xst_open_filter_write_from_names(@fstab_names);
if (not $ofh) { return; } # No point if we can't write.
*INFILE = $ifh; *OUTFILE = $ofh;
while (<INFILE>)
{
my ($disk, $device, $point, $fs, $options, $dump, $check);
my ($ipoint, $itype, $icheck, $ilisted, $imounted, $ibootable);
@line = split(/[ \n\r\t]+/, $_);
if ($line[0] eq "") { shift @line; }
if ($line[0] eq "" || $line[0] =~ /$LABEL=.*/ || $line[0] =~ /$UUID=.*/) { print OUTFILE; next; }
if (&xst_ignore_line($line[0])) { print OUTFILE; next; }
($device, $point, $fs, $options, $dump, $check) = @line;
if ($fs eq "nfs" || $fs eq "smbfs" || $fs eq "proc" || $fs eq "devpts" ||
$fs eq "iso9660" || $fs eq "swap")
{
print OUTFILE; next; # We can skip these filesystems for sure.
}
# By now, we know that the "entry" is "interesting". Check if known.
($disk) = ($device =~ /([a-zA-Z\/]+)/);
($ipoint, $itype, $ilisted, $imounted, $ibootable, $icheck) = &get_partition_data($disk, $device);
if ($ilisted)
{
# Write record if listedness requested.
print OUTFILE $device . " ";
if ($ipoint eq "") { print OUTFILE "none "; }
else { print OUTFILE $ipoint . " "; }
if ($itype eq "") { print OUTFILE "auto "; }
else { print OUTFILE $itype . " "; }
# Options merging and printing.
my $prev = 0;
if (!$imounted) { print OUTFILE "noauto"; $prev = 1; }
my @options = ($options =~ /([a-zA-Z0-9=]+),?/mg);
for $option (@options)
{
# Strip options we handle, keep the rest.
if ($option eq "auto" || $option eq "noauto" ||
$option eq "defaults") { next; }
if ($prev) { print OUTFILE ","; }
print OUTFILE $option;
$prev = 1;
}
if (!$prev) { print OUTFILE "defaults"; }
# Leave dump alone.
print OUTFILE " $dump ";
# Fsck onboot priority.
if ($icheck eq "") { $icheck = 0; }
if ($icheck == 1)
{
if ($ipoint eq "/") { print OUTFILE "1\n"; }
else { print OUTFILE "2\n"; }
}
else { print OUTFILE "0\n"; }
# Indicate that parameters for this partition have been stored.
my $partition = &get_partition($disk, $device);
%$partition->{stored} = 1;
}
# Unknown or unlisted-by-request partitions are not written.
}
# Print the remaining partitions from our internal list. These are
# newly added, and didn't exist in the fstab previously.
for ($i = 0; $cf_disks[$i]; $i++)
{
for ($j = 0; $cf_disks[$i]->{partitions}[$j]; $j++)
{
if ($cf_disks[$i]->{partitions}[$j]->{listed} &&
!$cf_disks[$i]->{partitions}[$j]->{stored})
{
my $part = $cf_disks[$i]->{partitions}[$j];
&xst_report_info(01, "Adding " . $cf_disks[$i]->{partitions}[$j]->{device} . " to fstab");
# Write record.
print OUTFILE %$part->{device} . " ";
if (%$part->{point} eq "") { print OUTFILE "none "; }
else { print OUTFILE %$part->{point} . " "; }
if (%$part->{type} eq "") { print OUTFILE "auto "; }
else { print OUTFILE %$part->{type} . " "; }
# Options printing.
if (!%$part->{mounted}) { print OUTFILE "noauto "; }
else { print OUTFILE "defaults "; }
# No dumping by default.
print OUTFILE " 0 ";
# Fsck onboot priority.
if (%$part->{check} == 1)
{
if (%$part->{point} eq "/") { print OUTFILE "1\n"; }
else { print OUTFILE "2\n"; }
}
else { print OUTFILE "0\n"; }
}
}
}
close OUTFILE;
}
# fdisk -l <disk device>
#
# <&filtered lines>
#
# <partition device> [*] <start cluster> <end cluster> <blocks> <id> <verbose id>
# <partition device> [*] <start cluster> <end cluster> <blocks> <id> <verbose id>
# ...
#
# Exists: Red Hat 6.2 (Presumably all Linux)
#
# Absent:
#
# The star is optional, and means that the partition is bootable. We could've
# used /proc/partitions to &get this information, but it lists CD-ROM devices
# and whatnot as well, without a disambiguating identifier. Then there is
# portability, forward-compatibility, people without /proc, etc.
# fdisk -s <disk device>
#
# <blocksize>
sub get_fdisk
{
my $fdisk_tool;
# Okay, so this is strictly not portable either. Patches welcome.
my @check_devs = ( "/dev/hda", "/dev/hdb", "/dev/hdc", "/dev/hdd",
"/dev/sda", "/dev/sdb", "/dev/sdc", "/dev/sdd",
"/dev/sde", "/dev/sdf",
"/dev/eda", "/dev/edb", "/dev/edc", "/dev/edd",
"/dev/xda", "/dev/xdb" );
$fdisk_tool = &xst_locate_tool("fdisk");
for $dev (@check_devs)
{
my ($disk, $device, $point, $fs, $options, $check, $size, $bootable);
&xst_report_info(02, "Looking for partitions on $dev");
open(FDISK_HD, "$fdisk_tool -l $dev 2>/dev/null |");
while (<FDISK_HD>)
{
if (/^\/dev/)
{
@line = split(/[ \n\r\t]+/, $_);
$device = $line[0]; shift @line;
($disk) = ($device =~ /([a-zA-Z\/]+)/);
if ($line[0] eq "\*")
{
# NOTE: Currently unused.
$bootable = 1; shift @line;
}
else { $bootable = 0; }
shift @line; shift @line; # Start and end clusters.
($size) = ($line[0] =~ /([0-9]+)/);
shift @line;
if ($line[0] eq "82") { next; } # Swap.
elsif ($line[0] eq "83") { $type = "ext2"; }
elsif ($line[0] eq "e") { $type = "vfat"; }
elsif ($line[0] eq "c") { $type = "fat32"; }
elsif ($line[0] eq "b") { $type = "fat32"; }
elsif ($line[0] eq "6") { $type = "msdos"; }
elsif ($line[0] eq "4") { $type = "msdos"; }
elsif ($line[0] eq "1") { $type = "msdos"; }
elsif ($line[0] eq "7") { $type = "hpfs"; }
else { $type = ""; }
&update_partition($disk, $device, "", $type, "noauto", 0, $size, 0,
$bootable, 1);
}
}
close(FDISK_HD);
&xst_report_info(03, "Querying size of $dev");
open(FDISK_HD, "$fdisk_tool -s $dev 2>/dev/null |");
($size) = (<FDISK_HD> =~ /([0-9]+)/);
if ($size ne "") { &update_disk_size($dev, $size); }
close(FDISK_HD);
&xst_print_progress();
}
}
# --- XML parsing --- #
sub xml_parse
{
# Scan XML to tree.
$tree = &xst_xml_scan;
# Walk the tree recursively and extract configuration parameters.
# This is the top level - find and enter the toplevel tag.
while (@$tree)
{
if ($$tree[0] eq "disks") { &xml_parse_toplevel($$tree[1]); }
shift @$tree;
shift @$tree;
}
return($tree);
}
sub xml_parse_toplevel
{
my $tree = $_[0];
shift @$tree; # Skip attributes.
while (@$tree)
{
if ($$tree[0] eq "disk") { &xml_parse_disk($$tree[1]); }
shift @$tree;
shift @$tree;
}
}
sub xml_parse_disk
{
my %disk;
my $tree = $_[0];
shift @$tree; # Skip attributes.
%disk->{partitions} = []; # Init partition list.
while (@$tree)
{
if ($$tree[0] eq "device") { %disk->{device} = &xst_xml_get_word($$tree[1]); }
elsif ($$tree[0] eq "size") { %disk->{size} = &xst_xml_get_word($$tree[1]); }
elsif ($$tree[0] eq "partition")
{
my %partition = &xml_parse_partition($$tree[1]);
$bleh = %disk->{partitions};
push(@$bleh, \%partition);
}
shift @$tree; shift @$tree;
}
push(@cf_disks, \%disk);
}
sub xml_parse_partition
{
my %partition;
my $tree = $_[0];
shift @$tree; # Skip attributes.
while (@$tree)
{
if ($$tree[0] eq "device") { %partition->{device} = &xst_xml_get_word($$tree[1]); }
elsif ($$tree[0] eq "type") { %partition->{type} = &xst_xml_get_word($$tree[1]); }
elsif ($$tree[0] eq "point") { %partition->{point} = &xst_xml_get_word($$tree[1]); }
elsif ($$tree[0] eq "size") { %partition->{size} = &xst_xml_get_word($$tree[1]); }
elsif ($$tree[0] eq "bootable") { %partition->{bootable} = &xml_parse_state($$tree[1]); }
elsif ($$tree[0] eq "integritycheck") { %partition->{check} = &xml_parse_state($$tree[1]); }
elsif ($$tree[0] eq "mounted") { %partition->{mounted} = &xml_parse_state($$tree[1]); }
elsif ($$tree[0] eq "listed") { %partition->{listed} = &xml_parse_state($$tree[1]); }
elsif ($$tree[0] eq "detected") { %partition->{detected} = &xml_parse_state($$tree[1]); }
shift @$tree; shift @$tree;
}
return(%partition);
}
sub xml_parse_state
{
my $tree = $_[0];
# Check attribute; 'yes', 'true', 'no', 'false'.
return(&xst_read_boolean($$tree[0]->{state}));
}
# --- XML printing --- #
sub xml_print
{
print "<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?>\n";
print "<!DOCTYPE disks []>\n\n";
print "<disks>\n";
&xst_xml_enter ();
&xst_xml_vspace ();
&xst_xml_print_line ("<!-- Configuration starts here -->\n");
&xst_xml_vspace ();
&xst_xml_print_line ("<!-- Local fixed media and partitions -->\n");
&xst_xml_vspace ();
my @disks = @cf_disks;
while (@disks)
{
if ($disks[0])
{
my $disk = $disks[0];
&xst_xml_vspace ();
&xst_xml_print_line ("<disk>\n");
&xst_xml_enter ();
&xst_xml_print_line ("<device>" . %$disk->{device} . "</device>\n");
if (%$disk->{size}) { &xst_xml_print_line ("<size>" . %$disk->{size} . "</size>\n"); }
my $partitions = %$disk->{partitions};
while (@$partitions)
{
my $partition = $$partitions[0];
&xst_xml_vspace ();
&xst_xml_print_line ("<partition>\n");
&xst_xml_enter ();
&xst_xml_print_line ("<device>" . %$partition->{device} . "</device>\n");
if (%$partition->{type}) { &xst_xml_print_line ("<type>" . %$partition->{type} . "</type>\n"); }
if (%$partition->{point}) { &xst_xml_print_line ("<point>" . %$partition->{point} . "</point>\n"); }
if (%$partition->{size})
{
&xst_xml_print_line ("<size>" . %$partition->{size} . "</size>\n");
}
&xst_xml_print_line ("<bootable state='" . &xst_print_boolean_truefalse(%$partition->{bootable}) . "'/>");
print "<integritycheck state='" . &xst_print_boolean_truefalse(%$partition->{check}) . "'/>\n";
&xst_xml_indent ();
print "<mounted state='" . &xst_print_boolean_truefalse(%$partition->{mounted}) . "'/>";
print "<listed state='" . &xst_print_boolean_truefalse(%$partition->{listed}) . "'/>";
print "<detected state='" . &xst_print_boolean_truefalse(%$partition->{detected}) . "'/>\n";
&xst_xml_leave ();
&xst_xml_print_line ("</partition>\n");
shift @$partitions;
}
&xst_xml_leave ();
&xst_xml_print_line ("</disk>\n");
&xst_xml_vspace ();
}
shift @disks;
}
&xst_xml_vspace ();
&xst_xml_print_line ("<!-- End of configuration -->\n");
&xst_xml_vspace ();
&xst_xml_leave ();
print "</disks>\n";
}
# --- Get (read) config --- #
sub get
{
&get_fdisk;
&read_fstab;
&xst_end();
&xml_print ();
}
# --- Set (write) config --- #
sub set_immediate
{
my $mount_tool;
my $umount_tool;
$mount_tool = &xst_locate_tool("mount");
$umount_tool = &xst_locate_tool("umount");
# Count partitions.
my $i; my $j;
my $num_partitions = 0;
my $num_done = 0;
for ($i = 0; $cf_disks[$i]; $i++)
{
for ($j = 0; $cf_disks[$i]->{partitions}[$j]; $j++)
{
$num_partitions++;
}
}
# Update mount status.
if (($mount_tool ne "") && ($umount_tool ne ""))
{
my $i; my $j;
for ($i = 0; $cf_disks[$i]; $i++)
{
for ($j = 0; $cf_disks[$i]->{partitions}[$j]; $j++)
{
if ($cf_disks[$i]->{partitions}[$j]->{mounted})
{
&xst_report_info(4, "Mounting " . $cf_disks[$i]->{partitions}[$j]->{device});
system "$mount_tool " . $cf_disks[$i]->{partitions}[$j]->{device} . " " .
$cf_disks[$i]->{partitions}[$j]->{point} . " >/dev/null 2>/dev/null";
}
else
{
&xst_report_info(5, "Unmounting " . $cf_disks[$i]->{partitions}[$j]->{device});
system "$umount_tool " . $cf_disks[$i]->{partitions}[$j]->{device} . " >/dev/null 2>/dev/null";
}
$num_done++;
&xst_progress(10 + (80 / ($num_partitions - $num_done + 1)));
}
}
}
else
{
&xst_report_error(01, "Could not find mount tools. No mounting done");
}
&xst_progress(90);
}
sub set
{
&xml_parse ();
&write_fstab; &xst_progress(10);
if ($xst_do_immediate)
{
&set_immediate;
}
&xst_end();
}
# --- Filter config: XML in, XML out --- #
sub filter
{
&xml_parse ();
&xst_end();
&xml_print ();
}
# --- Main --- #
&xst_init ($name, $version, $description, @ARGV);
&xst_platform_ensure_supported (@platforms);
# Do our thing.
if ($xst_operation eq "get") { &get; }
elsif ($xst_operation eq "set") { &set; }
elsif ($xst_operation eq "filter") { &filter; }
|