iPXE
disklog.h File Reference

Disk log console. More...

#include <stdint.h>
#include <ipxe/console.h>

Go to the source code of this file.

Data Structures

struct  disklog_header
 Disk log partition header. More...
struct  disklog
 A disk log. More...
struct  disklog_operations
 Disk log operations. More...

Macros

#define DISKLOG_PARTITION_TYPE   0xe0
 Disk log partition type.
#define DISKLOG_MAGIC   "iPXE LOG\n\n"
 Disk log partition magic signature.
#define DISKLOG_MAX_UNWRITTEN   64
 Maximum number of outstanding unwritten characters.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static void disklog_init (struct disklog *disklog, struct disklog_operations *op, struct console_driver *console, void *buffer, size_t blksize, uint64_t lba, uint64_t max_lba)
 Initialise disk log console.
int disklog_open (struct disklog *disklog)
 Open disk log console.
void disklog_putchar (struct disklog *disklog, int character)
 Write character to disk log console.

Detailed Description

Disk log console.

Definition in file disklog.h.

Macro Definition Documentation

◆ DISKLOG_PARTITION_TYPE

#define DISKLOG_PARTITION_TYPE   0xe0

Disk log partition type.

Definition at line 84 of file disklog.h.

Referenced by efi_disklog_open(), and int13con_find().

◆ DISKLOG_MAGIC

#define DISKLOG_MAGIC   "iPXE LOG\n\n"

Disk log partition magic signature.

Definition at line 87 of file disklog.h.

Referenced by disklog_open().

◆ DISKLOG_MAX_UNWRITTEN

#define DISKLOG_MAX_UNWRITTEN   64

Maximum number of outstanding unwritten characters.

Definition at line 90 of file disklog.h.

Referenced by disklog_putchar().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ disklog_init()

void disklog_init ( struct disklog * disklog,
struct disklog_operations * op,
struct console_driver * console,
void * buffer,
size_t blksize,
uint64_t lba,
uint64_t max_lba )
inlinestatic

Initialise disk log console.

Parameters
disklogDisk log
opDisk log operations
consoleConsole device
bufferData buffer
blksizeLogical block size
lbaStarting logical block index
max_lbaMaximum logical block index

Definition at line 66 of file disklog.h.

68 {
69
70 disklog->op = op;
71 disklog->console = console;
74 disklog->lba = lba;
75 disklog->max_lba = max_lba;
76}
uint64_t lba
Starting block number.
Definition int13.h:11
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER).
Definition netvsc.h:5
static uint16_t struct vmbus_xfer_pages_operations * op
Definition netvsc.h:327
uint32_t blksize
Cipher block size.
Definition pccrr.h:1
A disk log.
Definition disklog.h:25
struct disklog_operations * op
Disk log operations.
Definition disklog.h:29
uint8_t * buffer
Logical block data buffer.
Definition disklog.h:31
size_t blksize
Logical block size.
Definition disklog.h:33
uint64_t lba
Current logical block index.
Definition disklog.h:35
struct console_driver * console
Console device.
Definition disklog.h:27
uint64_t max_lba
Maximum logical block index.
Definition disklog.h:37

References blksize, disklog::blksize, buffer, disklog::buffer, disklog::console, disklog::lba, lba, disklog::max_lba, disklog::op, and op.

Referenced by efi_disklog_open(), and int13con_find().

◆ disklog_open()

int disklog_open ( struct disklog * disklog)
extern

Open disk log console.

Parameters
disklogDisk log
Return values
rcReturn status code

The data buffer must already contain the initial logical block.

Definition at line 46 of file disklog.c.

