mirrorfs.c
// TODO: incomplete; compare against dir2fd.  how to handle different directory
// orders?
incomplete; compare against dir2fd.
incomplete ; compare against dir2fd .
static int mirrorfs_readdir(const char *path, void *buf,
                            fuse_fill_dir_t filler, off_t offset,
                            struct fuse_file_info *fi,
                            enum fuse_readdir_flags flags)
{
    LOG_FUSE_OPERATION("%s %ld 0x%x", path, offset, flags);
    struct dirent *de;
    int dir1fd = openat(mntfd1, safe_path(path), O_DIRECTORY);
    int dir2fd = openat(mntfd2, safe_path(path), O_DIRECTORY);
    ABORT_IF_INCONSISTENT_FD(dir1fd, dir2fd);
    DIR *dp1 = fdopendir(dir1fd);
    DIR *dp2 = fdopendir(dir2fd);
    if (dp1 == NULL || dp2 == NULL) {
        return -errno;
    }
    while ((de = readdir(dp1)) != NULL) {
        struct stat st;
        memset(&st, 0, sizeof(st));
        st.st_ino = de->d_ino;
        st.st_mode = de->d_type << 12;
        if (filler(buf, de->d_name, &st, 0, 0)) {
            break;
        }
    }
    closedir(dp1);
    closedir(dp2);
    close(dir1fd);
    close(dir2fd);
    return 0;
}
static int mirrorfs_readdir ( const char * path , void * buf , fuse_fill_dir_t filler , off_t offset , struct fuse_file_info * fi , enum fuse_readdir_flags flags ) { LOG_FUSE_OPERATION ( " " , path , offset , flags ) ; struct dirent * de ; int dir1fd = openat ( mntfd1 , safe_path ( path ) , O_DIRECTORY ) ; int dir2fd = openat ( mntfd2 , safe_path ( path ) , O_DIRECTORY ) ; ABORT_IF_INCONSISTENT_FD ( dir1fd , dir2fd ) ; DIR * dp1 = fdopendir ( dir1fd ) ; DIR * dp2 = fdopendir ( dir2fd ) ; if ( dp1 == NULL || dp2 == NULL ) { return - errno ; } while ( ( de = readdir ( dp1 ) ) != NULL ) { struct stat st ; memset ( & st , 0 , sizeof ( st ) ) ; st . st_ino = de -> d_ino ; st . st_mode = de -> d_type << 12 ; if ( filler ( buf , de -> d_name , & st , 0 , 0 ) ) { break ; } } closedir ( dp1 ) ; closedir ( dp2 ) ; close ( dir1fd ) ; close ( dir2fd ) ; return 0 ; }
TODO: incomplete; compare against dir2fd.
TODO : incomplete ; compare against dir2fd .