Changeset 8b0bc1f in mainline
- Timestamp:
- 2008-10-26T11:36:13Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6ebaff9
- Parents:
- b4b7187
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_ops.c
rb4b7187 r8b0bc1f 149 149 free(block); 150 150 } 151 152 #define FAT1 0 151 153 152 154 #define FAT_BS(b) ((fat_bs_t *)((b)->data)) … … 891 893 (o - boundary) / bps); 892 894 memset(b->data, 0, min(bps, pos - o)); 893 b->dirty = true; 895 b->dirty = true; /* need to sync node */ 894 896 block_put(b); 895 897 } 896 898 } 897 899 900 static void 901 fat_mark_cluster(dev_handle_t dev_handle, unsigned fatno, fat_cluster_t clst, 902 fat_cluster_t value) 903 { 904 /* TODO */ 905 } 906 907 static void 908 fat_alloc_shadow_clusters(dev_handle_t dev_handle, fat_cluster_t *lifo, 909 unsigned nclsts) 910 { 911 /* TODO */ 912 } 913 898 914 static int 899 fat_alloc_clusters(unsigned nclsts, fat_cluster_t *mcl, fat_cluster_t *lcl) 900 { 901 return ENOTSUP; /* TODO */ 915 fat_alloc_clusters(dev_handle_t dev_handle, unsigned nclsts, fat_cluster_t *mcl, 916 fat_cluster_t *lcl) 917 { 918 uint16_t bps; 919 uint16_t rscnt; 920 uint16_t sf; 921 block_t *bb, *blk; 922 fat_cluster_t *lifo; /* stack for storing free cluster numbers */ 923 unsigned found = 0; /* top of the free cluster number stack */ 924 unsigned b, c, cl; 925 926 lifo = (fat_cluster_t *) malloc(nclsts * sizeof(fat_cluster_t)); 927 if (lifo) 928 return ENOMEM; 929 930 bb = block_get(dev_handle, BS_BLOCK, BS_SIZE); 931 bps = uint16_t_le2host(FAT_BS(bb)->bps); 932 rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt); 933 sf = uint16_t_le2host(FAT_BS(bb)->sec_per_fat); 934 block_put(bb); 935 936 /* 937 * Search FAT1 for unused clusters. 938 */ 939 for (b = 0, cl = 0; b < sf; blk++) { 940 blk = block_get(dev_handle, rscnt + b, bps); 941 for (c = 0; c < bps / sizeof(fat_cluster_t); c++, cl++) { 942 fat_cluster_t *clst = (fat_cluster_t *)blk->data + c; 943 if (*clst == FAT_CLST_RES0) { 944 /* 945 * The cluster is free. Put it into our stack 946 * of found clusters and mark it as non-free. 947 */ 948 lifo[found] = cl; 949 if (found == 0) 950 *clst = FAT_CLST_LAST1; 951 else 952 *clst = lifo[found - 1]; 953 blk->dirty = true; /* need to sync block */ 954 if (++found == nclsts) { 955 /* we are almost done */ 956 block_put(blk); 957 /* update the shadow copies of FAT */ 958 fat_alloc_shadow_clusters(dev_handle, 959 lifo, nclsts); 960 *mcl = lifo[found - 1]; 961 *lcl = lifo[0]; 962 free(lifo); 963 return EOK; 964 } 965 } 966 } 967 block_put(blk); 968 } 969 970 /* 971 * We could not find enough clusters. Now we need to free the clusters 972 * we have allocated so far. 973 */ 974 while (found--) 975 fat_mark_cluster(dev_handle, FAT1, lifo[found], FAT_CLST_RES0); 976 977 free(lifo); 978 return ENOSPC; 902 979 } 903 980 … … 987 1064 bps * spc; 988 1065 /* create an independent chain of nclsts clusters in all FATs */ 989 status = fat_alloc_clusters( nclsts, &mcl, &lcl);1066 status = fat_alloc_clusters(dev_handle, nclsts, &mcl, &lcl); 990 1067 if (status != EOK) { 991 1068 /* could not allocate a chain of nclsts clusters */
Note:
See TracChangeset
for help on using the changeset viewer.