sandbox.c (707acd01ded3c60a4e277f7c5432d397897b4dfd) | sandbox.c (7c4213f6a52f35ff6ba2d97aa4eb04cbfc963b86) |
---|---|
1/* 2 * Copyright (C) 2013 Henrik Nordstrom <henrik@henriknordstrom.net> 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7#include <config.h> 8#include <common.h> --- 8 unchanged lines hidden (view full) --- 17static struct host_block_dev *find_host_device(int dev) 18{ 19 if (dev >= 0 && dev < CONFIG_HOST_MAX_DEVICES) 20 return &host_devices[dev]; 21 22 return NULL; 23} 24 | 1/* 2 * Copyright (C) 2013 Henrik Nordstrom <henrik@henriknordstrom.net> 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7#include <config.h> 8#include <common.h> --- 8 unchanged lines hidden (view full) --- 17static struct host_block_dev *find_host_device(int dev) 18{ 19 if (dev >= 0 && dev < CONFIG_HOST_MAX_DEVICES) 20 return &host_devices[dev]; 21 22 return NULL; 23} 24 |
25static unsigned long host_block_read(int dev, unsigned long start, 26 lbaint_t blkcnt, void *buffer) | 25static unsigned long host_block_read(block_dev_desc_t *block_dev, 26 unsigned long start, lbaint_t blkcnt, 27 void *buffer) |
27{ | 28{ |
29 int dev = block_dev->dev; |
|
28 struct host_block_dev *host_dev = find_host_device(dev); 29 30 if (!host_dev) 31 return -1; 32 if (os_lseek(host_dev->fd, 33 start * host_dev->blk_dev.blksz, 34 OS_SEEK_SET) == -1) { 35 printf("ERROR: Invalid position\n"); 36 return -1; 37 } 38 ssize_t len = os_read(host_dev->fd, buffer, 39 blkcnt * host_dev->blk_dev.blksz); 40 if (len >= 0) 41 return len / host_dev->blk_dev.blksz; 42 return -1; 43} 44 | 30 struct host_block_dev *host_dev = find_host_device(dev); 31 32 if (!host_dev) 33 return -1; 34 if (os_lseek(host_dev->fd, 35 start * host_dev->blk_dev.blksz, 36 OS_SEEK_SET) == -1) { 37 printf("ERROR: Invalid position\n"); 38 return -1; 39 } 40 ssize_t len = os_read(host_dev->fd, buffer, 41 blkcnt * host_dev->blk_dev.blksz); 42 if (len >= 0) 43 return len / host_dev->blk_dev.blksz; 44 return -1; 45} 46 |
45static unsigned long host_block_write(int dev, unsigned long start, 46 lbaint_t blkcnt, const void *buffer) | 47static unsigned long host_block_write(block_dev_desc_t *block_dev, 48 unsigned long start, lbaint_t blkcnt, 49 const void *buffer) |
47{ | 50{ |
51 int dev = block_dev->dev; |
|
48 struct host_block_dev *host_dev = find_host_device(dev); 49 if (os_lseek(host_dev->fd, 50 start * host_dev->blk_dev.blksz, 51 OS_SEEK_SET) == -1) { 52 printf("ERROR: Invalid position\n"); 53 return -1; 54 } 55 ssize_t len = os_write(host_dev->fd, buffer, blkcnt * --- 69 unchanged lines hidden --- | 52 struct host_block_dev *host_dev = find_host_device(dev); 53 if (os_lseek(host_dev->fd, 54 start * host_dev->blk_dev.blksz, 55 OS_SEEK_SET) == -1) { 56 printf("ERROR: Invalid position\n"); 57 return -1; 58 } 59 ssize_t len = os_write(host_dev->fd, buffer, blkcnt * --- 69 unchanged lines hidden --- |