Example #1
0
        public override int GetFileFlags(DirectoryEntry entry)
        {
            int flags = 0;

            if (entry.StartSector > 719 && entry.EntryInUse) flags |= 0x1;
            if (entry.CreatedInDos2) flags |= 0x2;
            if (entry.Locked) flags |= 0x20;
            if (entry.EntryInUse && entry.StartSector < 720) flags |= 0x40;
            if (entry.Deleted) flags |= 0x80;

            return flags;
        }
 public abstract int GetFileFlags(DirectoryEntry entry);
Example #3
0
 public override void SetFileFlags(DirectoryEntry entry, int flags)
 {
     if ((flags & 0x01) > 0 || (flags & 0x40) > 0) entry.EntryInUse = true;
     if ((flags & 0x2) > 0) entry.CreatedInDos2 = true;
     if ((flags & 0x20) > 0) entry.Locked = true;
     if ((flags & 0x80) > 0) entry.Deleted = true;
 }
Example #4
0
 public override int GetFileFlags(DirectoryEntry entry)
 {
     return 0;
 }
 public abstract void SetFileFlags(DirectoryEntry entry, int flags);
        public override int GetFileFlags(DirectoryEntry entry)
        {
            int flags = 0;

            if (entry.OpenForOutput) flags |= 0x1;
            if (entry.CreatedInDos2) flags |= 0x2;
            if (entry.Locked) flags |= 0x20;
            if (entry.EntryInUse) flags |= 0x40;
            if (entry.Deleted) flags |= 0x80;

            return flags;
        }
Example #7
0
 public override void SetFileFlags(DirectoryEntry entry, int flags)
 {
     throw new System.NotImplementedException();
 }
 /// <summary>
 /// Adds a directory entry
 /// </summary>
 /// <param name="entry"></param>
 public void AddEntry(DirectoryEntry entry)
 {
     entries.Add(entry);
 }
Example #9
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Writes a directory entry back to the disk
        /// </summary>
        /// <param name="entry">Directory entry to write</param>
        /// <remarks>
        /// </remarks>
        /// -----------------------------------------------------------------------------
        protected void WriteDirectoryEntry(DirectoryEntry entry)
        {
            byte[] sec;
            int i;
            string filename;
            string ext;

            int sector, offset;

            DirectorySectorLocation(entry.FileNumber, out sector, out offset);

            sec = ReadSector(sector);

            // Write flags
            sec[offset] = (byte)GetFileFlags(entry);

            // Write location information
            sec[offset + 2] = (byte)(entry.NumSectors >> 8);
            sec[offset + 1] = (byte)(entry.NumSectors & 0xff);
            sec[offset + 4] = (byte)(entry.StartSector >> 8);
            sec[offset + 3] = (byte)(entry.StartSector & 0xff);

            //Split filename
            i = entry.FileName.IndexOf(".");
            if (i > -1)
            {
                filename = entry.FileName.Substring(0, i);
                ext = entry.FileName.Substring(i + 1);
            }
            else
            {
                filename = entry.FileName;
                ext = "";
            }
            filename = filename.PadRight(8);
            ext = ext.PadRight(3);

            //Write filename
            StringToBytes(sec, filename, offset + 5);
            StringToBytes(sec, ext, offset + 13);

            WriteSector(sector, sec);

        }
Example #10
0
        /// <summary>
        /// Finds the next open directory entry and creates a new entry at
        /// that locaiton
        /// </summary>
        /// <returns>New DirectoryEntry object</returns>
        private DirectoryEntry GetOpenEntry()
        {
            //Try to find an already open entry
            foreach (DirectoryEntry ent in directory)
            {
                if (!ent.EntryInUse && ent.Deleted) return ent;
            }

            //Check if directory is full
            if (directory.Count == maxFiles) return null;

            //Create a new entry 
            DirectoryEntry entry = new DirectoryEntry();
            entry.FileNumber = directory.Count;

            directory.Add(entry);

            return entry;
        }
