OSDN Git Service

misc: cleanup gcc -Wall warnings
authorTheodore Ts'o <tytso@mit.edu>
Mon, 13 Jul 2015 17:23:28 +0000 (13:23 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 13 Jul 2015 19:36:12 +0000 (15:36 -0400)
Also change ext2fs_symlink() so that the target parameter is a const
char *, thus promising that we will never change the incoming string.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/ext2fs.h
lib/ext2fs/symlink.c
misc/e2fuzz.c
misc/e4crypt.c
misc/filefrag.c
misc/fuse2fs.c
misc/mke2fs.c
misc/tune2fs.c

index e3b8170..86d860f 100644 (file)
@@ -1567,7 +1567,7 @@ errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
 
 /* symlink.c */
 errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
-                        const char *name, char *target);
+                        const char *name, const char *target);
 
 /* mmp.c */
 errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf);
index 279f48b..6e988ad 100644 (file)
@@ -29,7 +29,7 @@
 #include "ext2fs.h"
 
 errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
-                        const char *name, char *target)
+                        const char *name, const char *target)
 {
        errcode_t               retval;
        struct ext2_inode       inode;
@@ -42,7 +42,7 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
        EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
 
        /* The Linux kernel doesn't allow for links longer than a block */
-       target_len = strlen(target);
+       target_len = strnlen(target, fs->blocksize + 1);
        if (target_len > fs->blocksize) {
                retval = EXT2_ET_INVALID_ARGUMENT;
                goto cleanup;
@@ -51,6 +51,12 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
        /*
         * Allocate a data block for slow links
         */
+       retval = ext2fs_get_mem(fs->blocksize+1, &block_buf);
+       if (retval)
+               goto cleanup;
+       memset(block_buf, 0, fs->blocksize+1);
+       strncpy(block_buf, target, fs->blocksize);
+
        memset(&inode, 0, sizeof(struct ext2_inode));
        fastlink = (target_len < sizeof(inode.i_block));
        if (!fastlink) {
@@ -60,9 +66,6 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
                                           NULL, &blk);
                if (retval)
                        goto cleanup;
-               retval = ext2fs_get_mem(fs->blocksize, &block_buf);
-               if (retval)
-                       goto cleanup;
        }
 
        /*
@@ -97,7 +100,7 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
                retval = ext2fs_write_new_inode(fs, ino, &inode);
                if (retval)
                        goto cleanup;
-               retval = ext2fs_inline_data_set(fs, ino, &inode, target,
+               retval = ext2fs_inline_data_set(fs, ino, &inode, block_buf,
                                                target_len);
                if (retval) {
                        inode.i_flags &= ~EXT4_INLINE_DATA_FL;
@@ -109,10 +112,8 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
                        goto cleanup;
        } else {
 need_block:
-               ext2fs_iblk_set(fs, &inode, 1);
                /* Slow symlinks, target stored in the first block */
-               memset(block_buf, 0, fs->blocksize);
-               strncpy(block_buf, target, fs->blocksize);
+               ext2fs_iblk_set(fs, &inode, 1);
                if (fs->super->s_feature_incompat &
                    EXT3_FEATURE_INCOMPAT_EXTENTS) {
                        /*
index f786eac..5e33239 100644 (file)
@@ -42,7 +42,7 @@ static ssize_t my_pwrite(int fd, const void *buf, size_t count, off_t offset)
 }
 #endif /* !defined HAVE_PWRITE64 && !defined HAVE_PWRITE */
 
-int getseed(void)
+static int getseed(void)
 {
        int r;
        int fd;
@@ -65,8 +65,11 @@ struct find_block {
        blk64_t corrupt_blocks;
 };
 
-int find_block_helper(ext2_filsys fs, blk64_t *blocknr, e2_blkcnt_t blockcnt,
-                     blk64_t ref_blk, int ref_offset, void *priv_data)
+static int find_block_helper(ext2_filsys fs EXT2FS_ATTR((unused)),
+                            blk64_t *blocknr, e2_blkcnt_t blockcnt,
+                            blk64_t ref_blk EXT2FS_ATTR((unused)),
+                            int ref_offset EXT2FS_ATTR((unused)),
+                            void *priv_data)
 {
        struct find_block *fb = (struct find_block *)priv_data;
 
@@ -78,8 +81,8 @@ int find_block_helper(ext2_filsys fs, blk64_t *blocknr, e2_blkcnt_t blockcnt,
        return 0;
 }
 
-errcode_t find_metadata_blocks(ext2_filsys fs, ext2fs_block_bitmap bmap,
-                              off_t *corrupt_bytes)
+static errcode_t find_metadata_blocks(ext2_filsys fs, ext2fs_block_bitmap bmap,
+                                     off_t *corrupt_bytes)
 {
        dgrp_t i;
        blk64_t b, c;
@@ -160,10 +163,10 @@ out:
        return retval;
 }
 
-uint64_t rand_num(uint64_t min, uint64_t max)
+static uint64_t rand_num(uint64_t min, uint64_t max)
 {
        uint64_t x;
-       int i;
+       unsigned int i;
        uint8_t *px = (uint8_t *)&x;
 
        for (i = 0; i < sizeof(x); i++)
@@ -172,7 +175,7 @@ uint64_t rand_num(uint64_t min, uint64_t max)
        return min + (uint64_t)((double)(max - min) * (x / (UINT64_MAX + 1.0)));
 }
 
-int process_fs(const char *fsname)
+static int process_fs(const char *fsname)
 {
        errcode_t ret;
        int flags, fd;
@@ -180,7 +183,7 @@ int process_fs(const char *fsname)
        ext2fs_block_bitmap corrupt_map;
        off_t hsize, count, off, offset, corrupt_bytes;
        unsigned char c;
-       unsigned long i;
+       off_t i;
 
        /* If mounted rw, force dryrun mode */
        ret = ext2fs_check_if_mounted(fsname, &flags);
@@ -314,7 +317,7 @@ fail:
        return 1;
 }
 
-void print_help(const char *progname)
+static void print_help(const char *progname)
 {
        printf("Usage: %s OPTIONS device\n", progname);
        printf("-b:     Corrupt this many bytes.\n");
index d92fdf2..ad95bd2 100644 (file)
@@ -93,16 +93,16 @@ static long keyctl(int cmd, ...)
 #endif
 
 #ifndef HAVE_ADD_KEY
-key_serial_t add_key(const char *type, const char *description,
-                    const void *payload, size_t plen,
-                    key_serial_t keyring)
+static key_serial_t add_key(const char *type, const char *description,
+                           const void *payload, size_t plen,
+                           key_serial_t keyring)
 {
        return syscall(__NR_add_key, type, description, payload,
                       plen, keyring);
 }
 #endif
 
-static const char *hexchars = "0123456789abcdef";
+static const unsigned char *hexchars = (const unsigned char *) "0123456789abcdef";
 static const size_t hexchars_size = 16;
 
 #define SHA512_LENGTH 64
@@ -151,11 +151,11 @@ static void validate_paths(int argc, char *argv[], int path_start_index)
                exit(1);
 }
 
-static int hex2byte(const char *hex, size_t hex_size, char *bytes,
+static int hex2byte(const char *hex, size_t hex_size, unsigned char *bytes,
                    size_t bytes_size)
 {
-       int x;
-       char *h, *l;
+       size_t x;
+       unsigned char *h, *l;
 
        if (hex_size % 2)
                return -EINVAL;
@@ -187,11 +187,11 @@ struct salt {
 struct salt *salt_list;
 unsigned num_salt;
 unsigned max_salt;
-char passphrase[EXT4_MAX_PASSPHRASE_SIZE];
+char in_passphrase[EXT4_MAX_PASSPHRASE_SIZE];
 
 static struct salt *find_by_salt(unsigned char *salt, size_t salt_len)
 {
-       int i;
+       unsigned int i;
        struct salt *p;
 
        for (i = 0, p = salt_list; i < num_salt; i++, p++)
@@ -225,7 +225,7 @@ static void clear_secrets(void)
                free(salt_list);
                salt_list = NULL;
        }
-       memset(passphrase, 0, sizeof(passphrase));
+       memset(in_passphrase, 0, sizeof(in_passphrase));
 }
 
 static void die_signal_handler(int signum EXT2FS_ATTR((unused)),
@@ -236,7 +236,7 @@ static void die_signal_handler(int signum EXT2FS_ATTR((unused)),
        exit(-1);
 }
 
-void sigcatcher_setup(void)
+static void sigcatcher_setup(void)
 {
        struct sigaction        sa;
 
@@ -273,7 +273,8 @@ void sigcatcher_setup(void)
 static void parse_salt(char *salt_str, int flags)
 {
        unsigned char buf[EXT4_MAX_SALT_SIZE];
-       unsigned char *salt_buf, *cp = salt_str;
+       char *cp = salt_str;
+       unsigned char *salt_buf;
        int fd, ret, salt_len = 0;
 
        if (flags & PARSE_FLAGS_FORCE_FN)
@@ -283,7 +284,7 @@ static void parse_salt(char *salt_str, int flags)
                salt_len = strlen(cp);
                if (salt_len >= EXT4_MAX_SALT_SIZE)
                        goto invalid_salt;
-               strncpy(buf, cp, sizeof(buf));
+               strncpy((char *) buf, cp, sizeof(buf));
        } else if (cp[0] == '/') {
        salt_from_filename:
                fd = open(cp, O_RDONLY | O_DIRECTORY);
@@ -311,7 +312,7 @@ static void parse_salt(char *salt_str, int flags)
                cp += 2;
                goto salt_from_filename;
        } else if (strncmp(cp, "0x", 2) == 0) {
-               char *h, *l;
+               unsigned char *h, *l;
 
                cp += 2;
                if (strlen(cp) & 1)
@@ -401,27 +402,28 @@ static void set_policy(struct salt *set_salt, int pad,
        }
 }
 
-static void pbkdf2_sha512(const char *passphrase, struct salt *salt, int count,
-                         char derived_key[EXT4_MAX_KEY_SIZE])
+static void pbkdf2_sha512(const char *passphrase, struct salt *salt,
+                         unsigned int count,
+                         unsigned char derived_key[EXT4_MAX_KEY_SIZE])
 {
        size_t passphrase_size = strlen(passphrase);
-       char buf[SHA512_LENGTH + EXT4_MAX_PASSPHRASE_SIZE] = {0};
-       char tempbuf[SHA512_LENGTH] = {0};
+       unsigned char buf[SHA512_LENGTH + EXT4_MAX_PASSPHRASE_SIZE] = {0};
+       unsigned char tempbuf[SHA512_LENGTH] = {0};
        char final[SHA512_LENGTH] = {0};
-       char saltbuf[EXT4_MAX_SALT_SIZE + EXT4_MAX_PASSPHRASE_SIZE] = {0};
+       unsigned char saltbuf[EXT4_MAX_SALT_SIZE + EXT4_MAX_PASSPHRASE_SIZE] = {0};
        int actual_buf_len = SHA512_LENGTH + passphrase_size;
        int actual_saltbuf_len = EXT4_MAX_SALT_SIZE + passphrase_size;
-       int x, y;
+       unsigned int x, y;
        __u32 *final_u32 = (__u32 *)final;
        __u32 *temp_u32 = (__u32 *)tempbuf;
 
        if (passphrase_size > EXT4_MAX_PASSPHRASE_SIZE) {
-               printf("Passphrase size is %d; max is %d.\n", passphrase_size,
+               printf("Passphrase size is %zd; max is %d.\n", passphrase_size,
                       EXT4_MAX_PASSPHRASE_SIZE);
                exit(1);
        }
        if (salt->salt_len > EXT4_MAX_SALT_SIZE) {
-               printf("Salt size is %d; max is %d.\n", salt->salt_len,
+               printf("Salt size is %zd; max is %d.\n", salt->salt_len,
                       EXT4_MAX_SALT_SIZE);
                exit(1);
        }
@@ -463,7 +465,7 @@ static int disable_echo(struct termios *saved_settings)
        return rc;
 }
 
-void get_passphrase(char *passphrase, int len)
+static void get_passphrase(char *passphrase, int len)
 {
        char *p;
        struct termios current_settings;
@@ -500,7 +502,7 @@ static const struct keyring_map keyrings[] = {
 
 static int get_keyring_id(const char *keyring)
 {
-       int x;
+       unsigned int x;
        char *end;
 
        /*
@@ -528,7 +530,7 @@ static int get_keyring_id(const char *keyring)
                        return keyrings[x].code;
                }
        }
-       x = strtol(keyring, &end, 10);
+       x = strtoul(keyring, &end, 10);
        if (*end == '\0') {
                if (keyctl(KEYCTL_DESCRIBE, x, NULL, 0) < 0)
                        return 0;
@@ -539,8 +541,8 @@ static int get_keyring_id(const char *keyring)
 
 static void generate_key_ref_str(struct salt *salt)
 {
-       char key_ref1[SHA512_LENGTH];
-       char key_ref2[SHA512_LENGTH];
+       unsigned char key_ref1[SHA512_LENGTH];
+       unsigned char key_ref2[SHA512_LENGTH];
        int x;
 
        ext2fs_sha512(salt->key, EXT4_MAX_KEY_SIZE, key_ref1);
@@ -600,7 +602,7 @@ static void insert_key_into_keyring(const char *keyring, struct salt *salt)
        }
 }
 
-void get_default_salts(void)
+static void get_default_salts(void)
 {
        FILE    *f = setmntent("/etc/mtab", "r");
        struct mntent *mnt;
@@ -626,7 +628,7 @@ struct cmd_desc {
 
 #define CMD_HIDDEN     0x0001
 
-void do_help(int argc, char **argv, const struct cmd_desc *cmd);
+static void do_help(int argc, char **argv, const struct cmd_desc *cmd);
 
 #define add_key_desc "adds a key to the user's keyring"
 #define add_key_help \
@@ -638,11 +640,12 @@ void do_help(int argc, char **argv, const struct cmd_desc *cmd);
 "set the policy of those directories to use the key just entered by\n" \
 "the user.\n"
 
-void do_add_key(int argc, char **argv, const struct cmd_desc *cmd)
+static void do_add_key(int argc, char **argv, const struct cmd_desc *cmd)
 {
        struct salt *salt;
        char *keyring = NULL;
        int i, opt, pad = 4;
+       unsigned j;
 
        while ((opt = getopt(argc, argv, "k:S:p:vq")) != -1) {
                switch (opt) {
@@ -681,9 +684,9 @@ void do_add_key(int argc, char **argv, const struct cmd_desc *cmd)
        for (i = optind; i < argc; i++)
                parse_salt(argv[i], PARSE_FLAGS_FORCE_FN);
        printf("Enter passphrase (echo disabled): ");
-       get_passphrase(passphrase, sizeof(passphrase));
-       for (i = 0, salt = salt_list; i < num_salt; i++, salt++) {
-               pbkdf2_sha512(passphrase, salt,
+       get_passphrase(in_passphrase, sizeof(in_passphrase));
+       for (j = 0, salt = salt_list; j < num_salt; j++, salt++) {
+               pbkdf2_sha512(in_passphrase, salt,
                              EXT4_PBKDF2_ITERATIONS, salt->key);
                generate_key_ref_str(salt);
                insert_key_into_keyring(keyring, salt);
@@ -703,7 +706,7 @@ void do_add_key(int argc, char **argv, const struct cmd_desc *cmd)
 "policy matches what was specified.  A policy is an encryption key\n" \
 "identifier consisting of 16 hexadecimal characters.\n"
 
-void do_set_policy(int argc, char **argv, const struct cmd_desc *cmd)
+static void do_set_policy(int argc, char **argv, const struct cmd_desc *cmd)
 {
        struct salt saltbuf;
        int c, pad = 4;
@@ -746,7 +749,7 @@ void do_set_policy(int argc, char **argv, const struct cmd_desc *cmd)
 "e4crypt get_policy path ... \n\n" \
 "Gets the policy for the directories specified on the command line.\n"
 
-void do_get_policy(int argc, char **argv, const struct cmd_desc *cmd)
+static void do_get_policy(int argc, char **argv, const struct cmd_desc *cmd)
 {
        struct ext4_encryption_policy policy;
        struct stat st;
@@ -792,8 +795,8 @@ void do_get_policy(int argc, char **argv, const struct cmd_desc *cmd)
 "Give the invoking process (typically a shell) a new session keyring,\n" \
 "discarding its old session keyring.\n"
 
-void do_new_session(int argc, char **argv EXT2FS_ATTR((unused)),
-                   const struct cmd_desc *cmd)
+static void do_new_session(int argc, char **argv EXT2FS_ATTR((unused)),
+                          const struct cmd_desc *cmd)
 {
        long keyid, ret;
 
@@ -828,8 +831,8 @@ const struct cmd_desc cmd_list[] = {
        { NULL, NULL, NULL, NULL, 0 }
 };
 
-void do_help(int argc, char **argv,
-            const struct cmd_desc *cmd EXT2FS_ATTR((unused)))
+static void do_help(int argc, char **argv,
+                   const struct cmd_desc *cmd EXT2FS_ATTR((unused)))
 {
        const struct cmd_desc *p;
 
@@ -865,6 +868,7 @@ int main(int argc, char *argv[])
        if (argc < 2)
                do_help(argc, argv, cmd_list);
 
+       sigcatcher_setup();
        for (cmd = cmd_list; cmd->cmd_name; cmd++) {
                if (strcmp(cmd->cmd_name, argv[1]) == 0) {
                        cmd->cmd_func(argc-1, argv+1, cmd);
index 46f1218..5bcde91 100644 (file)
@@ -20,7 +20,13 @@ int main(void) {
        exit(EXIT_FAILURE);
 }
 #else
+#ifndef _LARGEFILE_SOURCE
+#define _LARGEFILE_SOURCE
+#endif
+#ifndef _LARGEFILE64_SOURCE
 #define _LARGEFILE64_SOURCE
+#endif
+
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -181,7 +187,8 @@ static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex,
                print_flag(&fe_flags, mask, flags, hex);
        }
 
-       if (fm_extent->fe_logical + fm_extent->fe_length >= st->st_size)
+       if (fm_extent->fe_logical + fm_extent->fe_length >=
+           (unsigned long long) st->st_size)
                strcat(flags, "eof,");
 
        /* Remove trailing comma, if any */
index ac869fb..5b89821 100644 (file)
@@ -10,7 +10,9 @@
  */
 #define _FILE_OFFSET_BITS 64
 #define FUSE_USE_VERSION 29
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
 #include "config.h"
 #include <pthread.h>
 #ifdef __linux__
@@ -184,7 +186,7 @@ static errcode_t fuse_to_ext4_acl(acl_ea_header *facl, size_t facl_sz,
        size_t h_sz;
        ext4_acl_entry *e;
        acl_ea_entry *a;
-       void *hptr;
+       unsigned char *hptr;
        errcode_t err;
 
        facl_count = acl_ea_count(facl_sz);
@@ -197,9 +199,9 @@ static errcode_t fuse_to_ext4_acl(acl_ea_header *facl, size_t facl_sz,
                return err;
 
        h->a_version = ext2fs_cpu_to_le32(EXT4_ACL_VERSION);
-       hptr = h + 1;
+       hptr = (unsigned char *) (h + 1);
        for (i = 0, a = facl->a_entries; i < facl_count; i++, a++) {
-               e = hptr;
+               e = (ext4_acl_entry *) hptr;
                e->e_tag = ext2fs_cpu_to_le16(a->e_tag);
                e->e_perm = ext2fs_cpu_to_le16(a->e_perm);
 
@@ -237,7 +239,7 @@ static errcode_t ext4_to_fuse_acl(acl_ea_header **facl, size_t *facl_sz,
        ext4_acl_entry *e;
        acl_ea_entry *a;
        size_t f_sz;
-       void *hptr;
+       unsigned char *hptr;
        errcode_t err;
 
        eacl_count = ext4_acl_count(eacl_sz);
@@ -251,9 +253,9 @@ static errcode_t ext4_to_fuse_acl(acl_ea_header **facl, size_t *facl_sz,
                return err;
 
        f->a_version = ACL_EA_VERSION;
-       hptr = eacl + 1;
+       hptr = (unsigned char *) (eacl + 1);
        for (i = 0, a = f->a_entries; i < eacl_count; i++, a++) {
-               e = hptr;
+               e = (ext4_acl_entry *) hptr;
                a->e_tag = ext2fs_le16_to_cpu(e->e_tag);
                a->e_perm = ext2fs_le16_to_cpu(e->e_perm);
 
@@ -347,7 +349,7 @@ static int __translate_error(ext2_filsys fs, errcode_t err, ext2_ino_t ino,
 #define EXT4_FITS_IN_INODE(ext4_inode, field)          \
        ((offsetof(typeof(*ext4_inode), field) +        \
          sizeof((ext4_inode)->field))                  \
-       <= (EXT2_GOOD_OLD_INODE_SIZE +                  \
+        <= ((size_t) EXT2_GOOD_OLD_INODE_SIZE +                \
            (ext4_inode)->i_extra_isize))               \
 
 static inline __u32 ext4_encode_extra_time(const struct timespec *time)
@@ -608,7 +610,7 @@ static int fs_writeable(ext2_filsys fs)
        return (fs->flags & EXT2_FLAG_RW) && (fs->super->s_error_count == 0);
 }
 
-static int check_inum_access(ext2_filsys fs, ext2_ino_t ino, int mask)
+static int check_inum_access(ext2_filsys fs, ext2_ino_t ino, mode_t mask)
 {
        struct fuse_context *ctxt = fuse_get_context();
        struct ext2_inode inode;
@@ -677,7 +679,7 @@ static int check_inum_access(ext2_filsys fs, ext2_ino_t ino, int mask)
        return -EACCES;
 }
 
-static void op_destroy(void *p)
+static void op_destroy(void *p EXT2FS_ATTR((unused)))
 {
        struct fuse_context *ctxt = fuse_get_context();
        struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -1449,7 +1451,7 @@ static int op_symlink(const char *src, const char *dest)
 
 
        /* Create symlink */
-       err = ext2fs_symlink(fs, parent, 0, node_name, (char *)src);
+       err = ext2fs_symlink(fs, parent, 0, node_name, src);
        if (err == EXT2_ET_DIR_NO_SPACE) {
                err = ext2fs_expand_dir(fs, parent);
                if (err) {
@@ -1457,7 +1459,7 @@ static int op_symlink(const char *src, const char *dest)
                        goto out2;
                }
 
-               err = ext2fs_symlink(fs, parent, 0, node_name, (char *)src);
+               err = ext2fs_symlink(fs, parent, 0, node_name, src);
        }
        if (err) {
                ret = translate_error(fs, parent, err);
@@ -1508,9 +1510,13 @@ struct update_dotdot {
        ext2_ino_t new_dotdot;
 };
 
-static int update_dotdot_helper(ext2_ino_t dir, int entry,
-                               struct ext2_dir_entry *dirent, int offset,
-                               int blocksize, char *buf, void *priv_data)
+static int update_dotdot_helper(ext2_ino_t dir EXT2FS_ATTR((unused)),
+                               int entry EXT2FS_ATTR((unused)),
+                               struct ext2_dir_entry *dirent,
+                               int offset EXT2FS_ATTR((unused)),
+                               int blocksize EXT2FS_ATTR((unused)),
+                               char *buf EXT2FS_ATTR((unused)),
+                               void *priv_data)
 {
        struct update_dotdot *ud = priv_data;
 
@@ -1940,7 +1946,7 @@ static int op_chown(const char *path, uid_t owner, gid_t group)
        }
 
        /* FUSE seems to feed us ~0 to mean "don't change" */
-       if (owner != ~0) {
+       if (owner != (uid_t) ~0) {
                /* Only root gets to change UID. */
                if (ctxt->uid != 0 &&
                    !(inode.i_uid == ctxt->uid && owner == ctxt->uid)) {
@@ -1950,7 +1956,7 @@ static int op_chown(const char *path, uid_t owner, gid_t group)
                inode.i_uid = owner;
        }
 
-       if (group != ~0) {
+       if (group != (gid_t) ~0) {
                /* Only root or the owner get to change GID. */
                if (ctxt->uid != 0 && inode.i_uid != ctxt->uid) {
                        ret = -EPERM;
@@ -2130,8 +2136,9 @@ static int op_open(const char *path, struct fuse_file_info *fp)
        return ret;
 }
 
-static int op_read(const char *path, char *buf, size_t len, off_t offset,
-                    struct fuse_file_info *fp)
+static int op_read(const char *path EXT2FS_ATTR((unused)), char *buf,
+                  size_t len, off_t offset,
+                  struct fuse_file_info *fp)
 {
        struct fuse_context *ctxt = fuse_get_context();
        struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -2182,11 +2189,12 @@ out2:
        }
 out:
        pthread_mutex_unlock(&ff->bfl);
-       return got ? got : ret;
+       return got ? (int) got : ret;
 }
 
-static int op_write(const char *path, const char *buf, size_t len, off_t offset,
-                     struct fuse_file_info *fp)
+static int op_write(const char *path EXT2FS_ATTR((unused)),
+                   const char *buf, size_t len, off_t offset,
+                   struct fuse_file_info *fp)
 {
        struct fuse_context *ctxt = fuse_get_context();
        struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -2253,10 +2261,11 @@ out2:
 
 out:
        pthread_mutex_unlock(&ff->bfl);
-       return got ? got : ret;
+       return got ? (int) got : ret;
 }
 
-static int op_release(const char *path, struct fuse_file_info *fp)
+static int op_release(const char *path EXT2FS_ATTR((unused)),
+                     struct fuse_file_info *fp)
 {
        struct fuse_context *ctxt = fuse_get_context();
        struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -2283,7 +2292,9 @@ static int op_release(const char *path, struct fuse_file_info *fp)
        return ret;
 }
 
-static int op_fsync(const char *path, int datasync, struct fuse_file_info *fp)
+static int op_fsync(const char *path EXT2FS_ATTR((unused)),
+                   int datasync EXT2FS_ATTR((unused)),
+                   struct fuse_file_info *fp)
 {
        struct fuse_context *ctxt = fuse_get_context();
        struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -2308,7 +2319,8 @@ static int op_fsync(const char *path, int datasync, struct fuse_file_info *fp)
        return ret;
 }
 
-static int op_statfs(const char *path, struct statvfs *buf)
+static int op_statfs(const char *path EXT2FS_ATTR((unused)),
+                    struct statvfs *buf)
 {
        struct fuse_context *ctxt = fuse_get_context();
        struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -2358,7 +2370,7 @@ static int op_statfs(const char *path, struct statvfs *buf)
 typedef errcode_t (*xattr_xlate_get)(void **cooked_buf, size_t *cooked_sz,
                                     const void *raw_buf, size_t raw_sz);
 typedef errcode_t (*xattr_xlate_set)(const void *cooked_buf, size_t cooked_sz,
-                                    void **raw_buf, size_t *raw_sz);
+                                    const void **raw_buf, size_t *raw_sz);
 struct xattr_translate {
        const char *prefix;
        xattr_xlate_get get;
@@ -2463,7 +2475,8 @@ out:
        return ret;
 }
 
-static int count_buffer_space(char *name, char *value, size_t value_len,
+static int count_buffer_space(char *name, char *value EXT2FS_ATTR((unused)),
+                             size_t value_len EXT2FS_ATTR((unused)),
                              void *data)
 {
        unsigned int *x = data;
@@ -2472,7 +2485,8 @@ static int count_buffer_space(char *name, char *value, size_t value_len,
        return 0;
 }
 
-static int copy_names(char *name, char *value, size_t value_len, void *data)
+static int copy_names(char *name, char *value EXT2FS_ATTR((unused)),
+                     size_t value_len EXT2FS_ATTR((unused)), void *data)
 {
        char **b = data;
 
@@ -2559,15 +2573,16 @@ out:
        return ret;
 }
 
-static int op_setxattr(const char *path, const char *key, const char *value,
-                      size_t len, int flags)
+static int op_setxattr(const char *path EXT2FS_ATTR((unused)),
+                      const char *key, const char *value,
+                      size_t len, int flags EXT2FS_ATTR((unused)))
 {
        struct fuse_context *ctxt = fuse_get_context();
        struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
        ext2_filsys fs;
        struct ext2_xattr_handle *h;
        struct xattr_translate *xt;
-       void *cvalue;
+       const void *cvalue;
        size_t clen;
        ext2_ino_t ino;
        errcode_t err;
@@ -2608,7 +2623,7 @@ static int op_setxattr(const char *path, const char *key, const char *value,
                goto out2;
        }
 
-       cvalue = (void *)value;
+       cvalue = value;
        clen = len;
        for (xt = xattr_translators; xt->prefix != NULL; xt++) {
                if (strncmp(key, xt->prefix, strlen(xt->prefix)) == 0) {
@@ -2719,9 +2734,12 @@ struct readdir_iter {
        fuse_fill_dir_t func;
 };
 
-static int op_readdir_iter(ext2_ino_t dir, int entry,
-                          struct ext2_dir_entry *dirent, int offset,
-                          int blocksize, char *buf, void *data)
+static int op_readdir_iter(ext2_ino_t dir EXT2FS_ATTR((unused)),
+                          int entry EXT2FS_ATTR((unused)),
+                          struct ext2_dir_entry *dirent,
+                          int offset EXT2FS_ATTR((unused)),
+                          int blocksize EXT2FS_ATTR((unused)),
+                          char *buf EXT2FS_ATTR((unused)), void *data)
 {
        struct readdir_iter *i = data;
        char namebuf[EXT2_NAME_LEN + 1];
@@ -2736,8 +2754,10 @@ static int op_readdir_iter(ext2_ino_t dir, int entry,
        return 0;
 }
 
-static int op_readdir(const char *path, void *buf, fuse_fill_dir_t fill_func,
-                     off_t offset, struct fuse_file_info *fp)
+static int op_readdir(const char *path EXT2FS_ATTR((unused)),
+                     void *buf, fuse_fill_dir_t fill_func,
+                     off_t offset EXT2FS_ATTR((unused)),
+                     struct fuse_file_info *fp)
 {
        struct fuse_context *ctxt = fuse_get_context();
        struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -2919,7 +2939,8 @@ out:
        return ret;
 }
 
-static int op_ftruncate(const char *path, off_t len, struct fuse_file_info *fp)
+static int op_ftruncate(const char *path EXT2FS_ATTR((unused)),
+                       off_t len, struct fuse_file_info *fp)
 {
        struct fuse_context *ctxt = fuse_get_context();
        struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -2969,7 +2990,8 @@ out:
        return 0;
 }
 
-static int op_fgetattr(const char *path, struct stat *statbuf,
+static int op_fgetattr(const char *path EXT2FS_ATTR((unused)),
+                      struct stat *statbuf,
                       struct fuse_file_info *fp)
 {
        struct fuse_context *ctxt = fuse_get_context();
@@ -2993,7 +3015,7 @@ static int op_utimens(const char *path, const struct timespec ctv[2])
 {
        struct fuse_context *ctxt = fuse_get_context();
        struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
-       struct timespec *tv = (struct timespec *)ctv;
+       struct timespec tv[2];
        ext2_filsys fs;
        errcode_t err;
        ext2_ino_t ino;
@@ -3022,6 +3044,8 @@ static int op_utimens(const char *path, const struct timespec ctv[2])
                goto out;
        }
 
+       tv[0] = ctv[0];
+       tv[1] = ctv[1];
 #ifdef UTIME_NOW
        if (tv[0].tv_nsec == UTIME_NOW)
                get_now(tv);
@@ -3219,8 +3243,10 @@ static int ioctl_fitrim(ext2_filsys fs, struct fuse2fs_file_handle *fh,
 #endif /* FITRIM */
 
 #if FUSE_VERSION >= FUSE_MAKE_VERSION(2, 8)
-static int op_ioctl(const char *path, int cmd, void *arg,
-                     struct fuse_file_info *fp, unsigned int flags, void *data)
+static int op_ioctl(const char *path EXT2FS_ATTR((unused)), int cmd,
+                   void *arg EXT2FS_ATTR((unused)),
+                   struct fuse_file_info *fp,
+                   unsigned int flags EXT2FS_ATTR((unused)), void *data)
 {
        struct fuse_context *ctxt = fuse_get_context();
        struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -3231,7 +3257,7 @@ static int op_ioctl(const char *path, int cmd, void *arg,
        FUSE2FS_CHECK_CONTEXT(ff);
        fs = ff->fs;
        pthread_mutex_lock(&ff->bfl);
-       switch (cmd) {
+       switch ((unsigned long) cmd) {
 #ifdef SUPPORT_I_FLAGS
        case EXT2_IOC_GETFLAGS:
                ret = ioctl_getflags(fs, fh, data);
@@ -3261,7 +3287,8 @@ static int op_ioctl(const char *path, int cmd, void *arg,
 }
 #endif /* FUSE 28 */
 
-static int op_bmap(const char *path, size_t blocksize, uint64_t *idx)
+static int op_bmap(const char *path, size_t blocksize EXT2FS_ATTR((unused)),
+                  uint64_t *idx)
 {
        struct fuse_context *ctxt = fuse_get_context();
        struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -3334,7 +3361,7 @@ static int fallocate_helper(struct fuse_file_info *fp, int mode, off_t offset,
 
        /* Update i_size */
        if (!(mode & FL_KEEP_SIZE_FLAG)) {
-               if (offset + len > fsize) {
+               if ((__u64) offset + len > fsize) {
                        err = ext2fs_inode_size_set(fs,
                                                (struct ext2_inode *)&inode,
                                                offset + len);
@@ -3496,7 +3523,8 @@ static int punch_helper(struct fuse_file_info *fp, int mode, off_t offset,
        return 0;
 }
 
-static int op_fallocate(const char *path, int mode, off_t offset, off_t len,
+static int op_fallocate(const char *path EXT2FS_ATTR((unused)), int mode,
+                       off_t offset, off_t len,
                        struct fuse_file_info *fp)
 {
        struct fuse_context *ctxt = fuse_get_context();
@@ -3586,16 +3614,16 @@ static int get_random_bytes(void *p, size_t sz)
        int fd;
        ssize_t r;
 
-       fd = open("/dev/random", O_RDONLY);
+       fd = open("/dev/urandom", O_RDONLY);
        if (fd < 0) {
-               perror("/dev/random");
+               perror("/dev/urandom");
                return 0;
        }
 
        r = read(fd, p, sz);
 
        close(fd);
-       return r == sz;
+       return (size_t) r == sz;
 }
 
 static void print_help(const char *progname)
index 68fbb66..179a4d1 100644 (file)
@@ -195,7 +195,7 @@ static int is_before_linux_ver(unsigned int major, unsigned int minor,
        if (linux_version_code == 0)
                return 0;
 
-       return linux_version_code < KERNEL_VERSION(major, minor, rev);
+       return linux_version_code < (int) KERNEL_VERSION(major, minor, rev);
 }
 #else
 static int is_before_linux_ver(unsigned int major, unsigned int minor,
@@ -1394,11 +1394,11 @@ static const char *default_files[] = { "<default>", 0 };
  * device's alignment offset, if any, or a negative error.
  */
 static int get_device_geometry(const char *file,
-                              struct ext2_super_block *fs_param,
-                              int psector_size)
+                              struct ext2_super_block *param,
+                              unsigned int psector_size)
 {
        int rc = -1;
-       int blocksize;
+       unsigned int blocksize;
        blkid_probe pr;
        blkid_topology tp;
        unsigned long min_io;
@@ -1419,7 +1419,7 @@ static int get_device_geometry(const char *file,
 
        min_io = blkid_topology_get_minimum_io_size(tp);
        opt_io = blkid_topology_get_optimal_io_size(tp);
-       blocksize = EXT2_BLOCK_SIZE(fs_param);
+       blocksize = EXT2_BLOCK_SIZE(param);
        if ((min_io == 0) && (psector_size > blocksize))
                min_io = psector_size;
        if ((opt_io == 0) && min_io)
@@ -1429,9 +1429,9 @@ static int get_device_geometry(const char *file,
 
        /* setting stripe/stride to blocksize is pointless */
        if (min_io > blocksize)
-               fs_param->s_raid_stride = min_io / blocksize;
+               param->s_raid_stride = min_io / blocksize;
        if (opt_io > blocksize)
-               fs_param->s_raid_stripe_width = opt_io / blocksize;
+               param->s_raid_stripe_width = opt_io / blocksize;
 
        rc = blkid_topology_get_alignment_offset(tp);
 out:
@@ -2179,7 +2179,8 @@ profile_error:
        }
 
 #ifdef HAVE_BLKID_PROBE_GET_TOPOLOGY
-       retval = get_device_geometry(device_name, &fs_param, psector_size);
+       retval = get_device_geometry(device_name, &fs_param,
+                                    (unsigned int) psector_size);
        if (retval < 0) {
                fprintf(stderr,
                        _("warning: Unable to get device geometry for %s\n"),
index be03168..f9ce38c 100644 (file)
@@ -2583,7 +2583,7 @@ err:
        return retval;
 }
 
-int
+static int
 fs_update_journal_user(struct ext2_super_block *sb, __u8 old_uuid[UUID_SIZE])
 {
        int retval, nr_users, start;
@@ -2659,6 +2659,7 @@ int tune2fs_main(int argc, char **argv)
        struct ext2_super_block *sb;
        io_manager io_ptr, io_ptr_orig = NULL;
        int rc = 0;
+       char default_undo_file[1] = { 0 };
 
 #ifdef ENABLE_NLS
        setlocale(LC_MESSAGES, "");
@@ -2760,7 +2761,7 @@ retry_open:
                 * If inode resize is requested use the
                 * Undo I/O manager
                 */
-               undo_file = "";
+               undo_file = default_undo_file;
        }
 
        /* Set up an undo file */