summaryrefslogtreecommitdiff
path: root/ext4_utils/ext4_utils.c
diff options
context:
space:
mode:
authorAnatol Pomazau <anatol@google.com>2012-02-03 10:57:40 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-02-03 10:57:40 -0800
commitae4f7dccadfafc36470a3e6f3084c6cf3cc63415 (patch)
treee9df9977417c5df1e15c07df7ef6cb6dad75cac8 /ext4_utils/ext4_utils.c
parent93eb1dc9e68d2e9dea94f56d8bce478c1a52b354 (diff)
downloadextras-ae4f7dccadfafc36470a3e6f3084c6cf3cc63415.tar.gz
Revert "Pass file descriptor instead of file name"
This reverts commit 93eb1dc9e68d2e9dea94f56d8bce478c1a52b354
Diffstat (limited to 'ext4_utils/ext4_utils.c')
-rw-r--r--ext4_utils/ext4_utils.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/ext4_utils/ext4_utils.c b/ext4_utils/ext4_utils.c
index 0016b652..3d5895e3 100644
--- a/ext4_utils/ext4_utils.c
+++ b/ext4_utils/ext4_utils.c
@@ -137,11 +137,11 @@ static void ext4_write_data_file(void *priv, u64 off, const char *file,
}
/* Write the filesystem image to a file */
-void write_ext4_image(int fd, int gz, int sparse, int crc, int wipe)
+void write_ext4_image(const char *filename, int gz, int sparse, int crc,
+ int wipe)
{
int ret = 0;
-
- struct output_file *out = open_output_fd(fd, gz, sparse,
+ struct output_file *out = open_output_file(filename, gz, sparse,
count_sparse_chunks(), crc, wipe);
if (!out)
@@ -446,11 +446,15 @@ void ext4_update_free()
}
}
-static u64 get_block_device_size(int fd)
+static u64 get_block_device_size(const char *filename)
{
+ int fd = open(filename, O_RDONLY);
u64 size = 0;
int ret;
+ if (fd < 0)
+ return 0;
+
#if defined(__linux__)
ret = ioctl(fd, BLKGETSIZE64, &size);
#elif defined(__APPLE__) && defined(__MACH__)
@@ -460,20 +464,22 @@ static u64 get_block_device_size(int fd)
return 0;
#endif
+ close(fd);
+
if (ret)
return 0;
return size;
}
-u64 get_file_size(int fd)
+u64 get_file_size(const char *filename)
{
struct stat buf;
int ret;
u64 reserve_len = 0;
s64 computed_size;
- ret = fstat(fd, &buf);
+ ret = stat(filename, &buf);
if (ret)
return 0;
@@ -483,7 +489,7 @@ u64 get_file_size(int fd)
if (S_ISREG(buf.st_mode))
computed_size = buf.st_size - reserve_len;
else if (S_ISBLK(buf.st_mode))
- computed_size = get_block_device_size(fd) - reserve_len;
+ computed_size = get_block_device_size(filename) - reserve_len;
else
computed_size = 0;