summaryrefslogtreecommitdiff
blob: 4f2f7a024e3ef138a60b72652dcc8de3d8f2f7e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2004/02/12 23:28:01+03:00 vitaly@bitstream.namesys.com 
#   a few bugs were fixed in the mount entry detection code.
# 
# reiserfsprogs/tune/tune.c
#   2004/02/12 23:27:42+03:00 vitaly@bitstream.namesys.com +1 -1
# 
# reiserfsprogs/resize_reiserfs/resize_reiserfs.c
#   2004/02/12 23:27:42+03:00 vitaly@bitstream.namesys.com +2 -2
# 
# reiserfsprogs/reiserfscore/reiserfslib.c
#   2004/02/12 23:27:42+03:00 vitaly@bitstream.namesys.com +1 -1
# 
# reiserfsprogs/lib/misc.c
#   2004/02/12 23:27:42+03:00 vitaly@bitstream.namesys.com +6 -29
# 
# reiserfsprogs/include/misc.h
#   2004/02/12 23:27:42+03:00 vitaly@bitstream.namesys.com +4 -4
# 
# reiserfsprogs/fsck/main.c
#   2004/02/12 23:27:42+03:00 vitaly@bitstream.namesys.com +11 -9
# 
# reiserfsprogs/fsck/fsck.h
#   2004/02/12 23:27:42+03:00 vitaly@bitstream.namesys.com +1 -0
# 
# reiserfsprogs/debugreiserfs/unpack.c
#   2004/02/12 23:27:42+03:00 vitaly@bitstream.namesys.com +1 -1
# 
diff -Nru a/reiserfsprogs/debugreiserfs/unpack.c b/reiserfsprogs/debugreiserfs/unpack.c
--- a/reiserfsprogs/debugreiserfs/unpack.c	Thu Feb 12 23:29:27 2004
+++ b/reiserfsprogs/debugreiserfs/unpack.c	Thu Feb 12 23:29:27 2004
@@ -616,7 +616,7 @@
 	/* only one non-option argument is permitted */
 	print_usage_and_exit();
 
-    if (misc_device_mounted(argv[optind], 0))
+    if (misc_device_mounted(argv[optind]) > 0)
 	reiserfs_panic ("%s seems mounted, umount it first\n", argv[optind]);
   
     fd = open (argv[optind], O_RDWR | O_LARGEFILE);
