]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h
Integrate patch from Andrew Fish to make it run on OS X.
[mirror_edk2.git] / UnixPkg / UnixSimpleFileSystemDxe / UnixSimpleFileSystem.h
1 /*++
2
3 Copyright (c) 2006 - 2008, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 UnixSimpleFileSystem.h
15
16 Abstract:
17
18 Produce Simple File System abstractions for a directory on your PC using Unix APIs.
19 The configuration of what devices to mount or emulate comes from
20 environment variables.
21
22 --*/
23
24 #ifndef _UNIX_SIMPLE_FILE_SYSTEM_H_
25 #define _UNIX_SIMPLE_FILE_SYSTEM_H_
26
27 #include "PiDxe.h"
28 #include <Guid/FileSystemInfo.h>
29 #include <Guid/FileInfo.h>
30 #include <Guid/FileSystemVolumeLabelInfo.h>
31 #include <Protocol/SimpleFileSystem.h>
32
33 #include <Library/DebugLib.h>
34 #include <Library/BaseLib.h>
35 #include <Library/UefiDriverEntryPoint.h>
36 #include <Library/UefiLib.h>
37 #include <Library/BaseMemoryLib.h>
38 #include <Library/MemoryAllocationLib.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include "UnixDxe.h"
41
42 extern EFI_DRIVER_BINDING_PROTOCOL gUnixSimpleFileSystemDriverBinding;
43 extern EFI_COMPONENT_NAME_PROTOCOL gUnixSimpleFileSystemComponentName;
44
45
46 #define UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE SIGNATURE_32 ('L', 'X', 'f', 's')
47
48 typedef struct {
49 UINTN Signature;
50 EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
51 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFileSystem;
52 CHAR8 *FilePath;
53 CHAR16 *VolumeLabel;
54 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
55 } UNIX_SIMPLE_FILE_SYSTEM_PRIVATE;
56
57 #define UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS(a) \
58 CR (a, \
59 UNIX_SIMPLE_FILE_SYSTEM_PRIVATE, \
60 SimpleFileSystem, \
61 UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE \
62 )
63
64 #define UNIX_EFI_FILE_PRIVATE_SIGNATURE SIGNATURE_32 ('l', 'o', 'f', 's')
65
66 typedef struct {
67 UINTN Signature;
68 EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
69 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;
70 EFI_FILE EfiFile;
71 INTN fd;
72 DIR *Dir;
73 BOOLEAN IsRootDirectory;
74 BOOLEAN IsDirectoryPath;
75 BOOLEAN IsOpenedByRead;
76 char *FileName;
77 struct dirent *Dirent;
78 } UNIX_EFI_FILE_PRIVATE;
79
80 #define UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS(a) \
81 CR (a, \
82 UNIX_EFI_FILE_PRIVATE, \
83 EfiFile, \
84 UNIX_EFI_FILE_PRIVATE_SIGNATURE \
85 )
86
87 //
88 // Global Protocol Variables
89 //
90 extern EFI_DRIVER_BINDING_PROTOCOL gUnixSimpleFileSystemDriverBinding;
91 extern EFI_COMPONENT_NAME_PROTOCOL gUnixSimpleFileSystemComponentName;
92
93 //
94 // Driver Binding protocol member functions
95 //
96 EFI_STATUS
97 EFIAPI
98 UnixSimpleFileSystemDriverBindingSupported (
99 IN EFI_DRIVER_BINDING_PROTOCOL *This,
100 IN EFI_HANDLE ControllerHandle,
101 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
102 )
103 /*++
104
105 Routine Description:
106
107 Check to see if the driver supports a given controller.
108
109 Arguments:
110
111 This - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.
112
113 ControllerHandle - EFI handle of the controller to test.
114
115 RemainingDevicePath - Pointer to remaining portion of a device path.
116
117 Returns:
118
119 EFI_SUCCESS - The device specified by ControllerHandle and RemainingDevicePath is supported by the driver
120 specified by This.
121
122 EFI_ALREADY_STARTED - The device specified by ControllerHandle and RemainingDevicePath is already being managed by
123 the driver specified by This.
124
125 EFI_ACCESS_DENIED - The device specified by ControllerHandle and RemainingDevicePath is already being managed by
126 a different driver or an application that requires exclusive access.
127
128 EFI_UNSUPPORTED - The device specified by ControllerHandle and RemainingDevicePath is not supported by the
129 driver specified by This.
130
131 --*/
132 ;
133
134 EFI_STATUS
135 EFIAPI
136 UnixSimpleFileSystemDriverBindingStart (
137 IN EFI_DRIVER_BINDING_PROTOCOL *This,
138 IN EFI_HANDLE ControllerHandle,
139 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
140 )
141 /*++
142
143 Routine Description:
144
145 Starts a device controller or a bus controller.
146
147 Arguments:
148
149 This - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.
150
151 ControllerHandle - EFI handle of the controller to start.
152
153 RemainingDevicePath - Pointer to remaining portion of a device path.
154
155 Returns:
156
157 EFI_SUCCESS - The device or bus controller has been started.
158
159 EFI_DEVICE_ERROR - The device could not be started due to a device failure.
160
161 EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources.
162
163 --*/
164 ;
165
166 EFI_STATUS
167 EFIAPI
168 UnixSimpleFileSystemDriverBindingStop (
169 IN EFI_DRIVER_BINDING_PROTOCOL *This,
170 IN EFI_HANDLE ControllerHandle,
171 IN UINTN NumberOfChildren,
172 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
173 )
174 /*++
175
176 Routine Description:
177
178 TODO: Add function description
179
180 Arguments:
181
182 This - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.
183
184 ControllerHandle - A handle to the device to be stopped.
185
186 NumberOfChildren - The number of child device handles in ChildHandleBuffer.
187
188 ChildHandleBuffer - An array of child device handles to be freed.
189
190 Returns:
191
192 EFI_SUCCESS - The device has been stopped.
193
194 EFI_DEVICE_ERROR - The device could not be stopped due to a device failure.
195
196 --*/
197 ;
198
199 //
200 // Simple File System protocol member functions
201 //
202 EFI_STATUS
203 EFIAPI
204 UnixSimpleFileSystemOpenVolume (
205 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
206 OUT EFI_FILE **Root
207 )
208 /*++
209
210 Routine Description:
211
212 Open the root directory on a volume.
213
214 Arguments:
215
216 This - A pointer to the volume to open.
217
218 Root - A pointer to storage for the returned opened file handle of the root directory.
219
220 Returns:
221
222 EFI_SUCCESS - The volume was opened.
223
224 EFI_UNSUPPORTED - The volume does not support the requested file system type.
225
226 EFI_NO_MEDIA - The device has no media.
227
228 EFI_DEVICE_ERROR - The device reported an error.
229
230 EFI_VOLUME_CORRUPTED - The file system structures are corrupted.
231
232 EFI_ACCESS_DENIED - The service denied access to the file.
233
234 EFI_OUT_OF_RESOURCES - The file volume could not be opened due to lack of resources.
235
236 EFI_MEDIA_CHANGED - The device has new media or the media is no longer supported.
237
238 --*/
239 ;
240
241 EFI_STATUS
242 EFIAPI
243 UnixSimpleFileSystemOpen (
244 IN EFI_FILE *This,
245 OUT EFI_FILE **NewHandle,
246 IN CHAR16 *FileName,
247 IN UINT64 OpenMode,
248 IN UINT64 Attributes
249 )
250 /*++
251
252 Routine Description:
253
254 Open a file relative to the source file location.
255
256 Arguments:
257
258 This - A pointer to the source file location.
259
260 NewHandle - Pointer to storage for the new file handle.
261
262 FileName - Pointer to the file name to be opened.
263
264 OpenMode - File open mode information.
265
266 Attributes - File creation attributes.
267
268 Returns:
269
270 EFI_SUCCESS - The file was opened.
271
272 EFI_NOT_FOUND - The file could not be found in the volume.
273
274 EFI_NO_MEDIA - The device has no media.
275
276 EFI_MEDIA_CHANGED - The device has new media or the media is no longer supported.
277
278 EFI_DEVICE_ERROR - The device reported an error.
279
280 EFI_VOLUME_CORRUPTED - The file system structures are corrupted.
281
282 EFI_WRITE_PROTECTED - The volume or file is write protected.
283
284 EFI_ACCESS_DENIED - The service denied access to the file.
285
286 EFI_OUT_OF_RESOURCES - Not enough resources were available to open the file.
287
288 EFI_VOLUME_FULL - There is not enough space left to create the new file.
289
290 --*/
291 ;
292
293 EFI_STATUS
294 EFIAPI
295 UnixSimpleFileSystemClose (
296 IN EFI_FILE *This
297 )
298 /*++
299
300 Routine Description:
301
302 Close the specified file handle.
303
304 Arguments:
305
306 This - Pointer to a returned opened file handle.
307
308 Returns:
309
310 EFI_SUCCESS - The file handle has been closed.
311
312 --*/
313 ;
314
315 EFI_STATUS
316 EFIAPI
317 UnixSimpleFileSystemDelete (
318 IN EFI_FILE *This
319 )
320 /*++
321
322 Routine Description:
323
324 Close and delete a file.
325
326 Arguments:
327
328 This - Pointer to a returned opened file handle.
329
330 Returns:
331
332 EFI_SUCCESS - The file handle was closed and deleted.
333
334 EFI_WARN_DELETE_FAILURE - The handle was closed but could not be deleted.
335
336 --*/
337 ;
338
339 EFI_STATUS
340 EFIAPI
341 UnixSimpleFileSystemRead (
342 IN EFI_FILE *This,
343 IN OUT UINTN *BufferSize,
344 OUT VOID *Buffer
345 )
346 /*++
347
348 Routine Description:
349
350 Read data from a file.
351
352 Arguments:
353
354 This - Pointer to a returned open file handle.
355
356 BufferSize - On input, the size of the Buffer. On output, the number of bytes stored in the Buffer.
357
358 Buffer - Pointer to the first byte of the read Buffer.
359
360 Returns:
361
362 EFI_SUCCESS - The data was read.
363
364 EFI_NO_MEDIA - The device has no media.
365
366 EFI_DEVICE_ERROR - The device reported an error.
367
368 EFI_VOLUME_CORRUPTED - The file system structures are corrupted.
369
370 EFI_BUFFER_TOO_SMALL - The supplied buffer size was too small to store the current directory entry.
371 *BufferSize has been updated with the size needed to complete the request.
372
373 --*/
374 ;
375
376 EFI_STATUS
377 EFIAPI
378 UnixSimpleFileSystemWrite (
379 IN EFI_FILE *This,
380 IN OUT UINTN *BufferSize,
381 IN VOID *Buffer
382 )
383 /*++
384
385 Routine Description:
386
387 Write data to a file.
388
389 Arguments:
390
391 This - Pointer to an opened file handle.
392
393 BufferSize - On input, the number of bytes in the Buffer to write to the file. On output, the number of bytes
394 of data written to the file.
395
396 Buffer - Pointer to the first by of data in the buffer to write to the file.
397
398 Returns:
399
400 EFI_SUCCESS - The data was written to the file.
401
402 EFI_UNSUPPORTED - Writes to an open directory are not supported.
403
404 EFI_NO_MEDIA - The device has no media.
405
406 EFI_DEVICE_ERROR - The device reported an error.
407
408 EFI_VOLUME_CORRUPTED - The file system structures are corrupt.
409
410 EFI_WRITE_PROTECTED - The file, directory, volume, or device is write protected.
411
412 EFI_ACCESS_DENIED - The file was opened read-only.
413
414 EFI_VOLUME_FULL - The volume is full.
415
416 --*/
417 ;
418
419 EFI_STATUS
420 EFIAPI
421 UnixSimpleFileSystemSetPosition (
422 IN EFI_FILE *This,
423 IN UINT64 Position
424 )
425 /*++
426
427 Routine Description:
428
429 Set a file's current position.
430
431 Arguments:
432
433 This - Pointer to an opened file handle.
434
435 Position - The byte position from the start of the file to set.
436
437 Returns:
438
439 EFI_SUCCESS - The file position has been changed.
440
441 EFI_UNSUPPORTED - The seek request for non-zero is not supported for directories.
442
443 --*/
444 ;
445
446 EFI_STATUS
447 EFIAPI
448 UnixSimpleFileSystemGetPosition (
449 IN EFI_FILE *This,
450 OUT UINT64 *Position
451 )
452 /*++
453
454 Routine Description:
455
456 Get a file's current position.
457
458 Arguments:
459
460 This - Pointer to an opened file handle.
461
462 Position - Pointer to storage for the current position.
463
464 Returns:
465
466 EFI_SUCCESS - The file position has been reported.
467
468 EFI_UNSUPPORTED - Not valid for directories.
469
470 --*/
471 ;
472
473 EFI_STATUS
474 EFIAPI
475 UnixSimpleFileSystemGetInfo (
476 IN EFI_FILE *This,
477 IN EFI_GUID *InformationType,
478 IN OUT UINTN *BufferSize,
479 OUT VOID *Buffer
480 )
481 /*++
482
483 Routine Description:
484
485 Return information about a file or volume.
486
487 Arguments:
488
489 This - Pointer to an opened file handle.
490
491 InformationType - GUID describing the type of information to be returned.
492
493 BufferSize - On input, the size of the information buffer. On output, the number of bytes written to the
494 information buffer.
495
496 Buffer - Pointer to the first byte of the information buffer.
497
498 Returns:
499
500 EFI_SUCCESS - The requested information has been written into the buffer.
501
502 EFI_UNSUPPORTED - The InformationType is not known.
503
504 EFI_NO_MEDIA - The device has no media.
505
506 EFI_DEVICE_ERROR - The device reported an error.
507
508 EFI_VOLUME_CORRUPTED - The file system structures are corrupt.
509
510 EFI_BUFFER_TOO_SMALL - The buffer size was too small to contain the requested information. The buffer size has
511 been updated with the size needed to complete the requested operation.
512
513 --*/
514 ;
515
516 EFI_STATUS
517 EFIAPI
518 UnixSimpleFileSystemSetInfo (
519 IN EFI_FILE *This,
520 IN EFI_GUID *InformationType,
521 IN UINTN BufferSize,
522 IN VOID *Buffer
523 )
524 /*++
525
526 Routine Description:
527
528 Set information about a file or volume.
529
530 Arguments:
531
532 This - Pointer to an opened file handle.
533
534 InformationType - GUID identifying the type of information to set.
535
536 BufferSize - Number of bytes of data in the information buffer.
537
538 Buffer - Pointer to the first byte of data in the information buffer.
539
540 Returns:
541
542 EFI_SUCCESS - The file or volume information has been updated.
543
544 EFI_UNSUPPORTED - The information identifier is not recognised.
545
546 EFI_NO_MEDIA - The device has no media.
547
548 EFI_DEVICE_ERROR - The device reported an error.
549
550 EFI_VOLUME_CORRUPTED - The file system structures are corrupt.
551
552 EFI_WRITE_PROTECTED - The file, directory, volume, or device is write protected.
553
554 EFI_ACCESS_DENIED - The file was opened read-only.
555
556 EFI_VOLUME_FULL - The volume is full.
557
558 EFI_BAD_BUFFER_SIZE - The buffer size is smaller than the type indicated by InformationType.
559
560 --*/
561 ;
562
563 EFI_STATUS
564 EFIAPI
565 UnixSimpleFileSystemFlush (
566 IN EFI_FILE *This
567 )
568 /*++
569
570 Routine Description:
571
572 Flush all modified data to the media.
573
574 Arguments:
575
576 This - Pointer to an opened file handle.
577
578 Returns:
579
580 EFI_SUCCESS - The data has been flushed.
581
582 EFI_NO_MEDIA - The device has no media.
583
584 EFI_DEVICE_ERROR - The device reported an error.
585
586 EFI_VOLUME_CORRUPTED - The file system structures have been corrupted.
587
588 EFI_WRITE_PROTECTED - The file, directory, volume, or device is write protected.
589
590 EFI_ACCESS_DENIED - The file was opened read-only.
591
592 EFI_VOLUME_FULL - The volume is full.
593
594 --*/
595 ;
596
597 #endif /* _UNIX_SIMPLE_FILE_SYSTEM_H_ */
598
599 /* eof - UnixSimpleFileSystem.h */