iPXE
disklog.c File Reference

Disk log console. More...

#include <assert.h>
#include <errno.h>
#include <string.h>
#include <ipxe/disklog.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
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.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ disklog_open()

int disklog_open ( struct disklog * disklog)

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
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
unsigned int offset
Current offset within logical block.
Definition disklog.h:39
uint64_t lba
Current logical block index.
Definition disklog.h:35
unsigned int unwritten
Current number of unwritten characters.
Definition disklog.h:41
struct console_driver * console
Console device.
Definition disklog.h:27
uint64_t max_lba
Maximum logical block index.
Definition disklog.h:37

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 )

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().