Skip to content

Instantly share code, notes, and snippets.

@danmoseley
Last active January 11, 2024 08:22
Show Gist options
  • Save danmoseley/ee382954ebdda9807d54a569dd662eb4 to your computer and use it in GitHub Desktop.
Save danmoseley/ee382954ebdda9807d54a569dd662eb4 to your computer and use it in GitHub Desktop.
Windows/Unix file IO errors
Unix code(s) Windows code(s) Existing exception (n) = interesting to distinguish
ERROR_DIRECTORY Directory name is invalid (eg RemoveDirectory, SetCurrentDirectory, FindFirstFile)
ENAMETOOLONG File name >255, path > 1023 ERROR_FILENAME_EXCED_RANGE Path normalization error PathTooLongException
ERROR_INVALID_NAME Invalid path IOException (0)
ELOOP? ERANGE Too many symbolic links ERROR_BAD_PATHNAME Relative path when full path expected IOException (0)
EEXIST Existing file or directory (mkdir, open with O_CREAT, ..rename to..) ERROR_FILE_EXISTS Existing file (CreateFile CREATE_NEW) IOException (1)
EEXIST EISDIR Existing file or directory (mkdir, open with O_CREAT, ..rename to..) Existing directory (open to modify, rename from file, .. ERROR_ALREADY_EXISTS Existing file (CreateFile CREATE_ALWAYS/OPEN_ALWAYS, CreateDirectory, MoveFileEx to) Existing directory (CreateDirectory) IOException (2)
ENOTDIR Component of path is not directory ERROR_PATH_NOT_FOUND Nonexistent folder (CreateFile CREATE_NEW, FindFirstFile,) DirectoryNotFoundException
ENOENT Absent file or directory (many API) ERROR_FILE_NOT_FOUND Nonexistent file (DeleteFile, CreateFile with OPEN_ALWAYS, GetFileInformation, FindFirstFile) Nonexistent directory (RemoveDirectory) FileNotFoundException
ENOTEMPTY ERROR_DIR_NOT_EMPTY Directory with files (RemoveDirectory) IOException (3)
ENODEV No such device ERROR_INVALID_DRIVE DriveNotFoundException
EBUSY ERROR_BUSY n/a
ERROR_BUSY_DRIVE n/a
EFBIG File too large ???
ENOSPC EDQUOT ERROR_DISK_FULL ERROR_DISK_QUOTA_EXCEEDED
ENOMEM Out of memory ERROR_OUTOFMEMORY ERROR_NOT_ENOUGH_MEMORY OutOfMemoryException
EMFILE Too many open files ERROR_TOO_MANY_OPEN_FILES ERROR_OPEN_FILES
ERROR_NOT_READY Removable media not present DriveNotReadyException
ERROR_INVALID_FUNCTION ?? Hardlink related
ERROR_NOT_SUPPORTED ?? NotSupportedException
ERROR_INVALID_PARAMETER ArgumentException/IOException
EBADF ERROR_INVALID_HANDLE
ERROR_WRITE_PROTECT
FVE_E_LOCKED_VOLUME Locked by BitLocker DriveLockedException
EACCES EPERM EROFS EISDIR EINVAL? ERROR_ACCESS_DENIED Readonly file (DeleteFile, MoveFileEx MOVEFILE_REPLACE_EXISTING to) Existing directory (CreateFile CREATE_NEW, MoveFileEx MOVEFILE_REPLACE_EXISTING to) Incompatible ACL (CreateFile) UnauthorizedAccessException or IOException(4)
ERROR_NOACCESS
ERROR_INVALID_ACCESS
EWOULDBLOCK? ERROR_SHARING_VIOLATION CreateFile on file already open with incompatible access mask and share mode IOException (5)
ERROR_LOCK_VIOLATION
ERROR_DRIVE_LOCKED
ERROR_LOCKED
ERROR_DEVICE_IN_USE
ERROR_CURRENT_DIRECTORY ??
ERROR_CANNOT_MAKE The directory or file cannot be created. (Cause unclear)
EXDEV Cross device link ERROR_NOT_SAME_DEVICE can't move across volumes IOException
ERROR_NO_MORE_FILES file enumeration
ERROR_SEEK The drive cannot locate a specific area or track on the disk.
EIO ERROR_FILE_CORRUPT
EIO ERROR_DISK_CORRUPT
EIO ERROR_WRITE_FAULT The system cannot write to the specified device
EIO ERROR_READ_FAULT The system cannot read from the specified device
ERROR_CANTOPEN
ERROR_OPEN_FAILED
ERROR_CANTREAD
ERROR_CANTWRITE
ERROR_OPERATION_ABORTED The I/O operation has been aborted because of either a thread exit or an application request. (Eg Ctrl-C) OperationCanceledException
ERROR_NETWORK_UNREACHABLE The specified network name is no longer available.
ERROR_NETWORK_ACCESS_DENIED Network access is denied.
ERROR_DEV_NOT_EXIST The specified network resource or device is no longer available.
ERROR_BAD_NETPATH The network path was not found.
ERROR_BAD_NET_NAME The network name cannot be found.
@joshudson
Copy link

ERROR_DIRECTORY <-> EISDIR
ERROR_IO_PENDING <-> EWOUDLBLOCK
ERROR_ALREADY_EXISTS | ERROR_FILE_EXISTS <-> EEXIST
ERROR_SHARING_VIOLATION <-> ETXTBUSY -- sharing violiations via flock() on Unix actually block until resolved unless async I/O is requested in which case the caller does indeed get to handle EWOULDBLOCK; but trying to open a running executable file for write yields ETXTBUSY rather than blocking. If we're going to be portable the handler for request lock really should translate EWOULDBLOCK explicitly to avoid more headaches.
ERROR_STOPPED_ON_SYMLINK <-> ELOOP
ERROR_FILE_TOO_LARGE <-> EFBIG
EINVAL is the result of passing a bad pointer to a file system call.
ERANGE can't happen as the result of an I/O call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment