Blob Blame History Raw
From 398305a92484dfc3475e90da8fdce7e26fa62a1e Mon Sep 17 00:00:00 2001
From: Justin Vreeland <jvreeland@twitter.com>
Date: Mon, 7 Jun 2021 14:56:26 -0700
Subject: [PATCH 1/1] Rebase hdparm to CentOS Stream 9 version 9.62

---
 .hdparm.metadata                              |  2 +-
 SOURCES/hdparm-9.54-dco_calc.patch            | 12 ---
 .../hdparm-9.54-resourceleak-fixes-2.patch    | 23 ++++++
 SOURCES/hdparm-9.54-resourceleak-fixes.patch  | 81 +++++++++++++++++++
 ...atch => hdparm-9.60-ditch_dead_code.patch} | 11 ++-
 SOURCES/hdparm-9.60-sysfs-fclose.patch        | 13 +++
 SPECS/hdparm.spec                             | 43 ++++++----
 7 files changed, 151 insertions(+), 34 deletions(-)
 delete mode 100644 SOURCES/hdparm-9.54-dco_calc.patch
 create mode 100644 SOURCES/hdparm-9.54-resourceleak-fixes-2.patch
 create mode 100644 SOURCES/hdparm-9.54-resourceleak-fixes.patch
 rename SOURCES/{hdparm-9.43-ditch_dead_code.patch => hdparm-9.60-ditch_dead_code.patch} (80%)
 create mode 100644 SOURCES/hdparm-9.60-sysfs-fclose.patch

