21 #include "modules/Module.h" 22 #include "modules/system/vfs/VFS.h" 23 #include "pedigree/kernel/LockGuard.h" 24 #include "pedigree/kernel/Log.h" 25 #include "pedigree/kernel/Service.h" 26 #include "pedigree/kernel/ServiceFeatures.h" 27 #include "pedigree/kernel/ServiceManager.h" 28 #include "pedigree/kernel/utilities/assert.h" 30 FileDisk::FileDisk(
String file, AccessType mode)
31 : m_pFile(0), m_Mode(mode), m_Cache(), m_MemRegion(
"FileDisk"),
32 m_ReqMutex(false), m_nAlignPoints(0)
36 WARNING(
"FileDisk: '" << file <<
"' doesn't exist...");
39 m_pFile->increaseRefCount(
false);
47 NOTICE(
"Asking if the partition provider supports touch");
50 NOTICE(
"It does, attempting to inform the partitioner of our " 56 reinterpret_cast<void *>(static_cast<Disk *>(
this)),
57 sizeof(*static_cast<Disk *>(
this))))
65 ERROR(
"FileDisk: Couldn't tell the partition service about the " 70 "FileDisk: Partition service doesn't appear to support touch");
76 m_pFile->decreaseRefCount(
false);
79 bool FileDisk::initialise()
81 return (m_pFile != 0);
89 FATAL(
"Read with location % 512.");
95 uint64_t alignPoint = 0;
96 for (
size_t i = 0; i < m_nAlignPoints; i++)
97 if (m_AlignPoints[i] <= location && m_AlignPoints[i] > alignPoint)
98 alignPoint = m_AlignPoints[i];
102 uint64_t readPage = ((location - alignPoint) & ~0xFFFUL) + alignPoint;
103 uint64_t pageOffset = (location - alignPoint) % 4096;
105 uintptr_t buffer = m_Cache.lookup(readPage);
108 return buffer + pageOffset;
110 buffer = m_Cache.insert(readPage);
113 m_pFile->read(readPage, 4096, buffer);
115 m_Cache.markNoLongerEditing(readPage);
117 return buffer + pageOffset;
131 assert(m_nAlignPoints < 8);
132 m_AlignPoints[m_nAlignPoints++] = location;
140 static void destroy()
144 MODULE_INFO(
"lodisk", &init, &destroy,
"vfs");
File * find(const String &path, File *pStartNode=0)
virtual uintptr_t read(uint64_t location)
virtual void write(uint64_t location)
virtual bool provides(Type service)
Service * getService(const String &serviceName)
virtual bool serve(ServiceFeatures::Type type, void *pData, size_t dataLen)=0
virtual void align(uint64_t location)
Sets the page boundary alignment after a specific location on the disk.
ServiceFeatures * enumerateOperations(const String &serviceName)