Skip to contentSkip to conversation

file easly seekable flag

PATCH In review Szymon Janc 2 participants 2 messages Apr 8, 2010 – Sep 4, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 file easly seekable flag

Hello,

Attached patch adds new flag to file structure.
It should be set by fs on files which cannot be easly seekable.

Also makes gzio respect this flag.

01_fileseek_indent.diff contains indentation fixes only not to blackout 02_fileseek.diff.

TODO:
should be also set by other fs when necessary (pxe?)

Signature · 2 lines
Szymon K. Janc
[email protected] // GG: 1383435

=== modified file 'include/grub/file.h'

grub/file.h +7 -7
@@ -44,18 +44,18 @@
 
   /* This is called when a sector is read. Used only for a disk device.  */
   void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
-		     unsigned offset, unsigned length);
+				      unsigned offset, unsigned length);
 };
 typedef struct grub_file *grub_file_t;
 
 /* Get a device name from NAME.  */
-char *EXPORT_FUNC(grub_file_get_device_name) (const char *name);
+char *EXPORT_FUNC (grub_file_get_device_name) (const char *name);
 
-grub_file_t EXPORT_FUNC(grub_file_open) (const char *name);
-grub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf,
-					  grub_size_t len);
-grub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset);
-grub_err_t EXPORT_FUNC(grub_file_close) (grub_file_t file);
+grub_file_t EXPORT_FUNC (grub_file_open) (const char *name);
+grub_ssize_t EXPORT_FUNC (grub_file_read) (grub_file_t file, void *buf,
+					   grub_size_t len);
+grub_off_t EXPORT_FUNC (grub_file_seek) (grub_file_t file, grub_off_t offset);
+grub_err_t EXPORT_FUNC (grub_file_close) (grub_file_t file);
 
 static inline grub_off_t
 grub_file_size (const grub_file_t file)

=== modified file 'io/gzio.c'

gzio.c +57 -53

242 lines not on this page · raw message

=== modified file 'kern/file.c'

file.c +6 -6
@@ -33,14 +33,14 @@
       char *p = grub_strchr (name, ')');
       char *ret;
 
-      if (! p)
+      if (!p)
 	{
 	  grub_error (GRUB_ERR_BAD_FILENAME, "missing `)'");
 	  return 0;
 	}
 
       ret = (char *) grub_malloc (p - name);
-      if (! ret)
+      if (!ret)
 	return 0;
 
       grub_memcpy (ret, name + 1, p - name - 1);
@@ -72,11 +72,11 @@
 
   device = grub_device_open (device_name);
   grub_free (device_name);
-  if (! device)
+  if (!device)
     goto fail;
 
   file = (grub_file_t) grub_zalloc (sizeof (*file));
-  if (! file)
+  if (!file)
     goto fail;
 
   file->device = device;
@@ -87,7 +87,7 @@
   else
     {
       file->fs = grub_fs_probe (device);
-      if (! file->fs)
+      if (!file->fs)
 	goto fail;
     }
 
@@ -96,7 +96,7 @@
 
   return file;
 
- fail:
+fail:
   if (device)
     grub_device_close (device);
 

=== modified file 'include/grub/file.h'

grub/file.h +9 -0
@@ -39,6 +39,9 @@
   /* The file size.  */
   grub_off_t size;
 
+  /* If file is not easly seekable. Should be set by underlying layer.  */
+  int not_easly_seekable;
+
   /* Filesystem-specific data.  */
   void *data;
 
@@ -69,4 +72,10 @@
   return file->offset;
 }
 
+static inline int
+grub_file_seekable (const grub_file_t file)
+{
+  return !file->not_easly_seekable;
+}
+
 #endif /* ! GRUB_FILE_HEADER */

=== modified file 'io/gzio.c'

gzio.c +8 -5
@@ -173,6 +173,7 @@
     grub_uint8_t extra_flags;
     grub_uint8_t os_type;
   } hdr;
+
   grub_uint16_t extra_len;
   grub_uint32_t orig_len;
   grub_gzio_t gzio = file->data;
@@ -214,12 +215,14 @@
 
   grub_file_seek (gzio->file, grub_file_size (gzio->file) - 4);
 
-  if (grub_file_read (gzio->file, &orig_len, 4) != 4)
+  if (grub_file_seekable (gzio->file))
     {
-      grub_error (GRUB_ERR_BAD_FILE_TYPE, "unsupported gzip format");
-      return 0;
+      if (grub_file_read (gzio->file, &orig_len, 4) != 4)
+	{
+	  grub_error (GRUB_ERR_BAD_FILE_TYPE, "unsupported gzip format");
+	  return 0;
+	}
     }
-
   /* FIXME: this does not handle files whose original size is over 4GB.
      But how can we know the real original size?  */
   file->size = grub_le_to_cpu32 (orig_len);
@@ -1140,6 +1143,7 @@
   file->data = gzio;
   file->read_hook = 0;
   file->fs = &grub_gzio_fs;
+  file->not_easly_seekable = 1;
 
   if (!test_header (file))
     {
@@ -1241,7 +1245,6 @@
 
   return grub_errno;
 }
-
 
 
 static struct grub_fs grub_gzio_fs = {
#1 lore raw

Comitted. Thanks

Quoted 21 lines · Szymon Janc

Hello,

Attached patch adds new flag to file structure.
It should be set by fs on files which cannot be easly seekable.

Also makes gzio respect this flag.

01_fileseek_indent.diff contains indentation fixes only not to blackout 02_fileseek.diff.

TODO:
should be also set by other fs when necessary (pxe?)

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko