Skip to content

Commit

Permalink
add __WASI_FILETYPE_FIFO type
Browse files Browse the repository at this point in the history
snapshot_preview2 added support for FIFO types. Prior to this,
FIFOs were treated as sockets and unknown files.

Refs: #59
  • Loading branch information
cjihrig committed Feb 21, 2020
1 parent 6939709 commit e3c85d4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,10 @@ Possible values:

The file refers to a symbolic link inode.

- <a href="#filetype.fifo" name="filetype.fifo"></a>**`UVWASI_FILETYPE_FIFO`**

The file descriptor or file refers to a FIFO.

### <a href="#fstflags" name="fstflags"></a>`uvwasi_fstflags_t` (`uint16_t` bitfield)

Which file time attributes to adjust.
Expand Down
1 change: 1 addition & 0 deletions include/wasi_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ typedef uint8_t uvwasi_filetype_t;
#define UVWASI_FILETYPE_SOCKET_DGRAM 5
#define UVWASI_FILETYPE_SOCKET_STREAM 6
#define UVWASI_FILETYPE_SYMBOLIC_LINK 7
#define UVWASI_FILETYPE_FIFO 8

typedef uint16_t uvwasi_fstflags_t; /* Bitfield */
#define UVWASI_FILESTAT_SET_ATIM (1 << 0)
Expand Down
2 changes: 1 addition & 1 deletion src/uv_mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ uvwasi_filetype_t uvwasi__stat_to_filetype(const uv_stat_t* stat) {

#ifdef S_ISFIFO
if (S_ISFIFO(mode))
return UVWASI_FILETYPE_SOCKET_STREAM;
return UVWASI_FILETYPE_FIFO;
#endif /* S_ISFIFO */

#ifdef S_ISBLK
Expand Down
2 changes: 2 additions & 0 deletions src/uvwasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,8 @@ uvwasi_errno_t uvwasi_fd_readdir(uvwasi_t* uvwasi,
dirent.d_type = UVWASI_FILETYPE_BLOCK_DEVICE;
break;
case UV_DIRENT_FIFO:
dirent.d_type = UVWASI_FILETYPE_FIFO;
break;
case UV_DIRENT_UNKNOWN:
default:
dirent.d_type = UVWASI_FILETYPE_UNKNOWN;
Expand Down
5 changes: 5 additions & 0 deletions src/wasi_rights.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ uvwasi_errno_t uvwasi__get_rights(uv_file fd,
*rights_inheriting = UVWASI__RIGHTS_BLOCK_DEVICE_INHERITING;
break;

case UVWASI_FILETYPE_FIFO:
*rights_base = UVWASI__RIGHTS_FIFO_BASE;
*rights_inheriting = UVWASI__RIGHTS_FIFO_INHERITING;
break;

default:
*rights_base = 0;
*rights_inheriting = 0;
Expand Down
7 changes: 7 additions & 0 deletions src/wasi_rights.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@
UVWASI_RIGHT_POLL_FD_READWRITE)
#define UVWASI__RIGHTS_TTY_INHERITING 0

#define UVWASI__RIGHTS_FIFO_BASE (UVWASI_RIGHT_FD_READ | \
UVWASI_RIGHT_FD_FDSTAT_SET_FLAGS | \
UVWASI_RIGHT_FD_WRITE | \
UVWASI_RIGHT_FD_FILESTAT_GET | \
UVWASI_RIGHT_POLL_FD_READWRITE)
#define UVWASI__RIGHTS_FIFO_INHERITING UVWASI__RIGHTS_ALL


uvwasi_errno_t uvwasi__get_rights(uv_file fd,
int flags,
Expand Down

0 comments on commit e3c85d4

Please sign in to comment.