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