summaryrefslogtreecommitdiff
path: root/src/ext4magic.c
diff options
context:
space:
mode:
authorrobi <robi>2010-06-08 21:39:12 +0000
committerrobi <robi>2010-06-08 21:39:12 +0000
commit972f26a10e5f0bacf12b2df2e9a00896b007e600 (patch)
tree08685c59e66d1bd8eef16c1e7968059ccfde5d3f /src/ext4magic.c
parent7e6b5e4198404e6418e05029d91e9d780bfd7d55 (diff)
prevent write to same filesystem
Diffstat (limited to 'src/ext4magic.c')
-rw-r--r--src/ext4magic.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/ext4magic.c b/src/ext4magic.c
index b356e13..a9fb5bf 100644
--- a/src/ext4magic.c
+++ b/src/ext4magic.c
@@ -573,6 +573,9 @@ if (mode & INPUT_TIME){
//check for the recoverdir
if ((mode & RECOVER_INODE) && (recovermodus & (REC_DIR_NEEDED)) || mode & RECOVER_LIST) {
+ struct stat st_buf;
+ dev_t file_rdev=0;
+
if(!des_dir)
des_dir = defaultdir;
@@ -589,7 +592,24 @@ if ((mode & RECOVER_INODE) && (recovermodus & (REC_DIR_NEEDED)) || mode & RECOV
}
if (!retval){
if (S_ISDIR(filestat.st_mode) && (filestat.st_mode & S_IRWXU) == S_IRWXU){
- printf("\"%s\" accept for recoverdir \n",des_dir);
+ if (stat(argv[optind], &st_buf) == 0) {
+ if (S_ISBLK(st_buf.st_mode)) {
+#ifndef __GNU__ /* The GNU hurd is broken with respect to stat devices */
+ file_rdev = st_buf.st_rdev;
+#endif /* __GNU__ */
+ } else {
+ file_rdev = st_buf.st_dev;
+ }
+ }
+ if (filestat.st_dev == file_rdev){
+ fprintf(stderr,"ERROR: can not use \"%s\" for recover directory. It's the same filesystem : \"%s\"\n", des_dir, argv[optind]);
+ exitval = EXIT_FAILURE ;
+#ifdef DEBUG
+ printf("recover_dir_dev : %d filesystem_dev : %d\n",filestat.st_dev, file_rdev);
+#endif
+ goto errout;
+ }
+ printf("\"%s\" accept for recoverdir\n",des_dir);
}
else {
fprintf(stderr,"ERROR: can not use \"%s\" for recover directory\n", des_dir);