summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/palmunits/src/fslib.pp
blob: 3ebb41eb07caeb43373d4f0538f3b8b36d7c11bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
{$MACRO ON}

{$define Rsc := }
(******************************************************************************
 *
 * Copyright (c) 1998-2000 Palm, Inc. or its subsidiaries.
 * All rights reserved.
 *
 * File: FSLib.h
 *
 * Release: Palm OS SDK 4.0 (63220)
 *
 * Description:
 *              Sample file system library implementation.
 *
 * History:
 *    02/29/00 Created by Steve Minns
 *    10/27/00 CS    Include VFSMgr.h, since we depend on it.
 *
 *****************************************************************************)

(********************************************************************
 * Filename and Label conventions:
 *
 * All path names are absolute
 *
 * All filesystems must support filenames and labels that are up to 255 characters long,
 * using any normal character including spaces and lower case characters in any
 * character set and the following special characters:
 * $ % ' - _ @ ~ ` ! ( ) ^ # & + , ; = [ ]
 ********************************************************************
 * When creating the 8.3 name or label from a long filename or label:
 *  a) Create the name from the first 1-6 valid, non-space characters, before the last period.
 *    The only valid characters are:
 *       A-Z 0-9 $ % ' - _ @ ~ ` ! ( ) ^ # &
 *  b) the extension is the first three valid characters after the last period '.'
 *  c) the end of the 6 byte name is appended with ~1, or the next unique number.
 *
 * A label is created from the first 11 valid non-space characters.
 ********************************************************************)

unit fslib;

interface

uses palmos, libtraps, vfsmgr;

// When building the PalmOS 3.5 version of ExpansionMgr,
// since this constant was not in the 3.5 SystemResources.h...
const
  sysFileTFileSystem = RSC('libf'); // File type for file system libraries

  fsLibAPIVersion_ = $00000002;

(********************************************************************
 * Type of FS Library database
 ********************************************************************)

(********************************************************************
 * FS library function trap ID's. Each library call gets a trap number:
 *   FSTrapXXXX which serves as an index into the library's dispatch table.
 *   The constant sysLibTrapCustom is the first available trap number after
 *   the system predefined library traps Open,Close,Sleep & Wake.
 *
 * WARNING!!! The order of these traps MUST match the order of the dispatch
 *  table in FSLibDispatch.c!!!
 ********************************************************************)

const
  FSTrapLibAPIVersion      = sysLibTrapCustom;
  FSTrapCustomControl      = sysLibTrapCustom + 1;
  FSTrapFilesystemType     = sysLibTrapCustom + 2;

  FSTrapFileCreate         = sysLibTrapCustom + 3;
  FSTrapFileOpen           = sysLibTrapCustom + 4;
  FSTrapFileClose          = sysLibTrapCustom + 5;
  FSTrapFileRead           = sysLibTrapCustom + 6;
  FSTrapFileWrite          = sysLibTrapCustom + 7;
  FSTrapFileDelete         = sysLibTrapCustom + 8;
  FSTrapFileRename         = sysLibTrapCustom + 9;
  FSTrapFileSeek           = sysLibTrapCustom + 10;
  FSTrapFileEOF            = sysLibTrapCustom + 11;
  FSTrapFileTell           = sysLibTrapCustom + 12;
  FSTrapFileResize         = sysLibTrapCustom + 13;
  FSTrapFileGetAttributes  = sysLibTrapCustom + 14;
  FSTrapFileSetAttributes  = sysLibTrapCustom + 15;
  FSTrapFileGetDate        = sysLibTrapCustom + 16;
  FSTrapFileSetDate        = sysLibTrapCustom + 17;
  FSTrapFileSize           = sysLibTrapCustom + 18;

  FSTrapDirCreate          = sysLibTrapCustom + 19;
  FSTrapDirEntryEnumerate  = sysLibTrapCustom + 20;

  FSTrapVolumeFormat       = sysLibTrapCustom + 21;
  FSTrapVolumeMount        = sysLibTrapCustom + 22;
  FSTrapVolumeUnmount      = sysLibTrapCustom + 23;
  FSTrapVolumeInfo         = sysLibTrapCustom + 24;
  FSTrapVolumeGetLabel     = sysLibTrapCustom + 25;
  FSTrapVolumeSetLabel     = sysLibTrapCustom + 26;
  FSTrapVolumeSize         = sysLibTrapCustom + 27;

  FSMaxSelector            = FSTrapVolumeSize;

(********************************************************************
 * API Prototypes
 ********************************************************************)

(********************************************************************
 * Standard library open, close, sleep and wake APIs:
 ********************************************************************)

function FSLibOpen(fsLibRefNum: UInt16): Err; syscall sysLibTrapOpen;

function FSLibClose(fsLibRefNum: UInt16): Err; syscall sysLibTrapClose;

function FSLibSleep(fsLibRefNum: UInt16): Err; syscall sysLibTrapSleep;

function FSLibWake(fsLibRefNum: UInt16): Err; syscall sysLibTrapWake;

(********************************************************************
 * Custom library APIs:
 ********************************************************************)

function FSLibAPIVersion(fsLibRefNum: UInt16): UInt32; syscall FSTrapLibAPIVersion;

function FSCustomControl(fsLibRefNum: UInt16; apiCreator: UInt32; apiSelector: UInt16;
                         valueP: Pointer; var valueLenP: UInt16): Err; syscall FSTrapCustomControl;

function FSFilesystemType(fsLibRefNum: UInt16; var filesystemTypeP: UInt32): Err; syscall FSTrapFilesystemType;

(********************************************************************
 * File Stream APIs:
 ********************************************************************)

