system/drivers/fatfs/cluster.c
/*
 * FindLastCluster();
 *
 * Or return -1 on error and return CLUSTER_EOC when there is no first cluster.
 * What about CLUSTER_BAD ?????
 */


Or return -1 on error and return CLUSTER_EOC when there is no first cluster.
Or return - 1 on error and return CLUSTER_EOC when there is no first cluster .
int FindLastCluster(struct FatNode *node, uint32_t *r_cluster) {
  uint32_t cluster, next_cluster;
  if (GetFirstCluster(&node->dirent) == CLUSTER_EOC) {
    *r_cluster = CLUSTER_EOC;
    return 0;
  } else {
    if (node->hint_cluster != 0)
      cluster = node->hint_cluster;
    else
      cluster = GetFirstCluster(&node->dirent);
    if (ReadFATEntry(cluster, &next_cluster) != 0)
      return -1;
    while (next_cluster >= CLUSTER_ALLOC_MIN &&
           next_cluster <= CLUSTER_ALLOC_MAX) {
      cluster = next_cluster;
      node->hint_offset += fsb.bpb.sectors_per_cluster * 512;
      node->hint_cluster = cluster;
      if (ReadFATEntry(cluster, &next_cluster) != 0)
        return -1;
    }
    *r_cluster = cluster;
    return 0;
  }
}
int FindLastCluster ( struct FatNode * node , uint32_t * r_cluster ) { uint32_t cluster , next_cluster ; if ( GetFirstCluster ( & node -> dirent ) == CLUSTER_EOC ) { * r_cluster = CLUSTER_EOC ; return 0 ; } else { if ( node -> hint_cluster != 0 ) cluster = node -> hint_cluster ; else cluster = GetFirstCluster ( & node -> dirent ) ; if ( ReadFATEntry ( cluster , & next_cluster ) != 0 ) return -1 ; while ( next_cluster >= CLUSTER_ALLOC_MIN && next_cluster <= CLUSTER_ALLOC_MAX ) { cluster = next_cluster ; node -> hint_offset += fsb . bpb . sectors_per_cluster * 512 ; node -> hint_cluster = cluster ; if ( ReadFATEntry ( cluster , & next_cluster ) != 0 ) return -1 ; } * r_cluster = cluster ; return 0 ; } }
FindLastCluster();
FindLastCluster () ;