Commit 1f85380f authored by Adrien Plazas's avatar Adrien Plazas
Browse files

playstation: Add DiscFileInfo

This will be used in a subsequent commit to parse PlayStation disc
images.

https://bugzilla.gnome.org/show_bug.cgi?id=775255
parent e2541850
......@@ -36,6 +36,7 @@ libgames_playstation_plugin_la_DEPENDENCIES = \
libgames_playstation_plugin_la_SOURCES = \
$(BUILT_SOURCES) \
disc-file-info.c \
disc-image-time.c \
playstation-error.vala \
playstation-game-factory.vala \
......
// This file is part of GNOME Games. License: GPL-3.0+.
#include "disc-file-info.h"
#include <string.h>
#include <stdio.h>
#include <gio/gio.h>
/* Private */
static gboolean
games_disc_file_info_is_valid (const GamesDiscFileInfo *file_info)
{
// FIXME Magic number, I have no idea what it is but it works.
const gsize MAGIC_SIZE = 47;
g_return_val_if_fail (file_info != NULL, FALSE);
return file_info->length >= MAGIC_SIZE + file_info->name_length;
}
static gchar *
games_disc_file_info_get_name (GamesDiscFileInfo *file_info)
{
g_return_val_if_fail (file_info != NULL, NULL);
return g_strndup (games_disc_file_info_access_name (file_info), file_info->name_length);
}
static GamesDiscFileInfo *
games_disc_file_info_get_next (const GamesDiscFileInfo *file_info)
{
g_return_val_if_fail (file_info != NULL, NULL);
if (!games_disc_file_info_is_valid (file_info))
return NULL;
return (GamesDiscFileInfo *) ((gpointer) file_info + file_info->length);
}
/* Public */
gboolean
games_disc_file_info_is_directory (GamesDiscFileInfo *file_info)
{
g_return_val_if_fail (file_info != NULL, FALSE);
return file_info->flags & 0x2;
}
gchar *
games_disc_file_info_access_name (GamesDiscFileInfo *file_info)
{
g_return_val_if_fail (file_info != NULL, NULL);
return (gchar *) file_info + sizeof (GamesDiscFileInfo);
}
void
games_disc_file_info_foreach_file (GamesDiscFileInfo *file_info,
gsize size,
GamesDiscFileInfoForeachCallback callback,
gpointer user_data)
{
GamesDiscFileInfo *current;
GamesDiscFileInfo *next;
g_return_if_fail (file_info != NULL);
for (current = file_info; current != NULL && games_disc_file_info_is_valid (current); current = games_disc_file_info_get_next (current)) {
// The file info should never go beyond the end of the buffer.
if ((gpointer) current - (gpointer) file_info + sizeof (GamesDiscFileInfo) >= size ||
(gpointer) current - (gpointer) file_info + current->length >= size)
break;
if (!callback (current, user_data))
break;
}
}
// This file is part of GNOME Games. License: GPL-3.0+.
#ifndef DISC_FILE_INFO_H
#define DISC_FILE_INFO_H
#include <glib.h>
G_BEGIN_DECLS
typedef struct _GamesDiscFileInfo GamesDiscFileInfo;
struct _GamesDiscFileInfo {
guint8 length;
guint8 ext_attr_length;
guint8 extent[8];
guint8 size[8];
guint8 date[7];
guint8 flags;
guint8 file_unit_size;
guint8 interleave;
guint8 volume_sequence_number[4];
guint8 name_length;
};
typedef gboolean (*GamesDiscFileInfoForeachCallback) (GamesDiscFileInfo *file_info, gpointer user_data);
gboolean games_disc_file_info_is_directory (GamesDiscFileInfo *file_info);
gchar *games_disc_file_info_access_name (GamesDiscFileInfo *file_info);
void games_disc_file_info_foreach_file (GamesDiscFileInfo *file_info,
gsize size,
GamesDiscFileInfoForeachCallback callback,
gpointer user_data);
G_END_DECLS
#endif /* DISC_FILE_INFO_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment