Whamcloud - gitweb
Change e2fsck to open non-mounted filesystems in exclusive mode
[tools/e2fsprogs.git] / ext2ed / dir_com.c
index e1471fb..c6b194e 100644 (file)
@@ -19,7 +19,7 @@ the functions here are a superset of those in the file_com.c source.
 We assume that the user reached here using the dir command of the inode type and not by using settype dir, so
 that init_dir_info is indeed called to gather the required information.
 
-type_data is not changed ! It still contains the inode of the file - We handle the directory in our own
+type_data is not changed! It still contains the inode of the file - We handle the directory in our own
 variables, so that settype ext2_inode will "go back" to the inode of this directory.
 
 First written on: April 28 1995
@@ -98,13 +98,12 @@ struct struct_file_info search_dir_entries (int (*action) (struct struct_file_in
 
 {
        struct struct_file_info info;                                           /* Temporary variables used to */
-       struct ext2_dir_entry *dir_entry_ptr;                                   /* contain the current search entries */
-       
-       int return_code;
+       struct ext2_dir_entry_2 *dir_entry_ptr;                                 /* contain the current search entries */
+       int return_code, next;
        
        info=first_file_info;                                                   /* Start from the first entry - Read it */
        low_read (info.buffer,file_system_info.block_size,info.global_block_offset);
-       dir_entry_ptr=(struct ext2_dir_entry *) (info.buffer+info.dir_entry_offset);
+       dir_entry_ptr=(struct ext2_dir_entry_2 *) (info.buffer+info.dir_entry_offset);
        
        while (info.file_offset < info.file_length) {                           /* While we haven't reached the end */
                
@@ -115,11 +114,14 @@ struct struct_file_info search_dir_entries (int (*action) (struct struct_file_in
 
                                                                                /* Pass to the next entry */
                                                                                
-               dir_entry_ptr=(struct ext2_dir_entry *) (info.buffer+info.dir_entry_offset);
+               dir_entry_ptr=(struct ext2_dir_entry_2 *) (info.buffer+info.dir_entry_offset);
 
                info.dir_entry_num++;
-               info.dir_entry_offset+=dir_entry_ptr->rec_len;
-               info.file_offset+=dir_entry_ptr->rec_len;
+               next = dir_entry_ptr->rec_len;
+               if (!next)
+                       next = file_system_info.block_size - info.dir_entry_offset;
+               info.dir_entry_offset += next;
+               info.file_offset += next;
 
                if (info.file_offset >= info.file_length) break;
 
@@ -133,7 +135,7 @@ struct struct_file_info search_dir_entries (int (*action) (struct struct_file_in
                                                                                /* read it and update the pointer */
                                                                                
                        low_read (info.buffer,file_system_info.block_size,info.global_block_offset);
-                       dir_entry_ptr=(struct ext2_dir_entry *) (info.buffer+info.dir_entry_offset);
+                       dir_entry_ptr=(struct ext2_dir_entry_2 *) (info.buffer+info.dir_entry_offset);
                        
                }
                
@@ -216,9 +218,9 @@ void type_dir___cd (char *command_line)
        int status;
        char *ptr,full_dir_name [500],dir_name [500],temp [500],temp2 [500];
        struct struct_file_info info;
-       struct ext2_dir_entry *dir_entry_ptr;
+       struct ext2_dir_entry_2 *dir_entry_ptr;
 
-       dir_entry_ptr=(struct ext2_dir_entry *) (file_info.buffer+file_info.dir_entry_offset);
+       dir_entry_ptr=(struct ext2_dir_entry_2 *) (file_info.buffer+file_info.dir_entry_offset);
                
        ptr=parse_word (command_line,dir_name);
        
@@ -317,9 +319,9 @@ Returns FOUND if found, or CONTINUE if not found.
 */
 
 {
-       struct ext2_dir_entry *dir_entry_ptr;
+       struct ext2_dir_entry_2 *dir_entry_ptr;
 
-       dir_entry_ptr=(struct ext2_dir_entry *) (info->buffer+info->dir_entry_offset);
+       dir_entry_ptr=(struct ext2_dir_entry_2 *) (info->buffer+info->dir_entry_offset);
 
        if (dir_entry_ptr->name_len != strlen (name_search))
                return (CONTINUE);
@@ -395,10 +397,10 @@ It involves computing the device offset of the inode and using directly the seto
        long inode_offset;
        char buffer [80];
 
-       struct ext2_dir_entry *dir_entry_ptr;
+       struct ext2_dir_entry_2 *dir_entry_ptr;
 
        low_read (file_info.buffer,file_system_info.block_size,file_info.global_block_offset);
-       dir_entry_ptr=(struct ext2_dir_entry *) (file_info.buffer+file_info.dir_entry_offset);
+       dir_entry_ptr=(struct ext2_dir_entry_2 *) (file_info.buffer+file_info.dir_entry_offset);
 
        inode_offset=inode_num_to_inode_offset (dir_entry_ptr->inode);                  /* Compute the inode's offset */
        sprintf (buffer,"setoffset %ld",inode_offset);dispatch (buffer);                /* Move to it */
@@ -449,9 +451,9 @@ Show the current search entry (info) in one line. If the entry happens to be the
 
 {
        unsigned char temp [80];
-       struct ext2_dir_entry *dir_entry_ptr;
+       struct ext2_dir_entry_2 *dir_entry_ptr;
        
-       dir_entry_ptr=(struct ext2_dir_entry *) (info->buffer+info->dir_entry_offset);
+       dir_entry_ptr=(struct ext2_dir_entry_2 *) (info->buffer+info->dir_entry_offset);
 
        if (info->dir_entry_num == file_info.dir_entry_num)                             /* Highlight the current entry */
                wattrset (show_pad,A_REVERSE);
@@ -591,9 +593,9 @@ because it is of variable length.
 {
        int found=0;
        unsigned char *ptr,buffer [80],variable [80],value [80],temp [80];
-       struct ext2_dir_entry *dir_entry_ptr;
+       struct ext2_dir_entry_2 *dir_entry_ptr;
        
-       dir_entry_ptr=(struct ext2_dir_entry *) (file_info.buffer+file_info.dir_entry_offset);
+       dir_entry_ptr=(struct ext2_dir_entry_2 *) (file_info.buffer+file_info.dir_entry_offset);
        
        ptr=parse_word (command_line,buffer);
        if (*ptr==0) {