computing file size in CP/M 2 or later [message #9320] |
Sun, 31 October 2021 06:26  |
lynchaj
Messages: 1080 Registered: June 2016
|
Senior Member |
|
|
Hi
Over in the Zmodem for CP/M thread, there is a need for a get_file_size() function for the CP/M version of the program. I think there are a couple of ways to do this. CP/M 2.2 does not support a BDOS function to compute exact file size. However it does give you the number of records present in a file which multiplied by 128 gives you the maximum possible file size. FCB is typically $005C on most CP/M instances
From https://www.seasip.info/Cpm/bdos.html
BDOS function 35 (F_SIZE) - Compute file size
Supported by: CP/M 2 and later.
Entered with C=23h, DE=FCB address. Returns error codes in BA and HL.
Set the random record count bytes of the FCB to the number of 128-byte records in the file. Returns A=0FFh if error (file not found, or CP/M 3 hardware error); otherwise A=0.
z88dk supports CP/M BDOS interface with the cpm.h library. More details here https://www.z88dk.org/wiki/doku.php?id=library:cpm
Thanks, Andrew Lynch
PS, if the approximate value of file size is not sufficient for Zmodem we could compute the exact file size using a C subroutine
https://www.geeksforgeeks.org/c-program-find-size-file/
[Updated on: Sun, 31 October 2021 07:13] Report message to a moderator
|
|
|
Re: computing file size in CP/M 2 or later [message #9321 is a reply to message #9320] |
Sun, 31 October 2021 07:37   |
jayindallas
Messages: 110 Registered: June 2021
|
Senior Member |
|
|
I think you can compute the exact filesize from the directory record of the file.
Now to get hold of the directory record you either access a raw sector read routine or...
find out *IF* and where CP/M holds an buffer image of the directory or buffer image of the last accessed file's directory image.
To find where that would be, look at one of the disassemblies of CP/M; that should document it.
[Updated on: Sun, 31 October 2021 08:27] Report message to a moderator
|
|
|
Re: computing file size in CP/M 2 or later [message #9323 is a reply to message #9321] |
Sun, 31 October 2021 10:53  |
lynchaj
Messages: 1080 Registered: June 2016
|
Senior Member |
|
|
jayindallas wrote on Sun, 31 October 2021 10:37I think you can compute the exact filesize from the directory record of the file.
Now to get hold of the directory record you either access a raw sector read routine or...
find out *IF* and where CP/M holds an buffer image of the directory or buffer image of the last accessed file's directory image.
To find where that would be, look at one of the disassemblies of CP/M; that should document it.
Hi Jay
Well, not quite in CP/M 2.2 and earlier. There is a BDOS function call that will tell you the number of sectors in a given file and you can compute maximum possible file size by multiplying by 128. Later versions of CP/M did include a byte in the directory record but it is ambiguous as to whether that's the bytes remaining in the last sector or bytes used because it is not documented. Unfortunately there have been both ways to interpret the byte so your answer can vary.
In this case though we really probably don't need an exact count of file size just a good count of sectors to get close enough. I implemented a get_file_size() based on the sample code from geeksforgeeks and it seems to work fine. It relies on the file functions in stdio.h which are fairly commonly implemented. Hopefully that will be sufficient for our needs. If not we can go about with the specific BDOS function call approach. z88dk supports a CP/M interface library for making direct BDOS calls but if we don't need it then why add a bunch of non-standard stuff?
Thanks, Andrew Lynch
PS, please download the Zmodem fileset and make on your computer. I think it is kind of Linux oriented. At least it worked pretty much out of the box for me on Linux. Even with the modification it worked fine. Would like to know if the get_file_size() is working though. Will do some experimenting to see what's happening.
[Updated on: Sun, 31 October 2021 10:54] Report message to a moderator
|
|
|