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/types.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h>
#include "BlockDevice.h" #include "BlockDevice.h"
#include "BlockCache.h" #include "BlockCache.h"
@ -34,7 +34,7 @@ AbstractBlockCache::~AbstractBlockCache()
MappedBlockCache::MappedBlockCache(void *data, unsigned blocks) MappedBlockCache::MappedBlockCache(void *data, unsigned blocks)
{ {
_blocks = blocks; _blocks = blocks;
_data = (uint8_t *)_data; _data = (uint8_t *)data;
} }
void MappedBlockCache::write() void MappedBlockCache::write()
@ -59,7 +59,14 @@ void MappedBlockCache::unload(unsigned block, bool dirty)
#define __METHOD__ "MappedBlockCache::unload" #define __METHOD__ "MappedBlockCache::unload"
if (!dirty) return; 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); throw POSIXException(__METHOD__ ": msync failed.", errno);
} }

View File

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

View File

@ -41,7 +41,7 @@ namespace LittleEndian {
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; _offset += count;
} }
void writeZero(unsigned count) void writeZero(unsigned count)