.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2014 Ezequiel Garcia |
---|
3 | 4 | * Copyright (c) 2011 Free Electrons |
---|
.. | .. |
---|
6 | 7 | * Copyright (c) International Business Machines Corp., 2006 |
---|
7 | 8 | * Copyright (c) Nokia Corporation, 2007 |
---|
8 | 9 | * Authors: Artem Bityutskiy, Frank Haverkamp |
---|
9 | | - * |
---|
10 | | - * This program is free software; you can redistribute it and/or modify |
---|
11 | | - * it under the terms of the GNU General Public License as published by |
---|
12 | | - * the Free Software Foundation, version 2. |
---|
13 | | - * |
---|
14 | | - * This program is distributed in the hope that it will be useful, |
---|
15 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
---|
17 | | - * the GNU General Public License for more details. |
---|
18 | 10 | */ |
---|
19 | 11 | |
---|
20 | 12 | /* |
---|
.. | .. |
---|
353 | 345 | .init_request = ubiblock_init_request, |
---|
354 | 346 | }; |
---|
355 | 347 | |
---|
| 348 | +static int calc_disk_capacity(struct ubi_volume_info *vi, u64 *disk_capacity) |
---|
| 349 | +{ |
---|
| 350 | + u64 size = vi->used_bytes >> 9; |
---|
| 351 | + |
---|
| 352 | + if (vi->used_bytes % 512) { |
---|
| 353 | + pr_warn("UBI: block: volume size is not a multiple of 512, " |
---|
| 354 | + "last %llu bytes are ignored!\n", |
---|
| 355 | + vi->used_bytes - (size << 9)); |
---|
| 356 | + } |
---|
| 357 | + |
---|
| 358 | + if ((sector_t)size != size) |
---|
| 359 | + return -EFBIG; |
---|
| 360 | + |
---|
| 361 | + *disk_capacity = size; |
---|
| 362 | + |
---|
| 363 | + return 0; |
---|
| 364 | +} |
---|
| 365 | + |
---|
356 | 366 | int ubiblock_create(struct ubi_volume_info *vi) |
---|
357 | 367 | { |
---|
358 | 368 | struct ubiblock *dev; |
---|
359 | 369 | struct gendisk *gd; |
---|
360 | | - u64 disk_capacity = vi->used_bytes >> 9; |
---|
| 370 | + u64 disk_capacity; |
---|
361 | 371 | int ret; |
---|
362 | 372 | |
---|
363 | | - if ((sector_t)disk_capacity != disk_capacity) |
---|
364 | | - return -EFBIG; |
---|
| 373 | + ret = calc_disk_capacity(vi, &disk_capacity); |
---|
| 374 | + if (ret) { |
---|
| 375 | + return ret; |
---|
| 376 | + } |
---|
| 377 | + |
---|
365 | 378 | /* Check that the volume isn't already handled */ |
---|
366 | 379 | mutex_lock(&devices_mutex); |
---|
367 | 380 | if (find_dev_nolock(vi->ubi_num, vi->vol_id)) { |
---|
.. | .. |
---|
515 | 528 | static int ubiblock_resize(struct ubi_volume_info *vi) |
---|
516 | 529 | { |
---|
517 | 530 | struct ubiblock *dev; |
---|
518 | | - u64 disk_capacity = vi->used_bytes >> 9; |
---|
| 531 | + u64 disk_capacity; |
---|
| 532 | + int ret; |
---|
519 | 533 | |
---|
520 | 534 | /* |
---|
521 | 535 | * Need to lock the device list until we stop using the device, |
---|
.. | .. |
---|
528 | 542 | mutex_unlock(&devices_mutex); |
---|
529 | 543 | return -ENODEV; |
---|
530 | 544 | } |
---|
531 | | - if ((sector_t)disk_capacity != disk_capacity) { |
---|
| 545 | + |
---|
| 546 | + ret = calc_disk_capacity(vi, &disk_capacity); |
---|
| 547 | + if (ret) { |
---|
532 | 548 | mutex_unlock(&devices_mutex); |
---|
533 | | - dev_warn(disk_to_dev(dev->gd), "the volume is too big (%d LEBs), cannot resize", |
---|
534 | | - vi->size); |
---|
535 | | - return -EFBIG; |
---|
| 549 | + if (ret == -EFBIG) { |
---|
| 550 | + dev_warn(disk_to_dev(dev->gd), |
---|
| 551 | + "the volume is too big (%d LEBs), cannot resize", |
---|
| 552 | + vi->size); |
---|
| 553 | + } |
---|
| 554 | + return ret; |
---|
536 | 555 | } |
---|
537 | 556 | |
---|
538 | 557 | mutex_lock(&dev->dev_mutex); |
---|