kernel+libc+libos: Add inode type for sockets

This commit is contained in:
apio 2023-07-27 16:35:27 +02:00
parent 27fcdab85f
commit 48f5f6ea33
Signed by: apio
GPG Key ID: B8A7D06E42258954
5 changed files with 7 additions and 0 deletions

View File

@ -17,6 +17,7 @@ namespace VFS
BlockDevice,
Symlink,
FIFO,
Socket,
};
class Inode;

View File

@ -55,6 +55,8 @@ Result<u64> 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);

View File

@ -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;
}

View File

@ -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

View File

@ -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 '?';
}