Example #11
0
        /// <summary>
        /// Read the directory from the disk
        /// </summary>
        public override void ReadDirectory()
        {
            int curSector = DirectoryStartSector;
            byte[] sec;
            int fileNumber = 0;

            directory = new List<DirectoryEntry>();

            while ((curSector <= DirectoryEndSector))
            {
                sec = ReadSector(curSector);
                int pos = 0; 
                while ((pos < 128))
                {
                    DirectoryEntry entry = new DirectoryEntry();

                    // Get flags
                    int flags = sec[pos];

                    SetFileFlags(entry, flags);

                    if (!entry.EntryInUse && !entry.Deleted) return;

                    //Assign filenumber
                    entry.FileNumber = fileNumber;
                    fileNumber += 1;

                    //Get file location information
                    entry.NumSectors = sec[pos + 2] * 256 + sec[pos + 1];
                    entry.StartSector = sec[pos + 4] * 256 + sec[pos + 3];

                    //Check location information
                    if (entry.StartSector < 4 | (entry.StartSector > 359 & entry.StartSector < 369) | entry.StartSector > LastUsableSector)
                    {
                        entry.ValidEntry = false;
                        entry.ErrorList.Add(DirectoryEntry.EntryError.InvalidStartSector);

                    }
                    if (entry.NumSectors < 1 | entry.NumSectors > AvailableSectors())
                    {
                        entry.ValidEntry = false;
                        entry.ErrorList.Add(DirectoryEntry.EntryError.InvalidNumberOfSectors);
                    }

                    //Check filename
                    if (sec[pos + 5] < 65 | sec[pos + 5] > 90)
                    {
                        entry.ValidEntry = false;
                        entry.ErrorList.Add(DirectoryEntry.EntryError.FileNameInvalidCharacters);
                    }
                    for (int i = 6; i <= 15; i++)
                    {
                        if (!ValidFileNameCharacter((char)(sec[pos + i])))
                        {
                            entry.ValidEntry = false;
                            entry.ErrorList.Add(DirectoryEntry.EntryError.FileNameInvalidCharacters);
                            break;
                        }

                    }

                    //Get filename
                    entry.FileName = BytesToString(sec, pos + 5, pos + 12).Trim();

                    string extension = BytesToString(sec, pos + 13, pos + 15).Trim();
                    if (extension != "") entry.FileName += "." + extension;

                    //Add entry
                    directory.Add(entry);

                    pos += 16;
                }
                curSector += 1;
            }

        }
Example #12
0
        /// <summary>
        /// Read the directory from the disk
        /// </summary>
        public override void DumpDirectory()
        {
            int curSector = DirectoryStartSector;
            byte[] sec;
            int fileNumber = 0;

            while ((curSector <= DirectoryEndSector))
            {
                sec = ReadSector(curSector);
                int pos = 0;
                while ((pos < 128))
                {
                    DirectoryEntry entry = new DirectoryEntry();

                    // Get flags
                    int flags = sec[pos];

                    SetFileFlags(entry, flags);

                    //Assign filenumber
                    entry.FileNumber = fileNumber;
                    fileNumber += 1;

                    //Get file location information
                    entry.NumSectors = sec[pos + 2] * 256 + sec[pos + 1];
                    entry.StartSector = sec[pos + 4] * 256 + sec[pos + 3];


                    //Get filename
                    entry.FileName = BytesToString(sec, pos + 5, pos + 12).Trim();

                    string extension = BytesToString(sec, pos + 13, pos + 15).Trim();
                    if (extension != "") entry.FileName += "." + extension;

                    pos += 16;

                    System.Diagnostics.Debug.WriteLine(string.Format("{0}: {1}, In Use: {2}, Delete: {3}, Dos2: {4}",entry.FileNumber, entry.FileName.ToString(), entry.EntryInUse, entry.Deleted, entry.CreatedInDos2));

                }
                curSector += 1;
            }

        }