1 /* ----------------------------------------------------------------------- *
3 * Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
20 #include "libfatint.h"
22 void *libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n)
24 struct libfat_sector *ls;
26 for (ls = fs->sectors; ls; ls = ls->next) {
28 return ls->data; /* Found in cache */
31 /* Not found in cache */
32 ls = malloc(sizeof(struct libfat_sector));
35 ls = malloc(sizeof(struct libfat_sector));
38 return NULL; /* Can't allocate memory */
41 if (fs->read(fs->readptr, ls->data, LIBFAT_SECTOR_SIZE, n)
42 != LIBFAT_SECTOR_SIZE) {
44 return NULL; /* I/O error */
48 ls->next = fs->sectors;
54 void libfat_flush(struct libfat_filesystem *fs)
56 struct libfat_sector *ls, *lsnext;
61 for (ls = lsnext; ls; ls = lsnext) {