summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-11-11 14:40:18 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-11-11 14:40:18 +0000
commit68640edf90c84c3d4494f0852f6236e1929a4603 (patch)
treefe74712bcebdfcc21ef272d83528209ce6e69fbb
parent228605dc7bfac86604166d5e3bbabb72ae40b78b (diff)
downloadrockbox-68640edf90c84c3d4494f0852f6236e1929a4603.zip
rockbox-68640edf90c84c3d4494f0852f6236e1929a4603.tar.gz
rockbox-68640edf90c84c3d4494f0852f6236e1929a4603.tar.bz2
rockbox-68640edf90c84c3d4494f0852f6236e1929a4603.tar.xz
Added ftruncate().
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2827 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/common/file.c27
-rw-r--r--firmware/common/file.h1
-rw-r--r--firmware/drivers/fat.c9
3 files changed, 33 insertions, 4 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index b869380..cf8c46c 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -90,7 +90,7 @@ int open(const char* pathname, int flags)
case O_WRONLY:
openfiles[fd].write = true;
break;
-
+
default:
DEBUGF("Only O_RDONLY and O_WRONLY is supported\n");
errno = EROFS;
@@ -214,6 +214,31 @@ int remove(const char* name)
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)
{
int sectors;
diff --git a/firmware/common/file.h b/firmware/common/file.h
index 7a7c63d..59ff717 100644
--- a/firmware/common/file.h
+++ b/firmware/common/file.h
@@ -56,6 +56,7 @@ extern int creat(const char *pathname, int mode);
extern int write(int fd, void* buf, int count);
extern int remove(const char* pathname);
extern int rename(const char* oldname, const char* newname);
+extern int ftruncate(int fd, unsigned int size);
#else
#ifdef WIN32
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 74bdbd3..ad1a7a0 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -1002,12 +1002,15 @@ int fat_truncate(struct fat_file *file)
{
/* truncate trailing clusters */
int next;
- int last = get_next_cluster(file->lastcluster);
- while ( last && last != FAT_EOF_MARK ) {
+ int last = file->lastcluster;
+
+ LDEBUGF("fat_truncate(%x, %x)\n", file->firstcluster, last);
+
+ for ( last = get_next_cluster(last); last; last = next ) {
next = get_next_cluster(last);
update_fat_entry(last,0);
- last = next;
}
+ update_fat_entry(file->lastcluster,FAT_EOF_MARK);
return 0;
}