Alternative library and kernel for add-in development on fx-9860G and fx-CG50 under Linux.
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.

126 lines
4.3KB

  1. //---
  2. // gint:bfile - BFile interface
  3. //
  4. // The system's file system is a nightmare and the risk of corrupting it
  5. // or the flash by driving it manually is too great to risk. This module
  6. // interfaces with the BFile syscalls for file management.
  7. //---
  8. #ifndef GINT_BFILE
  9. #define GINT_BFILE
  10. #include <stdint.h>
  11. /* BFile_Remove(): Remove a file
  12. Also works if the file does not exist.
  13. @file FONTCHARACTER file path
  14. Returns a BFile error code. */
  15. int BFile_Remove(uint16_t const *file);
  16. /* BFile_Create(): Create a new entry
  17. The file or directory must not exist. For a file the size pointer must point
  18. to the desired file size (which is fixed), for a folder it is ignored.
  19. @file FONTCHARACTER file path
  20. @type Entry type
  21. @size Pointer to file size if [type = BFile_File], ignored otherwise
  22. Returns a BFile error code. */
  23. enum BFile_EntryType
  24. {
  25. BFile_File = 1,
  26. BFile_Folder = 5,
  27. };
  28. int BFile_Create(uint16_t const *file, enum BFile_EntryType type, int *size);
  29. /* BFile_Open(): Open an existing file
  30. The file must exist.
  31. @file FONTCHARACTER file path
  32. @mode Desired access mode
  33. Returns a file descriptor on success, or a negative BFile error code. */
  34. enum BFile_OpenMode
  35. {
  36. BFile_ReadOnly = 0x01,
  37. BFile_WriteOnly = 0x02,
  38. BFile_ReadWrite = BFile_ReadOnly | BFile_WriteOnly,
  39. };
  40. int BFile_Open(uint16_t const *file, enum BFile_OpenMode mode);
  41. /* BFile_Close(): Close a file descriptor
  42. @fd Open file descriptor
  43. Returns a BFile error code. */
  44. int BFile_Close(int fd);
  45. /* BFile_Size(): Retrieve size of an open file
  46. @fd Open file descriptor
  47. Returns the file size in bytes, or a negative BFile error code*/
  48. int BFile_Size(int fd);
  49. /* BFile_Write(): Write data to an open file
  50. Second and third argument specify the data and length to write.
  51. WARNING: The file systems has shown to become inconsistent if an odd number
  52. of bytes is written with BFile_Write(). Keep it even!
  53. @fd File descriptor open for writing
  54. @data Data to write
  55. @even_size Size to write (must be even, yes)
  56. Returns a BFile error code. */
  57. int BFile_Write(int fd, void const *data, int even_size);
  58. /* BFile_Read(): Read data from an open file
  59. The second and third argument specify where to store and how much to read.
  60. The location from where the data is read depends on [whence]:
  61. * If [whence >= 0], it is taken as an absolute location within the file;
  62. * If [whence == -1], BFile_Read() reads from the current position.
  63. @fd File descriptor open for reading
  64. @data Buffer of at least [size] bytes to store data to
  65. @size Number of bytes to read
  66. @whence Starting position of the data to read in the file
  67. Returns a BFile error code. */
  68. int BFile_Read(int handle, void *data, int size, int whence);
  69. /* BFile_FindFirst(): Search a directory for file with matching name
  70. Doesn't work on Main memory. Only four search handle can be opened, you need
  71. to close them to be able to reuse them. Search is NOT case sensitive and *
  72. can be used as a wildcard.
  73. @search FONTCHARACTER file path to match
  74. @shandle Search handle to pass to BFile_FindNext or BFile_FindClose
  75. @founfile FONTCHARACTER found file path
  76. @fileinfo Structure containing a lot of information on the found file
  77. Returns 0 on success, -1 if no file found, or negative value on error. */
  78. struct BFile_FileInfo
  79. {
  80. uint16_t index;
  81. uint16_t type;
  82. uint32_t file_size;
  83. /* Data size (file size minus the header) */
  84. uint32_t data_size;
  85. /* Is 0 if the file is complete */
  86. uint32_t property;
  87. /* Address of first fragmented (do not use directly) */
  88. uint32_t address;
  89. };
  90. int BFile_FindFirst(uint16_t const *search, int *shandle, uint16_t *foundfile,
  91. struct BFile_FileInfo *fileinfo);
  92. /* BFile_FindNext(): Continue a search a directory for file with matching name
  93. @shandle Search handle from BFile_FindFirst
  94. @founfile FONTCHARACTER found file path
  95. @fileinfo Structure containing a lot of information on the found file
  96. Returns 0 on success, -1 if end is reached, or negative value on error. */
  97. int BFile_FindNext(int shandle, uint16_t *foundfile,
  98. struct BFile_FileInfo *fileinfo);
  99. /* BFile_FindClose(): Close the specified search handle
  100. @shandle Search handle from BFile_FindFirst
  101. Return 0 on success or negative value on error. */
  102. int BFile_FindClose(int shandle);
  103. #endif /* GINT_BFILE */