Whamcloud - gitweb
LU-6722 jbd: double minimum journal size for RHEL7
[tools/e2fsprogs.git] / lib / ext2fs / mkjournal.c
1 /*
2  * mkjournal.c --- make a journal for a filesystem
3  *
4  * Copyright (C) 2000 Theodore Ts'o.
5  *
6  * %Begin-Header%
7  * This file may be redistributed under the terms of the GNU Library
8  * General Public License, version 2.
9  * %End-Header%
10  */
11
12 #include "config.h"
13 #include <stdio.h>
14 #include <string.h>
15 #if HAVE_UNISTD_H
16 #include <unistd.h>
17 #endif
18 #if HAVE_ERRNO_H
19 #include <errno.h>
20 #endif
21 #include <fcntl.h>
22 #include <time.h>
23 #if HAVE_SYS_STAT_H
24 #include <sys/stat.h>
25 #endif
26 #if HAVE_SYS_TYPES_H
27 #include <sys/types.h>
28 #endif
29 #if HAVE_SYS_IOCTL_H
30 #include <sys/ioctl.h>
31 #endif
32 #if HAVE_NETINET_IN_H
33 #include <netinet/in.h>
34 #endif
35 #ifdef __linux__
36 #include <sys/utsname.h>
37 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
38 #endif
39
40 #include "ext2_fs.h"
41 #include "e2p/e2p.h"
42 #include "ext2fs.h"
43 #include "jfs_user.h"
44
45 /*
46  * This function automatically sets up the journal superblock and
47  * returns it as an allocated block.
48  */
49 errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
50                                            __u32 num_blocks, int flags,
51                                            char  **ret_jsb)
52 {
53         errcode_t               retval;
54         journal_superblock_t    *jsb;
55
56         if (num_blocks < JFS_MIN_JOURNAL_BLOCKS)
57                 return EXT2_ET_JOURNAL_TOO_SMALL;
58
59         if ((retval = ext2fs_get_mem(fs->blocksize, &jsb)))
60                 return retval;
61
62         memset (jsb, 0, fs->blocksize);
63
64         jsb->s_header.h_magic = htonl(JFS_MAGIC_NUMBER);
65         if (flags & EXT2_MKJOURNAL_V1_SUPER)
66                 jsb->s_header.h_blocktype = htonl(JFS_SUPERBLOCK_V1);
67         else
68                 jsb->s_header.h_blocktype = htonl(JFS_SUPERBLOCK_V2);
69         jsb->s_blocksize = htonl(fs->blocksize);
70         jsb->s_maxlen = htonl(num_blocks);
71         jsb->s_nr_users = htonl(1);
72         jsb->s_first = htonl(1);
73         jsb->s_sequence = htonl(1);
74         memcpy(jsb->s_uuid, fs->super->s_uuid, sizeof(fs->super->s_uuid));
75         /*
76          * If we're creating an external journal device, we need to
77          * adjust these fields.
78          */
79         if (fs->super->s_feature_incompat &
80             EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
81                 jsb->s_nr_users = 0;
82                 jsb->s_first = htonl(ext2fs_journal_sb_start(fs->blocksize) + 1);
83         }
84
85         *ret_jsb = (char *) jsb;
86         return 0;
87 }
88
89 /*
90  * This function writes a journal using POSIX routines.  It is used
91  * for creating external journals and creating journals on live
92  * filesystems.
93  */
94 static errcode_t write_journal_file(ext2_filsys fs, char *filename,
95                                     blk_t num_blocks, int flags)
96 {
97         errcode_t       retval;
98         char            *buf = 0;
99         int             fd, ret_size;
100         blk_t           i;
101
102         if ((retval = ext2fs_create_journal_superblock(fs, num_blocks, flags,
103                                                        &buf)))
104                 return retval;
105
106         /* Open the device or journal file */
107         if ((fd = open(filename, O_WRONLY)) < 0) {
108                 retval = errno;
109                 goto errfree;
110         }
111
112         /* Write the superblock out */
113         retval = EXT2_ET_SHORT_WRITE;
114         ret_size = write(fd, buf, fs->blocksize);
115         if (ret_size < 0) {
116                 retval = errno;
117                 goto errout;
118         }
119         if (ret_size != (int) fs->blocksize)
120                 goto errout;
121         memset(buf, 0, fs->blocksize);
122
123         if (flags & EXT2_MKJOURNAL_LAZYINIT)
124                 goto success;
125
126         for (i = 1; i < num_blocks; i++) {
127                 ret_size = write(fd, buf, fs->blocksize);
128                 if (ret_size < 0) {
129                         retval = errno;
130                         goto errout;
131                 }
132                 if (ret_size != (int) fs->blocksize)
133                         goto errout;
134         }
135
136 success:
137         retval = 0;
138 errout:
139         close(fd);
140 errfree:
141         ext2fs_free_mem(&buf);
142         return retval;
143 }
144
145 /*
146  * Convenience function which zeros out _num_ blocks starting at
147  * _blk_.  In case of an error, the details of the error is returned
148  * via _ret_blk_ and _ret_count_ if they are non-NULL pointers.
149  * Returns 0 on success, and an error code on an error.
150  *
151  * As a special case, if the first argument is NULL, then it will
152  * attempt to free the static zeroizing buffer.  (This is to keep
153  * programs that check for memory leaks happy.)
154  */
155 #define STRIDE_LENGTH 8
156 errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_t blk, int num,
157                               blk64_t *ret_blk, int *ret_count)
158 {
159         int             j, count;
160         static char     *buf;
161         errcode_t       retval;
162
163         /* If fs is null, clean up the static buffer and return */
164         if (!fs) {
165                 if (buf) {
166                         free(buf);
167                         buf = 0;
168                 }
169                 return 0;
170         }
171         /* Allocate the zeroizing buffer if necessary */
172         if (!buf) {
173                 buf = malloc(fs->blocksize * STRIDE_LENGTH);
174                 if (!buf)
175                         return ENOMEM;
176                 memset(buf, 0, fs->blocksize * STRIDE_LENGTH);
177         }
178         /* OK, do the write loop */
179         j=0;
180         while (j < num) {
181                 if (blk % STRIDE_LENGTH) {
182                         count = STRIDE_LENGTH - (blk % STRIDE_LENGTH);
183                         if (count > (num - j))
184                                 count = num - j;
185                 } else {
186                         count = num - j;
187                         if (count > STRIDE_LENGTH)
188                                 count = STRIDE_LENGTH;
189                 }
190                 retval = io_channel_write_blk64(fs->io, blk, count, buf);
191                 if (retval) {
192                         if (ret_count)
193                                 *ret_count = count;
194                         if (ret_blk)
195                                 *ret_blk = blk;
196                         return retval;
197                 }
198                 j += count; blk += count;
199         }
200         return 0;
201 }
202
203 errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num,
204                              blk_t *ret_blk, int *ret_count)
205 {
206         blk64_t ret_blk2;
207         errcode_t retval;
208
209         retval = ext2fs_zero_blocks2(fs, blk, num, &ret_blk2, ret_count);
210         if (retval)
211                 *ret_blk = (blk_t) ret_blk2;
212         return retval;
213 }
214
215 /*
216  * Helper function for creating the journal using direct I/O routines
217  */
218 struct mkjournal_struct {
219         int             num_blocks;
220         int             newblocks;
221         blk64_t         goal;
222         blk64_t         blk_to_zero;
223         int             zero_count;
224         int             flags;
225         char            *buf;
226         errcode_t       err;
227 };
228
229 static int mkjournal_proc(ext2_filsys   fs,
230                           blk64_t       *blocknr,
231                           e2_blkcnt_t   blockcnt,
232                           blk64_t       ref_block EXT2FS_ATTR((unused)),
233                           int           ref_offset EXT2FS_ATTR((unused)),
234                           void          *priv_data)
235 {
236         struct mkjournal_struct *es = (struct mkjournal_struct *) priv_data;
237         blk64_t new_blk;
238         errcode_t       retval;
239
240         if (*blocknr) {
241                 es->goal = *blocknr;
242                 return 0;
243         }
244         if (blockcnt &&
245             (EXT2FS_B2C(fs, es->goal) == EXT2FS_B2C(fs, es->goal+1)))
246                 new_blk = es->goal+1;
247         else {
248                 es->goal &= ~EXT2FS_CLUSTER_MASK(fs);
249                 retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk);
250                 if (retval) {
251                         es->err = retval;
252                         return BLOCK_ABORT;
253                 }
254                 ext2fs_block_alloc_stats2(fs, new_blk, +1);
255                 es->newblocks++;
256         }
257         if (blockcnt >= 0)
258                 es->num_blocks--;
259
260         retval = 0;
261         if (blockcnt <= 0)
262                 retval = io_channel_write_blk64(fs->io, new_blk, 1, es->buf);
263         else if (!(es->flags & EXT2_MKJOURNAL_LAZYINIT)) {
264                 if (es->zero_count) {
265                         if ((es->blk_to_zero + es->zero_count == new_blk) &&
266                             (es->zero_count < 1024))
267                                 es->zero_count++;
268                         else {
269                                 retval = ext2fs_zero_blocks2(fs,
270                                                              es->blk_to_zero,
271                                                              es->zero_count,
272                                                              0, 0);
273                                 es->zero_count = 0;
274                         }
275                 }
276                 if (es->zero_count == 0) {
277                         es->blk_to_zero = new_blk;
278                         es->zero_count = 1;
279                 }
280         }
281
282         if (blockcnt == 0)
283                 memset(es->buf, 0, fs->blocksize);
284
285         if (retval) {
286                 es->err = retval;
287                 return BLOCK_ABORT;
288         }
289         *blocknr = es->goal = new_blk;
290
291         if (es->num_blocks == 0)
292                 return (BLOCK_CHANGED | BLOCK_ABORT);
293         else
294                 return BLOCK_CHANGED;
295
296 }
297
298 /*
299  * Calculate the initial goal block to be roughly at the middle of the
300  * filesystem.  Pick a group that has the largest number of free
301  * blocks.
302  */
303 static blk64_t get_midpoint_journal_block(ext2_filsys fs)
304 {
305         dgrp_t  group, start, end, i, log_flex;
306
307         group = ext2fs_group_of_blk2(fs, (ext2fs_blocks_count(fs->super) -
308                                          fs->super->s_first_data_block) / 2);
309         log_flex = 1 << fs->super->s_log_groups_per_flex;
310         if (fs->super->s_log_groups_per_flex && (group > log_flex)) {
311                 group = group & ~(log_flex - 1);
312                 while ((group < fs->group_desc_count) &&
313                        ext2fs_bg_free_blocks_count(fs, group) == 0)
314                         group++;
315                 if (group == fs->group_desc_count)
316                         group = 0;
317                 start = group;
318         } else
319                 start = (group > 0) ? group-1 : group;
320         end = ((group+1) < fs->group_desc_count) ? group+1 : group;
321         group = start;
322         for (i = start + 1; i <= end; i++)
323                 if (ext2fs_bg_free_blocks_count(fs, i) >
324                     ext2fs_bg_free_blocks_count(fs, group))
325                         group = i;
326         return ext2fs_group_first_block2(fs, group);
327 }
328
329 /*
330  * This function creates a journal using direct I/O routines.
331  */
332 static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino,
333                                      blk_t num_blocks, blk64_t goal, int flags)
334 {
335         char                    *buf;
336         errcode_t               retval;
337         struct ext2_inode       inode;
338         unsigned long long      inode_size;
339         struct mkjournal_struct es;
340
341         if ((retval = ext2fs_create_journal_superblock(fs, num_blocks, flags,
342                                                        &buf)))
343                 return retval;
344
345         if ((retval = ext2fs_read_bitmaps(fs)))
346                 goto out2;
347
348         if ((retval = ext2fs_read_inode(fs, journal_ino, &inode)))
349                 goto out2;
350
351         if (inode.i_blocks > 0) {
352                 retval = EEXIST;
353                 goto out2;
354         }
355
356         es.num_blocks = num_blocks;
357         es.newblocks = 0;
358         es.buf = buf;
359         es.err = 0;
360         es.flags = flags;
361         es.zero_count = 0;
362         es.goal = (goal != ~0ULL) ? goal : get_midpoint_journal_block(fs);
363
364         if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) {
365                 inode.i_flags |= EXT4_EXTENTS_FL;
366                 if ((retval = ext2fs_write_inode(fs, journal_ino, &inode)))
367                         goto out2;
368         }
369
370         retval = ext2fs_block_iterate3(fs, journal_ino, BLOCK_FLAG_APPEND,
371                                        0, mkjournal_proc, &es);
372         if (es.err) {
373                 retval = es.err;
374                 goto errout;
375         }
376         if (es.zero_count) {
377                 retval = ext2fs_zero_blocks2(fs, es.blk_to_zero,
378                                             es.zero_count, 0, 0);
379                 if (retval)
380                         goto errout;
381         }
382
383         if ((retval = ext2fs_read_inode(fs, journal_ino, &inode)))
384                 goto errout;
385
386         inode_size = (unsigned long long)fs->blocksize * num_blocks;
387         ext2fs_iblk_add_blocks(fs, &inode, es.newblocks);
388         inode.i_mtime = inode.i_ctime = fs->now ? fs->now : time(0);
389         inode.i_links_count = 1;
390         inode.i_mode = LINUX_S_IFREG | 0600;
391         retval = ext2fs_inode_size_set(fs, &inode, inode_size);
392         if (retval)
393                 goto errout;
394
395         if ((retval = ext2fs_write_new_inode(fs, journal_ino, &inode)))
396                 goto errout;
397         retval = 0;
398
399         memcpy(fs->super->s_jnl_blocks, inode.i_block, EXT2_N_BLOCKS*4);
400         fs->super->s_jnl_blocks[15] = inode.i_size_high;
401         fs->super->s_jnl_blocks[16] = inode.i_size;
402         fs->super->s_jnl_backup_type = EXT3_JNL_BACKUP_BLOCKS;
403         ext2fs_mark_super_dirty(fs);
404
405 errout:
406         ext2fs_zero_blocks2(0, 0, 0, 0, 0);
407 out2:
408         ext2fs_free_mem(&buf);
409         return retval;
410 }
411
412 #ifdef __linux__
413 static int parse_version_number(const char *s)
414 {
415         int     major, minor, rev;
416         char    *endptr;
417         const char *cp = s;
418
419         if (!s)
420                 return 0;
421         major = strtol(cp, &endptr, 10);
422         if (cp == endptr || *endptr != '.')
423                 return 0;
424         cp = endptr + 1;
425         minor = strtol(cp, &endptr, 10);
426         if (cp == endptr || *endptr != '.')
427                 return 0;
428         cp = endptr + 1;
429         rev = strtol(cp, &endptr, 10);
430         if (cp == endptr)
431                 return 0;
432         return KERNEL_VERSION(major, minor, rev);
433 }
434
435 int ext2fs_is_before_linux_ver(unsigned int major, unsigned int minor,
436                                unsigned int rev)
437 {
438         struct          utsname ut;
439         static int      linux_version_code = -1;
440
441         if (uname(&ut)) {
442                 perror("uname");
443                 exit(1);
444         }
445         if (linux_version_code < 0)
446                 linux_version_code = parse_version_number(ut.release);
447         if (linux_version_code == 0)
448                 return 0;
449
450         return linux_version_code < KERNEL_VERSION(major, minor, rev);
451 }
452 #else
453 int ext2fs_is_before_linux_ver(unsigned int major, unsigned int minor,
454                                unsigned int rev)
455 {
456         return 0;
457 }
458 #endif
459
460 /*
461  * Find a reasonable journal file size (in blocks) given the number of blocks
462  * in the filesystem.  For very small filesystems, it is not reasonable to
463  * have a journal that fills more than half of the filesystem.
464  */
465 int ext2fs_default_journal_size(__u64 num_blocks)
466 {
467         if (num_blocks < 2048)
468                 return -1;
469         if (num_blocks <= 8192)
470                 return (1024);
471         if (num_blocks < 32768)
472                 return (2048);
473         if (num_blocks < 256*1024)
474                 return (4096);
475         if (num_blocks < 512*1024)
476                 return (8192);
477         if (num_blocks < 1024*1024)
478                 return (16384);
479         return 32768;
480 }
481
482 int ext2fs_journal_sb_start(int blocksize)
483 {
484         if (blocksize == EXT2_MIN_BLOCK_SIZE)
485                 return 2;
486         return 1;
487 }
488
489 /*
490  * This function adds a journal device to a filesystem
491  */
492 errcode_t ext2fs_add_journal_device(ext2_filsys fs, ext2_filsys journal_dev)
493 {
494         struct stat     st;
495         errcode_t       retval;
496         char            buf[SUPERBLOCK_SIZE];
497         journal_superblock_t    *jsb;
498         int             start;
499         __u32           i, nr_users;
500
501         /* Make sure the device exists and is a block device */
502         if (stat(journal_dev->device_name, &st) < 0)
503                 return errno;
504
505         if (!S_ISBLK(st.st_mode))
506                 return EXT2_ET_JOURNAL_NOT_BLOCK; /* Must be a block device */
507
508         /* Get the journal superblock */
509         start = ext2fs_journal_sb_start(journal_dev->blocksize);
510         if ((retval = io_channel_read_blk64(journal_dev->io, start,
511                                             -SUPERBLOCK_SIZE,
512                                             buf)))
513                 return retval;
514
515         jsb = (journal_superblock_t *) buf;
516         if ((jsb->s_header.h_magic != (unsigned) ntohl(JFS_MAGIC_NUMBER)) ||
517             (jsb->s_header.h_blocktype != (unsigned) ntohl(JFS_SUPERBLOCK_V2)))
518                 return EXT2_ET_NO_JOURNAL_SB;
519
520         if (ntohl(jsb->s_blocksize) != (unsigned long) fs->blocksize)
521                 return EXT2_ET_UNEXPECTED_BLOCK_SIZE;
522
523         /* Check and see if this filesystem has already been added */
524         nr_users = ntohl(jsb->s_nr_users);
525         for (i=0; i < nr_users; i++) {
526                 if (memcmp(fs->super->s_uuid,
527                            &jsb->s_users[i*16], 16) == 0)
528                         break;
529         }
530         if (i >= nr_users) {
531                 memcpy(&jsb->s_users[nr_users*16],
532                        fs->super->s_uuid, 16);
533                 jsb->s_nr_users = htonl(nr_users+1);
534         }
535
536         /* Writeback the journal superblock */
537         if ((retval = io_channel_write_blk64(journal_dev->io, start,
538                                             -SUPERBLOCK_SIZE, buf)))
539                 return retval;
540
541         fs->super->s_journal_inum = 0;
542         fs->super->s_journal_dev = st.st_rdev;
543         memcpy(fs->super->s_journal_uuid, jsb->s_uuid,
544                sizeof(fs->super->s_journal_uuid));
545         fs->super->s_feature_compat |= EXT3_FEATURE_COMPAT_HAS_JOURNAL;
546         ext2fs_mark_super_dirty(fs);
547         return 0;
548 }
549
550 /*
551  * This function adds a journal inode to a filesystem, using either
552  * POSIX routines if the filesystem is mounted, or using direct I/O
553  * functions if it is not.
554  */
555 errcode_t ext2fs_add_journal_inode2(ext2_filsys fs, blk_t num_blocks,
556                                     blk64_t goal, int flags)
557 {
558         errcode_t               retval;
559         ext2_ino_t              journal_ino;
560         struct stat             st;
561         char                    jfile[1024];
562         int                     mount_flags;
563         int                     fd = -1;
564
565         if (flags & EXT2_MKJOURNAL_NO_MNT_CHECK)
566                 mount_flags = 0;
567         else if ((retval = ext2fs_check_mount_point(fs->device_name,
568                                                     &mount_flags,
569                                                     jfile, sizeof(jfile)-10)))
570                 return retval;
571
572         if (mount_flags & EXT2_MF_MOUNTED) {
573 #if HAVE_EXT2_IOCTLS
574                 int f = 0;
575 #endif
576                 strcat(jfile, "/.journal");
577
578                 /*
579                  * If .../.journal already exists, make sure any
580                  * immutable or append-only flags are cleared.
581                  */
582 #if defined(HAVE_CHFLAGS) && defined(UF_NODUMP)
583                 (void) chflags (jfile, 0);
584 #else
585 #if HAVE_EXT2_IOCTLS
586                 fd = open(jfile, O_RDONLY);
587                 if (fd >= 0) {
588                         retval = ioctl(fd, EXT2_IOC_SETFLAGS, &f);
589                         close(fd);
590                         if (retval)
591                                 return retval;
592                 }
593 #endif
594 #endif
595
596                 /* Create the journal file */
597                 if ((fd = open(jfile, O_CREAT|O_WRONLY, 0600)) < 0)
598                         return errno;
599
600                 /* Note that we can't do lazy journal initialization for mounted
601                  * filesystems, since the zero writing is also allocating the
602                  * journal blocks.  We could use fallocate, but not all kernels
603                  * support that, and creating a journal on a mounted ext2
604                  * filesystems is extremely rare these days...  Ignore it. */
605                 flags &= ~EXT2_MKJOURNAL_LAZYINIT;
606
607                 if ((retval = write_journal_file(fs, jfile, num_blocks, flags)))
608                         goto errout;
609
610                 /* Get inode number of the journal file */
611                 if (fstat(fd, &st) < 0) {
612                         retval = errno;
613                         goto errout;
614                 }
615
616 #if defined(HAVE_CHFLAGS) && defined(UF_NODUMP)
617                 retval = fchflags (fd, UF_NODUMP|UF_IMMUTABLE);
618 #else
619 #if HAVE_EXT2_IOCTLS
620                 if (ioctl(fd, EXT2_IOC_GETFLAGS, &f) < 0) {
621                         retval = errno;
622                         goto errout;
623                 }
624                 f |= EXT2_NODUMP_FL | EXT2_IMMUTABLE_FL;
625                 retval = ioctl(fd, EXT2_IOC_SETFLAGS, &f);
626 #endif
627 #endif
628                 if (retval) {
629                         retval = errno;
630                         goto errout;
631                 }
632
633                 if (close(fd) < 0) {
634                         retval = errno;
635                         fd = -1;
636                         goto errout;
637                 }
638                 journal_ino = st.st_ino;
639                 memset(fs->super->s_jnl_blocks, 0,
640                        sizeof(fs->super->s_jnl_blocks));
641         } else {
642                 if ((mount_flags & EXT2_MF_BUSY) &&
643                     !(fs->flags & EXT2_FLAG_EXCLUSIVE)) {
644                         retval = EBUSY;
645                         goto errout;
646                 }
647                 journal_ino = EXT2_JOURNAL_INO;
648                 if ((retval = write_journal_inode(fs, journal_ino,
649                                                   num_blocks, goal, flags)))
650                         return retval;
651         }
652
653         fs->super->s_journal_inum = journal_ino;
654         fs->super->s_journal_dev = 0;
655         memset(fs->super->s_journal_uuid, 0,
656                sizeof(fs->super->s_journal_uuid));
657         fs->super->s_feature_compat |= EXT3_FEATURE_COMPAT_HAS_JOURNAL;
658
659         ext2fs_mark_super_dirty(fs);
660         return 0;
661 errout:
662         if (fd >= 0)
663                 close(fd);
664         return retval;
665 }
666
667 errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks, int flags)
668 {
669         return ext2fs_add_journal_inode2(fs, num_blocks, ~0ULL, flags);
670 }
671
672
673 #ifdef DEBUG
674 main(int argc, char **argv)
675 {
676         errcode_t       retval;
677         char            *device_name;
678         ext2_filsys     fs;
679
680         if (argc < 2) {
681                 fprintf(stderr, "Usage: %s filesystem\n", argv[0]);
682                 exit(1);
683         }
684         device_name = argv[1];
685
686         retval = ext2fs_open (device_name, EXT2_FLAG_RW, 0, 0,
687                               unix_io_manager, &fs);
688         if (retval) {
689                 com_err(argv[0], retval, "while opening %s", device_name);
690                 exit(1);
691         }
692
693         retval = ext2fs_add_journal_inode(fs, JFS_MIN_JOURNAL_BLOCKS, 0);
694         if (retval) {
695                 com_err(argv[0], retval, "while adding journal to %s",
696                         device_name);
697                 exit(1);
698         }
699         retval = ext2fs_flush(fs);
700         if (retval) {
701                 printf("Warning, had trouble writing out superblocks.\n");
702         }
703         ext2fs_close_free(&fs);
704         exit(0);
705
706 }
707 #endif