diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2007-10-29 00:04:35 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2007-10-29 00:04:35 +0000 |
commit | bae8f4c3167a0b44ff6516d421e95baaf8937066 (patch) | |
tree | f1e2ce95917dac1b6955880edbb8d15614d6209f /firmware/common | |
parent | bf9615f4e14561af6ff5cae8aba104312144676d (diff) | |
download | rockbox-bae8f4c3167a0b44ff6516d421e95baaf8937066.tar.gz rockbox-bae8f4c3167a0b44ff6516d421e95baaf8937066.zip |
More code police...
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15353 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common')
-rw-r--r-- | firmware/common/file.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c index 9cab001e8d..9290f508b8 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c | |||
@@ -69,7 +69,7 @@ static int open_internal(const char* pathname, int flags, bool use_cache) | |||
69 | #ifndef HAVE_DIRCACHE | 69 | #ifndef HAVE_DIRCACHE |
70 | (void)use_cache; | 70 | (void)use_cache; |
71 | #endif | 71 | #endif |
72 | 72 | ||
73 | LDEBUGF("open(\"%s\",%d)\n",pathname,flags); | 73 | LDEBUGF("open(\"%s\",%d)\n",pathname,flags); |
74 | 74 | ||
75 | if ( pathname[0] != '/' ) { | 75 | if ( pathname[0] != '/' ) { |
@@ -105,7 +105,7 @@ static int open_internal(const char* pathname, int flags, bool use_cache) | |||
105 | if (dircache_is_enabled() && !file->write && use_cache) | 105 | if (dircache_is_enabled() && !file->write && use_cache) |
106 | { | 106 | { |
107 | const struct dircache_entry *ce; | 107 | const struct dircache_entry *ce; |
108 | 108 | ||
109 | ce = dircache_get_entry_ptr(pathname); | 109 | ce = dircache_get_entry_ptr(pathname); |
110 | if (!ce) | 110 | if (!ce) |
111 | { | 111 | { |
@@ -113,7 +113,7 @@ static int open_internal(const char* pathname, int flags, bool use_cache) | |||
113 | file->busy = false; | 113 | file->busy = false; |
114 | return -7; | 114 | return -7; |
115 | } | 115 | } |
116 | 116 | ||
117 | fat_open(IF_MV2(unsupported at the moment,) | 117 | fat_open(IF_MV2(unsupported at the moment,) |
118 | ce->startcluster, | 118 | ce->startcluster, |
119 | &(file->fatfile), | 119 | &(file->fatfile), |
@@ -122,14 +122,14 @@ static int open_internal(const char* pathname, int flags, bool use_cache) | |||
122 | file->attr = ce->attribute; | 122 | file->attr = ce->attribute; |
123 | file->cacheoffset = -1; | 123 | file->cacheoffset = -1; |
124 | file->fileoffset = 0; | 124 | file->fileoffset = 0; |
125 | 125 | ||
126 | return fd; | 126 | return fd; |
127 | } | 127 | } |
128 | #endif | 128 | #endif |
129 | 129 | ||
130 | strncpy(pathnamecopy,pathname,sizeof(pathnamecopy)); | 130 | strncpy(pathnamecopy,pathname,sizeof(pathnamecopy)); |
131 | pathnamecopy[sizeof(pathnamecopy)-1] = 0; | 131 | pathnamecopy[sizeof(pathnamecopy)-1] = 0; |
132 | 132 | ||
133 | /* locate filename */ | 133 | /* locate filename */ |
134 | name=strrchr(pathnamecopy+1,'/'); | 134 | name=strrchr(pathnamecopy+1,'/'); |
135 | if ( name ) { | 135 | if ( name ) { |
@@ -148,7 +148,7 @@ static int open_internal(const char* pathname, int flags, bool use_cache) | |||
148 | file->busy = false; | 148 | file->busy = false; |
149 | return -4; | 149 | return -4; |
150 | } | 150 | } |
151 | 151 | ||
152 | if(name[0] == 0) { | 152 | if(name[0] == 0) { |
153 | DEBUGF("Empty file name\n"); | 153 | DEBUGF("Empty file name\n"); |
154 | errno = EINVAL; | 154 | errno = EINVAL; |
@@ -156,7 +156,7 @@ static int open_internal(const char* pathname, int flags, bool use_cache) | |||
156 | closedir_uncached(dir); | 156 | closedir_uncached(dir); |
157 | return -5; | 157 | return -5; |
158 | } | 158 | } |
159 | 159 | ||
160 | /* scan dir for name */ | 160 | /* scan dir for name */ |
161 | while ((entry = readdir_uncached(dir))) { | 161 | while ((entry = readdir_uncached(dir))) { |
162 | if ( !strcasecmp(name, entry->d_name) ) { | 162 | if ( !strcasecmp(name, entry->d_name) ) { |
@@ -367,7 +367,7 @@ int rename(const char* path, const char* newpath) | |||
367 | 367 | ||
368 | /* Extract new path */ | 368 | /* Extract new path */ |
369 | strcpy(newpath2, newpath); | 369 | strcpy(newpath2, newpath); |
370 | 370 | ||
371 | dirptr = strrchr(newpath2,'/'); | 371 | dirptr = strrchr(newpath2,'/'); |
372 | if(dirptr) | 372 | if(dirptr) |
373 | *dirptr = 0; | 373 | *dirptr = 0; |
@@ -375,20 +375,20 @@ int rename(const char* path, const char* newpath) | |||
375 | return - 4; | 375 | return - 4; |
376 | 376 | ||
377 | dirptr = newpath2; | 377 | dirptr = newpath2; |
378 | 378 | ||
379 | if(strlen(dirptr) == 0) { | 379 | if(strlen(dirptr) == 0) { |
380 | dirptr = "/"; | 380 | dirptr = "/"; |
381 | } | 381 | } |
382 | 382 | ||
383 | dir = opendir_uncached(dirptr); | 383 | dir = opendir_uncached(dirptr); |
384 | if(!dir) | 384 | if(!dir) |
385 | return - 5; | 385 | return - 5; |
386 | 386 | ||
387 | file = &openfiles[fd]; | 387 | file = &openfiles[fd]; |
388 | #ifdef HAVE_DIRCACHE | 388 | #ifdef HAVE_DIRCACHE |
389 | dircache_rename(path, newpath); | 389 | dircache_rename(path, newpath); |
390 | #endif | 390 | #endif |
391 | 391 | ||
392 | rc = fat_rename(&file->fatfile, &dir->fatdir, nameptr, | 392 | rc = fat_rename(&file->fatfile, &dir->fatdir, nameptr, |
393 | file->size, file->attr); | 393 | file->size, file->attr); |
394 | #ifdef HAVE_MULTIVOLUME | 394 | #ifdef HAVE_MULTIVOLUME |
@@ -453,16 +453,15 @@ static int flush_cache(int fd) | |||
453 | int rc; | 453 | int rc; |
454 | struct filedesc* file = &openfiles[fd]; | 454 | struct filedesc* file = &openfiles[fd]; |
455 | long sector = file->fileoffset / SECTOR_SIZE; | 455 | long sector = file->fileoffset / SECTOR_SIZE; |
456 | 456 | ||
457 | DEBUGF("Flushing dirty sector cache\n"); | 457 | DEBUGF("Flushing dirty sector cache\n"); |
458 | 458 | ||
459 | /* make sure we are on correct sector */ | 459 | /* make sure we are on correct sector */ |
460 | rc = fat_seek(&(file->fatfile), sector); | 460 | rc = fat_seek(&(file->fatfile), sector); |
461 | if ( rc < 0 ) | 461 | if ( rc < 0 ) |
462 | return rc * 10 - 3; | 462 | return rc * 10 - 3; |
463 | 463 | ||
464 | rc = fat_readwrite(&(file->fatfile), 1, | 464 | rc = fat_readwrite(&(file->fatfile), 1, file->cache, true ); |
465 | file->cache, true ); | ||
466 | 465 | ||
467 | if ( rc < 0 ) { | 466 | if ( rc < 0 ) { |
468 | if(file->fatfile.eof) | 467 | if(file->fatfile.eof) |
@@ -529,7 +528,7 @@ static int readwrite(int fd, void* buf, long count, bool write) | |||
529 | nread = headbytes; | 528 | nread = headbytes; |
530 | count -= headbytes; | 529 | count -= headbytes; |
531 | } | 530 | } |
532 | 531 | ||
533 | /* If the buffer has been modified, either it has been flushed already | 532 | /* If the buffer has been modified, either it has been flushed already |
534 | * (if (offs+headbytes == SECTOR_SIZE)...) or does not need to be (no | 533 | * (if (offs+headbytes == SECTOR_SIZE)...) or does not need to be (no |
535 | * more data to follow in this call). Do NOT flush here. */ | 534 | * more data to follow in this call). Do NOT flush here. */ |
@@ -585,7 +584,7 @@ static int readwrite(int fd, void* buf, long count, bool write) | |||
585 | } | 584 | } |
586 | /* seek back one sector to put file position right */ | 585 | /* seek back one sector to put file position right */ |
587 | rc = fat_seek(&(file->fatfile), | 586 | rc = fat_seek(&(file->fatfile), |
588 | (file->fileoffset + nread) / | 587 | (file->fileoffset + nread) / |
589 | SECTOR_SIZE); | 588 | SECTOR_SIZE); |
590 | if ( rc < 0 ) { | 589 | if ( rc < 0 ) { |
591 | DEBUGF("fat_seek() failed\n"); | 590 | DEBUGF("fat_seek() failed\n"); |
@@ -609,7 +608,7 @@ static int readwrite(int fd, void* buf, long count, bool write) | |||
609 | } | 608 | } |
610 | memcpy( (unsigned char*)buf + nread, file->cache, count ); | 609 | memcpy( (unsigned char*)buf + nread, file->cache, count ); |
611 | } | 610 | } |
612 | 611 | ||
613 | nread += count; | 612 | nread += count; |
614 | file->cacheoffset = count; | 613 | file->cacheoffset = count; |
615 | } | 614 | } |
@@ -700,7 +699,7 @@ off_t lseek(int fd, off_t offset, int whence) | |||
700 | if (rc < 0) | 699 | if (rc < 0) |
701 | return rc * 10 - 5; | 700 | return rc * 10 - 5; |
702 | } | 701 | } |
703 | 702 | ||
704 | rc = fat_seek(&(file->fatfile), newsector); | 703 | rc = fat_seek(&(file->fatfile), newsector); |
705 | if ( rc < 0 ) { | 704 | if ( rc < 0 ) { |
706 | errno = EIO; | 705 | errno = EIO; |
@@ -740,13 +739,13 @@ off_t filesize(int fd) | |||
740 | errno = EBADF; | 739 | errno = EBADF; |
741 | return -1; | 740 | return -1; |
742 | } | 741 | } |
743 | 742 | ||
744 | return file->size; | 743 | return file->size; |
745 | } | 744 | } |
746 | 745 | ||
747 | 746 | ||
748 | #ifdef HAVE_HOTSWAP | 747 | #ifdef HAVE_HOTSWAP |
749 | // release all file handles on a given volume "by force", to avoid leaks | 748 | /* release all file handles on a given volume "by force", to avoid leaks */ |
750 | int release_files(int volume) | 749 | int release_files(int volume) |
751 | { | 750 | { |
752 | struct filedesc* pfile = openfiles; | 751 | struct filedesc* pfile = openfiles; |