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

📄 unpack.c

📁 reiserfsprogs-3.6.19.tar.gz 源码 给有需要的人!
💻 C
📖 第 1 页 / 共 2 页
字号:
	fread32 (&v32);	if (v32 != ITEM_START_MAGIC)	    die ("unpack_leaf: no start item magic found: block %lu, item %i",		 bh->b_blocknr, i);#endif		fread (&pi, sizeof (struct packed_item), 1, stdin);		/* dir_id - if it is there */	if (get_pi_mask(&pi) & DIR_ID) {	    fread32 (&v32);            set_key_dirid (&ih->ih_key, le32_to_cpu(v32));	} else {	    if (!i)		die ("unpack_leaf: dir_id is not set");	    set_key_dirid (&ih->ih_key, get_key_dirid (&(ih - 1)->ih_key));	}	/* object_id - if it is there */	if (get_pi_mask(&pi) & OBJECT_ID) {	    fread32 (&v32);            set_key_objectid (&ih->ih_key, le32_to_cpu(v32));	} else {	    if (!i)		die ("unpack_leaf: object_id is not set");	    set_key_objectid (&ih->ih_key, get_key_objectid (&(ih - 1)->ih_key));	}	// we need to set item format before offset unpacking	set_ih_key_format (ih, (get_pi_mask(&pi) & NEW_FORMAT) ? KEY_FORMAT_2 : KEY_FORMAT_1);	// offset	unpack_offset (&pi, ih, bh->b_size);	/* type */	unpack_type (&pi, ih);	/* ih_free_space and ih_format */	if (get_pi_mask(&pi) & IH_FREE_SPACE) {	    fread16 (&v16);	    set_ih_entry_count (ih, le16_to_cpu(v16));	}	if (get_pi_mask(&pi) & IH_FORMAT)	    fread16 (&ih->ih_format);	/* item length and item location */	set_ih_item_len (ih, get_pi_item_len(&pi));	set_ih_location (ih, (i ? get_ih_location (ih - 1) : bh->b_size) - get_pi_item_len(&pi));	// item itself	if (is_direct_ih (ih)) {	    unpack_direct (&pi, bh, ih);	} else if (is_indirect_ih (ih)) {	    unpack_indirect (&pi, bh, ih);	} else if (is_direntry_ih (ih)) {	    unpack_direntry (&pi, bh, ih, hash_func);	} else if (is_stat_data_ih (ih)) {	    unpack_stat_data (&pi, bh, ih);	}	set_blkh_free_space (B_BLK_HEAD (bh), get_blkh_free_space (B_BLK_HEAD (bh)) -			     (IH_SIZE + get_ih_item_len (ih)));#if 0	fread32 (&v32);	if (v32 != ITEM_END_MAGIC)	    die ("unpack_leaf: no end item magic found: block %lu, item %i",		 bh->b_blocknr, i);	if (verbose)	    reiserfs_warning (stderr, "%d: %H\n", i, ih);#endif    }    fread_le16 (&v16);    if (v16 != LEAF_END_MAGIC)	die ("unpack_leaf: wrong end signature found - %x, block %lu", 	     v16, bh->b_blocknr);    mark_buffer_uptodate (bh, 1);    mark_buffer_dirty (bh);    bwrite (bh);    /*    if (!not_data_block (bh->b_blocknr))	data_blocks_unpacked ++;    */    brelse (bh);    if (what_unpacked)	reiserfs_bitmap_set_bit (what_unpacked, bh->b_blocknr);    /*unpacked ++;*/    if (!(++ unpacked_leaves % 10))	fprintf (stderr, "#");}static void unpack_full_block (int dev, int blocksize){    static int full_blocks_unpacked = 0;    __u32 block;    struct buffer_head * bh;    fread_le32 (&block);    if (verbose)	fprintf (stderr, "full #%d\n", block);    bh = getblk (dev, block, blocksize);    if (!bh)	die ("unpack_full_block: getblk failed");    fread (bh->b_data, bh->b_size, 1, stdin);    if (who_is_this (bh->b_data, bh->b_size) == THE_SUPER && !what_unpacked) {	unsigned long blocks;	struct buffer_head * tmp;		blocks = get_sb_block_count ((struct reiserfs_super_block *)(bh->b_data));	fprintf (stderr, "There were %lu blocks on the device\n", blocks);	what_unpacked = reiserfs_create_bitmap (blocks);	/* make file as long as filesystem is */	tmp = getblk (dev, blocks - 1, blocksize);	mark_buffer_dirty (tmp);	mark_buffer_uptodate (tmp, 0);	bwrite (tmp);	brelse (tmp);    }    mark_buffer_uptodate (bh, 1);    mark_buffer_dirty (bh);    bwrite (bh);/*    if (!not_data_block (bh->b_blocknr))	data_blocks_unpacked ++;*/    brelse (bh);    if (what_unpacked)	reiserfs_bitmap_set_bit (what_unpacked, block);    /*unpacked ++;*/    if (!(++ full_blocks_unpacked % 50))	fprintf (stderr, ".");}/* just skip bitmaps of unformatted nodes */static void unpack_unformatted_bitmap (int dev, int blocksize){    __u16 bmap_num;    __u32 block_count;    int i;    char * buf;     fread_le16 (&bmap_num);    fread_le32 (&block_count);        buf = malloc (blocksize);    if (!buf)	reiserfs_panic ("unpack_unformatted_bitmap: malloc failed: %m");    for (i = 0; i < bmap_num; i ++) {	if (fread (buf, blocksize, 1, stdin) != 1)	    reiserfs_panic ("unpack_unformatted_bitmap: "			    "could not read bitmap #%d: %m", i);    }    free (buf);}// read packed reiserfs partition metadata from stdinvoid unpack_partition (int fd, int jfd){    __u32 magic32;    long position;    __u16 magic16;    __u16 blocksize;    int dev = fd;        fread_le32 (&magic32);    if (magic32 != REISERFS_SUPER_MAGIC)	die ("unpack_partition: reiserfs magic number (0x%x) not found - %x\n",             REISERFS_SUPER_MAGIC, magic32);        fread_le16 (&blocksize);        if (verbose)	fprintf (stderr, "Blocksize %d\n", blocksize);        while (!feof (stdin)) {	char c[2];	fread (c, 1, 1, stdin);	switch (c[0]) {	case '.':	    if (verbose)		fprintf (stderr, "\".\" skipped\n");	    continue;	case '1':	    fread (c, 1, 1, stdin); /* that was 100%, read in first 0 */	case '2':	case '4':	case '6':	case '8':	    fread (c, 1, 1, stdin);	case '0':	    fread (c + 1, 1, 1, stdin); /* read % */			    if (c[0] != '0' || c[1] != '%')		die ("0%% expected\n");	    if (verbose)		fprintf (stderr, "0%% skipped\n");	    continue;	}	fread (c + 1, 1, 1, stdin);	magic16 = le16_to_cpu(*(__u16 *)c);	/*fread16 (&magic16);*/		switch (magic16 & 0xff) {	case LEAF_START_MAGIC:	    leaves ++;	    unpack_leaf (dev, code2func (magic16 >> 8), blocksize);	    break;	    	case SEPARATED_JOURNAL_START_MAGIC:	    if (Default_journal)		die ("file name for separated journal has to be specified");		    dev = jfd;	    break;    	case SEPARATED_JOURNAL_END_MAGIC:	    dev = fd;	    break;	    	case FULL_BLOCK_START_MAGIC:	    full ++;	    unpack_full_block (dev, blocksize);	    break;	case UNFORMATTED_BITMAP_START_MAGIC:	    fprintf (stderr, "\nBitmap of unformatted - ignored\n");	    unpack_unformatted_bitmap (dev, blocksize);	    break;	    	case END_MAGIC:	    goto out;	default:	    position = ftell(stdin);	    if (position == ~(long)0)		die ("unpack_partition: bad magic found - %x", magic16 & 0xff);	    else		die ("unpack_partition: bad magic found - %x, position %lu", 		    magic16 & 0xff, ftell(stdin));	}    }out:    fprintf (stderr, "Unpacked %d leaves, %d full blocks\n", leaves, full);    /*    fclose (block_list);*/}int do_unpack(char *host, char *j_filename, char *filename, int verbose) {    int fd, fdj = -2;    struct rlimit lim = {RLIM_INFINITY, RLIM_INFINITY};    if (filename == NULL)	    filename = ".bitmap";        if (j_filename)	    Default_journal = 0;        /* with this 2.4.0-test9's file_write does not send SIGXFSZ */    if (setrlimit (RLIMIT_FSIZE, &lim)) {	fprintf  (stderr, "sertlimit failed: %m\n");    }    if (misc_device_mounted(host) > 0) {	fprintf(stderr, "%s seems mounted, umount it first\n", host);	return 0;    }      fd = open (host, O_RDWR | O_LARGEFILE);    if (fd == -1) {	perror ("open failed");	return 0;    }    if (!Default_journal) {	fdj = open (j_filename, O_RDWR | O_LARGEFILE);	if (fdj == -1) {	    perror ("open failed");	    return 0;	}    }    unpack_partition (fd, fdj);    if (what_unpacked && filename) {        FILE * file = open_file(filename, "w+");        reiserfs_bitmap_save (file,  what_unpacked);        close_file(file);    }    close (fd);    if (!Default_journal)	close (fdj);	    return 0;}

⌨️ 快捷键说明

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