mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:58:11 +00:00
Add a Unix namespace for foo_t types.
This allows me to keep prototyping things on a random desktop machine, even if that machine has its own ideas about foo_t types.
This commit is contained in:
parent
c6d6ba7512
commit
1f41a36c52
16 changed files with 116 additions and 49 deletions
|
@ -7,8 +7,8 @@ class CharacterDevice {
|
||||||
public:
|
public:
|
||||||
virtual ~CharacterDevice();
|
virtual ~CharacterDevice();
|
||||||
|
|
||||||
virtual ssize_t read(byte* buffer, size_t bufferSize) = 0;
|
virtual Unix::ssize_t read(byte* buffer, Unix::size_t bufferSize) = 0;
|
||||||
virtual ssize_t write(const byte* buffer, size_t bufferSize) = 0;
|
virtual Unix::ssize_t write(const byte* buffer, Unix::size_t bufferSize) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CharacterDevice() { }
|
CharacterDevice() { }
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "Ext2FileSystem.h"
|
#include "Ext2FileSystem.h"
|
||||||
#include "ext2_fs.h"
|
#include "ext2_fs.h"
|
||||||
|
#include "UnixTypes.h"
|
||||||
#include <AK/Bitmap.h>
|
#include <AK/Bitmap.h>
|
||||||
#include <AK/StdLib.h>
|
#include <AK/StdLib.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -257,7 +258,7 @@ Vector<unsigned> Ext2FileSystem::blockListForInode(const ext2_inode& e2inode) co
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, FileOffset offset, size_t count, byte* buffer) const
|
ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, size_t count, byte* buffer) const
|
||||||
{
|
{
|
||||||
ASSERT(offset >= 0);
|
ASSERT(offset >= 0);
|
||||||
ASSERT(inode.fileSystemID() == id());
|
ASSERT(inode.fileSystemID() == id());
|
||||||
|
@ -281,7 +282,7 @@ ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, FileOffset offset,
|
||||||
// This avoids wasting an entire block on short links. (Most links are short.)
|
// This avoids wasting an entire block on short links. (Most links are short.)
|
||||||
static const unsigned maxInlineSymlinkLength = 60;
|
static const unsigned maxInlineSymlinkLength = 60;
|
||||||
if (isSymbolicLink(e2inode->i_mode) && e2inode->i_size < maxInlineSymlinkLength) {
|
if (isSymbolicLink(e2inode->i_mode) && e2inode->i_size < maxInlineSymlinkLength) {
|
||||||
ssize_t nread = min(e2inode->i_size - offset, static_cast<FileOffset>(count));
|
ssize_t nread = min(e2inode->i_size - offset, static_cast<Unix::off_t>(count));
|
||||||
memcpy(buffer, e2inode->i_block + offset, nread);
|
memcpy(buffer, e2inode->i_block + offset, nread);
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
@ -302,7 +303,7 @@ ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, FileOffset offset,
|
||||||
dword offsetIntoFirstBlock = offset % blockSize();
|
dword offsetIntoFirstBlock = offset % blockSize();
|
||||||
|
|
||||||
ssize_t nread = 0;
|
ssize_t nread = 0;
|
||||||
size_t remainingCount = min((FileOffset)count, e2inode->i_size - offset);
|
size_t remainingCount = min((Unix::off_t)count, e2inode->i_size - offset);
|
||||||
byte* out = buffer;
|
byte* out = buffer;
|
||||||
|
|
||||||
#ifdef EXT2_DEBUG
|
#ifdef EXT2_DEBUG
|
||||||
|
@ -348,7 +349,7 @@ ByteBuffer Ext2FileSystem::readInode(InodeIdentifier inode) const
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
byte buffer[512];
|
byte buffer[512];
|
||||||
byte* out = contents.pointer();
|
byte* out = contents.pointer();
|
||||||
FileOffset offset = 0;
|
Unix::off_t offset = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
nread = readInodeBytes(inode, offset, sizeof(buffer), buffer);
|
nread = readInodeBytes(inode, offset, sizeof(buffer), buffer);
|
||||||
if (nread <= 0)
|
if (nread <= 0)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "DeviceBackedFileSystem.h"
|
#include "DeviceBackedFileSystem.h"
|
||||||
|
#include "UnixTypes.h"
|
||||||
#include <AK/Buffer.h>
|
#include <AK/Buffer.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ private:
|
||||||
virtual InodeMetadata inodeMetadata(InodeIdentifier) const override;
|
virtual InodeMetadata inodeMetadata(InodeIdentifier) const override;
|
||||||
virtual bool setModificationTime(InodeIdentifier, dword timestamp) override;
|
virtual bool setModificationTime(InodeIdentifier, dword timestamp) override;
|
||||||
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, word mode) override;
|
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, word mode) override;
|
||||||
virtual ssize_t readInodeBytes(InodeIdentifier, FileOffset offset, size_t count, byte* buffer) const override;
|
virtual ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, size_t count, byte* buffer) const override;
|
||||||
|
|
||||||
bool isDirectoryInode(unsigned) const;
|
bool isDirectoryInode(unsigned) const;
|
||||||
unsigned allocateInode(unsigned preferredGroup, unsigned expectedSize);
|
unsigned allocateInode(unsigned preferredGroup, unsigned expectedSize);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "CharacterDevice.h"
|
#include "CharacterDevice.h"
|
||||||
#include "sys-errno.h"
|
#include "sys-errno.h"
|
||||||
|
#include "UnixTypes.h"
|
||||||
|
|
||||||
FileHandle::FileHandle(RetainPtr<VirtualFileSystem::Node>&& vnode)
|
FileHandle::FileHandle(RetainPtr<VirtualFileSystem::Node>&& vnode)
|
||||||
: m_vnode(std::move(vnode))
|
: m_vnode(std::move(vnode))
|
||||||
|
@ -12,14 +13,38 @@ FileHandle::~FileHandle()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool additionWouldOverflow(FileOffset a, FileOffset b)
|
bool additionWouldOverflow(Unix::off_t a, Unix::off_t b)
|
||||||
{
|
{
|
||||||
ASSERT(a > 0);
|
ASSERT(a > 0);
|
||||||
uint64_t ua = a;
|
uint64_t ua = a;
|
||||||
return (ua + b) > maxFileOffset;
|
return (ua + b) > maxFileOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileOffset FileHandle::lseek(FileOffset offset, SeekType seekType)
|
int FileHandle::stat(Unix::stat* buffer)
|
||||||
|
{
|
||||||
|
if (!m_vnode)
|
||||||
|
return -EBADF;
|
||||||
|
|
||||||
|
auto metadata = m_vnode->inode.metadata();
|
||||||
|
if (!metadata.isValid())
|
||||||
|
return -EIO;
|
||||||
|
|
||||||
|
buffer->st_dev = 0; // FIXME
|
||||||
|
buffer->st_ino = metadata.inode.index();
|
||||||
|
buffer->st_mode = metadata.mode;
|
||||||
|
buffer->st_nlink = metadata.linkCount;
|
||||||
|
buffer->st_uid = metadata.uid;
|
||||||
|
buffer->st_gid = metadata.gid;
|
||||||
|
buffer->st_rdev = 0; // FIXME
|
||||||
|
buffer->st_blksize = 0; // FIXME
|
||||||
|
buffer->st_blocks = 0; // FIXME
|
||||||
|
buffer->st_atime = metadata.atime;
|
||||||
|
buffer->st_mtime = metadata.mtime;
|
||||||
|
buffer->st_ctime = metadata.ctime;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Unix::off_t FileHandle::seek(Unix::off_t offset, int whence)
|
||||||
{
|
{
|
||||||
if (!m_vnode)
|
if (!m_vnode)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
@ -27,23 +52,26 @@ FileOffset FileHandle::lseek(FileOffset offset, SeekType seekType)
|
||||||
// FIXME: The file type should be cached on the vnode.
|
// FIXME: The file type should be cached on the vnode.
|
||||||
// It's silly that we have to do a full metadata lookup here.
|
// It's silly that we have to do a full metadata lookup here.
|
||||||
auto metadata = m_vnode->inode.metadata();
|
auto metadata = m_vnode->inode.metadata();
|
||||||
|
if (!metadata.isValid())
|
||||||
|
return -EIO;
|
||||||
|
|
||||||
if (metadata.isSocket() || metadata.isFIFO())
|
if (metadata.isSocket() || metadata.isFIFO())
|
||||||
return -ESPIPE;
|
return -ESPIPE;
|
||||||
|
|
||||||
FileOffset newOffset;
|
Unix::off_t newOffset;
|
||||||
|
|
||||||
switch (seekType) {
|
switch (whence) {
|
||||||
case SeekType::Absolute:
|
case SEEK_SET:
|
||||||
newOffset = offset;
|
newOffset = offset;
|
||||||
break;
|
break;
|
||||||
case SeekType::RelativeToCurrent:
|
case SEEK_CUR:
|
||||||
newOffset = m_currentOffset + offset;
|
newOffset = m_currentOffset + offset;
|
||||||
if (additionWouldOverflow(m_currentOffset, offset))
|
if (additionWouldOverflow(m_currentOffset, offset))
|
||||||
return -EOVERFLOW;
|
return -EOVERFLOW;
|
||||||
if (newOffset < 0)
|
if (newOffset < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
break;
|
break;
|
||||||
case SeekType::RelativeToEnd:
|
case SEEK_END:
|
||||||
// FIXME: Implement!
|
// FIXME: Implement!
|
||||||
notImplemented();
|
notImplemented();
|
||||||
break;
|
break;
|
||||||
|
@ -55,13 +83,13 @@ FileOffset FileHandle::lseek(FileOffset offset, SeekType seekType)
|
||||||
return m_currentOffset;
|
return m_currentOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t FileHandle::read(byte* buffer, size_t count)
|
Unix::ssize_t FileHandle::read(byte* buffer, Unix::size_t count)
|
||||||
{
|
{
|
||||||
if (m_vnode->isCharacterDevice()) {
|
if (m_vnode->isCharacterDevice()) {
|
||||||
// FIXME: What should happen to m_currentOffset?
|
// FIXME: What should happen to m_currentOffset?
|
||||||
return m_vnode->characterDevice()->read(buffer, count);
|
return m_vnode->characterDevice()->read(buffer, count);
|
||||||
}
|
}
|
||||||
ssize_t nread = m_vnode->fileSystem()->readInodeBytes(m_vnode->inode, m_currentOffset, count, buffer);
|
Unix::ssize_t nread = m_vnode->fileSystem()->readInodeBytes(m_vnode->inode, m_currentOffset, count, buffer);
|
||||||
m_currentOffset += nread;
|
m_currentOffset += nread;
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +98,7 @@ ByteBuffer FileHandle::readEntireFile()
|
||||||
{
|
{
|
||||||
if (m_vnode->isCharacterDevice()) {
|
if (m_vnode->isCharacterDevice()) {
|
||||||
auto buffer = ByteBuffer::createUninitialized(1024);
|
auto buffer = ByteBuffer::createUninitialized(1024);
|
||||||
ssize_t nread = m_vnode->characterDevice()->read(buffer.pointer(), buffer.size());
|
Unix::ssize_t nread = m_vnode->characterDevice()->read(buffer.pointer(), buffer.size());
|
||||||
buffer.trim(nread);
|
buffer.trim(nread);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,19 +3,14 @@
|
||||||
#include "VirtualFileSystem.h"
|
#include "VirtualFileSystem.h"
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
|
|
||||||
enum class SeekType {
|
|
||||||
Absolute, // SEEK_SET
|
|
||||||
RelativeToCurrent, // SEEK_CUR
|
|
||||||
RelativeToEnd, // SEEK_END
|
|
||||||
};
|
|
||||||
|
|
||||||
class FileHandle {
|
class FileHandle {
|
||||||
public:
|
public:
|
||||||
explicit FileHandle(RetainPtr<VirtualFileSystem::Node>&&);
|
explicit FileHandle(RetainPtr<VirtualFileSystem::Node>&&);
|
||||||
~FileHandle();
|
~FileHandle();
|
||||||
|
|
||||||
FileOffset lseek(FileOffset, SeekType);
|
Unix::off_t seek(Unix::off_t, int whence);
|
||||||
ssize_t read(byte* buffer, size_t count);
|
Unix::ssize_t read(byte* buffer, Unix::size_t count);
|
||||||
|
int stat(Unix::stat*);
|
||||||
|
|
||||||
ByteBuffer readEntireFile();
|
ByteBuffer readEntireFile();
|
||||||
|
|
||||||
|
@ -24,6 +19,6 @@ private:
|
||||||
|
|
||||||
RetainPtr<VirtualFileSystem::Node> m_vnode;
|
RetainPtr<VirtualFileSystem::Node> m_vnode;
|
||||||
|
|
||||||
FileOffset m_currentOffset { 0 };
|
Unix::off_t m_currentOffset { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "InodeIdentifier.h"
|
#include "InodeIdentifier.h"
|
||||||
#include "InodeMetadata.h"
|
#include "InodeMetadata.h"
|
||||||
#include "Limits.h"
|
#include "Limits.h"
|
||||||
|
#include "UnixTypes.h"
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
|
@ -28,7 +29,7 @@ public:
|
||||||
virtual bool writeInode(InodeIdentifier, const ByteBuffer&) = 0;
|
virtual bool writeInode(InodeIdentifier, const ByteBuffer&) = 0;
|
||||||
virtual InodeMetadata inodeMetadata(InodeIdentifier) const = 0;
|
virtual InodeMetadata inodeMetadata(InodeIdentifier) const = 0;
|
||||||
|
|
||||||
virtual ssize_t readInodeBytes(InodeIdentifier, FileOffset offset, size_t count, byte* buffer) const = 0;
|
virtual ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, size_t count, byte* buffer) const = 0;
|
||||||
|
|
||||||
struct DirectoryEntry {
|
struct DirectoryEntry {
|
||||||
String name;
|
String name;
|
||||||
|
|
|
@ -13,15 +13,15 @@ FullDevice::~FullDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t FullDevice::read(byte* buffer, size_t bufferSize)
|
Unix::ssize_t FullDevice::read(byte* buffer, Unix::size_t bufferSize)
|
||||||
{
|
{
|
||||||
printf("read from full device\n");
|
printf("read from full device\n");
|
||||||
size_t count = min(GoodBufferSize, bufferSize);
|
Unix::size_t count = min(GoodBufferSize, bufferSize);
|
||||||
memset(buffer, 0, count);
|
memset(buffer, 0, count);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t FullDevice::write(const byte*, size_t bufferSize)
|
Unix::ssize_t FullDevice::write(const byte*, Unix::size_t bufferSize)
|
||||||
{
|
{
|
||||||
if (bufferSize == 0)
|
if (bufferSize == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -7,7 +7,7 @@ public:
|
||||||
FullDevice();
|
FullDevice();
|
||||||
virtual ~FullDevice();
|
virtual ~FullDevice();
|
||||||
|
|
||||||
ssize_t read(byte* buffer, size_t bufferSize) override;
|
Unix::ssize_t read(byte* buffer, Unix::size_t bufferSize) override;
|
||||||
ssize_t write(const byte* buffer, size_t bufferSize) override;
|
Unix::ssize_t write(const byte* buffer, Unix::size_t bufferSize) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include "UnixTypes.h"
|
||||||
|
|
||||||
typedef dword size_t;
|
static const Unix::size_t GoodBufferSize = 4096;
|
||||||
typedef signed_dword ssize_t;
|
|
||||||
|
|
||||||
static const size_t GoodBufferSize = 4096;
|
inline static const Unix::off_t maxFileOffset = std::numeric_limits<Unix::off_t>::max();
|
||||||
|
|
||||||
typedef int64_t FileOffset;
|
|
||||||
inline static const FileOffset maxFileOffset = std::numeric_limits<FileOffset>::max();
|
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,13 @@ NullDevice::~NullDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t NullDevice::read(byte*, size_t)
|
Unix::ssize_t NullDevice::read(byte*, Unix::size_t)
|
||||||
{
|
{
|
||||||
printf("read from null\n");
|
printf("read from null\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t NullDevice::write(const byte*, size_t bufferSize)
|
Unix::ssize_t NullDevice::write(const byte*, Unix::size_t bufferSize)
|
||||||
{
|
{
|
||||||
return min(GoodBufferSize, bufferSize);
|
return min(GoodBufferSize, bufferSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ public:
|
||||||
NullDevice();
|
NullDevice();
|
||||||
virtual ~NullDevice();
|
virtual ~NullDevice();
|
||||||
|
|
||||||
ssize_t read(byte* buffer, size_t bufferSize) override;
|
Unix::ssize_t read(byte* buffer, Unix::size_t bufferSize) override;
|
||||||
ssize_t write(const byte* buffer, size_t bufferSize) override;
|
Unix::ssize_t write(const byte* buffer, Unix::size_t bufferSize) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,7 @@ bool SyntheticFileSystem::writeInode(InodeIdentifier, const ByteBuffer&)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier, FileOffset offset, size_t count, byte* buffer) const
|
ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier, Unix::off_t offset, size_t count, byte* buffer) const
|
||||||
{
|
{
|
||||||
printf("FIXME: Implement SyntheticFileSystem::readInodeBytes().\n");
|
printf("FIXME: Implement SyntheticFileSystem::readInodeBytes().\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
#include "UnixTypes.h"
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
|
|
||||||
class SyntheticFileSystem final : public FileSystem {
|
class SyntheticFileSystem final : public FileSystem {
|
||||||
|
@ -17,7 +18,7 @@ public:
|
||||||
virtual InodeMetadata inodeMetadata(InodeIdentifier) const override;
|
virtual InodeMetadata inodeMetadata(InodeIdentifier) const override;
|
||||||
virtual bool setModificationTime(InodeIdentifier, dword timestamp) override;
|
virtual bool setModificationTime(InodeIdentifier, dword timestamp) override;
|
||||||
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, word mode) override;
|
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, word mode) override;
|
||||||
virtual ssize_t readInodeBytes(InodeIdentifier, FileOffset offset, size_t count, byte* buffer) const override;
|
virtual ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, size_t count, byte* buffer) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SyntheticFileSystem();
|
SyntheticFileSystem();
|
||||||
|
|
43
VirtualFileSystem/UnixTypes.h
Normal file
43
VirtualFileSystem/UnixTypes.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
namespace Unix {
|
||||||
|
|
||||||
|
#define SEEK_SET 0
|
||||||
|
#define SEEK_CUR 1
|
||||||
|
#define SEEK_END 2
|
||||||
|
|
||||||
|
typedef dword dev_t;
|
||||||
|
typedef dword ino_t;
|
||||||
|
typedef dword mode_t;
|
||||||
|
typedef dword nlink_t;
|
||||||
|
typedef dword uid_t;
|
||||||
|
typedef dword gid_t;
|
||||||
|
typedef signed_qword off_t;
|
||||||
|
typedef dword blksize_t;
|
||||||
|
typedef dword blkcnt_t;
|
||||||
|
typedef dword time_t;
|
||||||
|
typedef dword size_t;
|
||||||
|
typedef signed_dword ssize_t;
|
||||||
|
|
||||||
|
struct stat {
|
||||||
|
dev_t st_dev; /* ID of device containing file */
|
||||||
|
ino_t st_ino; /* inode number */
|
||||||
|
mode_t st_mode; /* protection */
|
||||||
|
nlink_t st_nlink; /* number of hard links */
|
||||||
|
uid_t st_uid; /* user ID of owner */
|
||||||
|
gid_t st_gid; /* group ID of owner */
|
||||||
|
dev_t st_rdev; /* device ID (if special file) */
|
||||||
|
off_t st_size; /* total size, in bytes */
|
||||||
|
blksize_t st_blksize; /* blocksize for file system I/O */
|
||||||
|
blkcnt_t st_blocks; /* number of 512B blocks allocated */
|
||||||
|
time_t st_atime; /* time of last access */
|
||||||
|
time_t st_mtime; /* time of last modification */
|
||||||
|
time_t st_ctime; /* time of last status change */
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -12,15 +12,15 @@ ZeroDevice::~ZeroDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ZeroDevice::read(byte* buffer, size_t bufferSize)
|
Unix::ssize_t ZeroDevice::read(byte* buffer, Unix::size_t bufferSize)
|
||||||
{
|
{
|
||||||
printf("read from zero device\n");
|
printf("read from zero device\n");
|
||||||
size_t count = min(GoodBufferSize, bufferSize);
|
Unix::size_t count = min(GoodBufferSize, bufferSize);
|
||||||
memset(buffer, 0, count);
|
memset(buffer, 0, count);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ZeroDevice::write(const byte*, size_t bufferSize)
|
Unix::ssize_t ZeroDevice::write(const byte*, Unix::size_t bufferSize)
|
||||||
{
|
{
|
||||||
return min(GoodBufferSize, bufferSize);
|
return min(GoodBufferSize, bufferSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ public:
|
||||||
ZeroDevice();
|
ZeroDevice();
|
||||||
virtual ~ZeroDevice();
|
virtual ~ZeroDevice();
|
||||||
|
|
||||||
ssize_t read(byte* buffer, size_t bufferSize) override;
|
Unix::ssize_t read(byte* buffer, Unix::size_t bufferSize) override;
|
||||||
ssize_t write(const byte* buffer, size_t bufferSize) override;
|
Unix::ssize_t write(const byte* buffer, Unix::size_t bufferSize) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue