void LevelTransformer::transform(Level* level) { for(size_t i = 0; i < level->get_sector_count(); ++i) { transform_sector(level->get_sector(i)); } }
grub_err_t grub_disk_write (grub_disk_t disk, grub_disk_addr_t sector, grub_off_t offset, grub_size_t size, const void *buf) { unsigned real_offset; grub_disk_addr_t aligned_sector; grub_dprintf ("disk", "Writing `%s'...\n", disk->name); if (grub_disk_adjust_range (disk, §or, &offset, size) != GRUB_ERR_NONE) return -1; aligned_sector = (sector & ~((1ULL << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)) - 1)); real_offset = offset + ((sector - aligned_sector) << GRUB_DISK_SECTOR_BITS); sector = aligned_sector; while (size) { if (real_offset != 0 || (size < (1U << disk->log_sector_size) && size != 0)) { char *tmp_buf; grub_size_t len; grub_partition_t part; tmp_buf = grub_malloc (1U << disk->log_sector_size); if (!tmp_buf) return grub_errno; part = disk->partition; disk->partition = 0; if (grub_disk_read (disk, sector, 0, (1U << disk->log_sector_size), tmp_buf) != GRUB_ERR_NONE) { disk->partition = part; grub_free (tmp_buf); goto finish; } disk->partition = part; len = (1U << disk->log_sector_size) - real_offset; if (len > size) len = size; grub_memcpy (tmp_buf + real_offset, buf, len); grub_disk_cache_invalidate (disk->dev->id, disk->id, sector); if ((disk->dev->write) (disk, transform_sector (disk, sector), 1, tmp_buf) != GRUB_ERR_NONE) { grub_free (tmp_buf); goto finish; } grub_free (tmp_buf); sector += (1U << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); buf = (const char *) buf + len; size -= len; real_offset = 0; } else { grub_size_t len; grub_size_t n; len = size & ~((1ULL << disk->log_sector_size) - 1); n = size >> disk->log_sector_size; if (n > (disk->max_agglomerate << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS - disk->log_sector_size))) n = (disk->max_agglomerate << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS - disk->log_sector_size)); if ((disk->dev->write) (disk, transform_sector (disk, sector), n, buf) != GRUB_ERR_NONE) goto finish; while (n--) { grub_disk_cache_invalidate (disk->dev->id, disk->id, sector); sector += (1U << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); } buf = (const char *) buf + len; size -= len; } } finish: return grub_errno; }