From 5593c856f49684f149116a6f2f28ddf9338b8557 Mon Sep 17 00:00:00 2001 From: Rom Lemarchand Date: Fri, 21 Dec 2012 12:41:43 -0800 Subject: [PATCH] Fix calls to logwrap Make sure all the calls to logwrap are consistent with the function's semantics. Change-Id: Ib0e2ad5c283cc4bb06c0ef5d6a9a52a5840b3dd2 --- Ext4.cpp | 6 +++--- Fat.cpp | 14 ++++++-------- VoldUtil.h | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 VoldUtil.h diff --git a/Ext4.cpp b/Ext4.cpp index 4ec0616..c99d801 100644 --- a/Ext4.cpp +++ b/Ext4.cpp @@ -39,6 +39,7 @@ #include #include "Ext4.h" +#include "VoldUtil.h" #define MKEXT4FS_PATH "/system/bin/make_ext4fs"; @@ -69,7 +70,7 @@ int Ext4::doMount(const char *fsPath, const char *mountPoint, bool ro, bool remo 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 @@ int Ext4::format(const char *fsPath, const char *mountpoint) { 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 #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 Fat::check(const char *fsPath) { 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::doMount(const char *fsPath, const char *mountPoint, 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 @@ int Fat::format(const char *fsPath, unsigned int numSectors) { 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