* NAME: file->addextent() * DESCRIPTION: add an extent to a file */
| 200 | * DESCRIPTION: add an extent to a file |
| 201 | */ |
| 202 | int 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 |
no test coverage detected