Ejemplo n.º 1
0
        /// <summary>
        /// 根据 inode 建立 INodeDirectory
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="inode"></param>
        /// <returns></returns>
        public static INodeDirectory Load(VFSCore vfs, INode inode)
        {
            INodeDirectory t = new INodeDirectory(vfs, inode);

            t.Load();
            return(t);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 创建一个新目录
 /// </summary>
 /// <param name="vfs"></param>
 /// <returns></returns>
 public static INodeDirectory Create(VFSCore vfs)
 {
     INode inode = vfs.AllocateINode(1, 2333);
     INodeDirectory t = new INodeDirectory(vfs, inode);
     t.AddSelf();
     return t;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 从存储介质中获取 inode
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static INode Load(VFSCore vfs, UInt32 index)
        {
            if (index >= vfs.GetSuperBlock().data.inodeCapacity)
            {
                throw new Exception("无效 inode 编号");
            }

            INode inode = null;

            if (inodeInstances.ContainsKey(index))
            {
                inode = inodeInstances[index];
                return(inode);
            }
            else
            {
                _INode data = vfs.GetDevice().Read <_INode>(GetPosition(vfs, index));
                inode = new INode(vfs, data, index);
                inodeInstances[index] = inode;
            }

            inode.data.accessTime = (UInt64)DateTime.Now.Ticks;
            inode.Save();
            return(inode);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 创建一个新目录
        /// </summary>
        /// <param name="vfs"></param>
        /// <returns></returns>
        public static INodeDirectory Create(VFSCore vfs)
        {
            INode          inode = vfs.AllocateINode(1, 2333);
            INodeDirectory t     = new INodeDirectory(vfs, inode);

            t.AddSelf();
            return(t);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 创建一个全新的 SuperBlock
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="inodeCapacity"></param>
        /// <param name="blockSize"></param>
        /// <param name="blockCapacity"></param>
        /// <returns></returns>
        public static SuperBlock Create(VFSCore vfs, UInt32 inodeCapacity, UInt16 blockSize, UInt32 blockCapacity)
        {
            var _superBlock = new _SuperBlock(inodeCapacity, blockSize, blockCapacity);
            var superBlock  = new SuperBlock(vfs, _superBlock);

            superBlock.Save();
            return(superBlock);
        }
Ejemplo n.º 6
0
        public SuperBlock(VFSCore vfs, _SuperBlock data)
        {
            this.vfs  = vfs;
            this.data = data;

            if (data.IsValid())
            {
                init();
            }
        }
Ejemplo n.º 7
0
        public INode(VFSCore vfs, _INode data, UInt32 index = UInt32.MaxValue)
        {
            this.vfs   = vfs;
            this.data  = data;
            this.index = index;

            UInt32 blockSize     = vfs.GetSuperBlock().data.blockSize;
            UInt32 IndexPerBlock = blockSize / sizeof(UInt32);

            BoundLv0 = 12 * blockSize;
            BoundLv1 = BoundLv0 + IndexPerBlock * blockSize;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 创建一个新的 inode
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static INode Create(VFSCore vfs, UInt32 index, UInt32 flags, UInt32 owner)
        {
            if (index >= vfs.GetSuperBlock().data.inodeCapacity)
            {
                throw new Exception("无效 inode 编号");
            }

            _INode data  = new _INode(flags, owner);
            INode  inode = new INode(vfs, data, index);

            inode.Save();
            inodeInstances[index] = inode;

            return(inode);
        }
Ejemplo n.º 9
0
            public Directory(VFSCore vfs, String path)
            {
                this.vfs = vfs;

                if (!path.EndsWith("/"))
                {
                    path += "/";
                }

                this.path = path;

                dir = INodeDirectory.Resolve(vfs, path);

                if (dir == null)
                {
                    throw new Exception("无效路径");
                }
            }
Ejemplo n.º 10
0
            public Directory(VFSCore vfs, String path)
            {
                this.vfs = vfs;

                if (!path.EndsWith("/"))
                {
                    path += "/";
                }

                this.path = path;

                dir = INodeDirectory.Resolve(vfs, path);

                if (dir == null)
                {
                    throw new Exception("无效路径");
                }
            }
Ejemplo n.º 11
0
        /// <summary>
        /// 根据路径解析目录,路径必须以 / 结尾
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static INodeDirectory Resolve(VFSCore vfs, String path)
        {
            INodeDirectory root = Load(vfs, 0);

            var pathCom = path.Split('/');
            var node    = root;

            for (var i = 1; i < pathCom.Length - 1; ++i)
            {
                if (node.Contains(pathCom[i]) && INode.Load(vfs, node.Find(pathCom[i])).IsDirectory())
                {
                    node = Load(vfs, node.Find(pathCom[i]));
                }
                else
                {
                    return(null);
                }
            }

            return(node);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 根据路径解析目录,路径必须以 / 结尾
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static INodeDirectory Resolve(VFSCore vfs, String path)
        {
            INodeDirectory root = Load(vfs, 0);

            var pathCom = path.Split('/');
            var node = root;

            for (var i = 1; i < pathCom.Length - 1; ++i)
            {
                if (node.Contains(pathCom[i]) && INode.Load(vfs, node.Find(pathCom[i])).IsDirectory())
                {
                    node = Load(vfs, node.Find(pathCom[i]));
                }
                else
                {
                    return null;
                }
            }

            return node;
        }
Ejemplo n.º 13
0
 public VFS(AbstractDevice device)
 {
     vfs = new VFSCore(device);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 从存储介质上还原 SuperBlock
 /// </summary>
 /// <param name="vfs"></param>
 /// <returns></returns>
 public static SuperBlock Load(VFSCore vfs)
 {
     var _superBlock = vfs.GetDevice().Read<_SuperBlock>(0);
     return new SuperBlock(vfs, _superBlock);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// 创建一个全新的 SuperBlock
 /// </summary>
 /// <param name="vfs"></param>
 /// <param name="inodeCapacity"></param>
 /// <param name="blockSize"></param>
 /// <param name="blockCapacity"></param>
 /// <returns></returns>
 public static SuperBlock Create(VFSCore vfs, UInt32 inodeCapacity, UInt16 blockSize, UInt32 blockCapacity)
 {
     var _superBlock = new _SuperBlock(inodeCapacity, blockSize, blockCapacity);
     var superBlock = new SuperBlock(vfs, _superBlock);
     superBlock.Save();
     return superBlock;
 }
Ejemplo n.º 16
0
        public SuperBlock(VFSCore vfs, _SuperBlock data)
        {
            this.vfs = vfs;
            this.data = data;

            if (data.IsValid())
            {
                init();
            }
        }
Ejemplo n.º 17
0
            public File(VFSCore vfs, String path, FileMode fileMode)
            {
                this.vfs = vfs;

                var directory = VFS.GetPathDirectory(path);
                var name      = VFS.GetPathName(path);

                VFS.AssertNameValid(name);

                INodeDirectory dir = INodeDirectory.Resolve(vfs, directory);

                if (dir == null)
                {
                    throw new Exception("无法访问目录");
                }
                switch (fileMode)
                {
                case FileMode.CreateNew:
                    if (dir.Contains(name))
                    {
                        throw new Exception("文件已存在");
                    }
                    CreateFile(dir, name);
                    break;

                case FileMode.Create:
                    if (dir.Contains(name))
                    {
                        OpenFile(dir, name);
                        inode.Resize(0);
                    }
                    else
                    {
                        CreateFile(dir, name);
                    }
                    break;

                case FileMode.Open:
                    if (!dir.Contains(name))
                    {
                        throw new Exception("文件未找到");
                    }
                    OpenFile(dir, name);
                    break;

                case FileMode.OpenOrCreate:
                    if (dir.Contains(name))
                    {
                        OpenFile(dir, name);
                    }
                    else
                    {
                        CreateFile(dir, name);
                    }
                    break;

                case FileMode.Truncate:
                    if (!dir.Contains(name))
                    {
                        throw new Exception("文件未找到");
                    }
                    OpenFile(dir, name);
                    inode.Resize(0);
                    break;

                case FileMode.Append:
                    if (!dir.Contains(name))
                    {
                        CreateFile(dir, name);
                    }
                    else
                    {
                        OpenFile(dir, name);
                        position = inode.data.sizeByte;
                    }
                    break;

                default:
                    throw new ArgumentException();
                }
            }
Ejemplo n.º 18
0
 public static UInt32 GetPosition(VFSCore vfs, UInt32 index)
 {
     return(vfs.GetSuperBlock().pInodeData + index * (uint)Utils.GetStructSize <_INode>());
 }
Ejemplo n.º 19
0
 public INodeDirectory(VFSCore vfs, INode inode)
 {
     this.vfs     = vfs;
     this.inode   = inode;
     this.entries = new Dictionary <String, UInt32>();
 }
Ejemplo n.º 20
0
 /// <summary>
 /// 根据 inode 建立 INodeDirectory
 /// </summary>
 /// <param name="vfs"></param>
 /// <param name="inode"></param>
 /// <returns></returns>
 public static INodeDirectory Load(VFSCore vfs, INode inode)
 {
     INodeDirectory t = new INodeDirectory(vfs, inode);
     t.Load();
     return t;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// 根据 inode index 建立 INodeDirectory
 /// </summary>
 /// <param name="vfs"></param>
 /// <param name="inodeIndex"></param>
 /// <returns></returns>
 public static INodeDirectory Load(VFSCore vfs, UInt32 inodeIndex)
 {
     INode inode = INode.Load(vfs, inodeIndex);
     return Load(vfs, inode);
 }
Ejemplo n.º 22
0
 public VFS(AbstractDevice device)
 {
     vfs = new VFSCore(device);
 }
Ejemplo n.º 23
0
        /// <summary>
        /// 从存储介质上还原 SuperBlock
        /// </summary>
        /// <param name="vfs"></param>
        /// <returns></returns>
        public static SuperBlock Load(VFSCore vfs)
        {
            var _superBlock = vfs.GetDevice().Read <_SuperBlock>(0);

            return(new SuperBlock(vfs, _superBlock));
        }
Ejemplo n.º 24
0
 public INodeDirectory(VFSCore vfs, INode inode)
 {
     this.vfs = vfs;
     this.inode = inode;
     this.entries = new Dictionary<String, UInt32>();
 }
Ejemplo n.º 25
0
 public static UInt32 GetPosition(VFSCore vfs, UInt32 index)
 {
     return vfs.GetSuperBlock().pInodeData + index * (uint)Utils.GetStructSize<_INode>();
 }
Ejemplo n.º 26
0
        /// <summary>
        /// 创建一个新的 inode
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static INode Create(VFSCore vfs, UInt32 index, UInt32 flags, UInt32 owner)
        {
            if (index >= vfs.GetSuperBlock().data.inodeCapacity)
            {
                throw new Exception("无效 inode 编号");
            }

            _INode data = new _INode(flags, owner);
            INode inode = new INode(vfs, data, index);
            inode.Save();
            inodeInstances[index] = inode;

            return inode;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// 从存储介质中获取 inode
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static INode Load(VFSCore vfs, UInt32 index)
        {
            if (index >= vfs.GetSuperBlock().data.inodeCapacity)
            {
                throw new Exception("无效 inode 编号");
            }

            INode inode = null;

            if (inodeInstances.ContainsKey(index))
            {
                inode = inodeInstances[index];
                return inode;
            }
            else
            {
                _INode data = vfs.GetDevice().Read<_INode>(GetPosition(vfs, index));
                inode = new INode(vfs, data, index);
                inodeInstances[index] = inode;
            }

            inode.data.accessTime = (UInt64)DateTime.Now.Ticks;
            inode.Save();
            return inode;
        }
Ejemplo n.º 28
0
            public File(VFSCore vfs, String path, FileMode fileMode)
            {
                this.vfs = vfs;

                var directory = VFS.GetPathDirectory(path);
                var name = VFS.GetPathName(path);
                VFS.AssertNameValid(name);

                INodeDirectory dir = INodeDirectory.Resolve(vfs, directory);
                if (dir == null)
                {
                    throw new Exception("无法访问目录");
                }
                switch (fileMode)
                {
                    case FileMode.CreateNew:
                        if (dir.Contains(name))
                        {
                            throw new Exception("文件已存在");
                        }
                        CreateFile(dir, name);
                        break;
                    case FileMode.Create:
                        if (dir.Contains(name))
                        {
                            OpenFile(dir, name);
                            inode.Resize(0);
                        }
                        else
                        {
                            CreateFile(dir, name);
                        }
                        break;
                    case FileMode.Open:
                        if (!dir.Contains(name))
                        {
                            throw new Exception("文件未找到");
                        }
                        OpenFile(dir, name);
                        break;
                    case FileMode.OpenOrCreate:
                        if (dir.Contains(name))
                        {
                            OpenFile(dir, name);
                        }
                        else
                        {
                            CreateFile(dir, name);
                        }
                        break;
                    case FileMode.Truncate:
                        if (!dir.Contains(name))
                        {
                            throw new Exception("文件未找到");
                        }
                        OpenFile(dir, name);
                        inode.Resize(0);
                        break;
                    case FileMode.Append:
                        if (!dir.Contains(name))
                        {
                            CreateFile(dir, name);
                        }
                        else
                        {
                            OpenFile(dir, name);
                            position = inode.data.sizeByte;
                        }
                        break;
                    default:
                        throw new ArgumentException();
                }
            }
Ejemplo n.º 29
0
        /// <summary>
        /// 根据 inode index 建立 INodeDirectory
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="inodeIndex"></param>
        /// <returns></returns>
        public static INodeDirectory Load(VFSCore vfs, UInt32 inodeIndex)
        {
            INode inode = INode.Load(vfs, inodeIndex);

            return(Load(vfs, inode));
        }
Ejemplo n.º 30
0
        public INode(VFSCore vfs, _INode data, UInt32 index = UInt32.MaxValue)
        {
            this.vfs = vfs;
            this.data = data;
            this.index = index;

            UInt32 blockSize = vfs.GetSuperBlock().data.blockSize;
            UInt32 IndexPerBlock = blockSize / sizeof(UInt32);
            BoundLv0 = 12 * blockSize;
            BoundLv1 = BoundLv0 + IndexPerBlock * blockSize;
        }