~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to disk-utils/cramfs_common.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
 
19
19
#include <string.h>
20
 
#include "cramfs_common.h"
 
20
#include "cramfs.h"
21
21
#include "../include/bitops.h"
22
22
 
23
 
u32 u32_toggle_endianness(int big_endian, u32 what)
 
23
uint32_t u32_toggle_endianness(int big_endian, uint32_t what)
24
24
{
25
25
        return big_endian == HOST_IS_BIG_ENDIAN ? what : swab32(what);
26
26
}
35
35
                super->fsid.crc = swab32(super->fsid.crc);
36
36
                super->fsid.edition = swab32(super->fsid.edition);
37
37
                super->fsid.blocks = swab32(super->fsid.blocks);
38
 
                super->fsid.files = swab32(super->fsid.files);  
 
38
                super->fsid.files = swab32(super->fsid.files);
39
39
        }
40
40
}
41
41
 
42
 
void inode_toggle_endianness(int input_big_endian, int output_big_endian, struct cramfs_inode *inode_in, struct cramfs_inode *inode_out)
 
42
void inode_toggle_endianness(int input_big_endian, int output_big_endian,
 
43
                             struct cramfs_inode *inode_in,
 
44
                             struct cramfs_inode *inode_out)
43
45
{
44
46
        if (input_big_endian == output_big_endian) {
45
47
                memmove(inode_out, inode_in, sizeof(*inode_out));
46
 
        }
47
 
        else {
 
48
        } else {
48
49
                unsigned char inode_out_buf[sizeof(*inode_in)];
49
50
                unsigned char *inode_in_buf = (unsigned char*)inode_in;
50
51
 
52
53
                inode_out_buf[1] = inode_in_buf[0];
53
54
 
54
55
                inode_out_buf[2] = inode_in_buf[3]; /* 16 bit: uid */
55
 
                inode_out_buf[3] = inode_in_buf[2]; 
 
56
                inode_out_buf[3] = inode_in_buf[2];
56
57
 
57
58
                inode_out_buf[4] = inode_in_buf[6]; /* 24 bit: size */
58
59
                inode_out_buf[5] = inode_in_buf[5];
60
61
 
61
62
                inode_out_buf[7] = inode_in_buf[7]; /* 8 bit: gid width */
62
63
 
63
 
                /* Stop the madness! Outlaw C bitfields! They are unportable and nasty!
64
 
                See for yourself what a mess this is: */
65
 
 
 
64
                /*
 
65
                 * Stop the madness! Outlaw C bitfields! They are unportable
 
66
                 * and nasty! See for yourself what a mess this is:
 
67
                 */
66
68
                if (output_big_endian) {
67
 
                        inode_out_buf[ 8] = ( (inode_in_buf[ 8]&0x3F) << 2 ) | 
 
69
                        inode_out_buf[ 8] = ( (inode_in_buf[ 8]&0x3F) << 2 ) |
68
70
                                ( (inode_in_buf[11]&0xC0) >> 6 );
69
71
 
70
72
                        inode_out_buf[ 9] = ( (inode_in_buf[11]&0x3F) << 2 ) |
75
77
 
76
78
                        inode_out_buf[11] = ( (inode_in_buf[ 9]&0x3F) << 2 ) |
77
79
                                ( (inode_in_buf[ 8]&0xC0) >> 6 );
78
 
                }
79
 
                else {
80
 
                        inode_out_buf[ 8] = ( (inode_in_buf[ 8]&0xFD) >> 2 ) | 
 
80
                } else {
 
81
                        inode_out_buf[ 8] = ( (inode_in_buf[ 8]&0xFD) >> 2 ) |
81
82
                                ( (inode_in_buf[11]&0x03) << 6 );
82
83
 
83
 
                        inode_out_buf[ 9] = ( (inode_in_buf[11]&0xFD) >> 2 ) | 
 
84
                        inode_out_buf[ 9] = ( (inode_in_buf[11]&0xFD) >> 2 ) |
84
85
                                ( (inode_in_buf[10]&0x03) << 6 );
85
86
 
86
 
                        inode_out_buf[10] = ( (inode_in_buf[10]&0xFD) >> 2 ) | 
 
87
                        inode_out_buf[10] = ( (inode_in_buf[10]&0xFD) >> 2 ) |
87
88
                                ( (inode_in_buf[ 9]&0x03) << 6 );
88
89
 
89
 
                        inode_out_buf[11] = ( (inode_in_buf[ 9]&0xFD) >> 2 ) | 
 
90
                        inode_out_buf[11] = ( (inode_in_buf[ 9]&0xFD) >> 2 ) |
90
91
                                ( (inode_in_buf[ 8]&0x03) << 6 );
91
92
                }
92
 
 
93
93
                memmove(inode_out, inode_out_buf, sizeof(*inode_out));
94
94
        }
95
95
}
96
96
 
97
 
void inode_to_host(int from_big_endian, struct cramfs_inode *inode_in, struct cramfs_inode *inode_out)
 
97
void inode_to_host(int from_big_endian, struct cramfs_inode *inode_in,
 
98
                   struct cramfs_inode *inode_out)
98
99
{
99
 
        inode_toggle_endianness(from_big_endian, HOST_IS_BIG_ENDIAN, inode_in, inode_out);
 
100
        inode_toggle_endianness(from_big_endian, HOST_IS_BIG_ENDIAN, inode_in,
 
101
                                inode_out);
100
102
}
101
103
 
102
 
void inode_from_host(int to_big_endian, struct cramfs_inode *inode_in, struct cramfs_inode *inode_out)
 
104
void inode_from_host(int to_big_endian, struct cramfs_inode *inode_in,
 
105
                     struct cramfs_inode *inode_out)
103
106
{
104
 
        inode_toggle_endianness(HOST_IS_BIG_ENDIAN, to_big_endian, inode_in, inode_out);
 
107
        inode_toggle_endianness(HOST_IS_BIG_ENDIAN, to_big_endian, inode_in,
 
108
                                inode_out);
105
109
}