Please see the code first.
use Win32API::File 0.08 qw( :ALL );
my $fh = Win32API::File->new("< \\\\.\\e:");
my $block_size = 512;
seek($fh, 8388607 * $block_size, 0);
read($fh, my $buf, $block_size);
my $s = 2 * length($buf);
I want to read / write access to direct a volume.
The code works normally.
seek($fh, 8388608 * $block_size, 0);
However, the above code does not work.
In the output, the data of the 0 address.
I think more than 4G values seem to be a problem. (overflow)
Please tell us the solution plz~
I'm not overly familiar with Perl, but I have experienced a similar issue when playing with files in Windows. I would guess that the issue is trying to seek past 2 Gigabytes, when the
POSITION parameter will wrap around to a negative number ("traditionally", file positions for these methods tend to be 32-bit signed values). The solution I found was to not always seek from the beginning of the file... performing your seeks incrementally will allow the file system to point past the limits of the parameter types.
The parameters to seek are:
seek (FILEHANDLE, POSITION, WHENCE)
The value of
WHENCE should be
SEEK_SET to seek from the beginning,
SEEK_CUR to seek from the current position, and
SEEK_END to seek from the
EOF (the end of the file, generally meaning
POSITION should be negative).
You should be able to confirm if this is the issue by altering your code (as a test) to do the seek in several steps, in increments of (say)
2097152 * $block_size:
seek ($fh, 2097152 * $block_size, SEEK_SET); seek ($fh, 2097152 * $block_size, SEEK_CUR); // seek from current position seek ($fh, 2097152 * $block_size, SEEK_CUR); // seek from current position seek ($fh, 2097152 * $block_size, SEEK_CUR); // seek from current position read ($fh, my $buf, $block_size);