summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorAmaury Pouly <pamaury@rockbox.org>2010-03-16 12:15:56 +0000
committerAmaury Pouly <pamaury@rockbox.org>2010-03-16 12:15:56 +0000
commit1bff4b32d1f9465a64b839720f1fe0882a3f8426 (patch)
tree4d2a426f8fb71a57db38ffdce2ef8c7dda1f6b24 /apps
parent7430bb02a12ef5d32b4c895a628eebdb36cbfe4d (diff)
downloadrockbox-1bff4b32d1f9465a64b839720f1fe0882a3f8426.tar.gz
rockbox-1bff4b32d1f9465a64b839720f1fe0882a3f8426.zip
tagcache: Factor ecread of tagfile_entry/index_entry, and ecwrite of index_entry. This should save some binsize and avoid this stupidly repetitive sequence.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25217 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/tagcache.c73
1 files changed, 38 insertions, 35 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 90763bb9a6..b6ce45fa7f 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -264,6 +264,22 @@ const char* tagcache_tag_to_str(int tag)
264 return tags_str[tag]; 264 return tags_str[tag];
265} 265}
266 266
267/* Helper functions for the two most read/write data structure: tagfile_entry and index_entry */
268ssize_t ecread_tagfile_entry(int fd, struct tagfile_entry *buf)
269{
270 return ecread(fd, buf, 1, tagfile_entry_ec, tc_stat.econ);
271}
272
273ssize_t ecread_index_entry(int fd, struct index_entry *buf)
274{
275 return ecread(fd, buf, 1, index_entry_ec, tc_stat.econ);
276}
277
278ssize_t ecwrite_index_entry(int fd, struct index_entry *buf)
279{
280 return ecwrite(fd, buf, 1, index_entry_ec, tc_stat.econ);
281}
282
267#ifdef HAVE_DIRCACHE 283#ifdef HAVE_DIRCACHE
268/** 284/**
269 * Returns true if specified flag is still present, i.e., dircache 285 * Returns true if specified flag is still present, i.e., dircache
@@ -448,7 +464,7 @@ static long find_entry_disk(const char *filename, bool localfd)
448 pos_history[i+1] = pos_history[i]; 464 pos_history[i+1] = pos_history[i];
449 pos_history[0] = pos; 465 pos_history[0] = pos;
450 466
451 if (ecread(fd, &tfe, 1, tagfile_entry_ec, tc_stat.econ) 467 if (ecread_tagfile_entry(fd, &tfe)
452 != sizeof(struct tagfile_entry)) 468 != sizeof(struct tagfile_entry))
453 { 469 {
454 break ; 470 break ;
@@ -583,7 +599,7 @@ static bool get_index(int masterfd, int idxid,
583 599
584 lseek(masterfd, idxid * sizeof(struct index_entry) 600 lseek(masterfd, idxid * sizeof(struct index_entry)
585 + sizeof(struct master_header), SEEK_SET); 601 + sizeof(struct master_header), SEEK_SET);
586 if (ecread(masterfd, idx, 1, index_entry_ec, tc_stat.econ) 602 if (ecread_index_entry(masterfd, idx)
587 != sizeof(struct index_entry)) 603 != sizeof(struct index_entry))
588 { 604 {
589 logf("read error #3"); 605 logf("read error #3");
@@ -638,8 +654,7 @@ static bool write_index(int masterfd, int idxid, struct index_entry *idx)
638 654
639 lseek(masterfd, idxid * sizeof(struct index_entry) 655 lseek(masterfd, idxid * sizeof(struct index_entry)
640 + sizeof(struct master_header), SEEK_SET); 656 + sizeof(struct master_header), SEEK_SET);
641 if (ecwrite(masterfd, idx, 1, index_entry_ec, tc_stat.econ) 657 if (ecwrite_index_entry(masterfd, idx) != sizeof(struct index_entry))
642 != sizeof(struct index_entry))
643 { 658 {
644 logf("write error #3"); 659 logf("write error #3");
645 logf("idxid: %d", idxid); 660 logf("idxid: %d", idxid);
@@ -717,7 +732,7 @@ static bool retrieve(struct tagcache_search *tcs, struct index_entry *idx,
717 return false; 732 return false;
718 733
719 lseek(tcs->idxfd[tag], seek, SEEK_SET); 734 lseek(tcs->idxfd[tag], seek, SEEK_SET);
720 if (ecread(tcs->idxfd[tag], &tfe, 1, tagfile_entry_ec, tc_stat.econ) 735 if (ecread_tagfile_entry(tcs->idxfd[tag], &tfe)
721 != sizeof(struct tagfile_entry)) 736 != sizeof(struct tagfile_entry))
722 { 737 {
723 logf("read error #5"); 738 logf("read error #5");
@@ -960,7 +975,7 @@ static bool check_clauses(struct tagcache_search *tcs,
960 { 975 {
961 int fd = tcs->idxfd[clause[i]->tag]; 976 int fd = tcs->idxfd[clause[i]->tag];
962 lseek(fd, seek, SEEK_SET); 977 lseek(fd, seek, SEEK_SET);
963 ecread(fd, &tfe, 1, tagfile_entry_ec, tc_stat.econ); 978 ecread_tagfile_entry(fd, &tfe);
964 if (tfe.tag_length >= (int)sizeof(str)) 979 if (tfe.tag_length >= (int)sizeof(str))
965 { 980 {
966 logf("Too long tag read!"); 981 logf("Too long tag read!");
@@ -1091,7 +1106,7 @@ static bool build_lookup_list(struct tagcache_search *tcs)
1091 lseek(tcs->masterfd, tcs->seek_pos * sizeof(struct index_entry) + 1106 lseek(tcs->masterfd, tcs->seek_pos * sizeof(struct index_entry) +
1092 sizeof(struct master_header), SEEK_SET); 1107 sizeof(struct master_header), SEEK_SET);
1093 1108
1094 while (ecread(tcs->masterfd, &entry, 1, index_entry_ec, tc_stat.econ) 1109 while (ecread_index_entry(tcs->masterfd, &entry)
1095 == sizeof(struct index_entry)) 1110 == sizeof(struct index_entry))
1096 { 1111 {
1097 struct tagcache_seeklist_entry *seeklist; 1112 struct tagcache_seeklist_entry *seeklist;
@@ -1429,8 +1444,7 @@ static bool get_next(struct tagcache_search *tcs)
1429 /* Seek stream to the correct position and continue to direct fetch. */ 1444 /* Seek stream to the correct position and continue to direct fetch. */
1430 lseek(tcs->idxfd[tcs->type], tcs->position, SEEK_SET); 1445 lseek(tcs->idxfd[tcs->type], tcs->position, SEEK_SET);
1431 1446
1432 if (ecread(tcs->idxfd[tcs->type], &entry, 1, 1447 if (ecread_tagfile_entry(tcs->idxfd[tcs->type], &entry) != sizeof(struct tagfile_entry))
1433 tagfile_entry_ec, tc_stat.econ) != sizeof(struct tagfile_entry))
1434 { 1448 {
1435 logf("read error #5"); 1449 logf("read error #5");
1436 tcs->valid = false; 1450 tcs->valid = false;
@@ -2180,7 +2194,7 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
2180 for (i = 0; i < tcmh.tch.entry_count; i++) 2194 for (i = 0; i < tcmh.tch.entry_count; i++)
2181 { 2195 {
2182 /* Read the index entry. */ 2196 /* Read the index entry. */
2183 if (ecread(masterfd, &idx, 1, index_entry_ec, tc_stat.econ) 2197 if (ecread_index_entry(masterfd, &idx)
2184 != sizeof(struct index_entry)) 2198 != sizeof(struct index_entry))
2185 { 2199 {
2186 logf("read fail #3"); 2200 logf("read fail #3");
@@ -2251,8 +2265,7 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
2251 idx.flag |= FLAG_RESURRECTED; 2265 idx.flag |= FLAG_RESURRECTED;
2252 2266
2253 lseek(masterfd, -sizeof(struct index_entry), SEEK_CUR); 2267 lseek(masterfd, -sizeof(struct index_entry), SEEK_CUR);
2254 if (ecwrite(masterfd, &idx, 1, index_entry_ec, tc_stat.econ) 2268 if (ecwrite_index_entry(masterfd, &idx) != sizeof(struct index_entry))
2255 != sizeof(struct index_entry))
2256 { 2269 {
2257 logf("masterfd writeback fail #1"); 2270 logf("masterfd writeback fail #1");
2258 close(masterfd); 2271 close(masterfd);
@@ -2272,8 +2285,7 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
2272 { 2285 {
2273 int loc = lseek(masterfd, 0, SEEK_CUR); 2286 int loc = lseek(masterfd, 0, SEEK_CUR);
2274 2287
2275 if (ecread(masterfd, &idx, 1, index_entry_ec, tc_stat.econ) 2288 if (ecread_index_entry(masterfd, &idx) != sizeof(struct index_entry))
2276 != sizeof(struct index_entry))
2277 { 2289 {
2278 logf("read fail #3"); 2290 logf("read fail #3");
2279 close(masterfd); 2291 close(masterfd);
@@ -2302,8 +2314,7 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
2302 2314
2303 /* Write back the updated index. */ 2315 /* Write back the updated index. */
2304 lseek(masterfd, loc, SEEK_SET); 2316 lseek(masterfd, loc, SEEK_SET);
2305 if (ecwrite(masterfd, &idx, 1, index_entry_ec, tc_stat.econ) 2317 if (ecwrite_index_entry(masterfd, &idx) != sizeof(struct index_entry))
2306 != sizeof(struct index_entry))
2307 { 2318 {
2308 logf("write fail"); 2319 logf("write fail");
2309 close(masterfd); 2320 close(masterfd);
@@ -2429,8 +2440,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
2429 int loc = lseek(fd, 0, SEEK_CUR); 2440 int loc = lseek(fd, 0, SEEK_CUR);
2430 bool ret; 2441 bool ret;
2431 2442
2432 if (ecread(fd, &entry, 1, tagfile_entry_ec, tc_stat.econ) 2443 if (ecread_tagfile_entry(fd, &entry) != sizeof(struct tagfile_entry))
2433 != sizeof(struct tagfile_entry))
2434 { 2444 {
2435 logf("read error #7"); 2445 logf("read error #7");
2436 close(fd); 2446 close(fd);
@@ -3457,8 +3467,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs)
3457 3467
3458 for (i = 0; i < myhdr.tch.entry_count; i++) 3468 for (i = 0; i < myhdr.tch.entry_count; i++)
3459 { 3469 {
3460 if (ecread(tcs->masterfd, &idx, 1, index_entry_ec, tc_stat.econ) 3470 if (ecread_index_entry(tcs->masterfd, &idx) != sizeof(struct index_entry))
3461 != sizeof(struct index_entry))
3462 { 3471 {
3463 logf("read error #9"); 3472 logf("read error #9");
3464 tagcache_search_finish(tcs); 3473 tagcache_search_finish(tcs);
@@ -3522,8 +3531,7 @@ static bool delete_entry(long idx_id)
3522 return false; 3531 return false;
3523 3532
3524 lseek(masterfd, idx_id * sizeof(struct index_entry), SEEK_CUR); 3533 lseek(masterfd, idx_id * sizeof(struct index_entry), SEEK_CUR);
3525 if (ecread(masterfd, &myidx, 1, index_entry_ec, tc_stat.econ) 3534 if (ecread_index_entry(masterfd, &myidx) != sizeof(struct index_entry))
3526 != sizeof(struct index_entry))
3527 { 3535 {
3528 logf("delete_entry(): read error"); 3536 logf("delete_entry(): read error");
3529 goto cleanup; 3537 goto cleanup;
@@ -3537,8 +3545,7 @@ static bool delete_entry(long idx_id)
3537 3545
3538 myidx.flag |= FLAG_DELETED; 3546 myidx.flag |= FLAG_DELETED;
3539 lseek(masterfd, -sizeof(struct index_entry), SEEK_CUR); 3547 lseek(masterfd, -sizeof(struct index_entry), SEEK_CUR);
3540 if (ecwrite(masterfd, &myidx, 1, index_entry_ec, tc_stat.econ) 3548 if (ecwrite_index_entry(masterfd, &myidx) != sizeof(struct index_entry))
3541 != sizeof(struct index_entry))
3542 { 3549 {
3543 logf("delete_entry(): write_error #1"); 3550 logf("delete_entry(): write_error #1");
3544 goto cleanup; 3551 goto cleanup;
@@ -3560,8 +3567,7 @@ static bool delete_entry(long idx_id)
3560 else 3567 else
3561#endif 3568#endif
3562 { 3569 {
3563 if (ecread(masterfd, &idx, 1, index_entry_ec, tc_stat.econ) 3570 if (ecread_index_entry(masterfd, &idx) != sizeof(struct index_entry))
3564 != sizeof(struct index_entry))
3565 { 3571 {
3566 logf("delete_entry(): read error #2"); 3572 logf("delete_entry(): read error #2");
3567 goto cleanup; 3573 goto cleanup;
@@ -3617,8 +3623,7 @@ static bool delete_entry(long idx_id)
3617 3623
3618 /* Skip the header block */ 3624 /* Skip the header block */
3619 lseek(fd, myidx.tag_seek[tag], SEEK_SET); 3625 lseek(fd, myidx.tag_seek[tag], SEEK_SET);
3620 if (ecread(fd, &tfe, 1, tagfile_entry_ec, tc_stat.econ) 3626 if (ecread_tagfile_entry(fd, &tfe) != sizeof(struct tagfile_entry))
3621 != sizeof(struct tagfile_entry))
3622 { 3627 {
3623 logf("delete_entry(): read error #3"); 3628 logf("delete_entry(): read error #3");
3624 goto cleanup; 3629 goto cleanup;
@@ -3681,8 +3686,7 @@ static bool delete_entry(long idx_id)
3681 /* Write index entry back into master index. */ 3686 /* Write index entry back into master index. */
3682 lseek(masterfd, sizeof(struct master_header) + 3687 lseek(masterfd, sizeof(struct master_header) +
3683 (idx_id * sizeof(struct index_entry)), SEEK_SET); 3688 (idx_id * sizeof(struct index_entry)), SEEK_SET);
3684 if (ecwrite(masterfd, &myidx, 1, index_entry_ec, tc_stat.econ) 3689 if (ecwrite_index_entry(masterfd, &myidx) != sizeof(struct index_entry))
3685 != sizeof(struct index_entry))
3686 { 3690 {
3687 logf("delete_entry(): write_error #2"); 3691 logf("delete_entry(): write_error #2");
3688 goto cleanup; 3692 goto cleanup;
@@ -3872,7 +3876,7 @@ static bool load_tagcache(void)
3872 /* Load the master index table. */ 3876 /* Load the master index table. */
3873 for (i = 0; i < hdr->h.tch.entry_count; i++) 3877 for (i = 0; i < hdr->h.tch.entry_count; i++)
3874 { 3878 {
3875 rc = ecread(fd, idx, 1, index_entry_ec, tc_stat.econ); 3879 rc = ecread_index_entry(fd, idx);
3876 if (rc != sizeof(struct index_entry)) 3880 if (rc != sizeof(struct index_entry))
3877 { 3881 {
3878 logf("read error #10"); 3882 logf("read error #10");
@@ -3929,7 +3933,7 @@ static bool load_tagcache(void)
3929 3933
3930 fe = (struct tagfile_entry *)p; 3934 fe = (struct tagfile_entry *)p;
3931 pos = lseek(fd, 0, SEEK_CUR); 3935 pos = lseek(fd, 0, SEEK_CUR);
3932 rc = ecread(fd, fe, 1, tagfile_entry_ec, tc_stat.econ); 3936 rc = ecread_tagfile_entry(fd, fe);
3933 if (rc != sizeof(struct tagfile_entry)) 3937 if (rc != sizeof(struct tagfile_entry))
3934 { 3938 {
3935 /* End of lookup table. */ 3939 /* End of lookup table. */
@@ -4076,8 +4080,7 @@ static bool check_deleted_files(void)
4076 } 4080 }
4077 4081
4078 lseek(fd, sizeof(struct tagcache_header), SEEK_SET); 4082 lseek(fd, sizeof(struct tagcache_header), SEEK_SET);
4079 while (ecread(fd, &tfe, 1, tagfile_entry_ec, tc_stat.econ) 4083 while (ecread_tagfile_entry(fd, &tfe) == sizeof(struct tagfile_entry)
4080 == sizeof(struct tagfile_entry)
4081#ifndef __PCTOOL__ 4084#ifndef __PCTOOL__
4082 && !check_event_queue() 4085 && !check_event_queue()
4083#endif 4086#endif
@@ -4145,7 +4148,7 @@ static bool check_dir(const char *dirname, int add_files)
4145 dir = opendir(dirname); 4148 dir = opendir(dirname);
4146 if (!dir) 4149 if (!dir)
4147 { 4150 {
4148 logf("tagcache: opendir() failed"); 4151 logf("tagcache: opendir(%s) failed", dirname);
4149 return false; 4152 return false;
4150 } 4153 }
4151 4154