22 #include "gdb/fileio.h"
45 if (a >=
'0' && a <=
'9')
47 else if (a >=
'a' && a <=
'f')
48 *nibble = a -
'a' + 10;
49 else if (a >=
'A' && a <=
'F')
50 *nibble = a -
'A' + 10;
59 #if !defined (PATH_MAX) || (PATH_MAX > (PBUFSIZ / 2 + 1))
60 # define HOSTIO_PATH_MAX (PBUFSIZ / 2 + 1)
62 # define HOSTIO_PATH_MAX PATH_MAX
74 while (*p && *p !=
',')
86 filename[count++] = nib1 * 16 + nib2;
90 filename[count] =
'\0';
105 while (*p && *p !=
',')
115 *value = *value * 16 + nib;
127 int input_index, output_index, escaped;
133 for (input_index = 0; input_index < p_len; input_index++)
135 char b = p[input_index];
139 (*data)[output_index++] = b ^ 0x20;
145 (*data)[output_index++] = b;
154 *data_len = output_index;
184 for (fd_ptr = open_fds; fd_ptr != NULL; fd_ptr = fd_ptr->
next)
185 if (fd_ptr->
fd == fd)
202 sprintf (own_buf,
"F-1,%x", FILEIO_EINVAL);
208 sprintf (own_buf,
"F%x", result);
215 int input_index, output_index, out_maxlen;
217 sprintf (own_buf,
"F%x;", len);
218 output_index = strlen (own_buf);
222 for (input_index = 0; input_index < len; input_index++)
224 char b = buffer[input_index];
226 if (b ==
'$' || b ==
'#' || b ==
'}' || b ==
'*')
229 if (output_index + 2 > out_maxlen)
231 own_buf[output_index++] =
'}';
232 own_buf[output_index++] = b ^ 0x20;
236 if (output_index + 1 > out_maxlen)
238 own_buf[output_index++] = b;
242 *new_packet_len = output_index;
280 p = own_buf + strlen (
"vFile:setfs:");
300 int fileio_flags, fileio_mode, flags,
fd;
304 p = own_buf + strlen (
"vFile:open:");
325 fd = open (filename, flags, mode);
345 int fd, ret, len,
offset, bytes_sent;
347 static int max_reply_size = -1;
349 p = own_buf + strlen (
"vFile:pread:");
366 if (max_reply_size == -1)
368 sprintf (own_buf,
"F%x;",
PBUFSIZ);
369 max_reply_size =
PBUFSIZ - strlen (own_buf);
371 if (len > max_reply_size)
372 len = max_reply_size;
376 ret = pread (fd, data, len, offset);
383 ret = lseek (fd, offset, SEEK_SET);
385 ret = read (fd, data, len);
402 if (bytes_sent < ret)
415 p = own_buf + strlen (
"vFile:pwrite:");
422 ||
require_data (p, packet_len - (p - own_buf), &data, &len))
429 ret = pwrite (fd, data, len, offset);
436 ret = lseek (fd, offset, SEEK_SET);
438 ret = write (fd, data, len);
460 p = own_buf + strlen (
"vFile:fstat:");
470 if (fstat (fd, &st) == -1)
479 (
char *) &fst,
sizeof (fst),
484 if (bytes_sent <
sizeof (fst))
493 struct fd_list **open_fd_p, *old_fd;
495 p = own_buf + strlen (
"vFile:close:");
515 while ((*open_fd_p)->fd != fd)
516 open_fd_p = &(*open_fd_p)->
next;
519 *open_fd_p = (*open_fd_p)->
next;
532 p = own_buf + strlen (
"vFile:unlink:");
544 ret = unlink (filename);
562 p = own_buf + strlen (
"vFile:readlink:");
574 sizeof (linkname) - 1);
576 ret = readlink (filename, linkname,
sizeof (linkname) - 1);
588 if (bytes_sent < ret)
589 sprintf (own_buf,
"F-1,%x", FILEIO_ENAMETOOLONG);
599 else if (
startswith (own_buf,
"vFile:pread:"))
601 else if (
startswith (own_buf,
"vFile:pwrite:"))
603 else if (
startswith (own_buf,
"vFile:fstat:"))
605 else if (
startswith (own_buf,
"vFile:close:"))
607 else if (
startswith (own_buf,
"vFile:unlink:"))
609 else if (
startswith (own_buf,
"vFile:readlink:"))
611 else if (
startswith (own_buf,
"vFile:setfs:"))
int(* multifs_open)(int pid, const char *filename, int flags, mode_t mode)
static int require_filename(char **pp, char *filename)
static struct fd_list * open_fds
int fileio_to_host_mode(int fileio_mode, mode_t *mode_p)
static int require_comma(char **pp)
static int require_int(char **pp, int *value)
static int require_end(char *p)
static void handle_unlink(char *own_buf)
static void handle_readlink(char *own_buf, int *new_packet_len)
struct target_ops * the_target
void hostio_handle_new_gdb_connection(void)
int fileio_to_host_openflags(int fileio_open_flags, int *open_flags_p)
static void handle_pwrite(char *own_buf, int packet_len)
static void handle_fstat(char *own_buf, int *new_packet_len)
static void hostio_error(char *own_buf)
void host_to_fileio_stat(struct stat *st, struct fio_stat *fst)
static int startswith(const char *string, const char *pattern)
int(* multifs_unlink)(int pid, const char *filename)
static void hostio_packet_error(char *own_buf)
static void handle_close(char *own_buf)
int handle_vFile(char *own_buf, int packet_len, int *new_packet_len)
static void handle_open(char *own_buf)
static int require_data(char *p, int p_len, char **data, int *data_len)
static int hostio_reply_with_data(char *own_buf, char *buffer, int len, int *new_packet_len)
ssize_t(* multifs_readlink)(int pid, const char *filename, char *buf, size_t bufsiz)
static int safe_fromhex(char a, int *nibble)
static void handle_setfs(char *own_buf)
static void hostio_reply(char *own_buf, int result)
static void handle_pread(char *own_buf, int *new_packet_len)
static int require_valid_fd(int fd)
void write_enn(char *buf)
void(* hostio_last_error)(char *buf)