static void init_fs(){ /* u8 fsbuf[SECTOR_SIZE]; */ MESSAGE message; message.type=INFO_FS_DEVICE; message.device=ROOT_DEVICE; assert(dd_map[DRIVER(ROOT_DEVICE)].driver_pid!=PID_INVALID,""); send_receive(BOTH,dd_map[DRIVER(ROOT_DEVICE)].driver_pid,&message); //如果系统已经是要求的系统,就不需要在格式化系统了 get_super_block(ROOT_DEVICE,&super_block); /* if(super_block.magic!=MAGIC_V1) */{ mkfs(); get_super_block(ROOT_DEVICE,&super_block); } init_inode_table(); init_file_descriptor_table(); #ifdef DEBUG_FS //write test /* memset(fsbuf,0x23,SECTOR_SIZE); */ /* WRITE_SECTOR(ROOT_DEVICE,fsbuf,1); */ //read test u8 fsbuf[SECTOR_SIZE]; READ_SECTOR(ROOT_DEVICE,fsbuf,1); printl("read test:\nfsbuf[0]=%x fsbuf[1]=%x fsbuf[2]=%x fsbuf[3]=%x\n",fsbuf[0],fsbuf[1],fsbuf[2],fsbuf[3]); #endif }
//--------------------------------------------------------------------------- static int part_getPartitionTable(mass_dev* dev, part_table* part) { part_raw_record* part_raw; int ret; unsigned int i; unsigned char* sbuf; ret = READ_SECTOR(dev, 0, sbuf); // read sector 0 - Disk MBR or boot sector if ( ret < 0 ) { XPRINTF("USBHDFSD: part_getPartitionTable read failed %d!\n", ret); return -EIO; } printf("USBHDFSD: boot signature %X %X\n", sbuf[0x1FE], sbuf[0x1FF]); if (sbuf[0x1FE] == 0x55 && sbuf[0x1FF] == 0xAA) { for ( i = 0; i < 4; i++) { part_raw = ( part_raw_record* )( sbuf + 0x01BE + ( i * 16 ) ); part_getPartitionRecord(part_raw, &part->record[i]); } return 4; } else { for ( i = 0; i < 4; i++) { part->record[i].sid = 0;; } return 0; } }
//--------------------------------------------------------------------------- int scache_readSector(cache_set* cache, unsigned int sector, void** buf) { int index; //index is given in single sectors not octal sectors int ret; unsigned int alignedSector; XPRINTF("cache: readSector devId = %i %p sector = %u \n", cache->dev->devId, cache, sector); if (cache == NULL) { printf("cache: devId cache not created = %i \n", cache->dev->devId); return -1; } #ifdef SCACHE_RECORD_STATS cache->cacheAccess ++; #endif index = getIndexRead(cache, sector); XPRINTF("cache: indexRead=%i \n", index); if (index >= 0) { //sector found in cache #ifdef SCACHE_RECORD_STATS cache->cacheHits ++; #endif *buf = cache->sectorBuf + (index * cache->sectorSize); XPRINTF("cache: hit and done reading sector \n"); return cache->sectorSize; } //compute alignedSector - to prevent storage of duplicit sectors in slots alignedSector = (sector/cache->indexLimit)*cache->indexLimit; index = getIndexWrite(cache, alignedSector); XPRINTF("cache: indexWrite=%i slot=%d alignedSector=%u\n", index, index / cache->indexLimit, alignedSector); ret = READ_SECTOR(cache->dev, alignedSector, cache->sectorBuf + (index * cache->sectorSize), BLOCK_SIZE/cache->sectorSize); if (ret < 0) { printf("scache: ERROR reading sector from disk! sector=%u\n", alignedSector); return ret; } *buf = cache->sectorBuf + (index * cache->sectorSize) + ((sector%cache->indexLimit) * cache->sectorSize); XPRINTF("cache: done reading physical sector \n"); //write precaution //cache->flushCounter++; //if (cache->flushCounter == FLUSH_TRIGGER) { //scache_flushSectors(cache); //} return cache->sectorSize; }