예제 #1
0
        private static void GetName(SubDirectory dir, int i, char *outName)
        {
            FatDirEntry entry = dir.DirEntries[i];

            /**
             * Calculate length and offsets
             */
            string nameStr  = Util.CharPtrToString(entry.Name);
            int    fnLength = nameStr.IndexOf(' ');

            if (fnLength > 8 || fnLength == -1)
            {
                fnLength = 8;
            }

            int offset = 0;

            for (int z = 0; z < fnLength; z++)
            {
                outName[offset++] = entry.Name[z];
            }


            // Is it a file?
            if ((dir.DirEntries[i].Attribs & ATTRIB_SUBDIR) == 0)
            {
                nameStr = Util.CharPtrToString(entry.Name + 8);
                int extLength = nameStr.IndexOf(' ');
                if (extLength == -1)
                {
                    extLength = 3;
                }

                if (extLength != 0)
                {
                    outName[offset++] = '.';


                    for (int z = 0; z < extLength; z++)
                    {
                        outName[offset++] = entry.Name[z + 8];
                    }
                }
            }

            outName[offset] = '\0';

            for (int z = 0; z < offset; z++)
            {
                outName[z] = String.ToLower(outName[z]);
            }
        }
예제 #2
0
        /// <summary>
        /// Find node in directory
        /// </summary>
        /// <param name="cluster">Cluster number</param>
        /// <param name="testFor">Compare string</param>
        /// <returns></returns>
        public Node FindFileInDirectory(uint cluster, char *testFor)
        {
            SubDirectory dir = readDirectory(cluster);

            for (int i = 0; i < dir.Length; i++)
            {
                FatDirEntry entry = dir.DirEntries[i];

                if (entry.Name[0] == 0 || entry.Name[0] == 0xE5 || entry.Attribs == 0xF || (entry.Attribs & 0x08) > 0)
                {
                    continue;
                }

                if (Memory.Compare(testFor, entry.Name, 11))
                {
                    FatDirEntry *entr = (FatDirEntry *)Heap.Alloc(sizeof(FatDirEntry));
                    Memory.Memcpy(entr, dir.DirEntries + i, sizeof(FatDirEntry));
                    return(CreateNode(entr, cluster, (uint)i));
                }
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        /// Filesystem read directory implementation
        /// </summary>
        /// <param name="node"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        private static DirEntry *readDirImpl(Node node, uint index)
        {
            int j = 0;

            /**
             * Find cluster number if not root directory
             */
            uint cluster = 0xFFFFFFFF;

            Fat16Cookie cookie = (Fat16Cookie)node.Cookie;
            Fat16       fat    = cookie.FAT16;

            if (cookie.DirEntry != null)
            {
                FatDirEntry *entry = cookie.DirEntry;
                cluster = entry->ClusterNumberLo;
            }

            /**
             * Read directory entries
             */
            SubDirectory dir = fat.readDirectory(cluster);

            for (int i = 0; i < dir.Length; i++)
            {
                FatDirEntry entry = dir.DirEntries[i];

                /**
                 * Correct attributes?
                 */
                if (entry.Name[0] == 0 || entry.Name[0] == (char)0xE5 || entry.Attribs == 0xF || (entry.Attribs & 0x08) > 0)
                {
                    continue;
                }

                /**
                 * Do we need to search further?
                 */
                if (j >= index)
                {
                    DirEntry *outDir = (DirEntry *)Heap.Alloc(sizeof(DirEntry));
                    outDir->Reclen = (ushort)sizeof(DirEntry);

                    GetName(dir, i, outDir->Name);


                    /**
                     * Directory or file?
                     */
                    if ((dir.DirEntries[i].Attribs & ATTRIB_SUBDIR) == 0)
                    {
                        outDir->Type = (byte)DT_Type.DT_REG;
                    }
                    else
                    {
                        outDir->Type = (byte)DT_Type.DT_DIR;
                    }


                    return(outDir);
                }

                j++;
            }

            return(null);
        }