From: Antoni Date: Fri, 24 Jan 2025 10:58:48 +0000 (+0100) Subject: Drop blkid-print X-Git-Tag: accepted/tizen/unified/20250221.111441~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6ccb9f56f1368d6f6adcbe3491e3a9a62ec865fb;p=platform%2Fcore%2Fsystem%2Fupgrade.git Drop blkid-print All binaries provided in a delta have to be statically linked. Linking statically with libblkid turned out to be very difficult. blkid-print functionality is replaced by calling blkid. Change-Id: I6793b30f73b9b7323ce66e1a2eaba03a461c3717 --- diff --git a/CMakeLists.target-build b/CMakeLists.target-build index 10be844..20a8384 100644 --- a/CMakeLists.target-build +++ b/CMakeLists.target-build @@ -21,7 +21,6 @@ ADD_SUBDIRECTORY(src/dmverity) ADD_SUBDIRECTORY(src/img-verifier) ADD_SUBDIRECTORY(src/upgrade-apply) ADD_SUBDIRECTORY(src/upgrade-apply-deltafs) -ADD_SUBDIRECTORY(src/blkid-print) ADD_SUBDIRECTORY(data) ADD_SUBDIRECTORY(scripts/rw-upgrade) ADD_SUBDIRECTORY(src/dynamic-partitions) diff --git a/data/40-upgrade.list.in b/data/40-upgrade.list.in index 64b111d..98484fd 100644 --- a/data/40-upgrade.list.in +++ b/data/40-upgrade.list.in @@ -7,7 +7,6 @@ ${CMAKE_INSTALL_LIBDIR}/libcrypto.so.1.1 /bin/findmnt /bin/dd /bin/grep -/bin/blkid-print /usr/sbin/parse-dynparts /bin/resize-dynparts /bin/copy-blockdev diff --git a/packaging/upgrade.spec b/packaging/upgrade.spec index d596887..15b3b5a 100644 --- a/packaging/upgrade.spec +++ b/packaging/upgrade.spec @@ -186,7 +186,6 @@ fi %{_bindir}/upgrade-apply %{_bindir}/verity_handler %{_bindir}/upgrade-apply-deltafs -%{_bindir}/blkid-print # Image verifier %{_sbindir}/img-verifier %attr(755,root,root) %{img_verifier_root_ca_dir} diff --git a/scripts/upgrade-support/upgrade-common.inc b/scripts/upgrade-support/upgrade-common.inc index f9867eb..bf2e28e 100644 --- a/scripts/upgrade-support/upgrade-common.inc +++ b/scripts/upgrade-support/upgrade-common.inc @@ -20,10 +20,6 @@ UPGRADE_LOG_FILE="$UPGRADE_LOG_DIR/upgrade.log" UPGRADE_SUPPORT_SCRIPT_NAMES=("upgrade-prepare-partitions.sh" "upgrade-trigger.sh" \ "upgrade-partial.sh" "upgrade-fota.sh") -if [ -z "$BLKID_PRINT" ]; then - BLKID_PRINT="/usr/bin/blkid-print" -fi - if [ -z "$RESIZE_DYNPARTS" ]; then RESIZE_DYNPARTS="/bin/resize-dynparts" fi @@ -216,8 +212,20 @@ map_from_super() { fi } +get_partition_path() { + local device=$1 + local part_name=$2 + local suffix=$3 + + if [ -z "${device}" ] || [ -z "${part_name}" ] || [ -z "${suffix}" ]; then + echo "" + fi + + /usr/sbin/blkid -t PARTLABEL="${part_name}_${suffix}" -o device -l "${device}" +} + check_if_super() { - if SUPERFS="$( ("$BLKID_PRINT" "$EMMC_DEVICE" super a) 2>/dev/null)"; then + if SUPERFS="$(get_partition_path "$EMMC_DEVICE" super a)"; then local MAPPED_DEVICES="" MAPPED_DEVICES=$(dmsetup ls) @@ -349,7 +357,7 @@ background_copy() { NEXT_PARTITION="/dev/mapper/${partition_name}_${NEXT_AB}" NEXT_PARTITION_SIZE="$(blockdev --getsize64 $NEXT_PARTITION)" else - if ! CURRENT_PARTITION="$("$BLKID_PRINT" "$EMMC_DEVICE" "$partition_name" "$CURRENT_AB")"; then + if ! CURRENT_PARTITION="$(get_partition_path "$EMMC_DEVICE" "$partition_name" "$CURRENT_AB")"; then log "[Error] Unable to find: $partition_name current partition on $EMMC_DEVICE device on $CURRENT_AB slot" check_optional_partition "$partition_name" 1 continue @@ -357,7 +365,7 @@ background_copy() { CURRENT_PARTITION_SIZE="$(calculate_size $CURRENT_PARTITION)" - if ! NEXT_PARTITION="$("$BLKID_PRINT" "$EMMC_DEVICE" "$partition_name" "$NEXT_AB")"; then + if ! NEXT_PARTITION="$(get_partition_path "$EMMC_DEVICE" "$partition_name" "$NEXT_AB")"; then log "[Error] Unable to find: $partition_name next partition on $EMMC_DEVICE device on $NEXT_AB slot" check_optional_partition "$partition_name" 1 continue @@ -488,8 +496,8 @@ upgrade_images() { NEXT_PARTITION="/dev/mapper/${PART_NAME}_${NEXT_AB}" CURR_PARTITION="/dev/mapper/${PART_NAME}_${CURRENT_AB}" else - NEXT_PARTITION="$("$BLKID_PRINT" "$EMMC_DEVICE" "$PART_NAME" "$NEXT_AB")" - CURR_PARTITION="$("$BLKID_PRINT" "$EMMC_DEVICE" "$PART_NAME" "$CURRENT_AB")" + NEXT_PARTITION="$(get_partition_path "$EMMC_DEVICE" "$PART_NAME" "$NEXT_AB")" + CURR_PARTITION="$(get_partition_path "$EMMC_DEVICE" "$PART_NAME" "$CURRENT_AB")" fi log "[Info] Flashing $DELTA_NAME... to $NEXT_PARTITION, Delta type: ${TYPE_S[0]}" @@ -599,7 +607,7 @@ mount_partition() { local DST="$2" local MOUNT_OPTIONS="$3" local SRC - if ! SRC="$("$BLKID_PRINT" "$EMMC_DEVICE" "$GPT_LABEL" "$NEXT_AB")"; then + if ! SRC="$(get_partition_path "$EMMC_DEVICE" "$GPT_LABEL" "$NEXT_AB")"; then log "[Error] Unable to find $GPT_LABEL partition on $EMMC_DEVICE device for $NEXT_AB slot" return 1 fi diff --git a/src/blkid-print/CMakeLists.txt b/src/blkid-print/CMakeLists.txt deleted file mode 100644 index 7916889..0000000 --- a/src/blkid-print/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -INCLUDE(FindPkgConfig) - -pkg_check_modules(blkid_pkgs REQUIRED blkid) -SET(BLKIDSRCS blkid-print.c) -SET(BLKIDEXENAME "blkid-print") - -FOREACH(flag ${pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -ADD_EXECUTABLE(${BLKIDEXENAME} ${BLKIDSRCS}) -TARGET_LINK_LIBRARIES(${BLKIDEXENAME} ${blkid_pkgs_LDFLAGS}) -INSTALL(TARGETS ${BLKIDEXENAME} DESTINATION ${BINDIR}) diff --git a/src/blkid-print/blkid-api.c b/src/blkid-print/blkid-api.c deleted file mode 100644 index 9c2ddae..0000000 --- a/src/blkid-print/blkid-api.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * tota-ua - * - * Copyright (c) 2021 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "blkid-api.h" -#include -#include -#include - -blkid_partlist get_part_list(char *device_name, blkid_probe *pr) { - assert(pr); - - *pr = blkid_new_probe_from_filename(device_name); - if (*pr == NULL) - return NULL; - blkid_partlist ls = blkid_probe_get_partitions(*pr); - return ls; -} - -int get_part_number_by_name(blkid_partlist ls, const char *part_name, const char *new_slot) { - int nparts = blkid_partlist_numof_partitions(ls); - char part_name_with_slot[MAX_PARTNAME_LEN]; - int found_part_n = -1; - - if (snprintf(part_name_with_slot, MAX_PARTNAME_LEN, "%s_%s", part_name, new_slot) < 0) { - return -1; - } - - for (int it = 0; it < nparts; ++it) { - blkid_partition part = blkid_partlist_get_partition(ls, it); - const char *p; - - p = blkid_partition_get_name(part); - if (!p) - continue; - - if (found_part_n < 0 && strncmp(p, part_name, strlen(part_name)+1) == 0) - found_part_n = it + 1; - else if (strncmp(p, part_name_with_slot, strlen(part_name_with_slot)+1) == 0) - found_part_n = it + 1; - } - if (found_part_n >= 0) - return found_part_n; - - // nothing found - return -1; -} - diff --git a/src/blkid-print/blkid-api.h b/src/blkid-print/blkid-api.h deleted file mode 100644 index 0baa2f2..0000000 --- a/src/blkid-print/blkid-api.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * tota-ua - * - * Copyright (c) 2021 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once -#include - -#ifndef MAX_PARTNAME_LEN -#define MAX_PARTNAME_LEN 10000 -#endif -blkid_partlist get_part_list(char *device_name, blkid_probe *pr); -int get_part_number_by_name(blkid_partlist ls, const char *part_name, const char *new_slot); diff --git a/src/blkid-print/blkid-print.c b/src/blkid-print/blkid-print.c deleted file mode 100644 index 5f0e394..0000000 --- a/src/blkid-print/blkid-print.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * tota-ua - * - * Copyright (c) 2021 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include "blkid-api.h" - -#define ARRAY_LEN(arr) sizeof(arr)/sizeof(arr[0]) - -void usage(const char* msg) { - if (msg) { - fprintf(stderr, "%s\n", msg); - } - fprintf(stderr, "USAGE: blkid-print device_name partition_label suffix [verbose]\n" - "device_name: block device e.g. /dev/mmcblk0\n" - "partition_label: partiton label to search for e.g. rootfs,ramdisk etc.\n" - "suffix: a|b partiton slot\n" - "verbose: optional, prints part_nr: part_nr (part_label): part_path instead of part_path only\n"); -} - -blkid_partition partition_for(char *device_name, char *part_name, char *new_slot) { - char part_name_with_slot[MAX_PARTNAME_LEN]; - int found_part_n = -1; - if (!device_name || !part_name || !new_slot){ - fprintf(stderr, "partition_for: one or more argument is NULL\n"); - return NULL; - } - if (snprintf(part_name_with_slot, MAX_PARTNAME_LEN, "%s_%s", part_name, new_slot) < 0) { - return NULL; - } - blkid_probe pr = blkid_new_probe_from_filename(device_name); - if (pr == NULL) { - fprintf(stderr, "ERROR: blkid error for %s\n", device_name); - usage(NULL); - return NULL; - } - blkid_partlist ls = blkid_probe_get_partitions(pr); - if (!ls) { - fprintf(stderr, "ERROR: unable to probe partitions.\n"); - blkid_free_probe(pr); - return NULL; - } - int nparts = blkid_partlist_numof_partitions(ls); - if (nparts == -1) { - fprintf(stderr, "ERROR: unable to get partition count\n"); - blkid_free_probe(pr); - return NULL; - } - - - for (int i = 0; i < nparts; i++) { - blkid_partition part = blkid_partlist_get_partition(ls, i); - const char *p; - - p = blkid_partition_get_name(part); - if (!p) - continue; - - if (found_part_n < 0 && strncmp(p, part_name, strlen(part_name)+1) == 0) - found_part_n = i; - else if (strncmp(p, part_name_with_slot, strlen(part_name_with_slot)+1) == 0) - found_part_n = i; - } - - blkid_free_probe(pr); - if (found_part_n >= 0) { - blkid_partition par = blkid_partlist_get_partition(ls, found_part_n); - return par; - } - return NULL; -} - -const char *get_part_label(blkid_partlist ls, int part_nr) { - blkid_partition part = blkid_partlist_get_partition(ls, part_nr); - return blkid_partition_get_name(part); -} - -int main(int argc, char *argv[]) { - char device_name_path[PATH_MAX]; - if (argc < 4 || argc > 5 || (argc == 5 && strcmp(argv[4], "verbose")) ) { - usage("Please specify correct argument number\n"); - return 1; - } - - int verbose = (argc == 5) ? 1 : 0; - - char *device_name = realpath(argv[1], device_name_path); - if (!device_name) { - fprintf(stderr, "ERROR: Unable to determine realpath for: %s\n", argv[1]); - usage(NULL); - return 1; - } - char *partition_label = argv[2]; - char *suffix = argv[3]; - blkid_partition part = partition_for(device_name, partition_label, suffix); - if (part == NULL) { - fprintf(stderr, "ERROR: Partition '%s' not found.\n", partition_label); - return 2; - } - int part_nr = blkid_partition_get_partno(part); - if (part_nr < 0) { - fprintf(stderr, "ERROR: Partition '%s' not found", partition_label); - return 3; - } - const char *part_label = blkid_partition_get_name(part); - char part_path[PATH_MAX]; - // /dev/sda1 /dev/vda1 vs /dev/mmcblk0p1 /dev/nvme0n1p1 - // no_separator vs "p" separator - if (strncmp("/dev/sd", device_name, ARRAY_LEN("/dev/sd") - 1) == 0 || - strncmp("/dev/vd", device_name, ARRAY_LEN("/dev/vd") - 1) == 0) - snprintf(part_path, PATH_MAX, "%s%d", device_name, part_nr); - else - snprintf(part_path, PATH_MAX, "%sp%d", device_name, part_nr); - - if (verbose) - printf("part_nr: %d (%s): %s\n", part_nr, part_label, part_path); - else - printf("%s\n", part_path); - return 0; -}