1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Add tcgetblob and statvfs support to kramfs.

This commit is contained in:
Jonas 'Sortie' Termansen 2015-05-31 20:18:21 +02:00
parent 143e0a2059
commit 34a832dbf3
2 changed files with 90 additions and 2 deletions

View file

@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2014. Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2014, 2015.
This file is part of Sortix. This file is part of Sortix.
@ -26,6 +26,7 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <limits.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@ -35,6 +36,7 @@
#include <sortix/fcntl.h> #include <sortix/fcntl.h>
#include <sortix/seek.h> #include <sortix/seek.h>
#include <sortix/stat.h> #include <sortix/stat.h>
#include <sortix/statvfs.h>
#include <sortix/kernel/fsfunc.h> #include <sortix/kernel/fsfunc.h>
#include <sortix/kernel/inode.h> #include <sortix/kernel/inode.h>
@ -42,6 +44,7 @@
#include <sortix/kernel/ioctx.h> #include <sortix/kernel/ioctx.h>
#include <sortix/kernel/kernel.h> #include <sortix/kernel/kernel.h>
#include <sortix/kernel/kthread.h> #include <sortix/kernel/kthread.h>
#include <sortix/kernel/memorymanagement.h>
#include <sortix/kernel/refcount.h> #include <sortix/kernel/refcount.h>
#include <sortix/kernel/string.h> #include <sortix/kernel/string.h>
#include <sortix/kernel/time.h> #include <sortix/kernel/time.h>
@ -51,6 +54,65 @@
namespace Sortix { namespace Sortix {
namespace KRAMFS { namespace KRAMFS {
static ssize_t common_tcgetblob(ioctx_t* ctx, const char* name, void* buffer, size_t count)
{
if ( !name )
{
static const char index[] = "device-path\0filesystem-type\0";
size_t index_size = sizeof(index) - 1;
if ( buffer && count < index_size )
return errno = ERANGE, -1;
if ( buffer && !ctx->copy_to_dest(buffer, &index, index_size) )
return -1;
return (ssize_t) index_size;
}
else if ( !strcmp(name, "device-path") )
{
const char* data = "none";
size_t size = strlen(data);
if ( buffer && count < size )
return errno = ERANGE, -1;
if ( buffer && !ctx->copy_to_dest(buffer, data, size) )
return -1;
return (ssize_t) size;
}
else if ( !strcmp(name, "filesystem-type") )
{
const char* data = "kram";
size_t size = strlen(data);
if ( buffer && count < size )
return errno = ERANGE, -1;
if ( buffer && !ctx->copy_to_dest(buffer, data, size) )
return -1;
return (ssize_t) size;
}
else
return errno = ENOENT, -1;
}
int common_statvfs(ioctx_t* ctx, struct statvfs* stvfs, dev_t dev)
{
size_t memory_used;
size_t memory_total;
Memory::Statistics(&memory_used, &memory_total);
struct statvfs retstvfs;
memset(&retstvfs, 0, sizeof(retstvfs));
retstvfs.f_bsize = Page::Size();
retstvfs.f_frsize = Page::Size();
retstvfs.f_blocks = memory_total / Page::Size();
retstvfs.f_bfree = (memory_total - memory_used) / Page::Size();
retstvfs.f_bavail = (memory_total - memory_used) / Page::Size();
retstvfs.f_files = 0;
retstvfs.f_ffree = 0;
retstvfs.f_favail = 0;
retstvfs.f_fsid = dev;
retstvfs.f_flag = ST_NOSUID;
retstvfs.f_namemax = ULONG_MAX;
if ( !ctx->copy_to_dest(stvfs, &retstvfs, sizeof(retstvfs)) )
return -1;
return 0;
}
File::File(InodeType inode_type, mode_t type, dev_t dev, ino_t ino, uid_t owner, File::File(InodeType inode_type, mode_t type, dev_t dev, ino_t ino, uid_t owner,
gid_t group, mode_t mode) gid_t group, mode_t mode)
{ {
@ -116,6 +178,16 @@ ssize_t File::readlink(ioctx_t* ctx, char* buf, size_t bufsize)
return fcache.pread(ctx, (uint8_t*) buf, bufsize, 0); return fcache.pread(ctx, (uint8_t*) buf, bufsize, 0);
} }
ssize_t File::tcgetblob(ioctx_t* ctx, const char* name, void* buffer, size_t count)
{
return common_tcgetblob(ctx, name, buffer, count);
}
int File::statvfs(ioctx_t* ctx, struct statvfs* stvfs)
{
return common_statvfs(ctx, stvfs, dev);
}
Dir::Dir(dev_t dev, ino_t ino, uid_t owner, gid_t group, mode_t mode) Dir::Dir(dev_t dev, ino_t ino, uid_t owner, gid_t group, mode_t mode)
{ {
inode_type = INODE_TYPE_DIR; inode_type = INODE_TYPE_DIR;
@ -489,5 +561,15 @@ int Dir::rename_here(ioctx_t* ctx, Ref<Inode> from, const char* oldname,
return 0; return 0;
} }
ssize_t Dir::tcgetblob(ioctx_t* ctx, const char* name, void* buffer, size_t count)
{
return common_tcgetblob(ctx, name, buffer, count);
}
int Dir::statvfs(ioctx_t* ctx, struct statvfs* stvfs)
{
return common_statvfs(ctx, stvfs, dev);
}
} // namespace KRAMFS } // namespace KRAMFS
} // namespace Sortix } // namespace Sortix

View file

@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2014. Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2014, 2015.
This file is part of Sortix. This file is part of Sortix.
@ -51,6 +51,9 @@ public:
virtual ssize_t pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count, virtual ssize_t pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count,
off_t off); off_t off);
virtual ssize_t readlink(ioctx_t* ctx, char* buf, size_t bufsiz); virtual ssize_t readlink(ioctx_t* ctx, char* buf, size_t bufsiz);
virtual ssize_t tcgetblob(ioctx_t* ctx, const char* name, void* buffer,
size_t count);
virtual int statvfs(ioctx_t* ctx, struct statvfs* stvfs);
private: private:
FileCache fcache; FileCache fcache;
@ -77,6 +80,9 @@ public:
const char* filename); const char* filename);
virtual int rename_here(ioctx_t* ctx, Ref<Inode> from, const char* oldname, virtual int rename_here(ioctx_t* ctx, Ref<Inode> from, const char* oldname,
const char* newname); const char* newname);
virtual ssize_t tcgetblob(ioctx_t* ctx, const char* name, void* buffer,
size_t count);
virtual int statvfs(ioctx_t* ctx, struct statvfs* stvfs);
private: private:
size_t FindChild(const char* filename); size_t FindChild(const char* filename);