function FSFileCreate(fsLibRefNum: UInt16; volRefNum: UInt16; const pathNameP: PChar): Err; syscall FSTrapFileCreate;

function FSFileOpen(fsLibRefNum: UInt16; volRefNum: UInt16; const pathNameP: PChar;
                    openMode: UInt16; var fileRefP: FileRef): Err; syscall FSTrapFileOpen;

function FSFileClose(fsLibRefNum: UInt16; fileRef: FileRef): Err; syscall FSTrapFileClose;

function FSFileRead(fsLibRefNumUInt16: UInt16; fileRef: FileRef; numBytes: UInt32;
                    bufBaseP: Pointer; offset: UInt32; dataStoreBased: Boolean;
                    var numBytesReadP: UInt32): Err; syscall FSTrapFileRead;

function FSFileWrite(fsLibRefNum: UInt16; fileRef: FileRef; numBytes: UInt32;
                     const dataP: Pointer; var numBytesWrittenP: UInt32): Err; syscall FSTrapFileWrite;

function FSFileDelete(fsLibRefNum: UInt16; volRefNum: UInt16; const pathNameP: PChar): Err; syscall FSTrapFileDelete;

function FSFileRename(fsLibRefNum: UInt16; volRefNum: UInt16; const pathNameP: PChar; const newNameP: PChar): Err; syscall FSTrapFileRename;

function FSFileSeek(fsLibRefNum: UInt16; fileRef: FileRef; origin: FileOrigin; offset: Int32): Err; syscall FSTrapFileSeek;

function FSFileEOF(fsLibRefNum: UInt16; fileRef: FileRef): Err; syscall FSTrapFileEOF;

function FSFileTell(fsLibRefNum: UInt16; fileRef: FileRef; var filePosP: UInt32): Err; syscall FSTrapFileTell;

function FSFileResize(fsLibRefNum: UInt16; fileRef: FileRef; newSize: UInt32): Err; syscall FSTrapFileResize;

function FSFileGetAttributes(fsLibRefNum: UInt16; fileRef: FileRef; var attributesP: UInt32): Err; syscall FSTrapFileGetAttributes;

function FSFileSetAttributes(fsLibRefNum: UInt16; fileRef: FileRef; attributes: UInt32): Err; syscall FSTrapFileSetAttributes;

function FSFileGetDate(fsLibRefNum: UInt16; fileRef: FileRef; whichDate: UInt16; var dateP: UInt32): Err; syscall FSTrapFileGetDate;

function FSFileSetDate(fsLibRefNum: UInt16; fileRef: FileRef; whichDate: UInt16; date: UInt32): Err; syscall FSTrapFileSetDate;

function FSFileSize(fsLibRefNum: UInt16; fileRef: FileRef; var fileSizeP: UInt32): Err; syscall FSTrapFileSize;

(********************************************************************
 * Directory APIs:
 ********************************************************************)

function FSDirCreate(fsLibRefNum: UInt16; volRefNum: UInt16; const dirNameP: PChar): Err; syscall FSTrapDirCreate;

(************************************************************
 *
 *  MACRO:        FSDirDelete
 *
 *  DESCRIPTION:  Delete a closed directory.
 *
 *  PARAMETERS:   fsLibRefNum          -- FS library reference number
 *          volRefNum            -- Volume reference number returned by FSVolumeMount
 *          pathNameP            -- Full path of the directory to be deleted
 *
 *  RETURNS:   errNone              -- no error
 *          expErrNotOpen        -- FS driver library has not been opened
 *          vfsErrFileStillOpen     -- Directory is still open
 *          vfsErrFileNotFound      -- the file could not be found
 *          vfsErrVolumeBadRef      -- the volume has not been mounted with FSVolumeMount
 *
 *************************************************************)

function FSDirDelete(fsLibRefNum: UInt16; volRefNum: UInt16; const dirNameP: PChar): Err;

function FSDirEntryEnumerate(fsLibRefNum: UInt16; dirRef: FileRef; var dirEntryIteratorP: UInt32; var infoP: FileInfoType): Err; syscall FSTrapDirEntryEnumerate;

(********************************************************************
 * Volume APIs:
 ********************************************************************)

function FSVolumeFormat(fsLibRefNum: UInt16; vfsMountParamP: VFSAnyMountParamPtr): Err; syscall FSTrapVolumeFormat;

function FSVolumeMount(fsLibRefNum: UInt16; vfsMountParamP: VFSAnyMountParamPtr): Err; syscall FSTrapVolumeMount;

function FSVolumeUnmount(fsLibRefNum: UInt16; volRefNum: UInt16): Err; syscall FSTrapVolumeUnmount;

function FSVolumeInfo(fsLibRefNum: UInt16; volRefNum: UInt16; var volInfoP: VolumeInfoType): Err; syscall FSTrapVolumeInfo;

function FSVolumeGetLabel(fsLibRefNum: UInt16; volRefNum: UInt16; labelP: PChar; bufLen: UInt16): Err; syscall FSTrapVolumeGetLabel;

function FSVolumeSetLabel(fsLibRefNum: UInt16; volRefNum: UInt16; const labelP: PChar): Err; syscall FSTrapVolumeSetLabel;

function FSVolumeSize(fsLibRefNum: UInt16; volRefNum: UInt16; var volumeUsedP: UInt32; var volumeTotalP: UInt32): Err; syscall FSTrapVolumeSize;

implementation

function FSDirDelete(fsLibRefNum: UInt16; volRefNum: UInt16; const dirNameP: PChar): Err;
begin
  FSDirDelete := FSFileDelete(fsLibRefNum, volRefNum, dirNameP);
end;

end.