[hardlink] do not allow to hardlink files across filesystems by default (#786719) (use -f option to override)
Jindrich Novy
jnovy at fedoraproject.org
Sun Apr 15 09:20:00 UTC 2012
commit ad11a278e64c20effe412119d93c0362169a76ce
Author: Jindrich Novy <jnovy at redhat.com>
Date: Sun Apr 15 11:22:10 2012 +0200
do not allow to hardlink files across filesystems by default (#786719)
(use -f option to override)
hardlink.c | 20 ++++++++++++++++----
hardlink.spec | 6 +++++-
2 files changed, 21 insertions(+), 5 deletions(-)
---
diff --git a/hardlink.c b/hardlink.c
index 51a71cf..a7c7249 100644
--- a/hardlink.c
+++ b/hardlink.c
@@ -18,7 +18,7 @@
Boston, MA 02111-1307, USA. */
/* Changes by Rémy Card to use constants and add option -n. */
-/* Changes by Jindrich Novy to add option -h, replace mmap(2), fix overflows */
+/* Changes by Jindrich Novy to add option -h, -f, replace mmap(2), fix overflows */
#define _GNU_SOURCE
#include <sys/types.h>
@@ -56,6 +56,7 @@ h *hps[NHASH];
int no_link = 0;
int verbose = 0;
int content_only = 0;
+int force = 0;
typedef struct _f {
struct _f *next;
@@ -97,11 +98,12 @@ void doexit(int i)
void usage(char *prog)
{
- fprintf (stderr, "Usage: %s [-cnvh] directories...\n", prog);
+ fprintf (stderr, "Usage: %s [-cnvhf] directories...\n", prog);
fprintf (stderr, " -c When finding candidates for linking, compare only file contents.\n");
fprintf (stderr, " -n Don't actually link anything, just report what would be done.\n");
fprintf (stderr, " -v Print summary after hardlinking.\n");
fprintf (stderr, " -vv Print every hardlinked file and bytes saved + summary.\n");
+ fprintf (stderr, " -f Force hardlinking across filesystems.\n");
fprintf (stderr, " -h Show help.\n");
exit(255);
}
@@ -139,7 +141,7 @@ void growstr(dynstr *str, size_t newlen)
doexit(4);
}
}
-
+dev_t dev = 0;
void rf (const char *name)
{
struct stat st, st2, st3;
@@ -147,6 +149,13 @@ void rf (const char *name)
nobjects++;
if (lstat (name, &st))
return;
+ if (st.st_dev != dev && !force) {
+ if (dev) {
+ fprintf(stderr, "%s is on different filesystem than the rest.\nUse -f option to override.\n", name);
+ doexit(6);
+ }
+ dev = st.st_dev;
+ }
if (S_ISDIR (st.st_mode)) {
d * dp = malloc(add3(sizeof(d), namelen, 1));
if (!dp) {
@@ -318,7 +327,7 @@ int main(int argc, char **argv)
int ch;
int i;
dynstr nam1 = {NULL, 0};
- while ((ch = getopt (argc, argv, "cnvh")) != -1) {
+ while ((ch = getopt (argc, argv, "cnvhf")) != -1) {
switch (ch) {
case 'n':
no_link++;
@@ -329,6 +338,9 @@ int main(int argc, char **argv)
case 'c':
content_only++;
break;
+ case 'f':
+ force=1;
+ break;
case 'h':
default:
usage(argv[0]);
diff --git a/hardlink.spec b/hardlink.spec
index 84ae384..61fa585 100644
--- a/hardlink.spec
+++ b/hardlink.spec
@@ -1,7 +1,7 @@
Summary: Create a tree of hardlinks
Name: hardlink
Version: 1.0
-Release: 13%{?dist}
+Release: 14%{?dist}
Epoch: 1
Group: System Environment/Base
URL: http://pkgs.fedoraproject.org/gitweb/?p=hardlink.git
@@ -37,6 +37,10 @@ rm -rf $RPM_BUILD_ROOT
%{_mandir}/man1/hardlink.1*
%changelog
+* Sun Apr 15 2012 Jindrich Novy <jnovy at redhat.com> - 1:1.0-14
+- do not allow to hardlink files across filesystems by default (#786719)
+ (use -f option to override)
+
* Fri Jan 13 2012 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 1:1.0-13
- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild
More information about the scm-commits
mailing list