From e8c1af2d2c1f51c301e368b6d975fb05e7fe4a17 Mon Sep 17 00:00:00 2001 From: ksherlock Date: Sat, 12 Dec 2009 19:27:08 +0000 Subject: [PATCH] git-svn-id: https://profuse.googlecode.com/svn/branches/v2@159 aa027e90-d47c-11dd-86d7-074df07e0730 --- BlockCache.cpp | 13 +++++++++--- pascal/Date.cpp | 3 +-- pascal/File.cpp | 54 +++++++++++++++++++++++++++++++++++------------ pascal/IOBuffer.h | 2 +- 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/BlockCache.cpp b/BlockCache.cpp index f2a955a..8971383 100644 --- a/BlockCache.cpp +++ b/BlockCache.cpp @@ -4,7 +4,7 @@ #include #include - +#include #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); } diff --git a/pascal/Date.cpp b/pascal/Date.cpp index 5ccb29d..fa30630 100644 --- a/pascal/Date.cpp +++ b/pascal/Date.cpp @@ -1,6 +1,5 @@ #include "Date.h" #include -#include 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); } \ No newline at end of file diff --git a/pascal/File.cpp b/pascal/File.cpp index adea791..44a98a1 100644 --- a/pascal/File.cpp +++ b/pascal/File.cpp @@ -9,11 +9,13 @@ #include #include +#include #include 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; diff --git a/pascal/IOBuffer.h b/pascal/IOBuffer.h index ea3991e..a923e0e 100644 --- a/pascal/IOBuffer.h +++ b/pascal/IOBuffer.h @@ -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)