I use vmalloc to allocate a contiguous virtual memory block. I then set all the bytes of this block to 0 by using memset. I then, fill this memory region with a data structure that I created that is 16 bytes in size.
Then, during one of my functions, I place a pointer to one of these structures, and begin to walk down the memory region to find the first 0 byte so that I can place another data structure here. My first pointer correctly gets the previously placed structure, and I can see the address. This is the printout:
point’s filename / //Filename
ffffc9001095b500 //Address
That is the correct memory region for this structure (since I placed it here).
I then increment my pointer, which should take me to memory region ffffc9001095b510,
but instead my pointer comes back with an address of NULL. Why is this?
Here’s the code:
void * check_aux(char * upPath, int index, int location){
struct directory * point;
int i = 0;
int dirnum = 0;
//int lastaddr;
printk("Inside check_aux\n");
if(location > 117){
return NULL;
}
else if(upPath == NULL){
return NULL;
}
else{
point = getLocation(index, location);
printk("This is point's filename %s\n%p\n", point->filename, point);
while(point != NULL && dirnum < 16){
while(point->filename[i] == upPath[i] || (point->filename[i] == 0 && (upPath[i] =='/' || upPath[i] == 0))){
printk("%c == %c\n", point->filename[i], upPath[i]);
if(point->filename[i] == 0 && upPath[i] == 0){
return NULL;
}
else if(point->filename[i] == 0 && upPath[i] == '/'){
if(nodes[point->index].type[0] == 'd'){
return check_aux(&upPath[i+1], point->index, 0);
}
else{
return NULL;
}
}
else{
i++;
}
}
dirnum++;
(point++);
}
if(dirnum == 16){
return check_aux(upPath, index, location+1);
}
printk("Returning point %p\n", point);
return point;
}
}
The data struct is defined as
struct directory{
char filename[14];
short index;
};
And filename cannot start with 0.
You leave the loop in 2 cases:
All other return statements return NULL, too.