aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Schulz <quentin.schulz@bootlin.com>2018-07-02 05:43:51 -0400
committerRichard Weinberger <richard@nod.at>2018-08-14 18:25:21 -0400
commitc355aa465fce5b446789348a2c50c3eb58ee6756 (patch)
tree5333f16f778229dcd69b7c455eabb716f027592e
parent62652517753f3cdddce10935139cfa6e00f8da33 (diff)
ubi: expose the volume CRC check skip flag
Now that we have the logic for skipping CRC check for static UBI volumes in the core, let's expose it to users. This makes use of a padding byte in the volume description data structure as a flag. This flag only tell for now whether we should skip the CRC check of a volume. This checks the UBI volume for which we are trying to skip the CRC check is static. Let's also make sure that the flags passed to verify_mkvol_req are valid. We voluntarily do not take into account the skip_check flag in vol_cdev_write() as we want to make sure what we wrote was correctly written. Suggested-by: Boris Brezillon <boris.brezillon@bootlin.com> Signed-off-by: Quentin Schulz <quentin.schulz@bootlin.com> Reviewed-by: Boris Brezillon <boris.brezillon@bootlin.com> Signed-off-by: Richard Weinberger <richard@nod.at>
-rw-r--r--drivers/mtd/ubi/cdev.c11
-rw-r--r--drivers/mtd/ubi/vmt.c3
-rw-r--r--include/uapi/mtd/ubi-user.h18
3 files changed, 30 insertions, 2 deletions
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 45c329694a5e..22547d7a84ea 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -367,6 +367,10 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf,
367 return count; 367 return count;
368 } 368 }
369 369
370 /*
371 * We voluntarily do not take into account the skip_check flag
372 * as we want to make sure what we wrote was correctly written.
373 */
370 err = ubi_check_volume(ubi, vol->vol_id); 374 err = ubi_check_volume(ubi, vol->vol_id);
371 if (err < 0) 375 if (err < 0)
372 return err; 376 return err;
@@ -622,6 +626,13 @@ static int verify_mkvol_req(const struct ubi_device *ubi,
622 req->vol_type != UBI_STATIC_VOLUME) 626 req->vol_type != UBI_STATIC_VOLUME)
623 goto bad; 627 goto bad;
624 628
629 if (req->flags & ~UBI_VOL_VALID_FLGS)
630 goto bad;
631
632 if (req->flags & UBI_VOL_SKIP_CRC_CHECK_FLG &&
633 req->vol_type != UBI_STATIC_VOLUME)
634 goto bad;
635
625 if (req->alignment > ubi->leb_size) 636 if (req->alignment > ubi->leb_size)
626 goto bad; 637 goto bad;
627 638
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index e2606a4e1c9e..729588b94e41 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -174,6 +174,9 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
174 vol->dev.class = &ubi_class; 174 vol->dev.class = &ubi_class;
175 vol->dev.groups = volume_dev_groups; 175 vol->dev.groups = volume_dev_groups;
176 176
177 if (req->flags & UBI_VOL_SKIP_CRC_CHECK_FLG)
178 vol->skip_check = 1;
179
177 spin_lock(&ubi->volumes_lock); 180 spin_lock(&ubi->volumes_lock);
178 if (vol_id == UBI_VOL_NUM_AUTO) { 181 if (vol_id == UBI_VOL_NUM_AUTO) {
179 /* Find unused volume ID */ 182 /* Find unused volume ID */
diff --git a/include/uapi/mtd/ubi-user.h b/include/uapi/mtd/ubi-user.h
index 5b04a494d139..aad3b6201fc0 100644
--- a/include/uapi/mtd/ubi-user.h
+++ b/include/uapi/mtd/ubi-user.h
@@ -285,6 +285,20 @@ struct ubi_attach_req {
285 __s8 padding[10]; 285 __s8 padding[10];
286}; 286};
287 287
288/*
289 * UBI volume flags.
290 *
291 * @UBI_VOL_SKIP_CRC_CHECK_FLG: skip the CRC check done on a static volume at
292 * open time. Only valid for static volumes and
293 * should only be used if the volume user has a
294 * way to verify data integrity
295 */
296enum {
297 UBI_VOL_SKIP_CRC_CHECK_FLG = 0x1,
298};
299
300#define UBI_VOL_VALID_FLGS (UBI_VOL_SKIP_CRC_CHECK_FLG)
301
288/** 302/**
289 * struct ubi_mkvol_req - volume description data structure used in 303 * struct ubi_mkvol_req - volume description data structure used in
290 * volume creation requests. 304 * volume creation requests.
@@ -292,7 +306,7 @@ struct ubi_attach_req {
292 * @alignment: volume alignment 306 * @alignment: volume alignment
293 * @bytes: volume size in bytes 307 * @bytes: volume size in bytes
294 * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME) 308 * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
295 * @padding1: reserved for future, not used, has to be zeroed 309 * @flags: volume flags (%UBI_VOL_SKIP_CRC_CHECK_FLG)
296 * @name_len: volume name length 310 * @name_len: volume name length
297 * @padding2: reserved for future, not used, has to be zeroed 311 * @padding2: reserved for future, not used, has to be zeroed
298 * @name: volume name 312 * @name: volume name
@@ -321,7 +335,7 @@ struct ubi_mkvol_req {
321 __s32 alignment; 335 __s32 alignment;
322 __s64 bytes; 336 __s64 bytes;
323 __s8 vol_type; 337 __s8 vol_type;
324 __s8 padding1; 338 __u8 flags;
325 __s16 name_len; 339 __s16 name_len;
326 __s8 padding2[4]; 340 __s8 padding2[4];
327 char name[UBI_MAX_VOLUME_NAME + 1]; 341 char name[UBI_MAX_VOLUME_NAME + 1];