cramfs: use stdint.h instead of u{8,16,32}

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-07-20 22:00:02 +02:00
parent fc2798c50b
commit d51f37a368
4 changed files with 23 additions and 24 deletions

View File

@ -19,9 +19,7 @@
#ifndef __CRAMFS_H #ifndef __CRAMFS_H
#define __CRAMFS_H #define __CRAMFS_H
typedef unsigned char u8; #include <stdint.h>
typedef unsigned short u16;
typedef unsigned int u32;
#define CRAMFS_MAGIC 0x28cd3d45 /* some random number */ #define CRAMFS_MAGIC 0x28cd3d45 /* some random number */
#define CRAMFS_SIGNATURE "Compressed ROMFS" #define CRAMFS_SIGNATURE "Compressed ROMFS"
@ -49,9 +47,9 @@ typedef unsigned int u32;
* Reasonably terse representation of the inode data. * Reasonably terse representation of the inode data.
*/ */
struct cramfs_inode { struct cramfs_inode {
u32 mode:16, uid:16; uint32_t mode:16, uid:16;
/* SIZE for device files is i_rdev */ /* SIZE for device files is i_rdev */
u32 size:24, gid:8; uint32_t size:24, gid:8;
/* NAMELEN is the length of the file name, divided by 4 and /* NAMELEN is the length of the file name, divided by 4 and
rounded up. (cramfs doesn't support hard links.) */ rounded up. (cramfs doesn't support hard links.) */
/* OFFSET: For symlinks and non-empty regular files, this /* OFFSET: For symlinks and non-empty regular files, this
@ -60,28 +58,28 @@ struct cramfs_inode {
see README). For non-empty directories it is the offset see README). For non-empty directories it is the offset
(divided by 4) of the inode of the first file in that (divided by 4) of the inode of the first file in that
directory. For anything else, offset is zero. */ directory. For anything else, offset is zero. */
u32 namelen:6, offset:26; uint32_t namelen:6, offset:26;
}; };
struct cramfs_info { struct cramfs_info {
u32 crc; uint32_t crc;
u32 edition; uint32_t edition;
u32 blocks; uint32_t blocks;
u32 files; uint32_t files;
}; };
/* /*
* Superblock information at the beginning of the FS. * Superblock information at the beginning of the FS.
*/ */
struct cramfs_super { struct cramfs_super {
u32 magic; /* 0x28cd3d45 - random number */ uint32_t magic; /* 0x28cd3d45 - random number */
u32 size; /* Not used. mkcramfs currently uint32_t size; /* Not used. mkcramfs currently
writes a constant 1<<16 here. */ writes a constant 1<<16 here. */
u32 flags; /* 0 */ uint32_t flags; /* 0 */
u32 future; /* 0 */ uint32_t future; /* 0 */
u8 signature[16]; /* "Compressed ROMFS" */ uint8_t signature[16]; /* "Compressed ROMFS" */
struct cramfs_info fsid;/* unique filesystem info */ struct cramfs_info fsid;/* unique filesystem info */
u8 name[16]; /* user-defined name */ uint8_t name[16]; /* user-defined name */
struct cramfs_inode root; /* Root inode data */ struct cramfs_inode root; /* Root inode data */
}; };
@ -103,7 +101,7 @@ int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen);
int cramfs_uncompress_init(void); int cramfs_uncompress_init(void);
int cramfs_uncompress_exit(void); int cramfs_uncompress_exit(void);
u32 u32_toggle_endianness(int big_endian, u32 what); uint32_t u32_toggle_endianness(int big_endian, uint32_t what);
void super_toggle_endianness(int from_big_endian, struct cramfs_super *super); void super_toggle_endianness(int from_big_endian, struct cramfs_super *super);
void inode_to_host(int from_big_endian, struct cramfs_inode *inode_in, struct cramfs_inode *inode_out); void inode_to_host(int from_big_endian, struct cramfs_inode *inode_in, struct cramfs_inode *inode_out);
void inode_from_host(int to_big_endian, struct cramfs_inode *inode_in, struct cramfs_inode *inode_out); void inode_from_host(int to_big_endian, struct cramfs_inode *inode_in, struct cramfs_inode *inode_out);

