All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] AFS fixes and improvements
@ 2009-07-17 19:30 Vladimir 'phcoder' Serbinenko
  2009-07-17 22:35 ` Vladimir 'phcoder' Serbinenko
  0 siblings, 1 reply; 16+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-07-17 19:30 UTC (permalink / raw)
  To: The development of GRUB 2

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

Hello. Currently I'm coding BFS (filesystem of BeOS and Haiku) which
is similar to AFS. So I took the later as codebase. I found some bugs
and incompletenesses in it. Here is the fix. Tested using grub-fstest
on virtual machine image downloaded from Syllable website and then
successfully booted from it using grub-mkrescue image

-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git

[-- Attachment #2: afs.diff --]
[-- Type: text/plain, Size: 6314 bytes --]

diff --git a/ChangeLog b/ChangeLog
index e38ebc5..7eb823f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2009-07-17  Vladimir Serbinenko  <phcoder@gmail.com>
+
+	Fix and improve AtheFS support.
+
+	* fs/afs.c: Fix comments style.
+	(grub_afs_blockrun): Declare as packed.
+	(grub_afs_datastream): Likewise.
+	(grub_afs_bnode): Likewise.
+	(grub_afs_btree): Likewise.
+	(grub_afs_sblock): Likewise.
+	Declare `name' as char.
+	(grub_afs_inode): Declare as packed.
+	Change void *vnode to grub_uint32_t unused.
+	(grub_afs_iterate_dir): Check that key_size is positive.
+	(grub_afs_mount): Don't read superblock twice.
+	(grub_afs_dir): Remove double semicolon.
+	Pass mtime.
+	(grub_afs_label): New function.
+	(grub_afs_fs): Add grub_afs_label.
+
 2009-07-16  Pavel Roskin  <proski@gnu.org>
 
 	* configure.ac: Never add "-c" to CFLAGS.
diff --git a/fs/afs.c b/fs/afs.c
index 1f6e163..10ae931 100644
--- a/fs/afs.c
+++ b/fs/afs.c
@@ -29,7 +29,8 @@
 #define	GRUB_AFS_DIRECT_BLOCK_COUNT	12
 #define	GRUB_AFS_BLOCKS_PER_DI_RUN	4
 
-#define	GRUB_AFS_SBLOCK_MAGIC1	0x41465331	/* AFS1 */
+/* AFS1 in hexadecimal.  */
+#define	GRUB_AFS_SBLOCK_MAGIC1	0x41465331
 #define	GRUB_AFS_SBLOCK_MAGIC2	0xdd121031
 #define	GRUB_AFS_SBLOCK_MAGIC3	0x15b6830e
 
@@ -81,7 +82,7 @@ struct grub_afs_blockrun
   grub_uint32_t group;
   grub_uint16_t start;
   grub_uint16_t len;
