Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-arm
[pandora-kernel.git] / fs / udf / misc.c
index cc8ca32..15297de 100644 (file)
@@ -29,8 +29,7 @@
 #include "udf_i.h"
 #include "udf_sb.h"
 
-struct buffer_head *
-udf_tgetblk(struct super_block *sb, int block)
+struct buffer_head *udf_tgetblk(struct super_block *sb, int block)
 {
        if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV))
                return sb_getblk(sb, udf_fixed_to_variable(block));
@@ -38,8 +37,7 @@ udf_tgetblk(struct super_block *sb, int block)
                return sb_getblk(sb, block);
 }
 
-struct buffer_head *
-udf_tread(struct super_block *sb, int block)
+struct buffer_head *udf_tread(struct super_block *sb, int block)
 {
        if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV))
                return sb_bread(sb, udf_fixed_to_variable(block));
@@ -47,9 +45,8 @@ udf_tread(struct super_block *sb, int block)
                return sb_bread(sb, block);
 }
 
-struct genericFormat *
-udf_add_extendedattr(struct inode * inode, uint32_t size, uint32_t type,
-       uint8_t loc)
+struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
+                                          uint32_t type, uint8_t loc)
 {
        uint8_t *ea = NULL, *ad = NULL;
        int offset;
@@ -57,10 +54,9 @@ udf_add_extendedattr(struct inode * inode, uint32_t size, uint32_t type,
        int i;
 
        ea = UDF_I_DATA(inode);
-       if (UDF_I_LENEATTR(inode))
+       if (UDF_I_LENEATTR(inode)) {
                ad = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode);
-       else
-       {
+       } else {
                ad = ea;
                size += sizeof(struct extendedAttrHeaderDesc);
        }
@@ -70,27 +66,21 @@ udf_add_extendedattr(struct inode * inode, uint32_t size, uint32_t type,
 
        /* TODO - Check for FreeEASpace */
 
-       if (loc & 0x01 && offset >= size)
-       {
+       if (loc & 0x01 && offset >= size) {
                struct extendedAttrHeaderDesc *eahd;
                eahd = (struct extendedAttrHeaderDesc *)ea;
 
-               if (UDF_I_LENALLOC(inode))
-               {
+               if (UDF_I_LENALLOC(inode)) {
                        memmove(&ad[size], ad, UDF_I_LENALLOC(inode));
                }
 
-               if (UDF_I_LENEATTR(inode))
-               {
+               if (UDF_I_LENEATTR(inode)) {
                        /* check checksum/crc */
                        if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD ||
-                               le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum)
-                       {
+                           le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) {
                                return NULL;
                        }
-               }
-               else
-               {
+               } else {
                        size -= sizeof(struct extendedAttrHeaderDesc);
                        UDF_I_LENEATTR(inode) += sizeof(struct extendedAttrHeaderDesc);
                        eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD);
@@ -105,29 +95,23 @@ udf_add_extendedattr(struct inode * inode, uint32_t size, uint32_t type,
                }
 
                offset = UDF_I_LENEATTR(inode);
-               if (type < 2048)
-               {
-                       if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode))
-                       {
+               if (type < 2048) {
+                       if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) {
                                uint32_t aal = le32_to_cpu(eahd->appAttrLocation);
                                memmove(&ea[offset - aal + size],
                                        &ea[aal], offset - aal);
                                offset -= aal;
                                eahd->appAttrLocation = cpu_to_le32(aal + size);
                        }
-                       if (le32_to_cpu(eahd->impAttrLocation) < UDF_I_LENEATTR(inode))
-                       {
+                       if (le32_to_cpu(eahd->impAttrLocation) < UDF_I_LENEATTR(inode)) {
                                uint32_t ial = le32_to_cpu(eahd->impAttrLocation);
                                memmove(&ea[offset - ial + size],
                                        &ea[ial], offset - ial);
                                offset -= ial;
                                eahd->impAttrLocation = cpu_to_le32(ial + size);
                        }
-               }
-               else if (type < 65536)
-               {
-                       if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode))
-                       {
+               } else if (type < 65536) {
+                       if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) {
                                uint32_t aal = le32_to_cpu(eahd->appAttrLocation);
                                memmove(&ea[offset - aal + size],
                                        &ea[aal], offset - aal);
@@ -138,22 +122,23 @@ udf_add_extendedattr(struct inode * inode, uint32_t size, uint32_t type,
                /* rewrite CRC + checksum of eahd */
                crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag);
                eahd->descTag.descCRCLength = cpu_to_le16(crclen);
-               eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd + sizeof(tag), crclen, 0));
+               eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd +
+                                                           sizeof(tag), crclen, 0));
                eahd->descTag.tagChecksum = 0;
-               for (i=0; i<16; i++)
+               for (i = 0; i < 16; i++)
                        if (i != 4)
                                eahd->descTag.tagChecksum += ((uint8_t *)&(eahd->descTag))[i];
                UDF_I_LENEATTR(inode) += size;
                return (struct genericFormat *)&ea[offset];
        }
-       if (loc & 0x02)
-       {
+       if (loc & 0x02) {
        }
+
        return NULL;
 }
 
-struct genericFormat *
-udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype)
+struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
+                                          uint8_t subtype)
 {
        struct genericFormat *gaf;
        uint8_t *ea = NULL;
@@ -161,18 +146,16 @@ udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype)
 
        ea = UDF_I_DATA(inode);
 