View File

@ -20,7 +20,7 @@
#include "cramfs.h" #include "cramfs.h"
#include "../include/bitops.h" #include "../include/bitops.h"
u32 u32_toggle_endianness(int big_endian, u32 what) uint32_t u32_toggle_endianness(int big_endian, uint32_t what)
{ {
return big_endian == HOST_IS_BIG_ENDIAN ? what : swab32(what); return big_endian == HOST_IS_BIG_ENDIAN ? what : swab32(what);
} }

View File

@ -38,6 +38,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h>
#include <unistd.h> #include <unistd.h>
#include <dirent.h> #include <dirent.h>
#include <stdlib.h> #include <stdlib.h>
@ -139,7 +140,7 @@ static void die(int status, int syserr, const char *fmt, ...)
exit(status); exit(status);
} }
int get_superblock_endianness(u32 magic) int get_superblock_endianness(uint32_t magic)
{ {
if (magic == CRAMFS_MAGIC) { if (magic == CRAMFS_MAGIC) {
cramfs_is_big_endian = HOST_IS_BIG_ENDIAN; cramfs_is_big_endian = HOST_IS_BIG_ENDIAN;
@ -236,7 +237,7 @@ static void test_super(int *start, size_t *length) {
static void test_crc(int start) static void test_crc(int start)
{ {
void *buf; void *buf;
u32 crc; uint32_t crc;
if (!(super.flags & CRAMFS_FLAG_FSID_VERSION_2)) { if (!(super.flags & CRAMFS_FLAG_FSID_VERSION_2)) {
#ifdef INCLUDE_FS_TESTS #ifdef INCLUDE_FS_TESTS
@ -402,7 +403,7 @@ static void do_uncompress(char *path, int fd, unsigned long offset, unsigned lon
do { do {
unsigned long out = page_size; unsigned long out = page_size;
unsigned long next = u32_toggle_endianness(cramfs_is_big_endian, *(u32 *) romfs_read(offset)); unsigned long next = u32_toggle_endianness(cramfs_is_big_endian, *(uint32_t *) romfs_read(offset));
if (next > end_data) { if (next > end_data) {
end_data = next; end_data = next;
@ -563,7 +564,7 @@ static void do_symlink(char *path, struct cramfs_inode *i)
{ {
unsigned long offset = i->offset << 2; unsigned long offset = i->offset << 2;
unsigned long curr = offset + 4; unsigned long curr = offset + 4;
unsigned long next = u32_toggle_endianness(cramfs_is_big_endian, *(u32 *) romfs_read(offset)); unsigned long next = u32_toggle_endianness(cramfs_is_big_endian, *(uint32_t *) romfs_read(offset));
unsigned long size; unsigned long size;
if (offset == 0) { if (offset == 0) {

View File

@ -634,7 +634,7 @@ do_compress(char *base, unsigned int offset, unsigned char const *name,
exit(MKFS_ERROR); exit(MKFS_ERROR);
} }
*(u32 *) (base + offset) = u32_toggle_endianness(cramfs_is_big_endian, curr); *(uint32_t *) (base + offset) = u32_toggle_endianness(cramfs_is_big_endian, curr);
offset += 4; offset += 4;
} while (size); } while (size);
@ -736,7 +736,7 @@ int main(int argc, char **argv)
loff_t fslen_ub = sizeof(struct cramfs_super); loff_t fslen_ub = sizeof(struct cramfs_super);
unsigned int fslen_max; unsigned int fslen_max;
char const *dirname, *outfile; char const *dirname, *outfile;
u32 crc = crc32(0L, Z_NULL, 0); uint32_t crc = crc32(0L, Z_NULL, 0);
int c; int c;
cramfs_is_big_endian = HOST_IS_BIG_ENDIAN; /* default is to use host order */ cramfs_is_big_endian = HOST_IS_BIG_ENDIAN; /* default is to use host order */