/*---------------------------------------------------------------------------*/ static int32_t find_file(const char *name) { struct file_header hdr; int32_t page; page = dir_cache_find(name); if(page >= 0) { return page; } page = 0; do { READ_HEADER(&hdr, page); if(COFFEE_PAGE_ACTIVE(hdr)) { if(strcmp(name, hdr.name) == 0) { dir_cache_add(name[0], page); return page; } page += hdr.max_pages; } else if(COFFEE_PAGE_ISOLATED(hdr)) { ++page; } else if(COFFEE_PAGE_OBSOLETE(hdr)) { page += hdr.max_pages; } else { /* It follows from the properties of the page allocation algorithm that if a free page is encountered, then the rest of the sector is also free. */ page = (page + COFFEE_PAGES_PER_SECTOR) & ~(COFFEE_PAGES_PER_SECTOR - 1); } watchdog_periodic(); } while(page < COFFEE_PAGE_COUNT); return -1; }
int ppfs_readdir (const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi){ fprintf(stderr, "ppfs_readdir path : %s\n", path); (void) offset; (void) fi; dir_cache* dc; if(lookup_dir_cache(path,&dc) == 0){ fprintf(stderr,"f*****g dir_cache\n"); int i; for(i=0;i<dc->n;++i) { filler(buf, dc->entries[i], NULL, 0); } return 0; } ppacket *s = createpacket_s(4+strlen(path)+4, CLTOMD_READDIR,-1); uint8_t* ptr = s->startptr+HEADER_LEN; put32bit(&ptr, strlen(path)); memcpy(ptr, path, strlen(path)); ptr+=strlen(path); put32bit(&ptr, offset); sendpacket(fd, s); free(s); s = receivepacket(fd); const uint8_t* ptr2 = s->startptr; int status = get32bit(&ptr2); if(status == 0){ int nfiles = get32bit(&ptr2); int i; char** files = malloc(sizeof(char*)*nfiles); for(i=0;i<nfiles;++i) { int flen = get32bit(&ptr2); char * fn = (char*)malloc(flen*sizeof(char)+1); memcpy(fn, ptr2, flen); fn[flen] = 0; ptr2 += flen; filler(buf, fn, NULL, 0); files[i] = fn; } dir_cache_add(path,files,nfiles); for(i=0;i<nfiles;i++){ free(files[i]); } free(files); } else { if(status == -ENOENT){ fprintf(stderr,"\tENOENT\n"); } if(status == -ENOTDIR){ fprintf(stderr,"\tENOTDIR\n"); } } free(s); return 0; }