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

📄 skvpd.c

📁 内核linux2.4.20,可跟rtlinux3.2打补丁 组成实时linux系统,编译内核
💻 C
📖 第 1 页 / 共 3 页
字号:
		ip = etp ;		vp.p_len = 0 ;		head = 3 ;	}	if (len + 3 > free) {		if (free < 7) {			SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,				("VPD Buffer Overflow, keyword not written\n"));			return (4) ;		}		/* cut it again */		len = free - 3 ;		rtv = 2 ;		SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,			("VPD Buffer Full, Keyword was cut\n")) ;	}	vpd_move_para(ip + vp.p_len + found, etp+2, len-vp.p_len+head) ;	vpd_insert_key(key, buf, len, ip) ;	if (vpd_mod_endtag(pAC, etp + len - vp.p_len + head)) {		pAC->vpd.v.vpd_status &= ~VPD_VALID ;		SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,			("VPD Encoding Error\n")) ;		return(6) ;	}	return (rtv) ;}/* *	Read the contents of the VPD EEPROM and copy it to the *	VPD buffer if not already done. * * return:	A pointer to the vpd_status structure. The structure contain *		this fields. */SK_VPD_STATUS	*VpdStat(SK_AC		*pAC,	/* Adapters context */SK_IOC		IoC)	/* IO Context */{	if (!(pAC->vpd.v.vpd_status & VPD_VALID)) {		(void)VpdInit(pAC,IoC) ;	}	return(&pAC->vpd.v) ;}/* *	Read the contents of the VPD EEPROM and copy it to the VPD *	buffer if not already done. *	Scan the VPD buffer for VPD keywords and create the VPD *	keyword list by copying the keywords to 'buf', all after *	each other and terminated with a '\0'. * * Exceptions:	o The Resource Type ID String (product name) is called "Name" *		o The VPD end tags 'RV' and 'RW' are not listed * *	The number of copied keywords is counted in 'elements'. * * returns	0:	success *		2:	buffer overfull, one or more keywords are missing *		6:	fatal VPD error * *	example values after returning: * *		buf =	"Name\0PN\0EC\0MN\0SN\0CP\0VF\0VL\0YA\0" *		*len =		30 *		*elements =	 9 */int		VpdKeys(SK_AC		*pAC,		/* common data base */SK_IOC		IoC,		/* IO Context */char		*buf,		/* buffer where to copy the keywords */int		*len,		/* buffer length */int		*elements)	/* number of keywords returned */{	char *v ;	int n ;	SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_RX,("list vpd keys .. ")) ;	*elements = 0 ;	if (!(pAC->vpd.v.vpd_status & VPD_VALID)) {		if (VpdInit(pAC,IoC) != 0 ) {			*len = 0 ;			SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,				("VPD Init Error, terminated\n")) ;			return(6) ;		}	}	if ((signed)strlen(VPD_NAME) + 1 <= *len) {		v = pAC->vpd.vpd_buf ;		strcpy(buf,VPD_NAME) ;		n = strlen(VPD_NAME) + 1 ;		buf += n ;		*elements = 1 ;		SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_RX,			("'%c%c' ",v[0],v[1])) ;	} else {		*len = 0 ;		SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,			("buffer overflow\n")) ;		return(2) ;	}	v += 3 + VPD_GET_RES_LEN(v) + 3 ;	for ( ; ; ) {		/* exit when reaching the "RW" Tag */		if (SK_MEMCMP(VPD_RW,v,2) == 0) {			break ;		}		if (SK_MEMCMP(VPD_RV,v,2) == 0) {			v += 3 + VPD_GET_VPD_LEN(v) + 3 ;	/* skip VPD-W */			continue ;		}		if (n+3 <= *len) {			SK_MEMCPY(buf,v,2) ;			buf += 2 ;			*buf++ = '\0' ;			n += 3 ;			v += 3 + VPD_GET_VPD_LEN(v) ;			*elements += 1 ;			SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_RX,				("'%c%c' ",v[0],v[1])) ;		} else {			*len = n ;			SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,				("buffer overflow\n")) ;			return (2) ;		}	}	SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_RX,("\n")) ;	*len = n ;	return(0) ;}/* *	Read the contents of the VPD EEPROM and copy it to the *	VPD buffer if not already done. Search for the VPD keyword *	'key' and copy its value to 'buf'. Add a terminating '\0'. *	If the value does not fit into the buffer cut it after *	'len' - 1 bytes. * * returns	0:	success *		1:	keyword not found *		2:	value string was cut *		3:	VPD transfer timeout *		6:	fatal VPD error */int		VpdRead(SK_AC		*pAC,	/* common data base */SK_IOC		IoC,	/* IO Context */char		*key,	/* keyword to read (e.g. "MN") */char		*buf,	/* buffer where to copy the keyword value */int		*len)	/* buffer length */{	SK_VPD_PARA *p, vp ;	SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_RX,("vpd read %s .. ",key)) ;	if (!(pAC->vpd.v.vpd_status & VPD_VALID)) {		if (VpdInit(pAC,IoC) != 0 ) {			*len = 0 ;			SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,				("vpd init error\n")) ;			return(6) ;		}	}	if ((p = vpd_find_para(pAC,key,&vp))) {		if (p->p_len > (*(unsigned *)len)-1) {			p->p_len = *len - 1 ;		}		SK_MEMCPY(buf,p->p_val,p->p_len) ;		buf[p->p_len] = '\0' ;		*len = p->p_len ;		SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_RX,			("%c%c%c%c.., len = %d\n",			buf[0],buf[1],buf[2],buf[3],*len)) ;	} else {		*len = 0 ;		SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,("not found\n")) ;		return (1) ;	}	return (0) ;}/* *	Check whether a given key may be written * * returns *	SK_TRUE		Yes it may be written *	SK_FALSE	No it may be written */SK_BOOL		VpdMayWrite(char		*key)	/* keyword to write (allowed values "Yx", "Vx") */{	if ((*key != 'Y' && *key != 'V') ||		key[1] < '0' || key[1] > 'Z' ||		(key[1] > '9' && key[1] < 'A') || strlen(key) != 2) {		return (SK_FALSE) ;	}	return (SK_TRUE) ;}/* *	Read the contents of the VPD EEPROM and copy it to the VPD *	buffer if not already done. Insert/overwrite the keyword 'key' *	in the VPD buffer. Cut the keyword value if it does not fit *	into the VPD read / write area. * * returns	0:	success *		2:	value string was cut *		3:	VPD transfer timeout *		4:	VPD full, keyword was not written *		5:	keyword cannot be written *		6:	fatal VPD error */int		VpdWrite(SK_AC		*pAC,	/* common data base */SK_IOC		IoC,	/* IO Context */char		*key,	/* keyword to write (allowed values "Yx", "Vx") */char		*buf)	/* buffer where the keyword value can be read from */{	int len ;			/* lenght of the keyword to write */	int rtv ;			/* return code */	int rtv2 ;	SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_TX,		("vpd write %s = %s\n",key,buf)) ;	if ((*key != 'Y' && *key != 'V') ||		key[1] < '0' || key[1] > 'Z' ||		(key[1] > '9' && key[1] < 'A') || strlen(key) != 2) {		SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,			("illegal key tag, keyword not written\n")) ;		return (5) ;	}	if (!(pAC->vpd.v.vpd_status & VPD_VALID)) {		if (VpdInit(pAC,IoC) != 0 ) {			SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,				("vpd init error\n")) ;			return(6) ;		}	}	rtv = 0 ;	len = strlen(buf) ;	if (len > VPD_MAX_LEN) {		/* cut it */		len = VPD_MAX_LEN ;		rtv = 2 ;		SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,			("keyword to long, cut after %d bytes\n",VPD_MAX_LEN)) ;	}	if ((rtv2 = VpdSetupPara(pAC,key,buf,len,VPD_RW_KEY,OWR_KEY)) != 0) {		SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,			("vpd write error\n")) ;		return(rtv2) ;	}	return (rtv) ;}/* *	Read the contents of the VPD EEPROM and copy it to the *	VPD buffer if not already done. Remove the VPD keyword *	'key' from the VPD buffer. *	Only the keywords in the read/write area can be deleted. *	Keywords in the read only area cannot be deleted. * * returns	0:	success, keyword was removed *		1:	keyword not found *		5:	keyword cannot be deleted *		6:	fatal VPD error */int		VpdDelete(SK_AC		*pAC,	/* common data base */SK_IOC		IoC,	/* IO Context */char		*key)	/* keyword to read (e.g. "MN") */{	SK_VPD_PARA *p, vp ;	char *etp ;	SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_TX,("vpd delete key %s\n",key)) ;	if (!(pAC->vpd.v.vpd_status & VPD_VALID)) {		if (VpdInit(pAC,IoC) != 0 ) {			SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,				("vpd init error\n")) ;			return(6) ;		}	}	if ((p = vpd_find_para(pAC,key,&vp))) {		if (p->p_val < pAC->vpd.vpd_buf + VPD_SIZE/2) {			/* try to delete read only keyword */			SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,				("cannot delete RO keyword\n")) ;			return (5) ;		}		etp = pAC->vpd.vpd_buf + (VPD_SIZE-pAC->vpd.v.vpd_free_rw-1-3) ;		vpd_move_para(vp.p_val+vp.p_len, etp+2,			- ((int)(vp.p_len + 3))) ;		if (vpd_mod_endtag(pAC, etp - vp.p_len - 3)) {			pAC->vpd.v.vpd_status &= ~VPD_VALID ;			SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,				("vpd encoding error\n")) ;			return(6) ;		}	} else {		SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,			("keyword not found\n")) ;		return (1) ;	}	return (0) ;}/* *	If the VPD buffer contains valid data write the VPD *	read/write area back to the VPD EEPROM. * * returns	0:	success *		3:	VPD transfer timeout */int		VpdUpdate(SK_AC		*pAC,	/* Adapters context */SK_IOC		IoC)	/* IO Context */{	SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_TX,("vpd update .. ")) ;	if (pAC->vpd.v.vpd_status & VPD_VALID) {		if (VpdTransferBlock(pAC,IoC,pAC->vpd.vpd_buf + VPD_SIZE/2,			VPD_SIZE/2, VPD_SIZE/2, VPD_WRITE) != VPD_SIZE/2) {			SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,				("transfer timed out\n")) ;			return(3) ;		}	}	SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_TX,("done\n")) ;	return (0) ;}/* *	Read the contents of the VPD EEPROM and copy it to the VPD buffer *	if not already done. If the keyword "VF" is not present it will be *	created and the error log message will be stored to this keyword. *	If "VF" is not present the error log message will be stored to the *	keyword "VL". "VL" will created or overwritten if "VF" is present. *	The VPD read/write area is saved to the VPD EEPROM. * * returns nothing, errors will be ignored. */void		VpdErrLog(SK_AC		*pAC,	/* common data base */SK_IOC		IoC,	/* IO Context */char		*msg)	/* error log message */{	SK_VPD_PARA *v, vf ;	/* VF */	int len ;	SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_TX,		("vpd error log msg %s\n",msg)) ;	if (!(pAC->vpd.v.vpd_status & VPD_VALID)) {		if (VpdInit(pAC,IoC) != 0 ) {			SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,				("vpd init error\n")) ;			return ;		}	}	len = strlen(msg) ;	if (len > VPD_MAX_LEN) {		/* cut it */		len = VPD_MAX_LEN ;	}	if ((v = vpd_find_para(pAC,VPD_VF,&vf))) {		SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_TX,("overwrite VL\n")) ;		(void)VpdSetupPara(pAC,VPD_VL,msg,len,VPD_RW_KEY,OWR_KEY) ;	} else {		SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_TX,("write VF\n")) ;		(void)VpdSetupPara(pAC,VPD_VF,msg,len,VPD_RW_KEY,ADD_KEY) ;	}	(void)VpdUpdate(pAC,IoC) ;}

⌨️ 快捷键说明

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