syslinux-3.08-2 sources from FC4
[bootcd.git] / syslinux / libfat / libfat.h
1 #ident "$Id: libfat.h,v 1.3 2005/01/04 03:04:53 hpa Exp $"
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 struct libfat_direntry {
34   libfat_sector_t sector;
35   int offset;
36   unsigned char entry[32];
37 };
38
39 /*
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)
44  *
45  * ... where readptr is a private argument.
46  *
47  * A return value of != secsize is treated as error.
48  */
49 struct libfat_filesystem *
50 libfat_open(int (*readfunc)(intptr_t, void *, size_t, libfat_sector_t),
51             intptr_t readptr);
52
53 void libfat_close(struct libfat_filesystem *);
54
55 /*
56  * Convert a cluster number (or 0 for the root directory) to a
57  * sector number.  Return -1 on failure.
58  */
59 libfat_sector_t libfat_clustertosector(const struct libfat_filesystem *fs,
60                                        int32_t cluster);
61
62 /*
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.
65  */
66 libfat_sector_t libfat_nextsector(struct libfat_filesystem *fs,
67                                   libfat_sector_t s);
68
69 /*
70  * Flush all cached sectors for this filesystem.
71  */
72 void libfat_flush(struct libfat_filesystem *fs);
73
74 /*
75  * Get a pointer to a specific sector.
76  */
77 void * libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n);
78
79 /*
80  * Search a FAT directory for a particular pre-mangled filename.
81  * Copies the directory entry into direntry and returns 0 if found.
82  */
83 int32_t libfat_searchdir(struct libfat_filesystem *fs, int32_t dirclust,
84                          const void *name, struct libfat_direntry *direntry);
85
86 #endif /* LIBFAT_H */
87