Esempio n. 1
0
        private void boot()
        {
            Stream stream = new FileStream("block.dat", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);

            if (0 == stream.Length)
            {
                superBlock superblock = new superBlock(1024, 4096);
                dataBlock  block      = new dataBlock();
                block.data   = superblock;
                datablock[0] = block;
                initBoot();
                ((blockBitmap)datablock[2].data).findUnuse(1);
            }

            inode      root = new inode();
            List <int> b    = new List <int>();

            b.Add(4);
            root.init(0, b, "文件夹", DateTime.Now);
            ((inode[])datablock[3].data)[0] = root;
            dataBlock data = new dataBlock();

            ((blockBitmap)datablock[2].data).findUnuse(4);
            List <int> nodes = ((inodeBitmap)datablock[1].data).findUnuse(1);



            datablock[4] = new dataBlock();
            datablock[4].createInode("..", -1);
            datablock[4].createInode(".", nodes[0]);
            IOFormatter.getInstance().Serialize(IOStream.getInstance(), datablock);
        }
Esempio n. 2
0
        public Boolean saveFile(string content)
        {
            int num = node[selectedFile].getBlockNum();       //获取文件已有磁盘块数目

            byte[] buffer = Encoding.Default.GetBytes(content);
            int    n      = buffer.Length / 100; //计算所需磁盘块
            int    offset = buffer.Length % 100;

            if (n > 13)
            {
                return(false);
            }
            List <int> mem;

            if (offset > 0)
            {
                mem = blockMap.findUnuse(n + 1 - num);
            }
            else
            {
                mem = blockMap.findUnuse(n - num);
            }
            if (mem == null && n - num > 0)      //需要新块但找不到空的磁盘块
            {
                return(false);
            }
            for (int i = 0; i <= n; i++)
            {
                string con;
                if (i < n)
                {
                    con = Encoding.Default.GetString(buffer, 100 * i, 100);
                }
                else
                {
                    con = Encoding.Default.GetString(buffer, 100 * i, offset);
                }
                if (node[selectedFile].getBlock(i) == 0)
                {
                    if (datablock[mem[0]] == null)
                    {
                        datablock[mem[0]] = new dataBlock();
                    }
                    node[selectedFile].setBlock(mem[0], i); //为文件分配新的磁盘块
                    datablock[mem[0]].data = con;           //存储信息
                    mem.RemoveAt(0);
                }
                else
                {
                    datablock[node[selectedFile].getBlock(i)].data = con;
                }
            }
            node[selectedFile].setTime(DateTime.Now);
            IOFormatter.getInstance().Serialize(IOStream.getInstance(), datablock);
            listItems(workDir);
            return(true);
        }
Esempio n. 3
0
        public Boolean createEntry(string type, string _name)        //创建新的文件
        {
            int   parent = -1;
            inode _node  = null;

            if (_name != null)                                                  //点击文件夹创建
            {
                parent = datablock[node[workDir].getBlock(0)].findInode(_name); //选中文件夹为父目录
            }
            else                                                                //直接新建
            {
                parent = workDir;                                               //当前目录为父目录
            }

            _node = node[parent];
            List <int> nodeLoc  = nodeMap.findUnuse(1);    //找到未使用的inode节点
            List <int> blockLoc = blockMap.findUnuse(1);   //找到空闲磁盘块


            if (nodeLoc == null || blockLoc == null)        //inodeMap或blockMap用尽
            {
                return(false);
            }


            if (datablock[blockLoc[0]] == null)     //磁盘块未初始化
            {
                datablock[blockLoc[0]] = new dataBlock();
                if (type == "文件夹")
                {
                    initDir(blockLoc[0], parent, nodeLoc[0]);
                }
            }
            if (node[nodeLoc[0]] == null)       //inode为初始化
            {
                node[nodeLoc[0]] = new inode();
            }
            string name = "新建" + type;

            name = datablock[_node.getBlock(0)].createInode(name, nodeLoc[0]);
            if (_name == null)
            {
                setViewItem(name, type, 0, DateTime.Now);
            }
            node[nodeLoc[0]].init(nodeLoc[0], blockLoc, type, DateTime.Now);
            IOFormatter.getInstance().Serialize(IOStream.getInstance(), datablock);
            return(true);
        }
Esempio n. 4
0
        private void initBoot()
        {
            superBlock superblock = (superBlock)datablock[0].data;

            inode[]     node     = new inode[superblock.nodeNum];
            blockBitmap blockMap = new blockBitmap(superblock.blockNum);
            inodeBitmap nodeMap  = new inodeBitmap(superblock.nodeNum);

            datablock[1]      = new dataBlock();
            datablock[1].data = nodeMap;

            datablock[2]      = new dataBlock();
            datablock[2].data = blockMap;

            datablock[3]      = new dataBlock();
            datablock[3].data = node;
        }
Esempio n. 5
0
        public List <int> getRequireBlocks(int num)
        {
            List <int> blocks = ((blockBitmap)datablock[2].data).findUnuse(num);

            if (blocks == null)
            {
                return(null);
            }
            for (int i = 0; i < blocks.Count; i++)
            {
                if (datablock[blocks[i]] == null)
                {
                    datablock[blocks[i]] = new dataBlock();
                }
            }
            return(blocks);
        }
Esempio n. 6
0
        private void initBoot()
        {
            Stream stream = new FileStream("super.dat", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);

            if (0 == stream.Length)
            {
                superBlock superblock = new superBlock(1024, 4096);
                dataBlock  boot       = new dataBlock();
                boot.data = superblock;
                datablock = new dataBlock[4096];
                node      = new inode[1024];
                blockMap.findUnuse(1);
                datablock[0] = boot;
            }
            inode      root = new inode();
            List <int> b    = new List <int>();

            b.Add(4);
            root.init(0, b, "文件夹", DateTime.Now);
            node[0] = root;
            dataBlock data = new dataBlock();

            blockMap.findUnuse(4);
            List <int> nodes = nodeMap.findUnuse(1);

            datablock[1]      = new dataBlock();
            datablock[1].data = nodeMap;

            datablock[2]      = new dataBlock();
            datablock[2].data = blockMap;

            datablock[3]      = new dataBlock();
            datablock[3].data = node;

            datablock[4] = new dataBlock();
            initDir(4, -1, nodes[0]);
            IOFormatter.getInstance().Serialize(IOStream.getInstance(), datablock);
        }