ramfs.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* ramfs: read-only in-memory filesystem backed by the command pack (mkpack).
  2. * The pack is kept where the loader put it (no copies); paths inside it are
  3. * relative to the mount root (e.g. "bin/ls"). */
  4. #ifndef RAMFS_H
  5. #define RAMFS_H
  6. #define RAMFS_PATH_MAX 32
  7. #define RAMFS_MAX_FILES 128
  8. struct ramfs_dirent {
  9. char name[RAMFS_PATH_MAX];
  10. unsigned int size;
  11. unsigned int is_dir;
  12. };
  13. /* Validate a pack and make it the ramfs contents. Returns 0 on success. */
  14. int ramfs_init(const void *pack, unsigned int size);
  15. /* Replace the contents with a freshly received pack (page-allocated): the
  16. * old pack is validated first, so a bad image leaves the current one in
  17. * place; on success the previous heap copy is freed. Returns 0 on success. */
  18. int ramfs_replace(const void *pack, unsigned int size);
  19. /* Look up one path (no leading '/', e.g. "bin/ls"); returns a pointer into
  20. * the pack and its size, or NULL when absent. */
  21. const void *ramfs_lookup(const char *path, unsigned int *size);
  22. /* List one directory: "" for the mount root, "bin" for /ramfs/bin. Returns
  23. * 1 when an entry was filled, 0 at the end. */
  24. int ramfs_list(const char *dir, unsigned int index, struct ramfs_dirent *out);
  25. /* Number of files in the pack (0 when no pack is loaded). */
  26. unsigned int ramfs_count(void);
  27. /* Size of the loaded pack in bytes (0 when none). */
  28. unsigned int ramfs_pack_size(void);
  29. #endif