Final Year Project:
Using Linux Filesystems Under Windows
Chris Bryden
BEng. Electronics and Software Engineering
School of Computer Science
University of Birmingham
44
5.16 Layer 1: The ReadDir Function
This purpose of this function is to read the directory listing pointed to by a
specified inode. The inode number of the required directory is passed to the
function. The function returns a small structure with the type DIRECTORY. This
structure is defined as follows:
It contains two elements, ulDirLen is the directory list length in bytes and
lpDirData is a pointer to the memory location that the directory list is stored in.
The first operation that this function must carry out is to retrieve the inode
that corresponds to the inode number, ulINodeNum. This is achieved by calling
the GetInode function. Next the list of the blocks allocated to the inode is
obtained by calling the GetBlockList function. These blocks are then read into the
memory buffer, lpDirData, using a while loop to call the ReadBlock function for
each block in the block list. The ulDirLen variable is copied from the i_size field in
the Inode variable.
The Directory structure is then returned to the calling function. This
function makes up part of the interface between layers 1 and 2.
The structure of a directory is described in section 3.3.6, but a brief
description is given here. Directories are implemented in ext2fs as a special kind
of file. The structure of the file is a linked list of directory entries This method is
used rather placing the directory entries one after another to save disk space, as
ext2 filenames can be up to 255 characters long, but many are shorter. The
structure of the directory entry is shown below:
The length of the directory name is stored in the variable name_len. In
order To navigate through successive directory entries, a variable to record the
offset of the next entry is simply a cumulative total of these rec_len values. The
name_len value is recorded because the character array holding its name is not
typedef struct directory {
unsigned long ulDirLen;
LPBYTE lpDirData;
} DIRECTORY;
/*
* Structure of a directory entry
*/
#define EXT2_NAME_LEN 255
struct ext2_dir_entry {
unsigned long inode;
/* Inode number */
unsigned short rec_len;
/* Directory entry length
*/
unsigned short name_len;
/* Name length */
char
name[EXT2_NAME_LEN]; /* File name */
};