Пример #1
0
        public virtual FatFileInfo scan()
        {
            firstFreeCluster = vFile.FirstFreeCluster;

            FatFileInfo rootDirectory = new FatFileInfo(vFile.DeviceName, null, null, true, false, null, 0);

            rootDirectory.ParentDirectory = rootDirectory;

            scan(null, rootDirectory);

            vFile.RootDirectory = rootDirectory;

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("Using 0x{0:X} clusters out of 0x{1:X}", firstFreeCluster, maxNumberClusters));
                debugScan(rootDirectory);
            }

            if (firstFreeCluster > maxNumberClusters)
            {
                Console.WriteLine(string.Format("Too many files in the Fat partition: required clusters=0x{0:X}, max clusters=0x{1:X}", firstFreeCluster, maxNumberClusters));
            }

            return(rootDirectory);
        }
Пример #2
0
        public virtual sbyte[] buildDirectoryData(FatFileInfo fileInfo)
        {
            sbyte[] directoryData;

            // Is this the root directory?
            if (fileInfo.RootDirectory)
            {
                // The root directory has no "." nor ".." directory entries
                directoryData = new sbyte[0];
            }
            else
            {
                // Non-root directories have "." and ".." directory entries
                directoryData = new sbyte[directoryTableEntrySize * 2];

                buildDotDirectoryEntry(directoryData, 0, fileInfo, ".", fileInfo.LastModified);
                buildDotDirectoryEntry(directoryData, directoryTableEntrySize, fileInfo.ParentDirectory, "..", fileInfo.LastModified);
            }

            IList <FatFileInfo> children = fileInfo.Children;

            if (children != null)
            {
                foreach (FatFileInfo child in children)
                {
                    directoryData = addDirectoryEntry(directoryData, child);
                }
            }

            return(directoryData);
        }
Пример #3
0
        private void computeFileName83(FatFileInfo fileInfo, IList <FatFileInfo> siblings)
        {
            int    collisionIndex = 0;
            string fileName       = fileInfo.FileName;
            string fileName83     = convertFileNameTo83(fileName, collisionIndex);

            // Check if the 8.3 file name is not colliding
            // with other 8.3 file names in the same directory.
            bool hasCollision;

            do
            {
                hasCollision = false;
                foreach (FatFileInfo sibling in siblings)
                {
                    string siblingFileName83 = sibling.FileName83;
                    if (!string.ReferenceEquals(siblingFileName83, null))
                    {
                        if (fileName83.Equals(siblingFileName83))
                        {
                            // 8.3 file name collision
                            collisionIndex++;
                            hasCollision = true;
                            fileName83   = convertFileNameTo83(fileName, collisionIndex);
                            break;
                        }
                    }
                }
            } while (hasCollision);

            fileInfo.FileName83 = fileName83;
        }
Пример #4
0
        private void buildDotDirectoryEntry(sbyte[] directoryData, int offset, FatFileInfo fileInfo, string dotName, ScePspDateTime alternateLastModified)
        {
            storeSectorString(directoryData, offset + 0, dotName, 8 + 3);

            // File attributes: directory
            storeSectorInt8(directoryData, offset + 11, 0x10);

            // Has extended attributes?
            storeSectorInt8(directoryData, offset + 12, 0);

            ScePspDateTime lastModified = fileInfo.LastModified;

            if (lastModified == null)
            {
                // The root directory has no lastModified date/time,
                // rather use the date/time of the sub-directory.
                lastModified = alternateLastModified;
            }
            storeSectorInt8(directoryData, offset + 13, 0);             // Milliseconds, always set to 0 by the PSP

            int createTime = lastModified.hour << 11;

            createTime |= lastModified.minute << 5;
            createTime |= lastModified.second >> 1;
            storeSectorInt16(directoryData, offset + 14, createTime);

            int createDate = (lastModified.year - 1980) << 9;

            createDate |= lastModified.month << 5;
            createDate |= lastModified.day;
            storeSectorInt16(directoryData, offset + 16, createDate);

            storeSectorInt16(directoryData, offset + 18, createDate);

            int[] clusters = fileInfo.Clusters;
            if (clusters != null)
            {
                storeSectorInt16(directoryData, offset + 20, (int)((uint)clusters[0] >> 16));
            }
            else
            {
                storeSectorInt16(directoryData, offset + 20, 0);                 // Empty file
            }

            storeSectorInt16(directoryData, offset + 22, createTime);
            storeSectorInt16(directoryData, offset + 24, createDate);

            if (clusters != null)
            {
                storeSectorInt16(directoryData, offset + 26, clusters[0] & 0xFFFF);
            }
            else
            {
                storeSectorInt16(directoryData, offset + 26, 0);                 // Empty file
            }

            // File size
            storeSectorInt32(directoryData, offset + 28, 0);
        }
Пример #5
0
        public virtual void addChild(FatFileInfo fileInfo)
        {
            if (children == null)
            {
                children = new LinkedList <FatFileInfo>();
            }

            children.Add(fileInfo);
            fileInfo.ParentDirectory = this;
        }
Пример #6
0
 public virtual void setClusters(FatFileInfo fileInfo, int[] clusters)
 {
     if (clusters != null)
     {
         for (int i = 0; i < clusters.Length; i++)
         {
             vFile.setFatFileInfoMap(clusters[i], fileInfo);
         }
     }
     fileInfo.Clusters = clusters;
 }
Пример #7
0
        public static FatFileInfo[] extendArray(FatFileInfo[] array, int extend)
        {
            if (array == null)
            {
                return(new FatFileInfo[extend]);
            }

            FatFileInfo[] newArray = new FatFileInfo[array.Length + extend];
            Array.Copy(array, 0, newArray, 0, array.Length);

            return(newArray);
        }
