Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm looking at low-level directory structure of a disk partition, formatted as "vfat" filesystem. The directory entry structure I use is:

struct __attribute__ ((packed)) Dentry
{
  char          name[11];
  Attr          attr;
  uint8_t       reserved;
  uint8_t       ctimeTenth;
  Time          ctime;
  Date          cdate;
  Date          adate;
  uint16_t      clusterHi;
  Time          mtime;
  Date          mdate;
  uint16_t      clusterLo;
  uint32_t      size;
};

So, the last four bytes of the directory entry should represent size of file or directory in bytes. However, in my experiments directory entries for directories (not files) always have zero in the size field. For example, this is dd dump of my root directory with one file and one non-empty subdirectory (named qqq):

00000000  42 65 00 65 00 66 00 66  00 66 00 0f 00 fe 00 00  |Be.e.f.f.f......|
00000010  ff ff ff ff ff ff ff ff  ff ff 00 00 ff ff ff ff  |................|
00000020  01 61 00 61 00 61 00 62  00 62 00 0f 00 fe 62 00  |.a.a.a.b.b....b.|
00000030  63 00 63 00 63 00 64 00  64 00 00 00 64 00 65 00  |c.c.c.d.d...d.e.|
00000040  41 41 41 42 42 42 7e 31  20 20 20 20 00 64 43 60  |AAABBB~1    .dC`|
00000050  d1 44 d1 44 00 00 43 60  d1 44 04 00 0b 00 00 00  |.D.D..C`.D......|
00000060  41 71 00 71 00 71 00 00  00 ff ff 0f 00 3d ff ff  |Aq.q.q.......=..|
00000070  ff ff ff ff ff ff ff ff  ff ff 00 00 ff ff ff ff  |................|
00000080  51 51 51 20 20 20 20 20  20 20 20 10 00 00 20 79  |QQQ        ... y|
00000090  d1 44 d1 44 00 00 20 79  d1 44 09 00 00 00 00 00  |.D.D.. y.D......|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

(Bytes with size are 0x9c - 0x9f)

Could you please explain me why this size is zero? Or may be, somebody could point me to a doc, describing vfat directory entries with more details?

(I'm on Ubuntu 3.11.10.3, running as a guest OS in VMWare Fusion on Mac)

share|improve this question

1 Answer 1

A directory is not actually a file, but a logical way for a system to organize itself. The way the directories would be stored (depending on the file system) in some sort of table. For example: FAT uses a F ile A llocation T able.

So the size of the directory would be dependent upon the amount of space it takes up in that table, more directories equal larger table(s). It may be just a couple bytes.

I could be wrong on some points, but I am pretty sure this is why you are not seeing the size in the hex (as it is mostly a pointer).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.