]>
git.ipfire.org Git - thirdparty/e2fsprogs.git/blob - misc/util.c
2 * util.c --- helper functions used by tune2fs and mke2fs
4 * Copyright 1995, 1996, 1997, 1998, 1999, 2000 by Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
12 #ifndef _LARGEFILE_SOURCE
13 #define _LARGEFILE_SOURCE
15 #ifndef _LARGEFILE64_SOURCE
16 #define _LARGEFILE64_SOURCE
28 #ifdef HAVE_LINUX_MAJOR_H
29 #include <linux/major.h>
31 #include <sys/types.h>
32 #ifdef HAVE_SYS_STAT_H
40 #include "et/com_err.h"
42 #include "ext2fs/ext2_fs.h"
43 #include "ext2fs/ext2fs.h"
44 #include "support/nls-enable.h"
45 #include "blkid/blkid.h"
48 char *journal_location_string
= NULL
;
50 #ifndef HAVE_STRCASECMP
51 int strcasecmp (char *s1
, char *s2
)
54 int ch1
= *s1
++, ch2
= *s2
++;
62 return *s1
? 1 : *s2
? -1 : 0;
67 * Given argv[0], return the program name.
69 char *get_progname(char *argv_zero
)
73 cp
= strrchr(argv_zero
, '/');
80 static jmp_buf alarm_env
;
82 static void alarm_signal(int signal
EXT2FS_ATTR((unused
)))
84 longjmp(alarm_env
, 1);
87 void proceed_question(int delay
)
90 const char *short_yes
= _("yY");
95 if (setjmp(alarm_env
)) {
96 signal(SIGALRM
, SIG_IGN
);
97 printf("%s", _("<proceeding>\n"));
100 signal(SIGALRM
, alarm_signal
);
101 printf(_("Proceed anyway (or wait %d seconds) ? (y,n) "),
105 fputs(_("Proceed anyway? (y,n) "), stdout
);
107 if (!fgets(buf
, sizeof(buf
), stdin
) ||
108 strchr(short_yes
, buf
[0]) == 0) {
112 signal(SIGALRM
, SIG_IGN
);
115 void check_mount(const char *device
, int force
, const char *type
)
120 retval
= ext2fs_check_if_mounted(device
, &mount_flags
);
122 com_err("ext2fs_check_if_mount", retval
,
123 _("while determining whether %s is mounted."),
127 if (mount_flags
& EXT2_MF_MOUNTED
) {
128 fprintf(stderr
, _("%s is mounted; "), device
);
130 fputs(_("mke2fs forced anyway. Hope /etc/mtab is "
131 "incorrect.\n"), stderr
);
135 fprintf(stderr
, _("will not make a %s here!\n"), type
);
138 if (mount_flags
& EXT2_MF_BUSY
) {
139 fprintf(stderr
, _("%s is apparently in use by the system; "),
142 fputs(_("mke2fs forced anyway.\n"), stderr
);
149 void parse_journal_opts(const char *opts
)
151 char *buf
, *token
, *next
, *p
, *arg
;
153 int journal_usage
= 0;
158 fputs(_("Couldn't allocate memory to parse journal "
159 "options!\n"), stderr
);
163 for (token
= buf
; token
&& *token
; token
= next
) {
164 p
= strchr(token
, ',');
170 arg
= strchr(token
, '=');
176 printf("Journal option=%s, argument=%s\n", token
,
179 if (strcmp(token
, "device") == 0) {
180 journal_device
= blkid_get_devname(NULL
, arg
, NULL
);
181 if (!journal_device
) {
183 fprintf(stderr
, _("\nCould not find "
184 "journal device matching %s\n"),
189 } else if (strcmp(token
, "size") == 0) {
194 journal_size
= strtoul(arg
, &p
, 0);
197 } else if (!strcmp(token
, "location")) {
202 journal_location_string
= strdup(arg
);
203 } else if (strcmp(token
, "v1_superblock") == 0) {
204 journal_flags
|= EXT2_MKJOURNAL_V1_SUPER
;
210 fputs(_("\nBad journal options specified.\n\n"
211 "Journal options are separated by commas, "
212 "and may take an argument which\n"
213 "\tis set off by an equals ('=') sign.\n\n"
214 "Valid journal options are:\n"
215 "\tsize=<journal size in megabytes>\n"
216 "\tdevice=<journal device>\n"
217 "\tlocation=<journal location>\n\n"
218 "The journal size must be between "
219 "1024 and 10240000 filesystem blocks.\n\n"), stderr
);
227 * Determine the number of journal blocks to use, either via
228 * user-specified # of megabytes, or via some intelligently selected
231 * Find a reasonable journal file size (in blocks) given the number of blocks
232 * in the filesystem. For very small filesystems, it is not reasonable to
233 * have a journal that fills more than half of the filesystem.
235 unsigned int figure_journal_size(int size
, ext2_filsys fs
)
239 j_blocks
= ext2fs_default_journal_size(ext2fs_blocks_count(fs
->super
));
241 fputs(_("\nFilesystem too small for a journal\n"), stderr
);
246 j_blocks
= size
* 1024 / (fs
->blocksize
/ 1024);
247 if (j_blocks
< 1024 || j_blocks
> 10240000) {
248 fprintf(stderr
, _("\nThe requested journal "
249 "size is %d blocks; it must be\n"
250 "between 1024 and 10240000 blocks. "
255 if ((unsigned) j_blocks
> ext2fs_free_blocks_count(fs
->super
) / 2) {
256 fputs(_("\nJournal size too big for filesystem.\n"),
264 void print_check_message(int mnt
, unsigned int check
)
270 printf(_("This filesystem will be automatically "
271 "checked every %d mounts or\n"
272 "%g days, whichever comes first. "
273 "Use tune2fs -c or -i to override.\n"),
274 mnt
, ((double) check
) / (3600 * 24));
277 void dump_mmp_msg(struct mmp_struct
*mmp
, const char *msg
)
281 printf("MMP check failed: %s\n", msg
);
283 time_t t
= mmp
->mmp_time
;
285 printf("MMP error info: last update: %s node: %s device: %s\n",
286 ctime(&t
), mmp
->mmp_nodename
, mmp
->mmp_bdevname
);