summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-03-27 10:46:09 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-03-27 10:46:09 +0000
commit3f3aeb0e0d613213af508b8218afc408721b0a10 (patch)
tree3815479028c74df62e448d566f1c087bca4648d9
parentd63a09f2c6a48dc497b42f3a2a8a4f40a26f22ad (diff)
downloadrockbox-3f3aeb0e0d613213af508b8218afc408721b0a10.tar.gz
rockbox-3f3aeb0e0d613213af508b8218afc408721b0a10.zip
Alignment fix for ipods.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9282 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/tagcache.c54
1 files changed, 35 insertions, 19 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 3e1647018c..5214e508e8 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -69,6 +69,9 @@ static const int unique_tags[] = { tag_artist, tag_album, tag_genre };
69/* Variable-length tag entry in tag files. */ 69/* Variable-length tag entry in tag files. */
70struct tagfile_entry { 70struct tagfile_entry {
71 short tag_length; 71 short tag_length;
72#ifdef ROCKBOX_STRICT_ALIGN
73 short padding;
74#endif
72 char tag_data[0]; 75 char tag_data[0];
73}; 76};
74 77
@@ -690,14 +693,9 @@ static void add_tagcache(const char *path)
690 close(fd); 693 close(fd);
691 694
692 if (!ret) 695 if (!ret)
693 { 696 return ;
694 track.id3.title = (char *)path; 697
695 track.id3.artist = "Unknown"; 698 check_if_empty(&track.id3.title);
696 track.id3.album = "Unknown";
697 track.id3.genre_string = "Unknown";
698 }
699 else
700 check_if_empty(&track.id3.title);
701 check_if_empty(&track.id3.artist); 699 check_if_empty(&track.id3.artist);
702 check_if_empty(&track.id3.album); 700 check_if_empty(&track.id3.album);
703 check_if_empty(&track.id3.genre_string); 701 check_if_empty(&track.id3.genre_string);
@@ -835,13 +833,34 @@ static int tempbuf_sort(int fd)
835 struct tempbuf_searchidx *index = (struct tempbuf_searchidx *)tempbuf; 833 struct tempbuf_searchidx *index = (struct tempbuf_searchidx *)tempbuf;
836 struct tagfile_entry fe; 834 struct tagfile_entry fe;
837 int i; 835 int i;
836 int length;
837#ifdef ROCKBOX_STRICT_ALIGN
838 int fix;
839#endif
838 840
839 qsort(index, tempbufidx, sizeof(struct tempbuf_searchidx), compare); 841 qsort(index, tempbufidx, sizeof(struct tempbuf_searchidx), compare);
840 842
841 for (i = 0; i < tempbufidx; i++) 843 for (i = 0; i < tempbufidx; i++)
842 { 844 {
843 index[i].seek = lseek(fd, 0, SEEK_CUR); 845 index[i].seek = lseek(fd, 0, SEEK_CUR);
844 fe.tag_length = strlen(index[i].str) + 1; 846 length = strlen(index[i].str) + 1;
847 fe.tag_length = length;
848
849#ifdef ROCKBOX_STRICT_ALIGN
850 /* Make sure the entry is long aligned. */
851 if (index[i].seek & 0x03)
852 {
853 logf("tempbuf_sort: alignment error!");
854 return -3;
855 }
856
857 fix = (sizeof(struct tagfile_entry) + length) & 0x03;
858 if (fix)
859 fix = 4-fix;
860
861 fe.tag_length += fix;
862#endif
863
845 if (write(fd, &fe, sizeof(struct tagfile_entry)) != 864 if (write(fd, &fe, sizeof(struct tagfile_entry)) !=
846 sizeof(struct tagfile_entry)) 865 sizeof(struct tagfile_entry))
847 { 866 {
@@ -849,12 +868,17 @@ static int tempbuf_sort(int fd)
849 return -1; 868 return -1;
850 } 869 }
851 870
852 if (write(fd, index[i].str, fe.tag_length) != 871 if (write(fd, index[i].str, length) != length)
853 fe.tag_length)
854 { 872 {
855 logf("tempbuf_sort: write error #2"); 873 logf("tempbuf_sort: write error #2");
856 return -2; 874 return -2;
857 } 875 }
876
877#ifdef ROCKBOX_STRICT_ALIGN
878 /* Write some padding. */
879 if (fix)
880 write(fd, "XXX", fix);
881#endif
858 } 882 }
859 883
860 return i; 884 return i;
@@ -1544,14 +1568,6 @@ static bool load_tagcache(void)
1544 { 1568 {
1545 yield(); 1569 yield();
1546 fe = (struct tagfile_entry *)p; 1570 fe = (struct tagfile_entry *)p;
1547#ifdef ROCKBOX_STRICT_ALIGN
1548 /* Make sure the entry is long aligned. */
1549 if ((long)fe & 0x03)
1550 {
1551 bytesleft -= 4 - ((long)fe & 0x03);
1552 fe = (struct tagfile_entry *)(((long)fe & ~0x03) + 0x04);
1553 }
1554#endif
1555 rc = read(fd, fe, sizeof(struct tagfile_entry)); 1571 rc = read(fd, fe, sizeof(struct tagfile_entry));
1556 if (rc != sizeof(struct tagfile_entry)) 1572 if (rc != sizeof(struct tagfile_entry))
1557 { 1573 {