*/
extern int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set *ErrHandles, tTime *Timeout, BOOL IsKernel);
+/**
+ * \brief Map a file into memory
+ * \param ErrNo Error status pointer
+ * \param DestHint Suggested place for read data
+ * \param Length Size of area to map
+ * \param Protection Protection type (see `man mmap`)
+ * \param Flags Mapping flags
+ * \param FD File descriptor to load from
+ * \param Offset Start of region
+ */
+extern void *VFS_MMap(int *ErrNo, void *DestHint, size_t Length, int Protection, int Flags, int FD, Uint64 Offset);
+
+/**
+ * \brief Unmap memory allocated by VFS_MMap
+ * \param ErrNo Error status pointer
+ * \param Addr Address of data to unmap
+ * \param Length Length of data
+ */
+extern int VFS_MUnmap(int *ErrNo, void *Addr, size_t Length);
#endif
npages = ((Offset & (PAGE_SIZE-1)) + Length) / PAGE_SIZE;
pagenum = Offset / PAGE_SIZE;
- mapping_dest = DestHint;
+ mapping_dest = (tVAddr)DestHint;
+#if 0
// TODO: Locate space for the allocation
if( Flags & MAP_ANONYMOUS )
{
MM_Allocate(mapping_dest);
return (void*)mapping_dest;
}
+#endif
h = VFS_GetHandle(FD);
if( !h || !h->Node ) return NULL;
prev = pb, pb = pb->Next
);
+ // - Allocate a block if needed
if( !pb || pb->BaseOffset > pagenum )
{
void *old_pb = pb;
- // Allocate if needed
pb = malloc( sizeof(tVFS_MMapPageBlock) );
if(!pb) return NULL;
pb->Next = old_pb;
h->Node->MMapInfo = pb;
}
+ // - Map (and allocate) pages
while( npages -- )
{
if( pb->PhysAddrs[pagenum - pb->BaseOffset] == 0 )
else
{
// Allocate pages and read data
- MM_Allocate(mapping_dest);
+ if( MM_Allocate(mapping_dest) == 0 ) {
+ // TODO: Unwrap
+ return NULL;
+ }
h->Node->Read(h->Node, pagenum*PAGE_SIZE, PAGE_SIZE, (void*)mapping_dest);
}
pb->PhysAddrs[pagenum - pb->BaseOffset] = MM_GetPhysAddr( mapping_dest );
+// MM_SetPageInfo( pb->PhysAddrs[pagenum - pb->BaseOffset], h->Node, pagenum*PAGE_SIZE );
}
else
{