X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EdkUnixPkg%2FDxe%2FUnixThunk%2FBus%2FSimpleFileSystem%2FUnixSimpleFileSystem.c;h=10736d540737d4039b0eda655b7b8125741c3338;hp=2a745cbdd22da7e6edf37901f883db78fbb729f8;hb=4825e9d87d67da24adba382c5507cae80267b7ab;hpb=377fc2ae7125fec78f349c1ceda0cbeb53c988c2 diff --git a/EdkUnixPkg/Dxe/UnixThunk/Bus/SimpleFileSystem/UnixSimpleFileSystem.c b/EdkUnixPkg/Dxe/UnixThunk/Bus/SimpleFileSystem/UnixSimpleFileSystem.c index 2a745cbdd2..10736d5407 100644 --- a/EdkUnixPkg/Dxe/UnixThunk/Bus/SimpleFileSystem/UnixSimpleFileSystem.c +++ b/EdkUnixPkg/Dxe/UnixThunk/Bus/SimpleFileSystem/UnixSimpleFileSystem.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2006, Intel Corporation +Copyright (c) 2006 - 2007, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -30,7 +30,7 @@ EFI_DRIVER_BINDING_PROTOCOL gUnixSimpleFileSystemDriverBinding = { UnixSimpleFileSystemDriverBindingSupported, UnixSimpleFileSystemDriverBindingStart, UnixSimpleFileSystemDriverBindingStop, - 0x10, + 0xa, NULL, NULL }; @@ -257,7 +257,7 @@ Returns: EFI_STATUS Status; EFI_UNIX_IO_PROTOCOL *UnixIo; UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *Private; - INTN i; + INTN i; Private = NULL; @@ -295,8 +295,8 @@ Returns: Private->Signature = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE; Private->UnixThunk = UnixIo->UnixThunk; - Private->FilePath = NULL; - Private->VolumeLabel = NULL; + Private->FilePath = NULL; + Private->VolumeLabel = NULL; Status = gBS->AllocatePool ( EfiBootServicesData, @@ -307,10 +307,10 @@ Returns: if (EFI_ERROR (Status)) { goto Done; } - - for (i = 0; UnixIo->EnvString[i] != 0; i++) + + for (i = 0; UnixIo->EnvString[i] != 0; i++) Private->FilePath[i] = UnixIo->EnvString[i]; - Private->FilePath[i] = 0; + Private->FilePath[i] = 0; Private->VolumeLabel = NULL; Status = gBS->AllocatePool ( @@ -349,10 +349,10 @@ Done: if (Private != NULL) { - if (Private->VolumeLabel != NULL) - gBS->FreePool (Private->VolumeLabel); - if (Private->FilePath != NULL) - gBS->FreePool (Private->FilePath); + if (Private->VolumeLabel != NULL) + gBS->FreePool (Private->VolumeLabel); + if (Private->FilePath != NULL) + gBS->FreePool (Private->FilePath); FreeUnicodeStringTable (Private->ControllerNameTable); gBS->FreePool (Private); @@ -495,10 +495,12 @@ Returns: EFI_STATUS Status; UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *Private; UNIX_EFI_FILE_PRIVATE *PrivateFile; + EFI_TPL OldTpl; if (This == NULL || Root == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); Private = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This); @@ -540,20 +542,20 @@ Returns: PrivateFile->EfiFile.GetInfo = UnixSimpleFileSystemGetInfo; PrivateFile->EfiFile.SetInfo = UnixSimpleFileSystemSetInfo; PrivateFile->EfiFile.Flush = UnixSimpleFileSystemFlush; - PrivateFile->fd = -1; - PrivateFile->Dir = NULL; - PrivateFile->Dirent = NULL; + PrivateFile->fd = -1; + PrivateFile->Dir = NULL; + PrivateFile->Dirent = NULL; *Root = &PrivateFile->EfiFile; - PrivateFile->Dir = PrivateFile->UnixThunk->OpenDir(PrivateFile->FileName); + PrivateFile->Dir = PrivateFile->UnixThunk->OpenDir(PrivateFile->FileName); - if (PrivateFile->Dir == NULL) { + if (PrivateFile->Dir == NULL) { Status = EFI_ACCESS_DENIED; - } - else { + } + else { Status = EFI_SUCCESS; - } + } Done: if (EFI_ERROR (Status)) { @@ -566,6 +568,8 @@ Done: } } + gBS->RestoreTPL (OldTpl); + return Status; } @@ -629,10 +633,9 @@ Returns: UNIX_EFI_FILE_PRIVATE *NewPrivateFile; UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot; EFI_STATUS Status; - CHAR16 *Src; - char *Dst; + CHAR16 *Src; + char *Dst; CHAR8 *RealFileName; - CHAR16 *TempFileName; char *ParseFileName; char *GuardPointer; CHAR8 TempChar; @@ -672,9 +675,7 @@ Returns: return EFI_INVALID_PARAMETER; } - // - // - // + PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); PrivateRoot = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem); NewPrivateFile = NULL; @@ -683,7 +684,7 @@ Returns: // BUGBUG: assume an open of root // if current location, return current data // - if (StrCmp (FileName, L"\\") == 0 + if (StrCmp (FileName, L"\\") == 0 || (StrCmp (FileName, L".") == 0 && PrivateFile->IsRootDirectory)) { // // BUGBUG: assume an open root @@ -727,25 +728,25 @@ OpenRoot: if (*FileName == L'\\') { AsciiStrCpy (NewPrivateFile->FileName, PrivateRoot->FilePath); - // Skip first '\'. - Src = FileName + 1; + // Skip first '\'. + Src = FileName + 1; } else { AsciiStrCpy (NewPrivateFile->FileName, PrivateFile->FileName); - Src = FileName; - } - Dst = NewPrivateFile->FileName + AsciiStrLen(NewPrivateFile->FileName); - GuardPointer = NewPrivateFile->FileName + AsciiStrLen(PrivateRoot->FilePath); - *Dst++ = '/'; - // Convert unicode to ascii and '\' to '/' - while (*Src) { - if (*Src == '\\') - *Dst++ = '/'; - else - *Dst++ = *Src; - Src++; - } - *Dst = 0; - + Src = FileName; + } + Dst = NewPrivateFile->FileName + AsciiStrLen(NewPrivateFile->FileName); + GuardPointer = NewPrivateFile->FileName + AsciiStrLen(PrivateRoot->FilePath); + *Dst++ = '/'; + // Convert unicode to ascii and '\' to '/' + while (*Src) { + if (*Src == '\\') + *Dst++ = '/'; + else + *Dst++ = *Src; + Src++; + } + *Dst = 0; + // // Get rid of . and .., except leading . or .. @@ -810,22 +811,22 @@ OpenRoot: } RealFileName = NewPrivateFile->FileName + AsciiStrLen(NewPrivateFile->FileName) - 1; - while (RealFileName > NewPrivateFile->FileName && *RealFileName != '/') - RealFileName--; + while (RealFileName > NewPrivateFile->FileName && *RealFileName != '/') + RealFileName--; TempChar = *(RealFileName - 1); *(RealFileName - 1) = 0; *(RealFileName - 1) = TempChar; - - + + // // Test whether file or directory // NewPrivateFile->IsRootDirectory = FALSE; - NewPrivateFile->fd = -1; - NewPrivateFile->Dir = NULL; + NewPrivateFile->fd = -1; + NewPrivateFile->Dir = NULL; if (OpenMode & EFI_FILE_MODE_CREATE) { if (Attributes & EFI_FILE_DIRECTORY) { NewPrivateFile->IsDirectoryPath = TRUE; @@ -833,11 +834,11 @@ OpenRoot: NewPrivateFile->IsDirectoryPath = FALSE; } } else { - struct stat finfo; - int res = NewPrivateFile->UnixThunk->Stat (NewPrivateFile->FileName, &finfo); - if (res == 0 && S_ISDIR(finfo.st_mode)) + struct stat finfo; + int res = NewPrivateFile->UnixThunk->Stat (NewPrivateFile->FileName, &finfo); + if (res == 0 && S_ISDIR(finfo.st_mode)) NewPrivateFile->IsDirectoryPath = TRUE; - else + else NewPrivateFile->IsDirectoryPath = FALSE; } @@ -859,22 +860,22 @@ OpenRoot: // Create a directory // if (NewPrivateFile->UnixThunk->MkDir (NewPrivateFile->FileName, 0777) != 0) { - INTN LastError; + INTN LastError; LastError = PrivateFile->UnixThunk->GetErrno (); - if (LastError != EEXIST) { - gBS->FreePool (TempFileName); + if (LastError != EEXIST) { + //gBS->FreePool (TempFileName); Status = EFI_ACCESS_DENIED; goto Done; } } } - NewPrivateFile->Dir = NewPrivateFile->UnixThunk->OpenDir - (NewPrivateFile->FileName); + NewPrivateFile->Dir = NewPrivateFile->UnixThunk->OpenDir + (NewPrivateFile->FileName); - if (NewPrivateFile->Dir == NULL) { - if (PrivateFile->UnixThunk->GetErrno () == EACCES) { + if (NewPrivateFile->Dir == NULL) { + if (PrivateFile->UnixThunk->GetErrno () == EACCES) { Status = EFI_ACCESS_DENIED; } else { Status = EFI_NOT_FOUND; @@ -887,13 +888,13 @@ OpenRoot: // // deal with file // - NewPrivateFile->fd = NewPrivateFile->UnixThunk->Open + NewPrivateFile->fd = NewPrivateFile->UnixThunk->Open (NewPrivateFile->FileName, - ((OpenMode & EFI_FILE_MODE_CREATE) ? O_CREAT : 0) - | (NewPrivateFile->IsOpenedByRead ? O_RDONLY : O_RDWR), - 0666); - if (NewPrivateFile->fd < 0) { - if (PrivateFile->UnixThunk->GetErrno () == ENOENT) { + ((OpenMode & EFI_FILE_MODE_CREATE) ? O_CREAT : 0) + | (NewPrivateFile->IsOpenedByRead ? O_RDONLY : O_RDWR), + 0666); + if (NewPrivateFile->fd < 0) { + if (PrivateFile->UnixThunk->GetErrno () == ENOENT) { Status = EFI_NOT_FOUND; } else { Status = EFI_ACCESS_DENIED; @@ -980,6 +981,7 @@ Returns: // TODO: EFI_INVALID_PARAMETER - add return value to function comment { UNIX_EFI_FILE_PRIVATE *PrivateFile; + EFI_TPL OldTpl; if (This == NULL) { return EFI_INVALID_PARAMETER; @@ -987,21 +989,26 @@ Returns: PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); - if (PrivateFile->fd >= 0) { + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + + if (PrivateFile->fd >= 0) { PrivateFile->UnixThunk->Close (PrivateFile->fd); - } - if (PrivateFile->Dir != NULL) { + } + if (PrivateFile->Dir != NULL) { PrivateFile->UnixThunk->CloseDir (PrivateFile->Dir); - } + } - PrivateFile->fd = -1; - PrivateFile->Dir = NULL; + PrivateFile->fd = -1; + PrivateFile->Dir = NULL; if (PrivateFile->FileName) { gBS->FreePool (PrivateFile->FileName); } gBS->FreePool (PrivateFile); + + gBS->RestoreTPL (OldTpl); + return EFI_SUCCESS; } @@ -1030,12 +1037,15 @@ Returns: // TODO: EFI_INVALID_PARAMETER - add return value to function comment { EFI_STATUS Status; - UNIX_EFI_FILE_PRIVATE *PrivateFile; + UNIX_EFI_FILE_PRIVATE *PrivateFile; + EFI_TPL OldTpl; if (This == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); Status = EFI_WARN_DELETE_FAILURE; @@ -1043,7 +1053,7 @@ Returns: if (PrivateFile->IsDirectoryPath) { if (PrivateFile->Dir != NULL) { PrivateFile->UnixThunk->CloseDir (PrivateFile->Dir); - PrivateFile->Dir = NULL; + PrivateFile->Dir = NULL; } if (PrivateFile->UnixThunk->RmDir (PrivateFile->FileName) == 0) { @@ -1051,7 +1061,7 @@ Returns: } } else { PrivateFile->UnixThunk->Close (PrivateFile->fd); - PrivateFile->fd = -1; + PrivateFile->fd = -1; if (!PrivateFile->IsOpenedByRead) { if (!PrivateFile->UnixThunk->UnLink (PrivateFile->FileName)) { @@ -1063,6 +1073,8 @@ Returns: gBS->FreePool (PrivateFile->FileName); gBS->FreePool (PrivateFile); + gBS->RestoreTPL (OldTpl); + return Status; } @@ -1070,7 +1082,7 @@ STATIC VOID UnixSystemTimeToEfiTime ( EFI_UNIX_THUNK_PROTOCOL *UnixThunk, - IN time_t SystemTime, + IN time_t SystemTime, OUT EFI_TIME *Time ) /*++ @@ -1091,19 +1103,19 @@ Returns: --*/ { - struct tm *tm; - tm = UnixThunk->GmTime (&SystemTime); - Time->Year = tm->tm_year; - Time->Month = tm->tm_mon; - Time->Day = tm->tm_mday; - Time->Hour = tm->tm_hour; - Time->Minute = tm->tm_min; - Time->Second = tm->tm_sec; - Time->Nanosecond = 0; - - Time->TimeZone = UnixThunk->GetTimeZone (); - - if (UnixThunk->GetDayLight ()) { + struct tm *tm; + tm = UnixThunk->GmTime (&SystemTime); + Time->Year = tm->tm_year; + Time->Month = tm->tm_mon; + Time->Day = tm->tm_mday; + Time->Hour = tm->tm_hour; + Time->Minute = tm->tm_min; + Time->Second = tm->tm_sec; + Time->Nanosecond = 0; + + Time->TimeZone = UnixThunk->GetTimeZone (); + + if (UnixThunk->GetDayLight ()) { Time->Daylight = EFI_TIME_ADJUST_DAYLIGHT; } } @@ -1112,7 +1124,7 @@ STATIC EFI_STATUS UnixSimpleFileSystemFileInfo ( UNIX_EFI_FILE_PRIVATE *PrivateFile, - IN CHAR8 *FileName, + IN CHAR8 *FileName, IN OUT UINTN *BufferSize, OUT VOID *Buffer ) @@ -1141,18 +1153,18 @@ Returns: EFI_FILE_INFO *Info; CHAR8 *RealFileName; CHAR8 *TempPointer; - CHAR16 *BufferFileName; - struct stat buf; + CHAR16 *BufferFileName; + struct stat buf; - if (FileName != NULL) { - RealFileName = FileName; - } + if (FileName != NULL) { + RealFileName = FileName; + } else if (PrivateFile->IsRootDirectory) { - RealFileName = ""; + RealFileName = ""; } else { RealFileName = PrivateFile->FileName; - } - + } + TempPointer = RealFileName; while (*TempPointer) { if (*TempPointer == '/') { @@ -1161,7 +1173,7 @@ Returns: TempPointer++; } - + Size = SIZE_OF_EFI_FILE_INFO; NameSize = AsciiStrSize (RealFileName) * 2; ResultSize = Size + NameSize; @@ -1169,39 +1181,39 @@ Returns: if (*BufferSize < ResultSize) { *BufferSize = ResultSize; return EFI_BUFFER_TOO_SMALL; - } - if (PrivateFile->UnixThunk->Stat ( - FileName == NULL ? PrivateFile->FileName : FileName, - &buf) < 0) - return EFI_DEVICE_ERROR; - + } + if (PrivateFile->UnixThunk->Stat ( + FileName == NULL ? PrivateFile->FileName : FileName, + &buf) < 0) + return EFI_DEVICE_ERROR; + Status = EFI_SUCCESS; Info = Buffer; ZeroMem (Info, ResultSize); Info->Size = ResultSize; - Info->FileSize = buf.st_size; - Info->PhysicalSize = MultU64x32 (buf.st_blocks, buf.st_blksize); - - UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_ctime, &Info->CreateTime); - UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_atime, &Info->LastAccessTime); - UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_mtime, &Info->ModificationTime); - - if (!(buf.st_mode & S_IWUSR)) { + Info->FileSize = buf.st_size; + Info->PhysicalSize = MultU64x32 (buf.st_blocks, buf.st_blksize); + + UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_ctime, &Info->CreateTime); + UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_atime, &Info->LastAccessTime); + UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_mtime, &Info->ModificationTime); + + if (!(buf.st_mode & S_IWUSR)) { Info->Attribute |= EFI_FILE_READ_ONLY; } - if (S_ISDIR(buf.st_mode)) { + if (S_ISDIR(buf.st_mode)) { Info->Attribute |= EFI_FILE_DIRECTORY; } - BufferFileName = (CHAR16 *)((CHAR8 *) Buffer + Size); - while (*RealFileName) - *BufferFileName++ = *RealFileName++; - *BufferFileName = 0; - + BufferFileName = (CHAR16 *)((CHAR8 *) Buffer + Size); + while (*RealFileName) + *BufferFileName++ = *RealFileName++; + *BufferFileName = 0; + *BufferSize = ResultSize; return Status; } @@ -1245,83 +1257,96 @@ Returns: { UNIX_EFI_FILE_PRIVATE *PrivateFile; EFI_STATUS Status; - INTN Res; + INTN Res; UINTN Size; UINTN NameSize; UINTN ResultSize; - CHAR8 *FullFileName; + CHAR8 *FullFileName; + EFI_TPL OldTpl; if (This == NULL || BufferSize == NULL || Buffer == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); if (!PrivateFile->IsDirectoryPath) { if (PrivateFile->fd < 0) { - return EFI_DEVICE_ERROR; + Status = EFI_DEVICE_ERROR; + goto Done; } Res = PrivateFile->UnixThunk->Read ( PrivateFile->fd, Buffer, - *BufferSize); - if (Res < 0) - return EFI_DEVICE_ERROR; - *BufferSize = Res; - return EFI_SUCCESS; + *BufferSize); + if (Res < 0) { + Status = EFI_DEVICE_ERROR; + goto Done; + } + *BufferSize = Res; + Status = EFI_SUCCESS; + goto Done; } // - // Read on a directory. + // Read on a directory. // if (PrivateFile->Dir == NULL) { - return EFI_DEVICE_ERROR; + Status = EFI_DEVICE_ERROR; + goto Done; } - - if (PrivateFile->Dirent == NULL) { - PrivateFile->Dirent = PrivateFile->UnixThunk->ReadDir (PrivateFile->Dir); - if (PrivateFile->Dirent == NULL) { + + if (PrivateFile->Dirent == NULL) { + PrivateFile->Dirent = PrivateFile->UnixThunk->ReadDir (PrivateFile->Dir); + if (PrivateFile->Dirent == NULL) { *BufferSize = 0; - return EFI_SUCCESS; - } - } - + Status = EFI_SUCCESS; + goto Done; + } + } + Size = SIZE_OF_EFI_FILE_INFO; - NameSize = AsciiStrLen (PrivateFile->Dirent->d_name) + 1; + NameSize = AsciiStrLen (PrivateFile->Dirent->d_name) + 1; ResultSize = Size + 2 * NameSize; if (*BufferSize < ResultSize) { *BufferSize = ResultSize; - return EFI_BUFFER_TOO_SMALL; - } + Status = EFI_BUFFER_TOO_SMALL; + goto Done; + } Status = EFI_SUCCESS; *BufferSize = ResultSize; - + Status = gBS->AllocatePool ( EfiBootServicesData, - AsciiStrLen(PrivateFile->FileName) + 1 + NameSize, - (VOID **)&FullFileName + AsciiStrLen(PrivateFile->FileName) + 1 + NameSize, + (VOID **)&FullFileName ); if (EFI_ERROR (Status)) { - return Status; + goto Done; } - - AsciiStrCpy(FullFileName, PrivateFile->FileName); - AsciiStrCat(FullFileName, "/"); - AsciiStrCat(FullFileName, PrivateFile->Dirent->d_name); - Status = UnixSimpleFileSystemFileInfo (PrivateFile, - FullFileName, - BufferSize, - Buffer); - gBS->FreePool (FullFileName); + + AsciiStrCpy(FullFileName, PrivateFile->FileName); + AsciiStrCat(FullFileName, "/"); + AsciiStrCat(FullFileName, PrivateFile->Dirent->d_name); + Status = UnixSimpleFileSystemFileInfo (PrivateFile, + FullFileName, + BufferSize, + Buffer); + gBS->FreePool (FullFileName); - PrivateFile->Dirent = NULL; + PrivateFile->Dirent = NULL; - return Status; +Done: + gBS->RestoreTPL (OldTpl); + + return Status; } EFI_STATUS @@ -1368,12 +1393,16 @@ Returns: // TODO: EFI_INVALID_PARAMETER - add return value to function comment { UNIX_EFI_FILE_PRIVATE *PrivateFile; - UINTN Res; + UINTN Res; + EFI_STATUS Status; + EFI_TPL OldTpl; if (This == NULL || BufferSize == NULL || Buffer == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); if (PrivateFile->fd < 0) { @@ -1391,11 +1420,17 @@ Returns: Res = PrivateFile->UnixThunk->Write ( PrivateFile->fd, Buffer, - *BufferSize); - if (Res == (UINTN)-1) - return EFI_DEVICE_ERROR; - *BufferSize = Res; - return EFI_SUCCESS; + *BufferSize); + if (Res == (UINTN)-1) { + Status = EFI_DEVICE_ERROR; + goto Done; + } + *BufferSize = Res; + Status = EFI_SUCCESS; + +Done: + gBS->RestoreTPL (OldTpl); + return Status; // // bugbug: need to access unix error reporting @@ -1432,33 +1467,41 @@ Returns: EFI_STATUS Status; UNIX_EFI_FILE_PRIVATE *PrivateFile; UINT64 Pos; + EFI_TPL OldTpl; if (This == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); if (PrivateFile->IsDirectoryPath) { if (Position != 0) { - return EFI_UNSUPPORTED; + Status = EFI_UNSUPPORTED; + goto Done; } - if (PrivateFile->Dir == NULL) { - return EFI_DEVICE_ERROR; - } - PrivateFile->UnixThunk->RewindDir (PrivateFile->Dir); - return EFI_SUCCESS; + if (PrivateFile->Dir == NULL) { + Status = EFI_DEVICE_ERROR; + goto Done; + } + PrivateFile->UnixThunk->RewindDir (PrivateFile->Dir); + Status = EFI_SUCCESS; + goto Done; } else { if (Position == (UINT64) -1) { Pos = PrivateFile->UnixThunk->Lseek (PrivateFile->fd, 0, SEEK_END); } else { Pos = PrivateFile->UnixThunk->Lseek (PrivateFile->fd, Position, SEEK_SET); - } + } Status = (Pos == (UINT64) -1) ? EFI_DEVICE_ERROR : EFI_SUCCESS; + } +Done: + gBS->RestoreTPL (OldTpl); return Status; - } } EFI_STATUS @@ -1488,20 +1531,27 @@ Returns: --*/ // TODO: EFI_INVALID_PARAMETER - add return value to function comment { + EFI_STATUS Status; UNIX_EFI_FILE_PRIVATE *PrivateFile; + EFI_TPL OldTpl; if (This == NULL || Position == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); if (PrivateFile->IsDirectoryPath) { - return EFI_UNSUPPORTED; + Status = EFI_UNSUPPORTED; } else { - *Position = PrivateFile->UnixThunk->Lseek (PrivateFile->fd, 0, SEEK_CUR); - return (*Position == (UINT64) -1) ? EFI_DEVICE_ERROR : EFI_SUCCESS; + *Position = PrivateFile->UnixThunk->Lseek (PrivateFile->fd, 0, SEEK_CUR); + Status = (*Position == (UINT64) -1) ? EFI_DEVICE_ERROR : EFI_SUCCESS; } + + gBS->RestoreTPL (OldTpl); + return Status; } EFI_STATUS @@ -1552,12 +1602,15 @@ Returns: EFI_FILE_SYSTEM_INFO *FileSystemInfoBuffer; INTN UnixStatus; UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot; - struct statfs buf; + struct statfs buf; + EFI_TPL OldTpl; if (This == NULL || InformationType == NULL || BufferSize == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); PrivateRoot = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem); @@ -1565,17 +1618,19 @@ Returns: if (CompareGuid (InformationType, &gEfiFileInfoGuid)) { Status = UnixSimpleFileSystemFileInfo (PrivateFile, NULL, BufferSize, Buffer); - } - else if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) { + } else if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) { if (*BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) { *BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel); - return EFI_BUFFER_TOO_SMALL; + Status = EFI_BUFFER_TOO_SMALL; + goto Done; + } + + UnixStatus = PrivateFile->UnixThunk->StatFs (PrivateFile->FileName, &buf); + if (UnixStatus < 0) { + Status = EFI_DEVICE_ERROR; + goto Done; } - UnixStatus = PrivateFile->UnixThunk->StatFs (PrivateFile->FileName, &buf); - if (UnixStatus < 0) - return EFI_DEVICE_ERROR; - FileSystemInfoBuffer = (EFI_FILE_SYSTEM_INFO *) Buffer; FileSystemInfoBuffer->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel); FileSystemInfoBuffer->ReadOnly = FALSE; @@ -1583,21 +1638,19 @@ Returns: // // Succeeded // - FileSystemInfoBuffer->VolumeSize = MultU64x32 (buf.f_blocks, buf.f_bsize); - FileSystemInfoBuffer->FreeSpace = MultU64x32 (buf.f_bavail, buf.f_bsize); - FileSystemInfoBuffer->BlockSize = buf.f_bsize; + FileSystemInfoBuffer->VolumeSize = MultU64x32 (buf.f_blocks, buf.f_bsize); + FileSystemInfoBuffer->FreeSpace = MultU64x32 (buf.f_bavail, buf.f_bsize); + FileSystemInfoBuffer->BlockSize = buf.f_bsize; StrCpy ((CHAR16 *) FileSystemInfoBuffer->VolumeLabel, PrivateRoot->VolumeLabel); *BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel); Status = EFI_SUCCESS; - } - - else if (CompareGuid (InformationType, - &gEfiFileSystemVolumeLabelInfoIdGuid)) { + } else if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) { if (*BufferSize < StrSize (PrivateRoot->VolumeLabel)) { *BufferSize = StrSize (PrivateRoot->VolumeLabel); - return EFI_BUFFER_TOO_SMALL; + Status = EFI_BUFFER_TOO_SMALL; + goto Done; } StrCpy ((CHAR16 *) Buffer, PrivateRoot->VolumeLabel); @@ -1605,6 +1658,8 @@ Returns: Status = EFI_SUCCESS; } +Done: + gBS->RestoreTPL (OldTpl); return Status; } @@ -1662,6 +1717,7 @@ Returns: EFI_FILE_INFO *NewFileInfo; EFI_STATUS Status; UINTN OldInfoSize; + EFI_TPL OldTpl; mode_t NewAttr; struct stat OldAttr; CHAR8 *OldFileName; @@ -1674,9 +1730,9 @@ Returns: struct tm NewLastAccessSystemTime; struct tm NewLastWriteSystemTime; EFI_FILE_SYSTEM_INFO *NewFileSystemInfo; - CHAR8 *AsciiFilePtr; - CHAR16 *UnicodeFilePtr; - INTN UnixStatus; + CHAR8 *AsciiFilePtr; + CHAR16 *UnicodeFilePtr; + INTN UnixStatus; // // Check for invalid parameters. @@ -1685,6 +1741,8 @@ Returns: return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + // // Initialise locals. // @@ -1701,7 +1759,8 @@ Returns: // if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) { if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) { - return EFI_BAD_BUFFER_SIZE; + Status = EFI_BAD_BUFFER_SIZE; + goto Done; } NewFileSystemInfo = (EFI_FILE_SYSTEM_INFO *) Buffer; @@ -1721,7 +1780,8 @@ Returns: StrCpy (PrivateRoot->VolumeLabel, NewFileSystemInfo->VolumeLabel); - return EFI_SUCCESS; + Status = EFI_SUCCESS; + goto Done; } // @@ -1729,20 +1789,24 @@ Returns: // if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) { if (BufferSize < StrSize (PrivateRoot->VolumeLabel)) { - return EFI_BAD_BUFFER_SIZE; + Status = EFI_BAD_BUFFER_SIZE; + goto Done; } StrCpy (PrivateRoot->VolumeLabel, (CHAR16 *) Buffer); - return EFI_SUCCESS; + Status = EFI_SUCCESS; + goto Done; } if (!CompareGuid (InformationType, &gEfiFileInfoGuid)) { - return EFI_UNSUPPORTED; + Status = EFI_UNSUPPORTED; + goto Done; } if (BufferSize < SIZE_OF_EFI_FILE_INFO) { - return EFI_BAD_BUFFER_SIZE; + Status = EFI_BAD_BUFFER_SIZE; + goto Done; } // @@ -1758,7 +1822,8 @@ Returns: (NewFileInfo->Attribute &~(EFI_FILE_VALID_ATTR)) || (sizeof (UINTN) == 4 && NewFileInfo->Size > 0xFFFFFFFF) ) { - return EFI_INVALID_PARAMETER; + Status = EFI_INVALID_PARAMETER; + goto Done; } // @@ -1779,7 +1844,7 @@ Returns: goto Done; } - Status = gBS->AllocatePool (EfiBootServicesData, OldInfoSize, + Status = gBS->AllocatePool (EfiBootServicesData, OldInfoSize, (VOID **)&OldFileInfo); if (EFI_ERROR (Status)) { @@ -1819,9 +1884,9 @@ Returns: } AsciiStrCpy (NewFileName, PrivateRoot->FilePath); - AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName); - UnicodeFilePtr = NewFileInfo->FileName + 1; - *AsciiFilePtr++ ='/'; + AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName); + UnicodeFilePtr = NewFileInfo->FileName + 1; + *AsciiFilePtr++ ='/'; } else { Status = gBS->AllocatePool ( EfiBootServicesData, @@ -1834,18 +1899,18 @@ Returns: } AsciiStrCpy (NewFileName, PrivateRoot->FilePath); - AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName); - while (AsciiFilePtr > NewFileName && AsciiFilePtr[-1] != '/') { - AsciiFilePtr--; - } - UnicodeFilePtr = NewFileInfo->FileName; + AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName); + while (AsciiFilePtr > NewFileName && AsciiFilePtr[-1] != '/') { + AsciiFilePtr--; + } + UnicodeFilePtr = NewFileInfo->FileName; } - // Convert to ascii. - while (*UnicodeFilePtr) { - *AsciiFilePtr++ = *UnicodeFilePtr++; - } - *AsciiFilePtr = 0; - + // Convert to ascii. + while (*UnicodeFilePtr) { + *AsciiFilePtr++ = *UnicodeFilePtr++; + } + *AsciiFilePtr = 0; + // // Is there an attribute change request? @@ -1902,10 +1967,10 @@ Returns: // // Set file or directory information. // - if (PrivateFile->UnixThunk->Stat (OldFileName, &OldAttr) != 0) { - Status = EFI_DEVICE_ERROR; - goto Done; - } + if (PrivateFile->UnixThunk->Stat (OldFileName, &OldAttr) != 0) { + Status = EFI_DEVICE_ERROR; + goto Done; + } // // Name change. @@ -1977,7 +2042,7 @@ Returns: // Time change // if (TimeChangeFlag) { - struct utimbuf utime; + struct utimbuf utime; NewLastAccessSystemTime.tm_year = NewFileInfo->LastAccessTime.Year; NewLastAccessSystemTime.tm_mon = NewFileInfo->LastAccessTime.Month; @@ -1985,25 +2050,25 @@ Returns: NewLastAccessSystemTime.tm_hour = NewFileInfo->LastAccessTime.Hour; NewLastAccessSystemTime.tm_min = NewFileInfo->LastAccessTime.Minute; NewLastAccessSystemTime.tm_sec = NewFileInfo->LastAccessTime.Second; - NewLastAccessSystemTime.tm_isdst = 0; + NewLastAccessSystemTime.tm_isdst = 0; + + utime.actime = PrivateFile->UnixThunk->MkTime (&NewLastAccessSystemTime); - utime.actime = PrivateFile->UnixThunk->MkTime (&NewLastAccessSystemTime); - NewLastWriteSystemTime.tm_year = NewFileInfo->ModificationTime.Year; NewLastWriteSystemTime.tm_mon = NewFileInfo->ModificationTime.Month; NewLastWriteSystemTime.tm_mday = NewFileInfo->ModificationTime.Day; NewLastWriteSystemTime.tm_hour = NewFileInfo->ModificationTime.Hour; NewLastWriteSystemTime.tm_min = NewFileInfo->ModificationTime.Minute; NewLastWriteSystemTime.tm_sec = NewFileInfo->ModificationTime.Second; - NewLastWriteSystemTime.tm_isdst = 0; + NewLastWriteSystemTime.tm_isdst = 0; - utime.modtime = PrivateFile->UnixThunk->MkTime (&NewLastWriteSystemTime); - - if (utime.actime == (time_t)-1 || utime.modtime == (time_t)-1) { + utime.modtime = PrivateFile->UnixThunk->MkTime (&NewLastWriteSystemTime); + + if (utime.actime == (time_t)-1 || utime.modtime == (time_t)-1) { goto Done; } - if (PrivateFile->UnixThunk->UTime (PrivateFile->FileName, &utime) == -1) { + if (PrivateFile->UnixThunk->UTime (PrivateFile->FileName, &utime) == -1) { goto Done; } } @@ -2015,9 +2080,9 @@ Returns: NewAttr = OldAttr.st_mode; if (NewFileInfo->Attribute & EFI_FILE_READ_ONLY) { - NewAttr &= ~(S_IRUSR | S_IRGRP | S_IROTH); + NewAttr &= ~(S_IRUSR | S_IRGRP | S_IROTH); } else { - NewAttr |= S_IRUSR; + NewAttr |= S_IRUSR; } UnixStatus = PrivateFile->UnixThunk->Chmod (NewFileName, NewAttr); @@ -2039,6 +2104,8 @@ Done: gBS->FreePool (NewFileName); } + gBS->RestoreTPL (OldTpl); + return Status; } @@ -2077,30 +2144,43 @@ Returns: // TODO: EFI_INVALID_PARAMETER - add return value to function comment { UNIX_EFI_FILE_PRIVATE *PrivateFile; + EFI_STATUS Status; + EFI_TPL OldTpl; if (This == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); if (PrivateFile->IsDirectoryPath) { - return EFI_SUCCESS; + Status = EFI_SUCCESS; + goto Done; } if (PrivateFile->IsOpenedByRead) { - return EFI_ACCESS_DENIED; + Status = EFI_ACCESS_DENIED; + goto Done; } - if (PrivateFile->fd < 0) { - return EFI_DEVICE_ERROR; + if (PrivateFile->fd < 0) { + Status = EFI_DEVICE_ERROR; + goto Done; } - - return PrivateFile->UnixThunk->FSync (PrivateFile->fd) == 0 ? EFI_SUCCESS : EFI_DEVICE_ERROR; + + PrivateFile->UnixThunk->FSync (PrivateFile->fd) == 0 ? EFI_SUCCESS : EFI_DEVICE_ERROR; + +Done: + gBS->RestoreTPL (OldTpl); + + return Status; // // bugbug: - Use Unix error reporting. // } +