fslib.pp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. {$MACRO ON}
  2. {$define Rsc := }
  3. (******************************************************************************
  4. *
  5. * Copyright (c) 1998-2000 Palm, Inc. or its subsidiaries.
  6. * All rights reserved.
  7. *
  8. * File: FSLib.h
  9. *
  10. * Release: Palm OS SDK 4.0 (63220)
  11. *
  12. * Description:
  13. * Sample file system library implementation.
  14. *
  15. * History:
  16. * 02/29/00 Created by Steve Minns
  17. * 10/27/00 CS Include VFSMgr.h, since we depend on it.
  18. *
  19. *****************************************************************************)
  20. (********************************************************************
  21. * Filename and Label conventions:
  22. *
  23. * All path names are absolute
  24. *
  25. * All filesystems must support filenames and labels that are up to 255 characters long,
  26. * using any normal character including spaces and lower case characters in any
  27. * character set and the following special characters:
  28. * $ % ' - _ @ ~ ` ! ( ) ^ # & + , ; = [ ]
  29. ********************************************************************
  30. * When creating the 8.3 name or label from a long filename or label:
  31. * a) Create the name from the first 1-6 valid, non-space characters, before the last period.
  32. * The only valid characters are:
  33. * A-Z 0-9 $ % ' - _ @ ~ ` ! ( ) ^ # &
  34. * b) the extension is the first three valid characters after the last period '.'
  35. * c) the end of the 6 byte name is appended with ~1, or the next unique number.
  36. *
  37. * A label is created from the first 11 valid non-space characters.
  38. ********************************************************************)
  39. unit fslib;
  40. interface
  41. uses palmos, libtraps, vfsmgr;
  42. // When building the PalmOS 3.5 version of ExpansionMgr,
  43. // since this constant was not in the 3.5 SystemResources.h...
  44. const
  45. sysFileTFileSystem = RSC('libf'); // File type for file system libraries
  46. fsLibAPIVersion_ = $00000002;
  47. (********************************************************************
  48. * Type of FS Library database
  49. ********************************************************************)
  50. (********************************************************************
  51. * FS library function trap ID's. Each library call gets a trap number:
  52. * FSTrapXXXX which serves as an index into the library's dispatch table.
  53. * The constant sysLibTrapCustom is the first available trap number after
  54. * the system predefined library traps Open,Close,Sleep & Wake.
  55. *
  56. * WARNING!!! The order of these traps MUST match the order of the dispatch
  57. * table in FSLibDispatch.c!!!
  58. ********************************************************************)
  59. const
  60. FSTrapLibAPIVersion = sysLibTrapCustom;
  61. FSTrapCustomControl = sysLibTrapCustom + 1;
  62. FSTrapFilesystemType = sysLibTrapCustom + 2;
  63. FSTrapFileCreate = sysLibTrapCustom + 3;
  64. FSTrapFileOpen = sysLibTrapCustom + 4;
  65. FSTrapFileClose = sysLibTrapCustom + 5;
  66. FSTrapFileRead = sysLibTrapCustom + 6;
  67. FSTrapFileWrite = sysLibTrapCustom + 7;
  68. FSTrapFileDelete = sysLibTrapCustom + 8;
  69. FSTrapFileRename = sysLibTrapCustom + 9;
  70. FSTrapFileSeek = sysLibTrapCustom + 10;
  71. FSTrapFileEOF = sysLibTrapCustom + 11;
  72. FSTrapFileTell = sysLibTrapCustom + 12;
  73. FSTrapFileResize = sysLibTrapCustom + 13;
  74. FSTrapFileGetAttributes = sysLibTrapCustom + 14;
  75. FSTrapFileSetAttributes = sysLibTrapCustom + 15;
  76. FSTrapFileGetDate = sysLibTrapCustom + 16;
  77. FSTrapFileSetDate = sysLibTrapCustom + 17;
  78. FSTrapFileSize = sysLibTrapCustom + 18;
  79. FSTrapDirCreate = sysLibTrapCustom + 19;
  80. FSTrapDirEntryEnumerate = sysLibTrapCustom + 20;
  81. FSTrapVolumeFormat = sysLibTrapCustom + 21;
  82. FSTrapVolumeMount = sysLibTrapCustom + 22;
  83. FSTrapVolumeUnmount = sysLibTrapCustom + 23;
  84. FSTrapVolumeInfo = sysLibTrapCustom + 24;
  85. FSTrapVolumeGetLabel = sysLibTrapCustom + 25;
  86. FSTrapVolumeSetLabel = sysLibTrapCustom + 26;
  87. FSTrapVolumeSize = sysLibTrapCustom + 27;
  88. FSMaxSelector = FSTrapVolumeSize;
  89. (********************************************************************
  90. * API Prototypes
  91. ********************************************************************)
  92. (********************************************************************
  93. * Standard library open, close, sleep and wake APIs:
  94. ********************************************************************)
  95. function FSLibOpen(fsLibRefNum: UInt16): Err; syscall sysLibTrapOpen;
  96. function FSLibClose(fsLibRefNum: UInt16): Err; syscall sysLibTrapClose;
  97. function FSLibSleep(fsLibRefNum: UInt16): Err; syscall sysLibTrapSleep;
  98. function FSLibWake(fsLibRefNum: UInt16): Err; syscall sysLibTrapWake;
  99. (********************************************************************
  100. * Custom library APIs:
  101. ********************************************************************)
  102. function FSLibAPIVersion(fsLibRefNum: UInt16): UInt32; syscall FSTrapLibAPIVersion;
  103. function FSCustomControl(fsLibRefNum: UInt16; apiCreator: UInt32; apiSelector: UInt16;
  104. valueP: Pointer; var valueLenP: UInt16): Err; syscall FSTrapCustomControl;
  105. function FSFilesystemType(fsLibRefNum: UInt16; var filesystemTypeP: UInt32): Err; syscall FSTrapFilesystemType;
  106. (********************************************************************
  107. * File Stream APIs:
  108. ********************************************************************)
  109. function FSFileCreate(fsLibRefNum: UInt16; volRefNum: UInt16; const pathNameP: PChar): Err; syscall FSTrapFileCreate;
  110. function FSFileOpen(fsLibRefNum: UInt16; volRefNum: UInt16; const pathNameP: PChar;
  111. openMode: UInt16; var fileRefP: FileRef): Err; syscall FSTrapFileOpen;
  112. function FSFileClose(fsLibRefNum: UInt16; fileRef: FileRef): Err; syscall FSTrapFileClose;
  113. function FSFileRead(fsLibRefNumUInt16: UInt16; fileRef: FileRef; numBytes: UInt32;
  114. bufBaseP: Pointer; offset: UInt32; dataStoreBased: Boolean;
  115. var numBytesReadP: UInt32): Err; syscall FSTrapFileRead;
  116. function FSFileWrite(fsLibRefNum: UInt16; fileRef: FileRef; numBytes: UInt32;
  117. const dataP: Pointer; var numBytesWrittenP: UInt32): Err; syscall FSTrapFileWrite;
  118. function FSFileDelete(fsLibRefNum: UInt16; volRefNum: UInt16; const pathNameP: PChar): Err; syscall FSTrapFileDelete;
  119. function FSFileRename(fsLibRefNum: UInt16; volRefNum: UInt16; const pathNameP: PChar; const newNameP: PChar): Err; syscall FSTrapFileRename;
  120. function FSFileSeek(fsLibRefNum: UInt16; fileRef: FileRef; origin: FileOrigin; offset: Int32): Err; syscall FSTrapFileSeek;
  121. function FSFileEOF(fsLibRefNum: UInt16; fileRef: FileRef): Err; syscall FSTrapFileEOF;
  122. function FSFileTell(fsLibRefNum: UInt16; fileRef: FileRef; var filePosP: UInt32): Err; syscall FSTrapFileTell;
  123. function FSFileResize(fsLibRefNum: UInt16; fileRef: FileRef; newSize: UInt32): Err; syscall FSTrapFileResize;
  124. function FSFileGetAttributes(fsLibRefNum: UInt16; fileRef: FileRef; var attributesP: UInt32): Err; syscall FSTrapFileGetAttributes;
  125. function FSFileSetAttributes(fsLibRefNum: UInt16; fileRef: FileRef; attributes: UInt32): Err; syscall FSTrapFileSetAttributes;
  126. function FSFileGetDate(fsLibRefNum: UInt16; fileRef: FileRef; whichDate: UInt16; var dateP: UInt32): Err; syscall FSTrapFileGetDate;
  127. function FSFileSetDate(fsLibRefNum: UInt16; fileRef: FileRef; whichDate: UInt16; date: UInt32): Err; syscall FSTrapFileSetDate;
  128. function FSFileSize(fsLibRefNum: UInt16; fileRef: FileRef; var fileSizeP: UInt32): Err; syscall FSTrapFileSize;
  129. (********************************************************************
  130. * Directory APIs:
  131. ********************************************************************)
  132. function FSDirCreate(fsLibRefNum: UInt16; volRefNum: UInt16; const dirNameP: PChar): Err; syscall FSTrapDirCreate;
  133. (************************************************************
  134. *
  135. * MACRO: FSDirDelete
  136. *
  137. * DESCRIPTION: Delete a closed directory.
  138. *
  139. * PARAMETERS: fsLibRefNum -- FS library reference number
  140. * volRefNum -- Volume reference number returned by FSVolumeMount
  141. * pathNameP -- Full path of the directory to be deleted
  142. *
  143. * RETURNS: errNone -- no error
  144. * expErrNotOpen -- FS driver library has not been opened
  145. * vfsErrFileStillOpen -- Directory is still open
  146. * vfsErrFileNotFound -- the file could not be found
  147. * vfsErrVolumeBadRef -- the volume has not been mounted with FSVolumeMount
  148. *
  149. *************************************************************)
  150. function FSDirDelete(fsLibRefNum: UInt16; volRefNum: UInt16; const dirNameP: PChar): Err;
  151. function FSDirEntryEnumerate(fsLibRefNum: UInt16; dirRef: FileRef; var dirEntryIteratorP: UInt32; var infoP: FileInfoType): Err; syscall FSTrapDirEntryEnumerate;
  152. (********************************************************************
  153. * Volume APIs:
  154. ********************************************************************)
  155. function FSVolumeFormat(fsLibRefNum: UInt16; vfsMountParamP: VFSAnyMountParamPtr): Err; syscall FSTrapVolumeFormat;
  156. function FSVolumeMount(fsLibRefNum: UInt16; vfsMountParamP: VFSAnyMountParamPtr): Err; syscall FSTrapVolumeMount;
  157. function FSVolumeUnmount(fsLibRefNum: UInt16; volRefNum: UInt16): Err; syscall FSTrapVolumeUnmount;
  158. function FSVolumeInfo(fsLibRefNum: UInt16; volRefNum: UInt16; var volInfoP: VolumeInfoType): Err; syscall FSTrapVolumeInfo;
  159. function FSVolumeGetLabel(fsLibRefNum: UInt16; volRefNum: UInt16; labelP: PChar; bufLen: UInt16): Err; syscall FSTrapVolumeGetLabel;
  160. function FSVolumeSetLabel(fsLibRefNum: UInt16; volRefNum: UInt16; const labelP: PChar): Err; syscall FSTrapVolumeSetLabel;
  161. function FSVolumeSize(fsLibRefNum: UInt16; volRefNum: UInt16; var volumeUsedP: UInt32; var volumeTotalP: UInt32): Err; syscall FSTrapVolumeSize;
  162. implementation
  163. function FSDirDelete(fsLibRefNum: UInt16; volRefNum: UInt16; const dirNameP: PChar): Err;
  164. begin
  165. FSDirDelete := FSFileDelete(fsLibRefNum, volRefNum, dirNameP);
  166. end;
  167. end.