From nobody Wed Jan 26 09:27:10 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 1CEF7197B732; Wed, 26 Jan 2022 09:27:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JkJJv05v7z4dcH; Wed, 26 Jan 2022 09:27:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643189231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jMZPOkzrwyYALObE+rOh/tSIxtm0ecKdmLM+176T1s4=; b=oJlA+shIdnlxcM+x70beN+zbxDMYVmxlB0wmg8GigG13IdWFoW7TeOhwwHvS8AbyHUELOa f+pKviAB0fTlmmbhvDBNbNDfSr2Mq7TfaGKyANwlAws7rLHW+dKf7GScITRo3rxRD80aps j9ZUyovRNGyszNKKO35AgEgoP+jhz7nwHeybio8icCNbCKRPpcQwSq8qy8wmqxERrxwaX6 iYSikJEbyrSBu9mS3f0veFYy3kmH6sUR6MkU5teBPW0SKRM3qGUVky9+gfAQHyifPug1CK ZcCCJuz307LvCA2Ex2ODepgC8sZX4u5qOvi1Yuqnso+Iv96GE/XnXMvh2u3AZg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D688F1ABEC; Wed, 26 Jan 2022 09:27:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20Q9RAri008370; Wed, 26 Jan 2022 09:27:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20Q9RA0E008369; Wed, 26 Jan 2022 09:27:10 GMT (envelope-from git) Date: Wed, 26 Jan 2022 09:27:10 GMT Message-Id: <202201260927.20Q9RA0E008369@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andriy Gapon Subject: git: 1abf1e8c6b13 - main - cam_get_device: resolve path links before parsing device name List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: avg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1abf1e8c6b13f50eed08fef6fb1ade280894f1e4 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643189231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jMZPOkzrwyYALObE+rOh/tSIxtm0ecKdmLM+176T1s4=; b=TMFYv173VN86F6c3Uc2WBusece+TEnOa7DE9+EnBGyeKvdDCtrYIWCerfaW5L5u9U7oIlY UEYPE18J2kDMP9D6EMXeS0ah5r+8Eem4HrokZJnYywmmiXxM8RuxN5FWWi4pkYMqIN1/lP KoH/qZ/mNkNXwvH5zBXwddHIFwld//dXYkUBhh1PNNj+LNnE6CL/AevNpBHsoSvD81W7CP Zfh27i1U2xhuEp5FsKbbgf6tAOq9aHHz2KXIU2+Njzy6ByYS3gHNSBb1RxHrI6/KpNjsyl 2A+VpereY/BLmRZknV7PrsFKBjBQnyJIj8o5sxS6IRQ/uUKSmJ3OVzVegGtYNQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643189231; a=rsa-sha256; cv=none; b=T6gATB4P+k+Erkkzjht/FtosB5Hzh0LS6ibZpfE8lr36lebmJ8QrXUCO8slXLpOGGt9IoK d46+ALZeYCISGFpAnJlK5wAjAqmeo1fSy25ozHcRxGkih9WL0y/wPVXxl0xaCYgbc/ZuY1 H09G8FeXyne3xlYkMpeiSz1UawYOKny2WDModHH3DJs9I9aa7KmnMLKQ0H8b8EPmdlU3Ti RPAhcdtLZ3BWCrh81DhV4LJqwXwWVlQcM5tsQaKl8cXu4VzuJwE9GElBZT+l5Miq3APPyi 98sQ1XXA90j1BbL76u/nYukQxuTJ7CpuXom7PmvBT2A/ZfsfriCNLL/T2YA5GQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=1abf1e8c6b13f50eed08fef6fb1ade280894f1e4 commit 1abf1e8c6b13f50eed08fef6fb1ade280894f1e4 Author: Andriy Gapon AuthorDate: 2021-11-27 18:49:08 +0000 Commit: Andriy Gapon CommitDate: 2022-01-26 09:25:31 +0000 cam_get_device: resolve path links before parsing device name The CAM subsystem uses bus:taget:lun tuple to address peripherals. But for convenience many userland programs such as camcontrol accept devices names such as da0. There is a libcam function, cam_open_device, to support that. It first calls cam_get_device() to parse the device name as a driver name and a unit (and handle some special device name prefixes) and then uses cam_lookup_pass() to find a matching pass device. This change extends cam_get_device() to apply realpath(3) to the device name before parsing it. This will allow to use tools such as camcontrol and smartctl with symbolic links that could be friendlier (more distinguished) names for devices. MFC after: 3 weeks Relnotes: maybe --- lib/libcam/camlib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/libcam/camlib.c b/lib/libcam/camlib.c index 438b0e502fe0..6ebdb30ab82b 100644 --- a/lib/libcam/camlib.c +++ b/lib/libcam/camlib.c @@ -128,10 +128,13 @@ cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit) } /* - * We can be rather destructive to the path string. Make a copy of - * it so we don't hose the user's string. + * Resolve the given path to a real device path in case we are given + * an alias or other symbolic link. If the path cannot be resolved + * then try to parse it as is. */ - newpath = (char *)strdup(path); + newpath = realpath(path, NULL); + if (newpath == NULL) + newpath = strdup(path); if (newpath == NULL) return (-1);