コード例 #1
0
ファイル: bitsmodule.c プロジェクト: mfleming/bits
static PyObject *bits_disk_write(PyObject *self, PyObject *args)
{
    PyObject *pyfile;
    grub_file_t file;
    grub_disk_addr_t sector;
    const char *data;
    unsigned offset;
    int length;

    if (!PyArg_ParseTuple(args, "O!KIs#:disk_write", &PyFile_Type, &pyfile, &sector, &offset, &data, &length))
        return NULL;

    file = PyFile_AsFile(pyfile);
    if (!file->device->disk)
        return PyErr_Format(PyExc_RuntimeError, "Can't get disk device from non-disk-backed file");

    if (grub_disk_write(file->device->disk, sector, offset, length, data) != GRUB_ERR_NONE)
        return PyErr_SetFromErrno(PyExc_IOError);

    return Py_BuildValue("");
}
コード例 #2
0
ファイル: fs.c プロジェクト: P4N74/radare2
static grub_ssize_t
grub_fs_blocklist_rw (int write, grub_file_t file, char *buf, grub_size_t len)
{
  struct grub_fs_block *p;
  grub_off_t offset;
  grub_ssize_t ret = 0;

  if (len > file->size - file->offset)
    len = file->size - file->offset;

  offset = file->offset;
  for (p = file->data; p->length && len > 0; p++)
    {
      if (offset < p->length)
	{
	  grub_size_t size;

	  size = len;
	  if (offset + size > p->length)
	    size = p->length - offset;

	  if (buf && (write) ?
	       grub_disk_write (file->device->disk, 0, p->offset + offset,
				size, buf) :
	       grub_disk_read_ex (file->device->disk, 0, p->offset + offset,
				  size, buf, file->flags) != GRUB_ERR_NONE)
	    return -1;

	  ret += size;
	  len -= size;
	  if (buf)
	    buf += size;
	  offset += size;
	}
      offset -= p->length;
    }

  return ret;
}