return i;\r
}\r
\r
-/** Flush the console's IIO buffers.\r
-\r
- Flush the IIO Input or Output buffers depending upon the mode\r
- of the specified file.\r
-\r
- If the console is open for output, write any unwritten data in the output\r
- buffer to the console.\r
-\r
- If the console is open for input or output, discard any remaining data\r
- in the associated buffers.\r
-\r
- @param[in] filp Pointer to the target file's descriptor structure.\r
-\r
- @retval 0 Always succeeds\r
-**/\r
-static\r
-int\r
-EFIAPI\r
-da_ConFlush(\r
- struct __filedes *filp\r
-)\r
-{\r
- cIIO *This;\r
- char *MbcsPtr;\r
- ssize_t NumProc;\r
- void *OutPtr;\r
-\r
- This = filp->devdata;\r
-\r
- if (filp->f_iflags & S_ACC_READ) { // Readable so flush the input buffer\r
- This->InBuf->Flush(This->InBuf, UNICODE_STRING_MAX);\r
- }\r
- if (filp->f_iflags & S_ACC_WRITE) { // Writable so flush the output buffer\r
- // At this point, the characters to write are in OutBuf\r
- // First, linearize and consume the buffer\r
- NumProc = OutBuf->Read(OutBuf, gMD->UString, UNICODE_STRING_MAX-1);\r
- if (NumProc > 0) { // Optimization -- Nothing to do if no characters\r
- gMD->UString[NumProc] = 0; // Ensure that the buffer is terminated\r
-\r
- if(filp->f_iflags & _S_IWTTY) {\r
- // Output device expects wide characters, Output what we have\r
- OutPtr = gMD->UString;\r
- }\r
- else {\r
- // Output device expects narrow characters, convert to MBCS\r
- OutPtr = gMD->UString2;\r
- // Translate the wide buffer, gMD->UString into MBCS\r
- // in the buffer pointed to by OutPtr.\r
- // The returned value, NumProc, is the resulting number of bytes.\r
- NumProc = wcstombs((char *)OutPtr, (const wchar_t *)gMD->UString, NumProc);\r
- ((char *)OutPtr)[NumProc] = 0; // Ensure the buffer is terminated\r
- }\r
- // Do the actual write of the data\r
- (void) filp->f_ops->fo_write(filp, NULL, NumProc, OutPtr);\r
- }\r
- }\r
- return 0;\r
-}\r
-\r
-/** Close an open file.\r
-\r
- @param[in] filp Pointer to the file descriptor structure for this file.\r
-\r
- @retval 0 The file has been successfully closed.\r
- @retval -1 filp does not point to a valid console descriptor.\r
-**/\r
-static\r
-int\r
-EFIAPI\r
-da_ConClose(\r
- IN struct __filedes *filp\r
-)\r
-{\r
- ConInstance *Stream;\r
-\r
- Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);\r
- // Quick check to see if Stream looks reasonable\r
- if(Stream->Cookie != CON_COOKIE) { // Cookie == 'IoAb'\r
- errno = EINVAL;\r
- EFIerrno = RETURN_INVALID_PARAMETER;\r
- return -1; // Looks like a bad File Descriptor pointer\r
- }\r
- // Stream and filp look OK, so continue.\r
- // Flush the I/O buffers\r
- (void) da_ConFlush(filp);\r
-\r
- // Break the connection to IIO\r
- filp->devdata = NULL;\r
-\r
- gMD->StdIo[Stream->InstanceNum] = NULL; // Mark the stream as closed\r
- return 0;\r
-}\r
-\r
/** Position the console cursor to the coordinates specified by Position.\r
\r
@param[in] filp Pointer to the file descriptor structure for this file.\r
\r
}\r
\r
+/** Flush a console device's IIO buffers.\r
+\r
+ Flush the IIO Input or Output buffers associated with the specified file.\r
+\r
+ If the console is open for output, write any unwritten data in the associated\r
+ output buffer (stdout or stderr) to the console.\r
+\r
+ If the console is open for input, discard any remaining data\r
+ in the input buffer.\r
+\r
+ @param[in] filp Pointer to the target file's descriptor structure.\r
+\r
+ @retval 0 Always succeeds\r
+**/\r
+static\r
+int\r
+EFIAPI\r
+da_ConFlush(\r
+ struct __filedes *filp\r
+)\r
+{\r
+ cFIFO *OutBuf;\r
+ ssize_t NumProc;\r
+ int Flags;\r
+\r
+\r
+ if(filp->MyFD == STDERR_FILENO) {\r
+ OutBuf = IIO->ErrBuf;\r
+ }\r
+ else {\r
+ OutBuf = IIO->OutBuf;\r
+ }\r
+\r
+ Flags = filp->Oflags & O_ACCMODE; // Get the device's open mode\r
+ if (Flags != O_WRONLY) { // (Flags == O_RDONLY) || (Flags == O_RDWR)\r
+ // Readable so discard the contents of the input buffer\r
+ IIO->InBuf->Flush(IIO->InBuf, UNICODE_STRING_MAX);\r
+ }\r
+ if (Flags != O_RDONLY) { // (Flags == O_WRONLY) || (Flags == O_RDWR)\r
+ // Writable so flush the output buffer\r
+ // At this point, the characters to write are in OutBuf\r
+ // First, linearize and consume the buffer\r
+ NumProc = OutBuf->Read(OutBuf, gMD->UString, UNICODE_STRING_MAX-1);\r
+ if (NumProc > 0) { // Optimization -- Nothing to do if no characters\r
+ gMD->UString[NumProc] = 0; // Ensure that the buffer is terminated\r
+\r
+ /* OutBuf always contains wide characters.\r
+ The UEFI Console (this device) always expects wide characters.\r
+ There is no need to handle devices that expect narrow characters\r
+ like the device-independent functions do.\r
+ */\r
+ // Do the actual write of the data to the console\r
+ (void) da_ConWrite(filp, NULL, NumProc, gMD->UString);\r
+ // Paranoia -- Make absolutely sure that OutBuf is empty in case fo_write\r
+ // wasn't able to consume everything.\r
+ OutBuf->Flush(OutBuf, UNICODE_STRING_MAX);\r
+ }\r
+ }\r
+ return 0;\r
+}\r
+\r
+/** Close an open file.\r
+\r
+ @param[in] filp Pointer to the file descriptor structure for this file.\r
+\r
+ @retval 0 The file has been successfully closed.\r
+ @retval -1 filp does not point to a valid console descriptor.\r
+**/\r
+static\r
+int\r
+EFIAPI\r
+da_ConClose(\r
+ IN struct __filedes *filp\r
+)\r
+{\r
+ ConInstance *Stream;\r
+\r
+ Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);\r
+ // Quick check to see if Stream looks reasonable\r
+ if(Stream->Cookie != CON_COOKIE) { // Cookie == 'IoAb'\r
+ errno = EINVAL;\r
+ EFIerrno = RETURN_INVALID_PARAMETER;\r
+ return -1; // Looks like a bad File Descriptor pointer\r
+ }\r
+ // Stream and filp look OK, so continue.\r
+ // Flush the I/O buffers\r
+ (void) da_ConFlush(filp);\r
+\r
+ // Break the connection to IIO\r
+ filp->devdata = NULL;\r
+\r
+ gMD->StdIo[Stream->InstanceNum] = NULL; // Mark the stream as closed\r
+ return 0;\r
+}\r
+\r
#include <sys/poll.h>\r
/* Returns a bit mask describing which operations could be completed immediately.\r
\r