1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_KERNEL_READ_FILE_H
3 #define _LINUX_KERNEL_READ_FILE_H
5 #include <linux/file.h>
6 #include <linux/types.h>
8 /* This is a list of *what* is being read, not *how* nor *where*. */
9 #define __kernel_read_file_id(id) \
10 id(UNKNOWN, unknown) \
11 id(FIRMWARE, firmware) \
12 id(MODULE, kernel-module) \
13 id(KEXEC_IMAGE, kexec-image) \
14 id(KEXEC_INITRAMFS, kexec-initramfs) \
15 id(POLICY, security-policy) \
16 id(X509_CERTIFICATE, x509-certificate) \
19 #define __fid_enumify(ENUM, dummy) READING_ ## ENUM,
20 #define __fid_stringify(dummy, str) #str,
22 enum kernel_read_file_id {
23 __kernel_read_file_id(__fid_enumify)
26 static const char * const kernel_read_file_str[] = {
27 __kernel_read_file_id(__fid_stringify)
30 static inline const char *kernel_read_file_id_str(enum kernel_read_file_id id)
32 if ((unsigned int)id >= READING_MAX_ID)
33 return kernel_read_file_str[READING_UNKNOWN];
35 return kernel_read_file_str[id];
38 int kernel_read_file(struct file *file, loff_t offset,
39 void **buf, size_t buf_size,
41 enum kernel_read_file_id id);
42 int kernel_read_file_from_path(const char *path, loff_t offset,
43 void **buf, size_t buf_size,
45 enum kernel_read_file_id id);
46 int kernel_read_file_from_path_initns(const char *path, loff_t offset,
47 void **buf, size_t buf_size,
49 enum kernel_read_file_id id);
50 int kernel_read_file_from_fd(int fd, loff_t offset,
51 void **buf, size_t buf_size,
53 enum kernel_read_file_id id);
55 #endif /* _LINUX_KERNEL_READ_FILE_H */