コード例 #1
0
        public void removeFile(string name, inode n, int index)
        {
            inode _node = null;

            if (n == null)
            {
                _node = node[workDir];
                listView.Items.RemoveAt(index);
            }
            else
            {
                _node = n;
            }
            int id = datablock[_node.getBlock(0)].removeInode(name);      //找到删除文件的inode

            _node = node[id];
            for (int i = 0;; i++)       //释放inodetable中信息
            {
                string _name = datablock[_node.getBlock(0)].findInode(0);
                if (_name != null)
                {
                    removeFile(_name, node[id], -1);
                }
                else
                {
                    break;
                }
            }
            List <int> b = _node.getBlockPtr().ToList <int>(); //获得该节点占用的全部块

            blockMap.release(b);                               //释放块位图
            nodeMap.release(id);                               //释放节点位图
            IOFormatter.getInstance().Serialize(IOStream.getInstance(), datablock);
        }
コード例 #2
0
        private void listItems(int _index)          //列出文件夹下的文件
        {
            listView.Items.Clear();
            inode _node = node[_index];

            for (int i = 0; ; i++)
            {
                string _name = datablock[_node.getBlock(0)].findInode(i);
                if (_name == null)
                {
                    break;
                }

                if (_name.Equals("..") || _name.Equals("."))
                {
                    continue;
                }
                int      size = -1;
                string   type = node[datablock[_node.getBlock(0)].findInode(_name)].getType();
                DateTime time = node[datablock[_node.getBlock(0)].findInode(_name)].getTime();
                if (type.Equals("文件"))
                {
                    size = calculate(_node, _name);
                }
                setViewItem(_name, type, size, time);
            }
        }
コード例 #3
0
        public void reNameFile(string newName, int _index)       //重命名文件
        {
            inode _node = node[workDir];

            datablock[_node.getBlock(0)].reNameInode(newName, _index);      //在父目录的inodetable中进行修改
            IOFormatter.getInstance().Serialize(IOStream.getInstance(), datablock);
        }
コード例 #4
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);
        }
コード例 #5
0
        public Boolean reDirectCatalog(string name)     //切换文件目录或打开文件
        {
            inode _node = node[workDir];
            int   temp  = workDir;

            workDir = datablock[_node.getBlock(0)].reDirectInode(name);     //找到所选项的inode
            if (node[workDir].getType().Equals("文件"))
            {
                selectedFile = workDir;
                workDir      = temp;
                return(true);       //是文件直接打开
            }
            listItems(workDir);     //是文件夹进入目录
            return(false);
        }
コード例 #6
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);
        }
コード例 #7
0
        private int calculate(inode _node, string _name)     //计算文件大小
        {
            int[]  ptr     = node[datablock[_node.getBlock(0)].findInode(_name)].getBlockPtr();
            string content = "";

            for (int i = 0; i < 13; i++)        //遍历该文件的所有块,计算大小
            {
                if (datablock[ptr[i]] != null && datablock[ptr[i]].data != null && !datablock[ptr[i]].data.Equals(""))
                {
                    content += datablock[ptr[i]].data;
                    continue;
                }
                break;
            }
            byte[] sarr = Encoding.Default.GetBytes(content);
            return(sarr.Length);
        }
コード例 #8
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;
        }
コード例 #9
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);
        }
コード例 #10
0
 public void setInodeByIndex(int node_index, inode node)
 {
     ((inodeBitmap)datablock[1].data).obtain(node_index);
     ((inode[])datablock[3].data)[node_index] = node;
 }