Example #1
0
void read_super_blocks(char* device, file_system_info* fs_info)
{
    struct exfat_super_block* sb;
    uint64_t free_sectors, free_clusters;

    fs_open(device);
    free_clusters = exfat_count_free_clusters(&ef);
    free_sectors = (uint64_t) free_clusters << ef.sb->spc_bits;
    sb = ef.sb;

    strncpy(fs_info->fs, exfat_MAGIC, FS_MAGIC_SIZE);
    fs_info->block_size  = EXFAT_SECTOR_SIZE(*sb);
    fs_info->totalblock  = le64_to_cpu(sb->sector_count);
    fs_info->usedblocks  = le64_to_cpu(sb->sector_count) - free_sectors;
    fs_info->device_size = fs_info->totalblock * fs_info->block_size;
    fs_close();
}
Example #2
0
extern void initial_image_hdr(char* device, image_head* image_hdr)
{
    fs_open(device);
    strncpy(image_hdr->magic, IMAGE_MAGIC, IMAGE_MAGIC_SIZE);
    strncpy(image_hdr->fs, xfs_MAGIC, FS_MAGIC_SIZE);
    image_hdr->block_size = mp->m_sb.sb_blocksize;
    image_hdr->totalblock = mp->m_sb.sb_dblocks;
    image_hdr->usedblocks = mp->m_sb.sb_dblocks - mp->m_sb.sb_fdblocks;
    image_hdr->device_size = (image_hdr->totalblock * image_hdr->block_size);
    log_mesg(1, 0, 0, fs_opt.debug, "%s: blcos size= %i\n", __FILE__, mp->m_sb.sb_blocksize);
    log_mesg(1, 0, 0, fs_opt.debug, "%s: total b= %lli\n", __FILE__, mp->m_sb.sb_dblocks);
    log_mesg(1, 0, 0, fs_opt.debug, "%s: free block= %lli\n", __FILE__, mp->m_sb.sb_fdblocks);
    log_mesg(1, 0, 0, fs_opt.debug, "%s: used block= %lli\n", __FILE__, (mp->m_sb.sb_dblocks - mp->m_sb.sb_fdblocks));
    log_mesg(1, 0, 0, fs_opt.debug, "%s: device size= %lli\n", __FILE__, (mp->m_sb.sb_blocksize*mp->m_sb.sb_dblocks));
    fs_close();

}
Example #3
0
/// read super block and write to image head
extern void initial_image_hdr(char* device, image_head* image_hdr)
{

    uint32_t alloc,total;

    fs_open(device);
    strncpy(image_hdr->magic, IMAGE_MAGIC, IMAGE_MAGIC_SIZE);
    strncpy(image_hdr->fs, vmfs_MAGIC, FS_MAGIC_SIZE);
    total = fs->fbb->bmh.total_items;
    alloc = vmfs_bitmap_allocated_items(fs->fbb);

    image_hdr->block_size  = vmfs_fs_get_blocksize(fs);
    image_hdr->totalblock  = total;
    image_hdr->usedblocks  = alloc;
    image_hdr->device_size = (vmfs_fs_get_blocksize(fs)*total);
    fs_close();
}
/*..........................................................................*/
static void conn_err(void *arg, err_t err) {
    struct http_state *hs;

    LWIP_UNUSED_ARG(err);

    if (arg) {
        hs = arg;
        if (hs->handle) {
            fs_close(hs->handle);
            hs->handle = NULL;
        }
        if (hs->buf) {
            mem_free(hs->buf);
        }
        mem_free(hs);
    }
}
/// read super block and write to image head
extern void initial_image_hdr(char* device, image_head* image_hdr)
{
    reiser4_bitmap_t       *fs_bitmap;
    unsigned long long free_blocks=0;

    fs_open(device);
    fs_bitmap = reiser4_bitmap_create(reiser4_format_get_len(fs->format));
    reiser4_alloc_extract(fs->alloc, fs_bitmap);
    free_blocks = reiser4_format_get_free(fs->format);
    memcpy(image_hdr->magic, IMAGE_MAGIC, IMAGE_MAGIC_SIZE);
    memcpy(image_hdr->fs, reiser4_MAGIC, FS_MAGIC_SIZE);
    image_hdr->block_size = (int)get_ms_blksize(SUPER(fs->master));
    image_hdr->totalblock = (unsigned long long)reiser4_format_get_len(fs->format);
    image_hdr->usedblocks = (unsigned long long)(reiser4_format_get_len(fs->format) - free_blocks);
    image_hdr->device_size =(unsigned long long)(image_hdr->block_size * image_hdr->totalblock);
    fs_close();
}
Example #6
0
static int aux_close (lua_State *L) {
#if LUA_OPTIMIZE_MEMORY != 2
  lua_getfenv(L, 1);
  lua_getfield(L, -1, "__close");
  return (lua_tocfunction(L, -1))(L);
#else
  int *p = tofilep(L);
  if(*p == c_stdin || *p == c_stdout || *p == c_stderr)
  {
    lua_pushnil(L);
    lua_pushliteral(L, "cannot close standard file");
    return 2;  
  }
  int ok = (fs_close(*p) == 0);
  *p = FS_OPEN_OK - 1;
  return pushresult(L, ok, NULL);
#endif 
}
Example #7
0
/* This callback is called each time the sndstream driver needs
   some more data. It will tell us how much it needs in bytes. */
