Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect inode number emitted from nova_readdir_fast #147

Open
iaoing opened this issue Dec 22, 2023 · 0 comments
Open

Incorrect inode number emitted from nova_readdir_fast #147

iaoing opened this issue Dec 22, 2023 · 0 comments

Comments

@iaoing
Copy link
Contributor

iaoing commented Dec 22, 2023

Issue

The inode number is incorrect when readdir.

Reproduce

The blow C code is used to read the directory and print out the d_ino.

#include <dirent.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <limits.h>

void print_dirents(DIR * dir){
    struct dirent *entry;
    while ( (entry=readdir(dir)) != NULL ){
        printf("%s, %ld\n", entry->d_name, entry->d_ino);
    }
}

int main(int argc, char **argv){
    if (argc != 2) {
        printf("usgae: execuable [path]\n");
        return 0;
    }

    char *dir_name = argv[1];
    DIR *dir;

    dir = opendir(dir_name);
    print_dirents(dir);
    closedir(dir);

    return 0;
}
sudo insmod nova.ko
sudo mount -t NOVA -o init,dbgmask=255 /dev/pmem0 /mnt/pmem0
sudo mkdir /mnt/pmem/dir
# assuming the executable C code is a.out
./a.out /mnt/pmem0
# the output is:
# ., 1
# .., 33
# dir, 33
# The syslog shows the inode number for the `..` file and the `dir` entry is correct.

Reason

linux-nova/fs/nova/dir.c

Lines 708 to 713 in 976a4d1

if (prev_entry && !dir_emit(ctx, prev_entryc->name,
prev_entryc->name_len, ino,
IF2DT(le16_to_cpu(prev_child_pi->i_mode)))) {
nova_dbgv("Here: pos %llu\n", ctx->pos);
return 0;
}

linux-nova/fs/nova/dir.c

Lines 728 to 731 in 976a4d1

if (prev_entry && !dir_emit(ctx, prev_entryc->name,
prev_entryc->name_len, ino,
IF2DT(le16_to_cpu(prev_child_pi->i_mode))))
return 0;

In the above code snippet, the inode number passed to dir_emit is incorrect. It should be prev_entryc->ino rather than ino. This explains why the .. file's inode is 33 and dir's inode is still 33.

Fix

Simply modify the ino as prev_entryc->ino as the below code shows.

 // dir.c#L708-L713
 if (prev_entry && !dir_emit(ctx, prev_entryc->name, 
 	prev_entryc->name_len, prev_entryc->ino, 
 	IF2DT(le16_to_cpu(prev_child_pi->i_mode)))) { 
 	nova_dbgv("Here: pos %llu\n", ctx->pos); 
 	return 0; 
 } 

// dir.c#L728-L731
 if (prev_entry && !dir_emit(ctx, prev_entryc->name, 
 		prev_entryc->name_len, prev_entryc->ino, 
 		IF2DT(le16_to_cpu(prev_child_pi->i_mode)))) 
 	return 0; 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant