file_type.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
  3. * Use of this source code is governed by a BSD-style license that can be
  4. * found in the LICENSE file.
  5. */
  6. #ifndef VBOOT_REFERENCE_FUTILITY_FILE_TYPE_H_
  7. #define VBOOT_REFERENCE_FUTILITY_FILE_TYPE_H_
  8. /* What type of things do I know how to handle? */
  9. enum futil_file_type {
  10. FILE_TYPE_UNKNOWN,
  11. #define FILE_TYPE(A, B, C, D, E, F) FILE_TYPE_ ## A,
  12. #include "file_type.inc"
  13. #undef FILE_TYPE
  14. NUM_FILE_TYPES
  15. };
  16. /* Short name for file types */
  17. const char * const futil_file_type_name(enum futil_file_type type);
  18. /* Description of file type */
  19. const char * const futil_file_type_desc(enum futil_file_type type);
  20. /* Print the list of type names and exit with the given value. */
  21. void print_file_types_and_exit(int retval);
  22. /* Lookup a type by name. Return true on success */
  23. int futil_str_to_file_type(const char *str, enum futil_file_type *type);
  24. /*
  25. * This tries to match the buffer content to one of the known file types.
  26. */
  27. enum futil_file_type futil_file_type_buf(uint8_t *buf, uint32_t len);
  28. /*
  29. * This opens a file and tries to match it to one of the known file types.
  30. * It's not an error if it returns FILE_TYPE_UKNOWN.
  31. */
  32. enum futil_file_err futil_file_type(const char *filename,
  33. enum futil_file_type *type);
  34. /*
  35. * Call the show() method on a buffer containing a specific file type.
  36. * Returns zero on success. It's up to the caller to ensure that only valid
  37. * file types are invoked.
  38. */
  39. int futil_file_type_show(enum futil_file_type type,
  40. const char *filename,
  41. uint8_t *buf, uint32_t len);
  42. /*
  43. * Call the sign() method on a buffer containing a specific file type.
  44. * Returns zero on success. It's up to the caller to ensure that only valid
  45. * file types are invoked.
  46. */
  47. int futil_file_type_sign(enum futil_file_type type,
  48. const char *filename,
  49. uint8_t *buf, uint32_t len);
  50. /* Declare the file_type functions. */
  51. #define R_(FOO) \
  52. enum futil_file_type FOO(uint8_t *buf, uint32_t len);
  53. #define S_(FOO) \
  54. int FOO(const char *name, uint8_t *buf, uint32_t len, void *data);
  55. #define NONE
  56. #define FILE_TYPE(A, B, C, D, E, F) D E F
  57. #include "file_type.inc"
  58. #undef FILE_TYPE
  59. #undef NONE
  60. #undef S_
  61. #undef R_
  62. #endif /* VBOOT_REFERENCE_FUTILITY_FILE_TYPE_H_ */