ramfs.h 1.6 KB

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