46 {
47 struct disklog_header *hdr =
48 ( ( struct disklog_header * ) disklog->buffer );
49
50 /* Sanity checks */
51 assert ( disklog->console != NULL );
52 assert ( disklog->buffer != NULL );
53 assert ( disklog->blksize > 0 );
54 assert ( ( disklog->blksize & ( disklog->blksize - 1 ) ) == 0 );
56 assert ( disklog->op != NULL );
57 assert ( disklog->op->write != NULL );
58
59 /* Check magic signature */
60 if ( ( disklog->blksize < sizeof ( *hdr ) ) ||
61 ( memcmp ( hdr->magic, DISKLOG_MAGIC,
62 sizeof ( hdr->magic ) ) != 0 ) ) {
63 DBGC ( disklog, "DISKLOG has bad magic signature\n" );
64 return -EINVAL;
65 }
66
67 /* Initialise buffer */
68 disklog->offset = sizeof ( *hdr );
69 disklog->unwritten = 0;
70 memset ( ( disklog->buffer + sizeof ( *hdr ) ), 0,
71 ( disklog->blksize - sizeof ( *hdr ) ) );
72
73 /* Enable console */
75
76 return 0;
77}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
struct golan_inbox_hdr hdr
Message header.
Definition CIB_PRM.h:0
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
#define DISKLOG_MAGIC
Disk log partition magic signature.
Definition disklog.h:87
#define DBGC(...)
Definition compiler.h:530
#define EINVAL
Invalid argument.
Definition errno.h:429
void * memset(void *dest, int character, size_t len) __nonnull
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
int disabled
Console disabled flags.
Definition console.h:63
Disk log partition header.
Definition disklog.h:19
int(* write)(void)
Write current logical block.
Definition disklog.h:51
unsigned int offset
Current offset within logical block.
Definition disklog.h:39
unsigned int unwritten
Current number of unwritten characters.
Definition disklog.h:41

References assert, disklog::blksize, disklog::buffer, disklog::console, DBGC, console_driver::disabled, DISKLOG_MAGIC, EINVAL, hdr, disklog::lba, disklog::max_lba, memcmp(), memset(), NULL, disklog::offset, disklog::op, disklog::unwritten, and disklog_operations::write.

Referenced by efi_disklog_open(), and int13con_find().

◆ disklog_putchar()

void disklog_putchar ( struct disklog * disklog,
int character )
extern

Write character to disk log console.

Parameters
disklogDisk log
characterCharacter

Definition at line 85 of file disklog.c.

85 {
86 static int busy;
87 int rc;
88
89 /* Ignore if we are already mid-logging */
90 if ( busy )
91 return;
92 busy = 1;
93
94 /* Sanity checks */
96
97 /* Write character to buffer */
98 disklog->buffer[disklog->offset++] = character;
100
101 /* Write sector to disk, if applicable */
102 if ( ( disklog->offset == disklog->blksize ) ||
104 ( character == '\n' ) ) {
105
106 /* Write sector to disk */
107 if ( ( rc = disklog->op->write() ) != 0 ) {
108 DBGC ( disklog, "DISKLOG could not write: %s\n",
109 strerror ( rc ) );
110 /* Ignore and continue; there's nothing we can do */
111 }
112
113 /* Reset count of unwritten characters */
114 disklog->unwritten = 0;
115 }
116
117 /* Move to next sector, if applicable */
118 if ( disklog->offset == disklog->blksize ) {
119
120 /* Disable console if we have run out of space */
121 if ( disklog->lba >= disklog->max_lba )
123
124 /* Clear log buffer */
126 disklog->offset = 0;
127
128 /* Move to next sector */
129 disklog->lba++;
130 }
131
132 /* Clear busy flag */
133 busy = 0;
134}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define DISKLOG_MAX_UNWRITTEN
Maximum number of outstanding unwritten characters.
Definition disklog.h:90
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79

References assert, disklog::blksize, disklog::buffer, disklog::console, DBGC, console_driver::disabled, DISKLOG_MAX_UNWRITTEN, disklog::lba, disklog::max_lba, memset(), disklog::offset, disklog::op, rc, strerror(), disklog::unwritten, and disklog_operations::write.

Referenced by efi_disklog_putchar(), and int13con_putchar().