Add factory inode support.

This commit is contained in:
Jonas 'Sortie' Termansen 2016-10-22 23:47:28 +02:00
parent 1240a44298
commit d529a1e332
7 changed files with 42 additions and 4 deletions

View File

@ -214,6 +214,8 @@ public:
size_t size, off_t start);
virtual Ref<Inode> open(ioctx_t* ctx, const char* filename, int flags,
mode_t mode);
virtual Ref<Inode> factory(ioctx_t* ctx, const char* filename, int flags,
mode_t mode);
virtual int mkdir(ioctx_t* ctx, const char* filename, mode_t mode);
virtual int link(ioctx_t* ctx, const char* filename, Ref<Inode> node);
virtual int link_raw(ioctx_t* ctx, const char* filename, Ref<Inode> node);
@ -1065,6 +1067,12 @@ Ref<Inode> Unode::open(ioctx_t* ctx, const char* filename, int flags,
return ret;
}
Ref<Inode> Unode::factory(ioctx_t* /*ctx*/, const char* /*filename*/,
int /*flags*/, mode_t /*mode*/)
{
return errno = EBADF, Ref<Inode>(NULL);
}
int Unode::mkdir(ioctx_t* ctx, const char* filename, mode_t mode)
{
Channel* channel = server->Connect(ctx);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, 2014 Jonas 'Sortie' Termansen.
* Copyright (c) 2012, 2013, 2014, 2016 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -44,6 +44,9 @@ extern "C" {
#define O_SYMLINK_NOFOLLOW (1<<13)
#define O_NOCTTY (1<<14)
#define O_TTY_INIT (1<<15)
#ifdef __is_sortix_kernel
#define O_IS_STAT (1<<30)
#endif
#define O_ACCMODE (O_READ | O_WRITE | O_EXEC | O_SEARCH)

View File

@ -73,6 +73,8 @@ public:
size_t size, off_t start) = 0;
virtual Ref<Inode> open(ioctx_t* ctx, const char* filename, int flags,
mode_t mode) = 0;
virtual Ref<Inode> factory(ioctx_t* ctx, const char* filename, int flags,
mode_t mode) = 0;
virtual int mkdir(ioctx_t* ctx, const char* filename, mode_t mode) = 0;
virtual int link(ioctx_t* ctx, const char* filename, Ref<Inode> node) = 0;
virtual int link_raw(ioctx_t* ctx, const char* filename, Ref<Inode> node) = 0;
@ -166,6 +168,8 @@ public:
size_t size, off_t start);
virtual Ref<Inode> open(ioctx_t* ctx, const char* filename, int flags,
mode_t mode);
virtual Ref<Inode> factory(ioctx_t* ctx, const char* filename, int flags,
mode_t mode);
virtual int mkdir(ioctx_t* ctx, const char* filename, mode_t mode);
virtual int link(ioctx_t* ctx, const char* filename, Ref<Inode> node);
virtual int link_raw(ioctx_t* ctx, const char* filename, Ref<Inode> node);

View File

@ -84,6 +84,11 @@ struct stat
#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
#ifdef __is_sortix_kernel
#define S_IFFACTORY 0x10000
#define S_IFFACTORY_NOSTAT 0x20000
#endif
#define UTIME_NOW 0x3FFFFFFF
#define UTIME_OMIT 0x3FFFFFFE

View File

@ -217,6 +217,14 @@ Ref<Inode> AbstractInode::open(ioctx_t* /*ctx*/, const char* /*filename*/,
return errno = ENOTDIR, Ref<Inode>(NULL);
}
Ref<Inode> AbstractInode::factory(ioctx_t* /*ctx*/, const char* /*filename*/,
int /*flags*/, mode_t /*mode*/)
{
if ( inode_type == INODE_TYPE_DIR )
return errno = EBADF, Ref<Inode>(NULL);
return errno = ENOTDIR, Ref<Inode>(NULL);
}
int AbstractInode::mkdir(ioctx_t* /*ctx*/, const char* /*filename*/,
mode_t /*mode*/)
{

View File

@ -205,7 +205,8 @@ int sys_faccessat(int dirfd, const char* path, int mode, int flags)
ioctx_t ctx; SetupUserIOCtx(&ctx);
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
if ( !from ) { delete[] pathcopy; return -1; }
int open_flags = O_READ | (flags & AT_SYMLINK_NOFOLLOW ? O_SYMLINK_NOFOLLOW : 0);
int open_flags = O_READ | O_IS_STAT |
(flags & AT_SYMLINK_NOFOLLOW ? O_SYMLINK_NOFOLLOW : 0);
Ref<Descriptor> desc = from->open(&ctx, pathcopy, open_flags);
delete[] pathcopy;
if ( !desc )
@ -290,7 +291,8 @@ int sys_fstatat(int dirfd, const char* path, struct stat* st, int flags)
ioctx_t ctx; SetupUserIOCtx(&ctx);
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
if ( !from ) { delete[] pathcopy; return -1; }
int open_flags = O_READ | (flags & AT_SYMLINK_NOFOLLOW ? O_SYMLINK_NOFOLLOW : 0);
int open_flags = O_READ | O_IS_STAT |
(flags & AT_SYMLINK_NOFOLLOW ? O_SYMLINK_NOFOLLOW : 0);
Ref<Descriptor> desc = from->open(&ctx, pathcopy, open_flags);
delete[] pathcopy;
if ( !desc )
@ -326,7 +328,8 @@ int sys_fstatvfsat(int dirfd, const char* path, struct statvfs* stvfs, int flags
ioctx_t ctx; SetupUserIOCtx(&ctx);
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
if ( !from ) { delete[] pathcopy; return -1; }
int open_flags = O_READ | (flags & AT_SYMLINK_NOFOLLOW ? O_SYMLINK_NOFOLLOW : 0);
int open_flags = O_READ | O_IS_STAT |
(flags & AT_SYMLINK_NOFOLLOW ? O_SYMLINK_NOFOLLOW : 0);
Ref<Descriptor> desc = from->open(&ctx, pathcopy, open_flags);
delete[] pathcopy;
if ( !desc )

View File

@ -98,6 +98,13 @@ Ref<Vnode> Vnode::open(ioctx_t* ctx, const char* filename, int flags, mode_t mod
Ref<Inode> retinode = inode->open(ctx, filename, flags, mode);
if ( !retinode )
return Ref<Vnode>(NULL);
if ( retinode->type & S_IFFACTORY &&
!(retinode->type & S_IFFACTORY_NOSTAT && flags & O_IS_STAT) )
{
retinode = retinode->factory(ctx, filename, flags, mode);
if ( !retinode )
return Ref<Vnode>(NULL);
}
Ref<Vnode> retmountedat = mountedat;
ino_t retrootino = rootino;
dev_t retrootdev = rootdev;