dos.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * (C) Copyright 2002
  3. * Stäubli Faverges - <www.staubli.com>
  4. * Pierre AUBERT p.aubert@staubli.com
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #ifndef _DOS_H_
  25. #define _DOS_H_
  26. /* Definitions for Dos diskettes */
  27. /* General definitions */
  28. #define SZ_STD_SECTOR 512 /* Standard sector size */
  29. #define MDIR_SIZE 32 /* Direntry size */
  30. #define FAT_BITS 12 /* Diskette use 12 bits fat */
  31. #define MAX_PATH 128 /* Max size of the MSDOS PATH */
  32. #define MAX_DIR_SECS 64 /* Taille max d'un repertoire (en */
  33. /* secteurs) */
  34. /* Misc. definitions */
  35. #define DELMARK '\xe5'
  36. #define EXTENDED_BOOT (0x29)
  37. #define MEDIA_STD (0xf0)
  38. #define JUMP_0_1 (0xe9)
  39. #define JUMP_0_2 (0xeb)
  40. /* Boot size is 256 bytes, but we need to read almost a sector, then
  41. assume bootsize is 512 */
  42. #define BOOTSIZE 512
  43. /* Fat definitions for 12 bits fat */
  44. #define FAT12_MAX_NB 4086
  45. #define FAT12_LAST 0x0ff6
  46. #define FAT12_END 0x0fff
  47. /* file attributes */
  48. #define ATTR_READONLY 0x01
  49. #define ATTR_HIDDEN 0x02
  50. #define ATTR_SYSTEM 0x04
  51. #define ATTR_VOLUME 0x08
  52. #define ATTR_DIRECTORY 0x10
  53. #define ATTR_ARCHIVE 0x20
  54. #define ATTR_VSE 0x0f
  55. /* Name format */
  56. #define EXTCASE 0x10
  57. #define BASECASE 0x8
  58. /* Definition of the boot sector */
  59. #define BANNER_LG 8
  60. #define LABEL_LG 11
  61. typedef struct bootsector
  62. {
  63. unsigned char jump [3]; /* 0 Jump to boot code */
  64. char banner [BANNER_LG]; /* 3 OEM name & version */
  65. unsigned short secsiz; /* 11 Bytes per sector hopefully 512 */
  66. unsigned char clsiz; /* 13 Cluster size in sectors */
  67. unsigned short nrsvsect; /* 14 Number of reserved (boot) sectors */
  68. unsigned char nfat; /* 16 Number of FAT tables hopefully 2 */
  69. unsigned short dirents; /* 17 Number of directory slots */
  70. unsigned short psect; /* 19 Total sectors on disk */
  71. unsigned char descr; /* 21 Media descriptor=first byte of FAT */
  72. unsigned short fatlen; /* 22 Sectors in FAT */
  73. unsigned short nsect; /* 24 Sectors/track */
  74. unsigned short nheads; /* 26 Heads */
  75. unsigned int nhs; /* 28 number of hidden sectors */
  76. unsigned int bigsect; /* 32 big total sectors */
  77. unsigned char physdrive; /* 36 physical drive ? */
  78. unsigned char reserved; /* 37 reserved */
  79. unsigned char dos4; /* 38 dos > 4.0 diskette */
  80. unsigned int serial; /* 39 serial number */
  81. char label [LABEL_LG]; /* 43 disk label */
  82. char fat_type [8]; /* 54 FAT type */
  83. unsigned char res_2m; /* 62 reserved by 2M */
  84. unsigned char CheckSum; /* 63 2M checksum (not used) */
  85. unsigned char fmt_2mf; /* 64 2MF format version */
  86. unsigned char wt; /* 65 1 if write track after format */
  87. unsigned char rate_0; /* 66 data transfer rate on track 0 */
  88. unsigned char rate_any; /* 67 data transfer rate on track<>0 */
  89. unsigned short BootP; /* 68 offset to boot program */
  90. unsigned short Infp0; /* 70 T1: information for track 0 */
  91. unsigned short InfpX; /* 72 T2: information for track<>0 */
  92. unsigned short InfTm; /* 74 T3: track sectors size table */
  93. unsigned short DateF; /* 76 Format date */
  94. unsigned short TimeF; /* 78 Format time */
  95. unsigned char junk [BOOTSIZE - 80]; /* 80 remaining data */
  96. } __attribute__ ((packed)) BootSector_t;
  97. /* Structure d'une entree de repertoire */
  98. typedef struct directory {
  99. char name [8]; /* file name */
  100. char ext [3]; /* file extension */
  101. unsigned char attr; /* attribute byte */
  102. unsigned char Case; /* case of short filename */
  103. unsigned char reserved [9]; /* ?? */
  104. unsigned char time [2]; /* time stamp */
  105. unsigned char date [2]; /* date stamp */
  106. unsigned short start; /* starting cluster number */
  107. unsigned int size; /* size of the file */
  108. } __attribute__ ((packed)) Directory_t;
  109. #define MAX_VFAT_SUBENTRIES 20
  110. #define VSE_NAMELEN 13
  111. #define VSE1SIZE 5
  112. #define VSE2SIZE 6
  113. #define VSE3SIZE 2
  114. #define VBUFSIZE ((MAX_VFAT_SUBENTRIES * VSE_NAMELEN) + 1)
  115. #define MAX_VNAMELEN (255)
  116. #define VSE_PRESENT 0x01
  117. #define VSE_LAST 0x40
  118. #define VSE_MASK 0x1f
  119. /* Flag used by vfat_lookup */
  120. #define DO_OPEN 1
  121. #define ACCEPT_PLAIN 0x20
  122. #define ACCEPT_DIR 0x10
  123. #define ACCEPT_LABEL 0x08
  124. #define SINGLE 2
  125. #define MATCH_ANY 0x40
  126. struct vfat_subentry {
  127. unsigned char id; /* VSE_LAST pour la fin, VSE_MASK */
  128. /* pour un VSE */
  129. char text1 [VSE1SIZE * 2]; /* Caracteres encodes sur 16 bits */
  130. unsigned char attribute; /* 0x0f pour les VFAT */
  131. unsigned char hash1; /* toujours 0 */
  132. unsigned char sum; /* Checksum du nom court */
  133. char text2 [VSE2SIZE * 2]; /* Caracteres encodes sur 16 bits */
  134. unsigned char sector_l; /* 0 pour les VFAT */
  135. unsigned char sector_u; /* 0 pour les VFAT */
  136. char text3 [VSE3SIZE * 2]; /* Caracteres encodes sur 16 bits */
  137. } __attribute__ ((packed)) ;
  138. struct vfat_state {
  139. char name [VBUFSIZE];
  140. int status; /* is now a bit map of 32 bits */
  141. int subentries;
  142. unsigned char sum; /* no need to remember the sum for each */
  143. /* entry, it is the same anyways */
  144. } __attribute__ ((packed)) ;
  145. /* Conversion macros */
  146. #define DOS_YEAR(dir) (((dir)->date[1] >> 1) + 1980)
  147. #define DOS_MONTH(dir) (((((dir)->date[1]&0x1) << 3) + ((dir)->date[0] >> 5)))
  148. #define DOS_DAY(dir) ((dir)->date[0] & 0x1f)
  149. #define DOS_HOUR(dir) ((dir)->time[1] >> 3)
  150. #define DOS_MINUTE(dir) (((((dir)->time[1]&0x7) << 3) + ((dir)->time[0] >> 5)))
  151. #define DOS_SEC(dir) (((dir)->time[0] & 0x1f) * 2)
  152. #endif