All of lore.kernel.org
 help / color / mirror / Atom feed
From: phcoder <phcoder@gmail.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: UFS fixes
Date: Mon, 06 Apr 2009 15:29:58 +0200	[thread overview]
Message-ID: <49DA03D6.2020909@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 693 bytes --]

Here are the fixes for UFS. Basically it's a resubmit of my previous 
patch. It works fine with both solaris UFS and recent BSD UFS2. Does it 
break anything for anyone with ufs?
2009-04-06  Vladimir Serbinenko  <phcoder@gmail.com>

         UFS improvements

         * fs/ufs.c (INODE_NBLOCKS): new definition
         (struct grub_ufs_dirent): added fields for non-BSD dirents
         (grub_ufs_get_file_block): fixed double indirect handling
	(grub_ufs_lookup_symlink): use more robust way to determine whether
	symlink is inline
         (grub_ufs_find_file): support for non-BSD dirents
         (grub_ufs_dir): support for non-BSD dirents
	

-- 

Regards
Vladimir 'phcoder' Serbinenko

[-- Attachment #2: ufs.diff --]
[-- Type: text/x-diff, Size: 3827 bytes --]

diff --git a/fs/ufs.c b/fs/ufs.c
index e6eacd3..b799449 100644
--- a/fs/ufs.c
+++ b/fs/ufs.c
@@ -54,6 +54,8 @@
                            grub_le_to_cpu##bits1 (data->inode.field) : \
                            grub_le_to_cpu##bits2 (data->inode2.field))
 #define INODE_SIZE(data) INODE_ENDIAN (data,size,32,64)
+#define INODE_NBLOCKS(data) INODE_ENDIAN (data,nblocks,32,64)
+
 #define INODE_MODE(data) INODE_ENDIAN (data,mode,16,16)
 #define INODE_BLKSZ(data) (data->ufs_type == UFS1 ? 4 : 8)
 #define INODE_DIRBLOCKS(data,blk) INODE_ENDIAN \
@@ -174,8 +176,15 @@ struct grub_ufs_dirent
 {
   grub_uint32_t ino;
   grub_uint16_t direntlen;
-  grub_uint8_t filetype;
-  grub_uint8_t namelen;
+  union
+  {
+    grub_uint16_t namelen;
+    struct
+    {
+      grub_uint8_t filetype_bsd;
+      grub_uint8_t namelen_bsd;      
+    };
+  };
 } __attribute__ ((packed));
 
 /* Information about a "mounted" ufs filesystem.  */
@@ -234,15 +243,16 @@ grub_ufs_get_file_block (struct grub_ufs_data *data, unsigned int blk)
   blk -= indirsz;
   
   /* Double indirect block.  */
-  if (blk < UFS_BLKSZ (sblock) / indirsz)
+  if (blk < indirsz * indirsz)
     {
       grub_uint32_t indir[UFS_BLKSZ (sblock) >> 2];
       
       grub_disk_read (data->disk, INODE_INDIRBLOCKS (data, 1) << log2_blksz,
 		      0, sizeof (indir), (char *) indir);
       grub_disk_read (data->disk,
-      		      (data->ufs_type == UFS1) ?
-		      indir[blk / indirsz] : indir [(blk / indirsz) << 1],
+      		      ((data->ufs_type == UFS1) ?
+		      indir[blk / indirsz] : indir [(blk / indirsz) << 1]) 
+		      << log2_blksz,
 		      0, sizeof (indir), (char *) indir);
       
       return (data->ufs_type == UFS1) ?
@@ -387,8 +397,7 @@ grub_ufs_lookup_symlink (struct grub_ufs_data *data, int ino)
   if (++data->linknest > GRUB_UFS_MAX_SYMLNK_CNT)
     return grub_error (GRUB_ERR_SYMLINK_LOOP, "too deep nesting of symlinks");
   
-  if (INODE_SIZE (data) < (GRUB_UFS_DIRBLKS + GRUB_UFS_INDIRBLKS
-			  * INODE_BLKSZ (data)))
+  if (INODE_NBLOCKS (data) == 0)
     grub_strcpy (symlink, (char *) INODE (data, symlink));
   else
     {
@@ -447,6 +456,7 @@ grub_ufs_find_file (struct grub_ufs_data *data, const char *path)
   do
     {
       struct grub_ufs_dirent dirent;
+      int namelen;
       
       if (grub_strlen (name) == 0)
 	return GRUB_ERR_NONE;
@@ -454,15 +464,18 @@ grub_ufs_find_file (struct grub_ufs_data *data, const char *path)
       if (grub_ufs_read_file (data, 0, pos, sizeof (dirent),
 			      (char *) &dirent) < 0)
 	return grub_errno;
+
+      namelen = (data->ufs_type == UFS2)
+	? dirent.namelen_bsd : grub_le_to_cpu16 (dirent.namelen);
       
       {
-	char filename[dirent.namelen + 1];
+	char filename[namelen + 1];
 
 	if (grub_ufs_read_file (data, 0, pos + sizeof (dirent),
-				dirent.namelen, filename) < 0)
+				namelen, filename) < 0)
 	  return grub_errno;
 	
-	filename[dirent.namelen] = '\0';
+	filename[namelen] = '\0';
 	
 	if (!grub_strcmp (name, filename))
 	  {
@@ -595,21 +608,25 @@ grub_ufs_dir (grub_device_t device, const char *path,
   while (pos < INODE_SIZE (data))
     {
       struct grub_ufs_dirent dirent;
+      int namelen;
       
       if (grub_ufs_read_file (data, 0, pos, sizeof (dirent),
 			      (char *) &dirent) < 0)
 	break;
+
+      namelen = (data->ufs_type == UFS2)
+	? dirent.namelen_bsd : grub_le_to_cpu16 (dirent.namelen);
       
       {
-	char filename[dirent.namelen + 1];
+	char filename[namelen + 1];
 	struct grub_dirhook_info info;
 	grub_memset (&info, 0, sizeof (info));
 	
 	if (grub_ufs_read_file (data, 0, pos + sizeof (dirent),
-				dirent.namelen, filename) < 0)
+				namelen, filename) < 0)
 	  break;
 	
-	filename[dirent.namelen] = '\0';
+	filename[namelen] = '\0';
 	if (data->ufs_type == UFS1)
 	  {
 	    struct grub_ufs_inode inode;

             reply	other threads:[~2009-04-06 13:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-06 13:29 phcoder [this message]
2009-04-07  0:26 ` UFS fixes Yoshinori K. Okuji
2009-04-10 21:47   ` phcoder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49DA03D6.2020909@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.