Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
422 giacomo 1
/*
2
 * linux/include/linux/hfs_sysdep.h
3
 *
4
 * Copyright (C) 1996-1997  Paul H. Hargrove
5
 * This file may be distributed under the terms of the GNU General Public License.
6
 *
7
 * This file contains constants, types and inline
8
 * functions for various system dependent things.
9
 *
10
 * "XXX" in a comment is a note to myself to consider changing something.
11
 *
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.
15
 */
16
 
17
#ifndef _HFS_SYSDEP_H
18
#define _HFS_SYSDEP_H
19
 
20
#include <linux/slab.h>
21
#include <linux/types.h>
22
#include <linux/fs.h>
23
#include <linux/sched.h>
24
#include <linux/buffer_head.h>
25
 
26
#include <asm/byteorder.h>
27
#include <asm/unaligned.h>
28
 
29
extern struct timezone sys_tz;
30
 
31
/* Typedefs for integer types by size and signedness */
32
typedef __u8            hfs_u8;
33
typedef __u16           hfs_u16;
34
typedef __u32           hfs_u32;
35
typedef __s8            hfs_s8;
36
typedef __s16           hfs_s16;
37
typedef __s32           hfs_s32;
38
 
39
/* Typedefs for unaligned integer types */
40
typedef unsigned char hfs_byte_t;
41
typedef unsigned char hfs_word_t[2];
42
typedef unsigned char hfs_lword_t[4];
43
 
44
/* these funny looking things are GCC variable argument macros */
45
#define hfs_warn(format, args...) printk(KERN_WARNING format , ## args)
46
#define hfs_error(format, args...) printk(KERN_ERR format , ## args)
47
 
48
 
49
#if defined(DEBUG_ALL) || defined(DEBUG_MEM)
50
extern long int hfs_alloc;
51
#endif
52
 
53
static inline void *hfs_malloc(unsigned int size) {
54
#if defined(DEBUG_ALL) || defined(DEBUG_MEM)
55
        hfs_warn("%ld bytes allocation at %s:%u\n",
56
                 (hfs_alloc += size), __FILE__, __LINE__);
57
#endif
58
        return kmalloc(size, GFP_KERNEL);
59
}
60
 
61
static inline void hfs_free(void *ptr, unsigned int size) {
62
        kfree(ptr);
63
#if defined(DEBUG_ALL) || defined(DEBUG_MEM)
64
        hfs_warn("%ld bytes allocation at %s:%u\n",
65
                  (hfs_alloc -= ptr ? size : 0), __FILE__, __LINE__);
66
#endif
67
}
68
 
69
 
70
/* handle conversion between times.
71
 *
72
 * NOTE: hfs+ doesn't need this. also, we don't use tz_dsttime as that's
73
 *       not a good thing to do. instead, we depend upon tz_minuteswest
74
 *       having the correct daylight savings correction.
75
 */
76
static inline hfs_u32 hfs_from_utc(hfs_s32 time)
77
{
78
        return time - sys_tz.tz_minuteswest*60;
79
}
80
 
81
static inline hfs_s32 hfs_to_utc(hfs_u32 time)
82
{
83
        return time + sys_tz.tz_minuteswest*60;
84
}
85
 
86
static inline hfs_u32 hfs_time(void) {
87
        return htonl(hfs_from_utc(get_seconds())+2082844800U);
88
}
89
 
90
 
91
/*
92
 * hfs_wait_queue
93
 */
94
typedef wait_queue_head_t hfs_wait_queue;
95
 
96
static inline void hfs_init_waitqueue(hfs_wait_queue *queue) {
97
        init_waitqueue_head(queue);
98
}
99
 
100
static inline void hfs_sleep_on(hfs_wait_queue *queue) {
101
        sleep_on(queue);
102
}
103
 
104
static inline void hfs_wake_up(hfs_wait_queue *queue) {
105
        wake_up(queue);
106
}
107
 
108
static inline void hfs_relinquish(void) {
109
        schedule();
110
}
111
 
112
 
113
/*
114
 * hfs_sysmdb
115
 */
116
typedef struct super_block *hfs_sysmdb;
117
 
118
static inline void hfs_mdb_dirty(hfs_sysmdb sys_mdb) {
119
        sys_mdb->s_dirt = 1;
120
}
121
 
122
static inline const char *hfs_mdb_name(hfs_sysmdb sys_mdb) {
123
        return sys_mdb->s_id;
124
}
125
 
126
 
127
/*
128
 * hfs_sysentry
129
 */
130
typedef struct dentry *hfs_sysentry[4];
131
 
132
/*
133
 * hfs_buffer
134
 */
135
typedef struct buffer_head *hfs_buffer;
136
 
137
#define HFS_BAD_BUFFER NULL
138
 
139
/* In sysdep.c, since it needs HFS_SECTOR_SIZE */
140
extern hfs_buffer hfs_buffer_get(hfs_sysmdb, int, int);
141
 
