BTREE.DOC 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. TopSpeed Modula-2 B-tree Toolkit V3.0
  2. Release Notes
  3. This document provides corrections and additions to the TopSpeed
  4. Modula-2 B-tree Toolkit manual.
  5. Notation
  6. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  7. Within this document, the term B-tree refers to the entire B-tree
  8. Toolkit, while the term Btree refers to the single module by the
  9. same name.
  10. Also within this document, certain file names and partial file
  11. names may contain the meta-symbols %O% and %M%. The %O% symbol
  12. refers to the operating system, and should be replaced with
  13. either R or P (for real- or protected-mode i.e. DOS or OS/2).
  14. The %M% symbol refers to the memory model, and should be replaced
  15. with S, C, M, L, X, or MT (for Small, Compact, Medium, Large,
  16. Extra-Large, and Multi-Thread). These are standard conventions
  17. within the TopSpeed product line, and are used primarily within
  18. project files. (Within project files, the meta-symbols will
  19. automatically be converted to the appropriate characters. See
  20. your language User's Manual for details.)
  21. Libraries supplied with version 3.0
  22. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  23. The following pre-compiled libraries are supplied with the
  24. B-Tree toolkit
  25. Model Calling conv. Language OS Name
  26. ===================================================
  27. Small, JPI M2 DOS RS_BT.LIB
  28. Large, JPI M2 DOS RL_BT.LIB
  29. XLarge, JPI M2 DOS RX_BT.LIB
  30. MThread, JPI M2 DOS RT_BT.LIB
  31. Small, JPI M2 OS2 PS_BT.LIB
  32. Large, JPI M2 OS2 PL_BT.LIB
  33. XLarge, JPI M2 OS2 PX_BT.LIB
  34. MThread, JPI M2 OS2 PT_BT.LIB
  35. Large, Stack M2 DOS RLFBT.LIB
  36. Large, Stack M2 OS2 PLFBT.LIB
  37. Small, JPI C DOS RS_BTC.LIB
  38. Large, JPI C DOS RL_BTC.LIB
  39. XLarge, JPI C DOS RX_BTC.LIB
  40. Large, JPI C OS2 PL_BTC.LIB
  41. XLarge, JPI C OS2 PX_BTC.LIB
  42. Large, Stack C DOS RLFBTC.LIB
  43. Large, Stack C OS2 PLFBTC.LIB
  44. Other variations can be made by making the project MKBTREE
  45. with the appropriate settings.
  46. Data Compression with version 3.0
  47. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  48. This version of the TopSpeed Modula-2 B-tree Toolkit provides
  49. optional automatic data compression. See the section Using Data
  50. Compression for details. (All users should read this section,
  51. since data compression has a large effect on an application's
  52. memory usage.)
  53. This version of the Toolkit differs from V2.1 primarily in the
  54. organization of functions within libraries. This re-organization
  55. reduces the amount of redundant code between the libraries for
  56. different options, as well as making it possible to rebuild large
  57. portions of the Toolkit without owning the Extended Edition of
  58. TopSpeed Modula-2..
  59. This version of the Toolkit is able to read data files created
  60. with V2.0. It is unable to read data files from versions before
  61. V2.0. For backwards compatability, data files created with this
  62. version may be accessed using V2.0 with one exception: V2.0 will
  63. not recognize data files created using the new data compression
  64. option. Data files created with this version cannot not be
  65. accessed using any versions prior to V2.0. See the section
  66. Converting File Formats for details.
  67. The FreeIHandle procedure has been changed from V2.1 and earlier:
  68. in some cases, FreeIHandle may now be used for handles in a
  69. shared file. See the Errata section for details.
  70. Installation
  71. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  72. The B-tree Toolkit is installed by running the INSTALL program
  73. located on the installation disk. The INSTALL program must be
  74. used - it is not possible to use the files directly off of the
  75. disks. The INSTALL program will place the files into the
  76. appropriate subdirectories for your TopSpeed installation - you
  77. simply provide it with the name of the directory into which you
  78. installed your compiler.
  79. A number of installation options are provided by the INSTALL
  80. program. These options provide the ability to install support
  81. for DOS and OS/2, as well as support for TopSpeed C. Another
  82. option installs Modula-2 example programs. Finally, an option is
  83. provided for installing the B-tree Modula-2 source code.
  84. Using With TopSpeed Modula-2
  85. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  86. The Btree.DEF file provides all of the Modula-2 definitions
  87. needed for an application to use the B-tree Toolkit. The
  88. FIOx.DEF, Pack.DEF, and apack2.DEF files provide definition used
  89. by the Btree module.
  90. Changes must be made to an application's project file in order to
  91. link to the B-tree Toolkit routines. Modula-2 user's may link to
  92. the Toolkit in one of two ways: 1) By importing the pre-compiled
  93. libraries into the application's project: this requires an
  94. import statement to be added to the project file; 2) By
  95. implicitly including the object modules into the link step: this
  96. requires override statements to be added to the project file.
  97. 1) An example project file which imports the B-tree library
  98. into a Modula-2 program might look like this:
  99. #system auto exe
  100. #model mthread jpi
  101. #compile %main
  102. #pragma link(%O%%M%_bt.lib) -- link in btree library
  103. #link %prjname
  104. Note that you must have installed support for the
  105. appropriate operating system, in order to have the necessary
  106. libraries available.
  107. 2) An example project file which implicitly includes the B-
  108. tree object modules might look like this:
  109. #system auto exe
  110. #model mthread jpi
  111. #compile %main
  112. #link %prjname
  113. Note that you must install the B-tree source code to use
  114. this method.
  115. The main reason for using the second method is to be able to
  116. perform source-level debugging with the Btree, FIOx, and Pack
  117. modules. If this debugging ability isn't needed, then using the
  118. first method will make development easier (since the compiler
  119. won't need to recompile the Toolkit source code).
  120. Using With TopSpeed C
  121. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  122. The Btree.H file provides all of the C definitions needed to use
  123. the B-tree Toolkit. (It contains all of the definitions from
  124. Btree.DEF, FIOx.DEF, and apack2.DEF.) Since the Toolkit User's
  125. Manual documents all of the definitions using Modula-2 syntax,
  126. the Btree.H file provides the best reference for determining the
  127. C syntax for the same definitions.
  128. Since the C language does not provide a notation for automatic
  129. initialization of sub-systems, a C program using the Toolkit must
  130. explicitly call the initialization code. This is accomplished by
  131. executing the statement
  132. InitModules(Btree$,NULL);
  133. before any calls are made into the Toolkit. The InitModules()
  134. function is declared in mlang.H. The Btree$ structure is
  135. declared in Btree.H. Note that if data compression is to be
  136. used, then the statement must be changed to
  137. InitModules(Btree$,Pack$,NULL);
  138. in order to initialize the packing routines. See the section
  139. Using Data Compression for details.
  140. TopSpeed C user's must import the B-tree library into their
  141. application's project files. In addition, a special support
  142. library called %O%%M%_btc must be imported. An example project
  143. file might look like this:
  144. #system auto exe
  145. #model large jpi
  146. #compile %main
  147. #pragma link(%O%%M%_bt.lib) -- link in btree library
  148. #pragma link(%O%%M%_btc.lib) -- library for C
  149. #link %prjname
  150. Note that the support libraries must have been installed with the
  151. INSTALL program.
  152. The CBT.C program (and CBT.PRJ project file) serve as an an
  153. example of using the B-tree Toolkit with TopSpeed C. CBT accepts
  154. a single command-line parameter: the name of an input text file.
  155. It uses a B-tree file (named CBT.DAT) to sort the lines in the
  156. input file, and writes the result to standard output. While this
  157. is not necessarily a good illustration of the Toolkit's strengths
  158. (since there are much faster ways to sort a text file), it does
  159. illustrate how to interface to the Toolkit from C. On the other
  160. hand, this example program does use the Toolkit's data
  161. compression capabilities.
  162. Using With Both TopSpeed Modula-2 and TopSpeed C
  163. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  164. User's with both TopSpeed Modula-2 and TopSpeed C can use either
  165. of the any of the above methods in their application's project
  166. files. For mixed-language projects, If the main module is
  167. written in C, then Btree$ (and possibly Pack$)
  168. must be added to the InitModules() statement in the programs
  169. main() function. An example program which uses a Modula-2 main
  170. module and two C files might look like this:
  171. #system auto exe
  172. #model large jpi
  173. #compile mprog.mod
  174. #compile cproga.c
  175. #compile cprogb.c
  176. #pragma link(%O%%M%_bt.lib) -- link in btree library
  177. #link %prjname
  178. Using Data Compression
  179. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  180. This version of the Toolkit provides optional automatic data
  181. compression. Data compression is available only in memory models
  182. which use far data pointers (i.e. Compact, Large, Extra-Large,
  183. and Multi-Thread). Since data compression adds an overhead of
  184. 62K of data space (regardless of whether it is used or not), the
  185. default behavior is to not provide data compression. Data
  186. compression is only enabled when the initialization code of the
  187. Pack module is executed.
  188. Data compression is performed on any variable-length data files
  189. which are within physical files having an access mode of
  190. Compress. Thus, to use data compression, follow these steps:
  191. 1) Import the Pack module into one of the Modula-2 modules
  192. (or include Pack$ in the InitModules() statement of the C
  193. main() function). The Pack module will generate compilation
  194. errors if it is imported in the Small and Medium memory
  195. models.
  196. 2) Open the physical file with an access mode of Compress.
  197. Note that not importing Pack into a Modula-2 module will
  198. cause the error BadOpen to be generated at run-time if this
  199. access mode is used.
  200. 3) Open the logical data files as variable-length (i.e.
  201. specify a record length of 0 to Btree.OpenData()).
  202. 4) Always pass the correct (uncompressed) record length in
  203. calls to Btree.Add(). (If you are converting an existing
  204. program from fixed-length records to variable-length records
  205. with compression, be sure to check all of the calls your
  206. program makes to Btree.Add().)
  207. Apart from these three requirements, data compression is
  208. completely transparent. Data compression has a neglible effect
  209. on the speed of file access. Optimal compression ratios can be
  210. achieved by filling all used portions of records with a common
  211. byte value (preferably 0).
  212. Any call to Btree.Change() for a record in a data-compressed
  213. table will result in a BadSize run-time error.
  214. Any attempt to open a physical file created as Compress with a
  215. mode other than Compress (including attempting to open the file
  216. from the V2.0 Toolkit) will result in a BadOpen run-time error.
  217. Converting File Formats
  218. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  219. Any data files created with a version of the Toolkit prior to
  220. V2.0 must be converted in order to be used with V2.0 or V2.1.
  221. This conversion must be performed by programs which has
  222. information on the format of the data records within the file
  223. (i.e. by programs written by the user of the Toolkit).
  224. Converting the file involves two steps. The first step is to use
  225. the older Toolkit to read all of the data records from the B-tree
  226. file and write them out in an intermediate non-B-tree file. The
  227. second step is to read the records from the intermediate non-B-
  228. tree file and write them to a new B-tree file using the new
  229. Toolkit.
  230. Skeleton programs might look like this:
  231. MODULE Step1;
  232. IMPORT Btree, FIO;
  233. CONST
  234. Access = Btree.FixedSize; (* modify as appropriate *)
  235. Slots = 2; (* modify as appropriate *)
  236. DataSlot = 1; (* modify as appropriate *)
  237. IndexSlot = 1; (* modify as appropriate *)
  238. Dup = TRUE; (* modify as appropriate *)
  239. TYPE
  240. Dat = RECORD (* modify as appropriate *)
  241. END;
  242. Key = RECORD (* modify as appropriate *)
  243. END;
  244. PROCEDURE CompProc(a,b : ADDRESS) : Btree.CmpRes;
  245. BEGIN (* modify as appropriate *)
  246. END CompProc;
  247. PROCEDURE KeyProc(k,d : ADDRESS);
  248. BEGIN (* modify as appropriate *)
  249. END KeyProc;
  250. VAR
  251. fH : Btree.FHandle;
  252. dH,iH : Btree.IHandle;
  253. rec : Dat;
  254. tmp : FIO.File;
  255. BEGIN
  256. fH :=
  257. Btree.Open('Data.OLD',Slots,Access,FALSE,FALSE,FALSE);
  258. dH := Btree.OpenData(fH,DataSlot,SIZE(Dat),FALSE);
  259. iH :=
  260. Btree.OpenIndex(fH,dH,IndexSlot,CompProc,KeyProc,SIZE(Key),
  261. Dup,FALSE);
  262. tmp := FIO.Create('Data.TMP');
  263. Btree.Reset(dH);
  264. WHILE Btree.Next(iH,rec) DO
  265. FIO.WrBin(tmp,rec,SIZE(rec));
  266. END;
  267. FIO.Close(tmp)
  268. Btree.Close(fH);
  269. END Step1.
  270. MODULE Step2;
  271. IMPORT Btree, FIO;
  272. CONST
  273. Access = Btree.FixedSize; (* modify as appropriate *)
  274. Slots = 2; (* modify as appropriate *)
  275. DataSlot = 1; (* modify as appropriate *)
  276. IndexSlot = 1; (* modify as appropriate *)
  277. Dup = TRUE; (* modify as appropriate *)
  278. TYPE
  279. Dat = RECORD (* modify as appropriate *)
  280. END;
  281. Key = RECORD (* modify as appropriate *)
  282. END;
  283. PROCEDURE CompProc(a,b : ADDRESS) : Btree.CmpRes;
  284. BEGIN (* modify as appropriate *)
  285. END CompProc;
  286. PROCEDURE KeyProc(k,d : ADDRESS);
  287. BEGIN (* modify as appropriate *)
  288. END KeyProc;
  289. VAR
  290. fH : Btree.FHandle;
  291. dH,iH : Btree.IHandle;
  292. rec : Dat;
  293. tmp : FIO.File;
  294. BEGIN
  295. fH :=
  296. Btree.Open('Data.NEW',Slots,Access,FALSE,FALSE,TRUE);
  297. dH := Btree.OpenData(fH,DataSlot,SIZE(Dat)tl,TRUE);
  298. iH :=
  299. Btree.OpenIndex(fH,dH,IndexSlot,CompProc,KeyProc,SIZE(Key),
  300. Dup,TRUE);
  301. tmp := FIO.Open('Data.TMP');
  302. WHILE FIO.RdBin(tmp,rec,SIZE(rec))=SIZE(rec) DO
  303. Btree.Add(dH,rec,SIZE(rec));
  304. END;
  305. FIO.Close(tmp)
  306. Btree.Close(fH);
  307. END Step2.
  308. Again, the Step1 program must be linked using the older version
  309. of the Toolkit, and the Step2 program must be linked using the
  310. newer version of the Toolkit.
  311. Rebuilding the Toolkit
  312. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  313. The Toolkit source code is in the following files:
  314. Btree.DEF/.MOD - b-tree routines
  315. FIOx.DEF/.MOD - file i/o routines
  316. Pack.DEF/.MOD - high-level packing routines
  317. apack2.DEF/.A - low-level assembly packing routines
  318. The B-tree Toolkit libries can be made with the project
  319. file:
  320. MKBTREE.PR
  321. The model, operating system, whether C support is required,
  322. and whether packing is required should be set in this
  323. project file before making any particular library.
  324. Rebuilding the Toolkit libraries requires TopSpeed Modula-2.
  325. Errata
  326. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  327. The B-tree Toolkit uses mixed-model programming to overcome
  328. limitations of the Small and Medium memory models. Even so,
  329. manipulating large index files from within Small or Medium model
  330. programs may cause the B-tree system to exhaust all of heap
  331. memory. If this happens, the application may not terminate
  332. gracefully!
  333. -----------------------------------------------------------------
  334. The Btree.SetSyncMode documentation is incorrect. It should read
  335. as follows:
  336. PROCEDURE SetSyncMode(D: IHandle; On: BOOLEAN);
  337. Normally, each index maintains an independent "current record"
  338. pointer. If the SetSyncMode procedure is called with its second
  339. parameter set to TRUE, then these index operations will cause all
  340. indexes related to that data file to be moved to the located
  341. record: Find, Search, Next, Prev. (The result from any other
  342. index operations is undefined.) The procedure may be called with
  343. the second parameter as FALSE, to disable index syncronization.
  344. This procedure always calls Reset() with the data file handle.
  345. This means that whenever synchronization starts or ends, all of
  346. the indexes for the data file are set so that a Next or Prev call
  347. returns the first or last record, respectively.
  348. This procedure may only be called for data file handles.
  349. Error condition Last Error Value ErrorHandler Called
  350. =============== ================ ===================
  351. Not a data handle NotData yes
  352. -----------------------------------------------------------------
  353. When the Next and Prev procedures fail due to the data file being
  354. locked, they leave the location pointer for that index unchanged
  355. from its state before the call. The following algorithm is
  356. recommended for scanning through a data file sequentially, when
  357. other processes may be locking data records:
  358. LOOP
  359. IF Next(IndexFile,Record) THEN
  360. (* A *) (* process the record *)
  361. ELSE
  362. CASE LastError(IndexFile) OF
  363. OK : EXIT; (* past end of index *)
  364. | Locked : IF NextIndex(IndexFile,Location) THEN
  365. (* B *) (* either the index was briefly
  366. locked, or the
  367. data record was locked *)
  368. ELSE
  369. CASE LastError(IndexFile) OF
  370. OK : HALT; (* this should never
  371. happen *)
  372. | Locked : EXIT; (* the index is locked *)
  373. ELSE
  374. EXIT; (* some other error occured *)
  375. END;
  376. END;
  377. ELSE
  378. (* some other error occured *)
  379. END;
  380. END;
  381. END;
  382. This algorithm is useful for providing a list of records to the
  383. user. The application could print the contents of the records
  384. returned by the Next call (location A), and could print a line
  385. saying that the record is locked for records returned by the
  386. NextIndex call (location B).
  387. -----------------------------------------------------------------
  388. When the ClearIndex procedure is called for an index in a shared
  389. file, the last error value is BadFree, and the error handler
  390. procedure is called.
  391. -----------------------------------------------------------------
  392. In some cases, it is illegal to call the FreeIHandle procedure
  393. for an IHandle stored within a shared file. If this happens, the
  394. last error value is BadFree, and the error handler procedure is
  395. called.
  396. Specifically, any attempt to FreeIHandle for an index handle
  397. which is associated with a data handle is illegal. Note that it
  398. is legal to FreeIHandle for a data handle (in which case all of
  399. the index handles are also freed), as well as for an index handle
  400. which is not associated with a data handle.
  401. -----------------------------------------------------------------
  402. Since all of the file locking primitives are isolated in the FIOX
  403. module, it is fairly simple to customize the package for a
  404. particular environment. For example, under VM/386 file locking
  405. is always available, regardless of whether SHARE is loaded or
  406. not. The FIOx.Multi() procedure could be modified to return TRUE
  407. if the program is running under VM/386. Additionally, the
  408. locking calls can be easily customized for a particular network's
  409. API.
  410. You must have TopSpeed Modula-2 in order to recompile the source
  411. code after making these changes.
  412. -----------------------------------------------------------------
  413. The B-tree Toolkit may be freely used in a (DOS or OS/2) multi-
  414. threaded program. All operating system calls are locked as
  415. necessary, and the B-tree internal least-recently-used buffer and
  416. packing buffer are protected by locking.
  417. In a multi-threaded environment, each thread wishing to access a
  418. file must open its own handles for the file, specifying that the
  419. file is to be shared. This will ensure that the threads do not
  420. corrupt each other's file information. Alternatively, the
  421. application must ensure that while one thread is performing any
  422. operations on an FHandle(or any IHandles within it), that no
  423. other threads attempt to use that same FHandle (or any IHandles
  424. within it).
  425. -----------------------------------------------------------------
  426. The Btree.LastRef procedure has been added:
  427. PROCEDURE LastRef(I: IHandle): LONGCARD;
  428. This procedure returns the last data position referenced by a
  429. data or index handle. For instance, after an Add() operation,
  430. LastRef() for the data handle or any of its associated index
  431. handles will return the postion that the data record was written
  432. to. After a Find() operation, LastRef() will return the position
  433. that the record was read from.
  434. -----------------------------------------------------------------
  435. The Btree.RecordCount procedure has been added:
  436. PROCEDURE RecordCount(I: IHandle): LONGCARD;
  437. This procedure returns the number of records in a data handle or
  438. the number of keys in an index handle. For shared files, the
  439. handle must already be locked and will not be unlocked by this
  440. call. For shared files, the record count could change at any
  441. time that the process does not have a lock on the handle.
  442. Error condition Last Error Value ErrorHandler Called
  443. =============== ================ ===================
  444. Not an IHandle NotIHandle yes
  445. Not locked NotLocked yes
  446. -----------------------------------------------------------------
  447. The B-tree Toolkit attempts to intelligently determine whether
  448. files should be buffered or not, based upon the user's
  449. specification or whether file sharing should be allowed, and
  450. whether the file resides in a location where multi-access is
  451. possible. If both sharing and multi-access are enabled, then the
  452. file will *not* be buffered (because other processes could cause
  453. the in-memory buffer to become out-of-date). If either sharing
  454. or multi-access is disabled, then no other processes may access
  455. the file, and buffering will occur.
  456. The OS/2 FIOx module always allows multi-access.
  457. The DOS version of the FIOx module determines whether multi-
  458. access is
  459. available using the following algorithm:
  460. if the environment variable "multi" = "yes", then multi is
  461. available,
  462. elsif the environment variable "multi" = "no" then multi is no
  463. available,
  464. elsif the DOS version is 3.x+ and SHARE is installed, then
  465. multi is available,
  466. else
  467. multi is done on a file-by-file basis
  468. end
  469. If multi is done on a file-by-file basis (i.e. the last case of
  470. the above algorithm), and an application attempts to open a file
  471. in shared mode, then FIOx will attempt to determine if the file
  472. resides on a network drive:
  473. attempt to open file in ReadOnly DenyNone mode
  474. if file is opened and IOCTL signals that the file is remote,
  475. then
  476. attempt to open file with sharing, and return result
  477. end
  478. end
  479. attempt to open file without sharing, and return result
  480. Applications should follow these guidelines:
  481. 1) Applications which are designed to share files, which are
  482. run in a sharing environment, will share files.
  483. 2) Applications which are designed to share files, which are
  484. run in a *non*-sharing environment, will have exclusive use of
  485. the files.
  486. 3) Applications which are designed to *not* share files will
  487. always open the files in non-sharing mode, thus preventing all
  488. other processes from using them concurrently.
  489. Users should follow these guidelines:
  490. 1) If you are not using file sharing, you don't have to do
  491. anything special - just open the files in non-shared mode.
  492. 2) If you are using file sharing on a LAN that loades
  493. SHARE.EXE, you don't have to do anything special - Btree will
  494. detect that SHARE is loaded, and will share files that you open
  495. in shared mode.
  496. 3) If you are using file sharing on a LAN that supports IOCTL
  497. detection that the file is on a remote device (this include
  498. Novell's NetWare v2.1x), you don't have to do anything special -
  499. just open the files in shared mode.
  500. 4) If you want to always prevent sharing, then before your
  501. programs load, use SET MULTI=NO from the DOS command line. This
  502. will cause all files opened (in sharing mode or not) to be opened
  503. for exclusive access (regardless of whether SHARE is loaded or
  504. the file is on a network device).
  505. 5) If you want to always allow sharing, then before your
  506. programs load, use SET MULTI=YES from the DOS command line. This
  507. will cause all files opened in sharing mode to be opened for
  508. sharing (regardless of whether SHARE is loaded or the file is on
  509. a network device). Note that this may be incompatible in
  510. environments where the DOS file locking calls are not always
  511. available.
  512. -----------------------------------------------------------------
  513. The FIOx.Multi procedure has been changed:
  514. TYPE
  515. MultiMode = (_multi_yes,_multi_no,_multi_file);
  516. PROCEDURE Multi(): MultiMode;
  517. This procedure will return _multi_yes if multi-access is always
  518. available (i.e. SHARE is loaded, multi=yes in the environment, or
  519. OS/2 is being used),_multi_no if multi-access is disallowed (i.e.
  520. multi=no in the environment), or _multi_file if multi-access
  521. should be done on a file-by-file basis.
  522. The FIOx.MultiFile procedure has been added:
  523. PROCEDURE MultiFile(f: File): BOOLEAN;
  524. This procedure returns TRUE if the file should be used in multi-
  525. access mode. It is closely related to the Multi() procedure:
  526. 1) Multi() = _multi_yes ==> MultiFile() = TRUE
  527. 2) Multi() = _multi_no ==> MultiFile() = FALSE
  528. 3) Multi() = _multi_file ==> MultiFile() = TRUE if file is on
  529. net device
  530. Note that Btree does not provide a procedure for determing if an
  531. FHandle is actually being shared - applications should be written
  532. to be ignorant of the actual sharing mode of the file.
  533.