filelist.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: filelist.h,v 1.10 1999/12/26 06:59:00 jgg Exp $
  4. /* ######################################################################
  5. File List structures
  6. These structures represent the uncompacted binary records from the
  7. file list file. Functions are provided to compact and decompact these
  8. structures for reading and writing.
  9. The dsFList class can be instantiated to get get a general 'all records'
  10. storage. It also has a member to read the next record from the IO and
  11. to print out a record summary.
  12. Be sure to read filelist.sgml which contains the precise meaning of
  13. the feilds and the compaction technique used.
  14. ##################################################################### */
  15. /*}}}*/
  16. #ifndef DSYNC_FILELIST
  17. #define DSYNC_FILELIST
  18. #ifdef __GNUG__
  19. #pragma interface "dsync/filelist.h"
  20. #endif
  21. #include <string>
  22. using namespace std;
  23. class dsFList
  24. {
  25. public:
  26. class IO;
  27. struct Header
  28. {
  29. unsigned long Tag;
  30. unsigned long Signature;
  31. unsigned long MajorVersion;
  32. unsigned long MinorVersion;
  33. unsigned long Epoch;
  34. unsigned long FlagCount;
  35. unsigned long Flags[15];
  36. bool Read(IO &IO);
  37. bool Write(IO &IO);
  38. Header();
  39. };
  40. struct DirEntity
  41. {
  42. unsigned long Tag;
  43. signed long ModTime;
  44. unsigned long Permissions;
  45. unsigned long User;
  46. unsigned long Group;
  47. string Name;
  48. enum EntFlags {FlPerm = (1<<0), FlOwner = (1<<1)};
  49. /* You know what? egcs-2.91.60 will not call the destructor for Name
  50. if this in not here. I can't reproduce this in a simpler context
  51. either. - Jgg [time passes] serious egcs bug, it was mislinking
  52. the string classes :< */
  53. ~DirEntity() {};
  54. };
  55. struct Directory : public DirEntity
  56. {
  57. bool Read(IO &IO);
  58. bool Write(IO &IO);
  59. };
  60. struct NormalFile : public DirEntity
  61. {
  62. unsigned long Size;
  63. unsigned char MD5[16];
  64. enum Flags {FlMD5 = (1<<2)};
  65. bool Read(IO &IO);
  66. bool Write(IO &IO);
  67. };
  68. struct Symlink : public DirEntity
  69. {
  70. unsigned long Compress;
  71. string To;
  72. bool Read(IO &IO);
  73. bool Write(IO &IO);
  74. };
  75. struct DeviceSpecial : public DirEntity
  76. {
  77. unsigned long Dev;
  78. bool Read(IO &IO);
  79. bool Write(IO &IO);
  80. };
  81. struct Filter
  82. {
  83. unsigned long Tag;
  84. unsigned long Type;
  85. string Pattern;
  86. enum Types {Include=1, Exclude=2};
  87. bool Read(IO &IO);
  88. bool Write(IO &IO);
  89. };
  90. struct UidGidMap
  91. {
  92. unsigned long Tag;
  93. unsigned long FileID;
  94. unsigned long RealID;
  95. string Name;
  96. enum Flags {FlRealID = (1<<0)};
  97. bool Read(IO &IO);
  98. bool Write(IO &IO);
  99. };
  100. struct HardLink : public NormalFile
  101. {
  102. unsigned long Serial;
  103. bool Read(IO &IO);
  104. bool Write(IO &IO);
  105. };
  106. struct Trailer
  107. {
  108. unsigned long Tag;
  109. unsigned long Signature;
  110. bool Read(IO &IO);
  111. bool Write(IO &IO);
  112. Trailer();
  113. };
  114. struct RSyncChecksum
  115. {
  116. unsigned long Tag;
  117. unsigned long BlockSize;
  118. unsigned long FileSize;
  119. // Array of 160 bit values (20 bytes) stored in Network byte order
  120. unsigned char *Sums;
  121. bool Read(IO &IO);
  122. bool Write(IO &IO);
  123. RSyncChecksum();
  124. ~RSyncChecksum();
  125. };
  126. struct AggregateFile
  127. {
  128. unsigned long Tag;
  129. string File;
  130. bool Read(IO &IO);
  131. bool Write(IO &IO);
  132. };
  133. enum Types {tHeader=0, tDirMarker=1, tDirStart=2, tDirEnd=3, tNormalFile=4,
  134. tSymlink=5, tDeviceSpecial=6, tDirectory=7, tFilter=8,
  135. tUidMap=9, tGidMap=10, tHardLink=11, tTrailer=12, tRSyncChecksum=13,
  136. tAggregateFile=14, tRSyncEnd=15};
  137. unsigned long Tag;
  138. Header Head;
  139. Directory Dir;
  140. NormalFile NFile;
  141. Symlink SLink;
  142. DeviceSpecial DevSpecial;
  143. Filter Filt;
  144. UidGidMap UMap;
  145. HardLink HLink;
  146. Trailer Trail;
  147. DirEntity *Entity;
  148. NormalFile *File;
  149. RSyncChecksum RChk;
  150. AggregateFile AgFile;
  151. bool Step(IO &IO);
  152. bool Print(ostream &out);
  153. };
  154. class dsFList::IO
  155. {
  156. public:
  157. string LastSymlink;
  158. dsFList::Header Header;
  159. bool NoStrings;
  160. virtual bool Read(void *Buf,unsigned long Len) = 0;
  161. virtual bool Write(const void *Buf,unsigned long Len) = 0;
  162. virtual bool Seek(unsigned long Bytes) = 0;
  163. virtual unsigned long Tell() = 0;
  164. bool ReadNum(unsigned long &Number);
  165. bool WriteNum(unsigned long Number);
  166. bool ReadInt(unsigned long &Number,unsigned char Count);
  167. bool WriteInt(unsigned long Number,unsigned char Count);
  168. bool ReadInt(signed long &Number,unsigned char Count);
  169. bool WriteInt(signed long Number,unsigned char Count);
  170. bool ReadString(string &Foo);
  171. bool WriteString(string const &Foo);
  172. IO();
  173. virtual ~IO() {};
  174. };
  175. #endif