git-svn-id: https://profuse.googlecode.com/svn/branches/v2@159 aa027e90-d47c-11dd-86d7-074df07e0730

This commit is contained in:
ksherlock 2009-12-12 19:27:08 +00:00
parent 05e13f91a5
commit e8c1af2d2c
4 changed files with 52 additions and 20 deletions

View File

@ -4,7 +4,7 @@
#include <sys/types.h>
#include <sys/mman.h>
#include <unistd.h>
#include "BlockDevice.h"
#include "BlockCache.h"
@ -34,7 +34,7 @@ AbstractBlockCache::~AbstractBlockCache()
MappedBlockCache::MappedBlockCache(void *data, unsigned blocks)
{
_blocks = blocks;
_data = (uint8_t *)_data;
_data = (uint8_t *)data;
}
void MappedBlockCache::write()
@ -59,7 +59,14 @@ void MappedBlockCache::unload(unsigned block, bool dirty)
#define __METHOD__ "MappedBlockCache::unload"
if (!dirty) return;
if (::msync(_data + block * 512, 512, MS_ASYNC) < 0)
// msync must be page-size aligned.
unsigned pagesize = ::getpagesize();
unsigned offset = block * 512;
void *address = _data + offset / pagesize * pagesize;
unsigned length = offset % pagesize + 512;
if (::msync(address, length, MS_ASYNC) < 0)
{
throw POSIXException(__METHOD__ ": msync failed.", errno);
}

View File

@ -1,6 +1,5 @@
#include "Date.h"
#include <cstring>
#include <stdint.h>
using namespace Pascal;
@ -41,5 +40,5 @@ Date Date::Today()
::localtime_r(&t, &tm);
return Date(tm.tm_year, tm.tm_mon, tm.tm_mday);
return Date(tm.tm_year, tm.tm_mon + 1, tm.tm_mday);
}

View File

@ -9,11 +9,13 @@
#include <algorithm>
#include <cstring>
#include <cctype.h>
#include <memory>
using namespace LittleEndian;
using namespace Pascal;
/*
static bool isalpha(char c)
{
return (c >= 'A' && c <= 'Z')
@ -37,7 +39,7 @@ static bool islower(char c)
inline char tolower(char c) { return c | 0x20; }
inline char toupper(char c) { return c & ~0x20; }
*/
#pragma mark -
@ -45,23 +47,42 @@ inline char toupper(char c) { return c & ~0x20; }
unsigned Entry::ValidName(const char *cp, unsigned maxLength)
{
unsigned length;
// any printable char except:
// white space
// $ = ? , (file only)
// : (volume only)
if (!cp || !*cp) return 0;
if (!isalpha(*cp)) return 0;
for (length = 1; cp[length]; ++length)
for (unsigned i = 0; ; ++i)
{
if (length >= maxLength) return 0;
if (!isalnumdot(cp[length])) return 0;
}
unsigned c = cp[i];
if (c == 0) return i - 1;
if (i > maxLength) return 0;
return length;
switch(c)
{
case ':':
if (maxLength == 7) return 0;
break;
case '$':
case '=':
case ',':
case '?':
if (maxLength == 15) return 0;
break;
default:
if (!std::isascii(c)) return 0;
if (!std::isgraph(c)) return 0;
}
}
}
Entry::Entry()
{
_firstBlock = 0;
@ -103,6 +124,10 @@ void Entry::writeDirectoryEntry(IOBuffer *b)
unsigned VolumeEntry::ValidName(const char *cp)
{
// 7 chars max. Legal values: ascii, printable,
// no space/tab,
// no $=?,:
return Entry::ValidName(cp, 7);
}
@ -132,7 +157,7 @@ VolumeEntry::VolumeEntry(const char *name, ProFUSE::BlockDevice *device)
if (!length)
throw ProFUSE::Exception(__METHOD__ ": Invalid volume name.");
_firstBlock = 2;
_firstBlock = 0;
_lastBlock = 6;
_fileKind = kUntypedFile;
_inode = 1;
@ -143,7 +168,7 @@ VolumeEntry::VolumeEntry(const char *name, ProFUSE::BlockDevice *device)
std::memset(_fileName, 0, sizeof(_fileName));
for (unsigned i = 0; i < _fileNameLength; ++i)
{
_fileName[i] = toupper(name[i]);
_fileName[i] = std::toupper(name[i]);
}
_lastVolumeBlock = device->blocks();
@ -301,6 +326,7 @@ void VolumeEntry::writeDirectoryEntry(IOBuffer *b)
b->write8(0); // reserved
b->write8(_fileNameLength);
b->writeBytes(_fileName, 7);
b->write16(_lastVolumeBlock);
b->write16(_fileCount);
b->write16(_accessTime);
b->write16(_lastBoot);
@ -347,7 +373,7 @@ FileEntry::FileEntry(const char *name, unsigned fileKind)
_fileNameLength = length;
std::memset(_fileName, 0, sizeof(_fileName));
for (unsigned i = 0; i < length; ++i)
_fileName[i] = toupper(name[i]);
_fileName[i] = std::toupper(name[i]);
_modification = Date::Today();
_lastByte = 0;

View File

@ -41,7 +41,7 @@ namespace LittleEndian {
void writeBytes(const void *value, unsigned count)
{
std::memcpy(_offset + (uint8_t *)_buffer, value, count);
_size += count;
_offset += count;
}
void writeZero(unsigned count)