mirror of
https://github.com/ksherlock/profuse.git
synced 2025-02-20 16:28:56 +00:00
git-svn-id: https://profuse.googlecode.com/svn/branches/v2@153 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
parent
e3ef4d7c10
commit
05e13f91a5
@ -1,5 +1,6 @@
|
|||||||
#include "Date.h"
|
#include "Date.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
using namespace Pascal;
|
using namespace Pascal;
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ Date::operator std::time_t() const {
|
|||||||
return std::mktime(&tm);
|
return std::mktime(&tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
Date::operator unsigned() const {
|
Date::operator uint16_t() const {
|
||||||
// year must be 0 .. 127
|
// year must be 0 .. 127
|
||||||
return (_year << 9) | (_day << 4) | _month;
|
return (_year << 9) | (_day << 4) | _month;
|
||||||
}
|
}
|
||||||
@ -40,5 +41,5 @@ Date Date::Today()
|
|||||||
|
|
||||||
::localtime_r(&t, &tm);
|
::localtime_r(&t, &tm);
|
||||||
|
|
||||||
return Date(tm.tm_year, tm.tm_month, tm.tm_mday);
|
return Date(tm.tm_year, tm.tm_mon, tm.tm_mday);
|
||||||
}
|
}
|
@ -2,6 +2,7 @@
|
|||||||
#define __PASCAL_DATE_H__
|
#define __PASCAL_DATE_H__
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace Pascal {
|
namespace Pascal {
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ public:
|
|||||||
Date(unsigned);
|
Date(unsigned);
|
||||||
|
|
||||||
operator std::time_t() const;
|
operator std::time_t() const;
|
||||||
operator unsigned() const;
|
operator uint16_t() const;
|
||||||
|
|
||||||
unsigned month() const { return _month; }
|
unsigned month() const { return _month; }
|
||||||
unsigned day() const { return _day; }
|
unsigned day() const { return _day; }
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "../Endian.h"
|
#include "../Endian.h"
|
||||||
#include "../BlockDevice.h"
|
#include "../BlockDevice.h"
|
||||||
#include "../BlockCache.h"
|
#include "../BlockCache.h"
|
||||||
|
#include "../Exception.h"
|
||||||
|
|
||||||
#include "IOBuffer.h"
|
#include "IOBuffer.h"
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ unsigned Entry::ValidName(const char *cp, unsigned maxLength)
|
|||||||
|
|
||||||
if (!cp || !*cp) return 0;
|
if (!cp || !*cp) return 0;
|
||||||
|
|
||||||
if (!isalpaha(*cp)) return 0;
|
if (!isalpha(*cp)) return 0;
|
||||||
|
|
||||||
for (length = 1; cp[length]; ++length)
|
for (length = 1; cp[length]; ++length)
|
||||||
{
|
{
|
||||||
@ -129,7 +130,7 @@ VolumeEntry::VolumeEntry(const char *name, ProFUSE::BlockDevice *device)
|
|||||||
length = ValidName(name);
|
length = ValidName(name);
|
||||||
|
|
||||||
if (!length)
|
if (!length)
|
||||||
throw Exception(__METHOD__ ": Invalid volume name.");
|
throw ProFUSE::Exception(__METHOD__ ": Invalid volume name.");
|
||||||
|
|
||||||
_firstBlock = 2;
|
_firstBlock = 2;
|
||||||
_lastBlock = 6;
|
_lastBlock = 6;
|
||||||
@ -148,7 +149,7 @@ VolumeEntry::VolumeEntry(const char *name, ProFUSE::BlockDevice *device)
|
|||||||
_lastVolumeBlock = device->blocks();
|
_lastVolumeBlock = device->blocks();
|
||||||
_fileCount = 0;
|
_fileCount = 0;
|
||||||
_accessTime = 0;
|
_accessTime = 0;
|
||||||
_lastBoot = Date.Today();
|
_lastBoot = Date::Today();
|
||||||
|
|
||||||
_cache = device->blockCache();
|
_cache = device->blockCache();
|
||||||
_device = device;
|
_device = device;
|
||||||
@ -158,12 +159,12 @@ VolumeEntry::VolumeEntry(const char *name, ProFUSE::BlockDevice *device)
|
|||||||
device->zeroBlock(i);
|
device->zeroBlock(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *vp = _blockCache->lock(2);
|
void *vp = _cache->load(2);
|
||||||
IOBuffer b(vp, 0x1a);
|
IOBuffer b(vp, 0x1a);
|
||||||
|
|
||||||
write(&b);
|
writeDirectoryEntry(&b);
|
||||||
|
|
||||||
_blockCache->unlock(2, true);
|
_cache->unload(2, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +303,7 @@ void VolumeEntry::writeDirectoryEntry(IOBuffer *b)
|
|||||||
b->writeBytes(_fileName, 7);
|
b->writeBytes(_fileName, 7);
|
||||||
b->write16(_fileCount);
|
b->write16(_fileCount);
|
||||||
b->write16(_accessTime);
|
b->write16(_accessTime);
|
||||||
b->write16((unsigned)_lastBoot);
|
b->write16(_lastBoot);
|
||||||
|
|
||||||
// rest is reserved.
|
// rest is reserved.
|
||||||
b->writeZero(4);
|
b->writeZero(4);
|
||||||
@ -338,9 +339,9 @@ FileEntry::FileEntry(const char *name, unsigned fileKind)
|
|||||||
unsigned length = ValidName(name);
|
unsigned length = ValidName(name);
|
||||||
|
|
||||||
if (!length)
|
if (!length)
|
||||||
throw Exception(__METHOD__ ": Invalid file name.");
|
throw ProFUSE::Exception(__METHOD__ ": Invalid file name.");
|
||||||
|
|
||||||
_fileKind = kind;
|
_fileKind = fileKind;
|
||||||
_status = 0;
|
_status = 0;
|
||||||
|
|
||||||
_fileNameLength = length;
|
_fileNameLength = length;
|
||||||
|
@ -53,7 +53,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
unsigned static ValidName(const char *name, unsigned maxSize);
|
static unsigned ValidName(const char *name, unsigned maxSize);
|
||||||
|
|
||||||
virtual void writeDirectoryEntry(LittleEndian::IOBuffer *);
|
virtual void writeDirectoryEntry(LittleEndian::IOBuffer *);
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ public:
|
|||||||
void writeBlock(unsigned block, void *);
|
void writeBlock(unsigned block, void *);
|
||||||
|
|
||||||
|
|
||||||
static ValidName(const char *);
|
unsigned static ValidName(const char *);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void writeDirectoryEntry(LittleEndian::IOBuffer *);
|
virtual void writeDirectoryEntry(LittleEndian::IOBuffer *);
|
||||||
@ -146,7 +146,7 @@ class FileEntry : public Entry {
|
|||||||
const char *name() const { return _fileName; }
|
const char *name() const { return _fileName; }
|
||||||
Date modification() const { return _modification; }
|
Date modification() const { return _modification; }
|
||||||
|
|
||||||
static ValidName(const char *);
|
unsigned static ValidName(const char *);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "../Endian.h"
|
#include "../Endian.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
namespace LittleEndian {
|
namespace LittleEndian {
|
||||||
|
|
||||||
class IOBuffer {
|
class IOBuffer {
|
||||||
@ -37,7 +38,7 @@ namespace LittleEndian {
|
|||||||
_offset += 4;
|
_offset += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeBytes(const void *value, unsigned count);
|
void writeBytes(const void *value, unsigned count)
|
||||||
{
|
{
|
||||||
std::memcpy(_offset + (uint8_t *)_buffer, value, count);
|
std::memcpy(_offset + (uint8_t *)_buffer, value, count);
|
||||||
_size += count;
|
_size += count;
|
||||||
@ -56,7 +57,7 @@ namespace LittleEndian {
|
|||||||
unsigned offset() const { return _offset; }
|
unsigned offset() const { return _offset; }
|
||||||
void setOffset(unsigned offset) { _offset = offset; }
|
void setOffset(unsigned offset) { _offset = offset; }
|
||||||
|
|
||||||
unsinged size() const { return _size; }
|
unsigned size() const { return _size; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void *_buffer;
|
void *_buffer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user