예제 #1
0
파일: scache.c 프로젝트: AzagraMac/PS2_SDK
/*
	flush dirty sectors
 */
int scache_flushSectors(cache_set* cache) {
	int i,ret;
	int counter = 0;

	XPRINTF("cache: flushSectors devId = %i \n", cache->dev->devId);

	//cache->flushCounter = 0;

	XPRINTF("scache: flushSectors writeFlag=%d\n", cache->writeFlag);
	//no write operation occured since last flush
	if (cache->writeFlag==0) {
		return 0;
	}

	for (i = 0; i < CACHE_SIZE; i++) {
		if (cache->rec[i].writeDirty) {
			XPRINTF("scache: flushSectors dirty index=%d sector=%d \n", i, cache->rec[i].sector);
			ret = WRITE_SECTOR(cache->dev, cache->rec[i].sector, cache->sectorBuf + (i * BLOCK_SIZE), BLOCK_SIZE);
			cache->rec[i].writeDirty = 0;
			//TODO - error handling
			if (ret < 0) {
				printf("scache: ERROR writing sector to disk! sector=%d\n", cache->rec[i].sector);
				return ret;
			}
			counter ++;
		}
	}
	cache->writeFlag = 0;
	return counter;
}
예제 #2
0
파일: fs.c 프로젝트: 565407548/micro_os
static void init_data_block(int data_block_first_index){
    int dir_entry_index;
    u8 fsbuf[SECTOR_SIZE];
    memset(fsbuf,0,SECTOR_SIZE);
    
    dir_entry_index=0;
    DIR_ENTRY *dir_entry=((DIR_ENTRY*)fsbuf)+dir_entry_index;
    dir_entry->inode_index=ROOT_DIR_INODE_INDEX;
    strcpy(dir_entry->name,".");
#ifdef DEBUG_FS
    printl("dir_name=%s inode_index=%d\n",dir_entry->name,*(int *)fsbuf);
#endif

    for(dir_entry_index=1;dir_entry_index<=NR_CONSOLES;dir_entry_index++){
        dir_entry=((DIR_ENTRY*)fsbuf)+dir_entry_index; 
        dir_entry->inode_index=ROOT_DIR_INODE_INDEX+dir_entry_index;
        sprintf(dir_entry->name,"dev_tty%d",dir_entry_index-1);
#ifdef DEBUG_FS
        printl("dir_name=%s\n",dir_entry->name);
#endif
    }

#ifdef DEBUG_FS
    printl("fsbuf[0]=%d fsbuf[1]=%d fsbuf[2]=%d fsbuf[3]=%d\n",*(int*)(fsbuf),*(int*)(fsbuf+16),*(int*)(fsbuf+32),*(int*)(fsbuf+48));
#endif

    WRITE_SECTOR(ROOT_DEVICE,fsbuf,data_block_first_index);
}
예제 #3
0
파일: scache.c 프로젝트: AzagraMac/PS2_SDK
/* select the best record where to store new sector */
int getIndexWrite(cache_set* cache, unsigned int sector) {
	int i, ret;
	int minTax = 0x0FFFFFFF;
	int index = 0;

	for (i = 0; i < CACHE_SIZE; i++) {
		if (cache->rec[i].tax < minTax) {
			index = i;
			minTax = cache->rec[i].tax;
		}
	}

	//this sector is dirty - we need to flush it first
	if (cache->rec[index].writeDirty) {
		XPRINTF("scache: getIndexWrite: sector is dirty : %d   index=%d \n", cache->rec[index].sector, index);
		ret = WRITE_SECTOR(cache->dev, cache->rec[index].sector, cache->sectorBuf + (index * BLOCK_SIZE), BLOCK_SIZE);
		cache->rec[index].writeDirty = 0;
		//TODO - error handling
		if (ret < 0) {
			printf("scache: ERROR writing sector to disk! sector=%d\n", sector);
		}

	}
	cache->rec[index].tax +=2;
	cache->rec[index].sector = sector;

	return index * cache->indexLimit;
}
예제 #4
0
파일: fs.c 프로젝트: 565407548/micro_os
static void init_inode(int inode_first_index,int root_dir_start_index){
    int inode_index;
    u8 fsbuf[SECTOR_SIZE];

    memset(fsbuf,0,SECTOR_SIZE);
    INODE *pinode=NULL;
    
    inode_index=1;// inode_index=1:.;inode_index=0:reserved
    pinode=(INODE*)(fsbuf+inode_index*INODE_SIZE);
    pinode->i_mode=I_DIRECTORY;
    pinode->i_size=DIR_ENTRY_SIZE*4;//.,dev_tty0,dev_tty1,dev_tty2
    pinode->i_start_sector_index=root_dir_start_index;
    //pinode->i_sectors_length=DEFAULT_FILE_SECTOR_LENGTH*(1+NR_CONSOLES);
    pinode->i_sectors_length=DEFAULT_FILE_SECTOR_LENGTH;
    assert(inode_index==ROOT_DIR_INODE_INDEX,"");    

    for(inode_index=2;inode_index<2+NR_CONSOLES;inode_index++){
        pinode=(INODE*)(fsbuf+inode_index*INODE_SIZE);
        pinode->i_mode=I_CHAR_SPECIAL;
        pinode->i_size=0;
        pinode->i_start_sector_index=MAKE_DRIVER_DEVICE(DRIVER_TTY,inode_index-2);
        pinode->i_sectors_length=0;
    }
    WRITE_SECTOR(ROOT_DEVICE,fsbuf,inode_first_index);
}
예제 #5
0
파일: fs.c 프로젝트: 565407548/micro_os
static void init_super_block(SUPER_BLOCK *sb,int super_block_first_index,int part_size){
    u8 fsbuf[SECTOR_SIZE];
    sb->magic=MAGIC_V1;
    sb->inodes_length=BITS_PER_SECTOR;
    sb->inodes_sectors_length=(sb->inodes_length*INODE_SIZE+SECTOR_SIZE-1)/SECTOR_SIZE;
    sb->sectors_length=part_size;
    sb->imap_sectors_length=sb->inodes_length/(SECTOR_SIZE*BITS_PER_BYTE);
    sb->smap_sectors_length=sb->sectors_length/BITS_PER_SECTOR+1;
    sb->data_first_sector_index=BOOT_SECTORS_LENGTH+SUPER_SECTORS_LENGTH+sb->imap_sectors_length+sb->smap_sectors_length+sb->inodes_sectors_length;
    sb->root_dir_inode_index=ROOT_DIR_INODE_INDEX;
    INODE inode;
    sb->inode_size=INODE_SIZE;
    sb->inode_isize_off=(int)&inode.i_size-(int)&inode;
    sb->inode_start_off=(int)&inode.i_start_sector_index-(int)&inode;
    DIR_ENTRY dir_entry;
    sb->dir_entry_size=DIR_ENTRY_SIZE;
    sb->dir_entry_inode_off=(int)&dir_entry.inode_index-(int)&dir_entry;
    sb->dir_entry_fname_off=(int)&dir_entry.name-(int)&dir_entry;

    memset(fsbuf,0x80,SECTOR_SIZE);
    memcpy(fsbuf,sb,SUPER_BLOCK_SIZE);

#ifdef DEBUG_FS
    printl("super_block_first_index=%d fsbuf[0]=%d\n",super_block_first_index,*(int*)fsbuf);
#endif
    WRITE_SECTOR(ROOT_DEVICE,fsbuf,super_block_first_index);
}
예제 #6
0
파일: fs.c 프로젝트: 565407548/micro_os
static void init_imap(int imap_first_index,int imap_sectors_length){
    int bit_index,sector_index;
    u8 fsbuf[SECTOR_SIZE];

    memset(fsbuf,0,SECTOR_SIZE);
    sector_index=0;
    //0:reserved;1:/;2:tty0;3:tty1;4:tty2
    for(bit_index=0;bit_index<(NR_CONSOLES+2);bit_index++){
        fsbuf[0]|=1<<bit_index;
    }
    assert(fsbuf[0]==0x1F,"");
#ifdef DEBUG_FS
    printl("imap_first_index=%d fsbuf[0]=%d\n",imap_first_index,*(int*)fsbuf);
#endif
    WRITE_SECTOR(ROOT_DEVICE,fsbuf,imap_first_index+sector_index);

    memset(fsbuf,0,SECTOR_SIZE);
    for(sector_index=1;sector_index<imap_sectors_length;sector_index++){
        WRITE_SECTOR(ROOT_DEVICE,fsbuf,imap_first_index+sector_index);
    }
}
예제 #7
0
파일: fs.c 프로젝트: 565407548/micro_os
static void init_smap(int smap_first_index,int smap_sectors_length){
    int byte_index,bit_index,sector_index;
    //[0,1):reserved;[1,DEFAULT_FILE_SECTOR_LENGTH):(for root directory);
    int sectors_length=DEFAULT_FILE_SECTOR_LENGTH+1;
    u8 fsbuf[SECTOR_SIZE];

    memset(fsbuf,0,SECTOR_SIZE);
    sector_index=0;
    for(byte_index=0;byte_index<sectors_length/BITS_PER_BYTE;byte_index++){
        fsbuf[byte_index]=0xFF;
    }
    for(bit_index=0;bit_index<sectors_length%BITS_PER_BYTE;bit_index++){
        fsbuf[byte_index]|=(1<<bit_index);
    }
#ifdef DEBUG_FS
    printl("smap_first_index=%d fsbuf[0]=%d\n",smap_first_index,*(int*)fsbuf);
#endif
    WRITE_SECTOR(ROOT_DEVICE,fsbuf,smap_first_index+sector_index);
    
    memset(fsbuf,0,SECTOR_SIZE);
    for(sector_index=1;sector_index<smap_sectors_length;sector_index++){
        WRITE_SECTOR(ROOT_DEVICE,fsbuf,smap_first_index+sector_index);
    }
}
예제 #8
0
파일: scache.c 프로젝트: ps2dev/ps2sdk
/*
	flush dirty sectors
 */
static int scache_flushSector(cache_set* cache, int index) {
	int ret;

	if (cache->rec[index].writeDirty) {
		XPRINTF("scache: flushSector dirty index=%d sector=%u \n", index, cache->rec[index].sector);
		ret = WRITE_SECTOR(cache->dev, cache->rec[index].sector, cache->sectorBuf + (index * BLOCK_SIZE), BLOCK_SIZE/cache->sectorSize);
		if (ret < 0) {
			printf("scache: ERROR writing sector to disk! sector=%u\n", cache->rec[index].sector);
			return ret;
		}

		cache->rec[index].writeDirty = 0;
	}
	return 1;
}