diff options
author | Pascal Rigaux <pixel@mandriva.com> | 1999-10-09 13:26:41 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 1999-10-09 13:26:41 +0000 |
commit | fc5950e2eb1f9c0b7a1553f5717940d880e4853c (patch) | |
tree | f8fa3478c37b137673fca970963558e564f0916e /perl-install/resize_fat/io.pm | |
parent | 870d622c6e3ed5d9a81c84e3f3d0fc287733472f (diff) | |
download | drakx-backup-do-not-use-fc5950e2eb1f9c0b7a1553f5717940d880e4853c.tar drakx-backup-do-not-use-fc5950e2eb1f9c0b7a1553f5717940d880e4853c.tar.gz drakx-backup-do-not-use-fc5950e2eb1f9c0b7a1553f5717940d880e4853c.tar.bz2 drakx-backup-do-not-use-fc5950e2eb1f9c0b7a1553f5717940d880e4853c.tar.xz drakx-backup-do-not-use-fc5950e2eb1f9c0b7a1553f5717940d880e4853c.zip |
no_comment
Diffstat (limited to 'perl-install/resize_fat/io.pm')
-rw-r--r-- | perl-install/resize_fat/io.pm | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/perl-install/resize_fat/io.pm b/perl-install/resize_fat/io.pm new file mode 100644 index 000000000..48309db91 --- /dev/null +++ b/perl-install/resize_fat/io.pm @@ -0,0 +1,74 @@ +package resize_fat::io; + +use diagnostics; +use strict; + +use resize_fat::fat; + +1; + + +sub read($$$) { + my ($fs, $pos, $size) = @_; + my $buf; + sysseek $fs->{fd}, $pos, 0 or die "seeking to byte #$pos failed on device $fs->{fs_name}"; + sysread $fs->{fd}, $buf, $size or die "reading at byte #$pos failed on device $fs->{fs_name}"; + $buf; +} +sub write($$$$) { + my ($fs, $pos, $size, $buf) = @_; + sysseek $fs->{fd}, $pos, 0 or die "seeking to byte #$pos failed on device $fs->{fs_name}"; + syswrite $fs->{fd}, $buf or die "writing at byte #$pos failed on device $fs->{fs_name}"; +} + +sub read_cluster($$) { + my ($fs, $cluster) = @_; + my $buf; + + eval { + $buf = &read($fs, + $fs->{cluster_offset} + $cluster * $fs->{cluster_size}, + $fs->{cluster_size}); + }; @$ and die "reading cluster #$cluster failed on device $fs->{fs_name}"; + $buf; +} +sub write_cluster($$$) { + my ($fs, $cluster, $buf) = @_; + + eval { + &write($fs, + $fs->{cluster_offset} + $cluster * $fs->{cluster_size}, + $fs->{cluster_size}, + $buf); + }; @$ and die "writing cluster #$cluster failed on device $fs->{fs_name}"; +} + +sub read_file($$) { + my ($fs, $cluster) = @_; + my $buf = ''; + + for (; !resize_fat::fat::is_eof($cluster); $cluster = resize_fat::fat::next($fs, $cluster)) { + $cluster == 0 and die "Bad FAT: unterminated chain\n"; + $buf .= read_cluster($fs, $cluster); + } + $buf; +} + +sub check_mounted($) { + my ($f) = @_; + + local *F; + open F, "/proc/mounts" or die "error opening /proc/mounts\n"; + foreach (<F>) { + /^$f\s/ and die "device is mounted"; + } +} + +sub open($) { + my ($fs) = @_; + + check_mounted($fs->{device}); + + sysopen F, $fs->{fs_name}, 2 or sysopen F, $fs->{fs_name}, 0 or die "error opening device $fs->{fs_name} for writing\n"; + $fs->{fd} = \*F; +} |