summaryrefslogtreecommitdiff
path: root/apps/plugins/rockboy.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/rockboy.c')
-rw-r--r--apps/plugins/rockboy.c63
1 files changed, 39 insertions, 24 deletions
diff --git a/apps/plugins/rockboy.c b/apps/plugins/rockboy.c
index d3504572cf..f571894717 100644
--- a/apps/plugins/rockboy.c
+++ b/apps/plugins/rockboy.c
@@ -34,47 +34,62 @@ int audiobuf_size;
34/* this is the plugin entry point */ 34/* this is the plugin entry point */
35enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 35enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
36{ 36{
37 int fh, readsize; 37 int fd, readsize;
38 struct { 38 struct plugin_header header;
39 unsigned long magic;
40 unsigned char *start_addr;
41 unsigned char *end_addr;
42 enum plugin_status(*entry_point)(struct plugin_api*, void*);
43 } header;
44 39
45 rb = api; 40 rb = api;
46 41
47 fh = rb->open(OVL_NAME, O_RDONLY); 42 fd = rb->open(OVL_NAME, O_RDONLY);
48 if (fh < 0) 43 if (fd < 0)
49 { 44 {
50 rb->splash(2*HZ, true, "Couldn't open " OVL_DISPLAYNAME " overlay."); 45 rb->splash(2*HZ, true, "Can't open " OVL_NAME);
51 return PLUGIN_ERROR; 46 return PLUGIN_ERROR;
52 } 47 }
53 readsize = rb->read(fh, &header, sizeof(header)); 48 readsize = rb->read(fd, &header, sizeof(header));
54 if (readsize != sizeof(header) || header.magic != 0x524f564c) 49 rb->close(fd);
50 /* Close for now. Less code than doing it in all error checks.
51 * Would need to seek back anyway. */
52
53 if (readsize != sizeof(header))
55 { 54 {
56 rb->close(fh); 55 rb->splash(2*HZ, true, "Reading" OVL_DISPLAYNAME " overlay failed.");
57 rb->splash(2*HZ, true, OVL_NAME " is not a valid Rockbox overlay.");
58 return PLUGIN_ERROR; 56 return PLUGIN_ERROR;
59 } 57 }
60 58 if (header.magic != PLUGIN_MAGIC || header.target_id != TARGET_ID)
59 {
60 rb->splash(2*HZ, true, OVL_DISPLAYNAME
61 " overlay: Incompatible model.");
62 return PLUGIN_ERROR;
63 }
64 if (header.api_version != PLUGIN_API_VERSION)
65 {
66 rb->splash(2*HZ, true, OVL_DISPLAYNAME
67 " overlay: Incompatible version.");
68 return PLUGIN_ERROR;
69 }
70
61 audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size); 71 audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size);
62 if (header.start_addr < audiobuf || 72 if (header.load_addr < audiobuf ||
63 header.end_addr > audiobuf + audiobuf_size) 73 header.end_addr > audiobuf + audiobuf_size)
64 { 74 {
65 rb->close(fh);
66 rb->splash(2*HZ, true, OVL_DISPLAYNAME 75 rb->splash(2*HZ, true, OVL_DISPLAYNAME
67 " overlay doesn't fit into memory."); 76 " overlay doesn't fit into memory.");
77 return PLUGIN_ERROR;
78 }
79 rb->memset(header.load_addr, 0, header.end_addr - header.load_addr);
80
81 fd = rb->open(OVL_NAME, O_RDONLY);
82 if (fd < 0)
83 {
84 rb->splash(2*HZ, true, "Can't open " OVL_NAME);
68 return PLUGIN_ERROR; 85 return PLUGIN_ERROR;
69 } 86 }
70 rb->memset(header.start_addr, 0, header.end_addr - header.start_addr); 87 readsize = rb->read(fd, header.load_addr, header.end_addr - header.load_addr);
88 rb->close(fd);
71 89
72 rb->lseek(fh, 0, SEEK_SET); 90 if (readsize < 0)
73 readsize = rb->read(fh, header.start_addr, header.end_addr - header.start_addr);
74 rb->close(fh);
75 if (readsize <= (int)sizeof(header))
76 { 91 {
77 rb->splash(2*HZ, true, "Error loading " OVL_DISPLAYNAME " overlay."); 92 rb->splash(2*HZ, true, "Reading" OVL_DISPLAYNAME " overlay failed.");
78 return PLUGIN_ERROR; 93 return PLUGIN_ERROR;
79 } 94 }
80 return header.entry_point(api, parameter); 95 return header.entry_point(api, parameter);