BOOL IsRootDirPosition(RDWRHandle handle, struct DirectoryPosition* pos) { struct DirectoryPosition pos1; unsigned short NumberOfRootEntries; assert(pos->sector && (pos->offset < 16)); NumberOfRootEntries = GetNumberOfRootEntries(handle); if (NumberOfRootEntries == 0) return FALSE; /* Strange, but ultimately correct */ if (!GetRootDirPosition(handle, NumberOfRootEntries-1, &pos1)) RETURN_FTEERR(-1); if (pos->sector < pos1.sector) return TRUE; return ((pos->sector == pos1.sector) && (pos->offset <= pos1.offset)); }
static BOOL CleanRootDir(RDWRHandle handle) { unsigned short NumberOfRootEntries, i; struct DirectoryEntry entry; memset(&entry, 0, sizeof(struct DirectoryEntry)); NumberOfRootEntries = GetNumberOfRootEntries(handle); if (!NumberOfRootEntries) return FALSE; for (i = NumberOfRootEntries-1;; i--) { if (!WriteDirEntry(handle, i, &entry)) return FALSE; if (i == 0) break; } return TRUE; }
static long CountEntriesInRootDirectory(RDWRHandle handle, char attribute) { long count = 0, i; struct DirectoryEntry* entry; long rootcount = GetNumberOfRootEntries(handle); if (!rootcount) return FAIL; entry = AllocateDirectoryEntry(); if (!entry) return FAIL; for (i = 0; i < rootcount; i++) { if (!ReadDirEntry(handle, i, entry)) { FreeDirectoryEntry(entry); return FAIL; } if (IsLastLabel(*entry)) { FreeDirectoryEntry(entry); return count; } if (entry->attribute == LFN_ATTRIBUTES) { if (IsLFNEntry(entry)) count++; } else if ((entry->attribute & attribute) || (attribute == -1)) { count++; } } FreeDirectoryEntry(entry); return rootcount; }
static BOOL AddToRootDir(RDWRHandle handle, CLUSTER cluster, unsigned long filesize) { struct DirectoryEntry entry; static unsigned short index = 0; unsigned short NumberOfRootEntries = GetNumberOfRootEntries(handle); if (index < NumberOfRootEntries) { FillNewEntry(&entry, cluster, filesize, index); if (!WriteDirEntry(handle, index, &entry)) return FALSE; index++; return TRUE; } else { printf("Root directory full (or media error)!"); return FALSE; } }