How to print block of data
By Crifan Li
Date: 05.19 2008
/* print the buf data */
printk(KERN_WARNING "n%s : The buf=0x%p ,data is:n",__FUNCTION__, buf);
for(j = 0;j < 512; j+=4) /* total print one page=2048 bytes */
{
printk(KERN_WARNING "%08x ",*((u32 *)(buf+j)) );
/* after the first data , should not do n, then the whole block of data should do n every 32bytes */
if(j!=0 && 0 == (j+4)%32)
printk(KERN_WARNING "n");
}
printk(KERN_WARNING "n");
so above can change to this new version :
#define BYTES_PER_DATA 4
#define DATAS_PER_LINE 8
#define BYTES_PER_LINE ((BYTES_PER_DATA)*(DATAS_PER_LINE))
#define TOTAL_BYTES 2048
#define DATAS ((TOTAL_BYTES)/( BYTES_PER_DATA))
/* print the buf data */
printk(KERN_WARNING "nFUNC:%s LINE:%: The buf=0x%p ,data is:n",__FUNCTION__, __LINE__. buf);
for(j = 0;j < DATAS; j+= BYTES_PER_DATA) /* total print one page=2048 bytes */
{
printk(KERN_WARNING "%08x ",*((u32 *)(buf+j)) );
/* after the first data , should not do n */
/* if the end of every line , then do n */
if(j!=0 && 0 == (j+ BYTES_PER_DATA)% BYTES_PER_LINE)
printk(KERN_WARNING "n");
}
printk(KERN_WARNING "n");
转载请注明:在路上 » How to print block of data