Guest User

DasOS File API

a guest
Aug 8th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #pragma once
  2.  
  3. #define FILENAME_MAXLEN 13 // 8 + . + 3 + \0
  4.  
  5. #if defined(__cplusplus)
  6. extern "C"
  7. {
  8. #endif
  9.  
  10. typedef enum filetype
  11. {
  12.     ftUnknown = 0,
  13.     ftFile = 1,
  14.     ftDirectory = 2,
  15.     ftInvalid = 99,
  16. } filetype_t;
  17.  
  18.  
  19. typedef struct node
  20. {
  21.     char name[FILENAME_MAXLEN];
  22.     enum filetype type;
  23. } node_t;
  24.  
  25. /**
  26.  * Opens a file and gets a file handle.
  27.  */
  28. int fs_open(char const * name);
  29.  
  30. /**
  31.  * Returns the type of the given file.
  32.  */
  33. enum filetype fs_type(int file);
  34.  
  35. /**
  36.  * Releases a file handle.
  37.  */
  38. void fs_close(int file);
  39.  
  40.  
  41.  
  42. /**
  43.  * Reads a block of data from a file.
  44.  * @param file   The file handle.
  45.  * @param buffer The target memory
  46.  * @param offset The start position in the file
  47.  * @param length Number of bytes to read.
  48.  * @return       Number of bytes read.
  49.  */
  50. uint32_t file_read(
  51.     int file,
  52.     void *buffer,
  53.     uint32_t offset,
  54.     uint32_t length);
  55.  
  56. /**
  57.  * Returns the length of a file in bytes.
  58.  */
  59. uint32_t file_length(int file);
  60.  
  61.  
  62. /**
  63.  * Returns the number of entries in a directory.
  64.  * @param file The file handle.
  65.  */
  66. uint32_t dir_length(int file);
  67.  
  68. /**
  69.  * Gets a directory entry.
  70.  * @param file  The file handle
  71.  * @param index The index of the node in the directory.
  72.  * @param node  A pointer to a node to store the information.
  73.  */
  74. bool dir_get(int file, int index, struct node * node);
  75.  
  76. #if defined(__cplusplus)
  77. }
  78. #endif
Advertisement
Add Comment
Please, Sign In to add comment