1 #ident "$Id: cache.c,v 1.1 2004/12/15 10:14:39 hpa Exp $"
2 /* ----------------------------------------------------------------------- *
4 * Copyright 2004 H. Peter Anvin - All Rights Reserved
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 * Boston MA 02111-1307, USA; either version 2 of the License, or
10 * (at your option) any later version; incorporated herein by reference.
12 * ----------------------------------------------------------------------- */
21 #include "libfatint.h"
23 void * libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n)
25 struct libfat_sector *ls;
27 for ( ls = fs->sectors ; ls ; ls = ls->next ) {
29 return ls->data; /* Found in cache */
32 /* Not found in cache */
33 ls = malloc(sizeof(struct libfat_sector));
36 ls = malloc(sizeof(struct libfat_sector));
39 return NULL; /* Can't allocate memory */
42 if ( fs->read(fs->readptr, ls->data, LIBFAT_SECTOR_SIZE, n)
43 != LIBFAT_SECTOR_SIZE ) {
45 return NULL; /* I/O error */
49 ls->next = fs->sectors;
55 void libfat_flush(struct libfat_filesystem *fs)
57 struct libfat_sector *ls, *lsnext;
62 for ( ls = lsnext ; ls ; ls = lsnext ) {