Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
7.4 KiB

  1. BREAK <MFT Definitions>
  2. ;** MSDOS MFT definitions
  3. ;
  4. ; The Master File Table (MFT) associates the cannonicalized pathnames, lock
  5. ; records and SFTs for all files open on this machine.
  6. ;
  7. ; The MFT implementation employs a single memory buffer which is used from
  8. ; both ends. This gives the effect (at least until they run into each
  9. ; other) of two independent buffers.
  10. ;
  11. ; MFT buffer
  12. ; ==========
  13. ; The MFT buffer contains MFT name records and free space. It uses a
  14. ; classic heap architecture: freed name records are marked free and
  15. ; conglomerated with any adjacent free space. When one is to create a name
  16. ; entry the free list is searched first-fit. The list of name and free
  17. ; records is always terminated by a single END record.
  18. ;
  19. ; LOCK buffer
  20. ; ===========
  21. ; The lock buffer contains fixed format records containing record locking
  22. ; information. Since they are fixed format the space is handled as a series
  23. ; of chains: one for each MFT name record and one for the free list. No
  24. ; garbage collection is necessary.
  25. ;
  26. ; Space allocation
  27. ; ================
  28. ; The MFT is managed as a heap. Empty blocks are allocated on a first-fit
  29. ; basis. If there is no single large enough empty block the list is garbage
  30. ; collected.
  31. ;
  32. ; MFT name records:
  33. ;
  34. ; 8 16 8 16 32 16 n
  35. ; |------|-----|-----|------|------|------|---------~~~~~~---------|
  36. ; | FLAG | LEN | SUM | LPTR | SPTR | SERL | <.asciz string> |
  37. ; --------------------------------------------------~~~~~~----------
  38. ;
  39. ; FLAG = record type flag
  40. ; LEN = total byte length of record.
  41. ; SUM = sum of bytes in asciz string. Used to speed
  42. ; searches
  43. ; LPTR= pointer to first record in lock chain segment
  44. ; is MFT segment
  45. ; SPTR= pointer to first sft in sft chain
  46. ; SERL= serial number
  47. ; <string> = name string, zero-byte terminated. There
  48. ; may be garbage bytes following the 00 byte;
  49. ; these are counted in the LEN field.
  50. ;
  51. ;
  52. ; MFT free records
  53. ;
  54. ; 8 16
  55. ; |------|-----|----~~~~~~~~~~~~~~~~~~~~~~~~~~~---------|
  56. ; | FLAG | LEN | free |
  57. ; ------------------~~~~~~~~~~~~~~~~~~~~~~~~~~~----------
  58. ;
  59. ; FLAG = record type flag
  60. ; LEN = total byte length of record.
  61. ;
  62. ;
  63. ; MFT END records
  64. ;
  65. ; 8
  66. ; |------|
  67. ; | FLAG |
  68. ; --------
  69. ;
  70. ; FLAG = record type flag
  71. ;** MFT definitions
  72. ;*
  73. ;* NOTE: the flag and length fields are identical for all record types
  74. ;* (except the END type has no length) This must remain so as
  75. ;* some code depends upon it.
  76. ;*
  77. ;* NOTE: Many routines check for "n-1" of the N flag values and if no
  78. ;* match is found assume the flag value must be the remaining
  79. ;* possibility. If you add or remove flag values you must check
  80. ;* all references to mft_flag.
  81. MFT_entry STRUC
  82. mft_flag DB ? ; flag/len field
  83. mft_len DW ?
  84. mft_sum DB ? ; string sum word
  85. mft_lptr DW ? ; LCK pointer
  86. mft_sptr DD ? ; sft pointer
  87. mft_serl DW ? ; serial number
  88. mft_name DB ? ; offset to start of name
  89. MFT_entry ENDS
  90. MFLG_NAM EQU 1 ; min value for name record
  91. MFLG_FRE EQU 0 ; free record
  92. MFLG_END EQU -1 ; end record
  93. ;* Record Lock Record (RLR):
  94. ;
  95. ; 16 32 32 32
  96. ; |-------|--------|--------|--------|
  97. ; | NEXT | FBA | LBA | SPTR |
  98. ; | | lo hi | lo hi | |
  99. ; ------------|--------|--------------
  100. ;
  101. ; CHAIN = pointer to next RLR. 0 if end
  102. ; FBA = offset of 1st byte of locked region
  103. ; LBA = offset of last byte of locked region
  104. ; SPTR = pointer to SFT lock was issued on
  105. RLR_entry STRUC
  106. rlr_next DW ? ; chain to next RLR, 0 if end
  107. rlr_fba DW ? ; first byte addr (offset) of reigion
  108. DW ?
  109. rlr_lba DW ? ; last byte addr of region
  110. DW ?
  111. rlr_sptr DD ? ; SFT pointer
  112. rlr_pid dw ? ; process id of issuer
  113. rlr_type dw ? ; lock type
  114. RLR_entry ENDS
  115. rlr_lall equ 00h ; lock all ops
  116. rlr_lwr equ 01h ; lock write ops
  117. ;
  118. ; A pictorial diagram for the linkages is as follows:
  119. ;
  120. ; +---sptr------+
  121. ; V |
  122. ; +---+<----------|---sptr------+------------+
  123. ; |SFT+----+ | | |
  124. ; +-+-+ | +-+-+ +--+-+ +--+-+
  125. ; V +--->|MFT+-lptr->-|LOCK+-next->|LOCK+->0
  126. ; +---+ | +---+ +----+ +----+
  127. ; |SFT+----+ ^
  128. ; +-+-+ |
  129. ; | |
  130. ; +-------------+
  131. ;
  132. ;
  133. ;**
  134. ;
  135. ; Interesting behavior should be noted:
  136. ;
  137. ; The sharer must maintain information on files in three forms:
  138. ;
  139. ; local/remote handles. These are normal handles and behave in no
  140. ; strange manner. They are identified by SF_mode not having the
  141. ; sfIsFCB flag nor by having the sf_mode = 70. No problems with
  142. ; locking. No problems with open. No problems with close.
  143. ; CloseByName will iterate closes until the mft disappears.
  144. ; CloseUser will iterate closes until no SFT for the particular user
  145. ; appears. CloseProcess will iterate closes until no SFT for the
  146. ; particular user/process appears.
  147. ;
  148. ; local FCBs. There are no corresponding SFT's for these as the SFTs
  149. ; are cached but will be valid for the particular file. There is
  150. ; one SFT for each open on a file by a specific process. These are
  151. ; identified the sfIsFCB flag in the sf_mode field. When multiple
  152. ; opens occur, we merely find the sf pertinent to the file and
  153. ; process. Close decrements the ref count. CloseByName, CloseUser,
  154. ; CloseProcess will iterate closes until no more SFTs exist.
  155. ;
  156. ; handles with mode 70. These represent FCB's open across the network.
  157. ; As such, identical sfts may have been collapsed by the $open code.
  158. ; This results in a reuse of the same SFT. The $Open code must
  159. ; correctly set the ref-count for the sft to reflect the number of
  160. ; collapses that have occurred. These are identified by a 70 in the
  161. ; SF_mode field. There can be no locking on these SFTs. Open must
  162. ; scan the list of SFTs for the file and increment its ref count
  163. ; appropriately.
  164.