From d511bfb75b93ae56a3700bd443401ae2c5b43587 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Mon, 16 Feb 2015 14:23:59 +0100 Subject: [PATCH] Fix partition inode type and stat method. --- kernel/partition.cpp | 20 ++++++++++++++++++-- kernel/partition.h | 3 ++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/kernel/partition.cpp b/kernel/partition.cpp index 598ecbf2..47323ea5 100644 --- a/kernel/partition.cpp +++ b/kernel/partition.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2013. + Copyright(C) Jonas 'Sortie' Termansen 2013, 2015. This file is part of Sortix. @@ -27,8 +27,10 @@ #include #include +#include #include +#include #include #include @@ -40,11 +42,11 @@ Partition::Partition(Ref inner_inode, off_t start, off_t length) { this->dev = (dev_t) this; this->ino = (ino_t) this; + this->type = inner_inode->type; this->inode_type = INODE_TYPE_FILE; this->inner_inode = inner_inode; this->start = start; this->length = length; - this->stat_size = length; } Partition::~Partition() @@ -98,4 +100,18 @@ ssize_t Partition::pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count, return inner_inode->pwrite(ctx, buf, count, start + off); } +int Partition::stat(ioctx_t* ctx, struct stat* st) +{ + if ( inner_inode->stat(ctx, st) < 0 ) + return -1; + struct stat myst; + if ( !ctx->copy_from_src(&myst, st, sizeof(myst)) ) + return -1; + myst.st_size = length; + myst.st_blocks = length / (myst.st_blksize ? myst.st_blksize : 1); + if ( !ctx->copy_to_dest(st, &myst, sizeof(myst)) ) + return -1; + return 0; +} + } diff --git a/kernel/partition.h b/kernel/partition.h index eec26e1d..5afb0f2e 100644 --- a/kernel/partition.h +++ b/kernel/partition.h @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2013. + Copyright(C) Jonas 'Sortie' Termansen 2013, 2015. This file is part of Sortix. @@ -48,6 +48,7 @@ public: virtual ssize_t pread(ioctx_t* ctx, uint8_t* buf, size_t count, off_t off); virtual ssize_t pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count, off_t off); + virtual int stat(ioctx_t* ctx, struct stat* st); };