Linux Driver Code to print machine name, system name, release and Version
init_uts_ns(init/version.c) variable in Linux Kernel contains the information about:
- Operating system name (e.g., "Linux")
- Operating system release (e.g., "2.6.28")
- Operating system version
- Hardware identifier
When you run 'uname' command from user space, values from above structure are retrieved.
Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> | |
#include <linux/kernel.h> | |
#include <linux/types.h> | |
#include <linux/utsname.h> | |
#include <linux/errno.h> | |
static void data_cleanup(void) | |
{ | |
/* never called */ | |
} | |
static int data_init(void) | |
{ | |
/* print information and return an error */ | |
printk("Machine Name: %s\n",init_uts_ns.name.machine); | |
printk("System Name: %s\n",init_uts_ns.name.sysname); | |
printk("Release: %s\n",init_uts_ns.name.release); | |
printk("Version: %s\n",init_uts_ns.name.version); | |
return 0; | |
} | |
module_init(data_init); | |
module_exit(data_cleanup); | |
MODULE_LICENSE("GPL"); |
Output:
Comments
Post a Comment