⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cooking.c

📁 Linux下的系统信息获取
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Copyright (C) 2001-2001 Fujitsu Siemens Computers   Joachim Braeuer   This file is part of smbios   smbios is free software; you can redistribute it and/or modify it   under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License,   or (at your option) any later version.   smbios is distributed in the hope that it will be useful, but WITHOUT   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   for more details.   You should have received a copy of the GNU General Public License   along with smbios; see the file COPYING. If not, write to the   Free Software Foundation, Inc., 59 Temple Place - Suite 330,   Boston, MA 02111-1307, USA.*//* $Log: cooking.c,v $/* Revision 1.1  2001/09/15 14:52:43  bretthauert/* initial release/* *//** \file cooking.c *  DMI-BIOS and SM-BIOS interpreting (cooking) functions *  The functions defined in this file generate a human readable output of the *  raw binary DMI- and SM-BIOS types. However, every time the specification of *  DMI- and SM-BIOS (types) change, these changes have to be adopted in these *  routines, too. *   *  \author Thomas Bretthauer *  \author Joachim Braeuer *  \version 0.1 *  \date January 2001 */#ifndef __KERNEL__#  define __KERNEL__#endif#ifndef MODULE#  define MODULE#endif#define __NO_VERSION__		/* don't define kernel_version in module.h */#include <linux/module.h>#include <linux/kernel.h>	/* ... for 'printk()' */#include <linux/errno.h>	/* ... error codes */#include <linux/types.h>	/* ... fixed size types definitions, '__u8'... */#include <linux/proc_fs.h>  /* ... /proc file system ... */#include <linux/string.h>	/* ... for 'memcpy()', 'strncmp()' */#include "strgdef.h"        /* human readable output string definitions for directories,                             * files and file contents                             */#include "bios.h"		    /* ... local declarations for DMI-, SM-BIOS */#include "cooking.h"	    /* ... local declarations for interpreting DMI- and SM-BIOS types */EXPORT_NO_SYMBOLS;/** \fn unsigned char * bios_cook (smbios_struct *smbiosstruct, unsigned int * plength)  * \brief huge switch that calls the cooking functions for every SMBIOS structure  * \param smbiosstruct pointer to SMBIOS raw structure  * \param plength amount of memory allocated by functions called from this function  * \return pointer to string that holds the interpreted data  *  * this function gets a raw SMBIOS structure. it calls the appropriate cooking function  * whitch interpretes the raw data and builds a string with the interpreted data.  * the caller is responsible to free the memory allocated by the "sub"-functions.  *  * \author Joachim Braeuer  * \date March 2001  */unsigned char *bios_cook (smbios_struct *smbiosstruct, unsigned int * plength){	unsigned char *scratch = NULL;      /* pointer that holds the interpreded data */	/* do we have a valid SMBIOS? */	if ( !smbiosstruct )	   return NULL;	/* switch between the different smbios types to interpret and call the appropriate	 * cook function.	 */	switch (smbiosstruct->type)	{        case 0:	        scratch = bios_cook_type_0 (smbiosstruct, plength);	        break;	    case 1:	        scratch = bios_cook_type_1 (smbiosstruct, plength);	        break;	    case 2:	        scratch = bios_cook_type_2 (smbiosstruct, plength);	        break;	    case 3:	        scratch = bios_cook_type_3 (smbiosstruct, plength);	        break;	    case 4:	        scratch = bios_cook_type_4 (smbiosstruct, plength);	        break;	    case 5:	        scratch = bios_cook_type_5 (smbiosstruct, plength);	        break;	    case 6:	        scratch = bios_cook_type_6 (smbiosstruct, plength);	        break;	    case 7:	        scratch = bios_cook_type_7 (smbiosstruct, plength);	        break;	    case 8:		        scratch = bios_cook_type_8 (smbiosstruct, plength);		        break;		    case 9:		        scratch = bios_cook_type_9 (smbiosstruct, plength);		        break;	    case 10:		        scratch = bios_cook_type_10 (smbiosstruct, plength);		        break;		    case 11:		        scratch = bios_cook_type_11 (smbiosstruct, plength);		        break;	    case 12:		        scratch = bios_cook_type_12 (smbiosstruct, plength);		        break;    		    case 13:		        scratch = bios_cook_type_13 (smbiosstruct, plength);		        break;	    case 16:		        scratch = bios_cook_type_16 (smbiosstruct, plength);		        break;	    case 17:		        scratch = bios_cook_type_17 (smbiosstruct, plength);		        break;	    case 19:		        scratch = bios_cook_type_19 (smbiosstruct, plength);		        break;	    case 20:		        scratch = bios_cook_type_20 (smbiosstruct, plength);		        break;	    case 32:		        scratch = bios_cook_type_32 (smbiosstruct, plength);		        break;	    case 127:		        scratch = bios_cook_type_127 (smbiosstruct, plength);		        break;        				/* if it's none of the supported types, just display the standard		 * DMI header */	    default:	        {                unsigned char line[512];                unsigned char line_type[128];     /* type */                unsigned char line_length[128];   /* length */                unsigned char line_handle[128];   /* handle */                unsigned char line_text[128];     /* not supported message */                /* prepare type, length, handle and not supported message */                sprintf (line_type, "%20s : %d\n", TYPE, smbiosstruct->type);                sprintf (line_length, "%20s : %d %s\n", LENGTH, smbiosstruct->length, BYTES);                sprintf (line_handle, "%20s : %d\n", HANDLE, smbiosstruct->handle);	            sprintf (line_text, "\n%s\n\n", NOT_SUPPORTED);                sprintf (line, "%s%s%s%s", line_type, line_length, line_handle, line_text);                *plength = strlen (line);                /* allocate memory ... */                scratch = kmalloc (*plength+1, GFP_BUFFER);                if (scratch == NULL)                {                    *plength = 0;                    return NULL;                }	                /* ... and copy the string */                memcpy (scratch, line, *plength);            }	} /* end switch */		/* return a string with all the interpreted data for the given raw structure */	/* the caller is responsible to free the memory. */	return scratch;}/** \fn unsigned char * bios_cook_type_0 (smbios_struct *smbiosstruct, unsigned int * plength)  * \brief writes interpreted SMBIOS Type 0 data to a /proc file  * \param smbiosstruct pointer to SMBIOS Type 0 raw structure  * \param plength amount of memory allocated by this function  * \return pointer to string that holds the interpreted data  *  * this function gets a raw SMBIOS Type 0 (Bios) structure. it  * interpretes the raw data and builds a string with the interpreted  * data. this is the return value of this structure. the caller is  * responsible to free the allocated memory.  *  * \author Joachim Braeuer  * \date March 2001  */unsigned char *bios_cook_type_0 (smbios_struct * smbiosstruct, unsigned int * plength){	smbios_type_0 *type0;    unsigned char * scratch;	/* contains the full block of interpreted data */    /* on some systems the system crashed if the stack (local variables) */    /* is bigger than one pages (4k). since linux needs some space in this */    /* page the variables should never exceed 3kB. */	unsigned char file[2800];	/* contains one line of the above file */    unsigned char line[128];    /* cast raw data to type 0 structure */    type0 = (smbios_type_0 *)smbiosstruct;    /* prepare header string */    sprintf (line, "%-35s%s %d %s\n", TYPE, SEP1, smbiosstruct->type, TYPE0_NAME);    strcpy(file, line);	sprintf (line, "%-35s%s %d %s\n", LENGTH, SEP1, smbiosstruct->length, BYTES);	strcat(file, line);	sprintf (line, "%-35s%s %d\n\n", HANDLE, SEP1, smbiosstruct->handle);	strcat(file, line);	/* prepare strings with type 0 information */	sprintf (line, "%-35s%s %s\n", TYPE0_VENDOR, SEP1, GetString(smbiosstruct, (unsigned int)(type0->vendor)));	strcat(file, line);	sprintf (line, "%-35s%s %s\n", TYPE0_VERSION, SEP1, GetString(smbiosstruct, (unsigned int)(type0->version)));	strcat(file, line);	sprintf (line, "%-35s%s %X\n", TYPE0_ADR_SEG, SEP1, type0->startaddr);	strcat(file, line);	sprintf (line, "%-35s%s %s\n", TYPE0_REL_DATE, SEP1, GetString(smbiosstruct, (unsigned int)(type0->reldate)));	strcat(file, line);	sprintf (line, "%-35s%s %d kB\n", TYPE0_ROM_SIZE, SEP1, ((type0->romsize)+1) * 64);	strcat(file, line);	    /* bios characteristics interpretation */    sprintf(line, "%-35s%s\n", TYPE0_CHAR, SEP1);    strcat(file, line);    if( (type0->characteristics) & 0x0000000000000001 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_RES);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000000002 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_RES);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000000004 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_UNKNOWN);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000000008 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_NOTSUP);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000000010 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_ISA);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000000020 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_MCA);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000000040 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_EISA);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000000080 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_PCI);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000000100 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_PCMCIA);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000000200 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_PNP);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000000400 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_APM);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000000800 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_FLASH);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000001000 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_SHADOWING);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000002000 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_VL);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000004000 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_ESCD);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000008000 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_BOOTCD);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000010000 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_SELBOOT);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000020000 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_BIOS_IS_SOCKETED);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000040000 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_PCMCIA_BOOT);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000080000 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_ENH_DISK_DRIVE);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000100000 )    {        sprintf(line, "%-35s  %s %s \n", "", SEP2, TYPE0_CHAR_FD_NEC);        strcat(file, line);    }    if( (type0->characteristics) & 0x0000000000200000 )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -