Ejemplo n.º 1
0
/* Seek to a specific position in this open file descriptor */
static int
e_hfat_lseek (int fd, fs_off_t pos)
{
  int ret;
  F_FILE *fp;

  fp = fd_to_file (fd);

  // printf ("e_hfat_lseek (%d)\n", pos); fflush(stdout);
  if (pos == FS_OFFSET_APPEND)
    ret = f_seek (fp, 0, SEEK_END);
  else
    ret = f_seek (fp, pos, SEEK_SET);

//  if (ret)
//    printf ("Seek failed!\n"), fflush(stdout);
  return hfat_to_efs_err (ret);
}
Ejemplo n.º 2
0
static int
view_init (WDiff *view, const char *file1, const char *file2)
{
    int rv;

    view->file[0] = file1;
    view->file[1] = file2;

    rv = redo_diff(view, REINIT_OPEN);
    if (rv) {
	return -1;
    }

    view->pbytes = 0;
    view->maxmem = 0;
    view->diffs = NULL;
    view->df[0].data = NULL;
    view->df[1].data = NULL;
    view->df[0].move = 1;
    view->df[1].move = 1;
    view->df[0].end = f_seek(view->f[0], 0, SEEK_END);
    view->df[1].end = f_seek(view->f[1], 0, SEEK_END);
    view->max = view->df[0].end;
    if (view->max < view->df[1].end) {
	view->max = view->df[1].end;
    }

    view->view_quit = 0;

    view->bias = 0;
    view->subtract = 0;
    view->new_frame = 1;
    view->display_numbers = 1;
    view->ord = 0;
    view->full = 0;
    view->last_found = -1;

    view_compute_areas(view);
    return 0;
}
Ejemplo n.º 3
0
Archivo: lseek.c Proyecto: akat1/impala
errno_t
sc_lseek(thread_t *p, syscall_result_t *r, lseek_args *args)
{
    file_t *f = f_get(p->thr_proc->p_fd, args->fd);
    if (!f)
        return -EBADF;
    int res = f_seek(f, args->offset, args->whence);
    frele(f);
    if(res < 0)
        return res;
    r->result = res;
    return -EOK;
}
Ejemplo n.º 4
0
static portBASE_TYPE prvPerformCopy( const char *pcSourceFile,
									int32_t lSourceFileLength,
									const char *pcDestinationFile,
									char *pxWriteBuffer,
									size_t xWriteBufferLen )
{
int32_t lBytesRead = 0, lBytesToRead, lBytesRemaining;
F_FILE *pxFile;
portBASE_TYPE xReturn = pdPASS;

	/* NOTE:  Error handling has been omitted for clarity. */

	while( lBytesRead < lSourceFileLength )
	{
		/* How many bytes are left? */
		lBytesRemaining = lSourceFileLength - lBytesRead;

		/* How many bytes should be read this time around the loop.  Can't
		read more bytes than will fit into the buffer. */
		if( lBytesRemaining > ( long ) xWriteBufferLen )
		{
			lBytesToRead = ( long ) xWriteBufferLen;
		}
		else
		{
			lBytesToRead = lBytesRemaining;
		}

		/* Open the source file, seek past the data that has already been
		read from the file, read the next block of data, then close the
		file again so the destination file can be opened. */
		pxFile = f_open( pcSourceFile, "r" );
		if( pxFile != NULL )
		{
			f_seek( pxFile, lBytesRead, F_SEEK_SET );
			f_read( pxWriteBuffer, lBytesToRead, 1, pxFile );
			f_close( pxFile );
		}
		else
		{
			xReturn = pdFAIL;
			break;
		}

		/* Open the destination file and write the block of data to the end of
		the file. */
		pxFile = f_open( pcDestinationFile, "a" );
		if( pxFile != NULL )
		{
			f_write( pxWriteBuffer, lBytesToRead, 1, pxFile );
			f_close( pxFile );
		}
		else
		{
			xReturn = pdFAIL;
			break;
		}

		lBytesRead += lBytesToRead;
	}

	return xReturn;
}
Ejemplo n.º 5
0
static int
redo_diff (WDiff *view, int flags)
{
    size_t pbytes = view->pbytes;
    if (flags & REINIT_OPEN) {
	FBUF *f[2];
	f[0] = f_open(view->file[0], O_RDONLY);
	f[1] = f_open(view->file[1], O_RDONLY);
	if (f[0] == NULL || f[1] == NULL) {
	    f_close(f[0]);
	    f_close(f[1]);
	    return -1;
	}
	view->f[0] = f[0];
	view->f[1] = f[1];
    }
    if (flags & REINIT_REALLOC) {
	if (pbytes > view->maxmem) {
	    void *p = realloc(view->diffs, 3 * pbytes);
	    if (p == NULL) {
		return -1;
	    }
	    view->diffs = p;
	    view->maxmem = pbytes;
	}
	view->df[0].data = view->diffs + pbytes;
	view->df[1].data = view->df[0].data + pbytes;
	flags = REINIT_READ_LEFT | REINIT_READ_RIGHT;
    }
    if (flags & REINIT_READ_LEFT) {
	f_seek(view->f[0], view->df[0].offs, SEEK_SET);
	view->df[0].sz = f_read(view->f[0], view->df[0].data, pbytes);
	if (view->df[0].sz) {
	    if (view->df[0].sz < pbytes) {
		view->df[0].end = view->df[0].offs + view->df[0].sz;
	    }
	}
    }
    if (flags & REINIT_READ_RIGHT) {
	f_seek(view->f[1], view->df[1].offs, SEEK_SET);
	view->df[1].sz = f_read(view->f[1], view->df[1].data, pbytes);
	if (view->df[1].sz) {
	    if (view->df[1].sz < pbytes) {
		view->df[1].end = view->df[1].offs + view->df[1].sz;
	    }
	}
    }
    if (flags & (REINIT_READ_LEFT | REINIT_READ_RIGHT)) {
	size_t i, len;
	char *data1 = view->df[0].data;
	char *data2 = view->df[1].data;
	char *diffs = view->diffs;
	size_t sz1 = view->df[0].sz;
	size_t sz2 = view->df[1].sz;
	len = sz1;
	if (len > sz2) {
	    len = sz2;
	}
	memset(diffs, 0, pbytes);
	for (i = 0; i < len; i++) {
	    diffs[i] = XDIFF_IN_LEFT | XDIFF_IN_RIGHT;
	    if (data1[i] != data2[i]) {
		diffs[i] |= XDIFF_DIFFERENT;
	    }
	}
	for (i = len; i < sz1; i++) {
	    diffs[i] = XDIFF_IN_LEFT | XDIFF_DIFFERENT;
	}
	for (i = len; i < sz2; i++) {
	    diffs[i] = XDIFF_IN_RIGHT | XDIFF_DIFFERENT;
	}
	view->max = view->df[0].end;
	if (view->max < view->df[1].end) {
	    view->max = view->df[1].end;
	}
    }
    return 0;
}
Ejemplo n.º 6
0
UINT8 S2w_LoadS2wProfile(S2W_PROFILE_T *s2wProfile, UINT8 index)
{
    F_FILE *fp = NULL, *fpExt;
    UINT32 extSize = 0;
    UINT32 copySize = 0, profExtSize = 0, file_size = 0;

    if(index == 0)
    {
       fp = f_open("A:/s2w_profile0.conf","r");
       file_size = f_filelength("A:/s2w_profile0.conf");
       extSize = f_filelength("A:/s2w_profile0_ext.conf");
       if((extSize != -1) && extSize != 0)
       {
           fpExt = f_open("A:/s2w_profile0_ext.conf", "r+"); 
       }
       else
       {
           fpExt = f_open("A:/s2w_profile0_ext.conf", "w+");
           extSize = 0;
       }
       
    }
    else if(index == 1)
    {
       fp = f_open("A:/s2w_profile1.conf","r");
       file_size = f_filelength("A:/s2w_profile1.conf");
       extSize = f_filelength("A:/s2w_profile1_ext.conf");
       if((extSize != -1) && extSize != 0)
       {
           fpExt = f_open("A:/s2w_profile1_ext.conf", "r+"); 
       }
       else
       {
           fpExt = f_open("A:/s2w_profile1_ext.conf", "w+"); 
           extSize = 0;
       }
    }

    if (!fp || !fpExt)
    {     
    //S2w_Printf("\r\nFile cannot be opened!\r\n");
        if(fpExt)
            f_close(fpExt);
        if(fp)
            f_close(fp);
        return FILE_OPEN_ER;
    }

    profExtSize = sizeof(S2W_PROFILE_T) - offsetof(S2W_PROFILE_T, socRdCnt);

    if(profExtSize > extSize)
    {
      /* OTAFU from 5.1.X where X is less than or equal to 4  - Upgrade */
        copySize = extSize;
    }
    else
    {
      /* If extSize == profileExtSizeThis then it is same FW boot
         Else if the extSize > profileExtSize it is a downgrade

         In both cases only copy the size equivalent of the profExtSize
       */
        copySize = profExtSize;
    }

    /* Copy the file_size from the profileN.conf to the profile */
    if(f_read(&FlashParams.profile[index],1,file_size,fp) != file_size)
    {
        f_close(fp);
        f_close(fpExt);
        return FILE_READ_ER;
    }

    /* Copy the copySize from the profileN_ext.conf to the profile */
    if (copySize)
    {
        f_read(((UINT8 *)&FlashParams.profile[index]) + offsetof(S2W_PROFILE_T, socRdCnt), 1, copySize, fpExt);
    }

    /* Save Back */

    /* If this is OTAFU and the profile changed - save the extension */
    if (profExtSize > extSize)
    {
        f_seek(fpExt,0, F_SEEK_SET);
        f_write(((UINT8 *)&FlashParams.profile[index]) + offsetof(S2W_PROFILE_T, socRdCnt), 1, profExtSize, fpExt);
    }

    if(s2wProfile != &FlashParams.profile[index])
    {
        memcpy(s2wProfile, &FlashParams.profile[index], sizeof(S2W_PROFILE_T));
    }

    f_close(fpExt);
    f_close(fp);

    return S2W_SUCCESS;  
}