⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tune.c

📁 reiserfsprogs-3.6.19.tar.gz 源码 给有需要的人!
💻 C
📖 第 1 页 / 共 2 页
字号:
	    /* long-only optins */	    if (flag == OPT_NEW_J) {		Options |= OPT_NEW_J;		j_new_device_name = optarg;	    }	    if (flag == OPT_SKIP_J) {		Options |= OPT_SKIP_J;	    }	    if (flag == OPT_STANDARD) {		Options |=OPT_STANDARD;	    } 	    break;	case 'j': /* --journal-device */	    jdevice_name = optarg;	    break;	case 's': /* --journal-new-size */	    set_journal_device_size (optarg);	    Is_journal_or_maxtrans_size_specified = 1;	    break;	    	case 't': /* --trans-max-size */	    set_transaction_max_size (optarg);	    Is_journal_or_maxtrans_size_specified = 1;	    break;	    	case 'o': /* --offset */	    set_offset_in_journal_device (optarg);	    break;	    	case 'f':	    /* forces replacing standard journal with non-standard	       one. Specified more than once - allows to avoid asking for	       confirmation */	    Force ++;	    break;	case 'b': /* --add-badblocks */	    asprintf (&badblocks_file, "%s", optarg);	    Bads = 1;	    break;	case 'B': /* --badblocks */	    asprintf (&badblocks_file, "%s", optarg);	    Bads = 2;	    break;	case 'u':	    /* UUID */#if defined(HAVE_LIBUUID) && defined(HAVE_UUID_UUID_H)	    if (!strcmp(optarg, "random")) {		uuid_generate(UUID);	    } else {		if (uuid_parse(optarg, UUID) < 0) {		    message ("Invalid UUID '%s' was specified\n", optarg);		    return 1;		}	    }#else	    message ("Cannot set the UUID, uuidlib was not found "		     "by configure.\n");	    return 1;#endif            break;	case 'l':	    /* LABEL */	    LABEL = optarg;            break;	case 'V':	    print_banner("reiserfstune");	    exit(0);#if 0	case 'J': /* --journal-new-device */	    Options |= OPT_NEW_J;	    j_new_device_name = optarg;	    break;	case 'u':  /* --no-journal-available */	    Options |= OPT_SKIPJ;	    break;	case 'p':  /* --keep-old-journal-param */	    Options |= OPT_KEEPO;	    break;#endif    	default:	    print_usage_and_exit();	}    }        if (optind != argc - 1)	print_usage_and_exit ();    /* device to be formatted */    device_name = argv [optind];    fs = reiserfs_open (device_name, O_RDONLY, 0, NULL, 1);    if (no_reiserfs_found(fs)) {	message ("Cannot open reiserfs on %s", device_name);        return 1;    }    /* journal was opened or it wasn't opened but the option       --no-journal-available has been specified by user */    /* make sure filesystem is not mounted */    if (misc_device_mounted(fs->fs_file_name) > 0) {	/* fixme: it can not be mounted, btw */        message ("Reiserfstune is not allowed to be run on mounted filesystem.");	reiserfs_close (fs);        return 1;    }        if (!reiserfs_is_fs_consistent (fs)) {	message ("Filesystem looks not cleanly umounted, check the consistency first.\n");	reiserfs_close (fs);	return 1;    }    reiserfs_reopen (fs, O_RDWR);        if (badblocks_file) {	add_badblocks(fs);		reiserfs_close(fs);	exit(0);    }        if (!jdevice_name && !(Options & OPT_SKIP_J)) {	message ("Journal device has not been specified. Assuming journal is on the main "	    "device (%s).\n", device_name);        jdevice_name = device_name;    }    if (jdevice_name && (Options & OPT_SKIP_J)) {	message ("Either specify journal device, "		 "or choose the option --no-journal-available");	return 1;    }        if (j_new_device_name && (Options & OPT_STANDARD)) {	/* New device was specified and --make-journal-standard was also. */	message ("Either specify new journal device, "		 "or choose the option --make-journal-standard");	return 1;    }        /* now we try to open journal, it makes sence if there is no the flag       NEED_TUNE  in ondisk superblock and --no-journal available is not        specified. */    if (get_jp_journal_magic(sb_jp(fs->fs_ondisk_sb)) != NEED_TUNE && 	!(Options & OPT_SKIP_J))     {	if (reiserfs_open_journal (fs, jdevice_name, O_RDWR #if defined(O_LARGEFILE)				   | O_LARGEFILE#endif				   )) 	{	    message ("Failed to open the journal device (%s).", jdevice_name);	    return 1;	}	if (reiserfs_journal_params_check(fs)) {	    message ("Unable to open old journal. Wrong journal parameters.");	    reiserfs_close (fs);	    return 1;	}    }        /* in spite of journal was opened, the file system can be non-consistent or       there are non-replayed transaction in journal,        make sure it isn't (if there is no the flag NEED_TUNE in ondisk superblock */    if (get_jp_journal_magic(sb_jp(fs->fs_ondisk_sb)) != NEED_TUNE &&	reiserfs_journal_opened (fs)) {	j_head = (struct reiserfs_journal_header *)(fs->fs_jh_bh->b_data);	if (get_boundary_transactions(fs, &old, &new)) {	    if (new.trans_id != get_jh_last_flushed(j_head)) {		message ("There are non-replayed transaction in old journal,"			 " check filesystem consistency first");		reiserfs_close (fs);		return 1;	    }	}	if (!reiserfs_is_fs_consistent (fs)) {	    message ("Check filesystem consistency first");	    reiserfs_close (fs);	    return 1;	}     }    /* set UUID and LABEL if specified */    if (fs->fs_format == REISERFS_FORMAT_3_6) {#if defined(HAVE_LIBUUID) && defined(HAVE_UUID_UUID_H)        if (!uuid_is_null(UUID)) {	    memcpy (fs->fs_ondisk_sb->s_uuid, UUID, 16);	    mark_buffer_dirty (fs->fs_super_bh);	    fs->fs_dirt = 1;	}#endif		if (LABEL != NULL) {	    if (strlen (LABEL) > 16)	        message ("Specified LABEL is longer then 16 characters, will be truncated\n");	    strncpy (fs->fs_ondisk_sb->s_label, LABEL, 16);	    mark_buffer_dirty (fs->fs_super_bh);	    fs->fs_dirt = 1;	}    } else {#if defined(HAVE_LIBUUID) && defined(HAVE_UUID_UUID_H)        if (!uuid_is_null(UUID))            reiserfs_exit (1, "UUID cannot be specified for 3.5 format\n");#endif        if (LABEL)            reiserfs_exit (1, "LABEL cannot be specified for 3.5 format\n");    }    if (!j_new_device_name) {		/* new journal device hasn't been specified */	printf ("Current parameters:\n");	print_filesystem_state (stdout, fs);	print_block (stdout, fs, fs->fs_super_bh);	if ((Options & OPT_STANDARD)	    && should_make_journal_standard(fs, j_new_device_name)) 	{	    if (!user_confirmed (stderr, "ATTENTION! Filesystem with "		"non-standard journal found. Continue? (y/n):", "y\n")) 	    {		exit(1);	    }	    fs->fs_journal_dev = fs->fs_dev;	    if (set_standard_journal_params (fs)) {		printf ("\nNew parameters:\n");		print_filesystem_state (stdout, fs);		print_block (stdout, fs, fs->fs_super_bh);		printf ("New journal parameters:\n");		print_journal_params (stdout, sb_jp (fs->fs_ondisk_sb));		mark_buffer_dirty (fs->fs_super_bh);		mark_buffer_uptodate (fs->fs_super_bh, 1);		reiserfs_close (fs);		printf ("Syncing.."); fflush (stdout);		sync ();		printf ("ok\n");		return 0;	    }	}		if (Is_journal_or_maxtrans_size_specified) {	    /* new journal device hasn't been specified, but	       journal size or max transaction size have been, so we suppose	       that journal device remains the same */	    if (!reiserfs_journal_opened (fs)) {		message("Cannot set up new paramenters for not specified journal.");		return 1;	    }		    j_new_device_name = jdevice_name;	} else {		    /* the only parameter has been specified is device_name, so	       there is nothing to do */	    reiserfs_close (fs);	    return 0;	}    }		        /* new journal device has been specified */    /* make sure new journal device is block device file */    if (!can_we_format_it (j_new_device_name, Force)) {	reiserfs_close (fs);        return 1;    }    if (!strcmp (device_name, j_new_device_name)) {	unsigned long reserved, journal_size;	/* we have to put journal on main device. It is only possible if there	   is enough space reserved by mkreiserfs */	if (!is_reiserfs_jr_magic_string (fs->fs_ondisk_sb))	    /* standard journal */	    reserved = get_jp_journal_size(sb_jp(fs->fs_ondisk_sb)) + 1;	else	    /* non-standard journal */	    reserved = get_sb_reserved_for_journal (fs->fs_ondisk_sb);			journal_size = Journal_size;		if (!journal_size) {	    journal_size = journal_default_size(fs->fs_super_bh->b_blocknr, fs->fs_blocksize) + 1;	    message("Journal size has not been specified. Assuming it is the default size (%lu)", 		journal_size);	}	/*	journal_size = (Journal_size ? Journal_size : // specified			(fs->fs_blocksize == 1024 ? (fs->fs_blocksize) * 8 - 3 -			 REISERFS_DISK_OFFSET_IN_BYTES / fs->fs_blocksize :			 JOURNAL_DEFAULT_SIZE + 1));	// default*/	if (journal_size + Offset > get_journal_start_must (fs) + reserved) {		message ("There is no enough space reserved for journal on main "			 "device (journal_size=%lu, reserved=%lu)\n", journal_size,			 reserved);	    reiserfs_close (fs);	    return 1;	}    }    message ("Current journal parameters:");    print_journal_params (stdout, sb_jp (fs->fs_ondisk_sb));    if (!is_reiserfs_jr_magic_string (fs->fs_ondisk_sb)) {	/* we have standard journal, so check if we can convert it	   to non-standard one */		/*	if (!should_make_journal_non_standard (Force)) {	    reiserfs_close (fs);	    return 1;	}	*/	        if (is_reiserfs_3_6_magic_string (fs->fs_ondisk_sb))	    set_sb_version (fs->fs_ondisk_sb, REISERFS_FORMAT_3_6);        else if (is_reiserfs_3_5_magic_string (fs->fs_ondisk_sb))	    set_sb_version (fs->fs_ondisk_sb, REISERFS_FORMAT_3_5);        else {            message ("Could not convert from unknown version, try reiserfsck first");	    reiserfs_close (fs);            return 1;        }        	memcpy (fs->fs_ondisk_sb->s_v1.s_magic, REISERFS_JR_SUPER_MAGIC_STRING,		strlen (REISERFS_JR_SUPER_MAGIC_STRING));	set_sb_reserved_for_journal (fs->fs_ondisk_sb,		get_jp_journal_size (sb_jp(fs->fs_ondisk_sb)) + 1);    }    /* now we are going to close old journal and to create a new one */    reiserfs_close_journal (fs);    if (!reiserfs_create_journal (fs, j_new_device_name, Offset,				  Journal_size, Max_trans_size)) {	message ("Could not create new journal");	reiserfs_close (fs);        return 1;    }    if (should_make_journal_standard (fs, j_new_device_name))	set_standard_journal_params (fs);    message ("New journal parameters:");    print_journal_params (stdout, sb_jp (fs->fs_ondisk_sb));    print_block (stdout, fs, fs->fs_super_bh);    if (Force < 2) {        message ("ATTENTION: YOU ARE ABOUT TO SETUP THE NEW JOURNAL FOR THE \"%s\"!\n"                 "AREA OF \"%s\" DEDICATED FOR JOURNAL WILL BE ZEROED!",		 device_name, j_new_device_name);                if (!user_confirmed (stderr, "Continue (y/n):", "y\n")) {            return 1;	}    }    zero_journal (fs);        reiserfs_close (fs);        printf ("Syncing.."); fflush (stdout);    sync ();    printf ("ok\n");    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -