blob: 10539fa5930cee42617570c7afc9fdf3c742d455 [file] [log] [blame]
Ken Sumrallb05b0b52011-05-18 16:54:19 -07001/*
2 * Copyright 2011, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <sys/types.h>
18#include <unistd.h>
19#include <fcntl.h>
20#include <sys/stat.h>
21#include <sys/ioctl.h>
22#include <sys/mount.h> /* for BLKGETSIZE */
23#include <cutils/properties.h>
24
25static int only_one_char(char *buf, int len, char c)
26{
27 int i, ret;
28
29 ret = 1;
30 for (i=0; i<len; i++) {
31 if (buf[i] != c) {
32 ret = 0;
33 break;
34 }
35 }
36 return ret;
37}
38
39int partition_wiped(char *source)
40{
41 char buf[4096];
42 int fd, ret, wiped;
43
44 if ((fd = open(source, O_RDONLY)) < 0) {
45 return 0;
46 }
47
48 ret = read(fd, buf, sizeof(buf));
49 close(fd);
50
51 if (ret != sizeof(buf)) {
52 return 0;
53 }
54
55 /* Check for all zeros */
56 if (only_one_char(buf, sizeof(buf), 0)) {
57 return 1;
58 }
59
60 /* Check for all ones */
61 if (only_one_char(buf, sizeof(buf), 0xff)) {
62 return 1;
63 }
64
65 return 0;
66}
67