// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) International Business Machines Corp., 2006 * * Author: Artem Bityutskiy (Битюцкий Артём) */ /* * This file contains implementation of volume creation, deletion, updating and * resizing. */ #include <linux/err.h> #include <linux/math64.h> #include <linux/slab.h> #include <linux/export.h> #include "ubi.h" static int self_check_volumes(struct ubi_device *ubi); static ssize_t vol_attribute_show(struct device *dev, struct device_attribute *attr, char *buf); /* Device attributes corresponding to files in '/<sysfs>/class/ubi/ubiX_Y' */ static struct device_attribute attr_vol_reserved_ebs = …; static struct device_attribute attr_vol_type = …; static struct device_attribute attr_vol_name = …; static struct device_attribute attr_vol_corrupted = …; static struct device_attribute attr_vol_alignment = …; static struct device_attribute attr_vol_usable_eb_size = …; static struct device_attribute attr_vol_data_bytes = …; static struct device_attribute attr_vol_upd_marker = …; /* * "Show" method for files in '/<sysfs>/class/ubi/ubiX_Y/'. * * Consider a situation: * A. process 1 opens a sysfs file related to volume Y, say * /<sysfs>/class/ubi/ubiX_Y/reserved_ebs; * B. process 2 removes volume Y; * C. process 1 starts reading the /<sysfs>/class/ubi/ubiX_Y/reserved_ebs file; * * In this situation, this function will return %-ENODEV because it will find * out that the volume was removed from the @ubi->volumes array. */ static ssize_t vol_attribute_show(struct device *dev, struct device_attribute *attr, char *buf) { … } static struct attribute *volume_dev_attrs[] = …; ATTRIBUTE_GROUPS(…); /* Release method for volume devices */ static void vol_release(struct device *dev) { … } static struct fwnode_handle *find_volume_fwnode(struct ubi_volume *vol) { … } /** * ubi_create_volume - create volume. * @ubi: UBI device description object * @req: volume creation request * * This function creates volume described by @req. If @req->vol_id id * %UBI_VOL_NUM_AUTO, this function automatically assign ID to the new volume * and saves it in @req->vol_id. Returns zero in case of success and a negative * error code in case of failure. Note, the caller has to have the * @ubi->device_mutex locked. */ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) { … } /** * ubi_remove_volume - remove volume. * @desc: volume descriptor * @no_vtbl: do not change volume table if not zero * * This function removes volume described by @desc. The volume has to be opened * in "exclusive" mode. Returns zero in case of success and a negative error * code in case of failure. The caller has to have the @ubi->device_mutex * locked. */ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl) { … } /** * ubi_resize_volume - re-size volume. * @desc: volume descriptor * @reserved_pebs: new size in physical eraseblocks * * This function re-sizes the volume and returns zero in case of success, and a * negative error code in case of failure. The caller has to have the * @ubi->device_mutex locked. */ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs) { … } /** * ubi_rename_volumes - re-name UBI volumes. * @ubi: UBI device description object * @rename_list: list of &struct ubi_rename_entry objects * * This function re-names or removes volumes specified in the re-name list. * Returns zero in case of success and a negative error code in case of * failure. */ int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list) { … } /** * ubi_add_volume - add volume. * @ubi: UBI device description object * @vol: volume description object * * This function adds an existing volume and initializes all its data * structures. Returns zero in case of success and a negative error code in * case of failure. */ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol) { … } /** * ubi_free_volume - free volume. * @ubi: UBI device description object * @vol: volume description object * * This function frees all resources for volume @vol but does not remove it. * Used only when the UBI device is detached. */ void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol) { … } /** * self_check_volume - check volume information. * @ubi: UBI device description object * @vol_id: volume ID * * Returns zero if volume is all right and a negative error code if not. */ static int self_check_volume(struct ubi_device *ubi, int vol_id) { … } /** * self_check_volumes - check information about all volumes. * @ubi: UBI device description object * * Returns zero if volumes are all right and a negative error code if not. */ static int self_check_volumes(struct ubi_device *ubi) { … }