2 * linux/include/linux/hfs_sysdep.h 4 * Copyright (C) 1996-1997 Paul H. Hargrove 5 * This file may be distributed under the terms of the GNU Public License. 7 * This file contains constants, types and inline 8 * functions for various system dependent things. 10 * "XXX" in a comment is a note to myself to consider changing something. 12 * In function preconditions the term "valid" applied to a pointer to 13 * a structure means that the pointer is non-NULL and the structure it 14 * points to has all fields initialized to consistent values. 20 #include <linux/malloc.h> 21 #include <linux/types.h> 22 #include <linux/locks.h> 25 #include <asm/byteorder.h> 26 #include <asm/unaligned.h> 30 #define offsetof(TYPE, MEMB) ((size_t) &((TYPE *)0)->MEMB) 32 /* Typedefs for integer types by size and signedness */ 34 typedef __u16 hfs_u16
; 35 typedef __u32 hfs_u32
; 37 typedef __s16 hfs_s16
; 38 typedef __s32 hfs_s32
; 40 /* Typedefs for unaligned integer types */ 41 typedefunsigned char hfs_byte_t
; 42 typedefunsigned char hfs_word_t
[2]; 43 typedefunsigned char hfs_lword_t
[4]; 45 /* these funny looking things are GCC variable argument macros */ 46 #define hfs_warn(format, args...) printk(KERN_WARNING format , ## args) 47 #define hfs_error(format, args...) printk(KERN_ERR format , ## args) 50 #if defined(DEBUG_ALL) || defined(DEBUG_MEM) 51 externlong int hfs_alloc
; 54 extern inlinevoid*hfs_malloc(unsigned int size
) { 55 #if defined(DEBUG_ALL) || defined(DEBUG_MEM) 56 hfs_warn("%ld bytes allocation at %s:%u\n", 57 (hfs_alloc
+= size
), __FILE__
, __LINE__
); 59 returnkmalloc(size
, GFP_KERNEL
); 62 extern inlinevoidhfs_free(void*ptr
,unsigned int size
) { 64 #if defined(DEBUG_ALL) || defined(DEBUG_MEM) 65 hfs_warn("%ld bytes allocation at %s:%u\n", 66 (hfs_alloc
-= ptr
? size
:0), __FILE__
, __LINE__
); 71 extern inline hfs_u32
hfs_time(void) { 72 returnhtonl(CURRENT_TIME
+2082844800U); 79 typedefstruct wait_queue
*hfs_wait_queue
; 81 extern inlinevoidhfs_init_waitqueue(hfs_wait_queue
*queue
) { 82 init_waitqueue(queue
); 85 extern inlinevoidhfs_sleep_on(hfs_wait_queue
*queue
) { 89 extern inlinevoidhfs_wake_up(hfs_wait_queue
*queue
) { 93 extern inlinevoidhfs_relinquish(void) { 101 typedefstruct super_block
*hfs_sysmdb
; 103 extern inlinevoidhfs_mdb_dirty(hfs_sysmdb sys_mdb
) { 107 extern inlinechar*hfs_mdb_name(hfs_sysmdb sys_mdb
) { 108 returnkdevname(sys_mdb
->s_dev
); 115 typedefstruct dentry
*hfs_sysentry
[4]; 120 typedefstruct buffer_head
*hfs_buffer
; 122 #define HFS_BAD_BUFFER NULL 124 /* In sysdep.c, since it needs HFS_SECTOR_SIZE */ 125 extern hfs_buffer
hfs_buffer_get(hfs_sysmdb
,int,int); 127 extern inlineinthfs_buffer_ok(hfs_buffer buffer
) { 128 return(buffer
!= NULL
); 131 extern inlinevoidhfs_buffer_put(hfs_buffer buffer
) { 135 extern inlinevoidhfs_buffer_dirty(hfs_buffer buffer
) { 136 mark_buffer_dirty(buffer
,1); 139 extern inlinevoidhfs_buffer_sync(hfs_buffer buffer
) { 140 while(buffer_locked(buffer
)) { 141 wait_on_buffer(buffer
); 143 if(buffer_dirty(buffer
)) { 144 ll_rw_block(WRITE
,1, &buffer
); 145 wait_on_buffer(buffer
); 149 extern inlinevoid*hfs_buffer_data(const hfs_buffer buffer
) { 150 return buffer
->b_data
; 159 #if defined(__BIG_ENDIAN) 160 # define BITNR(X) ((X)^31) 161 # if !defined(__constant_htonl) 162 # define __constant_htonl(x) (x) 164 # if !defined(__constant_htons) 165 # define __constant_htons(x) (x) 167 #elif defined(__LITTLE_ENDIAN) 168 # define BITNR(X) ((X)^7) 169 # if !defined(__constant_htonl) 170 # define __constant_htonl(x) \ 171 ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \ 172 (((unsigned long int)(x) & 0x0000ff00U) << 8) | \ 173 (((unsigned long int)(x) & 0x00ff0000U) >> 8) | \ 174 (((unsigned long int)(x) & 0xff000000U) >> 24))) 176 # if !defined(__constant_htons) 177 # define __constant_htons(x) \ 178 ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \ 179 (((unsigned short int)(x) & 0xff00) >> 8))) 182 # error"Don't know if bytes are big- or little-endian!" 185 extern inlineinthfs_clear_bit(int bitnr
, hfs_u32
*lword
) { 186 returntest_and_clear_bit(BITNR(bitnr
), lword
); 189 extern inlineinthfs_set_bit(int bitnr
, hfs_u32
*lword
) { 190 returntest_and_set_bit(BITNR(bitnr
), lword
); 193 extern inlineinthfs_test_bit(int bitnr
,const hfs_u32
*lword
) { 194 /* the kernel should declare the second arg of test_bit as const */ 195 returntest_bit(BITNR(bitnr
), (void*)lword
); 201 * HFS structures have fields aligned to 16-bit boundaries. 202 * So, 16-bit get/put are easy while 32-bit get/put need 203 * some care on architectures like the DEC Alpha. 206 * ns = 16-bit integer in network byte-order w/ 16-bit alignment 207 * hs = 16-bit integer in host byte-order w/ 16-bit alignment 208 * nl = 32-bit integer in network byte-order w/ unknown alignment 209 * hl = 32-bit integer in host byte-order w/ unknown alignment 210 * anl = 32-bit integer in network byte-order w/ 32-bit alignment 211 * ahl = 32-bit integer in host byte-order w/ 32-bit alignment 212 * Example: hfs_get_hl() gets an unaligned 32-bit integer converting 213 * it to host byte-order. 215 #define hfs_get_hs(addr) ntohs(*((hfs_u16 *)(addr))) 216 #define hfs_get_ns(addr) (*((hfs_u16 *)(addr))) 217 #define hfs_get_hl(addr) ntohl(get_unaligned((hfs_u32 *)(addr))) 218 #define hfs_get_nl(addr) get_unaligned((hfs_u32 *)(addr)) 219 #define hfs_get_ahl(addr) ntohl(*((hfs_u32 *)(addr))) 220 #define hfs_get_anl(addr) (*((hfs_u32 *)(addr))) 221 #define hfs_put_hs(val, addr) ((void)(*((hfs_u16 *)(addr)) = ntohs(val))) 222 #define hfs_put_ns(val, addr) ((void)(*((hfs_u16 *)(addr)) = (val))) 223 #define hfs_put_hl(val, addr) put_unaligned(htonl(val), (hfs_u32 *)(addr)) 224 #define hfs_put_nl(val, addr) put_unaligned((val), (hfs_u32 *)(addr)) 225 #define hfs_put_ahl(val, addr) ((void)(*((hfs_u32 *)(addr)) = ntohl(val))) 226 #define hfs_put_anl(val, addr) ((void)(*((hfs_u32 *)(addr)) = (val)))