static void* xing_callback(snd_stream_hnd_t hnd, int size, int * actual) {
	static	int frames = 0;
	IN_OUT	x;

	/* Check for file not started or file finished */
	if (mp3_fd == 0)
		return NULL;

	/* Dump the last PCM packet */
	pcm_empty(pcm_discard);

	/* Loop decoding until we have a full buffer */
	while (pcm_count < size) {
		/* Pull in some more data (and check for EOF) */
		if (bs_fill() < 0 || bs_count < frame_bytes) {
			printf("Decode completed\r\n");
			goto errorout;
		}

		/* Decode a frame */
		x = audio_decode(&mpeg, bs_ptr, (short*)pcm_ptr);
		if (x.in_bytes <= 0) {
			printf("Bad sync in MPEG file\r\n");
			goto errorout;
		}

		bs_ptr += x.in_bytes; bs_count -= x.in_bytes;
		pcm_ptr += x.out_bytes; pcm_count += x.out_bytes;
		
		frames++;
		/*if (!(frames % 64)) {
			printf("Decoded %d frames    \r", frames);
		}*/
	}

	pcm_discard = *actual = size;

	/* Got it successfully */
	return pcm_buffer;

errorout:
	fs_close(mp3_fd); mp3_fd = 0;
	return NULL;
}
/// readbitmap - read bitmap
extern void readbitmap(char* device, image_head image_hdr, char* bitmap, int pui)
{
    unsigned long long     total_block, block, bused = 0, bfree = 0;
    int                    done = 0, i = 0, start = 0, bit_size = 1;
    char* p;


    fs_open(device);

    /// init progress
    progress_bar   bprog;	/// progress_bar structure defined in progress.h
    progress_init(&bprog, start, image_hdr.totalblock, bit_size);

    total_block = 0;
    /// read group
    while ((i = cgread(&disk)) != 0) {
        log_mesg(2, 0, 0, fs_opt.debug, "%s: \ncg = %d\n", __FILE__, disk.d_lcg);
        log_mesg(2, 0, 0, fs_opt.debug, "%s: blocks = %i\n", __FILE__, acg.cg_ndblk);
        p = cg_blksfree(&acg);

        for (block = 0; block < acg.cg_ndblk; block++) {
            if (isset(p, block)) {
                bitmap[total_block] = 0;
                bfree++;
                log_mesg(3, 0, 0, fs_opt.debug, "%s: bitmap is free %lli\n", __FILE__, block);
            } else {
                bitmap[total_block] = 1;
                bused++;
                log_mesg(3, 0, 0, fs_opt.debug, "%s: bitmap is used %lli\n", __FILE__, block);
            }
            total_block++;
            update_pui(&bprog, total_block ,done);
        }
        log_mesg(1, 0, 0, fs_opt.debug, "%s: read bitmap done\n", __FILE__);

    }

    fs_close();

    log_mesg(1, 0, 0, fs_opt.debug, "%s: total used = %lli, total free = %lli\n", __FILE__, bused, bfree);
    done = 1;
    update_pui(&bprog, 1, done);

}
Example #9
0
/* Common code for both dir_read and dir_write */
static int vmdfs_dir_read(const char *vmdfile, vmd_root_t * root, vmd_dir_t * dir_buf) {
    uint16  dir_block, dir_size;
    unsigned int i;
    int needsop;//, rv;
    int write = 0;

    /* Find the directory starting block and length */
    dir_block = root->dir_loc;
    dir_size = root->dir_size;

    /* The dir is stored backwards, so we start at the end and go back. */
    while(dir_size > 0) {
        if(write) {
            /* Scan this block for changes */
            for(i = 0, needsop = 0; i < 512 / sizeof(vmd_dir_t); i++) {
                if(dir_buf[i].dirty) {
                    needsop = 1;
                }

                dir_buf[i].dirty = 0;
            }
        }
        else
            needsop = 1;

		if(needsop) {
			
			if(!write){
			
				file_t f = fs_open(vmdfile,O_RDONLY);
				fs_seek(f,dir_block*BLOCK_SIZE,SEEK_SET);
				fs_read(f,(uint8 *)dir_buf,BLOCK_SIZE);
				fs_close(f);
			}
        }
      
        dir_block--;
        dir_size--;
        dir_buf += 512 / sizeof(vmd_dir_t); /* == 16 */
    }

    return 0;
}
Example #10
0
void read_super_blocks(char* device, file_system_info* fs_info)
{
    int fs_type = 0;
    fs_type = test_extfs_type(device);
    log_mesg(1, 0, 0, fs_opt.debug, "%s: extfs version is %i\n", __FILE__, fs_type);
    strncpy(fs_info->fs, extfs_MAGIC, FS_MAGIC_SIZE);
    fs_open(device);
    fs_info->block_size  = block_size();
    fs_info->totalblock  = block_count();
    fs_info->usedblocks  = get_used_blocks();
    fs_info->device_size = fs_info->block_size * fs_info->totalblock;

    log_mesg(1, 0, 0, fs_opt.debug, "%s: extfs block_size %i\n", __FILE__,    fs_info->block_size);
    log_mesg(1, 0, 0, fs_opt.debug, "%s: extfs total block %lli\n", __FILE__, fs_info->totalblock);
    log_mesg(1, 0, 0, fs_opt.debug, "%s: extfs used blocks %lli\n", __FILE__, fs_info->usedblocks);
    log_mesg(1, 0, 0, fs_opt.debug, "%s: extfs device size %lli\n", __FILE__, fs_info->device_size);

    fs_close();
}
Example #11
0
int main(int argc, char *argv[])
{
    DOS_FS fs;
    rw = 0;

    char *device = NULL;
    char *label = NULL;

    check_atari();

    if (argc < 2 || argc > 3)
        usage(1);

    if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
        usage(0);
    else if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
        printf( "dosfslabel " VERSION ", " VERSION_DATE ", FAT32, LFN\n" );
        exit(0);
    }

    device = argv[1];
    if (argc == 3) {
        label = argv[2];
        if (strlen(label) > 11) {
            fprintf(stderr,
                    "dosfslabel: labels can be no longer than 11 characters\n");
            exit(1);
        }
        rw = 1;
    }

    fs_open(device, rw);
    read_boot(&fs);
    if (!rw) {
        fprintf(stdout, "%s\n", fs.label);
        exit(0);
    }

    write_label(&fs, label);
    fs_close(rw);
    return 0;
}
Example #12
0
void read_bitmap(char* device, file_system_info fs_info, unsigned long* bitmap, int pui)
{
    reiserfs_bitmap_t    *fs_bitmap;
    reiserfs_tree_t	 *tree;
    unsigned long long	 blk = 0;
    unsigned long long 	 bused = 0, bfree = 0;
    int start = 0;
    int bit_size = 1;
    int done = 0;
    
    fs_open(device);
    tree = reiserfs_fs_tree(fs);
    fs_bitmap = tree->fs->bitmap;
    
    /// init progress
    progress_bar   bprog;	/// progress_bar structure defined in progress.h
    progress_init(&bprog, start, fs->super->s_v1.sb_block_count, fs->super->s_v1.sb_block_count, BITMAP, bit_size);

    for( blk = 0; blk < (unsigned long long)fs->super->s_v1.sb_block_count; blk++ ){
	
	log_mesg(3, 0, 0, fs_opt.debug, "%s: block sb_block_count %llu\n", __FILE__, fs->super->s_v1.sb_block_count);
	log_mesg(3, 0, 0, fs_opt.debug, "%s: block bitmap check %llu\n", __FILE__, blk);
	if(reiserfs_tools_test_bit(blk, fs_bitmap->bm_map)){
	    bused++;
	    pc_set_bit(blk, bitmap);
	}else{
	    bfree++;
	    pc_clear_bit(blk, bitmap);
	}
	/// update progress
	update_pui(&bprog, blk, blk, done);

    }

    if(bfree != fs->super->s_v1.sb_free_blocks)
	log_mesg(0, 1, 1, fs_opt.debug, "%s: bitmap free count err, free:%i\n", __FILE__, bfree);

    fs_close();
    /// update progress
    update_pui(&bprog, 1, 1, 1);

}
Example #13
0
/* Opens a file, allocates enough RAM to hold the whole thing,
   reads it into RAM, and closes it. The caller owns the allocated
   memory (and must free it). The file size is returned, or -1  
   on failure; on success, out_ptr is filled with the address    
   of the loaded buffer. */
