Use a net fs struct to handle open, reand and close in file.
This commit is contained in:
parent
f42313bdb0
commit
7dd64f1236
5 changed files with 27 additions and 41 deletions
|
@ -25,9 +25,6 @@
|
|||
#include <grub/fs.h>
|
||||
#include <grub/device.h>
|
||||
|
||||
grub_ssize_t (*grub_file_net_read) (grub_file_t file, void *buf, grub_size_t len) = NULL;
|
||||
grub_err_t (*grub_file_net_open) (struct grub_file *file, const char *name) = NULL;
|
||||
grub_err_t (*grub_file_net_close) (grub_file_t file) = NULL;
|
||||
grub_err_t (*grub_file_net_seek) (struct grub_file *file, grub_off_t offset) = NULL;
|
||||
|
||||
grub_file_filter_t grub_file_filters_all[GRUB_FILE_FILTER_MAX];
|
||||
|
@ -91,13 +88,6 @@ grub_file_open (const char *name)
|
|||
|
||||
file->device = device;
|
||||
|
||||
if (device->net && grub_file_net_open)
|
||||
{
|
||||
if (grub_file_net_open (file, file_name))
|
||||
goto fail;
|
||||
return file;
|
||||
}
|
||||
|
||||
if (device->disk && file_name[0] != '/')
|
||||
/* This is a block list. */
|
||||
file->fs = &grub_fs_blocklist;
|
||||
|
@ -143,7 +133,7 @@ grub_file_open (const char *name)
|
|||
grub_ssize_t
|
||||
grub_file_read (grub_file_t file, void *buf, grub_size_t len)
|
||||
{
|
||||
grub_ssize_t res = 0;
|
||||
grub_ssize_t res;
|
||||
|
||||
if (file->offset > file->size)
|
||||
{
|
||||
|
@ -161,12 +151,7 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len)
|
|||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
if (file->device->disk)
|
||||
res = (file->fs->read) (file, buf, len);
|
||||
else
|
||||
if (grub_file_net_read && file->device->net)
|
||||
res = grub_file_net_read (file, buf, len);
|
||||
|
||||
res = (file->fs->read) (file, buf, len);
|
||||
if (res > 0)
|
||||
file->offset += res;
|
||||
|
||||
|
@ -176,12 +161,6 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len)
|
|||
grub_err_t
|
||||
grub_file_close (grub_file_t file)
|
||||
{
|
||||
if (file->device->net)
|
||||
{
|
||||
grub_file_net_close (file);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
if (file->fs->close)
|
||||
(file->fs->close) (file);
|
||||
|
||||
|
|
|
@ -94,8 +94,8 @@ grub_fs_probe (grub_device_t device)
|
|||
count--;
|
||||
}
|
||||
}
|
||||
else if (device->net)
|
||||
return NULL;
|
||||
else if (device->net && device->net->fs)
|
||||
return device->net->fs;
|
||||
|
||||
grub_error (GRUB_ERR_UNKNOWN_FS, "unknown filesystem");
|
||||
return 0;
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include <grub/mm.h>
|
||||
#include <grub/ieee1275/ieee1275.h>
|
||||
#include <grub/ieee1275/ofnet.h>
|
||||
#include <grub/net/ieee1275/interface.h>
|
||||
#include <grub/net.h>
|
||||
#include <grub/net/tftp.h>
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ struct grub_net_network_level_interface *grub_net_network_level_interfaces = NUL
|
|||
struct grub_net_card *grub_net_cards = NULL;
|
||||
struct grub_net_card_driver *grub_net_card_drivers = NULL;
|
||||
struct grub_net_network_level_protocol *grub_net_network_level_protocols = NULL;
|
||||
static struct grub_fs grub_net_fs;
|
||||
|
||||
static inline void
|
||||
grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter)
|
||||
|
@ -571,6 +572,7 @@ grub_net_open_real (const char *name)
|
|||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
ret->fs = &grub_net_fs;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -580,7 +582,7 @@ grub_net_open_real (const char *name)
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_net_file_open_real (struct grub_file *file, const char *name)
|
||||
grub_net_fs_open (struct grub_file *file, const char *name)
|
||||
{
|
||||
grub_err_t err;
|
||||
grub_net_network_level_address_t addr;
|
||||
|
@ -620,7 +622,7 @@ grub_net_file_open_real (struct grub_file *file, const char *name)
|
|||
if (err)
|
||||
goto fail;
|
||||
file->not_easily_seekable = 1;
|
||||
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
fail:
|
||||
grub_net_socket_unregister (socket);
|
||||
|
@ -630,7 +632,7 @@ fail:
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_net_file_close_real (grub_file_t file)
|
||||
grub_net_fs_close (grub_file_t file)
|
||||
{
|
||||
grub_net_socket_t sock = file->device->net->socket;
|
||||
while (sock->packs.first)
|
||||
|
@ -681,11 +683,11 @@ grub_net_poll_cards (unsigned time)
|
|||
|
||||
/* Read from the packets list*/
|
||||
static grub_ssize_t
|
||||
grub_net_read_real (grub_file_t file, void *buf, grub_size_t len)
|
||||
grub_net_fs_read (grub_file_t file, char *buf, grub_size_t len)
|
||||
{
|
||||
grub_net_socket_t sock = file->device->net->socket;
|
||||
struct grub_net_buff *nb;
|
||||
char *ptr = (char *) buf;
|
||||
char *ptr = buf;
|
||||
grub_size_t amount, total = 0;
|
||||
int try = 0;
|
||||
while (try <= 3)
|
||||
|
@ -744,7 +746,7 @@ grub_net_seek_real (struct grub_file *file, grub_off_t offset)
|
|||
return grub_netbuff_push (nb, file->offset - offset);
|
||||
}
|
||||
|
||||
grub_net_read_real (file, NULL, len);
|
||||
grub_net_fs_read (file, NULL, len);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
@ -1009,6 +1011,17 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)),
|
|||
"unrecognised format specification %s", args[3]);
|
||||
}
|
||||
|
||||
static struct grub_fs grub_net_fs =
|
||||
{
|
||||
.name = "netfs",
|
||||
.dir = NULL,
|
||||
.open = grub_net_fs_open,
|
||||
.read = grub_net_fs_read,
|
||||
.close = grub_net_fs_close,
|
||||
.label = NULL,
|
||||
.uuid = NULL,
|
||||
.mtime = NULL,
|
||||
};
|
||||
static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute;
|
||||
static grub_command_t cmd_lsroutes, cmd_lscards, cmd_getdhcp;
|
||||
|
||||
|
@ -1034,10 +1047,8 @@ GRUB_MOD_INIT(net)
|
|||
N_("VAR INTERFACE NUMBER DESCRIPTION"),
|
||||
N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value."));
|
||||
|
||||
grub_fs_register (&grub_net_fs);
|
||||
grub_net_open = grub_net_open_real;
|
||||
grub_file_net_open = grub_net_file_open_real;
|
||||
grub_file_net_close = grub_net_file_close_real;
|
||||
grub_file_net_read = grub_net_read_real;
|
||||
grub_file_net_seek = grub_net_seek_real;
|
||||
}
|
||||
|
||||
|
@ -1050,8 +1061,7 @@ GRUB_MOD_FINI(net)
|
|||
grub_unregister_command (cmd_lsroutes);
|
||||
grub_unregister_command (cmd_lscards);
|
||||
grub_unregister_command (cmd_getdhcp);
|
||||
grub_fs_unregister (&grub_net_fs);
|
||||
grub_net_open = NULL;
|
||||
grub_file_net_read = NULL;
|
||||
grub_file_net_open = NULL;
|
||||
grub_file_net_close = NULL;
|
||||
grub_file_net_seek = NULL;
|
||||
}
|
||||
|
|
|
@ -234,11 +234,10 @@ typedef struct grub_net
|
|||
char *name;
|
||||
grub_net_app_level_t protocol;
|
||||
grub_net_socket_t socket;
|
||||
grub_fs_t fs;
|
||||
} *grub_net_t;
|
||||
|
||||
extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name);
|
||||
extern grub_ssize_t (*EXPORT_VAR (grub_file_net_read)) (grub_file_t file, void *buf, grub_size_t len);
|
||||
extern grub_err_t (*EXPORT_VAR (grub_file_net_open)) (struct grub_file *file, const char *name);
|
||||
extern grub_err_t (*EXPORT_VAR (grub_file_net_seek)) (struct grub_file *file, grub_off_t offset);
|
||||
|
||||
struct grub_net_network_level_interface
|
||||
|
@ -434,5 +433,4 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface *inf,
|
|||
void
|
||||
grub_net_poll_cards (unsigned time);
|
||||
|
||||
extern grub_err_t (*EXPORT_VAR (grub_file_net_close)) (grub_file_t file);
|
||||
#endif /* ! GRUB_NET_HEADER */
|
||||
|
|
Loading…
Reference in a new issue