Lines Matching refs:csi

39 csi_to_block(struct csi *csi)
42 ASSERT(_validate_cs_(csi->vol, csi->cluster, csi->sector) == 0);
43 if (_validate_cs_(csi->vol, csi->cluster, csi->sector) != 0)
46 if (IS_FIXED_ROOT(csi->cluster))
47 return csi->vol->root_start + csi->sector;
49 return csi->vol->data_start +
50 (off_t)(csi->cluster - 2)* csi->vol->sectors_per_cluster +
51 csi->sector;
56 init_csi(nspace *vol, uint32 cluster, uint32 sector, struct csi *csi)
62 csi->vol = vol; csi->cluster = cluster; csi->sector = sector;
69 iter_csi(struct csi *csi, int sectors)
71 if (csi->sector == 0xffff) // check if already at end of chain
80 if (IS_FIXED_ROOT(csi->cluster)) {
81 csi->sector += sectors;
82 if (csi->sector < csi->vol->root_sectors)
85 csi->sector += sectors;
86 if (csi->sector < csi->vol->sectors_per_cluster)
88 csi->cluster = get_nth_fat_entry(csi->vol, csi->cluster,
89 csi->sector / csi->vol->sectors_per_cluster);
91 if ((int32)csi->cluster < 0) {
92 csi->sector = 0xffff;
93 return csi->cluster;
96 if (vIS_DATA_CLUSTER(csi->vol,csi->cluster)) {
97 csi->sector %= csi->vol->sectors_per_cluster;
102 csi->sector = 0xffff;
109 csi_get_block(struct csi *csi)
114 if (_validate_cs_(csi->vol, csi->cluster, csi->sector) != 0)
117 status = block_cache_get_etc(csi->vol->fBlockCache,
118 csi_to_block(csi), 1, csi->vol->bytes_per_sector, &block);
126 csi_release_block(struct csi *csi)
128 if (_validate_cs_(csi->vol, csi->cluster, csi->sector) != 0)
131 block_cache_put(csi->vol->fBlockCache, csi_to_block(csi));
137 csi_make_writable(struct csi *csi)
139 if (_validate_cs_(csi->vol, csi->cluster, csi->sector) != 0)
142 return block_cache_make_writable(csi->vol->fBlockCache, csi_to_block(csi),
149 csi_read_blocks(struct csi *csi, uint8 *buffer, ssize_t len)
151 struct csi old_csi;
158 ASSERT(len > 0 && (size_t)len >= csi->vol->bytes_per_sector);
160 if (_validate_cs_(csi->vol, csi->cluster, csi->sector) != 0)
164 block = csi_to_block(csi);
167 old_csi = *csi;
168 err = iter_csi(csi, 1);
169 if ((size_t)len < (sectors + 1) * csi->vol->bytes_per_sector)
171 if ((err < B_OK) || (block + sectors != csi_to_block(csi)))
177 char *blockData = (char *)block_cache_get(csi->vol->fBlockCache, i);
178 memcpy(buf, blockData, csi->vol->bytes_per_sector);
179 buf += csi->vol->bytes_per_sector;
180 block_cache_put(csi->vol->fBlockCache, i);
183 *csi = old_csi;
185 return sectors * csi->vol->bytes_per_sector;
190 csi_write_blocks(struct csi *csi, uint8 *buffer, ssize_t len)
192 struct csi old_csi;
199 ASSERT(len > 0 && (size_t)len >= csi->vol->bytes_per_sector);
201 ASSERT(_validate_cs_(csi->vol, csi->cluster, csi->sector) == 0);
202 if (_validate_cs_(csi->vol, csi->cluster, csi->sector) != 0)
206 block = csi_to_block(csi);
209 old_csi = *csi;
210 err = iter_csi(csi, 1);
211 if ((size_t)len < (sectors + 1) * csi->vol->bytes_per_sector)
213 if ((err < B_OK) || (block + sectors != csi_to_block(csi)))
220 status_t status = block_cache_get_writable_etc(csi->vol->fBlockCache,
225 memcpy(blockData, buf, csi->vol->bytes_per_sector);
226 buf += csi->vol->bytes_per_sector;
227 block_cache_put(csi->vol->fBlockCache, i);
233 *csi = old_csi;
235 return sectors * csi->vol->bytes_per_sector;
240 csi_write_block(struct csi *csi, uint8 *buffer)
246 block = csi_to_block(csi);
248 ASSERT(_validate_cs_(csi->vol, csi->cluster, csi->sector) == 0);
249 if (_validate_cs_(csi->vol, csi->cluster, csi->sector) != 0)
252 status = block_cache_get_writable_etc(csi->vol->fBlockCache, block, 0, 1,
257 memcpy(blockData, buffer, csi->vol->bytes_per_sector);
258 block_cache_put(csi->vol->fBlockCache, block);
273 csi_release_block(&(diri->csi));
287 if (init_csi(vol,cluster,0,&(diri->csi)) != 0)
293 && iter_csi(&(diri->csi), diri->current_index
298 diri->current_block = csi_get_block(&diri->csi);
305 + (diri->current_index % (diri->csi.vol->bytes_per_sector / 0x20))*0x20;
311 csi.vol = NULL;
312 csi.cluster = 0;
313 csi.sector = 0;
333 + (diri->current_index % (diri->csi.vol->bytes_per_sector / 0x20))*0x20;
343 if ((++diri->current_index % (diri->csi.vol->bytes_per_sector / 0x20)) == 0) {
345 if (iter_csi(&(diri->csi), 1) != 0)
347 diri->current_block = csi_get_block(&(diri->csi));
353 + (diri->current_index % (diri->csi.vol->bytes_per_sector / 0x20))*0x20;
360 if (diri->current_index > (diri->csi.vol->bytes_per_sector / 0x20 - 1)) {
363 if (init_csi(diri->csi.vol, diri->starting_cluster, 0, &(diri->csi)) != 0)
365 diri->current_block = csi_get_block(&diri->csi);
375 csi_make_writable(&diri->csi);