107,6 → 107,7 |
*/ |
|
|
|
/* |
________________________________________________________________________________________________________________________________________ |
|
683,7 → 684,7 |
} |
Partition.IsValid = 1; // mark data in partition structure as valid |
Partition.CurrentWorkingDirectory = Partition.FirstRootDirSector; |
strcpy(Partition.PathToCwd,"/"); |
strcpy(Partition.PathToCwd,"/"); |
result = 0; |
end: |
if(result != 0) Fat16_Deinit(); |
1498,6 → 1499,7 |
File_t * fopen_(s8 * const filename, const s8 mode) |
{ |
File_t *file = 0; |
s8 *cptr; |
|
if((!Partition.IsValid) || (filename == 0)) return(file); |
|
1520,6 → 1522,15 |
file->DirectoryIndex = 0; // the index to the directoryentry within the specified sector. |
file->Attribute = 0; // the attribute of the file opened. |
|
// bring the path into the correct syntax |
cptr = filename; |
// search the whole string |
while(*cptr != 0) |
{ |
// replace all '\' by '/' |
if(*cptr == '\\') *cptr = '/'; |
cptr++; |
} |
// check if a real file (no directory) to the given filename exist |
if(FileExist(filename, ATTR_NONE, ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL, file)) |
{ // file exist |
2454,18 → 2465,29 |
Find_t fe; // The findelement needed for function findfirst to find the subdirectoryentry |
s8 tp[256]; // temporarily we remember the actual path until the operation has finished successfully |
u32 cwdt = 0; |
s8 *cptr; |
|
/* bring the path into the correct syntax */ |
cptr = path; |
/* search the whole string */ |
while(*cptr != 0) |
{ |
if(*cptr == '\\') *cptr = '/'; |
cptr++; |
} |
/* lets remember the actual path */ |
strcpy(tp, Partition.PathToCwd); |
cwdt = Partition.CurrentWorkingDirectory; |
/* how many subdirectories are there within the path? */ |
dircount = GetDirCount(path); |
/* if the path is absolute we begin at the rootdirectory */ |
if(path[0] == '/') |
{ |
strcpy(Partition.PathToCwd, "/"); |
Partition.CurrentWorkingDirectory = Partition.FirstRootDirSector; |
/* if there is no other pathinformation we only switch to the rootdirectory. So theres nothing left todo.*/ |
if(!dircount) return(1); |
} |
/* how many subdirectories are there within the path? */ |
dircount = GetDirCount(path); |
/* now we parse through all the subdirectories within the path */ |
do |
{ |
2507,98 → 2529,3 |
} |
return(retvalue); |
} |
|
|
|
void Test(void) |
{ |
Find_t find; |
text[64]; |
|
UART1_PutString("\r\nsearching for elements in CWD:"); |
UART1_PutString(GetPath()); |
|
if(chdir_("log")) |
{ |
UART1_PutString(" done"); |
UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath()); |
|
if(chdir_("log11")) |
{ |
UART1_PutString(" done"); |
UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath()); |
|
if(chdir_("log12")) |
{ |
UART1_PutString(" done"); |
UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath()); |
|
if(findfirst_("*.*", 0xff, &find)) |
{ |
sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text); |
while(findnext_(&find)) |
{ |
sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text); |
} |
} |
if(chdir_(".")) |
{ |
UART1_PutString(" done"); |
UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath()); |
if(findfirst_("*.*", 0xff, &find)) |
{ |
sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text); |
while(findnext_(&find)) |
{ |
sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text); |
} |
} |
} |
else UART1_PutString(" failed"); |
if(chdir_("..")) |
{ |
UART1_PutString(" done"); |
UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath()); |
if(findfirst_("*.*", 0xff, &find)) |
{ |
sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text); |
while(findnext_(&find)) |
{ |
sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text); |
} |
} |
} |
else UART1_PutString(" failed"); |
if(chdir_("..")) |
{ |
UART1_PutString(" done"); |
UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath()); |
if(findfirst_("*.*", 0xff, &find)) |
{ |
sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text); |
while(findnext_(&find)) |
{ |
sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text); |
} |
} |
} |
else UART1_PutString(" failed"); |
if(chdir_("..")) |
{ |
UART1_PutString(" done"); |
UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath()); |
if(findfirst_("*.*", 0xff, &find)) |
{ |
sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text); |
while(findnext_(&find)) |
{ |
sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text); |
} |
} |
} |
else UART1_PutString(" failed"); |
} |
} |
} |
else UART1_PutString(" failed"); |
} |