/*
* Copyright (c) 2006, 2008 Reinoud Zandijk
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* XXX right flags to mark dirty again on error? */
if (buf->b_error) {
/* write error on `defect free' media??? how to solve? */
/* XXX lookup UDF standard for unallocatable space */
udf_node->i_flags |= IN_MODIFIED | IN_ACCESSED;
}
static int
udf_write_nodedscr_direct(struct udf_strat_args *args)
{
struct udf_mount *ump = args->ump;
struct udf_node *udf_node = args->udf_node;
union dscrptr *dscr = args->dscr;
struct long_ad *icb = args->icb;
int waitfor = args->waitfor;
uint32_t logsector, sector, dummy;
int error, vpart __diagused;
/*
* we have to decide if we write it out sequential or at its fixed
* position by examining the partition its (to be) written on.
*/
vpart = udf_rw16(udf_node->loc.loc.part_num);
logsector = udf_rw32(icb->loc.lb_num);
KASSERT(ump->vtop_tp[vpart] != UDF_VTOP_TYPE_VIRT);
/*
* Buffers should not have been allocated to disc addresses yet on
* this queue. Note that a buffer can get multiple extents allocated.
*
* lmapping contains lb_num relative to base partition.
*/
lmapping = ump->la_lmapping;
node_ad_cpy = ump->la_node_ad_cpy;
/* logically allocate buf and map it in the file */
udf_late_allocate_buf(ump, buf, lmapping, node_ad_cpy, &vpart_num);
/* if we have FIDs, fixup using the new allocation table */
if (buf->b_udf_c_type == UDF_C_FIDS) {
buf_len = buf->b_bcount;
bpos = 0;
lmappos = lmapping;
while (buf_len) {
sectornr = *lmappos++;
len = MIN(buf_len, sector_size);
fidblk = (uint8_t *) buf->b_data + bpos;
udf_fixup_fid_block(fidblk, sector_size,
0, len, sectornr);
bpos += len;
buf_len -= len;
}
}
if (buf->b_udf_c_type == UDF_C_METADATA_SBM) {
if (buf->b_lblkno == 0) {
/* update the tag location inside */
tag = (struct desc_tag *) buf->b_data;
tag->tag_loc = udf_rw32(*lmapping);
udf_validate_tag_and_crc_sums(buf->b_data);
}
}
udf_fixup_node_internals(ump, buf->b_data, buf->b_udf_c_type);
/*
* Translate new mappings in lmapping to pmappings and try to
* conglomerate extents to reduce the number of writes.
*
* pmapping to contain lb_nums as used for disc addressing.
*/
pmapping = ump->la_pmapping;
sectors = (buf->b_bcount + sector_size -1) / sector_size;
udf_translate_vtop_list(ump, sectors, vpart_num, lmapping, pmapping);
/*
* Initialise pool for descriptors associated with nodes. This is done
* in lb_size units though currently lb_size is dictated to be
* sector_size.
*/
memset(&priv->desc_pool, 0, sizeof(struct pool));