@@ -97,28 +97,29 @@ static void fix_perms(const char *cmd, const struct ext2_inode *inode,
97
97
com_err (cmd , errno , "while setting times of %s" , name );
98
98
}
99
99
100
- static void dump_file (const char * cmdname , ext2_ino_t ino , int fd ,
100
+ static int dump_file (const char * cmdname , ext2_ino_t ino , int fd ,
101
101
int preserve , char * outname )
102
102
{
103
103
errcode_t retval ;
104
+ errcode_t retcode ;
104
105
struct ext2_inode inode ;
105
106
char * buf = 0 ;
106
107
ext2_file_t e2_file ;
107
108
int nbytes ;
108
109
unsigned int got , blocksize = current_fs -> blocksize ;
109
110
110
111
if (debugfs_read_inode (ino , & inode , cmdname ))
111
- return ;
112
+ return 1 ;
112
113
113
114
retval = ext2fs_file_open (current_fs , ino , 0 , & e2_file );
114
115
if (retval ) {
115
116
com_err (cmdname , retval , "while opening ext2 file" );
116
- return ;
117
+ return retval ;
117
118
}
118
119
retval = ext2fs_get_mem (blocksize , & buf );
119
120
if (retval ) {
120
121
com_err (cmdname , retval , "while allocating memory" );
121
- return ;
122
+ return retval ;
122
123
}
123
124
while (1 ) {
124
125
retval = ext2fs_file_read (e2_file , buf , blocksize , & got );
@@ -129,31 +130,39 @@ static void dump_file(const char *cmdname, ext2_ino_t ino, int fd,
129
130
if (got == 0 )
130
131
break ;
131
132
nbytes = write (fd , buf , got );
132
- if ((unsigned ) nbytes != got )
133
- com_err (cmdname , errno , "while writing file" );
133
+ if ((unsigned ) nbytes != got ) {
134
+ com_err (cmdname , errno , "while writing file" );
135
+ retval = 1 ;
136
+ break ;
137
+ }
134
138
}
135
- if (buf )
139
+
140
+ retcode = retval ;
141
+
142
+ if (buf )
136
143
ext2fs_free_mem (& buf );
137
- retval = ext2fs_file_close (e2_file );
144
+
145
+ retval = ext2fs_file_close (e2_file );
138
146
if (retval ) {
139
147
com_err (cmdname , retval , "while closing ext2 file" );
140
- return ;
148
+ return retval ;
141
149
}
142
150
143
151
if (preserve )
144
152
fix_perms ("dump_file" , & inode , fd , outname );
145
153
146
- return ;
154
+ return retcode ;
147
155
}
148
156
149
157
void do_dump (int argc , char * * argv , int sci_idx EXT2FS_ATTR ((unused )),
150
158
void * infop EXT2FS_ATTR ((unused )))
151
159
{
160
+ int retval ;
152
161
ext2_ino_t inode ;
153
162
int fd ;
154
163
int c ;
155
164
int preserve = 0 ;
156
- char * in_fn , * out_fn ;
165
+ char * in_fn , * out_fn ;
157
166
158
167
reset_getopt ();
159
168
while ((c = getopt (argc , argv , "p" )) != EOF ) {
@@ -165,37 +174,36 @@ void do_dump(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
165
174
print_usage :
166
175
com_err (argv [0 ], 0 , "Usage: dump_inode [-p] "
167
176
"<file> <output_file>" );
168
- return ;
177
+ exit ( 1 ) ;
169
178
}
170
179
}
171
180
if (optind != argc - 2 )
172
181
goto print_usage ;
173
182
174
183
if (check_fs_open (argv [0 ]))
175
- return ;
184
+ exit ( 1 ) ;
176
185
177
186
in_fn = argv [optind ];
178
187
out_fn = argv [optind + 1 ];
179
188
180
189
inode = string_to_inode (in_fn );
181
190
if (!inode )
182
- return ;
191
+ exit ( 1 ) ;
183
192
184
193
fd = open (out_fn , O_CREAT | O_WRONLY | O_TRUNC | O_LARGEFILE , 0666 );
185
194
if (fd < 0 ) {
186
195
com_err (argv [0 ], errno , "while opening %s for dump_inode" ,
187
196
out_fn );
188
- return ;
197
+ exit ( 1 ) ;
189
198
}
190
199
191
- dump_file (argv [0 ], inode , fd , preserve , out_fn );
192
- if (close (fd ) != 0 ) {
200
+ retval = dump_file (argv [0 ], inode , fd , preserve , out_fn );
201
+ if (close (fd ) != 0 ) {
193
202
com_err (argv [0 ], errno , "while closing %s for dump_inode" ,
194
203
out_fn );
195
- return ;
204
+ exit ( 1 ) ;
196
205
}
197
-
198
- return ;
206
+ exit (retval );
199
207
}
200
208
201
209
static void rdump_symlink (ext2_ino_t ino , struct ext2_inode * inode ,
@@ -273,8 +281,12 @@ static void rdump_inode(ext2_ino_t ino, struct ext2_inode *inode,
273
281
com_err ("rdump" , errno , "while opening %s" , fullname );
274
282
goto errout ;
275
283
}
276
- dump_file ("rdump" , ino , fd , 1 , fullname );
277
- if (close (fd ) != 0 ) {
284
+ if (dump_file ("rdump" , ino , fd , 1 , fullname ) != 0 ) {
285
+ com_err ("rdump" , errno , "while dumping %s" , fullname );
286
+ free (fullname );
287
+ exit (1 );
288
+ }
289
+ if (close (fd ) != 0 ) {
278
290
com_err ("rdump" , errno , "while closing %s" , fullname );
279
291
goto errout ;
280
292
}
0 commit comments