10/26/2016

insmod: ERROR: could not insert module / Invalid module format

Build kernel with this config off and feel free to load new kernel module without recompiling kernel
# CONFIG_MODULE_FORCE_UNLOAD is not set
# CONFIG_MODVERSIONS is not set
# CONFIG_MODULE_SRCVERSION_ALL is not set
# CONFIG_MODULE_SIG is not set
# CONFIG_MODULE_COMPRESS is not set
Download this Kernel_build.config

12/13/2015

Mount QCOW2 image

QCOW_IMG=$1
NBD_DEV=/dev/nbd0

modprobe nbd
qemu-nbd -c $NBD_DEV $QCOW_IMG

#Find start byte (offset) of a partition
parted $NBD_DEV -s unit B print

#Associate that offset with a loop dev
losetup -o 525336576 -f /dev/nbd0
#Mount loop device to a directory

7/13/2015

gdb: source indicator goes out of order

Problems:
If program is compiled with option "-O2", gdb might not recognize order of source lines correctly and the current statement  would point to incorrect line.

Solution:
Change "-O2" to "-O0"

http://www.linuxquestions.org/questions/programming-9/gdb-doesn%27t-provide-the-correct-line-in-the-source-code-858155/

1/30/2015

Dual boot: windows 7 & centos

menuentry "Windows 7" {
	set root=(hd0,1)
	chainloader +1
}
grub2-mkconfig -o /boot/grub2/grub.cfg

12/07/2014

C pointer variable

What is the difference between int* n and int *n

If int *n, that is a fallacy that there are 2 type of variables. In fact, variable is a place holder of data only, the variant is the type of data it holds.

int is data structure of 4 bytes while int* is the one of 8 bytes (for 64 bit system).


#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
#include <errno.h>
#include <string.h>

int main(int argc, char* argv[]){
 int fd = socket(AF_INET, SOCK_DGRAM, 0);
 unsigned int zero = 300;
 
 // building address structure 
 struct in_addr* ipaddr = malloc(sizeof(struct in_addr));
 if(ipaddr == NULL){
  perror(strerror(errno));
 }

 zero = *((unsigned int*)ipaddr);
 printf("size of struct in_addr*: %d\n", sizeof(struct in_addr*));
 printf("size of int*: %d\n",sizeof(int*));
 printf("%x\n",zero);
 printf("ipaddr = %x",*((int*)(ipaddr)));
 
 return 0;
}