- UID
- 1029342
- 性别
- 男
|
static int check_block(erase_block_t *block_old, erase_block_t *block_new)
{
int start_old, end_old, start_new, end_new;
if(block_old->start == -1 && block_old->end == -1) /* at the beginning */
{
start_old = -1;
end_old = -1;
}
else
{
start_old = block_old->start/SPI_SECTOR_SIZE;
end_old = block_old->end/SPI_SECTOR_SIZE;
}
start_new = block_new->start/SPI_SECTOR_SIZE;
end_new = block_new->end/SPI_SECTOR_SIZE;
if(end_new <= end_old)
{
return 0;
}
if(start_new <= end_old)
{
start_new = end_old+1;
}
block_new->start = start_new*SPI_SECTOR_SIZE;
block_new->end = (end_new+1)*SPI_SECTOR_SIZE - 1;
block_old->start = block_new->start;
block_old->end = block_new->end;
return (1);
}
ssize_t readn(int fd, void *buf, size_t n)
{
size_t nleft;
size_t nread;
char *ptr;
ptr = buf;
nleft = n;
while(nleft > 0)
{
if( (nread = read(fd, ptr, nleft)) < 0)
{
if(errno == EINTR)
{
nread = 0; /* and call read() again */
}
else
{
return (-1);
}
}
else if(nread == 0)
{
break; /* end of file */
}
nleft -= nread;
ptr += nread;
}
return(n - nleft);
}
ssize_t writen(int fd, const void *buf, size_t n)
{
size_t nleft;
ssize_t nwritten;
const char *ptr;
ptr = buf;
nleft = n;
while(nleft > 0)
{
if( (nwritten = write(fd, ptr, nleft)) < 0)
{
if(errno == EINTR)
{
nwritten = 0;
}
else
{
return (-1);
}
}
/* else if(nwritten == 0)
{
break;
} */
nleft -= nwritten;
ptr += nwritten;
}
return (n);
}
static void dbg_print(char *buf_s, char *buf_d, int cnt)
{
int i;
if(buf_s == NULL || buf_d == NULL)
{
return;
}
printf("************buf_s***********/n");
for(i = 0; i < cnt; i++)
{
printf("%c ", buf_s[i]);
if((i+1) % 16 == 0)
{
printf("/n");
}
}
printf("************buf_d***********/n");
for(i = 0; i < cnt; i++)
{
printf("%c ", buf_d[i]);
if((i+1) % 16 == 0)
{
printf("/n");
}
}
} |
|