Add fstat support for pipe
This commit is contained in:
parent
f77e2c5e89
commit
ba720dc346
@ -44,6 +44,25 @@ impl File for PipeReader {
|
||||
self.consumer.pop_slices(bufs)
|
||||
}
|
||||
|
||||
fn metadata(&self) -> Result<Metadata> {
|
||||
Ok(Metadata {
|
||||
dev: 0,
|
||||
inode: 0,
|
||||
size: 0,
|
||||
blk_size: 0,
|
||||
blocks: 0,
|
||||
atime: Timespec { sec: 0, nsec: 0 },
|
||||
mtime: Timespec { sec: 0, nsec: 0 },
|
||||
ctime: Timespec { sec: 0, nsec: 0 },
|
||||
type_: FileType::NamedPipe,
|
||||
mode: 0o600,
|
||||
nlinks: 1,
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
rdev: 0,
|
||||
})
|
||||
}
|
||||
|
||||
fn access_mode(&self) -> Result<AccessMode> {
|
||||
Ok(AccessMode::O_RDONLY)
|
||||
}
|
||||
@ -111,6 +130,25 @@ impl File for PipeWriter {
|
||||
return_errno!(ESPIPE, "Pipe does not support seek")
|
||||
}
|
||||
|
||||
fn metadata(&self) -> Result<Metadata> {
|
||||
Ok(Metadata {
|
||||
dev: 0,
|
||||
inode: 0,
|
||||
size: 0,
|
||||
blk_size: 0,
|
||||
blocks: 0,
|
||||
atime: Timespec { sec: 0, nsec: 0 },
|
||||
mtime: Timespec { sec: 0, nsec: 0 },
|
||||
ctime: Timespec { sec: 0, nsec: 0 },
|
||||
type_: FileType::NamedPipe,
|
||||
mode: 0o600,
|
||||
nlinks: 1,
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
rdev: 0,
|
||||
})
|
||||
}
|
||||
|
||||
fn access_mode(&self) -> Result<AccessMode> {
|
||||
Ok(AccessMode::O_WRONLY)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <unistd.h>
|
||||
@ -26,6 +27,23 @@ static void free_pipe(int *pipe) {
|
||||
// ============================================================================
|
||||
// Test cases
|
||||
// ============================================================================
|
||||
int test_fstat() {
|
||||
int pipe_fds[2];
|
||||
struct stat stat_bufs[2];
|
||||
if (pipe(pipe_fds) < 0) {
|
||||
THROW_ERROR("failed to create a pipe");
|
||||
}
|
||||
if (fstat(pipe_fds[0], &stat_bufs[0]) < 0 || fstat(pipe_fds[1], &stat_bufs[1]) < 0) {
|
||||
free_pipe(pipe_fds);
|
||||
THROW_ERROR("failed to fstat pipe fd");
|
||||
}
|
||||
free_pipe(pipe_fds);
|
||||
if (!S_ISFIFO(stat_bufs[0].st_mode) || !S_ISFIFO(stat_bufs[1].st_mode)) {
|
||||
THROW_ERROR("failed to check the pipe st_mode");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_fcntl_get_flags() {
|
||||
int pipe_fds[2];
|
||||
if (pipe(pipe_fds) < 0) {
|
||||
@ -315,6 +333,7 @@ int test_select_read_write() {
|
||||
// Test suite
|
||||
// ============================================================================
|
||||
static test_case_t test_cases[] = {
|
||||
TEST_CASE(test_fstat),
|
||||
TEST_CASE(test_fcntl_get_flags),
|
||||
TEST_CASE(test_fcntl_set_flags),
|
||||
TEST_CASE(test_create_with_flags),
|
||||
|
Loading…
Reference in New Issue
Block a user