ssize_t fs_load(const char * src, void ** out_ptr) {
	file_t	f;
	void	* data;
	uint8	* out;
	ssize_t	total, left, r;

	assert( out_ptr != NULL );
	*out_ptr = NULL;

	/* Try to open the file */
	f = fs_open(src, O_RDONLY);
	if (f == FILEHND_INVALID)
		return -1;

	/* Get the size and alloc a buffer */
	left = fs_total(f);
	total = 0;
	data = malloc(left);
	out = (uint8 *)data;

	/* Load the data */
	while (left > 0) {
		r = fs_read(f, out, left);
		if (r <= 0)
			break;
		left -= r;
		total += r;
		out += r;
	}

	/* Did we get it all? If not, realloc the buffer */
	if (left > 0) {
		*out_ptr = realloc(data, total);
		if (*out_ptr == NULL)
			*out_ptr = data;
	} else
		*out_ptr = data;

	fs_close(f);

	return total;
}
Example #14
0
File: main.c Project: wuwx/simba
static int test_read_timeout(struct harness_t *harness_p)
{
    struct fs_file_t file;
    uint8_t byte;
    uint8_t buf[516];
    int i, j;

    BTASSERT(fs_open(&file, "foo.txt", FS_WRITE | FS_CREAT | FS_TRUNC) == 0);

    byte = 0;

    for (i = 0; i < 130; i++) {
        BTASSERT(fs_write(&file, &byte, 1) == 1);
        byte++;
    }

    BTASSERT(fs_close(&file) == 0);

    /* Input read request packet. */
    socket_stub_input(0, "\x00""\x01""foo.txt""\x00""octet""\x00", 16);

    /* Read the packet three times (first transmission + two
       retransmissions). */
    for (i = 0; i < 3; i++) {
        socket_stub_output(&buf[0], 134);
        BTASSERT(buf[0] == 0);
        BTASSERT(buf[1] == 3);
        BTASSERT(buf[2] == 0);
        BTASSERT(buf[3] == 1);

        byte = 0;

        for (j = 0; j < 130; j++) {
            BTASSERT(buf[4 + j] == byte);
            byte++;
        }
    }

    thrd_sleep_ms(10);

    return (0);
}
/*..........................................................................*/
static void close_conn(struct tcp_pcb *pcb, struct http_state *hs) {
    err_t err;
    DEBUG_PRINT("Closing connection 0x%08x\n", pcb);

    tcp_arg(pcb, NULL);
    tcp_sent(pcb, NULL);
    tcp_recv(pcb, NULL);
    if (hs->handle) {
        fs_close(hs->handle);
        hs->handle = NULL;
    }
    if (hs->buf) {
        mem_free(hs->buf);
    }
    mem_free(hs);
    err = tcp_close(pcb);
    if (err != ERR_OK) {
        DEBUG_PRINT("Error %d closing 0x%08x\n", err, pcb);
    }
}
///  readbitmap - read bitmap
extern void readbitmap(char* device, image_head image_hdr, char* bitmap, int pui)
{
    reiserfs_bitmap_t    *fs_bitmap;
    reiserfs_tree_t	 *tree;
    reiserfs_block_t	 *node;
    blk_t		 blk;
    unsigned long long 	 bused = 0, bfree = 0;
    int start = 0;
    int bit_size = 1;
    int done = 0;
    
    fs_open(device);
    tree = reiserfs_fs_tree(fs);
    fs_bitmap = tree->fs->bitmap;
    
    /// init progress
    progress_bar   bprog;	/// progress_bar structure defined in progress.h
    progress_init(&bprog, start, fs->super->s_v1.sb_block_count, bit_size);

    for(blk = 0 ; (int)blk < fs->super->s_v1.sb_block_count; blk++){
	if(reiserfs_tools_test_bit(blk, fs_bitmap->bm_map)){
	    bused++;
	    bitmap[blk] = 1;
	}else{
	    bfree++;
	    bitmap[blk] = 0;
	}
	/// update progress
	update_pui(&bprog, blk, done);

    }

    if(bfree != fs->super->s_v1.sb_free_blocks)
	log_mesg(0, 1, 1, fs_opt.debug, "%s: bitmap free count err, free:%i\n", __FILE__, bfree);

    fs_close();
    /// update progress
    done = 1;
    update_pui(&bprog, 1, done);

}
Example #17
0
void course_init()
{
    fs_file fin;
    char *line;

    Array items;
    int i;

    if (course_state)
        course_free();

    count = 0;

    if ((fin = fs_open(COURSE_FILE, "r")))
    {
        while (count < MAXCRS && read_line(&line, fin))
        {
            if (course_load(&course_v[count], line))
                count++;

            free(line);
        }

        fs_close(fin);

        course_state = 1;
    }

    if ((items = fs_dir_scan("", is_unseen_course)))
    {
        array_sort(items, cmp_dir_items);

        for (i = 0; i < array_len(items) && count < MAXCRS; i++)
            if (course_load(&course_v[count], DIR_ITEM_GET(items, i)->path))
                count++;

        fs_dir_free(items);

        course_state = 1;
    }
}
Example #18
0
GDI_track_t *gdi_get_track(GDI_header_t *hdr, uint32 lba) {

	int i;

	for(i = hdr->track_count - 1; i > -1; i--) {
		
		if(hdr->tracks[i]->start_lba <= lba) {
			
#ifdef DEBUG
				dbglog(DBG_DEBUG, "%s: %ld found in track #%d\n", __func__, lba, i + 1);
#endif
			
			if(hdr->track_current != i) {
				
#ifdef DEBUG
				dbglog(DBG_DEBUG, "%s: Opening %s\n", __func__, hdr->tracks[i]->filename);
#endif
				
				if(hdr->track_fd != FILEHND_INVALID) {
					fs_close(hdr->track_fd);
				}

				hdr->track_fd = fs_open(hdr->tracks[i]->filename, O_RDONLY);
				
				if(hdr->track_fd < 0) {
#ifdef DEBUG
					dbglog(DBG_DEBUG, "%s: Can't open %s\n", __func__, hdr->tracks[i]->filename);
#endif
					return NULL;
				}
				
				hdr->track_current = i;
			}
			
			return hdr->tracks[i];
		}
	}

	return NULL;
}
/// readbitmap - read bitmap
extern void readbitmap(char* device, image_head image_hdr, char*bitmap, int pui)
{
    reiser4_bitmap_t       *fs_bitmap;
    unsigned long long     bit, block, bused = 0, bfree = 0;
    int start = 0;
    int bit_size = 1;

    fs_open(device);
    fs_bitmap = reiser4_bitmap_create(reiser4_format_get_len(fs->format));
    reiser4_alloc_extract(fs->alloc, fs_bitmap);

    /// init progress
    progress_bar   prog;	/// progress_bar structure defined in progress.h
    progress_init(&prog, start, image_hdr.totalblock, bit_size);


    for(bit = 0; bit < reiser4_format_get_len(fs->format); bit++){
        block = bit ;
        if(reiser4_bitmap_test(fs_bitmap, bit)){
            bused++;
            bitmap[block] = 1;
            log_mesg(3, 0, 0, fs_opt.debug, "%s: bitmap is used %lli", block, __FILE__);
        } else {
            bitmap[block] = 0;
            bfree++;
            log_mesg(3, 0, 0, fs_opt.debug, "%s: bitmap is free %lli", block, __FILE__);
        }
        /// update progress
        update_pui(&prog, bit, 0);

    }

    if(bfree != reiser4_format_get_free(fs->format))
        log_mesg(0, 1, 1, fs_opt.debug, "%s: bitmap free count err, bfree:%lli, sfree=%lli\n", __FILE__, bfree, reiser4_format_get_free(fs->format));

    fs_close();
    /// update progress
    update_pui(&prog, bit, 1);
}
Example #20
0
int
fsutil_write_file(const char *path, const void *data, uint32_t len)
{
    struct fs_file *file;
    int rc;

    rc = fs_open(path, FS_ACCESS_WRITE, &file);
    if (rc != 0) {
        goto done;
    }

    rc = fs_write(file, data, len);
    if (rc != 0) {
        goto done;
    }

    rc = 0;

done:
    fs_close(file);
    return rc;
}
Example #21
0
	void Font::load(std::string filename)
	{
		uint8 *data;
		file_t fd = fs_open(filename.c_str(), O_RDONLY);
		data = new uint8[fs_total(fd)];
		fs_read(fd, data, fs_total(fd));
		fs_close(fd);
		
		uint32 rofs;
		memcpy(&header, data, sizeof(HeaderStruct));
		
		assert_msg(Font::formatTag.compare(header.formatTag) == 0, "Wrong font format OR version");
		
		/* Read characters */
		rofs = header.characterDataOffset;
		memcpy(&characterList.characterCount, &data[rofs], 4);
		rofs += 4;
		
		characterList.characters = new CharacterDataStruct[characterList.characterCount];
		memcpy(characterList.characters, &data[rofs], (sizeof(CharacterDataStruct) * characterList.characterCount));
		
		/* Read font texture */
		rofs = header.fontTextureOffset;
		int w = 0, h = 0, fmt = 0, byte_count = 0;
		memcpy(&w, &data[rofs], 4);
		memcpy(&h, &data[rofs + 0x4], 4);
		memcpy(&fmt, &data[rofs + 0x8], 4);
		memcpy(&byte_count, &data[rofs + 0xC], 4);
		
		uint32 *tdata = new uint32[byte_count];
		memcpy(tdata, &data[rofs + 0x10], byte_count);
		
		texture = plx_txr_canvas(w, h, PVR_TXRFMT_ARGB4444);
		pvr_txr_load_ex(tdata, texture->ptr, texture->w, texture->h, PVR_TXRLOAD_16BPP);
		
		delete[] tdata;
		
		delete[] data;
	}
