Skip to content

libcecb: Allow _cecb_create to create new cassette image files in write mode - #81

Merged
tlindner merged 1 commit into
nitros9project:mainfrom
rlucente-retro:fix-cecb-create-file-handling
Aug 7, 2026
Merged

tlindner merged 1 commit into
nitros9project:mainfrom
rlucente-retro:fix-cecb-create-file-handling

Conversation

@rlucente-retro

Copy link
Copy Markdown
Contributor

Description

This PR resolves an issue where running cecb copy (and building target .cas files in sub-projects such as hdbdos) fails with error 215 - badly formed pathname when copying files into a cassette image that does not yet exist on disk.

Problem / Root Cause

  1. File Opening Mode: In _cecb_create() (libcecb/libcecbopen.c), cassette image files were opened with fopen(imgfile, "rb+") when FAM_WRITE was set. In standard C I/O, "rb+" update mode fails and returns NULL if the file does not already exist on disk. This caused _cecb_create() to abort and return EOS_BPNAM (error 215).
  2. Offset Calculation for New Files: When calculating play_at for a newly created 0-byte .cas file (cas_total_bytes == 0), play_at evaluated to -1 ((0 * 8) - 1), causing negative bitwise shifts (0x01 << (-1)) when determining the starting bit position.

Fix

In _cecb_create():
• If fopen(imgfile, "rb+") fails when FAM_WRITE is requested, fall back to fopen(imgfile, "wb+") to create the cassette image file.
• Set play_at = 0 when cas_total_bytes == 0 to ensure clean byte and bit offset initialization.

Verification

• Unit Tests: Built build/unix and verified all unit tests (librbftest, libdecbtest, libcecbtest, libtoolshedtest, os9commandtest, decbcommandtest) pass.
• ROM Builds: Successfully built cocoroms, dwdos, hdbdos, and superdos targets using cecb copy into new .cas cassette images without pre-touching files.

@tlindner
tlindner merged commit b554a5f into nitros9project:main Aug 7, 2026
6 checks passed
@rlucente-retro
rlucente-retro deleted the fix-cecb-create-file-handling branch August 8, 2026 03:16
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.

2 participants