* grub-core/fs/minix.c: Remove variable length arrays. Reduces jfs.mod

by 356 bytes (158 compressed).
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-10-20 13:26:37 +02:00
parent 2359bf887c
commit a07e6ad010
2 changed files with 65 additions and 71 deletions

View file

@ -1,3 +1,8 @@
2013-10-20 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/fs/minix.c: Remove variable length arrays. Reduces jfs.mod
by 356 bytes (158 compressed).
2013-10-20 Vladimir Serbinenko <phcoder@gmail.com> 2013-10-20 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/fs/jfs.c: Remove variable length arrays. Reduces jfs.mod * grub-core/fs/jfs.c: Remove variable length arrays. Reduces jfs.mod

View file

@ -161,6 +161,12 @@ struct grub_minix_inode
#endif #endif
#if defined(MODE_MINIX3)
#define MAX_MINIX_FILENAME_SIZE 60
#else
#define MAX_MINIX_FILENAME_SIZE 30
#endif
/* Information about a "mounted" minix filesystem. */ /* Information about a "mounted" minix filesystem. */
struct grub_minix_data struct grub_minix_data
{ {
@ -346,16 +352,19 @@ grub_minix_read_inode (struct grub_minix_data *data, grub_minix_ino_t ino)
static grub_err_t static grub_err_t
grub_minix_lookup_symlink (struct grub_minix_data *data, grub_minix_ino_t ino) grub_minix_lookup_symlink (struct grub_minix_data *data, grub_minix_ino_t ino)
{ {
char symlink[GRUB_MINIX_INODE_SIZE (data) + 1]; char *symlink;
grub_size_t sz = GRUB_MINIX_INODE_SIZE (data);
if (++data->linknest > GRUB_MINIX_MAX_SYMLNK_CNT) if (++data->linknest > GRUB_MINIX_MAX_SYMLNK_CNT)
return grub_error (GRUB_ERR_SYMLINK_LOOP, N_("too deep nesting of symlinks")); return grub_error (GRUB_ERR_SYMLINK_LOOP, N_("too deep nesting of symlinks"));
if (grub_minix_read_file (data, 0, 0, 0, symlink = grub_malloc (sz + 1);
GRUB_MINIX_INODE_SIZE (data), symlink) < 0) if (!symlink)
return grub_errno;
if (grub_minix_read_file (data, 0, 0, 0, sz, symlink) < 0)
return grub_errno; return grub_errno;
symlink[GRUB_MINIX_INODE_SIZE (data)] = '\0'; symlink[sz] = '\0';
/* The symlink is an absolute path, go back to the root inode. */ /* The symlink is an absolute path, go back to the root inode. */
if (symlink[0] == '/') if (symlink[0] == '/')
@ -376,37 +385,37 @@ grub_minix_lookup_symlink (struct grub_minix_data *data, grub_minix_ino_t ino)
static grub_err_t static grub_err_t
grub_minix_find_file (struct grub_minix_data *data, const char *path) grub_minix_find_file (struct grub_minix_data *data, const char *path)
{ {
char fpath[grub_strlen (path) + 1]; const char *name;
char *name = fpath; const char *next = path;
char *next;
unsigned int pos = 0; unsigned int pos = 0;
grub_minix_ino_t dirino; grub_minix_ino_t dirino;
grub_strcpy (fpath, path); while (1)
{
name = next;
/* Skip the first slash. */ /* Skip the first slash. */
while (*name == '/') while (*name == '/')
name++; name++;
if (!*name) if (!*name)
return 0; return GRUB_ERR_NONE;
if ((GRUB_MINIX_INODE_MODE (data)
& GRUB_MINIX_IFDIR) != GRUB_MINIX_IFDIR)
return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory"));
/* Extract the actual part from the pathname. */ /* Extract the actual part from the pathname. */
next = grub_strchr (name, '/'); for (next = name; *next && *next != '/'; next++);
if (next)
{
next[0] = '\0';
next++;
while (*next == '/')
next++;
}
do for (pos = 0; ; )
{ {
grub_minix_ino_t ino; grub_minix_ino_t ino;
char filename[data->filename_size + 1]; char filename[MAX_MINIX_FILENAME_SIZE + 1];
if (grub_strlen (name) == 0) if (pos >= GRUB_MINIX_INODE_SIZE (data))
return GRUB_ERR_NONE; {
grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file `%s' not found"), path);
return grub_errno;
}
if (grub_minix_read_file (data, 0, 0, pos, sizeof (ino), if (grub_minix_read_file (data, 0, 0, pos, sizeof (ino),
(char *) &ino) < 0) (char *) &ino) < 0)
@ -415,11 +424,14 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path)
data->filename_size, (char *) filename)< 0) data->filename_size, (char *) filename)< 0)
return grub_errno; return grub_errno;
pos += sizeof (ino) + data->filename_size;
filename[data->filename_size] = '\0'; filename[data->filename_size] = '\0';
/* Check if the current direntry matches the current part of the /* Check if the current direntry matches the current part of the
pathname. */ pathname. */
if (!grub_strcmp (name, filename)) if (grub_strncmp (name, filename, next - name) == 0
&& filename[next - name] == '\0')
{ {
dirino = data->ino; dirino = data->ino;
grub_minix_read_inode (data, grub_minix_to_cpu_ino (ino)); grub_minix_read_inode (data, grub_minix_to_cpu_ino (ino));
@ -433,33 +445,10 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path)
return grub_errno; return grub_errno;
} }
if (!next) break;
return 0; }
pos = 0;
name = next;
next = grub_strchr (name, '/');
if (next)
{
next[0] = '\0';
next++;
while (*next == '/')
next++;
} }
if ((GRUB_MINIX_INODE_MODE (data)
& GRUB_MINIX_IFDIR) != GRUB_MINIX_IFDIR)
return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory"));
continue;
} }
pos += sizeof (ino) + data->filename_size;
} while (pos < GRUB_MINIX_INODE_SIZE (data));
grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file `%s' not found"), path);
return grub_errno;
} }
@ -561,7 +550,7 @@ grub_minix_dir (grub_device_t device, const char *path,
while (pos < GRUB_MINIX_INODE_SIZE (data)) while (pos < GRUB_MINIX_INODE_SIZE (data))
{ {
grub_minix_ino_t ino; grub_minix_ino_t ino;
char filename[data->filename_size + 1]; char filename[MAX_MINIX_FILENAME_SIZE + 1];
grub_minix_ino_t dirino = data->ino; grub_minix_ino_t dirino = data->ino;
struct grub_dirhook_info info; struct grub_dirhook_info info;
grub_memset (&info, 0, sizeof (info)); grub_memset (&info, 0, sizeof (info));