-};
+} __attribute__ ((packed));
 
 struct grub_afs_datastream
 {
@@ -92,7 +93,7 @@ struct grub_afs_datastream
   struct grub_afs_blockrun double_indirect;
   grub_afs_off_t max_double_indirect_range;
   grub_afs_off_t size;
-};
+} __attribute__ ((packed));
 
 struct grub_afs_bnode
 {
@@ -102,7 +103,7 @@ struct grub_afs_bnode
   grub_uint32_t key_count;
   grub_uint32_t key_size;
   char key_data[0];
-};
+} __attribute__ ((packed));
 
 struct grub_afs_btree
 {
@@ -111,11 +112,11 @@ struct grub_afs_btree
   grub_uint32_t tree_depth;
   grub_afs_bvalue_t last_node;
   grub_afs_bvalue_t first_free;
-} ;
+} __attribute__ ((packed));
 
 struct grub_afs_sblock
 {
-  grub_uint8_t name[32];
+  char name[32];
   grub_uint32_t magic1;
   grub_uint32_t byte_order;
   grub_uint32_t	block_size;
@@ -124,8 +125,10 @@ struct grub_afs_sblock
   grub_afs_off_t used_blocks;
   grub_uint32_t	inode_size;
   grub_uint32_t	magic2;
-  grub_uint32_t	block_per_group;	// Number of blocks per allocation group (Max 65536)
-  grub_uint32_t	alloc_group_shift;	// Number of bits to shift a group number to get a byte address.
+  /* Number of blocks per allocation group. (Max 65536)  */
+  grub_uint32_t	block_per_group;
+  /* Number of bits to shift a group number to get a byte address.  */
+  grub_uint32_t	alloc_group_shift;
   grub_uint32_t	alloc_group_count;
   grub_uint32_t	flags;
   struct grub_afs_blockrun log_block;
@@ -133,12 +136,15 @@ struct grub_afs_sblock
   grub_uint32_t valid_log_blocks;
   grub_uint32_t log_size;
   grub_uint32_t	magic3;
-  struct grub_afs_blockrun root_dir;	// Root dir inode.
-  struct grub_afs_blockrun deleted_files; // Directory containing files scheduled for deletion.
-  struct grub_afs_blockrun index_dir;	// Directory of index files.
+  /* Root dir inode.  */
+  struct grub_afs_blockrun root_dir;
+  /* Directory containing files scheduled for deletion.  */
+  struct grub_afs_blockrun deleted_files;
+  /* Directory of index files.  */
+  struct grub_afs_blockrun index_dir;
   grub_uint32_t boot_loader_size;
   grub_uint32_t	pad[7];
-};
+}  __attribute__ ((packed));
 
 struct grub_afs_inode
 {
@@ -153,13 +159,14 @@ struct grub_afs_inode
   grub_afs_bigtime modified_time;
   struct grub_afs_blockrun parent;
   struct grub_afs_blockrun attrib_dir;
-  grub_uint32_t index_type;		/* Key data-key only used for index files */
+  /* Key data-key only used for index files. */
+  grub_uint32_t index_type;
   grub_uint32_t inode_size;
-  void* vnode;
+  grub_uint32_t unused;
   struct grub_afs_datastream stream;
   grub_uint32_t	pad[4];
   grub_uint32_t small_data[1];
-};
+} __attribute__ ((packed));
 
 struct grub_fshelp_node
 {
@@ -343,7 +350,7 @@ grub_afs_iterate_dir (grub_fshelp_node_t dir,
 
           key_start = U16 (sb, (cur_key > 0) ? index[cur_key - 1] : 0);
           key_size = U16 (sb, index[cur_key]) - key_start;
-          if (key_size)
+          if (key_size > 0)
             {
               char filename [key_size + 1];
               struct grub_fshelp_node *fdiro;
@@ -470,14 +477,7 @@ grub_afs_mount (grub_disk_t disk)
     goto fail;
 
   if (! grub_afs_validate_sblock (&data->sblock))
-    {
-      if (grub_disk_read (disk, 1 * 2, 0, sizeof (struct grub_afs_sblock),
-                          &data->sblock))
-        goto fail;
-
-      if (! grub_afs_validate_sblock (&data->sblock))
-        goto fail;
-    }
+    goto fail;
 
   data->diropen.data = data;
   data->inode = &data->diropen.inode;
@@ -557,7 +557,7 @@ grub_afs_dir (grub_device_t device, const char *path,
               int (*hook) (const char *filename,
 			   const struct grub_dirhook_info *info))
 {
-  struct grub_afs_data *data = 0;;
+  struct grub_afs_data *data = 0;
   struct grub_fshelp_node *fdiro = 0;
 
   auto int NESTED_FUNC_ATTR iterate (const char *filename,
@@ -571,6 +571,8 @@ grub_afs_dir (grub_device_t device, const char *path,
       struct grub_dirhook_info info;
       grub_memset (&info, 0, sizeof (info));
       info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
+      info.mtimeset = 1;
+      info.mtime = grub_divmod64 (node->inode.modified_time, 1000000, 0);
       grub_free (node);
       return hook (filename, &info);
     }
@@ -598,13 +600,35 @@ grub_afs_dir (grub_device_t device, const char *path,
   return grub_errno;
 }
 
+static grub_err_t
+grub_afs_label (grub_device_t device, char **label)
+{
+  struct grub_afs_data *data;
+  grub_disk_t disk = device->disk;
+
+  grub_dl_ref (my_mod);
+
+  data = grub_afs_mount (disk);
+  if (data)
+    *label = grub_strndup (data->sblock.name, sizeof (data->sblock.name));
+  else
+    *label = NULL;
+
+  grub_dl_unref (my_mod);
+
+  grub_free (data);
+
+  return grub_errno;
+}
+
+
 static struct grub_fs grub_afs_fs = {
   .name = "afs",
   .dir = grub_afs_dir,
   .open = grub_afs_open,
   .read = grub_afs_read,
   .close = grub_afs_close,
-  .label = 0,
+  .label = grub_afs_label,
   .next = 0
 };
 

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2009-07-20 19:36 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-17 19:30 [PATCH] AFS fixes and improvements Vladimir 'phcoder' Serbinenko
2009-07-17 22:35 ` Vladimir 'phcoder' Serbinenko
2009-07-19  5:11   ` Pavel Roskin
2009-07-19 13:20     ` Vladimir 'phcoder' Serbinenko
2009-07-19 15:34       ` Vladimir 'phcoder' Serbinenko
2009-07-19 19:56         ` Pavel Roskin
2009-07-19 20:23           ` Vladimir 'phcoder' Serbinenko
2009-07-19 20:32             ` Pavel Roskin
2009-07-19 20:40               ` Vladimir 'phcoder' Serbinenko
2009-07-19 20:47                 ` Pavel Roskin
2009-07-20  9:36                   ` Vladimir 'phcoder' Serbinenko
2009-07-20 18:34                     ` Pavel Roskin
2009-07-20 18:56                       ` Vladimir 'phcoder' Serbinenko
2009-07-20 19:36                         ` Pavel Roskin
2009-07-19 20:10       ` Pavel Roskin
2009-07-19 20:18         ` Vladimir 'phcoder' Serbinenko

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.