-       if (UDF_I_LENEATTR(inode))
-       {
+       if (UDF_I_LENEATTR(inode)) {
                struct extendedAttrHeaderDesc *eahd;
                eahd = (struct extendedAttrHeaderDesc *)ea;
 
                /* check checksum/crc */
                if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD ||
-                       le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum)
-               {
+                   le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) {
                        return NULL;
                }
-       
+
                if (type < 2048)
                        offset = sizeof(struct extendedAttrHeaderDesc);
                else if (type < 65536)
@@ -180,8 +163,7 @@ udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype)
                else
                        offset = le32_to_cpu(eahd->appAttrLocation);
 
-               while (offset < UDF_I_LENEATTR(inode))
-               {
+               while (offset < UDF_I_LENEATTR(inode)) {
                        gaf = (struct genericFormat *)&ea[offset];
                        if (le32_to_cpu(gaf->attrType) == type && gaf->attrSubtype == subtype)
                                return gaf;
@@ -189,6 +171,7 @@ udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype)
                                offset += le32_to_cpu(gaf->attrLength);
                }
        }
+
        return NULL;
 }
 
@@ -202,8 +185,8 @@ udf_get_extendedattr(struct inode *inode, uint32_t type, uint8_t subtype)
  *     July 1, 1997 - Andrew E. Mileski
  *     Written, tested, and released.
  */
-struct buffer_head *
-udf_read_tagged(struct super_block *sb, uint32_t block, uint32_t location, uint16_t *ident)
+struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
+                                   uint32_t location, uint16_t * ident)
 {
        tag *tag_p;
        struct buffer_head *bh = NULL;
@@ -215,9 +198,9 @@ udf_read_tagged(struct super_block *sb, uint32_t block, uint32_t location, uint1
                return NULL;
 
        bh = udf_tread(sb, block + UDF_SB_SESSION(sb));
-       if (!bh)
-       {
-               udf_debug("block=%d, location=%d: read failed\n", block + UDF_SB_SESSION(sb), location);
+       if (!bh) {
+               udf_debug("block=%d, location=%d: read failed\n",
+                         block + UDF_SB_SESSION(sb), location);
                return NULL;
        }
 
@@ -225,13 +208,12 @@ udf_read_tagged(struct super_block *sb, uint32_t block, uint32_t location, uint1
 
        *ident = le16_to_cpu(tag_p->tagIdent);
 
-       if ( location != le32_to_cpu(tag_p->tagLocation) )
-       {
+       if (location != le32_to_cpu(tag_p->tagLocation)) {
                udf_debug("location mismatch block %u, tag %u != %u\n",
-                       block + UDF_SB_SESSION(sb), le32_to_cpu(tag_p->tagLocation), location);
+                         block + UDF_SB_SESSION(sb), le32_to_cpu(tag_p->tagLocation), location);
                goto error_out;
        }
-       
+
        /* Verify the tag checksum */
        checksum = 0U;
        for (i = 0; i < 4; i++)
@@ -245,39 +227,32 @@ udf_read_tagged(struct super_block *sb, uint32_t block, uint32_t location, uint1
 
        /* Verify the tag version */
        if (le16_to_cpu(tag_p->descVersion) != 0x0002U &&
-               le16_to_cpu(tag_p->descVersion) != 0x0003U)
-       {
+           le16_to_cpu(tag_p->descVersion) != 0x0003U) {
                udf_debug("tag version 0x%04x != 0x0002 || 0x0003 block %d\n",
-                       le16_to_cpu(tag_p->descVersion), block);
+                         le16_to_cpu(tag_p->descVersion), block);
                goto error_out;
        }
 
        /* Verify the descriptor CRC */
        if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize ||
-               le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag),
-                       le16_to_cpu(tag_p->descCRCLength), 0))
-       {
+           le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag),
+                                                  le16_to_cpu(tag_p->descCRCLength), 0)) {
                return bh;
        }
        udf_debug("Crc failure block %d: crc = %d, crclen = %d\n",
-               block + UDF_SB_SESSION(sb), le16_to_cpu(tag_p->descCRC), le16_to_cpu(tag_p->descCRCLength));
+                 block + UDF_SB_SESSION(sb), le16_to_cpu(tag_p->descCRC),
+                 le16_to_cpu(tag_p->descCRCLength));
 
 error_out:
        brelse(bh);
        return NULL;
 }
 
-struct buffer_head *
-udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc, uint32_t offset, uint16_t *ident)
+struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc,
+                                    uint32_t offset, uint16_t * ident)
 {
        return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset),
-               loc.logicalBlockNum + offset, ident);
-}
-
-void udf_release_data(struct buffer_head *bh)
-{
-       if (bh)
-               brelse(bh);
+                              loc.logicalBlockNum + offset, ident);
 }
 
 void udf_update_tag(char *data, int length)
@@ -291,13 +266,13 @@ void udf_update_tag(char *data, int length)
        tptr->descCRCLength = cpu_to_le16(length);
        tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0));
 
-       for (i=0; i<16; i++)
+       for (i = 0; i < 16; i++)
                if (i != 4)
                        tptr->tagChecksum += (uint8_t)(data[i]);
 }
 
 void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
-       uint32_t loc, int length)
+                uint32_t loc, int length)
 {
        tag *tptr = (tag *)data;
        tptr->tagIdent = cpu_to_le16(ident);