MCPcopy Create free account
hub / github.com/davidgiven/fluxengine / f_addextent

Function f_addextent

dep/hfsutils/libhfs/file.c:202–305  ·  view source on GitHub ↗

* NAME: file->addextent() * DESCRIPTION: add an extent to a file */

Source from the content-addressed store, hash-verified

200 * DESCRIPTION: add an extent to a file
201 */
202int f_addextent(hfsfile *file, ExtDescriptor *blocks)
203{
204 hfsvol *vol = file->vol;
205 ExtDataRec *extrec;
206 unsigned long *pylen;
207 unsigned int start, end;
208 node n;
209 int i;
210
211 f_getptrs(file, &extrec, 0, &pylen);
212
213 start = file->fabn;
214 end = *pylen / vol->mdb.drAlBlkSiz;
215
216 n.nnum = 0;
217 i = -1;
218
219 while (start < end)
220 {
221 for (i = 0; i < 3; ++i)
222 {
223 unsigned int num;
224
225 num = file->ext[i].xdrNumABlks;
226 start += num;
227
228 if (start == end)
229 break;
230 else if (start > end)
231 ERROR(EIO, "file extents exceed file physical length");
232 else if (num == 0)
233 ERROR(EIO, "empty file extent");
234 }
235
236 if (start == end)
237 break;
238
239 if (v_extsearch(file, start, &file->ext, &n) <= 0)
240 goto fail;
241
242 file->fabn = start;
243 }
244
245 if (i >= 0 &&
246 file->ext[i].xdrStABN + file->ext[i].xdrNumABlks == blocks->xdrStABN)
247 file->ext[i].xdrNumABlks += blocks->xdrNumABlks;
248 else
249 {
250 /* create a new extent descriptor */
251
252 if (++i < 3)
253 file->ext[i] = *blocks;
254 else
255 {
256 ExtKeyRec key;
257 byte record[HFS_MAX_EXTRECLEN];
258 unsigned int reclen;
259

Callers 2

f_allocFunction · 0.85
hfs_formatFunction · 0.85

Calls 6

f_getptrsFunction · 0.85
v_extsearchFunction · 0.85
r_makeextkeyFunction · 0.85
r_packextrecFunction · 0.85
bt_insertFunction · 0.85
v_putextrecFunction · 0.85

Tested by

no test coverage detected