summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2003-06-19 12:08:22 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2003-06-19 12:08:22 +0000
commitc6db7870ef001ffd7a64884b3e03d3b4cfc67b1d (patch)
tree55480a6999283da7a1932a7ed906d9dd9f757950 /firmware
parent474c4b5427d4bce75ddb9217756da0173fe3ba84 (diff)
downloadrockbox-c6db7870ef001ffd7a64884b3e03d3b4cfc67b1d.tar.gz
rockbox-c6db7870ef001ffd7a64884b3e03d3b4cfc67b1d.zip
Slightly better handling of disk-full situations
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3756 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/file.c16
-rw-r--r--firmware/export/mpeg.h5
-rw-r--r--firmware/mpeg.c39
3 files changed, 56 insertions, 4 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index 46af790bf7..01279d4421 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -348,8 +348,13 @@ static int flush_cache(int fd)
rc = fat_readwrite(&(file->fatfile), 1,
file->cache, true );
- if ( rc < 0 )
+
+ if ( rc < 0 ) {
+ if(file->fatfile.eof)
+ errno = ENOSPC;
+
return rc * 10 - 2;
+ }
file->dirty = false;
@@ -418,14 +423,19 @@ static int readwrite(int fd, void* buf, int count, bool write)
return rc * 10 - 3;
}
- /* read whole sectors right into the supplied buffer */
+ /* read/write whole sectors right into/from the supplied buffer */
sectors = count / SECTOR_SIZE;
if ( sectors ) {
int rc = fat_readwrite(&(file->fatfile), sectors, buf+nread, write );
if ( rc < 0 ) {
DEBUGF("Failed read/writing %d sectors\n",sectors);
errno = EIO;
- file->fileoffset += nread;
+ if(write && file->fatfile.eof) {
+ DEBUGF("No space left on device\n");
+ errno = ENOSPC;
+ } else {
+ file->fileoffset += nread;
+ }
file->cacheoffset = -1;
return nread ? nread : rc * 10 - 4;
}
diff --git a/firmware/export/mpeg.h b/firmware/export/mpeg.h
index d939567f3d..dda93f811d 100644
--- a/firmware/export/mpeg.h
+++ b/firmware/export/mpeg.h
@@ -95,6 +95,8 @@ unsigned long mpeg_num_recorded_bytes(void);
#endif
void mpeg_get_debugdata(struct mpeg_debug *dbgdata);
void mpeg_set_buffer_margin(int seconds);
+unsigned int mpeg_error(void);
+void mpeg_error_clear(void);
#define SOUND_VOLUME 0
#define SOUND_BASS 1
@@ -120,5 +122,8 @@ void mpeg_set_buffer_margin(int seconds);
#define MPEG_STATUS_PLAY 1
#define MPEG_STATUS_PAUSE 2
#define MPEG_STATUS_RECORD 4
+#define MPEG_STATUS_ERROR 8
+
+#define MPEGERR_DISK_FULL 1
#endif
diff --git a/firmware/mpeg.c b/firmware/mpeg.c
index 6872ee171b..11f7e60f16 100644
--- a/firmware/mpeg.c
+++ b/firmware/mpeg.c
@@ -26,6 +26,7 @@
#include "string.h"
#include <kernel.h>
#include "thread.h"
+#include "errno.h"
#include "mp3data.h"
#include "buffer.h"
#ifndef SIMULATOR
@@ -356,6 +357,8 @@ static void set_elapsed(struct mp3entry* id3)
static bool paused; /* playback is paused */
+static unsigned int mpeg_errno;
+
#ifdef SIMULATOR
static bool is_playing = false;
static bool playing = false;
@@ -1952,7 +1955,20 @@ static void mpeg_thread(void)
writelen);
if(rc < 0)
- panicf("rec wrt: %d", rc);
+ {
+ if(errno == ENOSPC)
+ {
+ mpeg_errno = MPEGERR_DISK_FULL;
+ demand_irq_enable(false);
+ stop_recording();
+ queue_post(&mpeg_queue, MPEG_STOP_DONE, 0);
+ break;
+ }
+ else
+ {
+ panicf("rec wrt: %d", rc);
+ }
+ }
rc = flush(mpeg_file);
if(rc < 0)
@@ -2224,6 +2240,8 @@ static void init_playback(void)
void mpeg_record(char *filename)
{
+ mpeg_errno = 0;
+
strncpy(recording_filename, filename, MAX_PATH - 1);
recording_filename[MAX_PATH - 1] = 0;
@@ -2330,6 +2348,8 @@ void mpeg_play(int offset)
queue_post(&mpeg_queue, MPEG_PLAY, (void*)offset);
#endif
+
+ mpeg_errno = 0;
}
void mpeg_stop(void)
@@ -2343,6 +2363,7 @@ void mpeg_stop(void)
is_playing = false;
playing = false;
#endif
+
}
void mpeg_pause(void)
@@ -2452,9 +2473,23 @@ int mpeg_status(void)
if(is_recording)
ret |= MPEG_STATUS_RECORD;
#endif
+
+ if(mpeg_errno)
+ ret |= MPEG_STATUS_ERROR;
+
return ret;
}
+unsigned int mpeg_error(void)
+{
+ return mpeg_errno;
+}
+
+void mpeg_error_clear(void)
+{
+ mpeg_errno = 0;
+}
+
#ifndef SIMULATOR
#ifdef HAVE_MAS3507D
int current_left_volume = 0; /* all values in tenth of dB */
@@ -2919,6 +2954,8 @@ static void mpeg_thread(void)
void mpeg_init(int volume, int bass, int treble, int balance, int loudness,
int bass_boost, int avc, int channel_config)
{
+ mpeg_errno = 0;
+
#ifdef SIMULATOR
volume = bass = treble = balance = loudness
= bass_boost = avc = channel_config;