예제 #1
0
파일: fatxfc.c 프로젝트: HSOFEUP/mm
fx_rtn
fx_cap_dblk(char *name, char *ext, char *n_name, char *n_ext, u32_t size,
	    fat_dir_entry_t **rtn_de) {
    fat_dir_entry_t *de, *n_de;
    u32_t rds, n_rds, o_size, cluster;
    u32_t *fat, fat_sector, fat_offset;

    assert(fx_buf);
    if (strlen(name) != 8 || strlen(ext) != 3 ||
	strlen(n_name) != 8 || strlen(n_ext) != 3)
	return(FX_INTERNAL);

    /* check to see if new name already exists */
    de = f32_get_de(n_name, n_ext, &rds);
    if (de)
	return(FX_EXIST);
    de = f32_get_de(name, ext, &rds);
    if (!de)
	return(FX_NOT_FOUND);
    if (size >= CF_LE_32(de->size))
	return(FX_INTERNAL);
    if (!f32_find_empty(&n_de, &n_rds))
	return(FX_NO_ROOM);
    /*
     * read dir entry of original file and tweak size.
     */
    assert(! ms_read_blk(rds, fx_buf));
    o_size = CF_LE_32(de->size);
    de->size = CT_LE_32(size);
    assert(! ms_write_blk(rds, fx_buf));
    /*
     * compute eof cluster.  write it to eof.
     */
    cluster = (CF_LE_16(de->starthi) << 16) | CF_LE_16(de->start);
    cluster += (size + (FX_CLUSTER_SIZE * SECTOR_SIZE - 1))/(FX_CLUSTER_SIZE * SECTOR_SIZE) - 1;
    fat_sector = FAT_SECTOR(cluster) + fx_fat_start;
    fat_offset = FAT_OFFSET(cluster);
    assert(! ms_read_blk(fat_sector, fx_buf));
    fat = fx_buf;
    fat[fat_offset] = CT_LE_32(EOF_FAT32);
    assert(! ms_write_blk(fat_sector, fx_buf));
    /*
     * now read the directory sector for the new file
     */
    cluster++;
    assert(! ms_read_blk(n_rds, fx_buf));
    memcpy(n_de->name, n_name, 8);
    memcpy(n_de->ext, n_ext, 3);
    n_de->starthi = CT_LE_16(cluster >> 16);
    n_de->start = CT_LE_16(cluster & 0xffff);
    size += (FX_CLUSTER_SIZE * SECTOR_SIZE - 1);
    size &= ~FX_CB_MASK;	/* round up to next cluster */
    n_de->size = CT_LE_32(o_size - size);
    assert(! ms_write_blk(n_rds, fx_buf));
    return(FX_OK);
}
예제 #2
0
파일: tagfmtsd.c 프로젝트: MamMark/mm
void
display_info(void) {
    fat_dir_entry_t *de;
    u32_t rds;

    fprintf(stderr, "fs_loc:  p:   s: %-8x   e: %x\n",
            loc.locators[FS_LOC_PANIC].start,
            loc.locators[FS_LOC_PANIC].end);
    fprintf(stderr, "         c:   s: %-8x   e: %x\n",
            loc.locators[FS_LOC_CONFIG].start,
            loc.locators[FS_LOC_CONFIG].end);
    fprintf(stderr, "         i:   s: %-8x   e: %x\n",
            loc.locators[FS_LOC_IMAGE].start,
            loc.locators[FS_LOC_IMAGE].end);
    fprintf(stderr, "         d:   s: %-8x   e: %-8x   n: %x\n",
            loc.locators[FS_LOC_DBLK].start,
            loc.locators[FS_LOC_DBLK].end,
            msc_dblk_nxt);

    if (p0c.panic_start)
      fprintf(stderr, "panic0:    p: %-8x %-8x  (nxt) %-8x\n",
	      p0c.panic_start, p0c.panic_end,  p0c.panic_nxt);
    else
      fprintf(stderr, "panic0:   no panic0 block\n");

    de = f32_get_de("PANIC001", "   ", &rds);
    if (de) {
	rds = (CF_LE_16(de->starthi) << 16) | CF_LE_16(de->start);
	fprintf(stderr, "PANIC001:  start  0x%04x  size: %10u (0x%x)\n",
                fx_clu2sec(rds),  CF_LE_32(de->size), CF_LE_32(de->size));
    } else
	fprintf(stderr, "PANIC001: not found\n");
    de = f32_get_de("CNFG0001", "   ", &rds);
    if (de) {
	rds = (CF_LE_16(de->starthi) << 16) | CF_LE_16(de->start);
	fprintf(stderr, "CNFG0001:  start  0x%04x  size: %10u (0x%x)\n",
                fx_clu2sec(rds),  CF_LE_32(de->size), CF_LE_32(de->size));
    } else
	fprintf(stderr, "CNFG0001: not found\n");
    de = f32_get_de("IMAGE001", "   ", &rds);
    if (de) {
	rds = (CF_LE_16(de->starthi) << 16) | CF_LE_16(de->start);
	fprintf(stderr, "IMAGE001:  start  0x%04x  size: %10u (0x%x)\n",
		fx_clu2sec(rds), CF_LE_32(de->size), CF_LE_32(de->size));
    } else
	fprintf(stderr, "IMAGE001: not found\n");
    de = f32_get_de("DBLK0001", "   ", &rds);
    if (de) {
	rds = (CF_LE_16(de->starthi) << 16) | CF_LE_16(de->start);
	fprintf(stderr, "DBLK0001:  start  0x%04x  size: %10u (0x%x)\n",
		fx_clu2sec(rds), CF_LE_32(de->size), CF_LE_32(de->size));
    } else
	fprintf(stderr, "DBLK0001: not found\n");
}
예제 #3
0
파일: mkdblk.c 프로젝트: danome/mm
void
display_info(void) {
    fat_dir_entry_t *de;
    u32_t rds;
    
    if (msc.dblk_start) {
      fprintf(stderr, "dblk_loc:  p: %-8x %-8x\n",
              msc.panic_start,  msc.panic_end);
      fprintf(stderr, "           c: %-8x %-8x\n",
              msc.config_start, msc.config_end);
      fprintf(stderr, "           d: %-8x %-8x  (nxt) %-8x\n",
              msc.dblk_start, msc.dblk_end, msc.dblk_nxt);
    }

    if (p0c.panic_start)
      fprintf(stderr, "panic0:    p: %-8x %-8x  (nxt) %-8x\n",
	      p0c.panic_start, p0c.panic_end,  p0c.panic_nxt);
    else
      fprintf(stderr, "panic0:    no panic0 block\n");

    de = f32_get_de("PANIC001", "   ", &rds);
    if (de) {
	rds = (CF_LE_16(de->starthi) << 16) | CF_LE_16(de->start);
	fprintf(stderr, "PANIC001:  start  0x%04x  size: %10u (0x%x)\n",
                fx_clu2sec(rds),  CF_LE_32(de->size), CF_LE_32(de->size));
    } else
	fprintf(stderr, "PANIC001: not found\n");
    de = f32_get_de("CNFG0001", "   ", &rds);
    if (de) {
	rds = (CF_LE_16(de->starthi) << 16) | CF_LE_16(de->start);
	fprintf(stderr, "CNFG0001:  start  0x%04x  size: %10u (0x%x)\n",
                fx_clu2sec(rds),  CF_LE_32(de->size), CF_LE_32(de->size));
    } else
	fprintf(stderr, "CNFG0001: not found\n");
    de = f32_get_de("DBLK0001", "   ", &rds);
    if (de) {
	rds = (CF_LE_16(de->starthi) << 16) | CF_LE_16(de->start);
	fprintf(stderr, "DBLK0001:  start  0x%04x  size: %10u (0x%x)\n",
		fx_clu2sec(rds), CF_LE_32(de->size), CF_LE_32(de->size));
    } else
	fprintf(stderr, "DBLK0001: not found\n");
}
예제 #4
0
파일: fatxfc.c 프로젝트: HSOFEUP/mm
fx_rtn
fx_find_file(char *name, char *ext, u32_t *start, u32_t *end) {
    u32_t rds, cluster;
    fat_dir_entry_t *de;

    if(strlen(name) != 8 || strlen(ext) != 3)
	return(FX_INTERNAL);

    de = f32_get_de(name, ext, &rds);
    if (!de)
	return(FX_NOT_FOUND);
    cluster = (CF_LE_16(de->starthi) << 16) | CF_LE_16(de->start);
    if (cluster < 2 || cluster >= BAD_FAT32)
	return(FX_INTERNAL);
    if (!f32_get_chain(cluster, start, end))
	return(FX_NOT_CONTIGUOUS);
    return(FX_OK);
}