Пример #1
0
void * get_rootdirfile_blk(device_t * devp)
{
    void * retptr = NULL;
    rfsdir_t * rtdir = get_rootdir(devp);
    if(!rtdir)
    {
	printfk("get_rootdir failed\n\r");
	return NULL;
    }
    void * buf = new_buf(FSYS_ALCBLKSZ);
    if(!buf)
    {
	printfk("new_buf failed\n\r");
	retptr = NULL;
	goto err2;
    }
    hal_memset(buf, FSYS_ALCBLKSZ, 0);
    if(read_rfsdevblk(devp, buf, rtdir->rdr_blknr) == DFCERRSTUS)
    {
	printfk("read_rfsdevblk failed\n\r");
	retptr = NULL;
	goto err1;
    }
    retptr = buf;
    goto err2;

err1:
    del_buf(buf, FSYS_ALCBLKSZ);
err2:
    del_rootdir(devp, rtdir);
    return retptr;
}
Пример #2
0
void chk_rfsbitmap(device_t * devp)
{
    void * buf = new_buf(FSYS_ALCBLKSZ);
    if(buf == NULL)
    {
	printfk("alloc buf failed\n\r");
	return;
    }
    hal_memset(buf, FSYS_ALCBLKSZ, 0);
    if(read_rfsdevblk(devp, buf, 1) == DFCERRSTUS)
    {
	hal_sysdie("chkbitmap err1\n\r");
    }
    
    u8_t * bmp = (u8_t *)buf;
    uint_t b = 0;
    for(uint_t i = 0; i<FSYS_ALCBLKSZ; i++)
    {
	if(bmp[i] == 0)
	{
	    b++;
	}
    }

    printfk("chk bmp b:%x\n\r", b);
    del_buf(buf, FSYS_ALCBLKSZ);
    return;
}
Пример #3
0
drvstus_t rfs_closefileblk(device_t * devp, void * fblkp)
{
    fimgrhd_t * fmp = (fimgrhd_t *)fblkp;
    write_rfsdevblk(devp, fblkp, fmp->fmd_sfblk);
    del_buf(fblkp, FSYS_ALCBLKSZ);
    return DFCOKSTUS;
}
Пример #4
0
void del_superblk(device_t * devp, rfssublk_t * sbp)
{
    if(write_rfsdevblk(devp, (void *)sbp, 0) == DFCERRSTUS)
    {
	hal_sysdie("del superblk err\n\r");
    }
    del_buf((void *)sbp, FSYS_ALCBLKSZ);
    return;
}
Пример #5
0
void del_rootdirfile_blk(device_t * devp, void *blkp)
{
    fimgrhd_t * fmp = (fimgrhd_t *)blkp;
    if(write_rfsdevblk(devp, blkp, fmp->fmd_sfblk) == DFCERRSTUS)
    {
	hal_sysdie("del_rootfile_blk err");
    }
    del_buf(blkp, FSYS_ALCBLKSZ);
    return;
}
Пример #6
0
bool_t create_rootdir(device_t * devp)
{
    printfk("%s in \n\r", __func__);
    bool_t rets = FALSE;
    rfssublk_t * sbp = get_superblk(devp);
    if(!sbp)
    {
	printfk("%s get_superblk failed\n\r");
	return FALSE;
    }

    void * buf = new_buf(FSYS_ALCBLKSZ);
    if(!buf)
    {
	rets = FALSE;
	goto errlable1;
    }
    hal_memset(buf, FSYS_ALCBLKSZ, 0);
    uint_t blk = rfs_new_blk(devp);
    if(blk == 0)
    {
	rets = FALSE;
	printfk("%s rfs_new_blk failed\n\r");
	goto errlable;
    }

    sbp->rsb_rootdir.rdr_name[0] = '/';
    sbp->rsb_rootdir.rdr_type = RDR_DIR_TYPE;
    sbp->rsb_rootdir.rdr_blknr = blk;

    fimgrhd_t * fmp = (fimgrhd_t *)buf;
    fimgrhd_t_init(fmp);
    fmp->fmd_type = FMD_DIR_TYPE;
    fmp->fmd_sfblk = blk;
    fmp->fmd_curfwritebk = blk;
    fmp->fmd_curfinwbkoff = 0x200;
    fmp->fmd_fleblk[0].fb_blkstart = blk;
    fmp->fmd_fleblk[0].fb_blknr = 1;

    if(write_rfsdevblk(devp, buf, blk) == DFCERRSTUS)
    {
	rets = FALSE;
	goto errlable;
    }
    rets = TRUE;
errlable:
    del_buf(buf, FSYS_ALCBLKSZ);
errlable1:
    del_superblk(devp, sbp);
    
    return rets;
}
Пример #7
0
bool_t create_bitmap(device_t * devp)
{
    printfk("%s in \n\r", __func__);
    bool_t rets = FALSE;
    rfssublk_t * sbp = get_superblk(devp);
    if(!sbp)
    {
	return FALSE;
    }
    void * buf = new_buf(FSYS_ALCBLKSZ);
    if(!buf)
    {
	printfk("%s alloc failed\n\r", __func__);
	return FALSE;
    }

    uint_t bitmapblk = sbp->rsb_bmpbks;
    uint_t devmaxblk = sbp->rsb_fsysallblk;
    if(devmaxblk > FSYS_ALCBLKSZ)
    {
	rets = FALSE;
	goto errlable;
    }

    hal_memset(buf, FSYS_ALCBLKSZ, 1);
    u8_t * bitmap = (u8_t *)buf;
    for(uint_t bi=2; bi<devmaxblk; bi++)
    {
	bitmap[bi] = 0;
    }
    /*缓冲区数据回写到存储介质的第bitmapblk存储块中*/
    if(write_rfsdevblk(devp, buf, bitmapblk) == DFCERRSTUS)
    {
	rets = FALSE;
	goto errlable;
    }

    rets = TRUE;
errlable:
    del_superblk(devp, sbp);
    del_buf(buf, FSYS_ALCBLKSZ);

    return rets;
}
Пример #8
0
rfssublk_t * get_superblk(device_t * devp)
{
    void * buf = new_buf(FSYS_ALCBLKSZ);
    if(!buf)
    {
	printfk("%s alloc failed\n\r", __func__);
	return NULL;
    }

    hal_memset(buf, FSYS_ALCBLKSZ, 0);

    if(read_rfsdevblk(devp, buf, 0)==DFCERRSTUS)
    {
	del_buf(buf, FSYS_ALCBLKSZ);
	return NULL;
    }

    return (rfssublk_t *)buf;
}
Пример #9
0
void del_bitmapblk(device_t * devp, u8_t * bitmap)
{
    rfssublk_t * sbp = get_superblk(devp);
    if(!sbp)
    {
	hal_sysdie("get superblk err");
	return;
    }
    if(write_rfsdevblk(devp, (void *)bitmap, sbp->rsb_bmpbks) == DFCERRSTUS)
    {
	del_superblk(devp, sbp);
	hal_sysdie("del superblk err");
    }

    del_superblk(devp, sbp);
    del_buf((void *)bitmap, FSYS_ALCBLKSZ);

    return;
}
Пример #10
0
bool_t create_superblk(device_t * devp)
{
    printfk("%s in \n\r", __func__);
    void *buf = new_buf(FSYS_ALCBLKSZ);
    if(!buf)
    {
	printfk("alloc failed\n\r");
	return FALSE;
    }
    hal_memset(buf, FSYS_ALCBLKSZ, 0);
    rfssublk_t * sbp = (rfssublk_t *)buf;
    rfssublk_t_init(sbp);
    sbp->rsb_fsysallblk = ret_rfsdevmaxblknr(devp);
    if(write_rfsdevblk(devp, buf, 0) == DFCERRSTUS)
    {
	printfk("write_rfsdevblk failed\n\r");
	return FALSE;
    }
    del_buf(buf, FSYS_ALCBLKSZ);
    return TRUE;
}
Пример #11
0
void test_dir(device_t * devp)
{
    rfsdir_t * dr = get_rootdir(devp);
    void * buf = new_buf(FSYS_ALCBLKSZ);
    if(buf == NULL)
    {
	hal_sysdie("testdir1 err\n\r");
    }
    hal_memset(buf, FSYS_ALCBLKSZ, 0);

    if(read_rfsdevblk(devp, buf, dr->rdr_blknr) == DFCERRSTUS)
    {
	hal_sysdie("testdir1 err\n\r");
    }
    fimgrhd_t * fmp = (fimgrhd_t *)buf;
    printfk("fmp->fmd_type : %x fmd_filesz : %x fmd_fileifstbkoff : %x fmd_fileiendbkoff : %x\n\r",
		fmp->fmd_type, fmp->fmd_filesz, fmp->fmd_fileifstbkoff, fmp->fmd_fileiendbkoff);
    printfk("fmd_fleblk : %x : %x\n\r", fmp->fmd_fleblk[0].fb_blkstart, fmp->fmd_fleblk[0].fb_blknr);
    del_buf(buf, FSYS_ALCBLKSZ);
    del_rootdir(devp, dr);
    return;
}
Пример #12
0
u8_t * get_bitmapblk(device_t * devp)
{        
    rfssublk_t * sbp = get_superblk(devp);
    if(!sbp)
    {    
	printfk("%s get_superblk failed\n\r", __func__);
	return NULL;
    }    
    void *buf = new_buf(FSYS_ALCBLKSZ);
    if(!buf)
    {
	return NULL;
    }
    hal_memset(buf, FSYS_ALCBLKSZ, 0);
    if(read_rfsdevblk(devp, buf, sbp->rsb_bmpbks))
    {
	del_buf(buf, FSYS_ALCBLKSZ);
	del_superblk(devp, sbp);
	return NULL;
    }

    del_superblk(devp, sbp);
    return (u8_t *)buf;
}
Пример #13
0
void * rfs_openfileblk(device_t * devp, char_t * fname)
{
    char_t fne[DR_NM_MAX];
    void * rets = NULL;
    void * buf = NULL;

    hal_memset((void *)fne, DR_NM_MAX, 0);
    if(rfs_ret_fname(fne, fname) != 0)
    {
	printfk("name err\n\r");
	return NULL;
    }

    void * rblkp = get_rootdirfile_blk(devp);
    if(rblkp == NULL)
    {
	printfk("get rootdirfilebk failed\n\r");
	return NULL;
    }

    fimgrhd_t * fmp = (fimgrhd_t *)rblkp;
    if(fmp->fmd_type != FMD_DIR_TYPE)
    {
	printfk("fmd type err\n\r");
	rets = NULL;
	goto err;
    }
    if(fmp->fmd_curfwritebk == fmp->fmd_fleblk[0].fb_blkstart &&
	fmp->fmd_curfinwbkoff == fmp->fmd_fileifstbkoff)
    {
	rets = NULL;
	goto err;
    }

    rfsdir_t * dirp = (rfsdir_t *)((uint_t)(fmp) + fmp->fmd_fileifstbkoff);
    void * maxchkp = (void *)((uint_t)rblkp + FSYS_ALCBLKSZ - 1);
    for(; (void *)dirp<maxchkp; )
    {
	if(dirp->rdr_type == RDR_FIL_TYPE)
	{
	    if(rfs_strcmp(dirp->rdr_name, fne) == 1)
	    {
		goto opfblk;
	    }
	}
	dirp++;
    }
    rets = NULL;
    goto err;

opfblk:
    buf = new_buf(FSYS_ALCBLKSZ);
    if(buf == NULL)
    {
	printfk("alloc buf failed\n\r");
	rets = NULL;
	goto err;
    }
    if(read_rfsdevblk(devp, buf, dirp->rdr_blknr) == DFCERRSTUS)
    {
	printfk("read rfsdevblk failed\n\r");
	rets = NULL;
	goto err1;
    }
    fimgrhd_t * ffmp = (fimgrhd_t *)buf;
    if(ffmp->fmd_type == FMD_NUL_TYPE || ffmp->fmd_fileifstbkoff != 0x200)
    {
	printfk("ffmp err\n\r");
	rets = NULL;
	goto err1;
    }
    rets = buf;
    goto err;

err1:
    del_buf(buf, FSYS_ALCBLKSZ);
err:
    del_rootdirfile_blk(devp, rblkp);
    return rets;
}
Пример #14
0
drvstus_t rfs_new_dirfileblk(device_t * devp, char_t * fname, uint_t flgtype, uint_t val)
{
    drvstus_t rets = DFCERRSTUS;

    if(flgtype != RDR_FIL_TYPE)
    {
	printfk("file type error\n\r");
	return DFCERRSTUS;
    }

    void * buf = new_buf(FSYS_ALCBLKSZ);
    if(buf == NULL)
    {
	printfk("alloc buf failed\n\r");
	return DFCERRSTUS;
    }
    hal_memset(buf, FSYS_ALCBLKSZ, 0);

    uint_t fblk = rfs_new_blk(devp);
    if(fblk == 0)
    {
	printfk("rfs new blk failed\n\r");
	rets = DFCERRSTUS;
	goto err1;
    }

    void * rdirblk = get_rootdirfile_blk(devp);
    if(rdirblk == NULL)
    {
	rets = DFCERRSTUS;
	goto err1;
    }

    fimgrhd_t * fmp = (fimgrhd_t *)rdirblk;
    rfsdir_t * wrdirp = (rfsdir_t *)((uint_t)rdirblk + fmp->fmd_curfinwbkoff);
    if(((uint_t)wrdirp) >= ((uint_t)rdirblk + FSYS_ALCBLKSZ))
    {
	rets = DFCERRSTUS;
	printfk("wrdirp error\n\r");
	goto err;
    }
    wrdirp->rdr_stus = 0;
    wrdirp->rdr_type = flgtype;
    wrdirp->rdr_blknr = fblk;
    rfs_strcpy(fname, wrdirp->rdr_name);
    fmp->fmd_filesz += (uint_t)(sizeof(rfsdir_t));
    fmp->fmd_curfinwbkoff += (uint_t)(sizeof(rfsdir_t));
    fimgrhd_t * ffmp = (fimgrhd_t *)buf;
    fimgrhd_t_init(ffmp);
    ffmp->fmd_type = FMD_FIL_TYPE;
    ffmp->fmd_sfblk = fblk;
    ffmp->fmd_curfwritebk = fblk;
    ffmp->fmd_curfinwbkoff = 0x200;
    ffmp->fmd_fleblk[0].fb_blkstart = fblk;
    ffmp->fmd_fleblk[0].fb_blknr = 1;
    if(write_rfsdevblk(devp, buf, fblk) == DFCERRSTUS)
    {
	printfk("write rfsdevblk failed\n\r");
	rets = DFCERRSTUS;
	goto err;
    }
    rets = DFCOKSTUS;

err1:
    del_rootdirfile_blk(devp, rdirblk);
err:
    del_buf(buf, FSYS_ALCBLKSZ);
    return rets;
}
Пример #15
0
void del_rootdir(device_t * devp, rfsdir_t * rdir)
{
    del_buf((void *)rdir, sizeof(rfsdir_t));
    return;
}
Пример #16
0
int main(int argc, char **argv) {
    init_buf();
    if (argc > 1)
        strncpy(file_name, argv[1], BUFSIZ);
    else
        strcpy(file_name, "untitled.txt");
    read_file(file_name);
    initscr();
    cbreak();
    noecho();
    if (has_colors()) {
        int white;
        start_color();
        if (COLORS > 255)
            white = 231;
        else if (COLORS > 87)
            white = 79;
        else
            white = 15;
        init_pair(1, white, 0);
        minibuf_attrs = COLOR_PAIR(1);
    } else {
        minibuf_attrs = A_BOLD;
    }

    while (TRUE) {
        int ch;
        // Redisplay
        drop_until(getmaxy(stdscr) / 2);
        print_queue();
        mbuf_display();
        refresh();

        // Wait for input
        switch ((ch = getch())) {
        case EOF:
        case '\x04': // ^D
            quit();
        case '\x08': // ^H
        case '\x7f': // DEL
            del_buf(buf.i - 1); break;
        case '\x17': // ^W
            del_buf(buf.wbeg); break;
        case '\x15': // ^U
            reset_buf("");
            break;
        case '\x1b': // ESC
            mbuf_msg("Press CTRL+D to quit");
            break;
        case '\r':
        case '\n':
            append_buf('\n');
            break;
        default:
            mbuf_msg(file_name);
            if (ch > '\x1f')
                append_buf(ch);
        }
    }
    return 0;
}