Skip to content

Commit

Permalink
Merge "Crypto changes for devices that don't write ext4 fs on wipe"
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Sumrall authored and Android (Google) Code Review committed May 27, 2011
2 parents 7956d75 + b05b0b5 commit e555f54
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
27 changes: 27 additions & 0 deletions include/cutils/partition_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2011, 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 __CUTILS_PARTITION_WIPED_H__
#define __CUTILS_PARTITION_WIPED_H__

__BEGIN_DECLS

int partition_wiped(char *source);
void erase_footer(const char *dev_path, long long size);

__END_DECLS

#endif /* __CUTILS_PARTITION_WIPED_H__ */
2 changes: 1 addition & 1 deletion libcutils/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ else #!sim
# ========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := libcutils
LOCAL_SRC_FILES := $(commonSources) ashmem-dev.c mq.c android_reboot.c uevent.c
LOCAL_SRC_FILES := $(commonSources) ashmem-dev.c mq.c android_reboot.c partition_utils.c uevent.c

ifeq ($(TARGET_ARCH),arm)
LOCAL_SRC_FILES += arch-arm/memset32.S
Expand Down
67 changes: 67 additions & 0 deletions libcutils/partition_utils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2011, 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.
*/

#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mount.h> /* for BLKGETSIZE */
#include <cutils/properties.h>

static int only_one_char(char *buf, int len, char c)
{
int i, ret;

ret = 1;
for (i=0; i<len; i++) {
if (buf[i] != c) {
ret = 0;
break;
}
}
return ret;
}

int partition_wiped(char *source)
{
char buf[4096];
int fd, ret, wiped;

if ((fd = open(source, O_RDONLY)) < 0) {
return 0;
}

ret = read(fd, buf, sizeof(buf));
close(fd);

if (ret != sizeof(buf)) {
return 0;
}

/* Check for all zeros */
if (only_one_char(buf, sizeof(buf), 0)) {
return 1;
}

/* Check for all ones */
if (only_one_char(buf, sizeof(buf), 0xff)) {
return 1;
}

return 0;
}

0 comments on commit e555f54

Please sign in to comment.