diff -Nru a/reiserfsprogs/fsck/fsck.h b/reiserfsprogs/fsck/fsck.h
--- a/reiserfsprogs/fsck/fsck.h	Thu Feb 12 23:29:27 2004
+++ b/reiserfsprogs/fsck/fsck.h	Thu Feb 12 23:29:27 2004
@@ -408,6 +408,7 @@
 struct fsck_data {
     unsigned short mode; /* check, rebuild, etc*/
     unsigned long options;
+    unsigned long mounted;
 
     struct rebuild_info rebuild;
     struct check_info check;
diff -Nru a/reiserfsprogs/fsck/main.c b/reiserfsprogs/fsck/main.c
--- a/reiserfsprogs/fsck/main.c	Thu Feb 12 23:29:27 2004
+++ b/reiserfsprogs/fsck/main.c	Thu Feb 12 23:29:27 2004
@@ -746,10 +746,10 @@
 
     mark_filesystem_consistent (fs);
     clear_buffer_do_not_flush (fs->fs_super_bh);
-    
-    if (misc_device_mounted(fs->fs_file_name, MF_RO)) {
-	reiserfs_warning(stderr, "\nThe partition is mounted ro. It is better "
-			 "to umount and mount it again.\n\n");
+
+    if (fsck_data(fs)->mounted == MF_RO) {
+	reiserfs_warning(stderr, "\nThe partition is mounted ro. It "
+			 "is better to umount and mount it again.\n\n");
 	ret = EXIT_REBOOT;
     }
 
@@ -764,18 +764,20 @@
 }
 
 /* check umounted or read-only mounted filesystems only */
-void prepare_fs_for_check(reiserfs_filsys_t * fs) {
+static void prepare_fs_for_check(reiserfs_filsys_t * fs) {
     /* The method could be called from auto_check already. */
     if (fs->fs_flags == O_RDWR) 
 	return;
 
     reiserfs_reopen (fs, O_RDWR);
     
-    if (misc_device_mounted(fs->fs_file_name, 0)) {
-	if (!misc_device_mounted(fs->fs_file_name, MF_RO)) {
+    fsck_data(fs)->mounted = misc_device_mounted(fs->fs_file_name);
+    
+    if (fsck_data(fs)->mounted > 0) {
+	if (fsck_data(fs)->mounted == MF_RW) {
 	    fsck_progress ("Partition %s is mounted with write permissions, "
 		"cannot check it\n", fs->fs_file_name);
-	    reiserfs_close (fs);
+	    reiserfs_close(fs);
 	    exit(EXIT_USER);
 	}
 	
@@ -1093,7 +1095,7 @@
 	stage_report (5, fs);
 
 	if (fsck_mode(fs) != FSCK_CHECK) {
-		if (misc_device_mounted(fs->fs_file_name, MF_RO)) {
+		if (misc_device_mounted(fs->fs_file_name) == MF_RO) {
 			reiserfs_warning(stderr, "\nThe partition is mounted ro. It is better "
 					 "to umount and mount it again.\n\n");
 			retval = EXIT_REBOOT;
diff -Nru a/reiserfsprogs/include/misc.h b/reiserfsprogs/include/misc.h
--- a/reiserfsprogs/include/misc.h	Thu Feb 12 23:29:27 2004
+++ b/reiserfsprogs/include/misc.h	Thu Feb 12 23:29:27 2004
@@ -35,9 +35,9 @@
 char * kdevname (int dev);
 
 typedef enum mount_flags {
-	MF_MOUNTED	= 0x1,
-	MF_RO		= 0x2,
-	MF_RW		= 0x4
+	MF_NOT_MOUNTED  = 0x0,
+	MF_RO		= 0x1,
+	MF_RW		= 0x2
 } mount_flags_t;
 
 typedef struct mount_hint {
@@ -47,7 +47,7 @@
 } mount_hint_t;
 
 struct mntent *misc_mntent(char *device);
-int misc_device_mounted(char *device, __u32 options);
+int misc_device_mounted(char *device);
 	
 void misc_print_credit(FILE *out);
 
diff -Nru a/reiserfsprogs/lib/misc.c b/reiserfsprogs/lib/misc.c
--- a/reiserfsprogs/lib/misc.c	Thu Feb 12 23:29:27 2004
+++ b/reiserfsprogs/lib/misc.c	Thu Feb 12 23:29:27 2004
@@ -328,46 +328,23 @@
 	return (!proc && !path) ? INVAL_PTR : NULL;
 }
 
-static int callback_misc_mounted(char *device, __u32 options) {
-	fprintf(stderr, "Could not figure out, is '%s' '%s' mounted?",
-		device, options & MF_RO ? "RO" : options & MF_RW ? "RW" : "");
-	return (user_confirmed (stderr, " (Yes)", "Yes\n"));
-}
-
-int misc_device_mounted(char *device, __u32 options) {
+int misc_device_mounted(char *device) {
 	struct mntent *mnt;
 	
 	/* Check for the "/" first to avoid any possible problem with 
 	   reflecting the root fs info in mtab files. */
-	if (misc_root_mounted(device)) {
-		if (options & MF_RO)
-			return misc_file_ro(device);
-
-		if (options & MF_RW)
-			return !misc_file_ro(device);
-
-		return 1;
+	if (misc_root_mounted(device) == 1) {
+		return misc_file_ro("/") ? MF_RO : MF_RW;
 	}
 	
 	/* Lookup the mount entry. */
 	if ((mnt = misc_mntent(device)) == NULL) {
-		return 0;
+		return MF_NOT_MOUNTED;
 	} else if (mnt == INVAL_PTR) {
-		goto error;
+		return 0;
 	}
 
-	if (options & MF_RO)
-		return hasmntopt(mnt, MNTOPT_RO) != 0;
-	
-	if (options & MF_RW)
-		return hasmntopt(mnt, MNTOPT_RW) != 0;
-	
-	return 1;
-	
- error:
-	/* Failed to lookup in /proc/mounts and /etc/mtab. 
-	   Check if the "/" first and ask the user then. */
-	return callback_misc_mounted(device, options);
+	return hasmntopt(mnt, MNTOPT_RO) ? MF_RO : MF_RW;
 }
 
 char buf1 [100];
diff -Nru a/reiserfsprogs/reiserfscore/reiserfslib.c b/reiserfsprogs/reiserfscore/reiserfslib.c
--- a/reiserfsprogs/reiserfscore/reiserfslib.c	Thu Feb 12 23:29:27 2004
+++ b/reiserfsprogs/reiserfscore/reiserfslib.c	Thu Feb 12 23:29:27 2004
@@ -1197,7 +1197,7 @@
     dev_t rdev;
 
 
-    if (misc_device_mounted(device_name, 0)) {
+    if (misc_device_mounted(device_name) > 0) {
 	/* device looks mounted */
 	reiserfs_warning (stderr, "'%s' looks mounted.", device_name);
 	check_forcing_ask_confirmation (force);
diff -Nru a/reiserfsprogs/resize_reiserfs/resize_reiserfs.c b/reiserfsprogs/resize_reiserfs/resize_reiserfs.c
--- a/reiserfsprogs/resize_reiserfs/resize_reiserfs.c	Thu Feb 12 23:29:27 2004
+++ b/reiserfsprogs/resize_reiserfs/resize_reiserfs.c	Thu Feb 12 23:29:27 2004
@@ -152,7 +152,7 @@
     }
 
     if (new_size < get_sb_block_count(fs->fs_ondisk_sb)) {
-	if (misc_device_mounted(fs->fs_file_name, 0)) {
+	if (misc_device_mounted(fs->fs_file_name) > 0) {
 	    reiserfs_warning (stderr, "Can't shrink filesystem on-line.\n\n");
 	    return 1;
 	}
@@ -276,7 +276,7 @@
     if (resizer_check_fs_size(fs, block_count_new))
 	return 1;
 
-    if (misc_device_mounted(devname, 0)) {
+    if (misc_device_mounted(devname) > 0) {
 	reiserfs_close(fs);
 	error = resize_fs_online(devname, block_count_new);
 	reiserfs_warning(stderr, "\n\nresize_reiserfs: On-line resizing %s.\n\n",
diff -Nru a/reiserfsprogs/tune/tune.c b/reiserfsprogs/tune/tune.c
--- a/reiserfsprogs/tune/tune.c	Thu Feb 12 23:29:27 2004
+++ b/reiserfsprogs/tune/tune.c	Thu Feb 12 23:29:27 2004
@@ -467,7 +467,7 @@
        --no-journal-available has been specified by user */
 
     /* make sure filesystem is not mounted */
-    if (misc_device_mounted(fs->fs_file_name, 0)) {
+    if (misc_device_mounted(fs->fs_file_name) > 0) {
 	/* fixme: it can not be mounted, btw */
         message ("Reiserfstune is not allowed to be run on mounted filesystem.");
 	reiserfs_close (fs);