fat.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* fat.h - Read/write access to the FAT
  2. Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. On Debian systems, the complete text of the GNU General Public License
  14. can be found in /usr/share/common-licenses/GPL-3 file.
  15. */
  16. #ifndef _FAT_H
  17. #define _FAT_H
  18. void read_fat(DOS_FS * fs);
  19. /* Loads the FAT of the file system described by FS. Initializes the FAT,
  20. replaces broken FATs and rejects invalid cluster entries. */
  21. void get_fat(FAT_ENTRY * entry, void *fat, unsigned long cluster, DOS_FS * fs);
  22. /* Retrieve the FAT entry (next chained cluster) for CLUSTER. */
  23. void set_fat(DOS_FS * fs, unsigned long cluster, unsigned long new);
  24. /* Changes the value of the CLUSTERth cluster of the FAT of FS to NEW. Special
  25. values of NEW are -1 (EOF, 0xff8 or 0xfff8) and -2 (bad sector, 0xff7 or
  26. 0xfff7) */
  27. int bad_cluster(DOS_FS * fs, unsigned long cluster);
  28. /* Returns a non-zero integer if the CLUSTERth cluster is marked as bad or zero
  29. otherwise. */
  30. unsigned long next_cluster(DOS_FS * fs, unsigned long cluster);
  31. /* Returns the number of the cluster following CLUSTER, or -1 if this is the
  32. last cluster of the respective cluster chain. CLUSTER must not be a bad
  33. cluster. */
  34. loff_t cluster_start(DOS_FS * fs, unsigned long cluster);
  35. /* Returns the byte offset of CLUSTER, relative to the respective device. */
  36. void set_owner(DOS_FS * fs, unsigned long cluster, DOS_FILE * owner);
  37. /* Sets the owner pointer of the respective cluster to OWNER. If OWNER was NULL
  38. before, it can be set to NULL or any non-NULL value. Otherwise, only NULL is
  39. accepted as the new value. */
  40. DOS_FILE *get_owner(DOS_FS * fs, unsigned long cluster);
  41. /* Returns the owner of the repective cluster or NULL if the cluster has no
  42. owner. */
  43. void fix_bad(DOS_FS * fs);
  44. /* Scans the disk for currently unused bad clusters and marks them as bad. */
  45. void reclaim_free(DOS_FS * fs);
  46. /* Marks all allocated, but unused clusters as free. */
  47. void reclaim_file(DOS_FS * fs);
  48. /* Scans the FAT for chains of allocated, but unused clusters and creates files
  49. for them in the root directory. Also tries to fix all inconsistencies (e.g.
  50. loops, shared clusters, etc.) in the process. */
  51. unsigned long update_free(DOS_FS * fs);
  52. /* Updates free cluster count in FSINFO sector. */
  53. #endif