Пример #8
0
        private void debugScan(FatFileInfo fileInfo)
        {
            Console.WriteLine(string.Format("scan {0}", fileInfo));
            IList <FatFileInfo> children = fileInfo.Children;

            if (children != null)
            {
                foreach (FatFileInfo child in children)
                {
                    debugScan(child);
                }
            }
        }
Пример #9
0
        private void scan(string dirName, FatFileInfo parent)
        {
            string[] names = vfs.ioDopen(dirName);
            if (names == null || names.Length == 0)
            {
                return;
            }

            SceIoStat   stat = new SceIoStat();
            SceIoDirent dir  = new SceIoDirent(stat, null);

            for (int i = 0; i < names.Length; i++)
            {
                dir.filename = names[i];
                if (vfs.ioDread(dirName, dir) >= 0)
                {
                    bool        directory = (dir.stat.attr & 0x10) != 0;
                    bool        readOnly  = (dir.stat.mode & 0x2) == 0;
                    FatFileInfo fileInfo  = new FatFileInfo(vFile.DeviceName, dirName, dir.filename, directory, readOnly, dir.stat.mtime, dir.stat.size);

                    parent.addChild(fileInfo);

                    if (directory)
                    {
                        if (string.ReferenceEquals(dirName, null))
                        {
                            scan(dir.filename, fileInfo);
                        }
                        else
                        {
                            scan(dirName + "/" + dir.filename, fileInfo);
                        }
                    }

                    // Allocate the clusters after having scanned the children
                    allocateClusters(fileInfo);
                }
            }

            IList <FatFileInfo> children = parent.Children;

            if (children != null)
            {
                foreach (FatFileInfo child in children)
                {
                    computeFileName83(child, children);
                }
            }
        }
Пример #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void read(pspsharp.state.StateInputStream stream, FatVirtualFile fatVirtualFile) throws java.io.IOException
        public virtual void read(StateInputStream stream, FatVirtualFile fatVirtualFile)
        {
            parentDirectory = fatVirtualFile.readFatFileInfo(stream);

            // Read the children
            children = null;
            int countChildren = stream.readInt();

            for (int i = 0; i < countChildren; i++)
            {
                FatFileInfo child = fatVirtualFile.readFatFileInfo(stream);
                if (child != null)
                {
                    addChild(child);
                }
            }
        }
Пример #11
0
        private void allocateClusters(FatFileInfo fileInfo)
        {
            long dataSize = fileInfo.FileSize;

            if (fileInfo.Directory)
            {
                // Two child entries for "." and ".."
                int directoryTableEntries = 2;

                IList <FatFileInfo> children = fileInfo.Children;
                if (children != null)
                {
                    // TODO: take fake entries into account to support "long filename"
                    directoryTableEntries += children.Count;
                }

                dataSize = directoryTableEntrySize * directoryTableEntries;
            }

            int[] clusters = allocateClusters(dataSize);
            setClusters(fileInfo, clusters);
        }
Пример #12
0
        private sbyte[] addDirectoryEntry(sbyte[] directoryData, FatFileInfo fileInfo)
        {
            string fileName    = fileInfo.FileName;
            string fileName83  = fileInfo.FileName83;
            string fileName8_3 = convertFileName83To8_3(fileName83);

            if (isLongFileName(fileName8_3, fileName))
            {
                int checksum = getFileNameChecksum(fileName83);
                directoryData = addLongFileNameDirectoryEntries(directoryData, fileName, checksum);
            }

            int offset = directoryData.Length;

            directoryData = Utilities.extendArray(directoryData, directoryTableEntrySize);

            storeSectorString(directoryData, offset + 0, fileName83, 8 + 3);

            int fileAttributes = 0x20;             // Archive attribute

            if (fileInfo.ReadOnly)
            {
                fileAttributes |= 0x01;                 // Read Only attribute
            }
            if (fileInfo.Directory)
            {
                fileAttributes |= 0x10;                 // Sub-directory attribute
            }
            storeSectorInt8(directoryData, offset + 11, fileAttributes);

            // Has extended attributes?
            storeSectorInt8(directoryData, offset + 12, 0);

            ScePspDateTime lastModified = fileInfo.LastModified;

            storeSectorInt8(directoryData, offset + 13, 0);             // Milliseconds always set to 0 by the PSP

            int createTime = lastModified.hour << 11;

            createTime |= lastModified.minute << 5;
            createTime |= lastModified.second >> 1;
            storeSectorInt16(directoryData, offset + 14, createTime);

            int createDate = (lastModified.year - 1980) << 9;

            createDate |= lastModified.month << 5;
            createDate |= lastModified.day;
            storeSectorInt16(directoryData, offset + 16, createDate);

            storeSectorInt16(directoryData, offset + 18, createDate);

            int[] clusters = fileInfo.Clusters;
            if (clusters != null)
            {
                storeSectorInt16(directoryData, offset + 20, (int)((uint)clusters[0] >> 16));
            }
            else
            {
                storeSectorInt16(directoryData, offset + 20, 0);                 // Empty file
            }

            storeSectorInt16(directoryData, offset + 22, createTime);
            storeSectorInt16(directoryData, offset + 24, createDate);

            if (clusters != null)
            {
                storeSectorInt16(directoryData, offset + 26, clusters[0] & 0xFFFF);
            }
            else
            {
                storeSectorInt16(directoryData, offset + 26, 0);                 // Empty file
            }

            int fileSize = (int)fileInfo.FileSize;

            if (fileInfo.Directory)
            {
                fileSize = 0;
            }
            storeSectorInt32(directoryData, offset + 28, fileSize);

            return(directoryData);
        }