예제 #1
0
        /// <summary>
        ///     Checks that the given directory blocks follow the CP/M filesystem directory specification
        ///     Corrupted directories will fail.
        ///     FAT firectories will false positive if all files start with 0x05, and do not use full extentions, for example:
        ///     "σAFILE.GZ" (using code page 437)
        /// </summary>
        /// <returns>False if the directory does not follow the directory specification</returns>
        /// <param name="directory">Directory blocks.</param>
        bool CheckDir(byte[] directory)
        {
            try
            {
                if (directory == null)
                {
                    return(false);
                }

                int fileCount = 0;

                for (int off = 0; off < directory.Length; off += 32)
                {
                    DirectoryEntry entry = Marshal.ByteArrayToStructureLittleEndian <DirectoryEntry>(directory, off, 32);

                    if ((entry.statusUser & 0x7F) < 0x20)
                    {
                        for (int f = 0; f < 8; f++)
                        {
                            if (entry.filename[f] < 0x20 && entry.filename[f] != 0x00)
                            {
                                return(false);
                            }
                        }

                        for (int e = 0; e < 3; e++)
                        {
                            if (entry.extension[e] < 0x20 && entry.extension[e] != 0x00)
                            {
                                return(false);
                            }
                        }

                        if (!ArrayHelpers.ArrayIsNullOrWhiteSpace(entry.filename))
                        {
                            fileCount++;
                        }
                    }
                    else if (entry.statusUser == 0x20)
                    {
                        for (int f = 0; f < 8; f++)
                        {
                            if (entry.filename[f] < 0x20 && entry.filename[f] != 0x00)
                            {
                                return(false);
                            }
                        }

                        for (int e = 0; e < 3; e++)
                        {
                            if (entry.extension[e] < 0x20 && entry.extension[e] != 0x00)
                            {
                                return(false);
                            }
                        }

                        label             = Encoding.ASCII.GetString(directory, off + 1, 11).Trim();
                        labelCreationDate = new byte[4];
                        labelUpdateDate   = new byte[4];
                        Array.Copy(directory, off + 24, labelCreationDate, 0, 4);
                        Array.Copy(directory, off + 28, labelUpdateDate, 0, 4);
                    }
                    else if (entry.statusUser == 0x21)
                    {
                        if (directory[off + 1] == 0x00)
                        {
                            thirdPartyTimestamps = true;
                        }
                        else
                        {
                            standardTimestamps |= directory[off + 21] == 0x00 && directory[off + 31] == 0x00;
                        }
                    }
                }

                return(fileCount > 0);
            }
            catch { return(false); }
        }
예제 #2
0
        public bool FujitsuDisplay(out byte[] senseBuffer, bool flash, FujitsuDisplayModes mode, string firstHalf,
                                   string secondHalf, uint timeout, out double duration)
        {
            byte[] tmp;
            byte[] firstHalfBytes  = new byte[8];
            byte[] secondHalfBytes = new byte[8];
            byte[] buffer          = new byte[17];
            bool   displayLen      = false;
            bool   halfMsg         = false;

            byte[] cdb = new byte[10];

            if (!string.IsNullOrWhiteSpace(firstHalf))
            {
                tmp = Encoding.ASCII.GetBytes(firstHalf);
                Array.Copy(tmp, 0, firstHalfBytes, 0, 8);
            }

            if (!string.IsNullOrWhiteSpace(secondHalf))
            {
                tmp = Encoding.ASCII.GetBytes(secondHalf);
                Array.Copy(tmp, 0, secondHalfBytes, 0, 8);
            }

            if (mode != FujitsuDisplayModes.Half)
            {
                if (!ArrayHelpers.ArrayIsNullOrWhiteSpace(firstHalfBytes) &&
                    !ArrayHelpers.ArrayIsNullOrWhiteSpace(secondHalfBytes))
                {
                    displayLen = true;
                }
                else if (!ArrayHelpers.ArrayIsNullOrWhiteSpace(firstHalfBytes) &&
                         ArrayHelpers.ArrayIsNullOrWhiteSpace(secondHalfBytes))
                {
                    halfMsg = true;
                }
            }

            buffer[0] = (byte)((byte)mode << 5);
            if (displayLen)
            {
                buffer[0] += 0x10;
            }
            if (flash)
            {
                buffer[0] += 0x08;
            }
            if (halfMsg)
            {
                buffer[0] += 0x04;
            }
            buffer[0] += 0x01; // Always ASCII

            Array.Copy(firstHalfBytes, 0, buffer, 1, 8);
            Array.Copy(secondHalfBytes, 0, buffer, 9, 8);

            cdb[0] = (byte)ScsiCommands.FujitsuDisplay;
            cdb[6] = (byte)buffer.Length;

            LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.Out, out duration,
                                        out bool sense);
            Error = LastError != 0;

            DicConsole.DebugWriteLine("SCSI Device", "FUJITSU DISPLAY took {0} ms.", duration);

            return(sense);
        }