简体   繁体   English

虚拟文件系统内存块创建

[英]Virtual File System Memory Block Creation

I'm working on a project where I need to create all the basic components for a virtual file system(memory blocks, filename table, inodes, etc). 我正在一个项目中,我需要为虚拟文件系统创建所有基本组件(内存块,文件名表,inode等)。 My system needs to be able to make a single-layer(no sub directories) "disk" which is composed of fixed memory blocks(in this case 256 bytes). 我的系统需要能够制作一个由固定内存块(在这种情况下为256字节)组成的单层(无子目录)“磁盘”。 I understand all the basic components and their functions as far as using the file system, but I'm unsure of how to start making blocks of memory for allocation. 就使用文件系统而言,我了解所有基本组件及其功能,但是我不确定如何开始创建用于分配的内存块。 I don't have a structure designed yet for the inodes or the file table(I am required to come up with my own) but I believe I have the basic memory allocation set for making a "disk" where I can then format and add the subsequent data structures: 我还没有为inode或文件表设计的结构(我需要提供自己的结构),但是我相信我有基本的内存分配集来制作“磁盘”,然后可以对其进行格式化和添加后续数据结构:

int make_disk(char const *name)
{
    int c, dex;
    char buff[BLOKSIZE];

    if(!name)
    {
        fprintf(stderr, "Make: Invalid Name\n");
        return -1;
    }
    if((c=open(name, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) 
    {
        perror("Cannot Open File\n");
        return -1;  
    }

    memset(buff, 0, BLOKSIZE);
    for(dex=0;dex<NUMBLOKS;dex++)
    {
        write(c, buff, BLOKSIZE);
    }

    close(c);
    return 0;

}

My main question is am I on the right track as far as correctly allocating 256-byte memory blocks that will be used for file storage and metadata storage once this "disk" is properly partitioned? 我的主要问题是,是否正确分配了256字节的内存块,一旦正确地对“磁盘”进行了分区,这些内存块将用于文件存储和元数据存储?

最好的选择是使用内存映射文件作为虚拟磁盘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM