static void handle_unlink (char *own_buf) { char filename[PATH_MAX]; char *p; int ret; p = own_buf + strlen ("vFile:unlink:"); if (require_filename (&p, filename) || require_end (p)) { hostio_packet_error (own_buf); return; } ret = unlink (filename); if (ret == -1) { hostio_error (own_buf); return; } hostio_reply (own_buf, ret); }
static void handle_open (char *own_buf) { char filename[HOSTIO_PATH_MAX]; char *p; int fileio_flags, fileio_mode, flags, fd; mode_t mode; struct fd_list *new_fd; p = own_buf + strlen ("vFile:open:"); if (require_filename (&p, filename) || require_comma (&p) || require_int (&p, &fileio_flags) || require_comma (&p) || require_int (&p, &fileio_mode) || require_end (p) || fileio_to_host_openflags (fileio_flags, &flags) || fileio_to_host_mode (fileio_mode, &mode)) { hostio_packet_error (own_buf); return; } /* We do not need to convert MODE, since the fileio protocol uses the standard values. */ if (hostio_fs_pid != 0 && the_target->multifs_open != NULL) fd = the_target->multifs_open (hostio_fs_pid, filename, flags, mode); else fd = open (filename, flags, mode); if (fd == -1) { hostio_error (own_buf); return; } /* Record the new file descriptor. */ new_fd = xmalloc (sizeof (struct fd_list)); new_fd->fd = fd; new_fd->next = open_fds; open_fds = new_fd; hostio_reply (own_buf, fd); }
static void handle_open (char *own_buf) { char filename[PATH_MAX]; char *p; int fileio_flags, mode, flags, fd; struct fd_list *new_fd; p = own_buf + strlen ("vFile:open:"); if (require_filename (&p, filename) || require_comma (&p) || require_int (&p, &fileio_flags) || require_comma (&p) || require_int (&p, &mode) || require_end (p) || fileio_open_flags_to_host (fileio_flags, &flags)) { hostio_packet_error (own_buf); return; } /* We do not need to convert MODE, since the fileio protocol uses the standard values. */ fd = open (filename, flags, mode); if (fd == -1) { hostio_error (own_buf); return; } /* Record the new file descriptor. */ new_fd = xmalloc (sizeof (struct fd_list)); new_fd->fd = fd; new_fd->next = open_fds; open_fds = new_fd; hostio_reply (own_buf, fd); }
static void handle_readlink (char *own_buf, int *new_packet_len) { char filename[HOSTIO_PATH_MAX], linkname[HOSTIO_PATH_MAX]; char *p; int ret, bytes_sent; p = own_buf + strlen ("vFile:readlink:"); if (require_filename (&p, filename) || require_end (p)) { hostio_packet_error (own_buf); return; } if (hostio_fs_pid != 0 && the_target->multifs_readlink != NULL) ret = the_target->multifs_readlink (hostio_fs_pid, filename, linkname, sizeof (linkname) - 1); else ret = readlink (filename, linkname, sizeof (linkname) - 1); if (ret == -1) { hostio_error (own_buf); return; } bytes_sent = hostio_reply_with_data (own_buf, linkname, ret, new_packet_len); /* If the response does not fit into a single packet, do not attempt to return a partial response, but simply fail. */ if (bytes_sent < ret) sprintf (own_buf, "F-1,%x", FILEIO_ENAMETOOLONG); }