From 48f5f6ea3396a09bd026a51be8df9beba83131b6 Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 27 Jul 2023 16:35:27 +0200 Subject: [PATCH] kernel+libc+libos: Add inode type for sockets --- kernel/src/fs/VFS.h | 1 + kernel/src/sys/open.cpp | 2 ++ kernel/src/sys/stat.cpp | 1 + libc/include/bits/modes.h | 2 ++ libos/src/Mode.cpp | 1 + 5 files changed, 7 insertions(+) diff --git a/kernel/src/fs/VFS.h b/kernel/src/fs/VFS.h index f89eaa4d..ac014cd8 100644 --- a/kernel/src/fs/VFS.h +++ b/kernel/src/fs/VFS.h @@ -17,6 +17,7 @@ namespace VFS BlockDevice, Symlink, FIFO, + Socket, }; class Inode; diff --git a/kernel/src/sys/open.cpp b/kernel/src/sys/open.cpp index ce160a19..0a3de817 100644 --- a/kernel/src/sys/open.cpp +++ b/kernel/src/sys/open.cpp @@ -55,6 +55,8 @@ Result sys_openat(Registers*, SyscallArgs args) // This should only be possible if O_NOFOLLOW was in flags. if (inode->type() == VFS::InodeType::Symlink) return err(ELOOP); + if (inode->type() == VFS::InodeType::Socket) return err(ENXIO); + if (flags & O_TMPFILE) { if (inode->type() != VFS::InodeType::Directory) return err(EINVAL); diff --git a/kernel/src/sys/stat.cpp b/kernel/src/sys/stat.cpp index 85c534cd..55e35699 100644 --- a/kernel/src/sys/stat.cpp +++ b/kernel/src/sys/stat.cpp @@ -18,6 +18,7 @@ static mode_t make_mode(mode_t mode, VFS::InodeType type) case VFS::InodeType::BlockDevice: result |= S_IFBLK; break; case VFS::InodeType::Symlink: result |= S_IFLNK; break; case VFS::InodeType::FIFO: result |= S_IFIFO; break; + case VFS::InodeType::Socket: result |= S_IFSOCK; break; default: break; } diff --git a/libc/include/bits/modes.h b/libc/include/bits/modes.h index 6f567339..b46df7c2 100644 --- a/libc/include/bits/modes.h +++ b/libc/include/bits/modes.h @@ -10,6 +10,7 @@ #define S_IFBLK 030000 #define S_IFDIR 040000 #define S_IFCHR 050000 +#define S_IFSOCK 060000 #define __CHECK_TYPE(mode, type) (((mode)&S_IFMT) == type) @@ -19,6 +20,7 @@ #define S_ISBLK(mode) __CHECK_TYPE(mode, S_IFBLK) #define S_ISLNK(mode) __CHECK_TYPE(mode, S_IFLNK) #define S_ISFIFO(mode) __CHECK_TYPE(mode, S_IFIFO) +#define S_ISSOCK(mode) __CHECK_TYPE(mode, S_IFSOCK) #define S_IRWXU 0700 #define S_IRUSR 0400 diff --git a/libos/src/Mode.cpp b/libos/src/Mode.cpp index 2c6e6cbb..1b3d3c86 100644 --- a/libos/src/Mode.cpp +++ b/libos/src/Mode.cpp @@ -21,6 +21,7 @@ namespace os if (S_ISBLK(mode)) return 'b'; if (S_ISLNK(mode)) return 'l'; if (S_ISFIFO(mode)) return 'p'; + if (S_ISSOCK(mode)) return 's'; return '?'; }