diff --git a/.hdparm.metadata b/.hdparm.metadata
index 00c7ee3..f86bd1d 100644
--- a/.hdparm.metadata
+++ b/.hdparm.metadata
@@ -1 +1 @@
-b3425a141f1c0fe9f53b18631437129c2155ee45 SOURCES/hdparm-9.58.tar.gz
+141f1c0fe9f53b18631437129c2155ee45 SOURCES/hdparm-9.62.tar.gz
diff --git a/SOURCES/hdparm-9.54-dco_calc.patch b/SOURCES/hdparm-9.54-dco_calc.patch
deleted file mode 100644
index 3f1c659..0000000
--- a/SOURCES/hdparm-9.54-dco_calc.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-diff --color -u hdparm-9.54.orig/identify.c hdparm-9.54/identify.c
---- hdparm-9.54.orig/identify.c	2016-10-17 11:06:28.000000001 -0700
-+++ hdparm-9.54/identify.c	2021-04-28 06:19:01.005819050 -0700
-@@ -1488,7 +1488,7 @@
- 	else if (dco[2] & (1<<0)) printf(" udma0");
- 	putchar('\n');
- 
--	lba = ((((__u64)dco[5]) << 32) | (dco[4] << 16) | dco[3]) + 1;
-+	lba = ((((__u64)dco[5]) << 32) | ((__u64)dco[4] << 16) |(__u64)dco[3]) + 1U;
- 	printf("\tReal max sectors: %llu\n", lba);
- 
- 	printf("\tATA command/feature sets:");
diff --git a/SOURCES/hdparm-9.54-resourceleak-fixes-2.patch b/SOURCES/hdparm-9.54-resourceleak-fixes-2.patch
new file mode 100644
index 0000000..2fac03a
--- /dev/null
+++ b/SOURCES/hdparm-9.54-resourceleak-fixes-2.patch
@@ -0,0 +1,23 @@
+diff -up hdparm-9.54/hdparm.c.bak hdparm-9.54/hdparm.c
+--- hdparm-9.54/hdparm.c.bak	2020-06-01 17:56:47.257520643 +0200
++++ hdparm-9.54/hdparm.c	2020-06-01 17:57:29.285084217 +0200
+@@ -461,12 +461,15 @@ static void dump_identity (__u16 *idw)
+ {
+ 	int i;
+ 	char pmodes[64] = {0,}, dmodes[128]={0,}, umodes[128]={0,};
+-	char *model = strip(strndup((char *)&idw[27], 40));
+-	char *fwrev = strip(strndup((char *)&idw[23],  8));
+-	char *serno = strip(strndup((char *)&idw[10], 20));
++	char *model = strndup((char *)&idw[27], 40);
++	char *model_s = strip(model);
++	char *fwrev = strndup((char *)&idw[23],  8);
++	char *fwrev_s = strip(fwrev);
++	char *serno = strndup((char *)&idw[10], 20);
++	char *serno_s = strip(serno);
+ 	__u8 tPIO;
+ 
+-	printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s", model, fwrev, serno);
++	printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s", model_s, fwrev_s, serno_s);
+ 	printf("\n Config={");
+ 	for (i = 0; i <= 15; i++) {
+ 		if (idw[0] & (1<<i))
diff --git a/SOURCES/hdparm-9.54-resourceleak-fixes.patch b/SOURCES/hdparm-9.54-resourceleak-fixes.patch
new file mode 100644
index 0000000..1cc6630
--- /dev/null
+++ b/SOURCES/hdparm-9.54-resourceleak-fixes.patch
@@ -0,0 +1,81 @@
+diff -urN hdparm-9.54/fibmap.c hdparm-9.54_patched/fibmap.c
+--- hdparm-9.54/fibmap.c	2016-10-13 01:50:52.000000000 +0200
++++ hdparm-9.54_patched/fibmap.c	2018-10-04 12:17:39.630627349 +0200
+@@ -232,6 +232,7 @@
+ 	if (fstat(fd, &st) == -1) {
+ 		err = errno;
+ 		perror(file_name);
++		close(fd);
+ 		return err;
+ 	}
+ 	if (!S_ISREG(st.st_mode)) {
+diff -urN hdparm-9.54/fwdownload.c hdparm-9.54_patched/fwdownload.c
+--- hdparm-9.54/fwdownload.c	2017-12-06 13:41:40.000000000 +0100
++++ hdparm-9.54_patched/fwdownload.c	2018-10-04 12:19:23.819336125 +0200
+@@ -95,12 +95,19 @@
+ 	int xfer_min = 1, xfer_max = 0xffff, xfer_size;
+ 	ssize_t offset;
+ 
+-	if ((fwfd = open(fwpath, O_RDONLY)) == -1 || fstat(fwfd, &st) == -1) {
++	if ((fwfd = open(fwpath, O_RDONLY)) == -1) {
+ 		err = errno;
+ 		perror(fwpath);
+ 		return err;
+ 	}
+ 
++	if (fstat(fwfd, &st) == -1) {
++		err = errno;
++		perror(fwpath);
++		close(fwfd);
++		return err;
++	}
++
+ 	if (!S_ISREG(st.st_mode)) {
+ 		fprintf(stderr, "%s: not a regular file\n", fwpath);
+ 		err = EINVAL;
+diff -urN hdparm-9.54/hdparm.c hdparm-9.54_patched/hdparm.c
+--- hdparm-9.54/hdparm.c	2018-02-03 19:10:40.000000000 +0100
++++ hdparm-9.54_patched/hdparm.c	2018-10-04 13:25:58.924126976 +0200
+@@ -590,6 +590,9 @@
+ 	printf("\n");
+ 	printf("\n * signifies the current active mode\n");
+ 	printf("\n");
++	free(fwrev);
++	free(model);
++	free(serno);
+ }
+ 
+ static const char *busstate_str (unsigned int value)
+@@ -1174,8 +1177,10 @@
+ 	if (!shortened)
+ 		fdevname = strdup("the full disk");
+ 
+-	if (start_lba == 0ULL)
++	if (start_lba == 0ULL) {
++		free(fdevname);
+ 		return 0;
++	}
+ 	if (start_lba == START_LBA_UNKNOWN || fd_is_raid(fd)) {
+ 		fprintf(stderr, "%s is a RAID device: please specify an absolute LBA of a raw member device instead (raid1 only)\n", devname);
+ 	} else if (msg) {
+@@ -1187,6 +1192,7 @@
+ 		fprintf(stderr, "The absolute LBA of sector %llu from %s should be %llu\n", lba, devname, start_lba + lba);
+ 	}
+ 	fprintf(stderr, "Aborting.\n");
++	free(fdevname);
+ 	exit(EINVAL);
+ }
+ 
+diff -urN hdparm-9.54/sysfs.c hdparm-9.54_patched/sysfs.c
+--- hdparm-9.54/sysfs.c	2018-10-04 12:14:29.900157666 +0200
++++ hdparm-9.54_patched/sysfs.c	2018-10-04 14:13:07.056659514 +0200
+@@ -60,8 +63,8 @@
+ 		}
+ 		if (count < 0)
+ 			err = errno;
+-		fclose(fp);
+ 	}
++	fclose(fp);
+ 	if (err && verbose) perror(path);
+ 	*pathtail = '\0';
+ 	return err;
diff --git a/SOURCES/hdparm-9.43-ditch_dead_code.patch b/SOURCES/hdparm-9.60-ditch_dead_code.patch
similarity index 80%
rename from SOURCES/hdparm-9.43-ditch_dead_code.patch
rename to SOURCES/hdparm-9.60-ditch_dead_code.patch
index 4f4f177..cb67b00 100644
--- a/SOURCES/hdparm-9.43-ditch_dead_code.patch
+++ b/SOURCES/hdparm-9.60-ditch_dead_code.patch
@@ -1,7 +1,6 @@
-Index: hdparm-9.43/sgio.c
-===================================================================
---- hdparm-9.43.orig/sgio.c
-+++ hdparm-9.43/sgio.c
+diff -up hdparm-9.60/sgio.c.bak hdparm-9.60/sgio.c
+--- hdparm-9.60/sgio.c.bak	2019-01-03 23:37:54.000000000 +0100
++++ hdparm-9.60/sgio.c	2021-04-07 16:10:36.971836569 +0200
 @@ -17,6 +17,10 @@
  
  #include <linux/hdreg.h>
@@ -22,7 +21,7 @@ Index: hdparm-9.43/sgio.c
  
  	if (tf->command == ATA_OP_PIDENTIFY)
  		prefer12 = 0;
-@@ -302,14 +306,16 @@ int sg16 (int fd, int rw, int dma, struc
+@@ -306,14 +310,16 @@ int sg16 (int fd, int rw, int dma, struc
  
  	desc = sb + 8;
  	if (io_hdr.driver_status != SG_DRIVER_SENSE) {
@@ -44,4 +43,4 @@ Index: hdparm-9.43/sgio.c
 +#endif
  		}
  	} else if (sb[0] != 0x72 || sb[7] < 14 || desc[0] != 0x09 || desc[1] < 0x0c) {
- 		dump_bytes("SG_IO: bad/missing sense data, sb[]", sb, sizeof(sb));
+ 		if (verbose || tf->command != ATA_OP_IDENTIFY)
diff --git a/SOURCES/hdparm-9.60-sysfs-fclose.patch b/SOURCES/hdparm-9.60-sysfs-fclose.patch
new file mode 100644
index 0000000..0828da8
--- /dev/null
+++ b/SOURCES/hdparm-9.60-sysfs-fclose.patch
@@ -0,0 +1,13 @@
+diff -up hdparm-9.60/sysfs.c.bak hdparm-9.60/sysfs.c
+--- hdparm-9.60/sysfs.c.bak	2021-04-15 15:48:56.806354847 +0200
++++ hdparm-9.60/sysfs.c	2021-04-16 14:44:42.520395436 +0200
+@@ -61,7 +61,8 @@ static int sysfs_write_attr (char *path,
+ 		if (count < 0)
+ 			err = errno;
+ 	}
+-	fclose(fp);
++	if (fp)
++		fclose(fp);
+ 	if (err && verbose) perror(path);
+ 	*pathtail = '\0';
+ 	return err;
diff --git a/SPECS/hdparm.spec b/SPECS/hdparm.spec
index da001e7..d1f34e8 100644
--- a/SPECS/hdparm.spec
+++ b/SPECS/hdparm.spec
@@ -1,18 +1,22 @@
 Summary: A utility for displaying and/or setting hard disk parameters
 Name: hdparm
-Version: 9.58
-Release: 2%{?dist}
+Version: 9.62
+Release: 1%{?dist}
 License: BSD
 URL:    https://sourceforge.net/projects/%{name}/
 Source: https://downloads.sourceforge.net/%{name}/%{name}-%{version}.tar.gz
-Patch0: %{name}-9.43-ditch_dead_code.patch
+Patch0: %{name}-9.60-ditch_dead_code.patch
 Patch1: %{name}-9.43-close_fd.patch
 Patch2: %{name}-9.43-get_geom.patch
-Patch3: %{name}-9.54-dco_calc.patch
+Patch3: %{name}-9.54-resourceleak-fixes.patch
+Patch4: %{name}-9.54-resourceleak-fixes-2.patch
+Patch5: %{name}-9.60-sysfs-fclose.patch
 
 BuildRequires: gcc
 BuildRequires: make
 
+Provides: /sbin/hdparm
+
 %description
 Hdparm is a useful system utility for setting (E)IDE hard drive
 parameters.  For example, hdparm can be used to tweak hard drive
@@ -25,27 +29,36 @@ performance and to spin down hard drives for power conservation.
 CFLAGS="$RPM_OPT_FLAGS" %make_build STRIP=/bin/true LDFLAGS="$RPM_LD_FLAGS"
 
 %install
-mkdir -p $RPM_BUILD_ROOT/sbin
-mkdir -p $RPM_BUILD_ROOT/%{_mandir}/man8
-install -c -m 755 hdparm $RPM_BUILD_ROOT/sbin/hdparm
-install -c -m 644 hdparm.8 $RPM_BUILD_ROOT/%{_mandir}/man8
+mkdir -p $RPM_BUILD_ROOT%{_sbindir}
+mkdir -p $RPM_BUILD_ROOT%{_mandir}/man8
+install -c -m 755 hdparm $RPM_BUILD_ROOT%{_sbindir}/hdparm
+install -c -m 644 hdparm.8 $RPM_BUILD_ROOT%{_mandir}/man8
 
 
 %files
 %doc hdparm.lsm Changelog README.acoustic TODO
 %license LICENSE.TXT
-/sbin/hdparm
+%{_sbindir}/hdparm
 %{_mandir}/man8/hdparm.8*
 
 %changelog
-* Tue May 18 2021 Justin Vreeland <jvreeland@twitter.com> - 9.58-2
-- add dco-calc.path https://bugzilla.redhat.com/show_bug.cgi?id=1959918
+* Mon Jun  7 2021 Justin Vreeland <vreeland.justin@gmail.com> - 9.62-1
+- CentOS 8 Stream Hyperscale SIG release
+
+* Thu May 20 2021 Tomas Bzatek <tbzatek@redhat.com> - 9.62-1
+- New upstream version 9.62 (#1961841)
+
+* Fri Apr 16 2021 Tomas Bzatek <tbzatek@redhat.com> - 9.60-4
+- Fix fclose() on sysfs file write
+
+* Fri Apr 16 2021 Mohan Boddu <mboddu@redhat.com> - 9.60-3
+- Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937
 
-* Tue Mar  2 2021 Justin Vreeland <jvreeland@twitter.com> - 9.58-1
-- Reset release to 1 for hyperscale sig
+* Thu Apr 15 2021 Tomas Bzatek <tbzatek@redhat.com> - 9.60-2
+- Move hdparm binary to /usr/sbin
 
-* Tue Mar  2 2021 Justin Vreeland <jvreeland@twitter.com> - 9.58-5
-- Rebuild for CentOS-8-Stream Hyperscale
+* Fri Apr 09 2021 Tomas Bzatek <tbzatek@redhat.com> - 9.60-1
+- New upstream version 9.60 (#1947860)
 
 * Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 9.58-5
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
-- 
2.32.0