16
utFAT / ensuring a directory exists and is opened
« on: September 16, 2010, 07:55:43 PM »
I'm having trouble ensuring that a directory is present and opened. Here is the code I have:
Upon the second time calling this, the directory D:\CONF\CONF is created, but D:\CONF is opened.
I tried adding a statement before opening the directory to clear the VALID bit, but what that results in is the directory D:\CONF being created, but D:\ being opened.
I'm unsure how the directory argument to utOpenDirectory is used, I thought it was just a place to put the opened directory, but it appears to play a role in the relation of the directory to open. Plus, makeDirectory doesn't have any docs, so I'm not sure how it's used there either.
What I want is for this function to work even if someone has removed the directory between calls.
-Steve
Code: [Select]
static int openDirectory()
{
int result = UTFAT_SUCCESS;
if(sdDirectory == NULL)
{
sdDirectory = utAllocateDirectory(DISK_D, 0);
}
result = utOpenDirectory("/CONF", sdDirectory);
if(result == UTFAT_FILE_NOT_FOUND)
{
// need to create the directory
result = utMakeDirectory("/CONF", sdDirectory);
if(result == UTFAT_SUCCESS)
{
result = utOpenDirectory("/CONF", sdDirectory);
}
}
return result;
}
The first time this function is called, the directory D:\CONF is created and openedUpon the second time calling this, the directory D:\CONF\CONF is created, but D:\CONF is opened.
I tried adding a statement before opening the directory to clear the VALID bit, but what that results in is the directory D:\CONF being created, but D:\ being opened.
I'm unsure how the directory argument to utOpenDirectory is used, I thought it was just a place to put the opened directory, but it appears to play a role in the relation of the directory to open. Plus, makeDirectory doesn't have any docs, so I'm not sure how it's used there either.
What I want is for this function to work even if someone has removed the directory between calls.
-Steve