static uint32 disk_write(IRP * irp) { FILE_INFO * finfo; ssize_t r; uint32 len; LLOGLN(10, ("disk_write: id=%d len=%d off=%lld", irp->fileID, irp->inputBufferLength, irp->offset)); finfo = disk_get_file_info(irp->dev, irp->fileID); if (finfo == NULL) { LLOGLN(0, ("disk_read: invalid file id")); return RD_STATUS_INVALID_HANDLE; } if (finfo->is_dir) return RD_STATUS_FILE_IS_A_DIRECTORY; if (finfo->file == -1) return RD_STATUS_INVALID_HANDLE; if (lseek(finfo->file, irp->offset, SEEK_SET) == (off_t) - 1) return get_error_status(); len = 0; while (len < irp->inputBufferLength) { r = write(finfo->file, irp->inputBuffer, irp->inputBufferLength); if (r == -1) { return get_error_status(); } len += r; } return RD_STATUS_SUCCESS; }
void check_error(char* msg) { if(get_error_status() < 0) { printf("%s\n", msg); printf("%s\n", get_error_string()); exit(1); } }
static enum imx233_dcp_error_t imx233_dcp_job(int ch) { /* if IRQs are not enabled, don't enable channel interrupt and do some polling */ bool irq_enabled = irq_enabled(); /* enable channel, clear interrupt, enable interrupt */ imx233_icoll_enable_interrupt(INT_SRC_DCP, true); if(irq_enabled) __REG_SET(HW_DCP_CTRL) = HW_DCP_CTRL__CHANNEL_INTERRUPT_ENABLE(ch); __REG_CLR(HW_DCP_STAT) = HW_DCP_STAT__IRQ(ch); __REG_SET(HW_DCP_CHANNELCTRL) = HW_DCP_CHANNELCTRL__ENABLE_CHANNEL(ch); /* write back packet */ commit_discard_dcache_range(&channel_packet[ch], sizeof(struct imx233_dcp_packet_t)); /* write 1 to semaphore to run job */ HW_DCP_CHxCMDPTR(ch) = (uint32_t)PHYSICAL_ADDR(&channel_packet[ch]); HW_DCP_CHxSEMA(ch) = 1; /* wait completion */ if(irq_enabled) semaphore_wait(&channel_sema[ch], TIMEOUT_BLOCK); else while(__XTRACT_EX(HW_DCP_CHxSEMA(ch), HW_DCP_CHxSEMA__VALUE)) udelay(10); /* disable channel and interrupt */ __REG_CLR(HW_DCP_CTRL) = HW_DCP_CTRL__CHANNEL_INTERRUPT_ENABLE(ch); __REG_CLR(HW_DCP_CHANNELCTRL) = HW_DCP_CHANNELCTRL__ENABLE_CHANNEL(ch); /* read status */ return get_error_status(ch); }
static uint32 serial_read(IRP * irp) { long timeout = 90; SERIAL_DEVICE_INFO *info; struct termios *ptermios; char *buf; ssize_t r; info = (SERIAL_DEVICE_INFO *) irp->dev->info; ptermios = info->ptermios; /* Set timeouts kind of like the windows serial timeout parameters. Multiply timeout with requested read size */ if (info->read_total_timeout_multiplier | info->read_total_timeout_constant) { timeout = (info->read_total_timeout_multiplier * irp->length + info->read_total_timeout_constant + 99) / 100; } else if (info->read_interval_timeout) { timeout = (info->read_interval_timeout * irp->length + 99) / 100; } /* If a timeout is set, do a blocking read, which times out after some time. It will make rdesktop less responsive, but it will improve serial performance, by not reading one character at a time. */ if (timeout == 0) { ptermios->c_cc[VTIME] = 0; ptermios->c_cc[VMIN] = 0; } else { ptermios->c_cc[VTIME] = timeout; ptermios->c_cc[VMIN] = 1; } tcsetattr(info->file, TCSANOW, ptermios); buf = malloc(irp->length); memset(buf, 0, irp->length); r = read(info->file, buf, irp->length); if (r == -1) { free(buf); return get_error_status(); } else { info->event_txempty = r; irp->outputBuffer = buf; irp->outputBufferLength = r; return RD_STATUS_SUCCESS; } }
const char *Pdu::agent_error_reason() { int pdu_err = get_error_status(); if (pdu_err == 0) // any real error? return "not in error state"; int n_vbs = get_vb_count(); Vb bad; get_vb(bad, get_error_index() -1); // not zero based?? const char *pmsg = Snmp::error_string(get_error_status()); const char *id = bad.to_string_oid(); const char *val = bad.to_string_value(); const int HDR_SZ = 100; if (!output_) { int size = ACE_OS::strlen(pmsg) + ACE_OS::strlen(id) + ACE_OS::strlen(val); ACE_NEW_RETURN(output_, char[size + HDR_SZ], ""); }
static uint32 disk_read(IRP * irp) { FILE_INFO * finfo; char * buf; ssize_t r; LLOGLN(10, ("disk_read: id=%d len=%d off=%lld", irp->fileID, irp->length, irp->offset)); finfo = disk_get_file_info(irp->dev, irp->fileID); if (finfo == NULL) { LLOGLN(0, ("disk_read: invalid file id")); return RD_STATUS_INVALID_HANDLE; } if (finfo->is_dir) return RD_STATUS_FILE_IS_A_DIRECTORY; if (finfo->file == -1) return RD_STATUS_INVALID_HANDLE; if (lseek(finfo->file, irp->offset, SEEK_SET) == (off_t) - 1) return get_error_status(); buf = malloc(irp->length); memset(buf, 0, irp->length); r = read(finfo->file, buf, irp->length); if (r == -1) { free(buf); return get_error_status(); } else { irp->outputBuffer = buf; irp->outputBufferLength = r; return RD_STATUS_SUCCESS; } }
static uint32 serial_write_data(IRP * irp, uint8 * data, int len) { SERIAL_DEVICE_INFO * info; ssize_t r; info = (SERIAL_DEVICE_INFO *) irp->dev->info; r = write(info->file, data, len); if (r == -1) return get_error_status(); info->event_txempty = r; return RD_STATUS_SUCCESS; }
static uint32 serial_write(IRP * irp) { SERIAL_DEVICE_INFO * info; ssize_t r; uint32 len; info = (SERIAL_DEVICE_INFO *) irp->dev->info; len = 0; while (len < irp->inputBufferLength) { r = write(info->file, irp->inputBuffer, irp->inputBufferLength); if (r == -1) return get_error_status(); len += r; } info->event_txempty = len; LLOGLN(10, ("serial_write: id=%d len=%d off=%lld", irp->fileID, irp->inputBufferLength, irp->offset)); return RD_STATUS_SUCCESS; }
static uint32 disk_set_info(IRP * irp) { FILE_INFO *finfo; uint32 status; uint64 len; char * buf; int size; char * fullpath; struct stat file_stat; struct utimbuf tvs; int mode; uint32 attr; time_t t; LLOGLN(10, ("disk_set_info: class=%d id=%d", irp->infoClass, irp->fileID)); finfo = disk_get_file_info(irp->dev, irp->fileID); if (finfo == NULL) { LLOGLN(0, ("disk_set_info: invalid file id")); return RD_STATUS_INVALID_HANDLE; } status = RD_STATUS_SUCCESS; switch (irp->infoClass) { case FileBasicInformation: if (stat(finfo->fullpath, &file_stat) != 0) return get_error_status(); /* Change file time */ tvs.actime = file_stat.st_atime; tvs.modtime = file_stat.st_mtime; t = get_system_filetime(GET_UINT64(irp->inputBuffer, 8)); /* LastAccessTime */ if (t > 0) tvs.actime = t; t = get_system_filetime(GET_UINT64(irp->inputBuffer, 16)); /* LastWriteTime */ if (t > 0) tvs.modtime = t; utime(finfo->fullpath, &tvs); /* Change read-only flag */ attr = GET_UINT32(irp->inputBuffer, 32); if (attr == 0) break; mode = file_stat.st_mode; if (attr & FILE_ATTRIBUTE_READONLY) mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); else mode |= S_IWUSR; mode &= 0777; chmod(finfo->fullpath, mode); break; case FileEndOfFileInformation: case FileAllocationInformation: len = GET_UINT64(irp->inputBuffer, 0); set_file_size(finfo->file, len); break; case FileDispositionInformation: /* Delete on close */ finfo->delete_pending = 1; break; case FileRenameInformation: //replaceIfExists = GET_UINT8(irp->inputBuffer, 0); /* ReplaceIfExists */ //rootDirectory = GET_UINT8(irp->inputBuffer, 1); /* RootDirectory */ len = GET_UINT32(irp->inputBuffer, 2); size = len * 2; buf = malloc(size); memset(buf, 0, size); freerdp_get_wstr(buf, size, irp->inputBuffer + 6, len); fullpath = disk_get_fullpath(irp->dev, buf); free(buf); LLOGLN(10, ("disk_set_info: rename %s to %s", finfo->fullpath, fullpath)); if (rename(finfo->fullpath, fullpath) == 0) { free(finfo->fullpath); finfo->fullpath = fullpath; } else { free(fullpath); return get_error_status(); } break; default: LLOGLN(0, ("disk_set_info: invalid info class")); status = RD_STATUS_NOT_SUPPORTED; break; } return status; }
static uint32 disk_create_fullpath(IRP * irp, FILE_INFO * finfo, const char * fullpath) { int mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH; int flags = 0; char * p; struct stat file_stat; if (stat(fullpath, &file_stat) == 0) { finfo->is_dir = S_ISDIR(file_stat.st_mode); } else { finfo->is_dir = ((irp->createOptions & FILE_DIRECTORY_FILE) ? 1 : 0); } if (finfo->is_dir) { if (irp->createDisposition == FILE_CREATE) { if (mkdir(fullpath, mode) != 0) return get_error_status(); } finfo->dir = opendir(fullpath); if (finfo->dir == NULL) return get_error_status(); } else { switch (irp->createDisposition) { case FILE_SUPERSEDE: flags = O_TRUNC | O_CREAT; break; case FILE_OPEN: break; case FILE_CREATE: flags |= O_CREAT | O_EXCL; break; case FILE_OPEN_IF: flags |= O_CREAT; break; case FILE_OVERWRITE: flags |= O_TRUNC; break; case FILE_OVERWRITE_IF: flags |= O_TRUNC | O_CREAT; break; default: return RD_STATUS_INVALID_PARAMETER; } if ((irp->desiredAccess & GENERIC_ALL) || (irp->desiredAccess & GENERIC_WRITE) || (irp->desiredAccess & FILE_WRITE_DATA) || (irp->desiredAccess & FILE_APPEND_DATA)) { flags |= O_RDWR; } else { flags |= O_RDONLY; } finfo->file = open(fullpath, flags, mode); if (finfo->file == -1) return get_error_status(); } if (stat(fullpath, &finfo->file_stat) != 0) { return RD_STATUS_NO_SUCH_FILE; } p = strrchr(fullpath, '/'); finfo->file_attr = get_file_attribute((p ? p + 1 : fullpath), &finfo->file_stat); return RD_STATUS_SUCCESS; }
static uint32 disk_remove_dir(const char * path) { DIR * dir; struct dirent * pdirent; struct stat file_stat; char * p; uint32 ret = RD_STATUS_SUCCESS; dir = opendir(path); if (dir == NULL) return get_error_status(); pdirent = readdir(dir); while (pdirent) { if (strcmp(pdirent->d_name, ".") == 0 || strcmp(pdirent->d_name, "..") == 0) { pdirent = readdir(dir); continue; } p = malloc(strlen(path) + strlen(pdirent->d_name) + 2); sprintf(p, "%s/%s", path, pdirent->d_name); if (stat(p, &file_stat) != 0) { LLOGLN(0, ("disk_remove_dir: stat %s failed (%i)\n", p, errno)); ret = get_error_status(); } else if (S_ISDIR(file_stat.st_mode)) { ret = disk_remove_dir(p); } else { if (unlink(p) < 0) { LLOGLN(0, ("disk_remove_dir: unlink %s failed (%i)\n", p, errno)); ret = get_error_status(); } } free(p); if (ret != RD_STATUS_SUCCESS) break; pdirent = readdir(dir); } closedir(dir); if (ret == RD_STATUS_SUCCESS) { if (rmdir(path) < 0) { LLOGLN(0, ("disk_remove_dir: rmdir %s failed (%i)\n", path, errno)); ret = get_error_status(); } } return ret; }