Пример #1
0
        /// <summary>
        /// Creates inodes and dirents for superroot, flat_path_table, and uroot.
        /// Also, creates the root node for the FS tree.
        /// </summary>
        void SetupRootStructure()
        {
            inodes.Add(super_root_ino = new PfsDinode32
            {
                Mode  = InodeMode.dir | InodeMode.rx_only, Blocks = 1, Size = 65536, SizeCompressed = 65536, Nlink = 1, Number = 0,
                Flags = InodeFlags.@internal
            });
            inodes.Add(fpt_ino = new PfsDinode32
            {
                Mode = InodeMode.file | InodeMode.rwx, Blocks = 1, Number = 1, Flags = InodeFlags.@internal
            });
            var uroot_ino = new PfsDinode32 {
                Mode = InodeMode.dir | InodeMode.rwx, Number = 2, Size = 65536, SizeCompressed = 65536, Blocks = 1
            };

            super_root_dirents = new List <PfsDirent>
            {
                new PfsDirent {
                    InodeNumber = 1, Name = "flat_path_table", Type = 2
                },
                new PfsDirent {
                    InodeNumber = 2, Name = "uroot", Type = 3
                }
            };

            root = new FSDir
            {
                name    = "uroot",
                ino     = uroot_ino,
                Dirents = new List <PfsDirent>
                {
                    new PfsDirent {
                        Name = ".", Type = 4, InodeNumber = 2
                    },
                    new PfsDirent {
                        Name = "..", Type = 5, InodeNumber = 2
                    }
                }
            };
        }
Пример #2
0
        /// <summary>
        /// Takes a directory and a root node, and recursively makes a filesystem tree.
        /// </summary>
        /// <param name="root"></param>
        /// <param name="rootDir"></param>
        void BuildFSTree(FSDir root, string rootDir)
        {
            foreach (var d in Directory.EnumerateDirectories(rootDir))
            {
                FSDir dir;
                root.Dirs.Add(dir = new FSDir {
                    name = Path.GetFileName(d), Parent = root
                });
                BuildFSTree(dir, d);
            }

            foreach (var f in Directory.EnumerateFiles(rootDir))
            {
                root.Files.Add(new FSFile
                {
                    Parent       = root,
                    name         = Path.GetFileName(f),
                    OrigFileName = f,
                    Size         = new FileInfo(f).Length
                });
            }
        }