Fix calls to logwrap
Make sure all the calls to logwrap are consistent with the function's
semantics.
Change-Id: Ib0e2ad5c283cc4bb06c0ef5d6a9a52a5840b3dd2
diff --git a/Ext4.cpp b/Ext4.cpp
index 4ec0616..c99d801 100644
--- a/Ext4.cpp
+++ b/Ext4.cpp
@@ -39,6 +39,7 @@
#include <cutils/properties.h>
#include "Ext4.h"
+#include "VoldUtil.h"
#define MKEXT4FS_PATH "/system/bin/make_ext4fs";
@@ -69,7 +70,7 @@
int Ext4::format(const char *fsPath, const char *mountpoint) {
int fd;
- const char *args[6];
+ const char *args[5];
int rc;
args[0] = MKEXT4FS_PATH;
@@ -77,8 +78,7 @@
args[2] = "-a";
args[3] = mountpoint;
args[4] = fsPath;
- args[5] = NULL;
- rc = logwrap(5, args, 1);
+ rc = logwrap(ARRAY_SIZE(args), args, 1);
if (rc == 0) {
SLOGI("Filesystem (ext4) formatted OK");
diff --git a/Fat.cpp b/Fat.cpp
index 82a3f7a..b43f089 100644
--- a/Fat.cpp
+++ b/Fat.cpp
@@ -39,6 +39,7 @@
#include <cutils/properties.h>
#include "Fat.h"
+#include "VoldUtil.h"
static char FSCK_MSDOS_PATH[] = "/system/bin/fsck_msdos";
static char MKDOSFS_PATH[] = "/system/bin/newfs_msdos";
@@ -55,14 +56,13 @@
int pass = 1;
int rc = 0;
do {
- const char *args[5];
+ const char *args[4];
args[0] = FSCK_MSDOS_PATH;
args[1] = "-p";
args[2] = "-f";
args[3] = fsPath;
- args[4] = NULL;
- rc = logwrap(4, args, 1);
+ rc = logwrap(ARRAY_SIZE(args), args, 1);
switch(rc) {
case 0:
@@ -153,7 +153,7 @@
int Fat::format(const char *fsPath, unsigned int numSectors) {
int fd;
- const char *args[11];
+ const char *args[10];
int rc;
args[0] = MKDOSFS_PATH;
@@ -171,12 +171,10 @@
args[7] = "-s";
args[8] = size;
args[9] = fsPath;
- args[10] = NULL;
- rc = logwrap(11, args, 1);
+ rc = logwrap(ARRAY_SIZE(args), args, 1);
} else {
args[7] = fsPath;
- args[8] = NULL;
- rc = logwrap(9, args, 1);
+ rc = logwrap(8, args, 1);
}
if (rc == 0) {
diff --git a/VoldUtil.h b/VoldUtil.h
new file mode 100644
index 0000000..30a3add
--- /dev/null
+++ b/VoldUtil.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _VOLDUTIL_H
+#define _VOLDUTIL_H
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
+
+#endif