OSDN Git Service

Make vold compile with -Werror -Wall.
authorTim Murray <timmurray@google.com>
Mon, 15 Dec 2014 19:56:11 +0000 (11:56 -0800)
committerTim Murray <timmurray@google.com>
Thu, 18 Dec 2014 00:21:21 +0000 (00:21 +0000)
-Wno-missing-field-initializers is used as well, but that is an
overzealous warning from initializing structs with {0} and not a
real warning.

bug 18736778 and 16868177

Change-Id: Iffde89cd7200d9a11193e1614f1819f9fcace30a

Android.mk
CheckBattery.cpp
CommandListener.cpp
Devmapper.cpp
Ext4.cpp
Fat.cpp
Process.cpp
Volume.cpp
VolumeManager.cpp
cryptfs.c

index cde66d9..f4ba3f3 100644 (file)
@@ -61,6 +61,7 @@ LOCAL_C_INCLUDES := $(common_c_includes)
 LOCAL_SHARED_LIBRARIES := $(common_shared_libraries)
 LOCAL_STATIC_LIBRARIES := $(common_static_libraries)
 LOCAL_MODULE_TAGS := eng tests
+LOCAL_CFLAGS := -Werror -Wall -Wno-missing-field-initializers
 
 LOCAL_CXX_STL := libc++
 include $(BUILD_STATIC_LIBRARY)
@@ -75,7 +76,7 @@ LOCAL_SRC_FILES := \
        $(common_src_files)
 
 LOCAL_C_INCLUDES := $(common_c_includes)
-LOCAL_CFLAGS := -Werror=format
+LOCAL_CFLAGS := -Werror -Wall -Wno-missing-field-initializers
 LOCAL_SHARED_LIBRARIES := $(common_shared_libraries)
 LOCAL_STATIC_LIBRARIES := $(common_static_libraries)
 
@@ -89,5 +90,6 @@ LOCAL_CLANG := false
 LOCAL_SRC_FILES:= vdc.c
 LOCAL_MODULE:= vdc
 LOCAL_SHARED_LIBRARIES := libcutils
+LOCAL_CFLAGS := -Werror -Wall -Wno-missing-field-initializers
 
 include $(BUILD_EXECUTABLE)
index 21d426b..6390d02 100644 (file)
 
 using namespace android;
 
