[G1 Android Development] samuel.omlin:
First off, thanks for your reply, billc.

As regards the issuse that if the image of userdata.img is empty, the two methods are taken, as follows. (so sorry that the below is too long. :D)

1. checking that with bash command in the terminal

$ ls -lh

total 57M

-rw-r--r-- 1 samuel samuel 1.6M 2009-01-01 00:00 boot.img

-rw-r--r-- 1 samuel samuel 1.8M 2009-01-01 00:00 recovery.img

-rw-r--r-- 1 samuel samuel 54M 2009-01-01 00:00 system.img

-rw------- 1 samuel samuel 2.1K 2009-07-02 08:23 userdata.img

With the first scenario, the size of "userdata.img" is shown as "2.1K", which seems to indicate that the image of "userdata.img" isn't empty, instead of with the size.

2. checing that with programs (unyaffs.c[1]/unyaff.h[2]) for the tool of "unyaffs"

[1]http://unyaffs.googlecode.com/files/unyaffs.c

[2]http://unyaffs.googlecode.com/files/unyaffs.h

(NOTE: the instruction of complicatioin is "gcc -o unyaffs unyaffs.c" with the version 4.2.4 of gcc)

After compiling, the executable tool is got in your directory, also known as "unyaffs". And then, type the instruction with the terminal below.

$ unyaffs userdata.img

end of image

Unfortunately, there is nothing out there after extracting contents of "userdata.img" with the size of "2.1K"(-the length really includes what contents?). Only a message of "end of image" is shown up with the terminal.

To get more information about the message of "end of image, therefore, diving into the C file used to generate the tool of "unyaffs", getting the following connents. Meanwhile, please also pay more attention to the lines with the bold.

int read_chunk()

{

ssize_t s;

int ret = -1;

memset(chunk_data, 0xff, sizeof(chunk_data));

s = read(img_file, data, CHUNK_SIZE + SPARE_SIZE);

if (s == -1) {

perror("read image file\n");

} else if (s == 0) {

printf("end of image\n");

} else if ((s == (CHUNK_SIZE + SPARE_SIZE))) {

ret = 0;

} else {

fprintf(stderr, "broken image file\n");

}

return ret;

}

And then, indexing the function in the Linux Programmer's Mannual with the command of "man read" in the terminal to get more info, as shown below. In the meantime, please pay more attention to the lines with the bold as well.

$man read

...

...

NAME

read - read from a file descriptor

SYNOPSIS

#include <unistd.h>

ssize_t read(int fd, void *buf, size_t count);

DESCRIPTION

read() attempts to read up to count bytes from file descriptor fd into

the buffer starting at buf.

If count is zero, read() returns zero and has no other results. If

count is greater than SSIZE_MAX, the result is unspecified.

RETURN VALUE

On success, the number of bytes read is returned (zero indicates end of

file), and the file position is advanced by this number.

...

...

Just judging from the combination of the snippet of "unyaffs.c" and the mannual of "read" above, the conclusion below can be come to.

The real contents of "userdata.img" with the size of "2.1k" is exactly empty ending up with "end of file".

When compared the two conclusions as mentioned above, it's found that the both are just contrary, the former ISN'T empty while the latter IS empty.

So, there are a set of problems about the above confusion herein.

Q1: What contents exactly does the "userdata.img" with the size of "2.1k" mean?

Q2: What contents and from which position does the function of "read" read in the file? In the case of "userdata.img", what are"what contents" and "from which position" respectively?

Q3: According to the above two scenarios, what steps to take are to judge if the file is really empty?

Looking forward to your replies, thanks!!