static int img_name_parser(const struct option *opt, const char *arg, int unset)
{
- char *sep;
- struct stat st;
char path[PATH_MAX];
+ const char *cur;
+ struct stat st;
+ char *sep;
if (stat(arg, &st) == 0 &&
S_ISDIR(st.st_mode)) {
die("Currently only 4 images are supported");
disk_image[image_count].filename = arg;
- sep = strstr(arg, ",");
- if (sep) {
- if (strcmp(sep + 1, "ro") == 0)
- disk_image[image_count].readonly = true;
- *sep = 0;
- }
+ cur = arg;
+ do {
+ sep = strstr(cur, ",");
+ if (sep) {
+ if (strncmp(sep + 1, "ro", 2) == 0)
+ disk_image[image_count].readonly = true;
+ else if (strncmp(sep + 1, "direct", 6) == 0)
+ disk_image[image_count].direct = true;
+ *sep = 0;
+ cur = sep + 1;
+ }
+ } while (sep);
image_count++;
return false;
}
-struct disk_image *blkdev__probe(const char *filename, struct stat *st)
+struct disk_image *blkdev__probe(const char *filename, int flags, struct stat *st)
{
struct disk_image *disk;
int fd, r;
* Be careful! We are opening host block device!
* Open it readonly since we do not want to break user's data on disk.
*/
- fd = open(filename, O_RDWR);
+ fd = open(filename, flags);
if (fd < 0)
return ERR_PTR(fd);
return disk;
}
-struct disk_image *disk_image__open(const char *filename, bool readonly)
+struct disk_image *disk_image__open(const char *filename, bool readonly, bool direct)
{
struct disk_image *disk;
struct stat st;
- int fd;
+ int fd, flags;
+
+ if (readonly)
+ flags = O_RDONLY;
+ else
+ flags = O_RDWR;
+ if (direct)
+ flags |= O_DIRECT;
if (stat(filename, &st) < 0)
return ERR_PTR(-errno);
/* blk device ?*/
- disk = blkdev__probe(filename, &st);
+ disk = blkdev__probe(filename, flags, &st);
if (!IS_ERR_OR_NULL(disk))
return disk;
- fd = open(filename, readonly ? O_RDONLY : O_RDWR);
+ fd = open(filename, flags);
if (fd < 0)
return ERR_PTR(fd);
struct disk_image **disks;
const char *filename;
bool readonly;
+ bool direct;
void *err;
int i;
for (i = 0; i < count; i++) {
filename = params[i].filename;
readonly = params[i].readonly;
+ direct = params[i].direct;
if (!filename)
continue;
- disks[i] = disk_image__open(filename, readonly);
+ disks[i] = disk_image__open(filename, readonly, direct);
if (IS_ERR_OR_NULL(disks[i])) {
pr_err("Loading disk image '%s' failed", filename);
err = disks[i];
struct disk_image_params {
const char *filename;
bool readonly;
+ bool direct;
};
struct disk_image {
#endif
};
-struct disk_image *disk_image__open(const char *filename, bool readonly);
+struct disk_image *disk_image__open(const char *filename, bool readonly, bool direct);
struct disk_image **disk_image__open_all(struct disk_image_params *params, int count);
struct disk_image *disk_image__new(int fd, u64 size, struct disk_image_operations *ops, int mmap);
int disk_image__close(struct disk_image *disk);
ssize_t disk_image__get_serial(struct disk_image *disk, void *buffer, ssize_t *len);
struct disk_image *raw_image__probe(int fd, struct stat *st, bool readonly);
-struct disk_image *blkdev__probe(const char *filename, struct stat *st);
+struct disk_image *blkdev__probe(const char *filename, int flags, struct stat *st);
ssize_t raw_image__read(struct disk_image *disk, u64 sector,
const struct iovec *iov, int iovcount, void *param);