Группа :: Система/Ядро и оборудование
Пакет: clicfs
Главная Изменения Спек Патчи Sources Загрузить Gear Bugs and FR Repocop
Патч: clicfs-1.4.6-alt2.2.patch
Скачать
Скачать
src/clicfs.c | 56 ++++++++++++++++++++++++++++++-----------------------
src/clicfs_common.c | 26 ++++++++++++++-----------
src/mkclicfs.cpp | 2 +-
src/unclicfs.c | 2 +-
4 files changed, 49 insertions(+), 37 deletions(-)
diff --git a/src/clicfs.c b/src/clicfs.c
index 65ee891..f98ee6f 100644
--- a/src/clicfs.c
+++ b/src/clicfs.c
@@ -33,6 +33,7 @@
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/sysinfo.h>
+#include <inttypes.h>
//#define DEBUG 1
@@ -95,7 +96,7 @@ static int clic_write_cow()
int ret = 0;
- if (logger) fprintf(logger, "cow detached %dMB\n", (int)(detached_allocated / 1024));
+ if (logger) fprintf(logger, "cow detached %" PRIu64 "MB\n", detached_allocated / 1024);
if (logger) fprintf(logger, "clic_write_cow %ld\n", pthread_self());
pthread_mutex_lock(&cowfile_mutex);
@@ -282,12 +283,12 @@ static void clic_dump_use()
return;
struct buffer_combo *c = coms_sort_by_use_first;
- fprintf(logger, "dump %ldMB ", (long int)memory_used / 1024 / 1024);
+ fprintf(logger, "dump %ldMB ", (long)memory_used / 1024 / 1024);
while (c) {
- fprintf(logger, "%ld ", (long)c->part);
+ fprintf(logger, "%" PRIu32 " ", c->part);
c = c->next_by_use;
}
- fprintf(logger, "\n");
+ fputc('\n', logger);
}
/* slightly modified binary_search.
@@ -344,7 +345,7 @@ static void clic_free_com(struct buffer_combo *com)
}
} else
free(com->out_buffer);
- if (logger) fprintf(logger, "free block %d\n", com->part);
+ if (logger) fprintf(logger, "free block %" PRIu32 "\n", com->part);
memory_used -= com->out_buffer_size;
int32_t res = binary_search(coms_by_part, coms_sort_by_part_size, com->part);
assert(coms_by_part[res] == com);
@@ -361,7 +362,7 @@ static void clic_free_com(struct buffer_combo *com)
static const unsigned char *clic_uncompress(uint32_t part)
{
- if (logger) fprintf(logger, "clic_uncompress %d %d\n", part, parts);
+ if (logger) fprintf(logger, "clic_uncompress %" PRIu32 " %" PRIu32 "\n", part, parts);
long now = get_uptime();
pthread_mutex_lock(&coms_by_part_mutex);
@@ -384,7 +385,7 @@ static const unsigned char *clic_uncompress(uint32_t part)
com->last_used = now;
clic_remove_com_from_use(com);
clic_append_by_use(com);
- if (logger) fprintf(logger, "unlock fast\n");
+ if (logger) fputs("unlock fast\n", logger);
pthread_mutex_unlock(&coms_by_part_mutex);
return buf;
}
@@ -435,10 +436,12 @@ static const unsigned char *clic_uncompress(uint32_t part)
}
#if defined(DEBUG)
- if (logger) fprintf(logger, "uncompress %d %ld-%ld %ld (read took %ld - started %ld)\n", part, (long)offs[part], (long)sizes[part], (long)readin, (end.tv_sec - begin.tv_sec) * 1000 + (end.tv_usec - begin.tv_usec) / 1000, (begin.tv_sec - start.tv_sec) * 1000 + (begin.tv_usec - start.tv_usec) / 1000 );
+ if (logger)
+ fprintf(logger, "uncompress %" PRIu32 " %" PRIu64 "-%" PRIu64 " %zu (read took %ld - started %ld)\n",
+ part, offs[part], sizes[part], readin, (end.tv_sec - begin.tv_sec) * 1000 + (end.tv_usec - begin.tv_usec) / 1000, (begin.tv_sec - start.tv_sec) * 1000 + (begin.tv_usec - start.tv_usec) / 1000 );
#endif
if (!clic_decompress_part(com->out_buffer, inbuffer, readin)) {
- if (logger) fprintf(logger, "uncompess of part %d failed - ignoring\n", part);
+ if (logger) fprintf(logger, "uncompess of part %" PRIu32 " failed - ignoring\n", part);
}
free(inbuffer);
@@ -454,18 +457,18 @@ static void clic_log_access(size_t block, size_t part)
static ssize_t lastblock = -1;
#endif
- fprintf(logger, "access %ld+8 (part %ld)\n", (long)block*8, (long)part);
+ fprintf(logger, "access %zu+8 (part %zu)\n", block * 8, part);
#if 0
if (lastblock >= 0 && block != (size_t)(lastblock + 1))
{
- fprintf(logger, "access %ld+%ld (part %ld)\n", (long)firstblock*8, (long)(lastblock-firstblock+1)*8, part);
+ fprintf(logger, "access %zu+%zd (part %zu)\n", firstblock * 8, (lastblock - firstblock + 1) * 8, part);
firstblock = block;
}
lastblock = block;
if (block > firstblock + 30)
{
- fprintf(logger, "access %ld+%ld (part %ld)\n", (long)firstblock*8, (long)(lastblock-firstblock+1)*8, part);
+ fprintf(logger, "access %zu+%zd (part %zu)\n", firstblock * 8, (lastblock - firstblock + 1) * 8, part);
firstblock = block;
}
#endif
@@ -485,7 +488,7 @@ static int clic_detach(size_t block)
if ((PTR_CLASS(ptr) == CLASS_RO ) || (PTR_CLASS(ptr) == CLASS_COW))
{
if (PTR_CLASS(ptr) == CLASS_COW) {
- if (logger) fprintf(logger, "detach2 cow %d index\n", cows_index);
+ if (logger) fprintf(logger, "detach2 cow %u index\n", cows_index);
if (cows_index == CLICFS_COW_COUNT - 1) {
ret = clic_write_cow();
if (logger) fprintf(logger, "detach cow %d\n", ret);
@@ -501,11 +504,12 @@ static int clic_detach(size_t block)
assert(newptr);
//if (logger) fprintf(logger, "clic_detach3 %ld\n", PTR_CLASS(newptr));
detached_allocated += (pagesize / 1024);
- if (logger && detached_allocated % 1024 == 0 ) fprintf(logger, "detached %dMB\n", (int)(detached_allocated / 1024));
+ if (logger && detached_allocated % 1024 == 0)
+ fprintf(logger, "detached %" PRIu64 "MB\n", detached_allocated / 1024);
clic_read_block(newptr, block);
if (PTR_CLASS(ptr) == CLASS_COW && !cowfile_ro) { // we need to mark the place in the cow obsolete
- if (logger) fprintf(logger, "detach block %ld (was %ld)\n", (long)block, (long)ptr >> 2);
+ if (logger) fprintf(logger, "detach block %zu (was %lu)\n", block, (long)ptr >> 2);
assert(cows_index < CLICFS_COW_COUNT);
cows[cows_index++] = (long)ptr >> 2;
cow_pages--;
@@ -528,7 +532,8 @@ static int clic_detach(size_t block)
assert(blockmap[block]);
//assert(PTR_CLASS(ptr) == CLASS_MEMORY);
detached_allocated += (pagesize / 1024);
- if (logger && detached_allocated % 1024 == 0 ) fprintf(logger, "detached %dMB\n", (int)(detached_allocated / 1024));
+ if (logger && detached_allocated % 1024 == 0)
+ fprintf(logger, "detached %" PRIu64 "MB\n", detached_allocated / 1024);
memset(blockmap[block],0,pagesize);
}
@@ -541,10 +546,11 @@ static size_t clic_write_block(const char *buf, off_t block, off_t ioff, size_t
{
if (!size) return 0;
- if (logger) fprintf(logger, "clic_write_block %lld block:%lld ioff:%lld size:%lld\n",
- (long long)detached_allocated, (long long)block, (long long)ioff, (long long)size);
+ if (logger)
+ fprintf(logger, "clic_write_block %" PRIu64 " block:%lld ioff:%lld size:%zu\n",
+ detached_allocated, (long long)block, (long long)ioff, size);
if (clic_detach(block)) {
- if (logger) fprintf(logger, "clic_detach FAILED\n");
+ if (logger) fputs("clic_detach FAILED\n", logger);
return -ENOSPC;
}
memcpy(blockmap[block]+ioff, buf, size);
@@ -562,7 +568,9 @@ static int clic_write(const char *path, const char *buf, size_t size, off_t offs
if(path[0] == '/' && strcmp(path + 1, thefile) != 0)
return -ENOENT;
- if (logger) fprintf(logger, "clic_write offset %lld - size %lld (%lld)\n", (long long)offset, (long long)size, (long long)thefilesize);
+ if (logger)
+ fprintf(logger, "clic_write offset %lld - size %zu (%" PRIu64 ")\n",
+ (long long)offset, size, thefilesize);
if (offset >= (off_t)thefilesize) {
@@ -696,7 +704,7 @@ static int clic_flush(const char *path, struct fuse_file_info *fi)
(void)path;
(void)fi;
// TODO write out cow
- if (logger) { fprintf(logger, "flush\n"); fflush(logger); }
+ if (logger) { fputs("flush\n", logger); fflush(logger); }
return clic_write_cow();
}
@@ -706,7 +714,7 @@ static int clic_fsync(const char *path, int datasync, struct fuse_file_info *fi)
(void)fi;
(void)datasync;
// TODO write out cow
- if (logger) { fprintf(logger, "sync\n"); fflush(logger); }
+ if (logger) { fputs("sync\n", logger); fflush(logger); }
int ret = clic_write_cow();
return ret;
@@ -750,7 +758,7 @@ static void* clic_init(struct fuse_conn_info *conn)
static void clic_destroy(void *arg)
{
(void)arg;
- if (logger) fprintf(logger, "destroy\n");
+ if (logger) fputs("destroy\n", logger);
if (clic_sync_tid > 0) {
pthread_cancel(clic_sync_tid);
void *res;
@@ -880,7 +888,7 @@ int main(int argc, char *argv[])
//fuse_opt_add_arg(&args, "-s");
if (!packfilename) {
- fprintf(stderr, "usage: [-m <mb>] [-l <logfile|->] [-c <cowfile>] <packfile> <mntpoint>\n");
+ fputs("usage: [-m <mb>] [-l <logfile|->] [-c <cowfile>] <packfile> <mntpoint>\n", stderr);
return 1;
}
diff --git a/src/clicfs_common.c b/src/clicfs_common.c
index 48bd8bf..64d4fb1 100644
--- a/src/clicfs_common.c
+++ b/src/clicfs_common.c
@@ -31,6 +31,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>
+#include <inttypes.h>
int preset = 0;
int packfilefd = -1;
@@ -113,14 +114,14 @@ int clicfs_read_cow(const char *cowfilename)
char isready = 0;
read(cowfilefd, &isready, 1);
if (isready != 1) {
- fprintf(stderr, "Inconsistent COW file\n");
+ fputs("Inconsistent COW file\n", stderr);
return 1;
}
cow_index_start += sizeof(uint64_t);
thefilesize = clic_readindex_fd64(cowfilefd);
- printf("filesize %lx\n", thefilesize);
+ printf("filesize %" PRIx64 "\n", thefilesize);
uint32_t newpages = thefilesize / pagesize;
blockmap = realloc(blockmap, sizeof(unsigned char*)*newpages);
uint32_t i;
@@ -170,12 +171,12 @@ int clicfs_read_pack(const char *packfilename)
uint32_t stringlen = clic_readindex_fd(packfilefd);
if (stringlen == 0 || stringlen >= PATH_MAX) {
errno = ENAMETOOLONG;
- fprintf(stderr, "abnormal len %lx\n", (long)stringlen);
+ fprintf(stderr, "abnormal len %" PRIx32 "\n", stringlen);
return 1;
}
- if (read(packfilefd, thefile, stringlen) != stringlen) {
+ if (read(packfilefd, thefile, stringlen) != (ssize_t)stringlen) {
errno = EIO;
- fprintf(stderr, "short read %ld\n", (long)stringlen);
+ fprintf(stderr, "short read %" PRIu32 "\n", stringlen);
return 1;
}
thefile[stringlen] = 0;
@@ -205,20 +206,20 @@ int clicfs_read_pack(const char *packfilename)
if (read(packfilefd, (char*)(sizes + i), sizeof(uint64_t)) != sizeof(uint64_t))
parts = 0;
if (!sizes[i]) {
- fprintf(stderr, "unreasonable size 0 for part %d\n", i);
+ fprintf(stderr, "unreasonable size 0 for part %" PRIu32 "\n", i);
errno = EINVAL;
return 1;
}
if (read(packfilefd, (char*)(offs + i), sizeof(uint64_t)) != sizeof(uint64_t))
parts = 0;
if (i > 0 && offs[i] <= offs[i-1]) {
- fprintf(stderr, "the offset for i is not larger than i-1: %ld\n", (long)i);
+ fprintf(stderr, "the offset for i is not larger than i-1: %" PRIu32 "\n", i);
errno = EINVAL;
return 1;
}
}
if (parts == 0) {
- fprintf(stderr, "unreasonable part number 0\n");
+ fputs("unreasonable part number 0\n", stderr);
errno = EINVAL;
return 1;
}
@@ -249,11 +250,14 @@ off_t clic_map_block(off_t block)
size_t clic_readpart(unsigned char *buffer, int part)
{
#if defined(DEBUG)
- fprintf(stderr, "uncompress part=%d/%d off=%ld size=%ld\n", part, parts, offs[part], sizes[part] );
+ fprintf(stderr, "uncompress part=%d/%" PRIu32 " off=%" PRIu64 " size=%" PRIu64 "\n",
+ part, parts, offs[part], sizes[part]);
#endif
ssize_t readin = pread(packfilefd, buffer, sizes[part], offs[part]);
if (readin != (ssize_t)sizes[part]) {
fprintf(stderr, "short read: %d %ld %ld %ld\n", part, (long)offs[part], (long)sizes[part], (long)readin);
+ fprintf(stderr, "short read: %d %" PRIu64 " %" PRIu64 " %zd\n",
+ part, offs[part], sizes[part], (long)readin);
// returning half read blocks won't help lzma
return 0;
}
@@ -275,7 +279,7 @@ int clic_decompress_part(unsigned char *out, const unsigned char *in, size_t rea
while (1) {
ret = lzma_code(&strm, LZMA_RUN);
#if defined(DEBUG)
- fprintf(stderr, "ret %d %ld %ld\n", ret, strm.avail_in, strm.avail_out );
+ fprintf(stderr, "ret %d %zu %zu\n", ret, strm.avail_in, strm.avail_out );
#endif
if (ret != LZMA_OK)
break;
@@ -284,7 +288,7 @@ int clic_decompress_part(unsigned char *out, const unsigned char *in, size_t rea
}
if (ret == LZMA_DATA_ERROR) {
- fprintf(stderr, "lzma data corrupt!\n");
+ fputs("lzma data corrupt!\n", stderr);
pthread_mutex_unlock(&lzma_mutex);
return 0;
}
diff --git a/src/mkclicfs.cpp b/src/mkclicfs.cpp
index 32c8cca..7a42591 100644
--- a/src/mkclicfs.cpp
+++ b/src/mkclicfs.cpp
@@ -504,7 +504,7 @@ int main(int argc, char **argv)
num_pages = st.st_size / pagesize;
/* ext3 should be X blocks */
- if (num_pages * pagesize != st.st_size)
+ if (num_pages * (ssize_t)pagesize != st.st_size)
num_pages++;
// the number of original parts - to be saved in header
diff --git a/src/unclicfs.c b/src/unclicfs.c
index 2063b23..6ec1e97 100644
--- a/src/unclicfs.c
+++ b/src/unclicfs.c
@@ -78,7 +78,7 @@ int main(int argc, char *argv[])
if (++written_pages % delta == 0)
{
- fprintf(stderr, "read %d%%\n", (int)(written_pages * 100 / num_pages));
+ fprintf(stderr, "read %zu%%\n", written_pages * 100 / num_pages);
}
if (fseeko(outfile, page * pagesize, SEEK_SET)) {
perror("seek");