Exemplo n.º 1
0
void fs_init(FileSystem *fs) {
    fs->stor = (Storage *) malloc(sizeof(Storage));
    fs->stor->c = malloc(sizeof(char) * NUM_SECTORS() * 256);
    fs->freelist = freelist_new(fs);
    fs->cur = fs_load_inode(fs, ROOT_PAGE_NUM());
    fs->ninode = 0;
}
Exemplo n.º 2
0
ISODirectoryRecord *findEntryInCache(const char *name, int nameLen) {
	int i;
	CdRMode rmode = { 16, 0, CdSect2048, 0 };
	ISODirectoryRecord *entry;
	for (i = 0; i < NUM_SECTORS(cachedDirSize); i++) {
		entry = (ISODirectoryRecord *)cacheBuf;
		if (i != cachedDirOfs) {
			if (cdReadSectors(cachedDirLba + i, 1, cacheBuf, &rmode) < 0)
				return NULL;
			cachedDirOfs = i;
		}

		while (entry->len_dr && ((uint8 *)entry < cacheBuf + SECTOR_SIZE)) {
			if ((entry->len_fi > 2) && (entry->name[entry->len_fi - 2] == ';') && (entry->name[entry->len_fi - 1] == '1')) {
				if ((nameLen == entry->len_fi - 2) && (strnicmp(name, entry->name, entry->len_fi - 2) == 0))
					return entry;
			} else {
				if ((nameLen == entry->len_fi) && (strnicmp(name, entry->name, entry->len_fi) == 0))
					return entry;
			}
			entry = (ISODirectoryRecord *)( (uint8 *)entry + entry->len_dr );
		}
	}
	return NULL;
}
Exemplo n.º 3
0
Freelist* freelist_new(FileSystem *fs) {
    Freelist *freelist = NULL;
    int sec = 0;
    int islot = 0;
    
    freelist = (Freelist *) malloc(sizeof(Freelist));
    freelist->fs = fs;
    freelist->max_page_num = -1;
    freelist->nslot = 0;
    for (sec = 0; sec < NUM_SECTORS(); ++sec) {
        if (storage_readchar(fs->stor, sec / 256, sec % 256)) {
            freelist->max_page_num = sec;
        } else {
            freelist->nslot++;
        }
    }
    freelist->slots = (int *) malloc(sizeof(int) * (freelist->nslot + 1));
    for (sec = 0; sec < NUM_SECTORS(); ++sec) {
        if (!storage_readchar(fs->stor, sec / 256, sec % 256)) {
            freelist->slots[islot++] = sec;
        }
    }
    return freelist;
}
Exemplo n.º 4
0
void freelist_free(Freelist *freelist) {
    if (freelist) {
        int sec = 0;
        
        for (sec = 0; sec < NUM_SECTORS(); ++sec) {
            if (sec > freelist->max_page_num) {
                storage_writechar(freelist->fs->stor, sec / 256, sec % 256, 0);
            } else if (in_freelist(sec, freelist)) {
                storage_writechar(freelist->fs->stor, sec / 256, sec % 256, 0);
            } else {
                storage_writechar(freelist->fs->stor, sec / 256, sec % 256, 1);
            }
        }
        free(freelist->slots);
        free(freelist);
    }
}
Exemplo n.º 5
0
int FREELIST_NSEC() {
    return NUM_SECTORS() / 256;
}