Changes in / [cd18cd1:330df83] in mainline
- Files:
-
- 3 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
rcd18cd1 r330df83 202 202 $(USPACE_PATH)/app/websrv/websrv \ 203 203 $(USPACE_PATH)/app/date/date \ 204 $(USPACE_PATH)/app/vdemo/vdemo 204 $(USPACE_PATH)/app/vdemo/vdemo \ 205 $(USPACE_PATH)/app/df/df 205 206 206 207 ifeq ($(CONFIG_PCC),y) -
uspace/Makefile
rcd18cd1 r330df83 80 80 app/vlaunch \ 81 81 app/vterm \ 82 app/df \ 82 83 srv/clipboard \ 83 84 srv/locsrv \ -
uspace/app/trace/trace.c
rcd18cd1 r330df83 724 724 o = oper_new("stat", 0, arg_def, V_ERRNO, 0, resp_def); 725 725 proto_add_oper(p, VFS_IN_STAT, o); 726 o = oper_new("statfs", 0, arg_def, V_ERRNO, 0, resp_def); 727 proto_add_oper(p, VFS_IN_STATFS, o); 726 728 727 729 proto_register(SERVICE_VFS, p); -
uspace/lib/c/generic/vfs/vfs.c
rcd18cd1 r330df83 43 43 #include <stdio.h> 44 44 #include <sys/stat.h> 45 #include <sys/statfs.h> 45 46 #include <sys/types.h> 46 47 #include <ipc/services.h> … … 892 893 } 893 894 895 int statfs(const char *path, struct statfs *statfs) 896 { 897 sysarg_t rc; 898 sysarg_t rc_orig; 899 aid_t req; 900 size_t pa_size; 901 902 char *pa = absolutize(path, &pa_size); 903 if (!pa) 904 return ENOMEM; 905 async_exch_t *exch = vfs_exchange_begin(); 906 907 req = async_send_0(exch, VFS_IN_STATFS, NULL); 908 rc = async_data_write_start(exch, pa, pa_size); 909 if (rc != EOK) { 910 vfs_exchange_end(exch); 911 free(pa); 912 async_wait_for(req, &rc_orig); 913 if (rc_orig == EOK) 914 return (int) rc; 915 else 916 return (int) rc_orig; 917 } 918 rc = async_data_read_start(exch, (void *) statfs, sizeof(struct statfs)); 919 if (rc != EOK) { 920 vfs_exchange_end(exch); 921 free(pa); 922 async_wait_for(req, &rc_orig); 923 if (rc_orig == EOK) 924 return (int) rc; 925 else 926 return (int) rc_orig; 927 } 928 vfs_exchange_end(exch); 929 free(pa); 930 async_wait_for(req, &rc); 931 return rc; 932 } 933 894 934 /** @} 895 935 */ -
uspace/lib/c/include/ipc/vfs.h
rcd18cd1 r330df83 82 82 VFS_IN_WAIT_HANDLE, 83 83 VFS_IN_MTAB_GET, 84 VFS_IN_STATFS 84 85 } vfs_in_request_t; 85 86 … … 98 99 VFS_OUT_LOOKUP, 99 100 VFS_OUT_DESTROY, 101 VFS_OUT_STATFS, 100 102 VFS_OUT_LAST 101 103 } vfs_out_request_t; -
uspace/lib/c/include/vfs/vfs.h
rcd18cd1 r330df83 44 44 #include "vfs_mtab.h" 45 45 46 46 47 enum vfs_change_state_type { 47 48 VFS_PASS_HANDLE 48 49 }; 50 49 51 50 52 extern char *absolutize(const char *, size_t *); … … 61 63 extern async_exch_t *vfs_exchange_begin(void); 62 64 extern void vfs_exchange_end(async_exch_t *); 63 64 65 #endif 65 66 -
uspace/lib/fs/libfs.c
rcd18cd1 r330df83 45 45 #include <mem.h> 46 46 #include <sys/stat.h> 47 #include <sys/statfs.h> 47 48 #include <stdlib.h> 48 49 … … 74 75 static void libfs_open_node(libfs_ops_t *, fs_handle_t, ipc_callid_t, 75 76 ipc_call_t *); 77 static void libfs_statfs(libfs_ops_t *, fs_handle_t, ipc_callid_t, ipc_call_t *); 76 78 77 79 static void vfs_out_mounted(ipc_callid_t rid, ipc_call_t *req) … … 219 221 } 220 222 223 static void vfs_out_statfs(ipc_callid_t rid, ipc_call_t *req) 224 { 225 libfs_statfs(libfs_ops, reg.fs_handle, rid, req); 226 } 221 227 static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 222 228 { … … 276 282 case VFS_OUT_SYNC: 277 283 vfs_out_sync(callid, &call); 284 break; 285 case VFS_OUT_STATFS: 286 vfs_out_statfs(callid, &call); 278 287 break; 279 288 default: … … 830 839 } 831 840 841 void libfs_statfs(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid, 842 ipc_call_t *request) 843 { 844 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 845 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 846 847 fs_node_t *fn; 848 int rc = ops->node_get(&fn, service_id, index); 849 on_error(rc, answer_and_return(rid, rc)); 850 851 ipc_callid_t callid; 852 size_t size; 853 if ((!async_data_read_receive(&callid, &size)) || 854 (size != sizeof(struct statfs))) { 855 ops->node_put(fn); 856 async_answer_0(callid, EINVAL); 857 async_answer_0(rid, EINVAL); 858 return; 859 } 860 861 struct statfs statfs; 862 memset(&statfs, 0, sizeof(struct statfs)); 863 864 if (NULL != ops->size_block) 865 statfs.f_bsize = ops->size_block(service_id); 866 if (NULL != ops->total_block_count) 867 statfs.f_blocks = ops->total_block_count(service_id); 868 if (NULL != ops->free_block_count) 869 statfs.f_bfree = ops->free_block_count(service_id); 870 871 ops->node_put(fn); 872 873 async_data_read_finalize(callid, &statfs, sizeof(struct statfs)); 874 async_answer_0(rid, EOK); 875 } 876 877 832 878 /** Open VFS triplet. 833 879 * -
uspace/lib/fs/libfs.h
rcd18cd1 r330df83 93 93 bool (* is_file)(fs_node_t *); 94 94 service_id_t (* service_get)(fs_node_t *); 95 uint32_t (* size_block)(service_id_t); 96 uint64_t (* total_block_count)(service_id_t); 97 uint64_t (* free_block_count)(service_id_t); 95 98 } libfs_ops_t; 96 99 -
uspace/srv/fs/cdfs/cdfs_ops.c
rcd18cd1 r330df83 625 625 } 626 626 627 static uint32_t cdfs_size_block(service_id_t service_id) 628 { 629 uint32_t block_size = BLOCK_SIZE; 630 return block_size; 631 } 632 627 633 libfs_ops_t cdfs_libfs_ops = { 628 634 .root_get = cdfs_root_get, … … 641 647 .is_directory = cdfs_is_directory, 642 648 .is_file = cdfs_is_file, 643 .service_get = cdfs_service_get 649 .service_get = cdfs_service_get, 650 .size_block = cdfs_size_block 644 651 }; 645 652 -
uspace/srv/fs/exfat/exfat_ops.c
rcd18cd1 r330df83 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 uint32_t exfat_size_block(service_id_t); 92 static uint64_t exfat_total_block_count(service_id_t); 93 static uint64_t exfat_free_block_count(service_id_t); 91 94 92 95 /* … … 912 915 } 913 916 917 uint32_t exfat_size_block(service_id_t service_id) 918 { 919 exfat_bs_t *bs; 920 bs = block_bb_get(service_id); 921 922 return BPC(bs); 923 } 924 925 uint64_t exfat_total_block_count(service_id_t service_id) 926 { 927 exfat_bs_t *bs; 928 bs = block_bb_get(service_id); 929 930 uint64_t block_count = DATA_CNT(bs); 931 932 return block_count; 933 } 934 935 uint64_t exfat_free_block_count(service_id_t service_id) 936 { 937 exfat_bs_t *bs; 938 bs = block_bb_get(service_id); 939 940 uint64_t block_count = (DATA_CNT(bs) / 100) * 941 bs->allocated_percent; 942 943 return block_count; 944 } 914 945 915 946 /** libfs operations */ … … 930 961 .is_directory = exfat_is_directory, 931 962 .is_file = exfat_is_file, 932 .service_get = exfat_service_get 963 .service_get = exfat_service_get, 964 .size_block = exfat_size_block, 965 .total_block_count = exfat_total_block_count, 966 .free_block_count = exfat_free_block_count 933 967 }; 934 968 -
uspace/srv/fs/ext4fs/ext4fs_ops.c
rcd18cd1 r330df83 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 uint32_t ext4fs_size_block(service_id_t); 104 static uint64_t ext4fs_total_block_count(service_id_t); 105 static uint64_t ext4fs_free_block_count(service_id_t); 103 106 104 107 /* Static variables */ … … 836 839 ext4fs_node_t *enode = EXT4FS_NODE(fn); 837 840 return enode->instance->service_id; 841 } 842 843 uint32_t ext4fs_size_block(service_id_t service_id) 844 { 845 ext4fs_instance_t *inst; 846 int rc = ext4fs_instance_get(service_id, &inst); 847 if (rc != EOK) 848 return rc; 849 if (NULL == inst) 850 return ENOENT; 851 852 ext4_superblock_t *sb = inst->filesystem->superblock; 853 uint32_t block_size = ext4_superblock_get_block_size(sb); 854 855 return block_size; 856 } 857 858 uint64_t ext4fs_total_block_count(service_id_t service_id) 859 { 860 ext4fs_instance_t *inst; 861 int rc = ext4fs_instance_get(service_id, &inst); 862 if (rc != EOK) 863 return rc; 864 if (NULL == inst) 865 return ENOENT; 866 867 ext4_superblock_t *sb = inst->filesystem->superblock; 868 uint64_t block_count = ext4_superblock_get_blocks_count(sb); 869 870 return block_count; 871 } 872 873 uint64_t ext4fs_free_block_count(service_id_t service_id) 874 { 875 ext4fs_instance_t *inst; 876 int rc = ext4fs_instance_get(service_id, &inst); 877 if (rc != EOK) 878 return rc; 879 if (NULL == inst) 880 return ENOENT; 881 882 ext4_superblock_t *sb = inst->filesystem->superblock; 883 uint64_t block_count = ext4_superblock_get_free_blocks_count(sb); 884 885 return block_count; 838 886 } 839 887 … … 857 905 .is_directory = ext4fs_is_directory, 858 906 .is_file = ext4fs_is_file, 859 .service_get = ext4fs_service_get 907 .service_get = ext4fs_service_get, 908 .size_block = ext4fs_size_block, 909 .total_block_count = ext4fs_total_block_count, 910 .free_block_count = ext4fs_free_block_count 860 911 }; 861 912 -
uspace/srv/fs/fat/fat_ops.c
rcd18cd1 r330df83 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 uint32_t fat_size_block(service_id_t); 93 94 94 95 /* … … 843 844 } 844 845 846 uint32_t fat_size_block(service_id_t service_id) 847 { 848 fat_bs_t *bs; 849 bs = block_bb_get(service_id); 850 851 return BPC(bs); 852 } 853 845 854 /** libfs operations */ 846 855 libfs_ops_t fat_libfs_ops = { … … 860 869 .is_directory = fat_is_directory, 861 870 .is_file = fat_is_file, 862 .service_get = fat_service_get 871 .service_get = fat_service_get, 872 .size_block = fat_size_block 863 873 }; 864 874 -
uspace/srv/fs/mfs/mfs.h
rcd18cd1 r330df83 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
rcd18cd1 r330df83 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
rcd18cd1 r330df83 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 uint32_t mfs_size_block(service_id_t service_id); 67 static uint64_t mfs_total_block_count(service_id_t service_id); 68 static uint64_t mfs_free_block_count(service_id_t service_id); 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 uint32_t 1138 mfs_size_block(service_id_t service_id) 1139 { 1140 uint32_t block_size; 1141 1142 struct mfs_instance *inst; 1143 int rc = mfs_instance_get(service_id, &inst); 1144 if (rc != EOK) 1145 return rc; 1146 if (NULL == inst) 1147 return ENOENT; 1148 1149 block_size = inst->sbi->block_size; 1150 1151 return block_size; 1152 } 1153 1154 static uint64_t 1155 mfs_total_block_count(service_id_t service_id) 1156 { 1157 uint64_t block_total; 1158 1159 struct mfs_instance *inst; 1160 int rc = mfs_instance_get(service_id, &inst); 1161 if (rc != EOK) 1162 return rc; 1163 1164 if (NULL == inst) 1165 return ENOENT; 1166 1167 block_total = (uint64_t) MFS_BMAP_SIZE_BITS(inst->sbi, BMAP_ZONE); 1168 1169 return block_total; 1170 } 1171 1172 static uint64_t 1173 mfs_free_block_count(service_id_t service_id) 1174 { 1175 uint32_t block_free; 1176 1177 struct mfs_instance *inst; 1178 int rc = mfs_instance_get(service_id, &inst); 1179 if (rc != EOK) 1180 return rc; 1181 1182 if (NULL == inst) 1183 return ENOENT; 1184 1185 mfs_count_free_zones(inst, &block_free); 1186 1187 return (uint64_t)block_free; 1188 } 1189 1131 1190 vfs_out_ops_t mfs_ops = { 1132 1191 .mounted = mfs_mounted, -
uspace/srv/fs/udf/udf_ops.c
rcd18cd1 r330df83 249 249 } 250 250 251 static uint32_t udf_size_block(service_id_t service_id) 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 return instance->volumes[DEFAULT_VOL].logical_block_size; 262 } 263 251 264 libfs_ops_t udf_libfs_ops = { 252 265 .root_get = udf_root_get, … … 265 278 .is_directory = udf_is_directory, 266 279 .is_file = udf_is_file, 267 .service_get = udf_service_get 280 .service_get = udf_service_get, 281 .size_block = udf_size_block 268 282 }; 269 283 -
uspace/srv/vfs/vfs.c
rcd18cd1 r330df83 130 130 vfs_get_mtab(callid, &call); 131 131 break; 132 case VFS_IN_STATFS: 133 vfs_statfs(callid, &call); 134 break; 132 135 default: 133 136 async_answer_0(callid, ENOTSUP); -
uspace/srv/vfs/vfs.h
rcd18cd1 r330df83 222 222 extern void vfs_wait_handle(ipc_callid_t, ipc_call_t *); 223 223 extern void vfs_get_mtab(ipc_callid_t, ipc_call_t *); 224 extern void vfs_statfs(ipc_callid_t, ipc_call_t *); 224 225 225 226 #endif -
uspace/srv/vfs/vfs_ops.c
rcd18cd1 r330df83 1418 1418 } 1419 1419 1420 void vfs_statfs(ipc_callid_t rid, ipc_call_t *request) 1421 { 1422 char *path; 1423 int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL); 1424 if (rc != EOK) { 1425 async_answer_0(rid, rc); 1426 return; 1427 } 1428 1429 ipc_callid_t callid; 1430 if (!async_data_read_receive(&callid, NULL)) { 1431 free(path); 1432 async_answer_0(callid, EINVAL); 1433 async_answer_0(rid, EINVAL); 1434 return; 1435 } 1436 1437 vfs_lookup_res_t lr; 1438 fibril_rwlock_read_lock(&namespace_rwlock); 1439 rc = vfs_lookup_internal(path, L_NONE, &lr, NULL); 1440 free(path); 1441 if (rc != EOK) { 1442 fibril_rwlock_read_unlock(&namespace_rwlock); 1443 async_answer_0(callid, rc); 1444 async_answer_0(rid, rc); 1445 return; 1446 } 1447 vfs_node_t *node = vfs_node_get(&lr); 1448 if (!node) { 1449 fibril_rwlock_read_unlock(&namespace_rwlock); 1450 async_answer_0(callid, ENOMEM); 1451 async_answer_0(rid, ENOMEM); 1452 return; 1453 } 1454 1455 fibril_rwlock_read_unlock(&namespace_rwlock); 1456 1457 async_exch_t *exch = vfs_exchange_grab(node->fs_handle); 1458 1459 aid_t msg; 1460 msg = async_send_3(exch, VFS_OUT_STATFS, node->service_id, 1461 node->index, false, NULL); 1462 async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 1463 1464 vfs_exchange_release(exch); 1465 1466 sysarg_t rv; 1467 async_wait_for(msg, &rv); 1468 1469 async_answer_0(rid, rv); 1470 1471 vfs_node_put(node); 1472 } 1473 1420 1474 /** 1421 1475 * @}
Note:
See TracChangeset
for help on using the changeset viewer.