Thursday, 18 September 2014

Testing if PC is booted from UEFI or BIOS

#include <iostream>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
using namespace std;

class myInodeInfo
{
struct stat s;
int st;
public:

myInodeInfo(const char * f)
{
    st = stat(f,&s);
}
void display()
{

        mode_t m=s.st_mode;
       
        if(S_ISDIR(m))
            cout<<"\nSystem booted from UEFI"<<endl;
       
        else cout<<"\nSystem not booted from UEFI"<<endl;
}

void display1()
{
    int i=system("dmesg | grep 'EFI v'");
    if(i == 0)
    {
        cout<<"\nSystem booted from UEFI"<<endl;

    }
    else{
        cout<<"\nSystem booted from BIOS"<<endl;
}

}
};

int main() {

    char file[20]="/sys/firmware/efi";
   
    myInodeInfo obj= myInodeInfo(file);
    int ch=0;
    while(ch!=3)
    {
    cout<<"\n\nEnter choice: \n1. To check UEFI directory or BIOS.\n2.To check system log for UEFI or BIOS.\n3.Exit"<<endl;
    cin>>ch;
   
        switch(ch)
        {
       
            case 1:
                obj.display();
                break;
   
            case 2:
                obj.display1();
                break;

            case 3:
                //exit(0);
                break;
        }
    }
    return 0;
}



/*++++++++++++++++++++++OUTPUT++++++++++++++++++++

[root@localhost Documents]# g++ bootosd.cpp
[root@localhost Documents]# ./a.out


Enter choice:
1. To check UEFI directory or BIOS.
2.To check system log for UEFI or BIOS.
3.Exit
1

System not booted from UEFI


Enter choice:
1. To check UEFI directory or BIOS.
2.To check system log for UEFI or BIOS.
3.Exit
2

System booted from BIOS


Enter choice:
1. To check UEFI directory or BIOS.
2.To check system log for UEFI or BIOS.
3.Exit
3
[root@localhost Documents]#
++++++++++++++++++++++++++++++++++++++++++++++++ */

No comments:

Post a Comment