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 * ----------------------------------------------------------------------- */
17 * Headers for the libfat library
26 #define LIBFAT_SECTOR_SHIFT 9
27 #define LIBFAT_SECTOR_SIZE 512
28 #define LIBFAT_SECTOR_MASK 511
30 typedef uint32_t libfat_sector_t;
31 struct libfat_filesystem;
33 struct libfat_direntry {
34 libfat_sector_t sector;
36 unsigned char entry[32];
40 * Open the filesystem. The readfunc is the function to read
41 * sectors, in the format:
42 * int readfunc(intptr_t readptr, void *buf, size_t secsize,
43 * libfat_sector_t secno)
45 * ... where readptr is a private argument.
47 * A return value of != secsize is treated as error.
49 struct libfat_filesystem *
50 libfat_open(int (*readfunc)(intptr_t, void *, size_t, libfat_sector_t),
53 void libfat_close(struct libfat_filesystem *);
56 * Convert a cluster number (or 0 for the root directory) to a
57 * sector number. Return -1 on failure.
59 libfat_sector_t libfat_clustertosector(const struct libfat_filesystem *fs,
63 * Get the next sector of either the root directory or a FAT chain.
64 * Returns 0 on end of file and -1 on error.
66 libfat_sector_t libfat_nextsector(struct libfat_filesystem *fs,
70 * Flush all cached sectors for this filesystem.
72 void libfat_flush(struct libfat_filesystem *fs);
75 * Get a pointer to a specific sector.
77 void * libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n);
80 * Search a FAT directory for a particular pre-mangled filename.
81 * Copies the directory entry into direntry and returns 0 if found.
83 int32_t libfat_searchdir(struct libfat_filesystem *fs, int32_t dirclust,
84 const void *name, struct libfat_direntry *direntry);