Thanx so much.
Sorry for my long code. I´ll post my fat.c it is at begnning but I would like to share...
Code: Select all
#include <defines.h>
#include <fat.h>
#include <x86.h>
#include <cpux86.h>
#include <main.h>
#include <ide.h>
UCHAR *PartType[] = {"00",
"01 FAT12",
"02 XENIX root",
"03 XENIX usr",
"04 FAT16 <32M",
"05 Extended",
"06 FAT16",
"07 HPFS/NTFS",
"08 AIX",
"09 AIX bootable",
"0A OS/2 Boot Manager",
"0B WIN95 OSR2 FAT32",
"0C WIN95 OSR2 FAT32, LBA-mapped",
"0D SILICON SAFE",
"0E WIN95: DOS 16-bit FAT, LBA-mapped",
"0F WIN95: Extended partition, LBA-mapped",
"10 OPUS",
"11 Hidden DOS 12-bit FAT",
"12 Compaq diagnost",
"13",
"14 Hidden DOS 16-bit FAT <32M",
"15",
"16 Hidden DOS 16-bit FAT >=32M",
"17 Hidden IFS (e.g., HPFS)",
"18 AST SmartSleep Partition",
"19", "1A",
"1B Hidden WIN95 OSR2 FAT32",
"1C Hidden WIN95 OSR2 FAT32, LBA-mapped",
"1D",
"1E Hidden WIN95 16-bit FAT, LBA-mapped",
"1F", "20", "21", "22", "23",
"24 NEC DOS",
"25", "26",
"27 Windows RE hidden partition",
"28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38",
"39 Plan 9",
"3A", "3B",
"3C PartitionMagic",
"3D", "3E", "3F",
"40 Venix 80286",
"41 PPC PReP Boot",
"42 SFS (Secure Filesystem)",
"43", "44", "45", "46", "47", "48", "49", "4A", "4B", "4C",
"4D QNX4.x",
"4E QNX4.x 2nd part",
"4F QNX4.x 3rd part",
"50 OnTrack DM",
"51 OnTrack DM6 Aux",
"52 CP/M",
"53 OnTrack DM6 Aux",
"54 OnTrackDM6",
"55 EZ-Drive",
"56 Golden Bow",
"57", "58", "59", "5A", "5B",
"5C Priam Edisk",
"5D", "5E", "5F", "60",
"61 SpeedStor",
"62",
"63 GNU HURD or Sys",
"64 Novell Netware",
"65 Novell Netware",
"66", "67", "68", "69", "6A", "6B", "6C", "6D", "6E", "6F",
"70 DiskSecure Mult",
"71", "72", "73", "74",
"75 PC/IX",
"76", "77", "78", "79", "7A", "7B", "7C", "7D", "7E", "7F",
"80 Old Minix",
"81 Minix / old Lin",
"82 Linux swap / So",
"83 Linux",
"84 OS/2 hidden C:",
"85 Linux extended",
"86 NTFS volume set",
"87 NTFS volume set",
"88 Linux plein tex",
"89", "8A", "8B", "8C", "8D",
"8E Linux LVM",
"8F", "90", "91", "92",
"93 Amoeba",
"94 Amoeba BBT",
"95", "96", "97", "98", "99", "9A", "9B", "9C", "9D", "9E",
"9F BSD/OS",
"A0 IBM Thinkpad hi",
"A1", "a2", "a3", "a4",
"A5 FreeBSD",
"A6 OpenBSD",
"A7 NeXTSTEP",
"A8 UFS Darwin",
"A9 NetBSD",
"AA",
"AB Amorce Darwin",
"AC", "AD", "AE", "AF", "B0", "B1", "B2", "B3", "B4", "B5", "B6",
"B7 BSDI fs",
"B8 BSDI swap",
"B9", "ba",
"BB Boot Wizard hid",
"BC", "BD",
"BE Amorce Solaris",
"BF Solaris",
"C0",
"C1 DRDOS/sec (FAT-",
"C2", "C3",
"C4 DRDOS/sec (FAT-",
"C5",
"C6 DRDOS/sec (FAT-",
"C7 Syrinx",
"C8", "C9", "CA", "CB", "CC", "CD", "CE", "CF", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9",
"DA Non-FS data",
"DB CP/M / CTOS / .",
"DC", "dd",
"DE Dell Utility",
"DF BootIt",
"E0",
"E1 DOS access",
"E2",
"E3 DOS R/O",
"E4 SpeedStor",
"E5", "E6", "E7", "E8", "E9", "EA",
"EB BeOS fs",
"EC", "ED",
"EE GPT",
"EF EFI (FAT-12/16/",
"F0 Linux/PA-RISC b",
"F1 SpeedStor",
"F2 DOS secondary",
"F3",
"F4 SpeedStor",
"F5", "F6", "F7", "F8", "F9", "FA",
"FB VMware VMFS",
"FC VMware VMKCORE",
"FD Linux raid auto",
"FE LANstep",
"FF BBT"};
tFATBootSector bpb;
tFATBootSector bpb2;
ULONG RootDirSectors;
ULONG FirstDataSector;
ULONG FirstSectorofCluster;
ULONG DataSec;
ULONG TotSec;
ULONG CountofClusters;
ULONG ThisFATSecNum;
ULONG ThisFATEntOffset;
ULONG FirstRootDirSecNum;
union REGS regsin;
union REGS regsout;
USHORT CylinderInicial;
USHORT CylinderFinal;
UCHAR HeadInicial;
UCHAR HeadFinal;
UCHAR SectorInicial;
UCHAR SectorFinal;
UCHAR VolumeLabel[12];
UCHAR FileSystemType[9];
ULONG RootEntriesCount;
USHORT BytesPerSector;
ULONG ReservedSectorsCount;
UCHAR SectorsPerCluster;
ULONG FATSz;
USHORT NumFATs;
ULONG TotSec;
USHORT cyls;
UCHAR heads;
UCHAR secs;
UCHAR FATType;
ULONG FATOffset;
USHORT FAT16ClusEntryVal;
ULONG FAT32ClusEntryVal;
UCHAR X;
ULONG RootClusterNo;
ULONG Cluster;
ULONG NextCluster;
THDPARAM hdparam;
TDIR dir[128];
UCHAR buff01[512];
UCHAR buff02[512];
UCHAR SecBuff[512];
short r;
TPART *tpart1;
TPART *tpart2;
TPART *tpart3;
TPART *tpart4;
TDIRStruct DirStruct[256];
TLONGDIRNameStruct LongDirStruct;
UCHAR BootDrive;
TDIRLIST DirList[1000];
UCHAR Diretorio_Atual[12] = {"/"};
short read_sector(USHORT cylinder, UCHAR head, UCHAR sector, UCHAR drive, UCHAR* buff)
{
memset(®sin, 0, sizeof(union REGS));
memset(®sout, 0, sizeof(union REGS));
UCHAR c = (cylinder & 255);
UCHAR h = head;
UCHAR s = ((cylinder & 768) >> 8) | (sector & 63);
int attempts = 5;
while (attempts--) {
regsin.h.ah = 0x02;
regsin.h.al = 1;
regsin.h.ch = c;
regsin.h.cl = s;
regsin.h.dh = h;
regsin.h.dl = drive;
regsin.x.bx = 0x0000; // 0x0500;
regsin.d.es = 0x07E0;
regsin.x.bp = 0xffff;
regsin.d.cs = regsin.d.ds = regsin.d.fs = regsin.d.gs = regsin.d.ss = 0x9000;
int86x (0x13, ®sin, ®sout);
if (regsout.h.ah != 0 && regsout.h.ah != 11)
hd_reset(drive);
if (regsout.h.ah == 0) break;
}
if (regsout.h.ah == 0 && regsout.h.al == 1) {
UCHAR *buffer = (void*)0x7E00;//0x500;
memset(buff, 0, 512);
memcpy(buff, buffer, 512);
return regsout.h.ah;
} else {
return regsout.h.ah;
}
}
short read_sectorLBA(UCHAR Disk, ULONG LBA, USHORT Setores, UCHAR* Buff) {
USHORT I;
ULONG CheckSum;
UCHAR BUFF[512];
memset(®sin, 0, sizeof(union REGS));
memset(®sout, 0, sizeof(union REGS));
TDAPACK tdapack;
memset(&tdapack, 0, sizeof(TDAPACK));
tdapack.Size = sizeof(TDAPACK); // Size of packet (16 bytes)
tdapack.Reserved = 0; // Always 0
tdapack.Sectors = Setores; // Number of sectors to transfer (max 127 on some BIOSes)
tdapack.Buffer = FP_TO_LINEAR(0x0800, 0x0000); // Address of Buff
tdapack.LoLBA = LBA; // LBA 00..31
tdapack.HiLBA = 0; // LBA 32..63
memcpy(0x7E00, &tdapack, sizeof(TDAPACK));
int attempts = 5;
while (attempts--) {
regsin.h.ah = 0x42;
regsin.h.dl = Disk;
regsin.x.si = 0x0000; //0x0500;
regsin.d.ds = 0x07E0; // 0x0000;
regsin.x.bp = 0xffff;
regsin.d.cs = regsin.d.es = regsin.d.fs = regsin.d.gs = regsin.d.ss = 0x0900;
int86x (0x13, ®sin, ®sout);
if (regsout.h.ah != 0 && regsout.h.ah != 0x11)
hd_reset(Disk);
if (regsout.h.ah == 0) {
memset(&BUFF, 0, 512);
CheckSum = 0;
memcpy(&BUFF, 0x8000, 512 * Setores);
for (I=0;I<512;I++) {
CheckSum += BUFF[I];
}
if (CheckSum == 0) break;
}
}
if (regsout.h.ah == 0) {
memset(Buff, 0, 512 * Setores);
memcpy(Buff, 0x8000, 512 * Setores);
}
return regsout.h.ah;
}
short read_sectorsLBA(UCHAR Disk, ULONG LBA, USHORT Setores, UCHAR* Buff) {
USHORT SectorsToRead = 0;
USHORT PlusOffset = 0;
while (SectorsToRead < Setores) {
read_sectorLBA(Disk, LBA+SectorsToRead, Setores, Buff+PlusOffset);
PlusOffset += 512;
SectorsToRead += 1;
}
}
void BIOS_LBA2CHS (tFATBPB* pBPB, ULONG LBA, USHORT* pCylinder, UCHAR* pHead, UCHAR* pSector)
{
ULONG tmp = LBA / pBPB->BPB1.SectorsPerTrack;
*pSector = (LBA % pBPB->BPB1.SectorsPerTrack) + 1;
*pCylinder = tmp / pBPB->BPB1.HeadsPerCylinder;
*pHead = tmp % pBPB->BPB1.HeadsPerCylinder;
}
char hdtable_init(UCHAR drive)
{
memset(®sin, 0, sizeof(union REGS));
memset(®sout, 0, sizeof(union REGS));
regsin.h.al = 0x09;
regsin.h.dl = drive;
regsin.x.bp = 0xffff;
regsin.d.cs = regsin.d.es = regsin.d.ds = regsin.d.fs = regsin.d.gs = regsin.d.ss = 0x9000;
int86x (0x13, ®sin, ®sout);
return regsout.h.ah;
}
int hd_reset(UCHAR Drive)
{
union REGS inregs, outregs;
inregs.h.ah = 0x00;
inregs.h.dl = Drive;
inregs.x.bp = 0xffff;
inregs.d.cs = inregs.d.ds = inregs.d.fs = inregs.d.gs = inregs.d.ss = 0x9000;
int86x (0x13, &inregs, &outregs);
return !outregs.x.eflags;
}
void showPartitions(char Show) {
if (Show) {
sprintf("Particao=01, drive=0x%02X, tipo=0x%02X - %s\n", tpart1->MarcadeInicializacao, tpart1->TipodaParticao, PartType[tpart1->TipodaParticao]);
sprintf("Particao=02, drive=0x%02X, tipo=0x%02X - %s\n", tpart2->MarcadeInicializacao, tpart2->TipodaParticao, PartType[tpart2->TipodaParticao]);
sprintf("Particao=03, drive=0x%02X, tipo=0x%02X - %s\n", tpart3->MarcadeInicializacao, tpart3->TipodaParticao, PartType[tpart3->TipodaParticao]);
sprintf("Particao=04, drive=0x%02X, tipo=0x%02X - %s\n", tpart4->MarcadeInicializacao, tpart4->TipodaParticao, PartType[tpart4->TipodaParticao]);
}
}
void showBPBParams01(char Show)
{
if (Show)
{
printf("Bytes per Sector %d\n", BytesPerSector);
printf("Sectors per Cluster %d\n", SectorsPerCluster);
printf("Number of reserved sectors %d\n", ReservedSectorsCount);
printf("Number of FATS %d\n", NumFATs);
printf("Root entries Count %d\n", RootEntriesCount);
}
}
void showBPBParams02(char Show)
{
if (Show)
{
printf("RootDirSectors.........: %d\n", RootDirSectors);
printf("FirstDataSector........: %d\n", FirstDataSector);
printf("FirstSectorofCluster...: %d\n", FirstSectorofCluster);
printf("TotSec.................: %d\n", TotSec);
printf("DataSec................: %d\n", DataSec);
printf("CountofClusters........: %d\n", CountofClusters);
printf("FirstRootDirSecNum.....: %d\n", FirstRootDirSecNum);
printf("ThisFATSecNum..........: %d\n", ThisFATSecNum);
printf("ThisFATEntOffset.......: %d\n", ThisFATEntOffset);
printf("RootDirectoryClusterNo.: %d\n", bpb.BPB.BPB2.FAT32.RootDirectoryClusterNo);
}
}
char read_bpb(UCHAR drive)
{
hdtable_init(drive);
get_hd_param(drive, &hdparam);
getPartitions();
r = read_sector(0, 0, 1, drive, &buff01);
if (!r)
{
HeadInicial = tpart1->HeadInicial;
SectorInicial = (tpart1->SectorInicial & 63);
CylinderInicial = ((tpart1->SectorInicial & 192) << 2) | tpart1->CylinderInicial;
HeadFinal = tpart1->HeadFinal;
SectorFinal = (tpart1->SectorFinal & 63);
CylinderFinal = ((tpart1->SectorFinal & 192) << 2) | tpart1->CylinderFinal;
ULONG LBA = ((CylinderInicial*heads) + HeadInicial) * (secs+(SectorInicial-1));
showPartitions(0);
//r = read_sectorLBA(drive, tpart1->LBAInicial, 1, &bpb);
r = read_sectorLBA(drive, tpart1->LBAInicial, 1, &bpb);
if (!r)
{
memset(VolumeLabel, 0, 12);
memcpy(VolumeLabel, bpb.BPB.BPB2.FAT32.VolumeLabel, 11);
VolumeLabel[11] = '\0';
memset(FileSystemType, 0, 9);
memcpy(FileSystemType, bpb.BPB.BPB2.FAT32.FileSystemName, 8);
FileSystemType[8] = '\0';
RootEntriesCount = bpb.BPB.BPB1.RootEntriesCount;
BytesPerSector = bpb.BPB.BPB1.BytesPerSector;
ReservedSectorsCount = bpb.BPB.BPB1.ReservedSectorsCount;
NumFATs = bpb.BPB.BPB1.NumberOfFATs;
SectorsPerCluster = bpb.BPB.BPB1.SectorsPerCluster;
showBPBParams01(0);
if (bpb.BPB.BPB1.SectorsPerFAT1x != 0)
FATSz = bpb.BPB.BPB1.SectorsPerFAT1x;
else
FATSz = bpb.BPB.BPB2.FAT32.SectorsPerFAT32;
if (bpb.BPB.BPB1.TotalSectorsCount16 != 0)
TotSec = bpb.BPB.BPB1.TotalSectorsCount16;
else
TotSec = bpb.BPB.BPB1.TotalSectorsCount32;
RootClusterNo = bpb.BPB.BPB2.FAT32.RootDirectoryClusterNo;
RootDirSectors = ((RootEntriesCount * 32) + (BytesPerSector - 1)) / BytesPerSector;
DataSec = TotSec - (ReservedSectorsCount + (NumFATs * FATSz) + RootDirSectors);
CountofClusters = DataSec / SectorsPerCluster;
getFATType();
// Note that on a FAT32 volume, the BPB_RootEntCnt value is always 0; so on a FAT32 volume,
// RootDirSectors is always 0.
if (FATType == fat32)
{
RootEntriesCount = 0;
RootDirSectors = 0;
}
}
}
}
void getPartitions(void) {
tpart1 = (void*)&buff01+0x1BE;
tpart2 = (void*)&buff01+0x1CE;
tpart3 = (void*)&buff01+0x1DE;
tpart4 = (void*)&buff01+0x1EE;
}
char get_hd_param(UCHAR drive, THDPARAM *hdparam)
{
memset(®sin, 0, sizeof(union REGS));
memset(®sout, 0, sizeof(union REGS));
regsin.h.ah = 0x48;
regsin.h.dl = drive;
regsin.x.si = 0x0000; //0x0500;
regsin.d.ds = 0x07E0;
regsin.x.bp = 0xffff;
regsin.d.cs = regsin.d.es = regsin.d.fs = regsin.d.gs = regsin.d.ss = 0x9000;
int86x (0x13, ®sin, ®sout);
if (regsout.h.ah == 0)
{
THDPARAM * hdpar = (THDPARAM *)0x7E00;//0x0500;
memcpy(hdparam, hdpar, hdpar->BufferSize);
cyls = hdparam->Cylinders;
heads = hdparam->Heads;
secs = hdparam->SectorsPerTrack;
}
return regsout.h.ah;
}
UCHAR *get_dir_name(UCHAR *dnEntrie, UCHAR *filename)
{
UCHAR n = 0;
memset(filename, 0, 12);
for (UCHAR i = 0; i < 11; i++)
{
if (i == 8 && dnEntrie[i+1] != 0 && dnEntrie[i] != ' ')
filename[n++] = '.';
if (dnEntrie[i] != 0 && dnEntrie[i] != ' ')
filename[n++] = dnEntrie[i];
}
filename[n] = '\0';
}
UCHAR getFATType(void)
{
if (CountofClusters < 4085) {
FATType = fat12;
} else if(CountofClusters < 65525) {
FATType = fat16;
} else {
FATType = fat32;
}
}
ULONG getLBA(ULONG cluster)
{
RootDirSectors = ((RootEntriesCount * 32) + (BytesPerSector - 1)) / BytesPerSector;
FirstDataSector = ReservedSectorsCount + (NumFATs * FATSz) + RootDirSectors;
FirstSectorofCluster = ((cluster-2) * SectorsPerCluster) + FirstDataSector;
return tpart1->LBAInicial+FirstSectorofCluster;
}
ULONG getFATEntrie(UCHAR Drive, ULONG Cluster)
{
if (FATType == 16)
FATOffset = Cluster * 2;
else if (FATType == 32)
FATOffset = Cluster * 4;
ThisFATSecNum = ReservedSectorsCount + (FATOffset / BytesPerSector);
ThisFATEntOffset = (FATOffset % BytesPerSector);
ThisFATSecNum += tpart1->LBAInicial; // <- Relativo ao inicio da Partição!
/*sprintf("\nThisFATSecNum %d NumberOfFATs %d SectorsPerFAT %d FATSz %d\n",
ThisFATSecNum,
bpb.BPB.BPB1.NumberOfFATs,
bpb.BPB.BPB2.FAT32.SectorsPerFAT32,
FATSz);
*/
//r = read_sectorLBA(Drive, ThisFATSecNum, 1, (UCHAR*)&SecBuff);
r = read_sectorLBA(Drive, ThisFATSecNum, 1, SecBuff);
if (!r)
{
if (FATType == 16)
FAT16ClusEntryVal = *((USHORT *) &SecBuff[ThisFATEntOffset]);
else
FAT32ClusEntryVal = (*((ULONG *) &SecBuff[ThisFATEntOffset])) & 0x0FFFFFFF;
}
else
{
sprintf("Erro ao ler FAT, codigo de erro: 0x%02X\n", r);
return -1;
}
return FAT32ClusEntryVal;
}
fprintf(ULONG n)
{
USHORT n1 = n % 1000;
USHORT n2 = (n % 1000000) / 1000;
USHORT n3 = n / 1000000;
if (n3 > 0)
printf("%d.", n3);
if (n2 > 0)
printf("%d.", n2);
printf("%d", n1);
}
char list_dir(UCHAR Drive, UCHAR *parametros) {
printf("O Volume na Unidade e %s\n", VolumeLabel);
printf("O Numero de Serie da unidade e %x-%x\n", ((bpb.BPB.BPB2.FAT32.VolumeSerialNumber & 0xFFFF0000) >> 16), ((bpb.BPB.BPB2.FAT32.VolumeSerialNumber & 0xFFFF)));
printf("O Tipo do sistema de arquivos e %s\n", FileSystemType);
USHORT i;
USHORT Arquivos;
USHORT Pastas;
ULONG TotalUtilizado;
ULONG TotalDisponivel;
USHORT l;
i = 0;
l = 0;
Arquivos = 0;
Pastas = 0;
TotalUtilizado = 0;
TotalDisponivel = CountofClusters * SectorsPerCluster * BytesPerSector;
while (DirList[i].in_use == 1) {
if (DirList[i].is_dir == 1) {
if (DirList[i].ShortName[0] != 0) {
sprintf("\n%12s <DIR>", DirList[i].ShortName);
sprintf(" %02d/%02d/%04d %02d:%02d",
DirList[i].Days,
DirList[i].Months,
DirList[i].Years,
DirList[i].Hours,
DirList[i].Minutes,
DirList[i].Seconds);
Pastas++;
}
} else {
if (DirList[i].ShortName[0] != 0) {
sprintf("\n%12s", DirList[i].ShortName);
sprintf(" %02d/%02d/%04d %02d:%02d",
DirList[i].Days,
DirList[i].Months,
DirList[i].Years,
DirList[i].Hours,
DirList[i].Minutes,
DirList[i].Seconds);
sprintf(" %f", DirList[i].FileSize);
TotalUtilizado += DirList[i].FileSize;
Arquivos++;
}
}
i++;
l++;
if (i >= 1000) break;
if (strcmp((UCHAR*)parametros, "|more") == 0) {
if (l == 23) {
l = 0;
puts("\nPressione qualquer tecla para continuar...");
//readkey();
puts("\n");
}
}
}
sprintf("\n %d Arquivo(s) %f bytes\n %d Pastas %f bytes disponiveis\n", Arquivos, TotalUtilizado, Pastas, TotalDisponivel-TotalUtilizado);
}
void Setup_FAT(UCHAR drive) {
read_bpb(drive);
BootDrive = drive;
read_root();
}
char read_root(void) {
change_dir("/"); // Iremos ler o diretório principal!
}
char change_dir(UCHAR *procura) {
USHORT Index;
ULONG LBACluster;
ULONG NextCluster;
UCHAR p[15];
memset(&p, 0, sizeof(p));
upper(&p, procura);
Index = 0;
if (strcmp((UCHAR*)p, "/") == 0) {
RootClusterNo = bpb.BPB.BPB2.FAT32.RootDirectoryClusterNo;
LBACluster = getLBA(RootClusterNo);
NextCluster = 0;
} else {
Index = 0;
while (1) {
if (strcmp((UCHAR*)DirList[Index].ShortName, (UCHAR*)p) == 0) {
break; // Encontramos o diretório
} else {
Index++;
}
if (Index >= 1000) break;
}
if (strcmp((UCHAR*)DirList[Index].ShortName, (UCHAR*)p) == 0) {
if (DirList[Index].FirstClusterNo == 0) {
RootClusterNo = bpb.BPB.BPB2.FAT32.RootDirectoryClusterNo;
} else {
RootClusterNo = DirList[Index].FirstClusterNo;
}
LBACluster = getLBA(RootClusterNo);
NextCluster = 0;
} else {
return -1;
}
}
Index = 0;
memset(&DirList, 0, sizeof(DirList));
while (RootClusterNo != 0x0FFFFFF8)
{
memset((UCHAR*)&DirStruct, 0, sizeof(DirStruct));
// r = read_sectorLBA(BootDrive, LBACluster, SectorsPerCluster, (UCHAR*)&DirStruct);
r = read_sectorLBA(BootDrive, LBACluster, SectorsPerCluster, DirStruct);
if (!r)
{
UCHAR ShortName[12];
UCHAR LongName[260];
UCHAR LngEnt = 0;
UCHAR n = 0;
memset(&LongName, 0, sizeof(LongName));
for (UCHAR i=0; i<128; i++)
{
if (DirStruct[i].DIR_Attr == 0x08) {
get_dir_name(DirStruct[i].DIR_Name, ShortName);
memcpy(VolumeLabel, ShortName, sizeof(ShortName));
}
if ((DirStruct[i].DIR_Name[0] != 0xE5) &&
(DirStruct[i].DIR_Attr != 0x08) &&
(DirStruct[i].DIR_Attr != 0x0F) &&
(DirStruct[i].DIR_Attr != 0x0))
{
get_dir_name(DirStruct[i].DIR_Name, ShortName);
if (DirStruct[i].DIR_Attr & 0x10)
{
memcpy(DirList[Index].ShortName, ShortName, sizeof(ShortName));
DirList[Index].Attrib = DirStruct[i].DIR_Attr;
DirList[Index].Days = DirStruct[i].CrtDate.Days;
DirList[Index].Months = DirStruct[i].CrtDate.Months;
DirList[Index].Years = DirStruct[i].CrtDate.Years + 1980;
DirList[Index].Hours = DirStruct[i].CrtTime.Hours;
DirList[Index].Minutes = DirStruct[i].CrtTime.Minutes;
DirList[Index].Seconds = DirStruct[i].CrtTime.Seconds;
DirList[Index].FileSize = DirStruct[i].DIR_FileSize;
DirList[Index].FirstClusterNo = ((DirStruct[i].DIR_FstClusHI << 16) | DirStruct[i].DIR_FstClusLO);
DirList[Index].is_dir = 1;
DirList[Index].in_use = 1;
Index++;
}
else
{
memcpy(DirList[Index].ShortName, ShortName, sizeof(ShortName));
DirList[Index].Attrib = DirStruct[i].DIR_Attr;
DirList[Index].Days = DirStruct[i].CrtDate.Days;
DirList[Index].Months = DirStruct[i].CrtDate.Months;
DirList[Index].Years = DirStruct[i].CrtDate.Years + 1980;
DirList[Index].Hours = DirStruct[i].CrtTime.Hours;
DirList[Index].Minutes = DirStruct[i].CrtTime.Minutes;
DirList[Index].Seconds = DirStruct[i].CrtTime.Seconds;
DirList[Index].FileSize = DirStruct[i].DIR_FileSize;
DirList[Index].FirstClusterNo = ((DirStruct[i].DIR_FstClusHI << 16) | DirStruct[i].DIR_FstClusLO);
DirList[Index].is_dir = 0;
DirList[Index].in_use = 1;
Index++;
}
}
}
if (RootClusterNo != 0xFFFFFFF) // Ultimo cluster, nada mais a ser lido do disco.
{
RootClusterNo = getFATEntrie(BootDrive, RootClusterNo);
if (RootClusterNo != 0x0FFFFFF8)
LBACluster = getLBA(NextCluster);
NextCluster = RootClusterNo;
}
else
{
break;
}
} else {
sprintf("\nERRO: read_sectorLBA 0x%02X\nPressione qualquer tecla para continuar...", r);
//readkey();
puts("\n");
break;
}
}
return 1;
}
char find_file(UCHAR *nome)
{
}
char find_attr(UCHAR attr)
{
}
char set_label(UCHAR *nome)
{
}
char rename_file(UCHAR *dest, UCHAR *src)
{
}
char delete_file(UCHAR *nome)
{
}
char mkdir(UCHAR *nome)
{
}
long cat_file(UCHAR Drive, UCHAR *procura)
{
USHORT Index;
ULONG LBACluster;
ULONG NextCluster;
UCHAR p[15];
memset(&p, 0, sizeof(p));
upper(&p, procura);
Index = 0;
while (1) {
if (strcmp((UCHAR*)DirList[Index].ShortName, (UCHAR*)p) == 0) {
break; // Encontramos o arquivo
} else {
Index++;
}
if (Index >= 1000) break;
}
if (strcmp((UCHAR*)DirList[Index].ShortName, (UCHAR*)p) == 0) {
if (DirList[Index].is_dir == 1) return 0;
RootClusterNo = DirList[Index].FirstClusterNo;
LBACluster = getLBA(RootClusterNo);
NextCluster = 0;
} else {
return -1; // Não encontrado!
}
UCHAR Buffer[512];
ULONG C;
C = 0;
ULONG CheckSum;
USHORT i;
while (NextCluster != 0x0FFFFFF8)
{
r = read_sectorLBA(Drive, LBACluster, SectorsPerCluster, Buffer);
if (!r)
{
for(i = 0; i < 512; i++)
{
putch(Buffer[i]);
}
C += 512;
if (RootClusterNo != 0xFFFFFFF) // Ultimo cluster, nada mais a ser lido do disco.
{
RootClusterNo = getFATEntrie(Drive, RootClusterNo);
if (RootClusterNo >= 0x0FFFFFF8) break;
if (RootClusterNo != 0x0FFFFFF8)
LBACluster = getLBA(RootClusterNo);
NextCluster = RootClusterNo;
} else {
break;
}
} else {
sprintf("\nERRO: read_sectorLBA 0x%02X\nPressione qualquer tecla para continuar...", r);
puts("\n");
break;
}
}
return C;
}
long load_file_into_memory(UCHAR Drive, UCHAR *filename, UCHAR *addr) {
USHORT Index;
ULONG LBACluster;
ULONG NextCluster;
UCHAR p[15];
memset(&p, 0, sizeof(p));
upper(&p, filename);
Index = 0;
while (1) {
if (strcmp((UCHAR*)DirList[Index].ShortName, (UCHAR*)p) == 0) {
break; // Encontramos o diretório
} else {
Index++;
}
if (Index >= 1000) break;
}
if (strcmp((UCHAR*)DirList[Index].ShortName, (UCHAR*)p) == 0) {
if (DirList[Index].is_dir == 1) return 0;
RootClusterNo = DirList[Index].FirstClusterNo;
LBACluster = getLBA(RootClusterNo);
NextCluster = 0;
} else {
return -1; // Não encontrado!
}
ULONG C;
C = 0;
UCHAR Buffer[512];
USHORT i;
ULONG CheckSum;
while (NextCluster != 0x0FFFFFF8)
{
r = read_sectorLBA(Drive, LBACluster, SectorsPerCluster, Buffer);
if (!r)
{
memcpy((UCHAR*)addr+C, (UCHAR*)&Buffer, 512);
C += 512;
if (RootClusterNo != 0xFFFFFFF) // Ultimo cluster, nada mais a ser lido do disco.
{
RootClusterNo = getFATEntrie(Drive, RootClusterNo);
if (RootClusterNo >= 0x0FFFFFF8) break;
if (RootClusterNo != 0x0FFFFFF8)
LBACluster = getLBA(RootClusterNo);
NextCluster = RootClusterNo;
} else {
break;
}
} else {
sprintf("\nERRO: read_sectorLBA 0x%02X\nPressione qualquer tecla para continuar...", r);
puts("\n");
break;
}
}
return C;
}
ULONG fopen(UCHAR *arquivo) {
}
ULONG fclose(UCHAR arquivo) {
}
ULONG fread(UCHAR arquivo, UCHAR *buffer, ULONG n) {
}
ULONG fwrite(UCHAR arquivo, UCHAR *buffer, ULONG n) {
}
ULONG getfilesize(UCHAR *filename) {
USHORT Index;
ULONG LBACluster;
ULONG NextCluster;
UCHAR p[15];
memset(&p, 0, sizeof(p));
upper(&p, filename);
Index = 0;
while (1) {
if (strcmp((UCHAR*)DirList[Index].ShortName, (UCHAR*)p) == 0) {
break; // Encontramos o diretório
} else {
Index++;
}
if (Index >= 1000) break;
}
if (strcmp((UCHAR*)DirList[Index].ShortName, (UCHAR*)p) == 0) {
if (DirList[Index].is_dir == 1) return 0;
RootClusterNo = DirList[Index].FirstClusterNo;
LBACluster = getLBA(RootClusterNo);
NextCluster = 0;
return DirList[Index].FileSize;
} else {
return -1; // Não encontrado!
}
}