dat.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. typedef struct Dosboot Dosboot;
  2. typedef struct Dosboot32 Dosboot32;
  3. typedef struct Dosbpb Dosbpb;
  4. typedef struct Dosdir Dosdir;
  5. typedef struct Dospart Dospart;
  6. typedef struct Dosptr Dosptr;
  7. typedef struct Fatinfo Fatinfo;
  8. typedef struct Xfs Xfs;
  9. typedef struct Xfile Xfile;
  10. struct Dospart{
  11. uchar active;
  12. uchar hstart;
  13. uchar cylstart[2];
  14. uchar type;
  15. uchar hend;
  16. uchar cylend[2];
  17. uchar start[4];
  18. uchar length[4];
  19. };
  20. enum
  21. {
  22. /*
  23. * dos partition types
  24. */
  25. FAT12 = 0x01,
  26. FAT16 = 0x04, /* partitions smaller than 32MB */
  27. FATHUGE = 0x06, /* fat16 partitions larger than 32MB */
  28. FAT32 = 0x0b,
  29. FAT32X = 0x0c,
  30. FATHUGEX = 0x0e,
  31. DMDDO = 0x54,
  32. FATRESRV = 2, /* number of reserved fat entries */
  33. };
  34. /*
  35. * dos boot sector, the start of every dos partition
  36. */
  37. struct Dosboot{
  38. uchar magic[3];
  39. uchar version[8];
  40. uchar sectsize[2];
  41. uchar clustsize;
  42. uchar nresrv[2];
  43. uchar nfats;
  44. uchar rootsize[2];
  45. uchar volsize[2];
  46. uchar mediadesc;
  47. uchar fatsize[2];
  48. uchar trksize[2];
  49. uchar nheads[2];
  50. uchar nhidden[4];
  51. uchar bigvolsize[4]; /* same as Dosboot32 up to here */
  52. uchar driveno;
  53. uchar reserved0;
  54. uchar bootsig;
  55. uchar volid[4];
  56. uchar label[11];
  57. uchar reserved1[8];
  58. };
  59. /*
  60. * dos boot sector for FAT32
  61. */
  62. enum
  63. {
  64. NOFATMIRROR = 0x0080, /* masks for extflags */
  65. ACTFATMASK = 0x000f,
  66. };
  67. struct Dosboot32{
  68. uchar magic[3];
  69. uchar version[8];
  70. uchar sectsize[2];
  71. uchar clustsize;
  72. uchar nresrv[2];
  73. uchar nfats;
  74. uchar rootsize[2];
  75. uchar volsize[2];
  76. uchar mediadesc;
  77. uchar fatsize[2];
  78. uchar trksize[2];
  79. uchar nheads[2];
  80. uchar nhidden[4];
  81. uchar bigvolsize[4]; /* same as Dosboot up to here */
  82. uchar fatsize32[4]; /* sectors per fat */
  83. uchar extflags[2]; /* active fat flags */
  84. uchar version1[2]; /* fat32 version; major & minor bytes */
  85. uchar rootstart[4]; /* starting cluster of root dir */
  86. uchar infospec[2]; /* fat allocation info sector */
  87. uchar backupboot[2]; /* backup boot sector */
  88. uchar reserved[12];
  89. };
  90. /*
  91. * optional FAT32 info sector
  92. */
  93. enum
  94. {
  95. FATINFOSIG1 = 0x41615252UL,
  96. FATINFOSIG = 0x61417272UL,
  97. };
  98. struct Fatinfo
  99. {
  100. uchar sig1[4];
  101. uchar pad[480];
  102. uchar sig[4];
  103. uchar freeclust[4]; /* num frre clusters; -1 is unknown */
  104. uchar nextfree[4]; /* most recently allocated cluster */
  105. uchar resrv[4*3];
  106. };
  107. /*
  108. * BIOS paramater block
  109. */
  110. struct Dosbpb{
  111. MLock; /* access to fat */
  112. int sectsize; /* in bytes */
  113. int clustsize; /* in sectors */
  114. int nresrv; /* sectors */
  115. int nfats; /* usually 2; modified to 1 if fat mirroring disabled */
  116. int rootsize; /* number of entries, for fat12 and fat16 */
  117. long volsize; /* in sectors */
  118. int mediadesc;
  119. long fatsize; /* in sectors */
  120. int fatclusters;
  121. int fatbits; /* 12, 16, or 32 */
  122. long fataddr; /* sector number of first valid fat entry */
  123. long rootaddr; /* for fat16 or fat12, sector of root dir */
  124. long rootstart; /* for fat32, cluster of root dir */
  125. long dataaddr; /* initial sector of data clusters */
  126. long freeptr; /* next free cluster candidate */
  127. long freeclusters; /* count of free clusters, for fat32 */
  128. int fatinfo; /* fat info sector location; 0 => none */
  129. };
  130. enum
  131. {
  132. DOSDIRSIZE = 32,
  133. DOSEMPTY = 0xe5, /* first char in name if entry is unused */
  134. DOSRUNE = 13, /* runes per dosdir in a long file name */
  135. DOSNAMELEN = 261 /* max dos file name length */
  136. };
  137. struct Dosdir{
  138. uchar name[8];
  139. uchar ext[3];
  140. uchar attr;
  141. uchar reserved[1];
  142. uchar ctime[3]; /* creation time */
  143. uchar cdate[2]; /* creation date */
  144. uchar adate[2]; /* last access date */
  145. uchar hstart[2]; /* high bits of start for fat32 */
  146. uchar time[2]; /* last modified time */
  147. uchar date[2]; /* last modified date */
  148. uchar start[2];
  149. uchar length[4];
  150. };
  151. enum
  152. {
  153. DRONLY = 0x01,
  154. DHIDDEN = 0x02,
  155. DSYSTEM = 0x04,
  156. DVLABEL = 0x08,
  157. DDIR = 0x10,
  158. DARCH = 0x20,
  159. };
  160. #define GSHORT(p) (((p)[0])|(p)[1]<<8)
  161. #define GLONG(p) (((long)(p)[0])|(p)[1]<<8|(p)[2]<<16|(p)[3]<<24)
  162. #define PSHORT(p,v) ((p)[0]=(v),(p)[1]=(v)>>8)
  163. #define PLONG(p,v) ((p)[0]=(v),(p)[1]=(v)>>8,(p)[2]=(v)>>16,(p)[3]=(v)>>24)
  164. struct Dosptr{
  165. ulong addr; /* sector & entry within of file's directory entry */
  166. ulong offset;
  167. ulong paddr; /* of parent's directory entry */
  168. ulong poffset;
  169. ulong iclust; /* ordinal within file */
  170. ulong clust;
  171. ulong naddr; /* next block in directory (for writing multi entry elements) */
  172. ulong prevaddr;
  173. Iosect *p;
  174. Dosdir *d;
  175. };
  176. #define QIDPATH(p) ((p)->addr*(Sectorsize/DOSDIRSIZE) + \
  177. (p)->offset/DOSDIRSIZE)
  178. struct Xfs{
  179. Xfs *next;
  180. int omode; /* of file containing external fs */
  181. char *name; /* of file containing external f.s. */
  182. Qid qid; /* of file containing external f.s. */
  183. long ref; /* attach count */
  184. Qid rootqid; /* of plan9 constructed root directory */
  185. uchar isfat32; /* is a fat 32 file system? */
  186. short dev;
  187. short fmt;
  188. long offset;
  189. void *ptr;
  190. };
  191. struct Xfile{
  192. Xfile *next; /* in hash bucket */
  193. long fid;
  194. ulong flags;
  195. Qid qid;
  196. Xfs *xf;
  197. Dosptr *ptr;
  198. };
  199. enum{
  200. Asis, Clean, Clunk
  201. };
  202. enum{
  203. Invalid, Short, ShortLower, Long
  204. };
  205. enum{ /* Xfile flags */
  206. Oread = 1,
  207. Owrite = 2,
  208. Orclose = 4,
  209. Omodes = 3,
  210. };
  211. enum{
  212. Enevermind,
  213. Eformat,
  214. Eio,
  215. Enoauth,
  216. Enomem,
  217. Enonexist,
  218. Eperm,
  219. Enofilsys,
  220. Eauth,
  221. Econtig,
  222. Ebadfcall,
  223. Ebadstat,
  224. Eversion,
  225. Etoolong,
  226. Eerrstr,
  227. ESIZE
  228. };
  229. extern int chatty;
  230. extern int errno;
  231. extern int readonly;
  232. extern char *deffile;
  233. extern int trspaces;