Let say I have a structure of disk_info with members devname & devno. And I have created linked list of the same. Now I want to convert this linked list to contiguous memory so as to easily pass the data to kernel through ioctl. And at the kernel side I want to again read the contiguous memory & convert to array Basically I want to convert linked list- array-linked list.
struct blkext_node {
dev_t devno;
char devname[32];
};
typedef struct blkext_disk_info {
struct blkext_node blkext_device;
struct blkext_disk_info *next;
} blkext_disk_info_t;
ptr1 = head_list
// Allocate the contiguous memory where total_cnt is the no of nodes in linked list
ioctl_ptr = (struct blkext_node *)malloc(total_cnt*sizeof(struct blkext_node));
for(i=0; i<total_cnt; i++) {
if(ptr1!=NULL) {
memcpy(ioctl_ptr + i, ptr1, sizeof(struct blkext_node));
ptr1=ptr1->next;
} else
break;
}
This is the final working code.