Skip to contentSkip to conversation

GRUB 1.95 cannot read the ufs filesystem

DISCUSSION Hitoshi Ozeki 4 participants 10 messages Apr 12, 2007 – Sep 19, 2007

lore
Share & tools
lore
#0 lore raw

Hello, all.

GRUB 1.95 cannot read the ufs filesystem. Because, 1.95 mistakes a usage of char pointer. This patch fixes this problem, and make it a bit better.

Attached file: ufs.patch.gz (1Kbytes)

Signature · 1 line
 Hitoshi Ozeki [email protected]
#1 lore raw
Quoted 3 lines · Hitoshi Ozeki

GRUB 1.95 cannot read the ufs filesystem. Because, 1.95 mistakes a usage of char pointer. This patch fixes this problem, and make it a bit better.

Thanks for you contribution.

Quoted 1 line

Attached file: ufs.patch.gz (1Kbytes)

In the future, could you maybe attach patches uncompressed, and inlined (or with mime-type text/plain or similar) so we can review the patch directly within the mail, and give you comments.

Thanks again,
Johan.

#2 lore raw
In reply to Hitoshi Ozeki
Quoted 5 lines · Hitoshi Ozeki

Hello, all.

GRUB 1.95 cannot read the ufs filesystem. Because, 1.95 mistakes a usage of char pointer. This patch fixes this problem, and make it a bit better.

Could you maybe point out the problem for us? Personally, I think the use of pointers make the code more complex.

~j

#3 lore raw

Hello, all.

Johan Rydberg wrote:
> GRUB 1.95 cannot read the ufs filesystem.
> This patch fixes this problem, and make it a bit better. Could you maybe point out the problem for us? Personally, I think the use of pointers make the code more complex.

At first, When we use the 'strcmp' for the purpose of comparision C-strings, It requires to terminate with the NIL sentry('\0').

