diff --git a/ext/device.cpp b/ext/device.cpp index ed7426ef..cfcc6381 100644 --- a/ext/device.cpp +++ b/ext/device.cpp @@ -40,10 +40,11 @@ void* Device__SyncThread(void* ctx) 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->fd = fd; + this->path = path; this->block_size = block_size; struct stat st; fstat(fd, &st); diff --git a/ext/device.h b/ext/device.h index 69a21856..75c7d370 100644 --- a/ext/device.h +++ b/ext/device.h @@ -30,7 +30,7 @@ const size_t DEVICE_HASH_LENGTH = 1 << 16; class Device { public: - Device(int fd, uint32_t block_size, bool write); + Device(int fd, const char* path, uint32_t block_size, bool write); ~Device(); public: @@ -43,6 +43,7 @@ public: Block* dirty_block; Block* hash_blocks[DEVICE_HASH_LENGTH]; off_t device_size; + const char* path; uint32_t block_size; int fd; bool write; diff --git a/ext/extfs.cpp b/ext/extfs.cpp index c5d3daad..4a77f1c2 100644 --- a/ext/extfs.cpp +++ b/ext/extfs.cpp @@ -371,8 +371,8 @@ int main(int argc, char* argv[]) uint32_t block_size = 1024U << sb.s_log_block_size; - Device* dev = new Device(fd, block_size, write); - Filesystem* fs = new Filesystem(dev); + Device* dev = new Device(fd, device_path, block_size, write); + Filesystem* fs = new Filesystem(dev, mount_path); fs->block_groups = new BlockGroup*[fs->num_groups]; for ( size_t i = 0; i < fs->num_groups; i++ ) diff --git a/ext/filesystem.cpp b/ext/filesystem.cpp index 180ff81d..d6f68e85 100644 --- a/ext/filesystem.cpp +++ b/ext/filesystem.cpp @@ -38,7 +38,7 @@ #include "inode.h" #include "util.h" -Filesystem::Filesystem(Device* device) +Filesystem::Filesystem(Device* device, const char* mount_path) { uint64_t sb_offset = 1024; 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); this->device = device; block_groups = NULL; + this->mount_path = mount_path; block_size = device->block_size; mru_inode = NULL; lru_inode = NULL; diff --git a/ext/filesystem.h b/ext/filesystem.h index 071f2106..2056dc05 100644 --- a/ext/filesystem.h +++ b/ext/filesystem.h @@ -32,7 +32,7 @@ const size_t INODE_HASH_LENGTH = 1 << 16; class Filesystem { public: - Filesystem(Device* device); + Filesystem(Device* device, const char* mount_path); ~Filesystem(); public: @@ -40,6 +40,7 @@ public: Block* sb_block; Device* device; BlockGroup** block_groups; + const char* mount_path; uint32_t block_size; uint32_t inode_size; uint32_t num_blocks; diff --git a/ext/fsmarshall.cpp b/ext/fsmarshall.cpp index 9afc30c0..a1d3396a 100644 --- a/ext/fsmarshall.cpp +++ b/ext/fsmarshall.cpp @@ -150,6 +150,14 @@ bool RespondReadDir(int chl, struct kernel_dirent* dirent) 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) chl; @@ -577,6 +585,35 @@ void HandleRename(int chl, struct fsm_req_rename* msg, Filesystem* fs) 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) { 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_REFER] = (handler_t) HandleRefer; handlers[FSM_REQ_UNREF] = (handler_t) HandleUnref; + handlers[FSM_REQ_TCGETBLOB] = (handler_t) HandleTCGetBlob; if ( FSM_MSG_NUM <= hdr->msgtype || !handlers[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; 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; continue; }