📄 tune2fs.c
字号:
if (argc == 3) { open_flag = EXT2_FLAG_RW | EXT2_FLAG_JOURNAL_DEV_OK; L_flag = 1; new_label = argv[2]; } else print_label++;}#else#define parse_e2label_options(x,y)#endifstatic time_t parse_time(char *str){ struct tm ts; if (strcmp(str, "now") == 0) { return time(0); } memset(&ts, 0, sizeof(ts));#ifdef HAVE_STRPTIME strptime(str, "%Y%m%d%H%M%S", &ts);#else sscanf(str, "%4d%2d%2d%2d%2d%2d", &ts.tm_year, &ts.tm_mon, &ts.tm_mday, &ts.tm_hour, &ts.tm_min, &ts.tm_sec); ts.tm_year -= 1900; ts.tm_mon -= 1; if (ts.tm_year < 0 || ts.tm_mon < 0 || ts.tm_mon > 11 || ts.tm_mday < 0 || ts.tm_mday > 31 || ts.tm_hour > 23 || ts.tm_min > 59 || ts.tm_sec > 61) ts.tm_mday = 0;#endif if (ts.tm_mday == 0) { bb_error_msg_and_die("Cannot parse date/time specifier: %s", str); } return mktime(&ts);}static void parse_tune2fs_options(int argc, char **argv){ int c; char * tmp; printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE); while ((c = getopt(argc, argv, "c:e:fg:i:jlm:o:r:s:u:C:J:L:M:O:T:U:")) != EOF) switch (c) { case 'c': max_mount_count = xatou_range(optarg, 0, 16000); if (max_mount_count == 0) max_mount_count = -1; c_flag = 1; open_flag = EXT2_FLAG_RW; break; case 'C': mount_count = xatou_range(optarg, 0, 16000); C_flag = 1; open_flag = EXT2_FLAG_RW; break; case 'e': if (strcmp (optarg, "continue") == 0) errors = EXT2_ERRORS_CONTINUE; else if (strcmp (optarg, "remount-ro") == 0) errors = EXT2_ERRORS_RO; else if (strcmp (optarg, "panic") == 0) errors = EXT2_ERRORS_PANIC; else { bb_error_msg_and_die("bad error behavior - %s", optarg); } e_flag = 1; open_flag = EXT2_FLAG_RW; break; case 'f': /* Force */ f_flag = 1; break; case 'g': resgid = bb_strtoul(optarg, NULL, 10); if (errno) resgid = xgroup2gid(optarg); g_flag = 1; open_flag = EXT2_FLAG_RW; break; case 'i': interval = strtoul(optarg, &tmp, 0); switch (*tmp) { case 's': tmp++; break; case '\0': case 'd': case 'D': /* days */ interval *= 86400; if (*tmp != '\0') tmp++; break; case 'm': case 'M': /* months! */ interval *= 86400 * 30; tmp++; break; case 'w': case 'W': /* weeks */ interval *= 86400 * 7; tmp++; break; } if (*tmp || interval > (365 * 86400)) { bb_error_msg_and_die("bad interval - %s", optarg); } i_flag = 1; open_flag = EXT2_FLAG_RW; break; case 'j': if (!journal_size) journal_size = -1; open_flag = EXT2_FLAG_RW; break; case 'J': parse_journal_opts(&journal_device, &journal_flags, &journal_size, optarg); open_flag = EXT2_FLAG_RW; break; case 'l': l_flag = 1; break; case 'L': new_label = optarg; L_flag = 1; open_flag = EXT2_FLAG_RW | EXT2_FLAG_JOURNAL_DEV_OK; break; case 'm': reserved_ratio = xatou_range(optarg, 0, 50); m_flag = 1; open_flag = EXT2_FLAG_RW; break; case 'M': new_last_mounted = optarg; M_flag = 1; open_flag = EXT2_FLAG_RW; break; case 'o': if (mntopts_cmd) { bb_error_msg_and_die("-o may only be specified once"); } mntopts_cmd = optarg; open_flag = EXT2_FLAG_RW; break; case 'O': if (features_cmd) { bb_error_msg_and_die("-O may only be specified once"); } features_cmd = optarg; open_flag = EXT2_FLAG_RW; break; case 'r': reserved_blocks = xatoul(optarg); r_flag = 1; open_flag = EXT2_FLAG_RW; break; case 's': s_flag = atoi(optarg); open_flag = EXT2_FLAG_RW; break; case 'T': T_flag = 1; last_check_time = parse_time(optarg); open_flag = EXT2_FLAG_RW; break; case 'u': resuid = bb_strtoul(optarg, NULL, 10); if (errno) resuid = xuname2uid(optarg); u_flag = 1; open_flag = EXT2_FLAG_RW; break; case 'U': new_UUID = optarg; U_flag = 1; open_flag = EXT2_FLAG_RW | EXT2_FLAG_JOURNAL_DEV_OK; break; default: bb_show_usage(); } if (optind < argc - 1 || optind == argc) bb_show_usage(); if (!open_flag && !l_flag) bb_show_usage(); io_options = strchr(argv[optind], '?'); if (io_options) *io_options++ = 0; device_name = x_blkid_get_devname(argv[optind]);}#ifdef CONFIG_FINDFSstatic ATTRIBUTE_NORETURN void do_findfs(int argc, char **argv){ if ((argc != 2) || (strncmp(argv[1], "LABEL=", 6) && strncmp(argv[1], "UUID=", 5))) bb_show_usage(); device_name = x_blkid_get_devname(argv[1]); puts(device_name); exit(0);}#else#define do_findfs(x, y)#endifstatic void tune2fs_clean_up(void){ if (ENABLE_FEATURE_CLEAN_UP && device_name) free(device_name); if (ENABLE_FEATURE_CLEAN_UP && journal_device) free(journal_device);}int tune2fs_main(int argc, char **argv);int tune2fs_main(int argc, char **argv){ errcode_t retval; ext2_filsys fs; struct ext2_super_block *sb; io_manager io_ptr; if (ENABLE_FEATURE_CLEAN_UP) atexit(tune2fs_clean_up); if (ENABLE_FINDFS && (applet_name[0] == 'f')) /* findfs */ do_findfs(argc, argv); /* no return */ else if (ENABLE_E2LABEL && (applet_name[0] == 'e')) /* e2label */ parse_e2label_options(argc, argv); else parse_tune2fs_options(argc, argv); /* tune2fs */ io_ptr = unix_io_manager; retval = ext2fs_open2(device_name, io_options, open_flag, 0, 0, io_ptr, &fs); if (retval) bb_error_msg_and_die("No valid superblock on %s", device_name); sb = fs->super; if (print_label) { /* For e2label emulation */ printf("%.*s\n", (int) sizeof(sb->s_volume_name), sb->s_volume_name); return 0; } retval = ext2fs_check_if_mounted(device_name, &mount_flags); if (retval) bb_error_msg_and_die("cannot determine if %s is mounted", device_name); /* Normally we only need to write out the superblock */ fs->flags |= EXT2_FLAG_SUPER_ONLY; if (c_flag) { sb->s_max_mnt_count = max_mount_count; ext2fs_mark_super_dirty(fs); printf("Setting maximal mount count to %d\n", max_mount_count); } if (C_flag) { sb->s_mnt_count = mount_count; ext2fs_mark_super_dirty(fs); printf("Setting current mount count to %d\n", mount_count); } if (e_flag) { sb->s_errors = errors; ext2fs_mark_super_dirty(fs); printf("Setting error behavior to %d\n", errors); } if (g_flag) { sb->s_def_resgid = resgid; ext2fs_mark_super_dirty(fs); printf("Setting reserved blocks gid to %lu\n", resgid); } if (i_flag) { sb->s_checkinterval = interval; ext2fs_mark_super_dirty(fs); printf("Setting interval between check %lu seconds\n", interval); } if (m_flag) { sb->s_r_blocks_count = (sb->s_blocks_count / 100) * reserved_ratio; ext2fs_mark_super_dirty(fs); printf("Setting reserved blocks percentage to %u (%u blocks)\n", reserved_ratio, sb->s_r_blocks_count); } if (r_flag) { if (reserved_blocks >= sb->s_blocks_count/2) bb_error_msg_and_die("reserved blocks count is too big (%lu)", reserved_blocks); sb->s_r_blocks_count = reserved_blocks; ext2fs_mark_super_dirty(fs); printf("Setting reserved blocks count to %lu\n", reserved_blocks); } if (s_flag == 1) { if (sb->s_feature_ro_compat & EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) bb_error_msg("\nThe filesystem already has sparse superblocks"); else { sb->s_feature_ro_compat |= EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; sb->s_state &= ~EXT2_VALID_FS; ext2fs_mark_super_dirty(fs); printf("\nSparse superblock flag set. %s", please_fsck); } } if (s_flag == 0) { if (!(sb->s_feature_ro_compat & EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) bb_error_msg("\nThe filesystem already has sparse superblocks disabled"); else { sb->s_feature_ro_compat &= ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; sb->s_state &= ~EXT2_VALID_FS; fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; ext2fs_mark_super_dirty(fs); printf("\nSparse superblock flag cleared. %s", please_fsck); } } if (T_flag) { sb->s_lastcheck = last_check_time; ext2fs_mark_super_dirty(fs); printf("Setting time filesystem last checked to %s\n", ctime(&last_check_time)); } if (u_flag) { sb->s_def_resuid = resuid; ext2fs_mark_super_dirty(fs); printf("Setting reserved blocks uid to %lu\n", resuid); } if (L_flag) { if (strlen(new_label) > sizeof(sb->s_volume_name)) bb_error_msg("Warning: label too long, truncating"); memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name)); safe_strncpy(sb->s_volume_name, new_label, sizeof(sb->s_volume_name)); ext2fs_mark_super_dirty(fs); } if (M_flag) { memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted)); safe_strncpy(sb->s_last_mounted, new_last_mounted, sizeof(sb->s_last_mounted)); ext2fs_mark_super_dirty(fs); } if (mntopts_cmd) update_mntopts(fs, mntopts_cmd); if (features_cmd) update_feature_set(fs, features_cmd); if (journal_size || journal_device) add_journal(fs); if (U_flag) { if ((strcasecmp(new_UUID, "null") == 0) || (strcasecmp(new_UUID, "clear") == 0)) { uuid_clear(sb->s_uuid); } else if (strcasecmp(new_UUID, "time") == 0) { uuid_generate_time(sb->s_uuid); } else if (strcasecmp(new_UUID, "random") == 0) { uuid_generate(sb->s_uuid); } else if (uuid_parse(new_UUID, sb->s_uuid)) { bb_error_msg_and_die("Invalid UUID format"); } ext2fs_mark_super_dirty(fs); } if (l_flag) list_super (sb); return (ext2fs_close (fs) ? 1 : 0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -