@@ -12,21 +12,23 @@ import type { Natives } from "./util.ts";
1212
1313export const EPERM = 1 , ENOENT = 2 , EINTR = 4 , EIO = 5 , EBADF = 9 , ENOMEM = 12 , EACCES = 13 ,
1414 EEXIST = 17 , EXDEV = 18 , ENOTDIR = 20 , EISDIR = 21 , EINVAL = 22 , ENOSPC = 28 , EROFS = 30 ,
15- ENOTEMPTY = 39 , ENOSYS = 38 , ELOOP = 40 , ENOTSUP = 95 , ESTALE = 116 ;
15+ ENOTEMPTY = 39 , ENOSYS = 38 , ENAMETOOLONG = 36 , ELOOP = 40 , ENOTSUP = 95 , ESTALE = 116 , EDQUOT = 122 ;
1616
1717const MESSAGES : Record < number , string > = {
1818 [ EPERM ] : "Operation not permitted" , [ EINTR ] : "Interrupted system call" , [ EIO ] : "Input/output error" ,
1919 [ ENOMEM ] : "Cannot allocate memory" , [ ENOSPC ] : "No space left on device" ,
2020 [ ELOOP ] : "Too many levels of symbolic links" , [ ENOTSUP ] : "Operation not supported" , [ ESTALE ] : "Stale file handle" ,
21+ [ ENAMETOOLONG ] : "File name too long" , [ EDQUOT ] : "Disk quota exceeded" ,
2122 [ ENOENT ] : "No such file or directory" , [ EBADF ] : "Bad file descriptor" , [ EACCES ] : "Permission denied" ,
2223 [ EEXIST ] : "File exists" , [ EXDEV ] : "Invalid cross-device link" , [ ENOTDIR ] : "Not a directory" ,
2324 [ EISDIR ] : "Is a directory" , [ EINVAL ] : "Invalid argument" , [ EROFS ] : "Read-only file system" ,
2425 [ ENOTEMPTY ] : "Directory not empty" , [ ENOSYS ] : "Function not implemented" ,
2526} ;
2627
27- const CHMOD_ERRNO : Record < string , number > = {
28+ // errno numbers of the host errors Node reports by name
29+ const HOST_ERRNO : Record < string , number > = {
2830 EPERM , ENOENT , EINTR , EIO , EBADF , ENOMEM , EACCES , ENOTDIR , EINVAL , ENOSPC , EROFS , ELOOP ,
29- ENOTSUP , EOPNOTSUPP : ENOTSUP , ESTALE ,
31+ ENOTSUP , EOPNOTSUPP : ENOTSUP , ESTALE , ENAMETOOLONG , EDQUOT ,
3032} ;
3133
3234// Linux open(2) flags
@@ -66,7 +68,7 @@ function chmod(t: JThread, p: string, mode: number) {
6668 if ( ! fs . stat ( p ) ) unixError ( ENOENT ) ;
6769 unixError ( EROFS ) ;
6870 }
69- unixError ( CHMOD_ERRNO [ fs . chmodError ( p ) ?? "EIO" ] ?? EIO ) ;
71+ unixError ( HOST_ERRNO [ fs . chmodError ( p ) ?? "EIO" ] ?? EIO ) ;
7072}
7173
7274function fillAttrs ( t : JThread , attrs : JObject , p : string ) : number {
@@ -148,7 +150,11 @@ export const natives: Natives = {
148150 fileOf ( t , fd ) . ino = fileInode ( t , abs ) ;
149151 return fd ;
150152 } catch ( e ) {
151- if ( e instanceof PendingThrow ) unixError ( t . vm . fs . writable ( abs ) ? ENOENT : EROFS ) ;
153+ if ( e instanceof PendingThrow ) {
154+ // a new file the host would not create: its reason
155+ const host = st ? undefined : HOST_ERRNO [ t . vm . fs . writeError ( abs ) ?? "" ] ;
156+ unixError ( host ?? ( t . vm . fs . writable ( abs ) ? ENOENT : EROFS ) ) ;
157+ }
152158 throw e ;
153159 }
154160 } ,
0 commit comments