Example #22
0
int gdi_close(GDI_header_t *hdr) {

	if(!hdr) {
		return -1;
	}

	int i;

	for(i = 0; i < hdr->track_count; i++) {
		
		if(hdr->tracks[i] != NULL) {
			free(hdr->tracks[i]);
		}
	}
	
	if(hdr->track_fd != FILEHND_INVALID) {
		fs_close(hdr->track_fd);
	}

	free(hdr);
	return 0;
}
Example #23
0
/// readbitmap - read bitmap
extern void readbitmap(char* device, image_head image_hdr, unsigned long* bitmap, int pui)
{
    uint32_t current = 0, used_block = 0, free_block = 0, err_block = 0, total = 0, alloc = 0;
    int status = 0;
    int start = 0;
    int bit_size = 1;

    fs_open(device);
    /// init progress
    progress_bar   prog;        /// progress_bar structure defined in progress.h
    progress_init(&prog, start, image_hdr.totalblock, image_hdr.totalblock, BITMAP, bit_size);

    total = fs->fbb->bmh.total_items;
    alloc = vmfs_bitmap_allocated_items(fs->fbb);

    for(current = 0; current < total; current++){
	status = vmfs_block_get_status(fs, VMFS_BLK_FB_BUILD(current));
	if (status == -1) {
	    err_block++;
	    pc_clear_bit(current, bitmap);
	} else if (status == 1){
	    used_block++;
	    pc_set_bit(current, bitmap);
	} else if (status == 0){
	    free_block++;
	    pc_clear_bit(current, bitmap);
	}

	log_mesg(2, 0, 0, fs_opt.debug, "%s: Block 0x%8.8x status: %i\n", __FILE__, current, status);
	update_pui(&prog, current, current, 0);

    }
    fs_close();
    update_pui(&prog, 1, 1, 1);

    log_mesg(0, 0, 0, fs_opt.debug, "%s: Used:%lld, Free:%lld, Status err:%lld\n", __FILE__, used_block, free_block, err_block);

}
Example #24
0
int
fsutil_read_file(const char *path, uint32_t offset, uint32_t len, void *dst,
                 uint32_t *out_len)
{
    struct fs_file *file;
    int rc;

    rc = fs_open(path, FS_ACCESS_READ, &file);
    if (rc != 0) {
        goto done;
    }

    rc = fs_read(file, len, dst, out_len);
    if (rc != 0) {
        goto done;
    }

    rc = 0;

done:
    fs_close(file);
    return rc;
}
Example #25
0
/// read super block and write to image head
extern void initial_image_hdr(char* device, image_head* image_hdr)
{

    fs_open(device);
    strncpy(image_hdr->magic, IMAGE_MAGIC, IMAGE_MAGIC_SIZE);
    strncpy(image_hdr->fs, ufs_MAGIC, FS_MAGIC_SIZE);
    image_hdr->block_size  = afs.fs_fsize;
    image_hdr->usedblocks  = get_used_block();
    switch (disk.d_ufs) {
        case 2:
	    image_hdr->totalblock = (unsigned long long)afs.fs_size;
            image_hdr->device_size = afs.fs_fsize*afs.fs_size;
            break;
        case 1:
	    image_hdr->totalblock = (unsigned long long)afs.fs_old_size;
            image_hdr->device_size = afs.fs_fsize*afs.fs_old_size;
            break;
        default:
            break;
    }

    fs_close();
}
Example #26
0
// Lua: rename("oldname", "newname")
static int file_rename( lua_State* L )
{
  size_t len;
  if((FS_OPEN_OK - 1)!=file_fd){
    fs_close(file_fd);
    file_fd = FS_OPEN_OK - 1;
  }

  const char *oldname = luaL_checklstring( L, 1, &len );
  if( len > FS_NAME_MAX_LENGTH )
    return luaL_error(L, "filename too long");

  const char *newname = luaL_checklstring( L, 2, &len );
  if( len > FS_NAME_MAX_LENGTH )
    return luaL_error(L, "filename too long");

  if(SPIFFS_OK==myspiffs_rename( oldname, newname )){
    lua_pushboolean(L, 1);
  } else {
    lua_pushboolean(L, 0);
  }
  return 1;
}
Example #27
0
// Lua: open(filename, mode)
static int file_open( lua_State* L )
{
  size_t len;
  if((FS_OPEN_OK - 1)!=file_fd){
    fs_close(file_fd);
    file_fd = FS_OPEN_OK - 1;
  }

  const char *fname = luaL_checklstring( L, 1, &len );
  if( len > FS_NAME_MAX_LENGTH )
    return luaL_error(L, "filename too long");
  const char *mode = luaL_optstring(L, 2, "r");

  file_fd = fs_open(fname, fs_mode2flag(mode));

  if(file_fd < FS_OPEN_OK){
    file_fd = FS_OPEN_OK - 1;
    lua_pushnil(L);
  } else {
    lua_pushboolean(L, 1);
  }
  return 1; 
}
Example #28
0
File: efi.c Project: Fluray/kboot
/** Load an EFI application.
 * @param args          Argument list.
 * @return              Whether successful. */
