Skip to content

Commit c355aa4

Browse files
QSchulzrichardweinberger
authored andcommitted
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 <[email protected]> Signed-off-by: Quentin Schulz <[email protected]> Reviewed-by: Boris Brezillon <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent 6265251 commit c355aa4

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

drivers/mtd/ubi/cdev.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf,
367367
return count;
368368
}
369369

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+
*/
370374
err = ubi_check_volume(ubi, vol->vol_id);
371375
if (err < 0)
372376
return err;
@@ -622,6 +626,13 @@ static int verify_mkvol_req(const struct ubi_device *ubi,
622626
req->vol_type != UBI_STATIC_VOLUME)
623627
goto bad;
624628

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+
625636
if (req->alignment > ubi->leb_size)
626637
goto bad;
627638

drivers/mtd/ubi/vmt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
174174
vol->dev.class = &ubi_class;
175175
vol->dev.groups = volume_dev_groups;
176176

177+
if (req->flags & UBI_VOL_SKIP_CRC_CHECK_FLG)
178+
vol->skip_check = 1;
179+
177180
spin_lock(&ubi->volumes_lock);
178181
if (vol_id == UBI_VOL_NUM_AUTO) {
179182
/* Find unused volume ID */

include/uapi/mtd/ubi-user.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,28 @@ struct ubi_attach_req {
285285
__s8 padding[10];
286286
};
287287

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+
*/
296+
enum {
297+
UBI_VOL_SKIP_CRC_CHECK_FLG = 0x1,
298+
};
299+
300+
#define UBI_VOL_VALID_FLGS (UBI_VOL_SKIP_CRC_CHECK_FLG)
301+
288302
/**
289303
* struct ubi_mkvol_req - volume description data structure used in
290304
* volume creation requests.
291305
* @vol_id: volume number
292306
* @alignment: volume alignment
293307
* @bytes: volume size in bytes
294308
* @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)
296310
* @name_len: volume name length
297311
* @padding2: reserved for future, not used, has to be zeroed
298312
* @name: volume name
@@ -321,7 +335,7 @@ struct ubi_mkvol_req {
321335
__s32 alignment;
322336
__s64 bytes;
323337
__s8 vol_type;
324-
__s8 padding1;
338+
__u8 flags;
325339
__s16 name_len;
326340
__s8 padding2[4];
327341
char name[UBI_MAX_VOLUME_NAME + 1];

0 commit comments

Comments
 (0)