diff options
author | Richard Weinberger <richard@nod.at> | 2011-11-02 08:17:27 -0400 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2011-11-02 09:15:42 -0400 |
commit | 8535639810e578960233ad39def3ac2157b0c3ec (patch) | |
tree | 519778b447082e802b42c2d6720475ca1cc7c96e /arch/um/drivers | |
parent | 0d65ede0a605d6252acc5c8a9c536c4cd0211f3c (diff) |
um: fix ubd cow size
ubd_file_size() cannot use ubd_dev->cow.file because at this time
ubd_dev->cow.file is not initialized.
Therefore, ubd_file_size() will always report a wrong disk size when
COW files are used.
Reading from /dev/ubd* would crash the kernel.
We have to read the correct disk size from the COW file's backing
file.
Signed-off-by: Richard Weinberger <richard@nod.at>
CC: stable@kernel.org
Diffstat (limited to 'arch/um/drivers')
-rw-r--r-- | arch/um/drivers/ubd_kern.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index b3c854523e6c..944453a3ec99 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c | |||
@@ -511,8 +511,37 @@ __uml_exitcall(kill_io_thread); | |||
511 | static inline int ubd_file_size(struct ubd *ubd_dev, __u64 *size_out) | 511 | static inline int ubd_file_size(struct ubd *ubd_dev, __u64 *size_out) |
512 | { | 512 | { |
513 | char *file; | 513 | char *file; |
514 | int fd; | ||
515 | int err; | ||
516 | |||
517 | __u32 version; | ||
518 | __u32 align; | ||
519 | char *backing_file; | ||
520 | time_t mtime; | ||
521 | unsigned long long size; | ||
522 | int sector_size; | ||
523 | int bitmap_offset; | ||
524 | |||
525 | if (ubd_dev->file && ubd_dev->cow.file) { | ||
526 | file = ubd_dev->cow.file; | ||
527 | |||
528 | goto out; | ||
529 | } | ||
514 | 530 | ||
515 | file = ubd_dev->cow.file ? ubd_dev->cow.file : ubd_dev->file; | 531 | fd = os_open_file(ubd_dev->file, global_openflags, 0); |
532 | if (fd < 0) | ||
533 | return fd; | ||
534 | |||
535 | err = read_cow_header(file_reader, &fd, &version, &backing_file, \ | ||
536 | &mtime, &size, §or_size, &align, &bitmap_offset); | ||
537 | os_close_file(fd); | ||
538 | |||
539 | if(err == -EINVAL) | ||
540 | file = ubd_dev->file; | ||
541 | else | ||
542 | file = backing_file; | ||
543 | |||
544 | out: | ||
516 | return os_file_size(file, size_out); | 545 | return os_file_size(file, size_out); |
517 | } | 546 | } |
518 | 547 | ||