Home | History | Annotate | Download | only in genext2fs

Lines Matching refs:fs

21 // 	 6 Jun 2000	Bugfix: fs size multiple of 8
240 #define GRP_NBGROUPS(fs) \
241 (((fs)->sb.s_blocks_count - fs->sb.s_first_data_block + \
242 (fs)->sb.s_blocks_per_group - 1) / (fs)->sb.s_blocks_per_group)
245 #define GRP_GET_GROUP_BBM(fs,grp) ( get_blk((fs),(fs)->gd[(grp)].bg_block_bitmap) )
248 #define GRP_GET_GROUP_IBM(fs,grp) ( get_blk((fs),(fs)->gd[(grp)].bg_inode_bitmap) )
251 #define GRP_GROUP_OF_INODE(fs,nod) ( ((nod)-1) / (fs)->sb.s_inodes_per_group)
254 #define GRP_GET_INODE_BITMAP(fs,nod) \
255 ( GRP_GET_GROUP_IBM((fs),GRP_GROUP_OF_INODE((fs),(nod))) )
258 #define GRP_IBM_OFFSET(fs,nod) \
259 ( (nod) - GRP_GROUP_OF_INODE((fs),(nod))*(fs)->sb.s_inodes_per_group )
262 #define GRP_GROUP_OF_BLOCK(fs,blk) ( ((blk)-1) / (fs)->sb.s_blocks_per_group)
265 #define GRP_GET_BLOCK_BITMAP(fs,blk) \
266 ( GRP_GET_GROUP_BBM((fs),GRP_GROUP_OF_BLOCK((fs),(blk))) )
269 #define GRP_BBM_OFFSET(fs,blk) \
270 ( (blk) - GRP_GROUP_OF_BLOCK((fs),(blk))*(fs)->sb.s_blocks_per_group )
821 get_blk(filesystem *fs, uint32 blk)
823 return (uint8*)fs + blk*BLOCKSIZE;
828 get_nod(filesystem *fs, uint32 nod)
833 offset = GRP_IBM_OFFSET(fs,nod);
834 grp = GRP_GROUP_OF_INODE(fs,nod);
835 itab = (inode *)get_blk(fs, fs->gd[grp].bg_inode_table);
874 alloc_blk(filesystem *fs, uint32 nod)
879 grp = GRP_GROUP_OF_INODE(fs,nod);
880 nbgroups = GRP_NBGROUPS(fs);
881 if(!(bk = allocate(get_blk(fs,fs->gd[grp].bg_block_bitmap), 0))) {
883 bk=allocate(get_blk(fs,fs->gd[grp].bg_block_bitmap),0);
888 if(!(fs->gd[grp].bg_free_blocks_count--))
889 error_msg_and_die("group descr %d. free blocks count == 0 (corrupted fs?)",grp);
890 if(!(fs->sb.s_free_blocks_count--))
891 error_msg_and_die("superblock free blocks count == 0 (corrupted fs?)");
892 return fs->sb.s_blocks_per_group*grp + bk;
897 free_blk(filesystem *fs, uint32 bk)
901 grp = bk / fs->sb.s_blocks_per_group;
902 bk %= fs->sb.s_blocks_per_group;
903 deallocate(get_blk(fs,fs->gd[grp].bg_block_bitmap), bk);
904 fs->gd[grp].bg_free_blocks_count++;
905 fs->sb.s_free_blocks_count++;
910 alloc_nod(filesystem *fs)
915 nbgroups = GRP_NBGROUPS(fs);
920 /* Idea from find_group_dir in fs/ext2/ialloc.c in 2.4.19 kernel */
922 avefreei = fs->sb.s_free_inodes_count / nbgroups;
924 if (fs->gd[grp].bg_free_inodes_count < avefreei ||
925 fs->gd[grp].bg_free_inodes_count == 0)
928 fs->gd[grp].bg_free_blocks_count > fs->gd[best_group].bg_free_blocks_count)
931 if (!(nod = allocate(get_blk(fs,fs->gd[best_group].bg_inode_bitmap),0)))
933 if(!(fs->gd[best_group].bg_free_inodes_count--))
934 error_msg_and_die("group descr. free blocks count == 0 (corrupted fs?)");
935 if(!(fs->sb.s_free_inodes_count--))
936 error_msg_and_die("superblock free blocks count == 0 (corrupted fs?)");
937 return fs->sb.s_inodes_per_group*best_group+nod;
973 walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
980 if(bw->bnum >= get_nod(fs, nod)->i_blocks / INOBLK)
993 bkref = &get_nod(fs, nod)->i_block[bw->bpdir = 0];
995 *bkref = hole ? 0 : alloc_blk(fs,nod);
997 free_blk(fs, *bkref);
1002 bkref = &get_nod(fs, nod)->i_block[++bw->bpdir];
1004 *bkref = hole ? 0 : alloc_blk(fs,nod);
1006 free_blk(fs, *bkref);
1015 get_nod(fs, nod)->i_block[bw->bpdir] = alloc_blk(fs,nod);
1017 free_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
1018 b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
1021 *bkref = hole ? 0 : alloc_blk(fs,nod);
1023 free_blk(fs, *bkref);
1029 b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
1032 *bkref = hole ? 0 : alloc_blk(fs,nod);
1034 free_blk(fs, *bkref);
1044 get_nod(fs, nod)->i_block[bw->bpdir] = alloc_blk(fs,nod);
1046 free_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
1047 b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
1049 b[bw->bpind] = alloc_blk(fs,nod);
1051 free_blk(fs, b[bw->bpind]);
1052 b = (uint32*)get_blk(fs, b[bw->bpind]);
1055 *bkref = hole ? 0 : alloc_blk(fs,nod);
1057 free_blk(fs, *bkref);
1063 b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
1064 b = (uint32*)get_blk(fs, b[bw->bpind]);
1067 *bkref = hole ? 0 : alloc_blk(fs,nod);
1069 free_blk(fs, *bkref);
1077 b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
1079 b[bw->bpind] = alloc_blk(fs,nod);
1081 free_blk(fs, b[bw->bpind]);
1082 b = (uint32*)get_blk(fs, b[bw->bpind]);
1085 *bkref = hole ? 0 : alloc_blk(fs,nod);
1087 free_blk(fs, *bkref);
1102 get_nod(fs, nod)->i_block[bw->bpdir] = alloc_blk(fs,nod);
1104 free_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
1105 b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
1107 b[bw->bpind] = alloc_blk(fs,nod);
1109 free_blk(fs, b[bw->bpind]);
1110 b = (uint32*)get_blk(fs, b[bw->bpind]);
1112 b[bw->bpdind] = alloc_blk(fs,nod);
1114 free_blk(fs, b[bw->bpind]);
1115 b = (uint32*)get_blk(fs, b[bw->bpdind]);
1118 *bkref = hole ? 0 : alloc_blk(fs,nod);
1120 free_blk(fs, *bkref);
1129 b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
1130 b = (uint32*)get_blk(fs, b[bw->bpind]);
1131 b = (uint32*)get_blk(fs, b[bw->bpdind]);
1134 *bkref = hole ? 0 : alloc_blk(fs,nod);
1136 free_blk(fs, *bkref);
1148 b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
1149 b = (uint32*)get_blk(fs, b[bw->bpind]);
1151 b[bw->bpdind] = alloc_blk(fs,nod);
1153 free_blk(fs, b[bw->bpind]);
1154 b = (uint32*)get_blk(fs, b[bw->bpdind]);
1157 *bkref = hole ? 0 : alloc_blk(fs,nod);
1159 free_blk(fs, *bkref);
1171 b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
1173 b[bw->bpind] = alloc_blk(fs,nod);
1175 free_blk(fs, b[bw->bpind]);
1176 b = (uint32*)get_blk(fs, b[bw->bpind]);
1178 b[bw->bpdind] = alloc_blk(fs,nod);
1180 free_blk(fs, b[bw->bpind]);
1181 b = (uint32*)get_blk(fs, b[bw->bpdind]);
1184 *bkref = hole ? 0 : alloc_blk(fs,nod);
1186 free_blk(fs, *bkref);
1195 if(!reduce && !allocated(GRP_GET_BLOCK_BITMAP(fs,*bkref), GRP_BBM_OFFSET(fs,*bkref)))
1199 get_nod(fs, nod)->i_blocks = bw->bnum * INOBLK;
1205 extend_blk(filesystem *fs, uint32 nod, block b, int amount)
1214 for(i = 0; i < get_nod(fs, nod)->i_blocks / INOBLK + amount; i++)
1215 walk_bw(fs, nod, &bw, 0, 0);
1216 while(walk_bw(fs, nod, &bw, &create, 0) != WALK_END)
1218 get_nod(fs, nod)->i_blocks += amount * INOBLK;
1223 while((bk = walk_bw(fs, nod, &bw, 0, 0)) != WALK_END)
1229 if(!(fs->sb.s_reserved[200] & OP_HOLES))
1238 if((bk = walk_bw(fs, nod, &bw, &create, !copyb)) == WALK_END)
1241 memcpy(get_blk(fs, bk), b + BLOCKSIZE * (amount - create - 1), BLOCKSIZE);
1248 add2dir(filesystem *fs, uint32 dnod, uint32 nod, const char* name)
1258 pnode = get_nod(fs, dnod);
1270 while((bk = walk_bw(fs, dnod, &bw, 0, 0)) != WALK_END) // for all blocks in dir
1272 b = get_blk(fs, bk);
1280 node = get_nod(fs, nod);
1295 node = get_nod(fs, nod);
1308 node = get_nod(fs, nod);
1313 extend_blk(fs, dnod, b, 1);
1314 get_nod(fs, dnod)->i_size += BLOCKSIZE;
1320 find_dir(filesystem *fs, uint32 nod, const char * name)
1326 while((bk = walk_bw(fs, nod, &bw, 0, 0)) != WALK_END)
1330 b = get_blk(fs, bk);
1340 find_path(filesystem *fs, uint32 nod, const char * name)
1353 if(!(nod = find_dir(fs, nod, n)))
1366 chmod_fs(filesystem *fs, uint32 nod, uint16 mode, uint16 uid, uint16 gid)
1369 node = get_nod(fs, nod);
1377 mknod_fs(filesystem *fs, uint32 parent_nod, const char *name, uint16 mode, uint16 uid, uint16 gid, uint8 major, uint8 minor, uint32 ctime, uint32 mtime)
1382 nod = alloc_nod(fs);
1383 node = get_nod(fs, nod);
1385 add2dir(fs, parent_nod, nod, name);
1393 ((uint8*)get_nod(fs, nod)->i_block)[0] = minor;
1394 ((uint8*)get_nod(fs, nod)->i_block)[1] = major;
1397 add2dir(fs, nod, nod, ".");
1398 add2dir(fs, nod, parent_nod, "..");
1399 fs->gd[GRP_GROUP_OF_INODE(fs,nod)].bg_used_dirs_count++;
1413 mkdir_fs(filesystem *fs, uint32 parent_nod, const char *name, uint32 mode,
1416 return mknod_fs(fs, parent_nod, name, mode|FM_IFDIR, uid, gid, 0, 0, ctime, mtime);
1421 mklink_fs(filesystem *fs, uint32 parent_nod, const char *name, size_t size, uint8 *b, uid_t uid, gid_t gid, uint32 ctime, uint32 mtime)
1423 uint32 nod = mknod_fs(fs, parent_nod, name, FM_IFLNK | FM_IRWXU | FM_IRWXG | FM_IRWXO, uid, gid, 0, 0, ctime, mtime);
1424 extend_blk(fs, nod, 0, - (int)get_nod(fs, nod)->i_blocks / INOBLK);
1425 get_nod(fs, nod)->i_size = size;
1428 strncpy((char*)get_nod(fs, nod)->i_block, (char*)b, size);
1431 extend_blk(fs, nod, b, rndup(size, BLOCKSIZE) / BLOCKSIZE);
1437 mkfile_fs(filesystem *fs, uint32 parent_nod, const char *name, uint32 mode, size_t size, FILE *f, uid_t uid, gid_t gid, uint32 ctime, uint32 mtime)
1440 uint32 nod = mknod_fs(fs, parent_nod, name, mode|FM_IFREG, uid, gid, 0, 0, ctime, mtime);
1441 extend_blk(fs, nod, 0, - (int)get_nod(fs, nod)->i_blocks / INOBLK);
1442 get_nod(fs, nod)->i_size = size;
1448 extend_blk(fs, nod, b, rndup(size, BLOCKSIZE) / BLOCKSIZE);
1507 add2fs_from_file(filesystem *fs, uint32 this_nod, FILE * fh, uint32 fs_timestamp, struct stats *stats)
1553 if(fs)
1555 if(!(nod = find_path(fs, this_nod, dir)))
1604 oldnod = find_dir(fs, nod, dname);
1606 chmod_fs(fs, oldnod, mode, uid, gid);
1608 mknod_fs(fs, nod, dname, mode, uid, gid, major, minor + (i * increment - start), ctime, mtime);
1614 uint32 oldnod = find_dir(fs, nod, name);
1616 chmod_fs(fs, oldnod, mode, uid, gid);
1618 mknod_fs(fs, nod, name, mode, uid, gid, major, minor, ctime, mtime);
1655 add2fs_from_dir(filesystem *fs, const char *path, uint32 this_nod, int squash_uids, int squash_perms, int fixstats, uint32 fs_timestamp, struct stats *stats)
1712 add2fs_from_dir(fs, full_name, this_nod, squash_uids, squash_perms, fixstats, fs_timestamp, stats);
1720 if((nod = find_dir(fs, this_nod, name)))
1726 add2fs_from_dir(fs, full_name, nod, squash_uids, squash_perms, fixstats, fs_timestamp, stats);
1736 add2dir(fs, this_nod, hdlinks.hdl[hdlink].dst_nod, name);
1746 nod = mknod_fs(fs, this_nod, name, mode|FM_IFCHR, uid, gid, major(st.st_rdev), minor(st.st_rdev), ctime, mtime);
1749 nod = mknod_fs(fs, this_nod, name, mode|FM_IFBLK, uid, gid, major(st.st_rdev), minor(st.st_rdev), ctime, mtime);
1753 nod = mknod_fs(fs, this_nod, name, mode|FM_IFIFO, uid, gid, 0, 0, ctime, mtime);
1756 nod = mknod_fs(fs, this_nod, name, mode|FM_IFSOCK, uid, gid, 0, 0, ctime, mtime);
1760 mklink_fs(fs, this_nod, name, st.st_size, (uint8*)lnk, uid, gid, ctime, mtime);
1765 nod = mkfile_fs(fs, this_nod, name, mode, st.st_size, fh, uid, gid, ctime, mtime);
1769 nod = mkdir_fs(fs, this_nod, name, mode, uid, gid, ctime, mtime);
1772 add2fs_from_dir(fs, full_name, nod, squash_uids, squash_perms, fixstats, fs_timestamp, stats);
1798 swap_goodblocks(filesystem *fs, inode *nod)
1810 swap_block(get_blk(fs, nod->i_block[EXT2_IND_BLOCK]));
1829 swap_block(get_blk(fs, ((uint32*)get_blk(fs, nod->i_block[EXT2_DIND_BLOCK]))[i]));
1830 swap_block(get_blk(fs, nod->i_block[EXT2_DIND_BLOCK]));
1834 b = (uint32*)get_blk(fs,nod->i_block[EXT2_TIND_BLOCK]);
1836 b2 = (uint32*)get_blk(fs,b[i]);
1842 swap_block(get_blk(fs,b2[j]));
1855 swap_badblocks(filesystem *fs, inode *nod)
1867 swap_block(get_blk(fs, nod->i_block[EXT2_IND_BLOCK]));
1872 swap_block(get_blk(fs, nod->i_block[EXT2_DIND_BLOCK]));
1875 swap_block(get_blk(fs, ((uint32*)get_blk(fs, nod->i_block[EXT2_DIND_BLOCK]))[i]));
1879 b = (uint32*)get_blk(fs,nod->i_block[EXT2_TIND_BLOCK]);
1882 b2 = (uint32*)get_blk(fs,b[i]);
1889 swap_block(get_blk(fs,b2[j]));
1901 swap_goodfs(filesystem *fs)
1904 for(i = 1; i < fs->sb.s_inodes_count; i++)
1906 inode *nod = get_nod(fs, i);
1912 while((bk = walk_bw(fs, i, &bw, 0, 0)) != WALK_END)
1916 b = get_blk(fs, bk);
1921 swap_goodblocks(fs, nod);
1924 for(i=0;i<GRP_NBGROUPS(fs);i++)
1925 swap_gd(&(fs->gd[i]));
1926 swap_sb(&fs->sb);
1930 swap_badfs(filesystem *fs)
1933 swap_sb(&fs->sb);
1934 for(i=0;i<GRP_NBGROUPS(fs);i++)
1935 swap_gd(&(fs->gd[i]));
1936 for(i = 1; i < fs->sb.s_inodes_count; i++)
1938 inode *nod = get_nod(fs, i);
1940 swap_badblocks(fs, nod);
1946 while((bk = walk_bw(fs, i, &bw, 0, 0)) != WALK_END)
1950 b = get_blk(fs, bk);
1963 filesystem *fs;
2006 if(!(fs = (filesystem*)calloc(nbblocks, BLOCKSIZE)))
2010 fs->sb.s_inodes_count = nbinodes_per_group * nbgroups;
2011 fs->sb.s_blocks_count = nbblocks;
2012 fs->sb.s_r_blocks_count = nbresrvd;
2013 fs->sb.s_free_blocks_count = free_blocks;
2014 fs->sb.s_free_inodes_count = fs->sb.s_inodes_count - EXT2_FIRST_INO + 1;
2015 fs->sb.s_first_data_block = first_block;
2016 fs->sb.s_log_block_size = BLOCKSIZE >> 11;
2017 fs->sb.s_log_frag_size = BLOCKSIZE >> 11;
2018 fs->sb.s_blocks_per_group = nbblocks_per_group;
2019 fs->sb.s_frags_per_group = nbblocks_per_group;
2020 fs->sb.s_inodes_per_group = nbinodes_per_group;
2021 fs->sb.s_wtime = fs_timestamp;
2022 fs->sb.s_magic = EXT2_MAGIC_NUMBER;
2023 fs->sb.s_lastcheck = fs_timestamp;
2031 fs->gd[i].bg_free_blocks_count = free_blocks_per_group;
2034 fs->gd[i].bg_free_blocks_count = free_blocks;
2038 fs->gd[i].bg_free_inodes_count = nbinodes_per_group;
2040 fs->gd[i].bg_free_inodes_count = nbinodes_per_group -
2042 fs->gd[i].bg_used_dirs_count = 0;
2043 fs->gd[i].bg_block_bitmap = bbmpos;
2044 fs->gd[i].bg_inode_bitmap = ibmpos;
2045 fs->gd[i].bg_inode_table = itblpos;
2053 bbm = get_blk(fs,fs->gd[i].bg_block_bitmap);
2055 for(j = fs->gd[i].bg_free_blocks_count
2063 ibm = get_blk(fs,fs->gd[i].bg_inode_bitmap);
2065 for(j = fs->sb.s_inodes_per_group+1; j <= BLOCKSIZE * 8; j++)
2077 fs->gd[0].bg_free_inodes_count--;
2078 fs->gd[0].bg_used_dirs_count = 1;
2079 itab0 = (inode *)get_blk(fs,fs->gd[0].bg_inode_table);
2099 extend_blk(fs, EXT2_ROOT_INO, b, 1);
2102 if(fs->sb.s_r_blocks_count)
2104 nod = mkdir_fs(fs, EXT2_ROOT_INO, "lost+found", FM_IRWXU, 0, 0, fs_timestamp, fs_timestamp);
2110 if (fs->sb.s_r_blocks_count > fs->sb.s_blocks_count * MAX_RESERVED_BLOCKS )
2111 fs->sb.s_r_blocks_count = fs->sb.s_blocks_count * MAX_RESERVED_BLOCKS;
2112 for(i = 1; i < fs->sb.s_r_blocks_count; i++)
2113 extend_blk(fs, nod, b, 1);
2114 get_nod(fs, nod)->i_size = fs->sb.s_r_blocks_count * BLOCKSIZE;
2119 fs->sb.s_state = 1;
2120 fs->sb.s_max_mnt_count = 20;
2124 fs->sb.s_reserved[200] |= OP_HOLES;
2126 return fs;
2134 filesystem *fs;
2141 if(!(fs = (filesystem*)calloc(fssize, BLOCKSIZE)))
2143 if(fread(fs, BLOCKSIZE, fssize, fh) != fssize)
2146 swap_badfs(fs);
2147 if(fs->sb.s_rev_level || (fs->sb.s_magic != EXT2_MAGIC_NUMBER))
2149 return fs;
2153 free_fs(filesystem *fs)
2155 free(fs);
2160 flist_blocks(filesystem *fs, uint32 nod, FILE *fh)
2165 while((bk = walk_bw(fs, nod, &bw, 0, 0)) != WALK_END)
2172 list_blocks(filesystem *fs, uint32 nod)
2179 while((bk = walk_bw(fs, nod, &bw, 0, 0)) != WALK_END)
2186 write_blocks(filesystem *fs, uint32 nod, FILE* f)
2190 int32 fsize = get_nod(fs, nod)->i_size;
2192 while((bk = walk_bw(fs, nod, &bw, 0, 0)) != WALK_END)
2196 if(fwrite(get_blk(fs, bk), (fsize > BLOCKSIZE) ? BLOCKSIZE : fsize, 1, f) != 1)
2205 print_dev(filesystem *fs, uint32 nod)
2208 minor = ((uint8*)get_nod(fs, nod)->i_block)[0];
2209 major = ((uint8*)get_nod(fs, nod)->i_block)[1];
2215 print_dir(filesystem *fs, uint32 nod)
2221 while((bk = walk_bw(fs, nod, &bw, 0, 0)) != WALK_END)
2225 b = get_blk(fs, bk);
2240 print_link(filesystem *fs, uint32 nod)
2242 if(!get_nod(fs, nod)->i_blocks)
2243 printf("links to '%s'\n", (char*)get_nod(fs, nod)->i_block);
2247 write_blocks(fs, nod, stdout);
2314 print_inode(filesystem *fs, uint32 nod)
2318 if(!get_nod(fs, nod)->i_mode)
2341 printf("inode %d (%s, %d links): ", nod, s, get_nod(fs, nod)->i_links_count);
2342 if(!allocated(GRP_GET_INODE_BITMAP(fs,nod), GRP_IBM_OFFSET(fs,nod)))
2347 make_perms(get_nod(fs, nod)->i_mode, perms);
2348 printf("%s, size: %d byte%s (%d block%s)\n", perms, plural(get_nod(fs, nod)->i_size), plural(get_nod(fs, nod)->i_blocks / INOBLK));
2349 switch(get_nod(fs, nod)->i_mode & FM_IFMT)
2352 list_blocks(fs, nod);
2355 print_link(fs, nod);
2358 list_blocks(fs, nod);
2361 print_dev(fs, nod);
2364 list_blocks(fs, nod);
2365 print_dir(fs, nod);
2368 print_dev(fs, nod);
2371 list_blocks(fs, nod);
2374 list_blocks(fs, nod);
2381 print_fs(filesystem *fs)
2387 fs->sb.s_blocks_count, fs->sb.s_free_blocks_count,
2388 fs->sb.s_r_blocks_count, fs->sb.s_first_data_block);
2389 printf("%d inodes (%d free)\n", fs->sb.s_inodes_count,
2390 fs->sb.s_free_inodes_count);
2392 fs->sb.s_log_block_size ? (fs->sb.s_log_block_size << 11) : 1024,
2393 fs->sb.s_log_frag_size ? (fs->sb.s_log_frag_size << 11) : 1024);
2394 printf("number of groups: %d\n",GRP_NBGROUPS(fs));
2396 fs->sb.s_blocks_per_group, fs->sb.s_frags_per_group,
2397 fs->sb.s_inodes_per_group);
2399 (int)(fs->sb.s_inodes_per_group * sizeof(inode) / BLOCKSIZE));
2400 for (i = 0; i < GRP_NBGROUPS(fs); i++) {
2403 fs->gd[i].bg_block_bitmap, fs->gd[i].bg_inode_bitmap,
2404 fs->gd[i].bg_inode_table);
2406 print_bm(GRP_GET_GROUP_BBM(fs, i),fs->sb.s_blocks_per_group);
2408 ibm = GRP_GET_GROUP_IBM(fs, i);
2409 print_bm(ibm, fs->sb.s_inodes_per_group);
2410 for (i = 1; i <= fs->sb.s_inodes_per_group; i++)
2412 print_inode(fs, i);
2417 dump_fs(filesystem *fs, FILE * fh, int swapit)
2419 uint32 nbblocks = fs->sb.s_blocks_count;
2420 fs->sb.s_reserved[200] = 0;
2422 swap_goodfs(fs);
2423 if(fwrite(fs, BLOCKSIZE, nbblocks, fh) < nbblocks)
2426 swap_badfs(fs);
2430 populate_fs(filesystem *fs, char **dopt, int didx, int squash_uids, int squash_perms, int fixstats, uint32 fs_timestamp, struct stats *stats)
2440 if(fs)
2444 if(!(nod = find_path(fs, EXT2_ROOT_INO, pdest)))
2452 add2fs_from_file(fs, nod, fh, fs_timestamp, stats);
2462 add2fs_from_dir(fs, dopt[i], nod, squash_uids, squash_perms, fixstats, fs_timestamp, stats);
2537 filesystem *fs;
2654 fs = load_fs(fh, bigendian);
2658 fs = load_fs(stdin, bigendian);
2688 fs = init_fs(nbblocks, nbinodes, nbresrvd, holes, fs_timestamp);
2691 populate_fs(fs, dopt, didx, squash_uids, squash_perms, fix_android_stats, fs_timestamp, NULL);
2695 for(b = 1; b < fs->sb.s_blocks_count; b++)
2696 if(!allocated(GRP_GET_BLOCK_BITMAP(fs,b),GRP_BBM_OFFSET(fs,b)))
2697 memset(get_blk(fs, b), emptyval, BLOCKSIZE);
2700 print_fs(fs);
2707 if(!(nod = find_path(fs, EXT2_ROOT_INO, gopt[i])))
2713 fprintf(fh, "%d:", get_nod(fs, nod)->i_size);
2714 flist_blocks(fs, nod, fh);
2720 dump_fs(fs, fh, bigendian);
2724 dump_fs(fs, stdout, bigendian);
2725 free_fs(fs);