I recently saved the contents of a 128gb SSD which had Sparky Linux on it as a single file on my large 2tb NTFS hard drive. Since the Linux partition was taking up only the first 40GB of the hard drive, I wanted to shorten the file. So, I opened a text editor (Keep in mind that I am using Windows XP Pro SP2 32-bit with TinyPerl 5.8), and I type the following:

#!/usr/bin/perl -w use strict; use warnings; # shorten file to 50GB: truncate "K:\\LINUX\\SparkyLinux.bin", 50000000000;

And I was surprised, because nothing happened! And truncate doesn't even have a return value about whether it succeeded or not. Well, it was evident that it failed. But why??? I then booted into Sparky Linux 7.2 which is a Debian based 64-bit Linux with Perl 5.36, and I typed the following and it worked perfectly:

truncate "/media/owner/DATA 2TB/LINUX/SparkyLinux.bin", 50000000000;

Now, I have used truncate() function before in Windows on much smaller files and it worked. So, I'm wondering if maybe the truncate() function does not work in Windows XP when we're dealing with larger files? I tried to write this same code in other languages, and those codes failed too. Weird...

I have been aware that QBASIC 1.1 in DOS has a limitation of 2GB when it comes to reading/writing binary files, and it's because they store the file pointer in a signed long, which goes from -2 billion to +2 billion. That forces a limit on how far you can move the file pointer for read and write operations. The LOF() function which returns the file size in QBASIC is also affected by issue, because it returns a negative value every time you're checking a file's size that is greater than 2GB. Looks like these older operating systems can't deal with big numbers correctly. :/


In reply to file truncate not working on 128GB file in Windows by harangzsolt33

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.