Loading pkgs/by-name/sd/sdformat/package.nix 0 → 100644 +49 −0 Original line number Diff line number Diff line { lib, stdenv, fetchFromGitHub, util-linuxMinimal, installShellFiles, }: stdenv.mkDerivation (finalAttrs: { pname = "sdformat"; version = "0.2.0"; __structuredAttrs = true; src = fetchFromGitHub { owner = "profi200"; repo = "sdFormatLinux"; rev = "v${finalAttrs.version}"; hash = "sha256-AoAhP1dr+hQSnOpZC0oHt0j3fUVNVhD+3jWm6iMfskk="; }; nativeBuildInputs = [ installShellFiles ]; patches = [ ./remove-hardcoded-lsblk-path.diff ]; strictDeps = true; makeFlags = [ "TARGET=${finalAttrs.pname}" "LSBLK_PATH=${lib.getExe' util-linuxMinimal "lsblk"}" ]; installPhase = '' runHook preInstall installBin ${finalAttrs.pname} runHook postInstall ''; meta = { description = "Format your SD card the way the SD Association intended"; homepage = "https://github.com/profi200/sdFormatLinux"; license = lib.licenses.mit; mainProgram = finalAttrs.pname; maintainers = with lib.maintainers; [ thiagokokada ]; platforms = lib.platforms.linux; }; }) pkgs/by-name/sd/sdformat/remove-hardcoded-lsblk-path.diff 0 → 100644 +39 −0 Original line number Diff line number Diff line diff --git i/Makefile w/Makefile index c45b32b..258189c 100644 --- i/Makefile +++ w/Makefile @@ -5,7 +5,8 @@ TARGET := $(notdir $(CURDIR)) BUILD := build INCLUDES := include SOURCES := source -DEFINES := -D_FORTIFY_SOURCE=2 +LSBLK_PATH ?= /usr/bin/lsblk +DEFINES := -D_FORTIFY_SOURCE=2 -DLSBLK_PATH=\"$(LSBLK_PATH)\" # Compiler settings diff --git i/source/blockdev.cpp w/source/blockdev.cpp index a179604..b4de5ef 100644 --- i/source/blockdev.cpp +++ w/source/blockdev.cpp @@ -7,6 +7,7 @@ #include <errno.h> #include <fcntl.h> // open()... #include <linux/fs.h> // BLKGETSIZE64... +#include <limits.h> // PATH_MAX #include <sys/ioctl.h> // ioctl()... #include <sys/stat.h> // S_IRUSR, S_IWUSR... #include <unistd.h> // write(), close()... @@ -21,8 +22,10 @@ static int checkDevice(const char *const path) { int res = EINVAL; // By default assume the given path is not a suitable device. - char cmd[64] = "/usr/bin/lsblk -dnr -oTYPE,HOTPLUG,PHY-SEC "; - strncpy(&cmd[43], path, sizeof(cmd) - 43); + const char cmdPrefix[] = LSBLK_PATH " -dnr -oTYPE,HOTPLUG,PHY-SEC "; + char cmd[sizeof(cmdPrefix) + PATH_MAX]; + memcpy(cmd, cmdPrefix, sizeof(cmdPrefix) - 1); + strncpy(&cmd[sizeof(cmdPrefix) - 1], path, sizeof(cmd) - sizeof(cmdPrefix)); cmd[sizeof(cmd) - 1] = '\0'; FILE *const p = ::popen(cmd, "r"); if(p == nullptr) Loading
pkgs/by-name/sd/sdformat/package.nix 0 → 100644 +49 −0 Original line number Diff line number Diff line { lib, stdenv, fetchFromGitHub, util-linuxMinimal, installShellFiles, }: stdenv.mkDerivation (finalAttrs: { pname = "sdformat"; version = "0.2.0"; __structuredAttrs = true; src = fetchFromGitHub { owner = "profi200"; repo = "sdFormatLinux"; rev = "v${finalAttrs.version}"; hash = "sha256-AoAhP1dr+hQSnOpZC0oHt0j3fUVNVhD+3jWm6iMfskk="; }; nativeBuildInputs = [ installShellFiles ]; patches = [ ./remove-hardcoded-lsblk-path.diff ]; strictDeps = true; makeFlags = [ "TARGET=${finalAttrs.pname}" "LSBLK_PATH=${lib.getExe' util-linuxMinimal "lsblk"}" ]; installPhase = '' runHook preInstall installBin ${finalAttrs.pname} runHook postInstall ''; meta = { description = "Format your SD card the way the SD Association intended"; homepage = "https://github.com/profi200/sdFormatLinux"; license = lib.licenses.mit; mainProgram = finalAttrs.pname; maintainers = with lib.maintainers; [ thiagokokada ]; platforms = lib.platforms.linux; }; })
pkgs/by-name/sd/sdformat/remove-hardcoded-lsblk-path.diff 0 → 100644 +39 −0 Original line number Diff line number Diff line diff --git i/Makefile w/Makefile index c45b32b..258189c 100644 --- i/Makefile +++ w/Makefile @@ -5,7 +5,8 @@ TARGET := $(notdir $(CURDIR)) BUILD := build INCLUDES := include SOURCES := source -DEFINES := -D_FORTIFY_SOURCE=2 +LSBLK_PATH ?= /usr/bin/lsblk +DEFINES := -D_FORTIFY_SOURCE=2 -DLSBLK_PATH=\"$(LSBLK_PATH)\" # Compiler settings diff --git i/source/blockdev.cpp w/source/blockdev.cpp index a179604..b4de5ef 100644 --- i/source/blockdev.cpp +++ w/source/blockdev.cpp @@ -7,6 +7,7 @@ #include <errno.h> #include <fcntl.h> // open()... #include <linux/fs.h> // BLKGETSIZE64... +#include <limits.h> // PATH_MAX #include <sys/ioctl.h> // ioctl()... #include <sys/stat.h> // S_IRUSR, S_IWUSR... #include <unistd.h> // write(), close()... @@ -21,8 +22,10 @@ static int checkDevice(const char *const path) { int res = EINVAL; // By default assume the given path is not a suitable device. - char cmd[64] = "/usr/bin/lsblk -dnr -oTYPE,HOTPLUG,PHY-SEC "; - strncpy(&cmd[43], path, sizeof(cmd) - 43); + const char cmdPrefix[] = LSBLK_PATH " -dnr -oTYPE,HOTPLUG,PHY-SEC "; + char cmd[sizeof(cmdPrefix) + PATH_MAX]; + memcpy(cmd, cmdPrefix, sizeof(cmdPrefix) - 1); + strncpy(&cmd[sizeof(cmdPrefix) - 1], path, sizeof(cmd) - sizeof(cmdPrefix)); cmd[sizeof(cmd) - 1] = '\0'; FILE *const p = ::popen(cmd, "r"); if(p == nullptr)