diff options
author | hpa <hpa> | 2004-12-15 10:14:39 +0000 |
---|---|---|
committer | hpa <hpa> | 2004-12-15 10:14:39 +0000 |
commit | 7be70022dd3ae138998fc7185351b9b49ad9a9b2 (patch) | |
tree | 2599a8ede407eec131228fb607a52e22145ba1f9 /libfat/cache.c | |
parent | 4912df96419eff85394da1160bcb19a4dd2c1c59 (diff) | |
download | syslinux-7be70022dd3ae138998fc7185351b9b49ad9a9b2.tar.gz |
Prepping for new 2.20 version: rewrite main syslinux program to support
FAT32 and EDD, and a new cleaner installer infrastructure.
Diffstat (limited to 'libfat/cache.c')
-rw-r--r-- | libfat/cache.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/libfat/cache.c b/libfat/cache.c new file mode 100644 index 00000000..cc6c57fe --- /dev/null +++ b/libfat/cache.c @@ -0,0 +1,70 @@ +#ident "$Id$" +/* ----------------------------------------------------------------------- * + * + * Copyright 2004 H. Peter Anvin - All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +/* + * cache.c + * + * Simple sector cache + */ + +#include <stdlib.h> +#include "libfatint.h" + +void * libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n) +{ + struct libfat_sector *ls; + + for ( ls = fs->sectors ; ls ; ls = ls->next ) { + if ( ls->n == n ) + return ls->data; /* Found in cache */ + } + + /* Not found in cache */ + ls = malloc(sizeof(struct libfat_sector)); + if ( !ls ) { + libfat_flush(fs); + ls = malloc(sizeof(struct libfat_sector)); + + if ( !ls ) + return NULL; /* Can't allocate memory */ + } + + if ( fs->read(fs->readptr, ls->data, LIBFAT_SECTOR_SIZE, n) + != LIBFAT_SECTOR_SIZE ) { + free(ls); + return NULL; /* I/O error */ + } + + ls->n = n; + ls->next = fs->sectors; + fs->sectors = ls; + + return ls->data; +} + +void libfat_flush(struct libfat_filesystem *fs) +{ + struct libfat_sector *ls, *lsnext; + + lsnext = fs->sectors; + fs->sectors = NULL; + + for ( ls = lsnext ; ls ; ls = lsnext ) { + lsnext = ls->next; + free(ls); + } +} + + + + |