Ver código fonte

fix(net,unix): fix miss create of file

Samuka007 2 semanas atrás
pai
commit
e158632590
2 arquivos alterados com 6 adições e 45 exclusões
  1. 1 30
      kernel/src/net/posix.rs
  2. 5 15
      kernel/src/net/socket/unix/stream/mod.rs

+ 1 - 30
kernel/src/net/posix.rs

@@ -200,36 +200,7 @@ impl SockAddr {
                         crate::filesystem::vfs::fcntl::AtFlags::AT_FDCWD.bits(),
                         crate::filesystem::vfs::fcntl::AtFlags::AT_FDCWD.bits(),
                         path.trim(),
                         path.trim(),
                     )?;
                     )?;
-                    let inode0: Result<Arc<dyn IndexNode>, SystemError> =
-                        inode_begin.lookup_follow_symlink(&path, VFS_MAX_FOLLOW_SYMLINK_TIMES);
-
-                    let inode = match inode0 {
-                        Ok(inode) => inode,
-                        Err(_) => {
-                            let (filename, parent_path) =
-                                crate::filesystem::vfs::utils::rsplit_path(&path);
-                            // 查找父目录
-                            log::debug!("filename {:?} parent_path {:?}", filename, parent_path);
-
-                            let parent_inode: Arc<dyn IndexNode> =
-                                ROOT_INODE().lookup(parent_path.unwrap_or("/"))?;
-                            // 创建文件
-                            let inode: Arc<dyn IndexNode> = match parent_inode.create(
-                                filename,
-                                FileType::File,
-                                crate::filesystem::vfs::syscall::ModeType::from_bits_truncate(
-                                    0o755,
-                                ),
-                            ) {
-                                Ok(inode) => inode,
-                                Err(e) => {
-                                    log::debug!("inode create fail {:?}", e);
-                                    return Err(e);
-                                }
-                            };
-                            inode
-                        }
-                    };
+                    let inode = inode_begin.lookup_follow_symlink(&path, VFS_MAX_FOLLOW_SYMLINK_TIMES)?;
 
 
                     return Ok(Endpoint::Unixpath((inode.metadata()?.inode_id, path)));
                     return Ok(Endpoint::Unixpath((inode.metadata()?.inode_id, path)));
                 }
                 }

+ 5 - 15
kernel/src/net/socket/unix/stream/mod.rs

@@ -163,26 +163,16 @@ impl Socket for StreamSocket {
         let (peer_inode, sun_path) = match server_endpoint {
         let (peer_inode, sun_path) = match server_endpoint {
             Endpoint::Inode((inode, path)) => (inode, path),
             Endpoint::Inode((inode, path)) => (inode, path),
             Endpoint::Unixpath((inode_id, path)) => {
             Endpoint::Unixpath((inode_id, path)) => {
-                let inode_guard = INODE_MAP.read_irqsave();
-                let inode = inode_guard.get(&inode_id).unwrap();
-                match inode {
-                    Endpoint::Inode((inode, _)) => (inode.clone(), path),
+                match INODE_MAP.read_irqsave().get(&inode_id) {
+                    Some(Endpoint::Inode((inode, _))) => (inode.clone(), path),
                     _ => return Err(SystemError::EINVAL),
                     _ => return Err(SystemError::EINVAL),
                 }
                 }
             }
             }
             Endpoint::Abspath((abs_addr, path)) => {
             Endpoint::Abspath((abs_addr, path)) => {
-                let inode_guard = ABS_INODE_MAP.lock_irqsave();
-                let inode = match inode_guard.get(&abs_addr.name()) {
-                    Some(inode) => inode,
-                    None => {
-                        log::debug!("can not find inode from absInodeMap");
-                        return Err(SystemError::EINVAL);
-                    }
-                };
-                match inode {
-                    Endpoint::Inode((inode, _)) => (inode.clone(), path),
+                match ABS_INODE_MAP.lock_irqsave().get(&abs_addr.name()) {
+                    Some(Endpoint::Inode((inode, _))) => (inode.clone(), path),
                     _ => {
                     _ => {
-                        debug!("when connect, find inode failed!");
+                        log::debug!("can not find inode from absInodeMap");
                         return Err(SystemError::EINVAL);
                         return Err(SystemError::EINVAL);
                     }
                     }
                 }
                 }