This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
HometownPotato's profile picture

h.write

Started by HometownPotato, 26 April 2014 - 02:01 PM
HometownPotato #1
Posted 26 April 2014 - 04:01 PM
Does h.write (h = fs.open("etc", "w [or a]")) return an error if there is no available disk space? I seem to test it and I get an error creating a file even when I have some bytes free. I can edit files and append to it fine but I can't create an actual file

Edit:
The error only shows up when I have very little space (like 10 bytes), even when I write nothing to the file.
Edited on 26 April 2014 - 02:20 PM
apemanzilla #2
Posted 26 April 2014 - 05:36 PM
It should return nil AFAIK. Usually it doesn't error, only return nil when it cannot open a file.
HometownPotato #3
Posted 26 April 2014 - 06:04 PM
Is there a reason that, even if I have little bit of space at most (like 10+ bytes left), files can not be created?
I wanted to test it since it was giving me problems with fs.open, so I used the edit program and I get "can not save to file" or something of the sort, even when the file is less than the free space available. (Even when the file is empty and there is > 1 byte FS)
Lyqyd #4
Posted 26 April 2014 - 06:28 PM
Files take up a certain minimum amount of space on the physical computer's hard drive, usually about 1kb.
HometownPotato #5
Posted 26 April 2014 - 06:39 PM
Oh, that makes sense. Thank you.
Do empty files take exactly 1024 bytes and the total file being 1024 bytes + #text?

Or does it depend on the name of the file?
Lyqyd #6
Posted 26 April 2014 - 07:52 PM
Depends on your/the server's file system and the hard drive's block size. I think 1024b is a pretty common minimum file size. The total file size is 1024 (or whatever the minimum is on that system) for all files smaller than that, and the smallest possible multiple of that (iirc) for all files larger. You can observe this yourself by viewing the properties of a file and looking at the difference between the file size and the size on disk.

Mine happens to have a 4kb block size (4096 bytes), both on my SSD and on my RAID5 array.
HometownPotato #7
Posted 26 April 2014 - 08:00 PM
Alright, thanks again
Bomb Bloke #8
Posted 26 April 2014 - 10:34 PM
4kb is definitely the usual cluster size figure, for what it's worth. Note that the file system which tracks the location of a given file's clusters takes up additional space in order to do so - Windows' file properties panel doesn't account for this, though I doubt ComputerCraft does either so it's very likely a moot point.