diff options
author | Dexter Morgan <dmorgan@mageia.org> | 2011-06-02 20:51:35 +0000 |
---|---|---|
committer | Dexter Morgan <dmorgan@mageia.org> | 2011-06-02 20:51:35 +0000 |
commit | a9b2bdafaf625d10aef2f476aa4014fd36c846bc (patch) | |
tree | 2364afc0ee6739b59a25c44d68c9f003bcaf03d9 /perl-install/resize_fat/io.pm | |
download | drakx-a9b2bdafaf625d10aef2f476aa4014fd36c846bc.tar drakx-a9b2bdafaf625d10aef2f476aa4014fd36c846bc.tar.gz drakx-a9b2bdafaf625d10aef2f476aa4014fd36c846bc.tar.bz2 drakx-a9b2bdafaf625d10aef2f476aa4014fd36c846bc.tar.xz drakx-a9b2bdafaf625d10aef2f476aa4014fd36c846bc.zip |
Branch for updates
Diffstat (limited to 'perl-install/resize_fat/io.pm')
-rw-r--r-- | perl-install/resize_fat/io.pm | 58 |
1 files changed, 58 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..68443ad2a --- /dev/null +++ b/perl-install/resize_fat/io.pm @@ -0,0 +1,58 @@ +package resize_fat::io; # $Id: io.pm 208669 2004-08-12 04:20:25Z prigaux $ + +use diagnostics; +use strict; + +use resize_fat::fat; +use c; + +1; + + +sub read($$$) { + my ($fs, $pos, $size) = @_; + my $buf = "\0" x $size; + 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; + my $pos = $fs->{cluster_offset} / 512 + $cluster * ($fs->{cluster_size} / 512); + + c::lseek_sector(fileno $fs->{fd}, $pos, 0) or die "seeking to sector #$pos failed on device $fs->{fs_name}"; + sysread $fs->{fd}, $buf, $fs->{cluster_size} or die "reading at sector #$pos failed on device $fs->{fs_name}"; + $buf; +} +sub write_cluster($$$) { + my ($fs, $cluster, $buf) = @_; + my $pos = $fs->{cluster_offset} / 512 + $cluster * ($fs->{cluster_size} / 512); + + c::lseek_sector(fileno $fs->{fd}, $pos, 0) or die "seeking to sector #$pos failed on device $fs->{fs_name}"; + syswrite $fs->{fd}, $buf or die "writing at sector #$pos 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 open { + my ($fs) = @_; + + sysopen $fs->{fd}, $fs->{fs_name}, 2 or + sysopen $fs->{fd}, $fs->{fs_name}, 0 or die "error opening device $fs->{fs_name} for writing\n"; +} |