View Single Post
pichlo's Avatar
Posts: 6,445 | Thanked: 20,981 times | Joined on Sep 2012 @ UK
#16
I had a similar case once. A different set of files seen by the phone than seen by the PC in mass storage mode.

The reason is simple although it may sounds a bit complicated to a layman.

Historically, there have been essentially two types of storage: floppies and hard disks. A floppy has a small capacity and is treated as a single storage unit. It has some metadata describing the physical layout (most commonly the File Access Table, or FAT), followed by the data themselves. It may look something like this (PT = Partition Table):

Code:
+---------+--------------------------------------------+
|   FAT   |                    Data                    |
+---------+--------------------------------------------+
(Please note that this is a simplification. "FAT" is just one of a number of possible types of metadata and "Data" includes all data, i.e. files as well as directories.)

The other type of storage is the hard disk. Hard disks are several orders of magnitude larger than floppies. It was considered a good idea to have a mechanism to split the capacity into a number of smaller units, each with its own file system. These units are called "partitions". As the time progressed, the importance of partitions has grown. Nowadays, every computer is shipped from the factory with a number of partitions, each with a different purpose (boot, data, recovery, swap...).

Now, you need some global metadata (called the partition table) describing where the partitions are plus each of these partitions needs its own metadata describing its physical layout. So the picture may look something like this:

Code:
+--+--------------------+--------------------+---------+
|  |     Partition 1    |     Partition 2    |   etc   |
|  |+---+--------------+|+---+--------------+|         |
|PT||FAT|     Data     |||FAT|     Data     || ....... |
|  |+---+--------------+|+---+--------------+|         |
+--+--------------------+--------------------+---------+
Memory cards, USB memory sticks etc.use both layouts. They are usually shipped with the "big floppy" layout but they can easily be converted to the "hard disk" layout by the end user with the proper tools.

In the N900, you have three partitions. The first one is the largest one at 27GB and contains all your pictures, videos, music etc. This partition is exposed to the PC in mass storage mode.

But the PC does not know that it is a partition. All it can see is the red bit. Does that look familiar? If not, then it should. It is the exact replica of the first picture, i.e. what the floppy looks like. To the PC, the N900's storage looks like a large floppy.

Now image a serious data corruption, to the extent that the PC cannot figure out what the hell is going on. You run some recovery tool and that tool decides that the situation is beyond repair. In some cases, the corruption may even fool the PC into thinking that it is dealing with the "hard disk" layout and not the "big floppy" one. So the recovery tool proceeds to "fix" the partition table and you end up with the situation like this:

Code:
+--+--------------------+--------------------+---------+
|  |     Partition 1    |     Partition 2    |   etc   |
|  |+--+---------------+|+---+--------------+|         |
|  ||  |+---+---------+|||   |              ||         |
|PT||PT||FAT|  Data   ||||FAT|     Data     || ....... |
|  ||  |+---+---------+|||   |              ||         |
|  |+--+---------------+|+---+--------------+|         |
+--+--------------------+--------------------+---------+
See the problem? You have a partition table inside a partition. This is illegal and the phone, which sees the whole layout, will get rightfully confused. The PC, which can see only the red part of the layout, can see nothing wrong. As far as the PC is concerned, it has a perfectly valid USB mass storage attached, with a partition table and a single partition.

For several reasons that are too technical to go into (even more than the above tirade ), you may easily get into a situation when the phone not only does not know that you have a nested partition; to the phone, Partition 1 actually looks like a perfectly normal partition, with a valid FAT and data. So the phone can see a full set of files. The PC, however, can see a different FAT describing the same area and it can see a different set of files. Funnily, both can happily coexist for a while but since none of them knows about the other one, the areas that one thinks are empty can be already claimed by the other one and if you use either of them to write onto the medium, you inevitably create more corruption.

The solution is not very easy. I ended up writing my own CLI program to locate both FATs (one seen by the phone and one seen by the PC) and update one using data from the other. The result was that the PC could see exactly the same files as the phone. The layout was still wrong so I had to copy the files off, reformat the storage and copy the files back. I lost some of the data but managed to save most. The CLI tool was very crude as it was meant for a single job, definitely not for public consumption. It required some manual assistance and understanding of what you are doing. It was a lot of work and I would not want to go through it again, so now I am a bit more cautious and backup more frequently. If a similar corruption happens again, I just reformat the damn thing and restore from the last backup.
__________________
Русский военный корабль, иди нахуй!
 

The Following 8 Users Say Thank You to pichlo For This Useful Post: