Changeset 758f8d5 in mainline for uspace/srv/fs
- Timestamp:
- 2013-09-11T21:53:36Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e1ec5a2
- Parents:
- 1e371cf (diff), 9dbdda9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/srv/fs
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/cdfs/cdfs_ops.c
r1e371cf r758f8d5 619 619 } 620 620 621 static int cdfs_size_block(service_id_t service_id, uint32_t *size) 622 { 623 *size = BLOCK_SIZE; 624 625 return EOK; 626 } 627 628 static int cdfs_total_block_count(service_id_t service_id, uint64_t *count) 629 { 630 *count = 0; 631 632 return EOK; 633 } 634 635 static int cdfs_free_block_count(service_id_t service_id, uint64_t *count) 636 { 637 *count = 0; 638 639 return EOK; 640 } 641 621 642 libfs_ops_t cdfs_libfs_ops = { 622 643 .root_get = cdfs_root_get, … … 635 656 .is_directory = cdfs_is_directory, 636 657 .is_file = cdfs_is_file, 637 .service_get = cdfs_service_get 658 .service_get = cdfs_service_get, 659 .size_block = cdfs_size_block, 660 .total_block_count = cdfs_total_block_count, 661 .free_block_count = cdfs_free_block_count 638 662 }; 639 663 -
uspace/srv/fs/exfat/exfat_ops.c
r1e371cf r758f8d5 89 89 static bool exfat_is_file(fs_node_t *node); 90 90 static service_id_t exfat_service_get(fs_node_t *node); 91 static int exfat_size_block(service_id_t, uint32_t *); 92 static int exfat_total_block_count(service_id_t, uint64_t *); 93 static int exfat_free_block_count(service_id_t, uint64_t *); 91 94 92 95 /* … … 910 913 } 911 914 915 int exfat_size_block(service_id_t service_id, uint32_t *size) 916 { 917 exfat_bs_t *bs; 918 bs = block_bb_get(service_id); 919 *size = BPC(bs); 920 921 return EOK; 922 } 923 924 int exfat_total_block_count(service_id_t service_id, uint64_t *count) 925 { 926 exfat_bs_t *bs; 927 bs = block_bb_get(service_id); 928 *count = DATA_CNT(bs); 929 930 return EOK; 931 } 932 933 int exfat_free_block_count(service_id_t service_id, uint64_t *count) 934 { 935 fs_node_t *node; 936 exfat_node_t *bmap_node; 937 exfat_bs_t *bs; 938 uint64_t free_block_count = 0; 939 uint64_t block_count; 940 unsigned sector; 941 int rc; 942 943 rc = exfat_total_block_count(service_id, &block_count); 944 if (rc != EOK) 945 goto exit; 946 947 bs = block_bb_get(service_id); 948 node = NULL; 949 rc = exfat_bitmap_get(&node, service_id); 950 if (rc != EOK) 951 goto exit; 952 953 bmap_node = (exfat_node_t *) node->data; 954 955 unsigned const bmap_sectors = ROUND_UP(bmap_node->size, BPS(bs)) / 956 BPS(bs); 957 958 for (sector = 0; sector < bmap_sectors; ++sector) { 959 960 block_t *block; 961 uint8_t *bitmap; 962 unsigned bit; 963 964 rc = exfat_block_get(&block, bs, bmap_node, sector, 965 BLOCK_FLAGS_NONE); 966 if (rc != EOK) { 967 free_block_count = 0; 968 goto exit; 969 } 970 971 bitmap = (uint8_t *) block->data; 972 973 for (bit = 0; bit < BPS(bs) * 8 && block_count > 0; 974 ++bit, --block_count) { 975 if (!(bitmap[bit / 8] & (1 << (bit % 8)))) 976 ++free_block_count; 977 } 978 979 block_put(block); 980 981 if (block_count == 0) { 982 /* Reached the end of the bitmap */ 983 goto exit; 984 } 985 } 986 987 exit: 988 exfat_node_put(node); 989 *count = free_block_count; 990 return rc; 991 } 912 992 913 993 /** libfs operations */ … … 928 1008 .is_directory = exfat_is_directory, 929 1009 .is_file = exfat_is_file, 930 .service_get = exfat_service_get 1010 .service_get = exfat_service_get, 1011 .size_block = exfat_size_block, 1012 .total_block_count = exfat_total_block_count, 1013 .free_block_count = exfat_free_block_count 931 1014 }; 932 1015 -
uspace/srv/fs/ext4fs/ext4fs_ops.c
r1e371cf r758f8d5 101 101 static bool ext4fs_is_file(fs_node_t *node); 102 102 static service_id_t ext4fs_service_get(fs_node_t *node); 103 static int ext4fs_size_block(service_id_t, uint32_t *); 104 static int ext4fs_total_block_count(service_id_t, uint64_t *); 105 static int ext4fs_free_block_count(service_id_t, uint64_t *); 103 106 104 107 /* Static variables */ … … 833 836 ext4fs_node_t *enode = EXT4FS_NODE(fn); 834 837 return enode->instance->service_id; 838 } 839 840 int ext4fs_size_block(service_id_t service_id, uint32_t *size) 841 { 842 ext4fs_instance_t *inst; 843 int rc = ext4fs_instance_get(service_id, &inst); 844 if (rc != EOK) 845 return rc; 846 847 if (NULL == inst) 848 return ENOENT; 849 850 ext4_superblock_t *sb = inst->filesystem->superblock; 851 *size = ext4_superblock_get_block_size(sb); 852 853 return EOK; 854 } 855 856 int ext4fs_total_block_count(service_id_t service_id, uint64_t *count) 857 { 858 ext4fs_instance_t *inst; 859 int rc = ext4fs_instance_get(service_id, &inst); 860 if (rc != EOK) 861 return rc; 862 863 if (NULL == inst) 864 return ENOENT; 865 866 ext4_superblock_t *sb = inst->filesystem->superblock; 867 *count = ext4_superblock_get_blocks_count(sb); 868 869 return EOK; 870 } 871 872 int ext4fs_free_block_count(service_id_t service_id, uint64_t *count) 873 { 874 ext4fs_instance_t *inst; 875 int rc = ext4fs_instance_get(service_id, &inst); 876 if (rc != EOK) 877 return rc; 878 if (NULL == inst) 879 return ENOENT; 880 881 ext4_superblock_t *sb = inst->filesystem->superblock; 882 *count = ext4_superblock_get_free_blocks_count(sb); 883 884 return EOK; 835 885 } 836 886 … … 854 904 .is_directory = ext4fs_is_directory, 855 905 .is_file = ext4fs_is_file, 856 .service_get = ext4fs_service_get 906 .service_get = ext4fs_service_get, 907 .size_block = ext4fs_size_block, 908 .total_block_count = ext4fs_total_block_count, 909 .free_block_count = ext4fs_free_block_count 857 910 }; 858 911 -
uspace/srv/fs/fat/fat_ops.c
r1e371cf r758f8d5 91 91 static bool fat_is_file(fs_node_t *node); 92 92 static service_id_t fat_service_get(fs_node_t *node); 93 static int fat_size_block(service_id_t, uint32_t *); 94 static int fat_total_block_count(service_id_t, uint64_t *); 95 static int fat_free_block_count(service_id_t, uint64_t *); 93 96 94 97 /* … … 841 844 } 842 845 846 int fat_size_block(service_id_t service_id, uint32_t *size) 847 { 848 fat_bs_t *bs; 849 850 bs = block_bb_get(service_id); 851 *size = BPC(bs); 852 853 return EOK; 854 } 855 856 int fat_total_block_count(service_id_t service_id, uint64_t *count) 857 { 858 fat_bs_t *bs; 859 860 bs = block_bb_get(service_id); 861 *count = (SPC(bs)) ? TS(bs) / SPC(bs) : 0; 862 863 return EOK; 864 } 865 866 int fat_free_block_count(service_id_t service_id, uint64_t *count) 867 { 868 fat_bs_t *bs; 869 fat_cluster_t e0; 870 uint64_t block_count; 871 int rc; 872 uint32_t cluster_no, clusters; 873 874 block_count = 0; 875 bs = block_bb_get(service_id); 876 clusters = (SPC(bs)) ? TS(bs) / SPC(bs) : 0; 877 for (cluster_no = 0; cluster_no < clusters; cluster_no++) { 878 rc = fat_get_cluster(bs, service_id, FAT1, cluster_no, &e0); 879 if (rc != EOK) 880 return EIO; 881 882 if (e0 == FAT_CLST_RES0) 883 block_count++; 884 } 885 *count = block_count; 886 887 return EOK; 888 } 889 843 890 /** libfs operations */ 844 891 libfs_ops_t fat_libfs_ops = { … … 858 905 .is_directory = fat_is_directory, 859 906 .is_file = fat_is_file, 860 .service_get = fat_service_get 907 .service_get = fat_service_get, 908 .size_block = fat_size_block, 909 .total_block_count = fat_total_block_count, 910 .free_block_count = fat_free_block_count 861 911 }; 862 912 -
uspace/srv/fs/mfs/mfs.h
r1e371cf r758f8d5 58 58 #endif 59 59 60 #define MFS_BMAP_START_BLOCK(sbi, bid) \ 61 ((bid) == BMAP_ZONE ? 2 + (sbi)->ibmap_blocks : 2) 62 63 #define MFS_BMAP_SIZE_BITS(sbi, bid) \ 64 ((bid) == BMAP_ZONE ? (sbi)->nzones - (sbi)->firstdatazone - 1 : \ 65 (sbi)->ninodes - 1) 66 67 #define MFS_BMAP_SIZE_BLOCKS(sbi, bid) \ 68 ((bid) == BMAP_ZONE ? (sbi)->zbmap_blocks : (sbi)->ibmap_blocks) 69 60 70 typedef uint32_t bitchunk_t; 61 71 … … 201 211 mfs_free_zone(struct mfs_instance *inst, uint32_t zone); 202 212 213 extern int 214 mfs_count_free_zones(struct mfs_instance *inst, uint32_t *zones); 215 216 extern int 217 mfs_count_free_inodes(struct mfs_instance *inst, uint32_t *inodes); 218 219 203 220 /* mfs_utils.c */ 204 221 extern uint16_t -
uspace/srv/fs/mfs/mfs_balloc.c
r1e371cf r758f8d5 44 44 mfs_alloc_bit(struct mfs_instance *inst, uint32_t *idx, bmap_id_t bid); 45 45 46 static int 47 mfs_count_free_bits(struct mfs_instance *inst, bmap_id_t bid, uint32_t *free); 48 49 46 50 /**Allocate a new inode. 47 51 * … … 102 106 103 107 return mfs_free_bit(inst, zone, BMAP_ZONE); 108 } 109 110 /** Count the number of free zones 111 * 112 * @param inst Pointer to the instance structure. 113 * @param zones Pointer to the memory location where the result 114 * will be stored. 115 * 116 * @return EOK on success or a negative error code. 117 */ 118 int 119 mfs_count_free_zones(struct mfs_instance *inst, uint32_t *zones) 120 { 121 return mfs_count_free_bits(inst, BMAP_ZONE, zones); 122 } 123 124 /** Count the number of free inodes 125 * 126 * @param inst Pointer to the instance structure. 127 * @param zones Pointer to the memory location where the result 128 * will be stored. 129 * 130 * @return EOK on success or a negative error code. 131 */ 132 133 int 134 mfs_count_free_inodes(struct mfs_instance *inst, uint32_t *inodes) 135 { 136 return mfs_count_free_bits(inst, BMAP_INODE, inodes); 137 } 138 139 /** Count the number of free bits in a bitmap 140 * 141 * @param inst Pointer to the instance structure. 142 * @param bid Type of the bitmap (inode or zone). 143 * @param free Pointer to the memory location where the result 144 * will be stores. 145 * 146 * @return EOK on success or a negative error code. 147 */ 148 static int 149 mfs_count_free_bits(struct mfs_instance *inst, bmap_id_t bid, uint32_t *free) 150 { 151 int r; 152 unsigned start_block; 153 unsigned long nblocks; 154 unsigned long nbits; 155 unsigned long block; 156 unsigned long free_bits = 0; 157 bitchunk_t chunk; 158 size_t const bitchunk_bits = sizeof(bitchunk_t) * 8; 159 block_t *b; 160 struct mfs_sb_info *sbi = inst->sbi; 161 162 start_block = MFS_BMAP_START_BLOCK(sbi, bid); 163 nblocks = MFS_BMAP_SIZE_BLOCKS(sbi, bid); 164 nbits = MFS_BMAP_SIZE_BITS(sbi, bid); 165 166 for (block = 0; block < nblocks; ++block) { 167 r = block_get(&b, inst->service_id, block + start_block, 168 BLOCK_FLAGS_NONE); 169 if (r != EOK) 170 return r; 171 172 size_t i; 173 bitchunk_t *data = (bitchunk_t *) b->data; 174 175 /* Read the bitmap block, chunk per chunk, 176 * counting the zero bits. 177 */ 178 for (i = 0; i < sbi->block_size / sizeof(bitchunk_t); ++i) { 179 chunk = conv32(sbi->native, data[i]); 180 181 size_t bit; 182 for (bit = 0; bit < bitchunk_bits && nbits > 0; 183 ++bit, --nbits) { 184 if (!(chunk & (1 << bit))) 185 free_bits++; 186 } 187 188 if (nbits == 0) 189 break; 190 } 191 192 r = block_put(b); 193 if (r != EOK) 194 return r; 195 } 196 197 *free = free_bits; 198 assert(nbits == 0); 199 200 return EOK; 104 201 } 105 202 … … 124 221 sbi = inst->sbi; 125 222 223 start_block = MFS_BMAP_START_BLOCK(sbi, bid); 224 126 225 if (bid == BMAP_ZONE) { 127 226 search = &sbi->zsearch; 128 start_block = 2 + sbi->ibmap_blocks;129 227 if (idx > sbi->nzones) { 130 228 printf(NAME ": Error! Trying to free beyond the " … … 135 233 /* bid == BMAP_INODE */ 136 234 search = &sbi->isearch; 137 start_block = 2;138 235 if (idx > sbi->ninodes) { 139 236 printf(NAME ": Error! Trying to free beyond the " … … 192 289 sbi = inst->sbi; 193 290 291 start_block = MFS_BMAP_START_BLOCK(sbi, bid); 292 limit = MFS_BMAP_SIZE_BITS(sbi, bid); 293 nblocks = MFS_BMAP_SIZE_BLOCKS(sbi, bid); 294 194 295 if (bid == BMAP_ZONE) { 195 296 search = &sbi->zsearch; 196 start_block = 2 + sbi->ibmap_blocks;197 nblocks = sbi->zbmap_blocks;198 limit = sbi->nzones - sbi->firstdatazone - 1;199 297 } else { 200 298 /* bid == BMAP_INODE */ 201 299 search = &sbi->isearch; 202 start_block = 2;203 nblocks = sbi->ibmap_blocks;204 limit = sbi->ninodes - 1;205 300 } 206 301 bits_per_block = sbi->block_size * 8; -
uspace/srv/fs/mfs/mfs_ops.c
r1e371cf r758f8d5 64 64 static int mfs_check_sanity(struct mfs_sb_info *sbi); 65 65 static bool is_power_of_two(uint32_t n); 66 static int mfs_size_block(service_id_t service_id, uint32_t *size); 67 static int mfs_total_block_count(service_id_t service_id, uint64_t *count); 68 static int mfs_free_block_count(service_id_t service_id, uint64_t *count); 66 69 67 70 static hash_table_t open_nodes; … … 84 87 .destroy = mfs_destroy_node, 85 88 .has_children = mfs_has_children, 86 .lnkcnt_get = mfs_lnkcnt_get 89 .lnkcnt_get = mfs_lnkcnt_get, 90 .size_block = mfs_size_block, 91 .total_block_count = mfs_total_block_count, 92 .free_block_count = mfs_free_block_count 87 93 }; 88 94 … … 1129 1135 } 1130 1136 1137 static int 1138 mfs_size_block(service_id_t service_id, uint32_t *size) 1139 { 1140 struct mfs_instance *inst; 1141 int rc; 1142 1143 rc = mfs_instance_get(service_id, &inst); 1144 if (rc != EOK) 1145 return rc; 1146 1147 if (NULL == inst) 1148 return ENOENT; 1149 1150 *size = inst->sbi->block_size; 1151 1152 return EOK; 1153 } 1154 1155 static int 1156 mfs_total_block_count(service_id_t service_id, uint64_t *count) 1157 { 1158 struct mfs_instance *inst; 1159 int rc; 1160 1161 rc = mfs_instance_get(service_id, &inst); 1162 if (rc != EOK) 1163 return rc; 1164 1165 if (NULL == inst) 1166 return ENOENT; 1167 1168 *count = (uint64_t) MFS_BMAP_SIZE_BITS(inst->sbi, BMAP_ZONE); 1169 1170 return EOK; 1171 } 1172 1173 static int 1174 mfs_free_block_count(service_id_t service_id, uint64_t *count) 1175 { 1176 uint32_t block_free; 1177 1178 struct mfs_instance *inst; 1179 int rc = mfs_instance_get(service_id, &inst); 1180 if (rc != EOK) 1181 return rc; 1182 1183 if (NULL == inst) 1184 return ENOENT; 1185 1186 mfs_count_free_zones(inst, &block_free); 1187 *count = block_free; 1188 1189 return EOK; 1190 } 1191 1131 1192 vfs_out_ops_t mfs_ops = { 1132 1193 .mounted = mfs_mounted, -
uspace/srv/fs/udf/udf_ops.c
r1e371cf r758f8d5 249 249 } 250 250 251 static int udf_size_block(service_id_t service_id, uint32_t *size) 252 { 253 udf_instance_t *instance; 254 int rc = fs_instance_get(service_id, (void **) &instance); 255 if (rc != EOK) 256 return rc; 257 258 if (NULL == instance) 259 return ENOENT; 260 261 *size = instance->volumes[DEFAULT_VOL].logical_block_size; 262 263 return EOK; 264 } 265 266 static int udf_total_block_count(service_id_t service_id, uint64_t *count) 267 { 268 *count = 0; 269 270 return EOK; 271 } 272 273 static int udf_free_block_count(service_id_t service_id, uint64_t *count) 274 { 275 *count = 0; 276 277 return EOK; 278 } 279 251 280 libfs_ops_t udf_libfs_ops = { 252 281 .root_get = udf_root_get, … … 265 294 .is_directory = udf_is_directory, 266 295 .is_file = udf_is_file, 267 .service_get = udf_service_get 296 .service_get = udf_service_get, 297 .size_block = udf_size_block, 298 .total_block_count = udf_total_block_count, 299 .free_block_count = udf_free_block_count 268 300 }; 269 301
Note:
See TracChangeset
for help on using the changeset viewer.