static void printer_process_irp_write(PRINTER_DEVICE* printer_dev, IRP* irp) { UINT32 Length; UINT64 Offset; rdpPrintJob* printjob = NULL; stream_read_UINT32(irp->input, Length); stream_read_UINT64(irp->input, Offset); stream_seek(irp->input, 20); /* Padding */ if (printer_dev->printer != NULL) printjob = printer_dev->printer->FindPrintJob(printer_dev->printer, irp->FileId); if (printjob == NULL) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("printjob id %d not found.", irp->FileId); } else { printjob->Write(printjob, stream_get_tail(irp->input), Length); DEBUG_SVC("printjob id %d written %d bytes.", irp->FileId, Length); } stream_write_UINT32(irp->output, Length); stream_write_BYTE(irp->output, 0); /* Padding */ irp->Complete(irp); }
static void drive_process_irp_read(DRIVE_DEVICE* disk, IRP* irp) { DRIVE_FILE* file; UINT32 Length; UINT64 Offset; BYTE* buffer = NULL; stream_read_UINT32(irp->input, Length); stream_read_UINT64(irp->input, Offset); file = drive_get_file_by_id(disk, irp->FileId); if (file == NULL) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("FileId %d not valid.", irp->FileId); } else if (!drive_file_seek(file, Offset)) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("seek %s(%d) failed.", file->fullpath, file->id); } else { buffer = (BYTE*) malloc(Length); if (!drive_file_read(file, buffer, &Length)) { irp->IoStatus = STATUS_UNSUCCESSFUL; free(buffer); buffer = NULL; Length = 0; DEBUG_WARN("read %s(%d) failed.", file->fullpath, file->id); } else { DEBUG_SVC("read %llu-%llu from %s(%d).", Offset, Offset + Length, file->fullpath, file->id); } } stream_write_UINT32(irp->output, Length); if (Length > 0) { stream_check_size(irp->output, (int) Length); stream_write(irp->output, buffer, Length); } free(buffer); irp->Complete(irp); }
static void serial_process_irp_read(SERIAL_DEVICE* serial, IRP* irp) { SERIAL_TTY* tty; UINT32 Length; UINT64 Offset; BYTE* buffer = NULL; stream_read_UINT32(irp->input, Length); stream_read_UINT64(irp->input, Offset); DEBUG_SVC("length %u offset %llu", Length, Offset); tty = serial->tty; if (tty == NULL) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("tty not valid."); } else { buffer = (BYTE*) malloc(Length); if (!serial_tty_read(tty, buffer, &Length)) { irp->IoStatus = STATUS_UNSUCCESSFUL; free(buffer); buffer = NULL; Length = 0; DEBUG_WARN("read %s(%d) failed.", serial->path, tty->id); } else { DEBUG_SVC("read %llu-%llu from %d", Offset, Offset + Length, tty->id); } } stream_write_UINT32(irp->output, Length); if (Length > 0) { stream_check_size(irp->output, Length); stream_write(irp->output, buffer, Length); } free(buffer); irp->Complete(irp); }
static void drive_process_irp_write(DRIVE_DEVICE* disk, IRP* irp) { DRIVE_FILE* file; UINT32 Length; UINT64 Offset; stream_read_UINT32(irp->input, Length); stream_read_UINT64(irp->input, Offset); stream_seek(irp->input, 20); /* Padding */ file = drive_get_file_by_id(disk, irp->FileId); if (file == NULL) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("FileId %d not valid.", irp->FileId); } else if (!drive_file_seek(file, Offset)) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("seek %s(%d) failed.", file->fullpath, file->id); } else if (!drive_file_write(file, stream_get_tail(irp->input), Length)) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("write %s(%d) failed.", file->fullpath, file->id); } else { DEBUG_SVC("write %llu-%llu to %s(%d).", Offset, Offset + Length, file->fullpath, file->id); } stream_write_UINT32(irp->output, Length); stream_write_BYTE(irp->output, 0); /* Padding */ irp->Complete(irp); }
static void parallel_process_irp_read(PARALLEL_DEVICE* parallel, IRP* irp) { UINT32 Length; UINT64 Offset; ssize_t status; BYTE* buffer = NULL; stream_read_UINT32(irp->input, Length); stream_read_UINT64(irp->input, Offset); buffer = (BYTE*) malloc(Length); status = read(parallel->file, irp->output->p, Length); if (status < 0) { irp->IoStatus = STATUS_UNSUCCESSFUL; free(buffer); buffer = NULL; Length = 0; DEBUG_WARN("read %s(%d) failed", parallel->path, parallel->id); } else { DEBUG_SVC("read %llu-%llu from %d", Offset, Offset + Length, parallel->id); } stream_write_UINT32(irp->output, Length); if (Length > 0) { stream_check_size(irp->output, Length); stream_write(irp->output, buffer, Length); } free(buffer); irp->Complete(irp); }
static void serial_process_irp_write(SERIAL_DEVICE* serial, IRP* irp) { SERIAL_TTY* tty; UINT32 Length; UINT64 Offset; stream_read_UINT32(irp->input, Length); stream_read_UINT64(irp->input, Offset); stream_seek(irp->input, 20); /* Padding */ DEBUG_SVC("length %u offset %llu", Length, Offset); tty = serial->tty; if (tty == NULL) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("tty not valid."); } else if (!serial_tty_write(tty, stream_get_tail(irp->input), Length)) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("write %s(%d) failed.", serial->path, tty->id); } else { DEBUG_SVC("write %llu-%llu to %s(%d).", Offset, Offset + Length, serial->path, tty->id); } stream_write_UINT32(irp->output, Length); stream_write_BYTE(irp->output, 0); /* Padding */ irp->Complete(irp); }
static void parallel_process_irp_write(PARALLEL_DEVICE* parallel, IRP* irp) { UINT32 Length; UINT64 Offset; ssize_t status; UINT32 len; stream_read_UINT32(irp->input, Length); stream_read_UINT64(irp->input, Offset); stream_seek(irp->input, 20); /* Padding */ DEBUG_SVC("Length %u Offset %llu", Length, Offset); len = Length; while (len > 0) { status = write(parallel->file, stream_get_tail(irp->input), len); if (status < 0) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("write %s(%d) failed.", parallel->path, parallel->id); break; } stream_seek(irp->input, status); len -= status; } stream_write_UINT32(irp->output, Length); stream_write_BYTE(irp->output, 0); /* Padding */ irp->Complete(irp); }
BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UINT32 Length, STREAM* input) { char* s = NULL; mode_t m; UINT64 size; int status; char* fullpath; struct STAT st; struct timeval tv[2]; UINT64 LastWriteTime; UINT32 FileAttributes; UINT32 FileNameLength; m = 0; switch (FsInformationClass) { case FileBasicInformation: /* http://msdn.microsoft.com/en-us/library/cc232094.aspx */ stream_seek_UINT64(input); /* CreationTime */ stream_seek_UINT64(input); /* LastAccessTime */ stream_read_UINT64(input, LastWriteTime); stream_seek_UINT64(input); /* ChangeTime */ stream_read_UINT32(input, FileAttributes); if (FSTAT(file->fd, &st) != 0) return FALSE; tv[0].tv_sec = st.st_atime; tv[0].tv_usec = 0; tv[1].tv_sec = (LastWriteTime > 0 ? FILE_TIME_RDP_TO_SYSTEM(LastWriteTime) : st.st_mtime); tv[1].tv_usec = 0; #ifndef WIN32 /* TODO on win32 */ futimes(file->fd, tv); if (FileAttributes > 0) { m = st.st_mode; if ((FileAttributes & FILE_ATTRIBUTE_READONLY) == 0) m |= S_IWUSR; else m &= ~S_IWUSR; if (m != st.st_mode) fchmod(file->fd, st.st_mode); } #endif break; case FileEndOfFileInformation: /* http://msdn.microsoft.com/en-us/library/cc232067.aspx */ case FileAllocationInformation: /* http://msdn.microsoft.com/en-us/library/cc232076.aspx */ stream_read_UINT64(input, size); if (ftruncate(file->fd, size) != 0) return FALSE; break; case FileDispositionInformation: /* http://msdn.microsoft.com/en-us/library/cc232098.aspx */ /* http://msdn.microsoft.com/en-us/library/cc241371.aspx */ if (Length) stream_read_BYTE(input, file->delete_pending); else file->delete_pending = 1; break; case FileRenameInformation: /* http://msdn.microsoft.com/en-us/library/cc232085.aspx */ stream_seek_BYTE(input); /* ReplaceIfExists */ stream_seek_BYTE(input); /* RootDirectory */ stream_read_UINT32(input, FileNameLength); status = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) stream_get_tail(input), FileNameLength / 2, &s, 0, NULL, NULL); if (status < 1) s = (char*) calloc(1, 1); fullpath = drive_file_combine_fullpath(file->basepath, s); free(s); /* TODO rename does not work on win32 */ if (rename(file->fullpath, fullpath) == 0) { DEBUG_SVC("renamed %s to %s", file->fullpath, fullpath); drive_file_set_fullpath(file, fullpath); } else { DEBUG_WARN("rename %s to %s failed, errno = %d", file->fullpath, fullpath, errno); free(fullpath); return FALSE; } break; default: DEBUG_WARN("invalid FsInformationClass %d", FsInformationClass); return FALSE; } return TRUE; }