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 * ----------------------------------------------------------------------- */
16 * Headers for the libfat library
25 #define LIBFAT_SECTOR_SHIFT 9
26 #define LIBFAT_SECTOR_SIZE 512
27 #define LIBFAT_SECTOR_MASK 511
29 typedef uint64_t libfat_sector_t;
30 struct libfat_filesystem;
32 struct libfat_direntry {
33 libfat_sector_t sector;
35 unsigned char entry[32];
39 * Open the filesystem. The readfunc is the function to read
40 * sectors, in the format:
41 * int readfunc(intptr_t readptr, void *buf, size_t secsize,
42 * libfat_sector_t secno)
44 * ... where readptr is a private argument.
46 * A return value of != secsize is treated as error.
48 struct libfat_filesystem
49 *libfat_open(int (*readfunc) (intptr_t, void *, size_t, libfat_sector_t),
52 void libfat_close(struct libfat_filesystem *);
55 * Convert a cluster number (or 0 for the root directory) to a
56 * sector number. Return -1 on failure.
58 libfat_sector_t libfat_clustertosector(const struct libfat_filesystem *fs,
62 * Get the next sector of either the root directory or a FAT chain.
63 * Returns 0 on end of file and -1 on error.
65 libfat_sector_t libfat_nextsector(struct libfat_filesystem *fs,
69 * Flush all cached sectors for this filesystem.
71 void libfat_flush(struct libfat_filesystem *fs);
74 * Get a pointer to a specific sector.
76 void *libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n);
79 * Search a FAT directory for a particular pre-mangled filename.
80 * Copies the directory entry into direntry and returns 0 if found.
82 int32_t libfat_searchdir(struct libfat_filesystem *fs, int32_t dirclust,
83 const void *name, struct libfat_direntry *direntry);