Start of a file map disk driver for the bootloader.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26911 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008, François Revol <[email protected]>.
|
||||||
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _BOOT_FILE_MAP_DISK_H
|
||||||
|
#define _BOOT_FILE_MAP_DISK_H
|
||||||
|
|
||||||
|
#include <boot/vfs.h>
|
||||||
|
#include <boot/partitions.h>
|
||||||
|
|
||||||
|
#define FMAP_FOLDER_NAME "BEOS"
|
||||||
|
#define FMAP_IMAGE_NAME "IMAGE.BE"
|
||||||
|
//#define FMAP_FOLDER_NAME "HAIKU"
|
||||||
|
//#define FMAP_IMAGE_NAME "IMAGE.BFS"
|
||||||
|
|
||||||
|
#define FMAP_MAX_RUNS 128
|
||||||
|
|
||||||
|
struct file_map_run {
|
||||||
|
off_t offset;
|
||||||
|
off_t block;
|
||||||
|
off_t len;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FileMap {
|
||||||
|
public:
|
||||||
|
FileMap();
|
||||||
|
~FileMap();
|
||||||
|
void AddRun(off_t offset, off_t block, off_t len);
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct file_map_run fRuns[FMAP_MAX_RUNS];
|
||||||
|
};
|
||||||
|
|
||||||
|
class FileMapDisk : public Node {
|
||||||
|
public:
|
||||||
|
FileMapDisk();
|
||||||
|
virtual ~FileMapDisk();
|
||||||
|
|
||||||
|
status_t Init(Node *node/*Partition *partition, FileMap *map, off_t imageSize*/);
|
||||||
|
|
||||||
|
virtual status_t Open(void **_cookie, int mode);
|
||||||
|
virtual status_t Close(void *cookie);
|
||||||
|
|
||||||
|
|
||||||
|
virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer,
|
||||||
|
size_t bufferSize);
|
||||||
|
virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer,
|
||||||
|
size_t bufferSize);
|
||||||
|
|
||||||
|
virtual status_t GetName(char *nameBuffer, size_t bufferSize) const;
|
||||||
|
virtual off_t Size() const;
|
||||||
|
|
||||||
|
status_t GetFileMap(FileMap **map);
|
||||||
|
|
||||||
|
static FileMapDisk *FindAnyFileMapDisk(Directory *volume);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Node *fNode;
|
||||||
|
/*
|
||||||
|
Partition *fPartition;
|
||||||
|
FileMap *fMap;
|
||||||
|
off_t fImageSize;
|
||||||
|
*/
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _BOOT_FILE_MAP_DISK_H
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2005, Ingo Weinhold <[email protected]>.
|
||||||
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <boot/FileMapDisk.h>
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
|
#include <endian.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <OS.h>
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
FileMapDisk::FileMapDisk()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
FileMapDisk::~FileMapDisk()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init
|
||||||
|
status_t
|
||||||
|
FileMapDisk::Init(Node *node/*, Partition *partition, FileMap *map, off_t imageSize*/)
|
||||||
|
{
|
||||||
|
fNode = node;
|
||||||
|
/*
|
||||||
|
fPartition = partition;
|
||||||
|
fMap = map;
|
||||||
|
fImageSize = imageSize;
|
||||||
|
|
||||||
|
// create and bind socket
|
||||||
|
fSocket = new(nothrow) UDPSocket;
|
||||||
|
if (!fSocket)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
status_t error = fSocket->Bind(INADDR_ANY, 6666);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
*/
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
FileMapDisk::Open(void **_cookie, int mode)
|
||||||
|
{
|
||||||
|
if (!fNode)
|
||||||
|
return B_NO_INIT;
|
||||||
|
|
||||||
|
return fNode->Open(_cookie, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
FileMapDisk::Close(void *cookie)
|
||||||
|
{
|
||||||
|
if (!fNode)
|
||||||
|
return B_NO_INIT;
|
||||||
|
|
||||||
|
return fNode->Close(cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ReadAt
|
||||||
|
ssize_t
|
||||||
|
FileMapDisk::ReadAt(void *cookie, off_t pos, void *_buffer,
|
||||||
|
size_t bufferSize)
|
||||||
|
{
|
||||||
|
if (!fNode)
|
||||||
|
return B_NO_INIT;
|
||||||
|
|
||||||
|
return fNode->ReadAt(cookie, pos, _buffer, bufferSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// WriteAt
|
||||||
|
ssize_t
|
||||||
|
FileMapDisk::WriteAt(void */*cookie*/, off_t pos, const void *buffer,
|
||||||
|
size_t bufferSize)
|
||||||
|
{
|
||||||
|
// Not needed in the boot loader.
|
||||||
|
return B_PERMISSION_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName
|
||||||
|
status_t
|
||||||
|
FileMapDisk::GetName(char *nameBuffer, size_t bufferSize) const
|
||||||
|
{
|
||||||
|
const char *prefix = "FileMapDisk:";
|
||||||
|
if (!nameBuffer)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
snprintf(nameBuffer, bufferSize, prefix);
|
||||||
|
if (bufferSize > strlen(prefix) && fNode)
|
||||||
|
return fNode->GetName(nameBuffer + strlen(prefix),
|
||||||
|
bufferSize - strlen(prefix));
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size
|
||||||
|
off_t
|
||||||
|
FileMapDisk::Size() const
|
||||||
|
{
|
||||||
|
if (!fNode)
|
||||||
|
return B_NO_INIT;
|
||||||
|
return fNode->Size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
FileMapDisk::GetFileMap(FileMap **map)
|
||||||
|
{
|
||||||
|
return ENOSYS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// FindAnyFileMapDisk
|
||||||
|
FileMapDisk *
|
||||||
|
FileMapDisk::FindAnyFileMapDisk(Directory *volume)
|
||||||
|
{
|
||||||
|
Node *node;
|
||||||
|
status_t error;
|
||||||
|
|
||||||
|
if (!volume)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
node = volume->Lookup(FMAP_FOLDER_NAME "/" FMAP_IMAGE_NAME, true);
|
||||||
|
if (!node)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// create a FileMapDisk object
|
||||||
|
FileMapDisk *disk = new(nothrow) FileMapDisk;
|
||||||
|
if (disk) {
|
||||||
|
error = disk->Init(node);
|
||||||
|
if (error != B_OK) {
|
||||||
|
delete disk;
|
||||||
|
disk = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return disk;
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@ UsePrivateHeaders shared storage ;
|
|||||||
KernelStaticLibrary boot_loader :
|
KernelStaticLibrary boot_loader :
|
||||||
main.cpp
|
main.cpp
|
||||||
vfs.cpp
|
vfs.cpp
|
||||||
|
FileMapDisk.cpp
|
||||||
RootFileSystem.cpp
|
RootFileSystem.cpp
|
||||||
partitions.cpp
|
partitions.cpp
|
||||||
heap.cpp
|
heap.cpp
|
||||||
|
|||||||
Reference in New Issue
Block a user