[Sheepdog] [PATCH 1/3] collie: make offset and len block-aligned in vdi_read()/vdi_write()
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Mon Oct 17 17:34:20 CEST 2011
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
collie/vdi.c | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/collie/vdi.c b/collie/vdi.c
index 6ac73cf..6343207 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -971,10 +971,18 @@ static int vdi_read(int argc, char **argv)
ret = parse_option_size(argv[optind++], &offset);
if (ret < 0)
return EXIT_USAGE;
+ if (offset % 512 != 0) {
+ fprintf(stderr, "offset must be block-aligned\n");
+ return EXIT_USAGE;
+ }
if (argv[optind]) {
ret = parse_option_size(argv[optind++], &total);
if (ret < 0)
return EXIT_USAGE;
+ if (total % 512 != 0) {
+ fprintf(stderr, "len must be block-aligned\n");
+ return EXIT_USAGE;
+ }
}
}
@@ -1007,6 +1015,7 @@ static int vdi_read(int argc, char **argv)
}
total = min(total, inode->vdi_size - offset);
+ total = roundup(total, 512);
idx = offset / SD_DATA_OBJ_SIZE;
while (done < total) {
len = min(total - done, SD_DATA_OBJ_SIZE - offset);
@@ -1057,10 +1066,18 @@ static int vdi_write(int argc, char **argv)
ret = parse_option_size(argv[optind++], &offset);
if (ret < 0)
return EXIT_USAGE;
+ if (offset % 512 != 0) {
+ fprintf(stderr, "offset must be block-aligned\n");
+ return EXIT_USAGE;
+ }
if (argv[optind]) {
ret = parse_option_size(argv[optind++], &total);
if (ret < 0)
return EXIT_USAGE;
+ if (total % 512 != 0) {
+ fprintf(stderr, "len must be block-aligned\n");
+ return EXIT_USAGE;
+ }
}
}
@@ -1092,6 +1109,7 @@ static int vdi_write(int argc, char **argv)
}
total = min(total, inode->vdi_size - offset);
+ total = roundup(total, 512);
idx = offset / SD_DATA_OBJ_SIZE;
while (done < total) {
create = 0;
--
1.7.2.5
More information about the sheepdog
mailing list