Ejemplo n.º 1
0
BOOL PreReadClusterChain(RDWRHandle handle, CLUSTER start)
{
    SECTOR  firstsector;
    char* ReadBuf;
    struct Pipe pipe, *ppipe = &pipe;
    unsigned char sectorspercluster;
    unsigned BufSize;

    if (!CacheActive()) return TRUE;

    sectorspercluster = GetSectorsPerCluster(handle);
    if (!sectorspercluster) return FALSE;

    ReadBuf = AllocateReadBuf(MAX_ALLOCATING, &BufSize);
    BufSize /= BYTESPERSECTOR;

    pipe.buf          = ReadBuf;
    pipe.bufsize      = BufSize;
    pipe.index        = 0;
    pipe.maxindex     = BufSize / sectorspercluster;
    pipe.prevcluster  = 0;
    pipe.firstcluster = start;

    if (!FileTraverseFat(handle, start, ClusterPreReader, (void**) &ppipe))
    {
        FreeReadBuf(ReadBuf);
        return FALSE;
    }

    if (pipe.index)
    {
        firstsector = ConvertToDataSector(handle, pipe.firstcluster);
        if (!firstsector)
        {
            FreeReadBuf(ReadBuf);
            return FALSE;
        }

        if (ReadSectors(handle, pipe.index*sectorspercluster,
                        firstsector, pipe.buf) == -1)
        {
            FreeReadBuf(ReadBuf);
            return FALSE;
        }
    }

    FreeReadBuf(ReadBuf);
    return TRUE;
}
Ejemplo n.º 2
0
CLUSTER GetNthFileCluster(RDWRHandle handle, CLUSTER firstclust, unsigned n,
                          BOOL* pasttheend)
{
   struct Pipe pipe, *ppipe = &pipe;
   
   pipe.n = n;
   pipe.count = 0;
   pipe.result = 1;
   pipe.found = FALSE;
   
   if (!FileTraverseFat(handle, firstclust, NthFileClusterFinder, 
                        (void**)&ppipe))
      RETURN_FTEERROR(FALSE);
   
   *pasttheend = ((!pipe.found) && (n >= pipe.count));
         
   return pipe.result;
}