示例#1
0
        public bool hasSubDir(UInt32 clusterNum)
        {
            byte[] secBuff            = new byte[bootSector.BPS];
            byte[] directoryEntryBuff = new byte[32];

            UInt64 byteAdd;


            SafeFileHandle handle = WindowsAPI.Open(@"\\.\" + this.name);


            do
            {
                byteAdd = clusterByteAddress(clusterNum);

                WindowsAPI.SetFilePointer(handle, byteAdd);
                int i = 64;
                for (int j = 0; j < bootSector.SPC; j++)
                {
                    secBuff = WindowsAPI.ReadFile(handle, secBuff, 0, secBuff.Length);

                    for (; i < bootSector.BPS; i += 32)
                    {
                        if (secBuff[i] == 0x00)
                        {
                            handle.Close();

                            return(false);
                        }

                        for (int f = 0; f < 32; f++)
                        {
                            directoryEntryBuff[f] = secBuff[f + i];
                        }
                        DirectoryEntry.EntryType type = DirectoryEntry.type(directoryEntryBuff);
                        if (type == DirectoryEntry.EntryType.Valid_short)
                        {
                            DirectoryEntry entry = new DirectoryEntry(directoryEntryBuff, null);
                            if (entry.attribute == DirectoryEntry.attributes.Directory)
                            {
                                return(true);
                            }
                        }
                    }
                    i = 0;
                }

                clusterNum = getNextChain(clusterNum);
            } while (clusterNum < 0x0FFFFFF8);

            return(false);
        }
示例#2
0
        public DirectoryEntry[] getDirectoryData(UInt32 clusterNum)
        {
            byte[] secBuff                        = new byte[bootSector.BPS];
            byte[] directoryEntryBuff             = new byte[32];
            Queue <DirectoryEntry> directoryEntry = new Queue <DirectoryEntry>();
            UInt64 byteAdd;

            //TODO : to take care if address is 64 bit;
            SafeFileHandle handle    = WindowsAPI.Open(@"\\.\" + this.name);
            SafeFileHandle fatHandle = WindowsAPI.Open(@"\\.\" + this.name);

            do
            {
                byteAdd = clusterByteAddress(clusterNum);

                WindowsAPI.SetFilePointer(handle, byteAdd);
                bool inLongSet = false;
                LongDirectoryEntry longEntry = null;

                for (int j = 0; j < bootSector.SPC; j++)
                {
                    secBuff = WindowsAPI.ReadFile(handle, secBuff, 0, secBuff.Length);

                    for (int i = 0; i < bootSector.BPS; i += 32)
                    {
                        if (secBuff[i] == 0x00)
                        {
                            handle.Close();
                            fatHandle.Close();
                            return(directoryEntry.ToArray());
                        }

                        for (int f = 0; f < 32; f++)
                        {
                            directoryEntryBuff[f] = secBuff[f + i];
                        }
                        DirectoryEntry.EntryType type = DirectoryEntry.type(directoryEntryBuff);
                        if (type == DirectoryEntry.EntryType.Deleted)
                        {
                        }
                        else if (type == DirectoryEntry.EntryType.Valid_long)
                        {
                            if (!inLongSet)
                            {
                                inLongSet = true;
                                longEntry = new LongDirectoryEntry(directoryEntryBuff);
                            }
                            else
                            {
                                longEntry.merge(directoryEntryBuff);
                            }
                        }
                        else if (type == DirectoryEntry.EntryType.Valid_short)
                        {
                            DirectoryEntry entry = new DirectoryEntry(directoryEntryBuff, this);
                            if (entry.attribute != DirectoryEntry.attributes.Vollume_ID)
                            {
                                if (inLongSet)
                                {
                                    longEntry.merge(entry);
                                }
                                directoryEntry.Enqueue(entry);
                                inLongSet = false;
                            }
                        }
                    }
                }

                clusterNum = getNextChain(clusterNum);
            } while (clusterNum < 0x0FFFFFF8);

            return(directoryEntry.ToArray());
        }