]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2004-06-27 Tomas Ebenlendr <ebik@ucw.cz>
authormarco_g <marco_g@localhost>
Sun, 27 Jun 2004 10:43:11 +0000 (10:43 +0000)
committermarco_g <marco_g@localhost>
Sun, 27 Jun 2004 10:43:11 +0000 (10:43 +0000)
* fs/ext2.c (FILETYPE_INO_MASK, FILETYPE_INO_DIRECTORY)
(FILETYPE_INO_SYMLINK): New macros.
(grub_ext2_find_file): Check if the node is a directory using the
inode stat information instead of using the filetype in the
dirent.  Exclude the first character of an absolute symlink.
(grub_ext2_dir): Mask out the filetype part of the mode member of
the inode.

ChangeLog
fs/ext2.c

index 6ae670bc0d9b286bd7f6a7d15c55af871d4cc6bc..450f70592927ff0119006d5f02c4b97f092c7808 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2004-06-27  Tomas Ebenlendr  <ebik@ucw.cz>
+
+       * fs/ext2.c (FILETYPE_INO_MASK, FILETYPE_INO_DIRECTORY)
+       (FILETYPE_INO_SYMLINK): New macros.
+       (grub_ext2_find_file): Check if the node is a directory using the
+       inode stat information instead of using the filetype in the
+       dirent.  Exclude the first character of an absolute symlink.
+       (grub_ext2_dir): Mask out the filetype part of the mode member of
+       the inode.
+
 2004-05-24  Marco Gerards  <metgerards@student.han.nl>
 
        Add support for UFS version 1 and 2.  Add support for the minix
index 7b1ffc7d43308809f6093b0605c023d98fb681e4..7c4cbd03dc13092483cc14a38cdb5b417fa56814 100644 (file)
--- a/fs/ext2.c
+++ b/fs/ext2.c
 #define        FILETYPE_DIRECTORY      2
 #define        FILETYPE_SYMLINK        7
 
+/* Filetype information as used in inodes.  */
+#define FILETYPE_INO_MASK      0170000
+#define FILETYPE_INO_DIRECTORY 0040000
+#define FILETYPE_INO_SYMLINK   0120000
+
 #include <grub/err.h>
 #include <grub/file.h>
 #include <grub/mm.h>
@@ -451,8 +456,14 @@ grub_ext2_find_file (struct grub_ext2_data *data, const char *path, int *ino)
              if (dirent.namelen == namesize 
                  && !grub_strncmp (name, filename, namesize))
                {
+                 /* Stat the inode.  */
+                 grub_ext2_read_inode (data, 
+                                       grub_le_to_cpu32 (dirent.inode),
+                                       inode);
+
                  /* If this is a symlink, follow it.  */
-                 if (dirent.filetype == FILETYPE_SYMLINK)
+                 if ((grub_le_to_cpu16 (data->inode.mode) 
+                      & FILETYPE_INO_MASK) == FILETYPE_INO_SYMLINK)
                    {
                      /* XXX: Use malloc instead?  */
                      char symlink[blocksize];
@@ -464,11 +475,6 @@ grub_ext2_find_file (struct grub_ext2_data *data, const char *path, int *ino)
                          goto fail;
                        }
 
-                     /* Read the symlink.  */
-                     grub_ext2_read_inode (data, 
-                                           grub_le_to_cpu32 (dirent.inode),
-                                           inode);
-
                      /* If the filesize of the symlink is bigger than
                         60 the symlink is stored in a separate block,
                         otherwise it is stored in the inode.  */
@@ -490,7 +496,7 @@ grub_ext2_find_file (struct grub_ext2_data *data, const char *path, int *ino)
                      /* Check if the symlink is absolute or relative.  */
                      if (symlink[0] == '/')
                        {
-                         grub_strncpy (fpath, symlink, EXT2_PATH_MAX);
+                         grub_strncpy (fpath, symlink + 1, EXT2_PATH_MAX);
                          name = fpath;
                          currinode = 2;
                        }
@@ -516,7 +522,7 @@ grub_ext2_find_file (struct grub_ext2_data *data, const char *path, int *ino)
                              grub_free (bak);
                            }
                        }
-                 
+
                      fpos = 0;
                      break;
                    }
@@ -526,7 +532,8 @@ grub_ext2_find_file (struct grub_ext2_data *data, const char *path, int *ino)
                      currinode = grub_le_to_cpu32 (dirent.inode);
                      name = next;
 
-                     if (dirent.filetype != FILETYPE_DIRECTORY)
+                     if ((grub_le_to_cpu16 (data->inode.mode) 
+                          & FILETYPE_INO_MASK) != FILETYPE_INO_DIRECTORY)
                        {
                          grub_error (GRUB_ERR_BAD_FILE_TYPE,
                                      "not a directory");
@@ -653,7 +660,8 @@ grub_ext2_dir (grub_device_t device, const char *path,
   if (grub_errno)
     goto fail;
 
-  if (!(grub_le_to_cpu16 (data->inode.mode) & 040000))
+  if ((grub_le_to_cpu16 (data->inode.mode)
+       & FILETYPE_INO_MASK) != FILETYPE_INO_DIRECTORY)
     {
       grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
       goto fail;