forked from len0rd/rockbox
Added ftruncate().
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2827 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
228605dc7b
commit
68640edf90
3 changed files with 33 additions and 4 deletions
|
|
@ -90,7 +90,7 @@ int open(const char* pathname, int flags)
|
||||||
case O_WRONLY:
|
case O_WRONLY:
|
||||||
openfiles[fd].write = true;
|
openfiles[fd].write = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DEBUGF("Only O_RDONLY and O_WRONLY is supported\n");
|
DEBUGF("Only O_RDONLY and O_WRONLY is supported\n");
|
||||||
errno = EROFS;
|
errno = EROFS;
|
||||||
|
|
@ -214,6 +214,31 @@ int remove(const char* name)
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ftruncate(int fd, unsigned int size)
|
||||||
|
{
|
||||||
|
int rc, sector;
|
||||||
|
|
||||||
|
sector = size / SECTOR_SIZE;
|
||||||
|
if (size % SECTOR_SIZE)
|
||||||
|
sector++;
|
||||||
|
|
||||||
|
rc = fat_seek(&(openfiles[fd].fatfile), sector);
|
||||||
|
if (rc < 0) {
|
||||||
|
errno = EIO;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = fat_truncate(&(openfiles[fd].fatfile));
|
||||||
|
if (rc < 0) {
|
||||||
|
errno = EIO;
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
openfiles[fd].size = size;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int readwrite(int fd, void* buf, int count, bool write)
|
static int readwrite(int fd, void* buf, int count, bool write)
|
||||||
{
|
{
|
||||||
int sectors;
|
int sectors;
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ extern int creat(const char *pathname, int mode);
|
||||||
extern int write(int fd, void* buf, int count);
|
extern int write(int fd, void* buf, int count);
|
||||||
extern int remove(const char* pathname);
|
extern int remove(const char* pathname);
|
||||||
extern int rename(const char* oldname, const char* newname);
|
extern int rename(const char* oldname, const char* newname);
|
||||||
|
extern int ftruncate(int fd, unsigned int size);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
|
||||||
|
|
@ -1002,12 +1002,15 @@ int fat_truncate(struct fat_file *file)
|
||||||
{
|
{
|
||||||
/* truncate trailing clusters */
|
/* truncate trailing clusters */
|
||||||
int next;
|
int next;
|
||||||
int last = get_next_cluster(file->lastcluster);
|
int last = file->lastcluster;
|
||||||
while ( last && last != FAT_EOF_MARK ) {
|
|
||||||
|
LDEBUGF("fat_truncate(%x, %x)\n", file->firstcluster, last);
|
||||||
|
|
||||||
|
for ( last = get_next_cluster(last); last; last = next ) {
|
||||||
next = get_next_cluster(last);
|
next = get_next_cluster(last);
|
||||||
update_fat_entry(last,0);
|
update_fat_entry(last,0);
|
||||||
last = next;
|
|
||||||
}
|
}
|
||||||
|
update_fat_entry(file->lastcluster,FAT_EOF_MARK);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue