Add tcgetblob support to extfs.
This commit is contained in:
parent
6e8f17b5df
commit
d85f446da9
|
@ -40,10 +40,11 @@ void* Device__SyncThread(void* ctx)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::Device(int fd, uint32_t block_size, bool write)
|
Device::Device(int fd, const char* path, uint32_t block_size, bool write)
|
||||||
{
|
{
|
||||||
this->write = write;
|
this->write = write;
|
||||||
this->fd = fd;
|
this->fd = fd;
|
||||||
|
this->path = path;
|
||||||
this->block_size = block_size;
|
this->block_size = block_size;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
fstat(fd, &st);
|
fstat(fd, &st);
|
||||||
|
|
|
@ -30,7 +30,7 @@ const size_t DEVICE_HASH_LENGTH = 1 << 16;
|
||||||
class Device
|
class Device
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Device(int fd, uint32_t block_size, bool write);
|
Device(int fd, const char* path, uint32_t block_size, bool write);
|
||||||
~Device();
|
~Device();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -43,6 +43,7 @@ public:
|
||||||
Block* dirty_block;
|
Block* dirty_block;
|
||||||
Block* hash_blocks[DEVICE_HASH_LENGTH];
|
Block* hash_blocks[DEVICE_HASH_LENGTH];
|
||||||
off_t device_size;
|
off_t device_size;
|
||||||
|
const char* path;
|
||||||
uint32_t block_size;
|
uint32_t block_size;
|
||||||
int fd;
|
int fd;
|
||||||
bool write;
|
bool write;
|
||||||
|
|
|
@ -371,8 +371,8 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
uint32_t block_size = 1024U << sb.s_log_block_size;
|
uint32_t block_size = 1024U << sb.s_log_block_size;
|
||||||
|
|
||||||
Device* dev = new Device(fd, block_size, write);
|
Device* dev = new Device(fd, device_path, block_size, write);
|
||||||
Filesystem* fs = new Filesystem(dev);
|
Filesystem* fs = new Filesystem(dev, mount_path);
|
||||||
|
|
||||||
fs->block_groups = new BlockGroup*[fs->num_groups];
|
fs->block_groups = new BlockGroup*[fs->num_groups];
|
||||||
for ( size_t i = 0; i < fs->num_groups; i++ )
|
for ( size_t i = 0; i < fs->num_groups; i++ )
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "inode.h"
|
#include "inode.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
Filesystem::Filesystem(Device* device)
|
Filesystem::Filesystem(Device* device, const char* mount_path)
|
||||||
{
|
{
|
||||||
uint64_t sb_offset = 1024;
|
uint64_t sb_offset = 1024;
|
||||||
uint32_t sb_block_id = sb_offset / device->block_size;
|
uint32_t sb_block_id = sb_offset / device->block_size;
|
||||||
|
@ -47,6 +47,7 @@ Filesystem::Filesystem(Device* device)
|
||||||
(sb_block->block_data + sb_offset % device->block_size);
|
(sb_block->block_data + sb_offset % device->block_size);
|
||||||
this->device = device;
|
this->device = device;
|
||||||
block_groups = NULL;
|
block_groups = NULL;
|
||||||
|
this->mount_path = mount_path;
|
||||||
block_size = device->block_size;
|
block_size = device->block_size;
|
||||||
mru_inode = NULL;
|
mru_inode = NULL;
|
||||||
lru_inode = NULL;
|
lru_inode = NULL;
|
||||||
|
|
|
@ -32,7 +32,7 @@ const size_t INODE_HASH_LENGTH = 1 << 16;
|
||||||
class Filesystem
|
class Filesystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Filesystem(Device* device);
|
Filesystem(Device* device, const char* mount_path);
|
||||||
~Filesystem();
|
~Filesystem();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -40,6 +40,7 @@ public:
|
||||||
Block* sb_block;
|
Block* sb_block;
|
||||||
Device* device;
|
Device* device;
|
||||||
BlockGroup** block_groups;
|
BlockGroup** block_groups;
|
||||||
|
const char* mount_path;
|
||||||
uint32_t block_size;
|
uint32_t block_size;
|
||||||
uint32_t inode_size;
|
uint32_t inode_size;
|
||||||
uint32_t num_blocks;
|
uint32_t num_blocks;
|
||||||
|
|
|
@ -150,6 +150,14 @@ bool RespondReadDir(int chl, struct kernel_dirent* dirent)
|
||||||
RespondData(chl, dirent->d_name, dirent->d_namlen);
|
RespondData(chl, dirent->d_name, dirent->d_namlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RespondTCGetBlob(int chl, const void* data, size_t data_size)
|
||||||
|
{
|
||||||
|
struct fsm_resp_tcgetblob body;
|
||||||
|
body.count = data_size;
|
||||||
|
return RespondMessage(chl, FSM_RESP_TCGETBLOB, &body, sizeof(body)) &&
|
||||||
|
RespondData(chl, data, data_size);
|
||||||
|
}
|
||||||
|
|
||||||
void HandleRefer(int chl, struct fsm_req_refer* msg, Filesystem* fs)
|
void HandleRefer(int chl, struct fsm_req_refer* msg, Filesystem* fs)
|
||||||
{
|
{
|
||||||
(void) chl;
|
(void) chl;
|
||||||
|
@ -577,6 +585,35 @@ void HandleRename(int chl, struct fsm_req_rename* msg, Filesystem* fs)
|
||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HandleTCGetBlob(int chl, struct fsm_req_tcgetblob* msg, Filesystem* fs)
|
||||||
|
{
|
||||||
|
if ( fs->num_inodes <= msg->ino )
|
||||||
|
return (void) RespondError(chl, EBADF);
|
||||||
|
|
||||||
|
char* nameraw = (char*) &(msg[1]);
|
||||||
|
char* name = (char*) malloc(msg->namelen + 1);
|
||||||
|
if ( !name )
|
||||||
|
return (void) RespondError(chl, errno);
|
||||||
|
memcpy(name, nameraw, msg->namelen);
|
||||||
|
name[msg->namelen] = '\0';
|
||||||
|
|
||||||
|
static const char index[] = "device-path\0filesystem-type\0filesystem-uuid\0mount-path\0";
|
||||||
|
if ( !strcmp(name, "") )
|
||||||
|
RespondTCGetBlob(chl, index, sizeof(index) - 1);
|
||||||
|
else if ( !strcmp(name, "device-path") )
|
||||||
|
RespondTCGetBlob(chl, fs->device->path, strlen(fs->device->path));
|
||||||
|
else if ( !strcmp(name, "filesystem-type") )
|
||||||
|
RespondTCGetBlob(chl, "ext2", strlen("ext2"));
|
||||||
|
else if ( !strcmp(name, "filesystem-uuid") )
|
||||||
|
RespondTCGetBlob(chl, fs->sb->s_uuid, sizeof(fs->sb->s_uuid));
|
||||||
|
else if ( !strcmp(name, "mount-path") )
|
||||||
|
RespondTCGetBlob(chl, fs->mount_path, strlen(fs->mount_path));
|
||||||
|
else
|
||||||
|
RespondError(chl, ENOENT);
|
||||||
|
|
||||||
|
free(name);
|
||||||
|
}
|
||||||
|
|
||||||
void HandleIncomingMessage(int chl, struct fsm_msg_header* hdr, Filesystem* fs)
|
void HandleIncomingMessage(int chl, struct fsm_msg_header* hdr, Filesystem* fs)
|
||||||
{
|
{
|
||||||
typedef void (*handler_t)(int, void*, Filesystem*);
|
typedef void (*handler_t)(int, void*, Filesystem*);
|
||||||
|
@ -602,6 +639,7 @@ void HandleIncomingMessage(int chl, struct fsm_msg_header* hdr, Filesystem* fs)
|
||||||
handlers[FSM_REQ_RENAME] = (handler_t) HandleRename;
|
handlers[FSM_REQ_RENAME] = (handler_t) HandleRename;
|
||||||
handlers[FSM_REQ_REFER] = (handler_t) HandleRefer;
|
handlers[FSM_REQ_REFER] = (handler_t) HandleRefer;
|
||||||
handlers[FSM_REQ_UNREF] = (handler_t) HandleUnref;
|
handlers[FSM_REQ_UNREF] = (handler_t) HandleUnref;
|
||||||
|
handlers[FSM_REQ_TCGETBLOB] = (handler_t) HandleTCGetBlob;
|
||||||
if ( FSM_MSG_NUM <= hdr->msgtype || !handlers[hdr->msgtype] )
|
if ( FSM_MSG_NUM <= hdr->msgtype || !handlers[hdr->msgtype] )
|
||||||
{
|
{
|
||||||
fprintf(stderr, "extfs: message type %zu not supported!\n", hdr->msgtype);
|
fprintf(stderr, "extfs: message type %zu not supported!\n", hdr->msgtype);
|
||||||
|
@ -682,7 +720,7 @@ int fsmarshall_main(const char* argv0,
|
||||||
size_t amount;
|
size_t amount;
|
||||||
if ( (amount = readall(channel, &hdr, sizeof(hdr))) != sizeof(hdr) )
|
if ( (amount = readall(channel, &hdr, sizeof(hdr))) != sizeof(hdr) )
|
||||||
{
|
{
|
||||||
error(0, errno, "incomplete header: got %zi of %zu bytes", amount, sizeof(hdr));
|
//error(0, errno, "incomplete header: got %zi of %zu bytes", amount, sizeof(hdr));
|
||||||
errno = 0;
|
errno = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue