@@ -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,38 @@ 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
+ break ;
136
+ }
134
137
}
135
- if (buf )
138
+
139
+ retcode = retval ;
140
+
141
+ if (buf )
136
142
ext2fs_free_mem (& buf );
137
- retval = ext2fs_file_close (e2_file );
143
+
144
+ retval = ext2fs_file_close (e2_file );
138
145
if (retval ) {
139
146
com_err (cmdname , retval , "while closing ext2 file" );
140
- return ;
147
+ return retval ;
141
148
}
142
149
143
150
if (preserve )
144
151
fix_perms ("dump_file" , & inode , fd , outname );
145
152
146
- return ;
153
+ return retcode ;
147
154
}
148
155
149
156
void do_dump (int argc , char * * argv , int sci_idx EXT2FS_ATTR ((unused )),
150
157
void * infop EXT2FS_ATTR ((unused )))
151
158
{
159
+ int retval ;
152
160
ext2_ino_t inode ;
153
161
int fd ;
154
162
int c ;
155
163
int preserve = 0 ;
156
- char * in_fn , * out_fn ;
164
+ char * in_fn , * out_fn ;
157
165
158
166
reset_getopt ();
159
167
while ((c = getopt (argc , argv , "p" )) != EOF ) {
@@ -165,37 +173,36 @@ void do_dump(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
165
173
print_usage :
166
174
com_err (argv [0 ], 0 , "Usage: dump_inode [-p] "
167
175
"<file> <output_file>" );
168
- return ;
176
+ exit ( 1 ) ;
169
177
}
170
178
}
171
179
if (optind != argc - 2 )
172
180
goto print_usage ;
173
181
174
182
if (check_fs_open (argv [0 ]))
175
- return ;
183
+ exit ( 1 ) ;
176
184
177
185
in_fn = argv [optind ];
178
186
out_fn = argv [optind + 1 ];
179
187
180
188
inode = string_to_inode (in_fn );
181
189
if (!inode )
182
- return ;
190
+ exit ( 1 ) ;
183
191
184
192
fd = open (out_fn , O_CREAT | O_WRONLY | O_TRUNC | O_LARGEFILE , 0666 );
185
193
if (fd < 0 ) {
186
194
com_err (argv [0 ], errno , "while opening %s for dump_inode" ,
187
195
out_fn );
188
- return ;
196
+ exit ( 1 ) ;
189
197
}
190
198
191
- dump_file (argv [0 ], inode , fd , preserve , out_fn );
192
- if (close (fd ) != 0 ) {
199
+ retval = dump_file (argv [0 ], inode , fd , preserve , out_fn );
200
+ if (close (fd ) != 0 ) {
193
201
com_err (argv [0 ], errno , "while closing %s for dump_inode" ,
194
202
out_fn );
195
- return ;
203
+ exit ( 1 ) ;
196
204
}
197
-
198
- return ;
205
+ exit (retval );
199
206
}
200
207
201
208
static void rdump_symlink (ext2_ino_t ino , struct ext2_inode * inode ,
@@ -273,8 +280,12 @@ static void rdump_inode(ext2_ino_t ino, struct ext2_inode *inode,
273
280
com_err ("rdump" , errno , "while opening %s" , fullname );
274
281
goto errout ;
275
282
}
276
- dump_file ("rdump" , ino , fd , 1 , fullname );
277
- if (close (fd ) != 0 ) {
283
+ if (dump_file ("rdump" , ino , fd , 1 , fullname ) != 0 ) {
284
+ com_err ("rdump" , errno , "while dumping %s" , fullname );
285
+ free (fullname );
286
+ exit (1 );
287
+ }
288
+ if (close (fd ) != 0 ) {
278
289
com_err ("rdump" , errno , "while closing %s" , fullname );
279
290
goto errout ;
280
291
}
0 commit comments