static bool config_cmd_efi(value_list_t *args) {
    efi_loader_t *loader;
    status_t ret;

    if (args->count != 1 || args->values[0].type != VALUE_TYPE_STRING) {
        config_error("Invalid arguments");
        return false;
    }

    loader = malloc(sizeof(*loader));

    loader->args.type = VALUE_TYPE_STRING;
    split_cmdline(args->values[0].string, &loader->path, &loader->args.string);

    ret = fs_open(loader->path, NULL, FILE_TYPE_REGULAR, 0, &loader->handle);
    if (ret != STATUS_SUCCESS) {
        config_error("Error opening '%s': %pS", loader->path, ret);
        goto err_free;
    }

    loader->efi_path = convert_file_path(loader->handle, loader->path);
    if (!loader->efi_path)
        goto err_close;

    environ_set_loader(current_environ, &efi_loader_ops, loader);
    return true;

err_close:
    fs_close(loader->handle);

err_free:
    value_destroy(&loader->args);
    free(loader->path);
    free(loader);
    return false;
}
Example #29
0
uint32 camsensor_reg_file_read
(
    const char *filename,
    uint32 register_set_size,
    camsensor_parser_register_t *register_set
)
{
  //int i;
  fs_rsp_msg_type        rsp_msg;     
  fs_handle_type         fhandle = 0;

  unsigned char *param_file;
  unsigned char *temp_ptr;
  uint32 file_size;
  uint32 register_index = 0;

  //u_int16_t param_version;

  u_int16_t reg_address;
  u_int16_t reg_val;


  fs_nametest(filename, FS_TEST_FILE, NULL, &rsp_msg);

  if ( !rsp_msg.nametest.name_found )
  {
    MSG_FATAL(" File Not Found! ",0,0,0);
    return 0;
  } 
  else 
  {  //when SensorParamTable exists
    fs_open(filename, FS_OA_READONLY, NULL, NULL, &rsp_msg);

    MSG_FATAL(" File Open O.K ! ",0,0,0);

    if (rsp_msg.open.handle == FS_NULL_HANDLE)
    {
      MSG_ERROR ("File was not opened!!!",0,0,0);
      fs_close(fhandle,NULL,&rsp_msg);
      return 0;
    }
    fhandle = rsp_msg.open.handle;

    fs_file_size(filename, NULL, &rsp_msg);
    if (rsp_msg.file_size.status != FS_OKAY_S)
    {
      MSG_ERROR ("File size read fail!!!",0,0,0);
      rsp_msg.file_size.size = MAX_SENSORPARAM_SIZE;
      fs_close(fhandle,NULL,&rsp_msg);
      ERR_FATAL("ERR!",0,0,0);
      return 0;
    }
    file_size = rsp_msg.file_size.size;

    param_file = (unsigned char *)malloc(file_size+2);

    if(param_file==NULL)
    {
      fs_close(fhandle,NULL,&rsp_msg);
      ERR_FATAL("ERR!",0,0,0);
      return 0;
    }

    *(param_file+file_size)= NULL;
    *(param_file+file_size+1)=NULL;

    fs_read ( fhandle, (void *)param_file, file_size, NULL, &rsp_msg );
  
    if ( rsp_msg.read.status != FS_OKAY_S )
    {
      MSG_ERROR ("File read file header fail!!!",0,0,0);
      free((void *)param_file);
      fs_close(fhandle,NULL,&rsp_msg);
      return 0;
    }
    else
    {
      fs_close(fhandle, NULL, &rsp_msg);
      if ( rsp_msg.close.status != FS_OKAY_S )
      {
        MSG_ERROR ("File closing fail!!!",0,0,0);
      }

      temp_ptr = param_file;

      while (temp_ptr)
      {  
//20070622_c@m_이창원_chg [ 
//        if ((temp_ptr=find_next_address(temp_ptr, &reg_address)))
        if ((temp_ptr=find_next_address(temp_ptr, &reg_address)) != NULL)
        {
//20070622_c@m_이창원_chg [ 
//          if ((temp_ptr=find_next_val(temp_ptr, &reg_val)))
          if ((temp_ptr=find_next_val(temp_ptr, &reg_val)) != NULL)
          {
              register_set[register_index].address = reg_address;
              register_set[register_index].value = reg_val;
              register_index++;
              if (register_index >= register_set_size)
              {
                ERR_FATAL("ERR!",0,0,0);
                return 0;
              }
          }
        }
      }
    }

    free((void *)param_file);
  }

  return register_index;
}
Example #30
0
int DC_CheckForMaps(char *path) {
    file_t dir;
    dirent_t *dirent;
    char fpath[1024];
    int disc_status;

    for(;;) {
        SDL_Delay(5);
        disc_status = DC_CheckDrive();
#ifdef SPEAR
        DC_DrawString(4, 1, "Sod4SDL\\DC");
#else
        DC_DrawString(4, 1, "Wolf4SDL\\DC");
#endif
        switch(disc_status) {
            //case CD_STATUS_BUSY:
            //case CD_STATUS_OPEN:
            //    DC_DrawString(4, 6, "Please insert your Wolfenstein 3D CD.");
            //    break;
            default:
                dir = fs_open(path, O_DIR);
                while(dirent = fs_readdir(dir)) {
#ifdef SPEAR
#ifdef SPEARDEMO
                    if(!strcmp(dirent->name, "AUDIOHED.SDM")) {
                        fs_close(dir);
                        strcpy(dcwolf3dpath, path);
                        return 0;
                    }
#else
                    if(!strcmp(dirent->name, "AUDIOHED.SOD")) {
                        fs_close(dir);
                        strcpy(dcwolf3dpath, path);
                        param_mission = DC_SetMission(path);
                        return 0;
                    }
#endif
#else
#ifdef UPLOAD
                    if(!strcmp(dirent->name, "AUDIOHED.WL1")) {
                        fs_close(dir);
                        strcpy(dcwolf3dpath, path);
                        return 0;
                    }
#else
                    if(!strcmp(dirent->name, "AUDIOHED.WL6")) {
                        fs_close(dir);
                        strcpy(dcwolf3dpath, path);
                        return 0;
                    }
#endif
#endif
                    strcpy(fpath, path);
                    sprintf(fpath, "%s/%s", fpath, dirent->name);
                    DC_CheckForMaps(fpath);
                }
                fs_close(dir);
                return -1;
        }
        DC_Flip();
    }
}