]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
Fix signed/unsigned compiler warnings
authorTheodore Ts'o <tytso@mit.edu>
Wed, 21 May 2025 17:44:24 +0000 (13:44 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 21 May 2025 17:44:24 +0000 (13:44 -0400)
Fixes: a5a6bcfb4820 ("libext2fs: make unix_io cache size configurable")
Fixes: 516805378ff5 ("fuse2fs: allow setting of the cache size")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/unix_io.c
misc/fuse2fs.c

index fba206abf03bd0f5e86f2dcaa13ff40057f84f79..dbe748d9c4358346c2d59c4056c353e2990f656b 100644 (file)
@@ -509,7 +509,7 @@ static errcode_t alloc_cache(io_channel channel,
 {
        errcode_t               retval;
        struct unix_cache       *cache;
-       int                     i;
+       unsigned int            i;
 
        data->access_time = 0;
        for (i=0, cache = data->cache; i < data->cache_size; i++, cache++) {
@@ -535,7 +535,7 @@ static errcode_t alloc_cache(io_channel channel,
 static void free_cache(struct unix_private_data *data)
 {
        struct unix_cache       *cache;
-       int                     i;
+       unsigned int            i;
 
        data->access_time = 0;
        for (i=0, cache = data->cache; i < data->cache_size; i++, cache++) {
@@ -557,7 +557,7 @@ static void free_cache(struct unix_private_data *data)
 #define CACHE_LINE_SIZE                64
 
 /* buffer cache hashing function, crudely stolen from xfsprogs */
-unsigned int
+static unsigned int
 cache_hash(struct unix_private_data *data, blk64_t blkno)
 {
        uint64_t        hashval = blkno;
@@ -583,7 +583,7 @@ static struct unix_cache *find_cached_block(struct unix_private_data *data,
 {
        struct unix_cache       *cache, *unused_cache, *oldest_cache;
        unsigned int            hash = cache_hash(data, block);
-       int                     i;
+       unsigned int            i;
 
        unused_cache = oldest_cache = 0;
        /* walk [hash..] cache elements */
@@ -664,7 +664,7 @@ static errcode_t flush_cached_blocks(io_channel channel,
 {
        struct unix_cache       *cache;
        errcode_t               retval, retval2 = 0;
-       int                     i;
+       unsigned int            i;
        int                     errors_found = 0;
 
        if ((flags & FLUSH_NOLOCK) == 0)
@@ -732,7 +732,7 @@ static errcode_t shrink_cache(io_channel channel,
                              unsigned int new_size)
 {
        struct unix_cache       *cache, *new_cache;
-       int                     i;
+       unsigned int            i;
        errcode_t               retval;
 
        mutex_lock(data, CACHE_MTX);
@@ -774,7 +774,7 @@ static errcode_t grow_cache(io_channel channel,
                            unsigned int new_size)
 {
        struct unix_cache       *cache, *new_cache;
-       int                     i;
+       unsigned int            i;
        errcode_t               retval;
 
        mutex_lock(data, CACHE_MTX);
index 99ef573cac39228bd746c9737f4f1511a9785eed..58c80c5c9a1ea29d8e2ab6cc0986fcc49d4d2c77 100644 (file)
@@ -3884,6 +3884,8 @@ out_default:
 static unsigned long long default_cache_size(void)
 {
        long pages = 0, pagesize = 0;
+       unsigned long long max_cache;
+       unsigned long long ret = 32ULL << 20; /* 32 MB */
 
 #ifdef _SC_PHYS_PAGES
        pages = sysconf(_SC_PHYS_PAGES);
@@ -3891,11 +3893,12 @@ static unsigned long long default_cache_size(void)
 #ifdef _SC_PAGESIZE
        pagesize = sysconf(_SC_PAGESIZE);
 #endif
-       long long max_cache = (long long)pagesize * pages / 20;
-       unsigned long long ret = 32ULL << 20; /* 32 MB */
+       if (pages > 0 && pagesize > 0) {
+               max_cache = (unsigned long long)pagesize * pages / 20;
 
-       if (max_cache > 0 && ret > max_cache)
-               return max_cache;
+               if (max_cache > 0 && ret > max_cache)
+                       ret = max_cache;
+       }
        return ret;
 }