-namespace
-{
-    // How often to check battery in seconds
-    const int CHECK_PERIOD = 30;
-
-    // How charged should the battery be (percent) to start encrypting
-    const int START_THRESHOLD = 10;
-
-    // How charged should the battery be (percent) to continue encrypting
-    const int CONTINUE_THRESHOLD = 5;
-
-    const String16 serviceName("batteryproperties");
-
-    sp<IBinder> bs;
-    sp<IBatteryPropertiesRegistrar> interface;
-
-    bool singletonInitialized = false;
-    time_t last_checked = {0};
-    int last_result = 100;
-
-    int is_battery_ok(int threshold)
-    {
-        time_t now = time(NULL);
-        if (now == -1 || difftime(now, last_checked) < 5) {
-            goto finish;
-        }
-        last_checked = now;
-
-        if (!singletonInitialized) {
-            bs = defaultServiceManager()->checkService(serviceName);
-            if (bs == NULL) {
-                SLOGE("No batteryproperties service!");
-                goto finish;
-            }
-
-            interface = interface_cast<IBatteryPropertiesRegistrar>(bs);
-            if (interface == NULL) {
-                SLOGE("No IBatteryPropertiesRegistrar interface");
-                goto finish;
-            }
-
-            singletonInitialized = true;
-        }
-
-        {
-            BatteryProperty val;
-            status_t status = interface
-                ->getProperty(android::BATTERY_PROP_CAPACITY, &val);
-            if (status == NO_ERROR) {
-                SLOGD("Capacity is %d", (int)val.valueInt64);
-                last_result = val.valueInt64;
-            } else {
-                SLOGE("Failed to get battery charge");
-                last_result = 100;
-            }
-        }
-
-    finish:
-        return last_result >= threshold;
-    }
-}
-
 extern "C"
 {
     int is_battery_ok_to_start()
index 8003095..261da8e 100644 (file)
@@ -216,7 +216,6 @@ int CommandListener::VolumeCmd::runCommand(SocketClient *cli,
     if (!rc) {
         cli->sendMsg(ResponseCode::CommandOkay, "volume operation succeeded", false);
     } else {
-        int erno = errno;
         rc = ResponseCode::convertFromErrno();
         cli->sendMsg(rc, "volume operation failed", true);
     }
index 700e538..703902f 100644 (file)
@@ -296,7 +296,7 @@ int Devmapper::destroy(const char *name) {
 
 void *Devmapper::_align(void *ptr, unsigned int a)
 {
-        register unsigned long agn = --a;
+        unsigned long agn = --a;
 
         return (void *) (((unsigned long) ptr + agn) & ~agn);
 }
index dc31fd0..f5a964a 100644 (file)
--- a/Ext4.cpp
+++ b/Ext4.cpp
@@ -112,7 +112,6 @@ int Ext4::resize(const char *fspath, unsigned int numSectors) {
 }
 
 int Ext4::format(const char *fsPath, unsigned int numSectors, const char *mountpoint) {
-    int fd;
     const char *args[7];
     int rc;
     int status;
diff --git a/Fat.cpp b/Fat.cpp
index cd4ea5f..6ac1f8a 100644 (file)
--- a/Fat.cpp
+++ b/Fat.cpp
@@ -50,7 +50,6 @@ static char MKDOSFS_PATH[] = "/system/bin/newfs_msdos";
 extern "C" int mount(const char *, const char *, const char *, unsigned long, const void *);
 
 int Fat::check(const char *fsPath) {
-    bool rw = true;
     if (access(FSCK_MSDOS_PATH, X_OK)) {
         SLOGW("Skipping fs checks\n");
         return 0;
@@ -170,7 +169,6 @@ int Fat::doMount(const char *fsPath, const char *mountPoint,
 }
 
 int Fat::format(const char *fsPath, unsigned int numSectors, bool wipe) {
-    int fd;
     const char *args[11];
     int rc;
     int status;
index 08be28e..b675436 100644 (file)
@@ -191,7 +191,6 @@ void Process::killProcessesWithOpenFiles(const char *path, int action) {
     }
 
     while ((de = readdir(dir))) {
-        int killed = 0;
         int pid = getPid(de->d_name);
         char name[PATH_MAX];
 
index bfad29d..75cc4c1 100644 (file)
@@ -332,7 +332,7 @@ bool Volume::isMountpointMounted(const char *path) {
 
 int Volume::mountVol() {
     dev_t deviceNodes[4];
-    int n, i, rc = 0;
+    int n, i;
     char errmsg[255];
 
     int flags = getFlags();
@@ -454,7 +454,6 @@ int Volume::mountVol() {
         }
 
         errno = 0;
-        int gid;
 
         if (Fat::doMount(devicePath, getMountpoint(), false, false, false,
                 AID_MEDIA_RW, AID_MEDIA_RW, 0007, true)) {
@@ -549,8 +548,6 @@ int Volume::doUnmount(const char *path, bool force) {
 }
 
 int Volume::unmountVol(bool force, bool revert) {
-    int i, rc;
-
     int flags = getFlags();
     bool providesAsec = (flags & VOL_PROVIDES_ASEC) != 0;
 
index 14f1509..0409ce8 100644 (file)
@@ -238,7 +238,9 @@ int VolumeManager::addVolume(Volume *v) {
 }
 
 void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
+#ifdef NETLINK_DEBUG
     const char *devpath = evt->findParam("DEVPATH");
+#endif
 
     /* Lookup a volume to handle this device */
     VolumeCollection::iterator it;
@@ -1216,8 +1218,6 @@ bool VolumeManager::isAsecInDirectory(const char *dir, const char *asecName) con
 
 int VolumeManager::findAsec(const char *id, char *asecPath, size_t asecPathLen,
         const char **directory) const {
-    int dirfd, fd;
-    const int idLen = strlen(id);
     char *asecName;
 
     if (!isLegalAsecId(id)) {
@@ -1297,7 +1297,7 @@ int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid, bool
 
     char dmDevice[255];
     bool cleanupDm = false;
-    int fd;
+
     unsigned int nr_sec = 0;
     struct asec_superblock sb;
 
index a29053b..aefc606 100644 (file)
--- a/cryptfs.c
+++ b/cryptfs.c
@@ -473,7 +473,7 @@ static int get_crypt_ftr_info(char **metadata_fname, off64_t *off)
 static int put_crypt_ftr_and_key(struct crypt_mnt_ftr *crypt_ftr)
 {
   int fd;
-  unsigned int nr_sec, cnt;
+  unsigned int cnt;
   /* starting_off is set to the SEEK_SET offset
    * where the crypto structure starts
    */
@@ -612,7 +612,7 @@ static void upgrade_crypt_ftr(int fd, struct crypt_mnt_ftr *crypt_ftr, off64_t o
 static int get_crypt_ftr_and_key(struct crypt_mnt_ftr *crypt_ftr)
 {
   int fd;
-  unsigned int nr_sec, cnt;
+  unsigned int cnt;
   off64_t starting_off;
   int rc = -1;
   char *fname = NULL;
@@ -805,7 +805,6 @@ static int save_persistent_data(void)
     char *fname;
     off64_t write_offset;
     off64_t erase_offset;
-    int found = 0;
     int fd;
     int ret;
 
@@ -1021,7 +1020,6 @@ static int get_dm_crypt_version(int fd, const char *name,  int *version)
     char buffer[DM_CRYPT_BUF_SIZE];
     struct dm_ioctl *io;
     struct dm_target_versions *v;
-    int i;
 
     io = (struct dm_ioctl *) buffer;
 
@@ -1053,13 +1051,9 @@ static int create_crypto_blk_dev(struct crypt_mnt_ftr *crypt_ftr, unsigned char
                                     char *real_blk_name, char *crypto_blk_name, const char *name)
 {
   char buffer[DM_CRYPT_BUF_SIZE];
-  char master_key_ascii[129]; /* Large enough to hold 512 bit key and null */
-  char *crypt_params;
   struct dm_ioctl *io;
-  struct dm_target_spec *tgt;
   unsigned int minor;
   int fd;
-  int i;
   int retval = -1;
   int version[3];
   char *extra_params;
@@ -1416,8 +1410,6 @@ static int create_encrypted_random_key(char *passwd, unsigned char *master_key,
         struct crypt_mnt_ftr *crypt_ftr) {
     int fd;
     unsigned char key_buf[KEY_LEN_BYTES];
-    EVP_CIPHER_CTX e_ctx;
-    int encrypted_len, final_len;
 
     /* Get some random bits for a key */
     fd = open("/dev/urandom", O_RDONLY);
@@ -1543,13 +1535,8 @@ static void cryptfs_trigger_restart_min_framework()
 /* returns < 0 on failure */
 static int cryptfs_restart_internal(int restart_main)
 {
-    char fs_type[32];
-    char real_blkdev[MAXPATHLEN];
     char crypto_blkdev[MAXPATHLEN];
-    char fs_options[256];
-    unsigned long mnt_flags;
-    struct stat statbuf;
-    int rc = -1, i;
+    int rc = -1;
     static int restart_successful = 0;
 
     /* Validate that it's OK to call this routine */
@@ -1730,8 +1717,6 @@ static int test_mount_encrypted_fs(struct crypt_mnt_ftr* crypt_ftr,
   char tmp_mount_point[64];
   unsigned int orig_failed_decrypt_count;
   int rc;
-  kdf_func kdf;
-  void *kdf_params;
   int use_keymaster = 0;
   int upgrade = 0;
   unsigned char* intermediate_key = 0;
@@ -1877,7 +1862,8 @@ int cryptfs_setup_volume(const char *label, int major, int minor,
     char real_blkdev[MAXPATHLEN], crypto_blkdev[MAXPATHLEN];
     struct crypt_mnt_ftr sd_crypt_ftr;
     struct stat statbuf;
-    int nr_sec, fd;
+    unsigned int nr_sec;
+    int fd;
 
     sprintf(real_blkdev, "/dev/block/vold/%d:%d", major, minor);
 
@@ -2544,7 +2530,6 @@ static int cryptfs_enable_inplace_f2fs(char *crypto_blkdev,
                                        off64_t tot_size,
                                        off64_t previously_encrypted_upto)
 {
-    u32 i;
     struct encryptGroupsData data;
     struct f2fs_info *f2fs_info = NULL;
     int rc = ENABLE_INPLACE_ERR_OTHER;
@@ -2838,7 +2823,7 @@ static int cryptfs_enable_all_volumes(struct crypt_mnt_ftr *crypt_ftr, int how,
                                       int previously_encrypted_upto)
 {
     off64_t cur_encryption_done=0, tot_encryption_size=0;
-    int i, rc = -1;
+    int rc = -1;
 
     if (!is_battery_ok_to_start()) {
         SLOGW("Not starting encryption due to low battery");
@@ -2893,7 +2878,7 @@ int cryptfs_enable_internal(char *howarg, int crypt_type, char *passwd,
     char crypto_blkdev[MAXPATHLEN], real_blkdev[MAXPATHLEN];
     unsigned long nr_sec;
     unsigned char decrypted_master_key[KEY_LEN_BYTES];
-    int rc=-1, fd, i, ret;
+    int rc=-1, fd, i;
     struct crypt_mnt_ftr crypt_ftr;
     struct crypt_persist_data *pdata;
     char encrypted_state[PROPERTY_VALUE_MAX];
@@ -3260,7 +3245,6 @@ int cryptfs_enable_default(char *howarg, int allow_reboot)
 int cryptfs_changepw(int crypt_type, const char *newpw)
 {
     struct crypt_mnt_ftr crypt_ftr;
-    unsigned char decrypted_master_key[KEY_LEN_BYTES];
 
     /* This is only allowed after we've successfully decrypted the master key */
     if (!master_key_saved) {
@@ -3371,7 +3355,6 @@ static int persist_set_key(char *fieldname, char *value, int encrypted)
 int cryptfs_getfield(char *fieldname, char *value, int len)
 {
     char temp_value[PROPERTY_VALUE_MAX];
-    char real_blkdev[MAXPATHLEN];
     /* 0 is success, 1 is not encrypted,
      * -1 is value not set, -2 is any other error
      */
@@ -3401,9 +3384,6 @@ out:
 /* Set the value of the specified field. */
 int cryptfs_setfield(char *fieldname, char *value)
 {
-    struct crypt_persist_data stored_pdata;
-    struct crypt_persist_data *pdata_p;
-    struct crypt_mnt_ftr crypt_ftr;
     char encrypted_state[PROPERTY_VALUE_MAX];
     /* 0 is success, -1 is an error */
     int rc = -1;