Skip to content

Conversation

Copy link

Copilot AI commented Dec 20, 2025

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

Problem

Notepad fails to open text files from read-only media (such as VirtualBox shared folders configured as read-only) with the error message "The medium is write-protected." The file is not displayed in Notepad. However, WordPad opens the same files without any errors.

Root Cause

The issue is in the DoOpenFile function in base/applications/notepad/dialog.c. The function uses OPEN_ALWAYS when calling CreateFile:

hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
                   OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

OPEN_ALWAYS attempts to open a file, and if it doesn't exist, it will create it. This fails on read-only media because the system cannot create a new file, even though we're only requesting GENERIC_READ access.

Solution

Change OPEN_ALWAYS to OPEN_EXISTING in the CreateFile call. OPEN_EXISTING only opens existing files without attempting to create them, which is the correct behavior for opening files for reading.

hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
                   OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

This change makes Notepad's behavior consistent with other text editors like WordPad.

Testing

After this fix:

  • Files from read-only media (VirtualBox shared folders, CD-ROMs, etc.) should open successfully
  • Normal file opening behavior should remain unchanged
  • Non-existent files will properly fail to open (which is the expected behavior)

Files Changed

  • base/applications/notepad/dialog.c - Change OPEN_ALWAYS to OPEN_EXISTING in DoOpenFile function

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@katahiromz
Copy link
Contributor

Failed to update. I will retry. Closed.

@katahiromz katahiromz closed this Dec 20, 2025
@katahiromz katahiromz deleted the copilot/fix-notepad-read-only-issue branch December 20, 2025 04:48
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