From 2ba7a9f581a1c622f4b77585d7c36fdd1783cfb9 Mon Sep 17 00:00:00 2001 From: longjin Date: Tue, 12 Sep 2023 16:43:05 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4PipeFlag=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/src/ipc/pipe.rs | 14 +++----------- user/apps/shell/cmd.c | 1 + user/apps/shell/cmd_test.h | 3 ++- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/kernel/src/ipc/pipe.rs b/kernel/src/ipc/pipe.rs index 14d585b06..819a7a8a7 100644 --- a/kernel/src/ipc/pipe.rs +++ b/kernel/src/ipc/pipe.rs @@ -12,15 +12,7 @@ use crate::{ }; use alloc::sync::{Arc, Weak}; -bitflags! { - pub struct PipeFlag:u32 { - // 管道标志位 - const NORMAL=0;// 0:默认行为,创建一个阻塞管道。与使用 pipe 函数创建的管道行为一致。 - // 设为fcntl里面的定义的数,方便C里面调用 - const O_NONBLOCK = 2048; // 创建一个非阻塞管道 - const O_CLOEXEC = 524288; // 在执行 exec 调用时关闭管道文件描述符。 - } -} + /// 我们设定pipe_buff的总大小为1024字节 const PIPE_BUFF_SIZE: usize = 1024; @@ -57,7 +49,7 @@ impl LockedPipeInode { metadata: Metadata { dev_id: 0, inode_id: generate_inode_id(), - size: 0, + size: PIPE_BUFF_SIZE as i64, blk_size: 0, blocks: 0, atime: TimeSpec::default(), @@ -95,7 +87,7 @@ impl IndexNode for LockedPipeInode { // 加锁 let mut inode = self.0.lock(); - //如果管道里面没有数据,则唤醒写端, + // 如果管道里面没有数据,则唤醒写端, while inode.valid_cnt == 0 { inode.write_wait_queue.wakeup(PROC_INTERRUPTIBLE.into()); // 如果为非阻塞管道,直接返回错误 diff --git a/user/apps/shell/cmd.c b/user/apps/shell/cmd.c index 7657f122a..564dcdb80 100644 --- a/user/apps/shell/cmd.c +++ b/user/apps/shell/cmd.c @@ -35,6 +35,7 @@ struct built_in_cmd_t shell_cmds[] = { {"free", shell_cmd_free}, {"help", shell_help}, {"pipe", shell_pipe_test}, + {"pipe2", shell_pipe2_test}, {"kill", shell_cmd_kill}, }; diff --git a/user/apps/shell/cmd_test.h b/user/apps/shell/cmd_test.h index bdf448a77..b187ed1a5 100644 --- a/user/apps/shell/cmd_test.h +++ b/user/apps/shell/cmd_test.h @@ -1,4 +1,5 @@ #pragma once #include "cmd.h" -int shell_pipe_test(int argc, char **argv); \ No newline at end of file +int shell_pipe_test(int argc, char **argv); +int shell_pipe2_test(int argc, char **argv); \ No newline at end of file