summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2010-11-30 13:49:32 -0800
committerKenny Root <kroot@google.com>2010-11-30 16:51:13 -0800
commit33b2264ea9ab0f1980c49698729a0ab3c51d07fe (patch)
tree0c30e474c5ddb66c8bc0bcdc44126447f26afd92
parent0b44476a23660baabc1984c2fa8ee2c0c114460b (diff)
downloadframeworks_base-33b2264ea9ab0f1980c49698729a0ab3c51d07fe.zip
frameworks_base-33b2264ea9ab0f1980c49698729a0ab3c51d07fe.tar.gz
frameworks_base-33b2264ea9ab0f1980c49698729a0ab3c51d07fe.tar.bz2
Move disk usage utilities to its own library
Disk usage calculation will happen in more places now, so move the installd calculation utilities out to its own library that only gets built for the target. Change-Id: Idceb6bd663ca6ab3d38fa00e57ee74a25b784855
-rw-r--r--cmds/installd/Android.mk17
-rw-r--r--cmds/installd/commands.c50
-rw-r--r--include/diskusage/dirsize.h30
-rw-r--r--libs/diskusage/Android.mk24
-rw-r--r--libs/diskusage/MODULE_LICENSE_APACHE20
-rw-r--r--libs/diskusage/dirsize.c75
6 files changed, 140 insertions, 56 deletions
diff --git a/cmds/installd/Android.mk b/cmds/installd/Android.mk
index 6673862..8641c30 100644
--- a/cmds/installd/Android.mk
+++ b/cmds/installd/Android.mk
@@ -1,21 +1,24 @@
ifneq ($(TARGET_SIMULATOR),true)
-LOCAL_PATH:= $(call my-dir)
+LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_SRC_FILES:= \
+LOCAL_SRC_FILES := \
installd.c commands.c utils.c
-LOCAL_C_INCLUDES := \
- $(call include-path-for, system-core)/cutils
+#LOCAL_C_INCLUDES := \
+# $(call include-path-for, system-core)/cutils
LOCAL_SHARED_LIBRARIES := \
libcutils
-LOCAL_STATIC_LIBRARIES :=
+LOCAL_STATIC_LIBRARIES := \
+ libdiskusage
-LOCAL_MODULE:= installd
+LOCAL_MODULE := installd
+
+LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
-endif # !simulator))
+endif # !simulator
diff --git a/cmds/installd/commands.c b/cmds/installd/commands.c
index 2f03c7a..cde1573 100644
--- a/cmds/installd/commands.c
+++ b/cmds/installd/commands.c
@@ -15,6 +15,7 @@
*/
#include "installd.h"
+#include <diskusage/dirsize.h>
int install(const char *pkgname, int encrypted_fs_flag, uid_t uid, gid_t gid)
{
@@ -327,55 +328,6 @@ int protect(char *pkgname, gid_t gid)
return 0;
}
-static int64_t stat_size(struct stat *s)
-{
- int64_t blksize = s->st_blksize;
- int64_t size = s->st_size;
-
- if (blksize) {
- /* round up to filesystem block size */
- size = (size + blksize - 1) & (~(blksize - 1));
- }
-
- return size;
-}
-
-static int64_t calculate_dir_size(int dfd)
-{
- int64_t size = 0;
- struct stat s;
- DIR *d;
- struct dirent *de;
-
- d = fdopendir(dfd);
- if (d == NULL) {
- close(dfd);
- return 0;
- }
-
- while ((de = readdir(d))) {
- const char *name = de->d_name;
- if (de->d_type == DT_DIR) {
- int subfd;
- /* always skip "." and ".." */
- if (name[0] == '.') {
- if (name[1] == 0) continue;
- if ((name[1] == '.') && (name[2] == 0)) continue;
- }
- subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY);
- if (subfd >= 0) {
- size += calculate_dir_size(subfd);
- }
- } else {
- if (fstatat(dfd, name, &s, AT_SYMLINK_NOFOLLOW) == 0) {
- size += stat_size(&s);
- }
- }
- }
- closedir(d);
- return size;
-}
-
int get_size(const char *pkgname, const char *apkpath,
const char *fwdlock_apkpath,
int64_t *_codesize, int64_t *_datasize, int64_t *_cachesize, int encrypted_fs_flag)
diff --git a/include/diskusage/dirsize.h b/include/diskusage/dirsize.h
new file mode 100644
index 0000000..34236c0
--- /dev/null
+++ b/include/diskusage/dirsize.h
@@ -0,0 +1,30 @@
+/*
+ *
+ * Copyright (C) 2010 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 __LIBDISKUSAGE_DIRSIZE_H
+#define __LIBDISKUSAGE_DIRSIZE_H
+
+#include <stdint.h>
+
+__BEGIN_DECLS
+
+int64_t stat_size(struct stat *s);
+int64_t calculate_dir_size(int dfd);
+
+__END_DECLS
+
+#endif /* __LIBDISKUSAGE_DIRSIZE_H */
diff --git a/libs/diskusage/Android.mk b/libs/diskusage/Android.mk
new file mode 100644
index 0000000..d54f8ad
--- /dev/null
+++ b/libs/diskusage/Android.mk
@@ -0,0 +1,24 @@
+# Copyright (C) 2010 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.
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libdiskusage
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := dirsize.c
+
+include $(BUILD_STATIC_LIBRARY) \ No newline at end of file
diff --git a/libs/diskusage/MODULE_LICENSE_APACHE2 b/libs/diskusage/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/libs/diskusage/MODULE_LICENSE_APACHE2
diff --git a/libs/diskusage/dirsize.c b/libs/diskusage/dirsize.c
new file mode 100644
index 0000000..45e7b2a
--- /dev/null
+++ b/libs/diskusage/dirsize.c
@@ -0,0 +1,75 @@
+/*
+ *
+ * Copyright (C) 2008, 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 <dirent.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#include <diskusage/dirsize.h>
+
+int64_t stat_size(struct stat *s)
+{
+ int64_t blksize = s->st_blksize;
+ int64_t size = s->st_size;
+
+ if (blksize) {
+ /* round up to filesystem block size */
+ size = (size + blksize - 1) & (~(blksize - 1));
+ }
+
+ return size;
+}
+
+int64_t calculate_dir_size(int dfd)
+{
+ int64_t size = 0;
+ struct stat s;
+ DIR *d;
+ struct dirent *de;
+
+ d = fdopendir(dfd);
+ if (d == NULL) {
+ close(dfd);
+ return 0;
+ }
+
+ while ((de = readdir(d))) {
+ const char *name = de->d_name;
+ if (de->d_type == DT_DIR) {
+ int subfd;
+
+ /* always skip "." and ".." */
+ if (name[0] == '.') {
+ if (name[1] == 0)
+ continue;
+ if ((name[1] == '.') && (name[2] == 0))
+ continue;
+ }
+
+ subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY);
+ if (subfd >= 0) {
+ size += calculate_dir_size(subfd);
+ }
+ } else {
+ if (fstatat(dfd, name, &s, AT_SYMLINK_NOFOLLOW) == 0) {
+ size += stat_size(&s);
+ }
+ }
+ }
+ closedir(d);
+ return size;
+}