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


#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");
view raw datasize.c hosted with ❤ by GitHub


Output:


Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

PR, PN and PV Variable in Yocto