示例#1
0
        static void AddFile(FSDir root, string path, string name, byte[] data)
        {
            var dir = FindDir(path, root);

            dir.Files.Add(new FSFile(s => s.Write(data, 0, data.Length), name, data.Length)
            {
                Parent = dir
            });
        }
示例#2
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 = MakeInode(
                           Mode: InodeMode.dir | InodeMode.rx_only,
                           Blocks: 1,
                           Size: 65536,
                           SizeCompressed: 65536,
                           Nlink: 1,
                           Number: 0,
                           Flags: InodeFlags.@internal | InodeFlags.@readonly
                           ));
            inodes.Add(fpt_ino = MakeInode(
                           Mode: InodeMode.file | InodeMode.rx_only,
                           Blocks: 1,
                           Number: 1,
                           Flags: InodeFlags.@internal | InodeFlags.@readonly
                           ));
            var uroot_ino = MakeInode(
                Mode: InodeMode.dir | InodeMode.rx_only,
                Number: 2,
                Size: 65536,
                SizeCompressed: 65536,
                Blocks: 1,
                Flags: InodeFlags.@readonly,
                Nlink: 3
                );

            super_root_dirents = new List <PfsDirent>
            {
                new PfsDirent {
                    InodeNumber = 1, Name = "flat_path_table", Type = DirentType.File
                },
                new PfsDirent {
                    InodeNumber = 2, Name = "uroot", Type = DirentType.Directory
                }
            };

            root         = properties.root;
            root.name    = "uroot";
            root.ino     = uroot_ino;
            root.Dirents = new List <PfsDirent>
            {
                new PfsDirent {
                    Name = ".", Type = DirentType.Dot, InodeNumber = 2
                },
                new PfsDirent {
                    Name = "..", Type = DirentType.DotDot, InodeNumber = 2
                }
            };
            if (properties.Sign) // HACK: Outer PFS lacks readonly flags
            {
                super_root_ino.Flags &= ~InodeFlags.@readonly;
                fpt_ino.Flags        &= ~InodeFlags.@readonly;
                uroot_ino.Flags      &= ~InodeFlags.@readonly;
            }
        }
示例#3
0
 public static void AddDirs(FSDir parent, List <GP4.Dir> imgDir)
 {
     foreach (var d in imgDir)
     {
         FSDir dir;
         parent.Dirs.Add(dir = new FSDir {
             name = d.TargetName, Parent = parent
         });
         AddDirs(dir, d.Children);
     }
 }
示例#4
0
        static FSDir FindDir(string name, FSDir root)
        {
            FSDir dir         = root;
            var   breadcrumbs = name.Split('/');

            foreach (var crumb in breadcrumbs)
            {
                dir = dir.Dirs.Where(d => d.name == crumb).First();
            }
            return(dir);
        }
示例#5
0
        public static PfsProperties MakeOuterPFSProps(PKG.PkgProperties props, PfsBuilder innerPFS, byte[] EKPFS, bool encrypt = true)
        {
            var root = new FSDir();

            root.Files.Add(new FSFile(innerPFS)
            {
                Parent = root,
            });
            return(new PfsProperties()
            {
                root = root,
                BlockSize = 0x10000,
                Encrypt = encrypt,
                Sign = true,
                EKPFS = EKPFS,
                Seed = new byte[16],
                FileTime = GetTimeStamp(props),
            });
        }
示例#6
0
        /// <summary>
        /// Takes a directory and a root node, and recursively makes a filesystem tree.
        /// </summary>
        /// <param name="proj">GP4 Project</param>
        /// <param name="projDir">Directory of GP4 file</param>
        /// <returns>Root directory of the image</returns>
        public static FSDir BuildFSTree(GP4.Gp4Project proj, string projDir)
        {
            var root = new FSDir();

            AddDirs(root, proj.RootDir);

            foreach (var f in proj.files.Items)
            {
                var lastSlash = f.TargetPath.LastIndexOf('/') + 1;
                var name      = f.TargetPath.Substring(lastSlash);
                var source    = Path.Combine(projDir, f.OrigPath);
                var parent    = lastSlash == 0 ? root : FindDir(f.TargetPath.Substring(0, lastSlash - 1), root);
                parent.Files.Add(new FSFile(source)
                {
                    Parent = parent,
                    name   = name,
                });
            }
            return(root);
        }