----begin------------------------------- grub_ufs_find_file (struct grub_ufs_data *data, const char *path) {
char fpath[grub_strlen (path)]; <-- not enough.
char *name = fpath;
char *next;
unsigned int pos = 0;
int dirino;

grub_strncpy (fpath, path, grub_strlen (path)); <--without NIL.
----end---------------------------------

From the manpage of 'strncpy(3)':
The strcpy() function copies the string pointed to by src
(including
the terminating `\0' character) to the array pointed to by dest.
The
strings may not overlap, and the destination string dest must be
large
enough to receive the copy.

The strncpy() function is similar, except that not more than n bytes
of
src are copied. Thus, if there is no null byte among the first n
bytes
of src, the result will not be null-terminated.

At second, However we have the filepath in 'const char* path', The original code copies the filepath. It wastes the processor time.

If you think the use of pointers makes complex,
I recommend to use array and index.

In addition, ufs filesystem has no label.

----begin-------------------------------
static struct grub_fs grub_ufs_fs =
{
.name = "ufs",
.dir = grub_ufs_dir,
.open = grub_ufs_open,
.read = grub_ufs_read,
.close = grub_ufs_close,
.label = grub_ufs_label,
.next = 0
};
----end---------------------------------

The '.label' should set to 0.
On the original code, The 'label' function returns the invalid pointer, so the 'ls -l' command gets wrong.

Signature · 2 lines
Regard,
 Hitoshi Ozeki
#4 lore raw
Quoted 12 lines · Hitoshi Ozeki

At first, When we use the 'strcmp' for the purpose of comparision C-strings, It requires to terminate with the NIL sentry('\0').

----begin------------------------------- grub_ufs_find_file (struct grub_ufs_data *data, const char *path) {
char fpath[grub_strlen (path)]; <-- not enough.
char *name = fpath;
char *next;
unsigned int pos = 0;
int dirino;

Quoted 2 lines

grub_strncpy (fpath, path, grub_strlen (path)); <--without NIL.
----end---------------------------------

It feels easier to just add +1 at both the location. Can anyone else comment on this, please?

Quoted 3 lines

The '.label' should set to 0.
On the original code, The 'label' function returns the invalid pointer, so the 'ls -l' command gets wrong.

Marco?

~j

#5 lore raw
In reply to Hitoshi Ozeki
Quoted 12 lines · Hitoshi Ozeki

At first, When we use the 'strcmp' for the purpose of comparision C-strings, It requires to terminate with the NIL sentry('\0').

----begin------------------------------- grub_ufs_find_file (struct grub_ufs_data *data, const char *path) {
char fpath[grub_strlen (path)]; <-- not enough.
char *name = fpath;
char *next;
unsigned int pos = 0;
int dirino;

Quoted 2 lines

grub_strncpy (fpath, path, grub_strlen (path)); <--without NIL.
----end---------------------------------

It feels easier to just add +1 at both the location. Can anyone else comment on this, please?

Quoted 3 lines

The '.label' should set to 0.
On the original code, The 'label' function returns the invalid pointer, so the 'ls -l' command gets wrong.

Marco?

~j

#6 lore raw
In reply to Hitoshi Ozeki

Hello,all.

I wrote in the last:
At second, However we have the filepath in 'const char* path', The original code copies the filepath. It wastes the processor time.
If you think the use of pointers makes complex, I recommend to use array and index.

It doesn't only waste the processor time.

The original code uses a large amount of auto-variable. It wastes the stack space.
When we exhaust the stack space, we should expect the worst result.

GRUB is a bootloader, It does not support the virtual memory.

So we must stingy about the auto-variables.

Signature · 2 lines
Regards,
 Hitoshi Ozeki
#7 lore raw
In reply to Hitoshi Ozeki
Quoted 15 lines · Hitoshi Ozeki

In addition, ufs filesystem has no label.

----begin-------------------------------
static struct grub_fs grub_ufs_fs =
{
.name = "ufs",
.dir = grub_ufs_dir,
.open = grub_ufs_open,
.read = grub_ufs_read,
.close = grub_ufs_close,
.label = grub_ufs_label,
.next = 0
};
----end---------------------------------

Quoted 3 lines

The '.label' should set to 0.
On the original code, The 'label' function returns the invalid pointer, so the 'ls -l' command gets wrong.

That is right, but I think UFS2 supports a volume name. Does anybody know it?

Thanks,
Okuji

#8 lore raw

i think volume name of ufs2 is stored at offset 680–711 in the super block.

btw, i also find out that volume name of fat is incorrect if international character is used.

Quoted 31 lines · Yoshinori K. Okuji
Quoted 15 lines · Hitoshi Ozeki

In addition, ufs filesystem has no label.

----begin-------------------------------
static struct grub_fs grub_ufs_fs =
{
.name = "ufs",
.dir = grub_ufs_dir,
.open = grub_ufs_open,
.read = grub_ufs_read,
.close = grub_ufs_close,
.label = grub_ufs_label,
.next = 0
};
----end---------------------------------

Quoted 3 lines

The '.label' should set to 0.
On the original code, The 'label' function returns the invalid pointer, so the 'ls -l' command gets wrong.

That is right, but I think UFS2 supports a volume name. Does anybody know it?

Thanks,
Okuji

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

Signature · 1 line
Bean
#9 lore raw
In reply to Yoshinori K. Okuji

Hello.

On 17 April 2007, I wrote:
--- begin grub-1.95/fs/ufs.c ---------------------------------- static struct grub_fs grub_ufs_fs =
{
.name = "ufs",
.dir = grub_ufs_dir,
.open = grub_ufs_open,
.read = grub_ufs_read,
.close = grub_ufs_close,
.label = grub_ufs_label,
.next = 0
};
--- end grub-1.95/fs/ufs.c ------------------------------------ The '.label' should set to 0.

On 4 September 2007, Okuji wrote:
but I think UFS2 supports a volume name.

This source is function "grub_normal_print_device_info()" of the "grub-1.95/normal/misc.c".

--- begin grub-1.95/normal/misc.c -----------------------------
dev = grub_device_open (name);
if (! dev)

    grub_printf ("Filesystem cannot be accessed");
  else if (! dev->disk || ! dev->disk->has_partitions ||
dev->disk->partition)
    {
      char *label;
      grub_fs_t fs;

      fs = grub_fs_probe (dev);
      /* Ignore all errors.  */
      grub_errno = 0;

      grub_printf ("Filesystem type %s", fs ? fs->name : "unknown");
	  
      if (fs && fs->label) 
	{
	  (fs->label) (dev, &label);		<----  We expect that C
string will be set as a 'label.'
	  if (grub_errno == GRUB_ERR_NONE)
	    {
	      if (label && grub_strlen (label)) 	<--- ouch! 'label'
is not C string.
		grub_printf (", Label %s", label);
	      grub_free (label);			<--- gaaaaah!
	    }
	  grub_errno = GRUB_ERR_NONE;
	}

--- end grub-1.95/normal/misc.c -------------------------------

In ufs.c, "label" function does nothing.
but, In "normal/misc.c" expects that "ufs.c" allocates a memory and terminates with NIL.

Even if we did not have any return value in the "label" function, it is not good to do nothing.

static grub_err_t
grub_ufs_label (grub_device_t device __attribute ((unused)),
char **label)
{
*label = grub_malloc (1);
**label = '\0';
return GRUB_ERR_NONE;
}

Signature · 2 lines
Regards,
 Hitoshi Ozeki