142
static inline int hfs_buffer_ok(hfs_buffer buffer) {
143
        return (buffer != NULL);
144
}
145
 
146
static inline void hfs_buffer_put(hfs_buffer buffer) {
147
        brelse(buffer);
148
}
149
 
150
static inline void hfs_buffer_dirty(hfs_buffer buffer) {
151
        mark_buffer_dirty(buffer);
152
}
153
 
154
static inline void hfs_buffer_sync(hfs_buffer buffer) {
155
        if (buffer_dirty(buffer))
156
                sync_dirty_buffer(buffer);
157
}
158
 
159
static inline void *hfs_buffer_data(const hfs_buffer buffer) {
160
        return buffer->b_data;
161
}
162
 
163
 
164
/*
165
 * bit operations
166
 */
167
 
168
#undef BITNR
169
#if defined(__BIG_ENDIAN)
170
#       define BITNR(X) ((X)^31)
171
#       if !defined(__constant_htonl)
172
#               define __constant_htonl(x) (x)
173
#       endif
174
#       if !defined(__constant_htons)
175
#               define __constant_htons(x) (x)
176
#       endif
177
#elif defined(__LITTLE_ENDIAN)
178
#       define BITNR(X) ((X)^7)
179
#       if !defined(__constant_htonl)
180
#               define __constant_htonl(x) \
181
        ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
182
                             (((unsigned long int)(x) & 0x0000ff00U) <<  8) | \
183
                             (((unsigned long int)(x) & 0x00ff0000U) >>  8) | \
184
                             (((unsigned long int)(x) & 0xff000000U) >> 24)))
185
#       endif
186
#       if !defined(__constant_htons)
187
#               define __constant_htons(x) \
188
        ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
189
                              (((unsigned short int)(x) & 0xff00) >> 8)))
190
#       endif
191
#else
192
#       error "Don't know if bytes are big- or little-endian!"
193
#endif
194
 
195
static inline int hfs_clear_bit(int bitnr, hfs_u32 *lword) {
196
        return test_and_clear_bit(BITNR(bitnr), (unsigned long *)lword);
197
}
198
 
199
static inline int hfs_set_bit(int bitnr, hfs_u32 *lword) {
200
        return test_and_set_bit(BITNR(bitnr), (unsigned long *)lword);
201
}
202
 
203
static inline int hfs_test_bit(int bitnr, const hfs_u32 *lword) {
204
        /* the kernel should declare the second arg of test_bit as const */
205
        return test_bit(BITNR(bitnr), (unsigned long *)lword);
206
}
207
 
208
#undef BITNR
209
 
210
/*
211
 * HFS structures have fields aligned to 16-bit boundaries.
212
 * So, 16-bit get/put are easy while 32-bit get/put need
213
 * some care on architectures like the DEC Alpha.
214
 *
215
 * In what follows:
216
 *      ns  = 16-bit integer in network byte-order w/ 16-bit alignment
217
 *      hs  = 16-bit integer in host byte-order w/ 16-bit alignment
218
 *      nl  = 32-bit integer in network byte-order w/ unknown alignment
219
 *      hl  = 32-bit integer in host byte-order w/ unknown alignment
220
 *      anl = 32-bit integer in network byte-order w/ 32-bit alignment
221
 *      ahl = 32-bit integer in host byte-order w/ 32-bit alignment
222
 * Example: hfs_get_hl() gets an unaligned 32-bit integer converting
223
 *      it to host byte-order.
224
 */
225
#define hfs_get_hs(addr)        ntohs(*((hfs_u16 *)(addr)))
226
#define hfs_get_ns(addr)        (*((hfs_u16 *)(addr)))
227
#define hfs_get_hl(addr)        ntohl(get_unaligned((hfs_u32 *)(addr)))
228
#define hfs_get_nl(addr)        get_unaligned((hfs_u32 *)(addr))
229
#define hfs_get_ahl(addr)       ntohl(*((hfs_u32 *)(addr)))
230
#define hfs_get_anl(addr)       (*((hfs_u32 *)(addr)))
231
#define hfs_put_hs(val, addr)   ((void)(*((hfs_u16 *)(addr)) = ntohs(val)))
232
#define hfs_put_ns(val, addr)   ((void)(*((hfs_u16 *)(addr)) = (val)))
233
#define hfs_put_hl(val, addr)   put_unaligned(htonl(val), (hfs_u32 *)(addr))
234
#define hfs_put_nl(val, addr)   put_unaligned((val), (hfs_u32 *)(addr))
235
#define hfs_put_ahl(val, addr)  ((void)(*((hfs_u32 *)(addr)) = ntohl(val)))
236
#define hfs_put_anl(val, addr)  ((void)(*((hfs_u32 *)(addr)) = (val)))
237
 
238
#endif