More fixes to the extlinux installer; change back to writable types
[profile/ivi/syslinux.git] / libfat / libfat.h
1 #ident "$Id$"
2 /* ----------------------------------------------------------------------- *
3  *   
4  *   Copyright 2004 H. Peter Anvin - All Rights Reserved
5  *
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.
11  *
12  * ----------------------------------------------------------------------- */
13
14 /*
15  * libfat.h
16  *
17  * Headers for the libfat library
18  */
19
20 #ifndef LIBFAT_H
21 #define LIBFAT_H
22
23 #include <stddef.h>
24 #include <inttypes.h>
25
26 #define LIBFAT_SECTOR_SHIFT     9
27 #define LIBFAT_SECTOR_SIZE      512
28 #define LIBFAT_SECTOR_MASK      511
29
30 typedef uint32_t libfat_sector_t;
31 struct libfat_filesystem;
32
33 /*
34  * Open the filesystem.  The readfunc is the function to read
35  * sectors, in the format:
36  * int readfunc(intptr_t readptr, void *buf, size_t secsize,
37  *              libfat_sector_t secno)
38  *
39  * ... where readptr is a private argument.
40  *
41  * A return value of != secsize is treated as error.
42  */
43 struct libfat_filesystem *
44 libfat_open(int (*readfunc)(intptr_t, void *, size_t, libfat_sector_t),
45             intptr_t readptr);
46
47 void libfat_close(struct libfat_filesystem *);
48
49 /*
50  * Convert a cluster number (or 0 for the root directory) to a
51  * sector number.  Return -1 on failure.
52  */
53 libfat_sector_t libfat_clustertosector(const struct libfat_filesystem *fs,
54                                        int32_t cluster);
55
56 /*
57  * Get the next sector of either the root directory or a FAT chain.
58  * Returns 0 on end of file and -1 on error.
59  */
60 libfat_sector_t libfat_nextsector(struct libfat_filesystem *fs,
61                                   libfat_sector_t s);
62
63 /*
64  * Flush all cached sectors for this filesystem.
65  */
66 void libfat_flush(struct libfat_filesystem *fs);
67
68 /*
69  * Get a pointer to a specific sector.
70  */
71 void * libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n);
72
73 /*
74  * Search a FAT directory for a particular pre-mangled filename.
75  * Copies the directory entry into direntry and returns 0 if found.
76  */
77 int32_t libfat_searchdir(struct libfat_filesystem *fs, int32_t dirclust,
78                          const void *name, void *direntry);
79
80 #endif /* LIBFAT_H */
81