Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unlink(2) implementation for CP/M. #235

Open
wants to merge 1 commit into
base: default
Choose a base branch
from

Conversation

ibara
Copy link

@ibara ibara commented Jun 27, 2021

Hello --

When compiling C code for CP/M, unlink is accepted by the compiler via the unistd.h header but then fails when linking due to an undefined reference for _unlink.

This PR adds an unlink implementation for CP/M.

I am not 100% sure the errno = EIO is the correct errno for when cpm_delete_file returns 0xff, but this is good enough for my needs.

Thanks!

@davidgiven
Copy link
Owner

Thanks very much! I've left a couple of comments.

@ibara
Copy link
Author

ibara commented Jun 27, 2021

Hello --

Thanks.
(However, I don't see any comments anywhere...)

@davidgiven
Copy link
Owner

That is, github review comments, not code comments! They should show up in the github UI here, above this message: #235

@ibara
Copy link
Author

ibara commented Jun 28, 2021

Embarrassingly, my GitHub UI appears to be broken (though I am using Chrome on Windows atm): there is no github review anywhere for me...

@tkchia
Copy link
Contributor

tkchia commented Jan 13, 2022

Hello @ibara, hello @davidgiven,

I do not see any GitHub review comments either (?). Meanwhile I have a few queries of my own on this PR:

  • Is it really necessary to find an empty slot in the __fd[] array? I would think that the FCB could simply be created on the stack, and unlink can do the file deletion from there.
  • If the code is going to touch the __fd[] array, then should it use __fd[] to check that the file to be unlink-ed is not currently open? Is it OK under CP/M to remove a file that is still open?

(My knowledge of the CP/M interface is admittedly quite limited — but I had been looking at Microsoft's GW-BASIC implementation of the KILL command for deleting files, which uses CP/M-like FCBs under MS-DOS 1.x.)

Thank you!

@ibara
Copy link
Author

ibara commented Jan 13, 2022

My knowledge of the CP/M interface is also limited. I freely and fully admit to stealing this code from another library file (maybe open?) and modifying it until it did the right thing for my use case. I am sure it needs lots of improvement!

uint8_t olduser;

__init_file_descriptors();
while (fd != NUM_FILE_DESCRIPTORS)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a while since I looked at this code, but I believe that this chunk is trying to find a free FCBE structure for use when parsing the filename, right? I think it would actually be more efficient to have a static structure used by unlink() instead --- the size of the structure is probably smaller than the size of the code needed to manage allocating one.


if (cpm_delete_file(&fcbe->fcb) == 0xff)
{
fcbe->fcb.f[0] = 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUIC, this will leak the FCBE if the call succeeds. (I assume you don't want to allocate one permanently, right?)

@davidgiven
Copy link
Owner

Very very belatedly someone told me that github doesn't actually send reviews until you do something unobvious. Hopefully I've done that now. Sorry for the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants