• Home
  • Raw
  • Download

Lines Matching refs:fs

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