iPXE
cpio.h
Go to the documentation of this file.
1 #ifndef _IPXE_CPIO_H
2 #define _IPXE_CPIO_H
3 
4 /** @file
5  *
6  * CPIO archives
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <stdint.h>
14 #include <ipxe/image.h>
15 
16 /** A CPIO archive header
17  *
18  * All field are hexadecimal ASCII numbers padded with '0' on the
19  * left to the full width of the field.
20  */
21 struct cpio_header {
22  /** The string "070701" or "070702" */
23  char c_magic[6];
24  /** File inode number */
25  char c_ino[8];
26  /** File mode and permissions */
27  char c_mode[8];
28  /** File uid */
29  char c_uid[8];
30  /** File gid */
31  char c_gid[8];
32  /** Number of links */
33  char c_nlink[8];
34  /** Modification time */
35  char c_mtime[8];
36  /** Size of data field */
37  char c_filesize[8];
38  /** Major part of file device number */
39  char c_maj[8];
40  /** Minor part of file device number */
41  char c_min[8];
42  /** Major part of device node reference */
43  char c_rmaj[8];
44  /** Minor part of device node reference */
45  char c_rmin[8];
46  /** Length of filename, including final NUL */
47  char c_namesize[8];
48  /** Checksum of data field if c_magic is 070702, othersize zero */
49  char c_chksum[8];
50 } __attribute__ (( packed ));
51 
52 /** CPIO magic */
53 #define CPIO_MAGIC "070701"
54 
55 /** CPIO type for regular files */
56 #define CPIO_MODE_FILE 0100000
57 
58 /** CPIO type for directories */
59 #define CPIO_MODE_DIR 0040000
60 
61 /** CPIO header length alignment */
62 #define CPIO_ALIGN 4
63 
64 /**
65  * Get CPIO image name
66  *
67  * @v image Image
68  * @ret name Image name (not NUL terminated)
69  */
70 static inline __attribute__ (( always_inline )) const char *
71 cpio_name ( struct image *image ) {
72  return image->cmdline;
73 }
74 
75 /**
76  * Get CPIO header zero-padding length
77  *
78  * @v len Length of CPIO header (including name, excluding NUL)
79  * @ret pad_len Padding length
80  */
81 static inline __attribute__ (( always_inline )) size_t
82 cpio_pad_len ( size_t len ) {
83 
84  /* Pad by at least one byte (for name's terminating NUL) */
85  return ( CPIO_ALIGN - ( len % CPIO_ALIGN ) );
86 }
87 
88 extern size_t cpio_header ( struct image *image, unsigned int index,
89  struct cpio_header *cpio );
90 
91 #endif /* _IPXE_CPIO_H */
char c_ino[8]
File inode number.
Definition: cpio.h:25
#define __attribute__(x)
Definition: compiler.h:10
char c_maj[8]
Major part of file device number.
Definition: cpio.h:39
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
char c_filesize[8]
Size of data field.
Definition: cpio.h:37
A CPIO archive header.
Definition: cpio.h:21
#define CPIO_ALIGN
CPIO header length alignment.
Definition: cpio.h:62
long index
Definition: bigint.h:65
char c_mtime[8]
Modification time.
Definition: cpio.h:35
An executable image.
Definition: image.h:24
char c_uid[8]
File uid.
Definition: cpio.h:29
static size_t cpio_pad_len(size_t len)
Get CPIO header zero-padding length.
Definition: cpio.h:82
char * cmdline
Command line to pass to image.
Definition: image.h:43
char c_gid[8]
File gid.
Definition: cpio.h:31
Executable images.
ring len
Length.
Definition: dwmac.h:231
FILE_SECBOOT(PERMITTED)
char c_min[8]
Minor part of file device number.
Definition: cpio.h:41
char c_rmin[8]
Minor part of device node reference.
Definition: cpio.h:45
char c_mode[8]
File mode and permissions.
Definition: cpio.h:27
char c_namesize[8]
Length of filename, including final NUL.
Definition: cpio.h:47
char c_nlink[8]
Number of links.
Definition: cpio.h:33
char c_magic[6]
The string "070701" or "070702".
Definition: cpio.h:23
char c_chksum[8]
Checksum of data field if c_magic is 070702, othersize zero.
Definition: cpio.h:49
char c_rmaj[8]
Major part of device node reference.
Definition: cpio.h:43
size_t cpio_header(struct image *image, unsigned int index, struct cpio_header *cpio)
Construct CPIO header for image, if applicable.
Definition: cpio.c:156
static const char * cpio_name(struct image *image)
Get CPIO image name.
Definition: cpio.h:71