-/** 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