Load() public static method

从存储介质中获取 inode
public static Load ( VFSCore vfs, UInt32 index ) : INode
vfs VFSCore
index System.UInt32
return INode
Exemplo n.º 1
0
        /// <summary>
        /// 删除一个目录项
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Boolean Delete(String name)
        {
            if (!Contains(name))
            {
                return(false);
            }
            if (name == "." || name == "..")
            {
                return(false);
            }

            var inodeIndex = entries[name];

            INode inode = INode.Load(vfs, inodeIndex);

            if (inode.IsDirectory())
            {
                // 删除非空目录项:递归删除
                INodeDirectory id = INodeDirectory.Load(vfs, inodeIndex);
                if (id.Size() > 2)
                {
                    var l = id.List();
                    foreach (var pair in l)
                    {
                        id.Delete(pair.Key);
                    }
                }
            }

            inode.data.linkCount--;

            if (inode.data.linkCount == 0)
            {
                inode.Resize(0);
                vfs.DeAllocateINode(inode.index);
            }
            else
            {
                inode.Save();
            }

            entries.Remove(name);
            Save();

            return(true);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
            /// <summary>
            /// 列出一个目录下所有内容
            /// </summary>
            /// <returns></returns>
            public List <DirectoryInfo> List()
            {
                var ret     = new List <DirectoryInfo>();
                var entries = dir.List();

                foreach (var entry in entries)
                {
                    var   info  = new DirectoryInfo();
                    INode inode = INode.Load(vfs, entry.Value);
                    info.isDirectory  = inode.IsDirectory();
                    info.accessTime   = inode.data.accessTime;
                    info.creationTime = inode.data.creationTime;
                    info.flags        = inode.data.flags;
                    info.modifyTime   = inode.data.modifyTime;
                    info.name         = entry.Key;
                    info.path         = this.path + entry.Key;
                    info.owner        = inode.data.owner;
                    info.size         = inode.data.sizeByte;
                    info.inode        = inode.data;
                    info.inodeIndex   = inode.index;
                    ret.Add(info);
                }
                return(ret);
            }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
 /// <summary>
 /// 通过打开现有文件来初始化该类
 /// </summary>
 /// <param name="dir"></param>
 /// <param name="name"></param>
 private void OpenFile(INodeDirectory dir, String name)
 {
     inode = INode.Load(vfs, dir.Find(name));
 }