loader/config.c
static REFIT_FILE * GenerateOptionsFromEtcFstab(REFIT_VOLUME *Volume) {
   UINTN        TokenCount, i;
   REFIT_FILE   *Options = NULL, *Fstab = NULL;
   EFI_STATUS   Status;
   CHAR16       **TokenList, *Line, Root[100];

   if (FileExists(Volume->RootDir, L"\\etc\\fstab")) {
      Options = AllocateZeroPool(sizeof(REFIT_FILE));
      Fstab = AllocateZeroPool(sizeof(REFIT_FILE));
      Status = ReadFile(Volume->RootDir, L"\\etc\\fstab", Fstab, &i);
      if (CheckError(Status, L"while reading /etc/fstab")) {
         if (Options != NULL)
            FreePool(Options);
         if (Fstab != NULL)
            FreePool(Fstab);
         Options = NULL;
         Fstab = NULL;
      } else { // File read; locate root fs and create entries
         Options->Encoding = ENCODING_UTF16_LE;
         while ((TokenCount = ReadTokenLine(Fstab, &TokenList)) > 0) {
            if (TokenCount > 2) {
               Root[0] = '\0';
               if (StrCmp(TokenList[1], L"\\") == 0) {
                  SPrint(Root, 99, L"%s", TokenList[0]);
               } else if (StrCmp(TokenList[2], L"\\") == 0) {
                  SPrint(Root, 99, L"%s=%s", TokenList[0], TokenList[1]);
               } // if/elseif/elseif
               if (Root[0] != L'\0') {
                  for (i = 0; i < StrLen(Root); i++)
                     if (Root[i] == '\\')
                        Root[i] = '/';
                  Line = PoolPrint(L"\"Boot with normal options\"    \"ro root=%s\"\n", Root);
                  MergeStrings((CHAR16 **) &(Options->Buffer), Line, 0);
                  MyFreePool(Line);
                  Line = PoolPrint(L"\"Boot into single-user mode\"  \"ro root=%s single\"\n", Root);
                  MergeStrings((CHAR16**) &(Options->Buffer), Line, 0);
                  Options->BufferSize = StrLen((CHAR16*) Options->Buffer) * sizeof(CHAR16);
               } // if
            } // if
            FreeTokenLine(&TokenList, &TokenCount);
         } // while

         if (Options->Buffer) {
            Options->Current8Ptr  = (CHAR8 *)Options->Buffer;
            Options->End8Ptr      = Options->Current8Ptr + Options->BufferSize;
            Options->Current16Ptr = (CHAR16 *)Options->Buffer;
            Options->End16Ptr     = Options->Current16Ptr + (Options->BufferSize >> 1);
         } else {
             MyFreePool(Options);
             Options = NULL;
         }

         MyFreePool(Fstab->Buffer);
         MyFreePool(Fstab);
      } // if/else file read error
   } // if /etc/fstab exists
   return Options;
}
// Create an options file based on /etc/fstab. The resulting file has two options
// lines, one of which boots the system with "ro root={rootfs}" and the other of
// which boots the system with "ro root={rootfs} single", where "{rootfs}" is the
// filesystem identifier associated with the "/" line in /etc/fstab.
Create an options file based on /etc/fstab.
Create an options file based on / etc / fstab .
static REFIT_FILE * GenerateOptionsFromEtcFstab(REFIT_VOLUME *Volume) {
   UINTN        TokenCount, i;
   REFIT_FILE   *Options = NULL, *Fstab = NULL;
   EFI_STATUS   Status;
   CHAR16       **TokenList, *Line, Root[100];
   if (FileExists(Volume->RootDir, L"\\etc\\fstab")) {
      Options = AllocateZeroPool(sizeof(REFIT_FILE));
      Fstab = AllocateZeroPool(sizeof(REFIT_FILE));
      Status = ReadFile(Volume->RootDir, L"\\etc\\fstab", Fstab, &i);
      if (CheckError(Status, L"while reading /etc/fstab")) {
         if (Options != NULL)
            FreePool(Options);
         if (Fstab != NULL)
            FreePool(Fstab);
         Options = NULL;
         Fstab = NULL;
      } else { 
         Options->Encoding = ENCODING_UTF16_LE;
         while ((TokenCount = ReadTokenLine(Fstab, &TokenList)) > 0) {
            if (TokenCount > 2) {
               Root[0] = '\0';
               if (StrCmp(TokenList[1], L"\\") == 0) {
                  SPrint(Root, 99, L"%s", TokenList[0]);
               } else if (StrCmp(TokenList[2], L"\\") == 0) {
                  SPrint(Root, 99, L"%s=%s", TokenList[0], TokenList[1]);
               } 
               if (Root[0] != L'\0') {
                  for (i = 0; i < StrLen(Root); i++)
                     if (Root[i] == '\\')
                        Root[i] = '/';
                  Line = PoolPrint(L"\"Boot with normal options\"    \"ro root=%s\"\n", Root);
                  MergeStrings((CHAR16 **) &(Options->Buffer), Line, 0);
                  MyFreePool(Line);
                  Line = PoolPrint(L"\"Boot into single-user mode\"  \"ro root=%s single\"\n", Root);
                  MergeStrings((CHAR16**) &(Options->Buffer), Line, 0);
                  Options->BufferSize = StrLen((CHAR16*) Options->Buffer) * sizeof(CHAR16);
               } 
            } 
            FreeTokenLine(&TokenList, &TokenCount);
         } 
         if (Options->Buffer) {
            Options->Current8Ptr  = (CHAR8 *)Options->Buffer;
            Options->End8Ptr      = Options->Current8Ptr + Options->BufferSize;
            Options->Current16Ptr = (CHAR16 *)Options->Buffer;
            Options->End16Ptr     = Options->Current16Ptr + (Options->BufferSize >> 1);
         } else {
             MyFreePool(Options);
             Options = NULL;
         }
         MyFreePool(Fstab->Buffer);
         MyFreePool(Fstab);
      } /else file read error
   }  /etc/fstab exists
   return Options;
}
static REFIT_FILE * GenerateOptionsFromEtcFstab ( REFIT_VOLUME * Volume ) { UINTN TokenCount , i ; REFIT_FILE * Options = NULL , * Fstab = NULL ; EFI_STATUS Status ; CHAR16 * * TokenList , * Line , Root [ 100 ] ; if ( FileExists ( Volume -> RootDir , L" \\ \\ " ) ) { Options = AllocateZeroPool ( sizeof ( REFIT_FILE ) ) ; Fstab = AllocateZeroPool ( sizeof ( REFIT_FILE ) ) ; Status = ReadFile ( Volume -> RootDir , L" \\ \\ " , Fstab , & i ) ; if ( CheckError ( Status , L" " ) ) { if ( Options != NULL ) FreePool ( Options ) ; if ( Fstab != NULL ) FreePool ( Fstab ) ; Options = NULL ; Fstab = NULL ; } else { Options -> Encoding = ENCODING_UTF16_LE ; while ( ( TokenCount = ReadTokenLine ( Fstab , & TokenList ) ) > 0 ) { if ( TokenCount > 2 ) { Root [ 0 ] = ' \0 ' ; if ( StrCmp ( TokenList [ 1 ] , L" \\ " ) == 0 ) { SPrint ( Root , 99 , L" " , TokenList [ 0 ] ) ; } else if ( StrCmp ( TokenList [ 2 ] , L" \\ " ) == 0 ) { SPrint ( Root , 99 , L" " , TokenList [ 0 ] , TokenList [ 1 ] ) ; } if ( Root [ 0 ] != L' \0 ' ) { for ( i = 0 ; i < StrLen ( Root ) ; i ++ ) if ( Root [ i ] == ' \\ ' ) Root [ i ] = ' ' ; Line = PoolPrint ( L" \" \" \" \" \n " , Root ) ; MergeStrings ( ( CHAR16 * * ) & ( Options -> Buffer ) , Line , 0 ) ; MyFreePool ( Line ) ; Line = PoolPrint ( L" \" \" \" \" \n " , Root ) ; MergeStrings ( ( CHAR16 * * ) & ( Options -> Buffer ) , Line , 0 ) ; Options -> BufferSize = StrLen ( ( CHAR16 * ) Options -> Buffer ) * sizeof ( CHAR16 ) ; } } FreeTokenLine ( & TokenList , & TokenCount ) ; } if ( Options -> Buffer ) { Options -> Current8Ptr = ( CHAR8 * ) Options -> Buffer ; Options -> End8Ptr = Options -> Current8Ptr + Options -> BufferSize ; Options -> Current16Ptr = ( CHAR16 * ) Options -> Buffer ; Options -> End16Ptr = Options -> Current16Ptr + ( Options -> BufferSize >> 1 ) ; } else { MyFreePool ( Options ) ; Options = NULL ; } MyFreePool ( Fstab -> Buffer ) ; MyFreePool ( Fstab ) ; } } return Options ; }
Create an options file based on /etc/fstab.
Create an options file based on / etc / fstab .
// File read; locate root fs and create entries // if/elseif/elseif // if // if // while // if/else file read error // if /etc/fstab exists