blob: 79a340a1909e19f44d5f925a5fb589894b0f241d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/ufs/util.h
3 *
4 * Copyright (C) 1998
5 * Daniel Pirkl <daniel.pirkl@email.cz>
6 * Charles University, Faculty of Mathematics and Physics
7 */
8
9#include <linux/buffer_head.h>
10#include <linux/fs.h>
11#include "swab.h"
12
13
14/*
15 * some useful macros
16 */
17#define in_range(b,first,len) ((b)>=(first)&&(b)<(first)+(len))
18
19/*
Evgeniy Dushistov9695ef12006-06-25 05:47:22 -070020 * functions used for retyping
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 */
Evgeniy Dushistov9695ef12006-06-25 05:47:22 -070022static inline struct ufs_buffer_head *UCPI_UBH(struct ufs_cg_private_info *cpi)
23{
24 return &cpi->c_ubh;
25}
26static inline struct ufs_buffer_head *USPI_UBH(struct ufs_sb_private_info *spi)
27{
28 return &spi->s_ubh;
29}
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31
32
33/*
34 * macros used for accessing structures
35 */
36static inline s32
37ufs_get_fs_state(struct super_block *sb, struct ufs_super_block_first *usb1,
38 struct ufs_super_block_third *usb3)
39{
40 switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
41 case UFS_ST_SUN:
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -070042 return fs32_to_cpu(sb, usb3->fs_un2.fs_sun.fs_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 case UFS_ST_SUNx86:
44 return fs32_to_cpu(sb, usb1->fs_u1.fs_sunx86.fs_state);
45 case UFS_ST_44BSD:
46 default:
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -070047 return fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 }
49}
50
51static inline void
52ufs_set_fs_state(struct super_block *sb, struct ufs_super_block_first *usb1,
53 struct ufs_super_block_third *usb3, s32 value)
54{
55 switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
56 case UFS_ST_SUN:
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -070057 usb3->fs_un2.fs_sun.fs_state = cpu_to_fs32(sb, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 break;
59 case UFS_ST_SUNx86:
60 usb1->fs_u1.fs_sunx86.fs_state = cpu_to_fs32(sb, value);
61 break;
62 case UFS_ST_44BSD:
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -070063 usb3->fs_un2.fs_44.fs_state = cpu_to_fs32(sb, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 break;
65 }
66}
67
68static inline u32
69ufs_get_fs_npsect(struct super_block *sb, struct ufs_super_block_first *usb1,
70 struct ufs_super_block_third *usb3)
71{
72 if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -070073 return fs32_to_cpu(sb, usb3->fs_un2.fs_sunx86.fs_npsect);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 else
75 return fs32_to_cpu(sb, usb1->fs_u1.fs_sun.fs_npsect);
76}
77
78static inline u64
79ufs_get_fs_qbmask(struct super_block *sb, struct ufs_super_block_third *usb3)
80{
81 __fs64 tmp;
82
83 switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
84 case UFS_ST_SUN:
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -070085 ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sun.fs_qbmask[0];
86 ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sun.fs_qbmask[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 break;
88 case UFS_ST_SUNx86:
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -070089 ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sunx86.fs_qbmask[0];
90 ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sunx86.fs_qbmask[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 break;
92 case UFS_ST_44BSD:
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -070093 ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_44.fs_qbmask[0];
94 ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_44.fs_qbmask[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 break;
96 }
97
98 return fs64_to_cpu(sb, tmp);
99}
100
101static inline u64
102ufs_get_fs_qfmask(struct super_block *sb, struct ufs_super_block_third *usb3)
103{
104 __fs64 tmp;
105
106 switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
107 case UFS_ST_SUN:
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700108 ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sun.fs_qfmask[0];
109 ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sun.fs_qfmask[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 break;
111 case UFS_ST_SUNx86:
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700112 ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sunx86.fs_qfmask[0];
113 ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sunx86.fs_qfmask[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 break;
115 case UFS_ST_44BSD:
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700116 ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_44.fs_qfmask[0];
117 ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_44.fs_qfmask[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 break;
119 }
120
121 return fs64_to_cpu(sb, tmp);
122}
123
124static inline u16
125ufs_get_de_namlen(struct super_block *sb, struct ufs_dir_entry *de)
126{
127 if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) == UFS_DE_OLD)
128 return fs16_to_cpu(sb, de->d_u.d_namlen);
129 else
130 return de->d_u.d_44.d_namlen; /* XXX this seems wrong */
131}
132
133static inline void
134ufs_set_de_namlen(struct super_block *sb, struct ufs_dir_entry *de, u16 value)
135{
136 if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) == UFS_DE_OLD)
137 de->d_u.d_namlen = cpu_to_fs16(sb, value);
138 else
139 de->d_u.d_44.d_namlen = value; /* XXX this seems wrong */
140}
141
142static inline void
143ufs_set_de_type(struct super_block *sb, struct ufs_dir_entry *de, int mode)
144{
145 if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) != UFS_DE_44BSD)
146 return;
147
148 /*
149 * TODO turn this into a table lookup
150 */
151 switch (mode & S_IFMT) {
152 case S_IFSOCK:
153 de->d_u.d_44.d_type = DT_SOCK;
154 break;
155 case S_IFLNK:
156 de->d_u.d_44.d_type = DT_LNK;
157 break;
158 case S_IFREG:
159 de->d_u.d_44.d_type = DT_REG;
160 break;
161 case S_IFBLK:
162 de->d_u.d_44.d_type = DT_BLK;
163 break;
164 case S_IFDIR:
165 de->d_u.d_44.d_type = DT_DIR;
166 break;
167 case S_IFCHR:
168 de->d_u.d_44.d_type = DT_CHR;
169 break;
170 case S_IFIFO:
171 de->d_u.d_44.d_type = DT_FIFO;
172 break;
173 default:
174 de->d_u.d_44.d_type = DT_UNKNOWN;
175 }
176}
177
178static inline u32
179ufs_get_inode_uid(struct super_block *sb, struct ufs_inode *inode)
180{
181 switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
182 case UFS_UID_EFT:
183 return fs32_to_cpu(sb, inode->ui_u3.ui_sun.ui_uid);
184 case UFS_UID_44BSD:
185 return fs32_to_cpu(sb, inode->ui_u3.ui_44.ui_uid);
186 default:
187 return fs16_to_cpu(sb, inode->ui_u1.oldids.ui_suid);
188 }
189}
190
191static inline void
192ufs_set_inode_uid(struct super_block *sb, struct ufs_inode *inode, u32 value)
193{
194 switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
195 case UFS_UID_EFT:
196 inode->ui_u3.ui_sun.ui_uid = cpu_to_fs32(sb, value);
197 break;
198 case UFS_UID_44BSD:
199 inode->ui_u3.ui_44.ui_uid = cpu_to_fs32(sb, value);
200 break;
201 }
202 inode->ui_u1.oldids.ui_suid = cpu_to_fs16(sb, value);
203}
204
205static inline u32
206ufs_get_inode_gid(struct super_block *sb, struct ufs_inode *inode)
207{
208 switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
209 case UFS_UID_EFT:
210 return fs32_to_cpu(sb, inode->ui_u3.ui_sun.ui_gid);
211 case UFS_UID_44BSD:
212 return fs32_to_cpu(sb, inode->ui_u3.ui_44.ui_gid);
213 default:
214 return fs16_to_cpu(sb, inode->ui_u1.oldids.ui_sgid);
215 }
216}
217
218static inline void
219ufs_set_inode_gid(struct super_block *sb, struct ufs_inode *inode, u32 value)
220{
221 switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
222 case UFS_UID_EFT:
223 inode->ui_u3.ui_sun.ui_gid = cpu_to_fs32(sb, value);
224 break;
225 case UFS_UID_44BSD:
226 inode->ui_u3.ui_44.ui_gid = cpu_to_fs32(sb, value);
227 break;
228 }
229 inode->ui_u1.oldids.ui_sgid = cpu_to_fs16(sb, value);
230}
231
232extern dev_t ufs_get_inode_dev(struct super_block *, struct ufs_inode_info *);
233extern void ufs_set_inode_dev(struct super_block *, struct ufs_inode_info *, dev_t);
Nick Piggin82b9d1d2007-10-16 01:25:19 -0700234extern int __ufs_write_begin(struct file *file, struct address_space *mapping,
235 loff_t pos, unsigned len, unsigned flags,
236 struct page **pagep, void **fsdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238/*
239 * These functions manipulate ufs buffers
240 */
241#define ubh_bread(sb,fragment,size) _ubh_bread_(uspi,sb,fragment,size)
242extern struct ufs_buffer_head * _ubh_bread_(struct ufs_sb_private_info *, struct super_block *, u64 , u64);
243extern struct ufs_buffer_head * ubh_bread_uspi(struct ufs_sb_private_info *, struct super_block *, u64, u64);
244extern void ubh_brelse (struct ufs_buffer_head *);
245extern void ubh_brelse_uspi (struct ufs_sb_private_info *);
246extern void ubh_mark_buffer_dirty (struct ufs_buffer_head *);
247extern void ubh_mark_buffer_uptodate (struct ufs_buffer_head *, int);
Evgeniy Dushistov098d5af2006-06-25 05:47:31 -0700248extern void ubh_ll_rw_block(int, struct ufs_buffer_head *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249extern void ubh_wait_on_buffer (struct ufs_buffer_head *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250extern void ubh_bforget (struct ufs_buffer_head *);
251extern int ubh_buffer_dirty (struct ufs_buffer_head *);
252#define ubh_ubhcpymem(mem,ubh,size) _ubh_ubhcpymem_(uspi,mem,ubh,size)
253extern void _ubh_ubhcpymem_(struct ufs_sb_private_info *, unsigned char *, struct ufs_buffer_head *, unsigned);
254#define ubh_memcpyubh(ubh,mem,size) _ubh_memcpyubh_(uspi,ubh,mem,size)
255extern void _ubh_memcpyubh_(struct ufs_sb_private_info *, struct ufs_buffer_head *, unsigned char *, unsigned);
256
Evgeniy Dushistov10e5dce2006-07-01 04:36:24 -0700257/* This functions works with cache pages*/
258extern struct page *ufs_get_locked_page(struct address_space *mapping,
259 pgoff_t index);
260static inline void ufs_put_locked_page(struct page *page)
261{
262 unlock_page(page);
263 page_cache_release(page);
264}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
266
267/*
Evgeniy7b4ee732006-01-14 11:42:06 +0300268 * macros and inline function to get important structures from ufs_sb_private_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Evgeniy7b4ee732006-01-14 11:42:06 +0300271static inline void *get_usb_offset(struct ufs_sb_private_info *uspi,
272 unsigned int offset)
273{
274 unsigned int index;
275
276 index = offset >> uspi->s_fshift;
277 offset &= ~uspi->s_fmask;
278 return uspi->s_ubh.bh[index]->b_data + offset;
279}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Evgeniy7b4ee732006-01-14 11:42:06 +0300281#define ubh_get_usb_first(uspi) \
282 ((struct ufs_super_block_first *)get_usb_offset((uspi), 0))
283
284#define ubh_get_usb_second(uspi) \
285 ((struct ufs_super_block_second *)get_usb_offset((uspi), UFS_SECTOR_SIZE))
286
287#define ubh_get_usb_third(uspi) \
288 ((struct ufs_super_block_third *)get_usb_offset((uspi), 2*UFS_SECTOR_SIZE))
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291#define ubh_get_ucg(ubh) \
292 ((struct ufs_cylinder_group *)((ubh)->bh[0]->b_data))
293
294
295/*
296 * Extract byte from ufs_buffer_head
297 * Extract the bits for a block from a map inside ufs_buffer_head
298 */
299#define ubh_get_addr8(ubh,begin) \
300 ((u8*)(ubh)->bh[(begin) >> uspi->s_fshift]->b_data + \
301 ((begin) & ~uspi->s_fmask))
302
303#define ubh_get_addr16(ubh,begin) \
304 (((__fs16*)((ubh)->bh[(begin) >> (uspi->s_fshift-1)]->b_data)) + \
Mariusz Kozlowski71a3d1b2006-12-06 20:40:09 -0800305 ((begin) & ((uspi->fsize>>1) - 1)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307#define ubh_get_addr32(ubh,begin) \
308 (((__fs32*)((ubh)->bh[(begin) >> (uspi->s_fshift-2)]->b_data)) + \
309 ((begin) & ((uspi->s_fsize>>2) - 1)))
310
Evgeniy Dushistov54fb9962007-02-12 00:54:32 -0800311#define ubh_get_addr64(ubh,begin) \
312 (((__fs64*)((ubh)->bh[(begin) >> (uspi->s_fshift-3)]->b_data)) + \
313 ((begin) & ((uspi->s_fsize>>3) - 1)))
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#define ubh_get_addr ubh_get_addr8
316
Evgeniy Dushistov54fb9962007-02-12 00:54:32 -0800317static inline void *ubh_get_data_ptr(struct ufs_sb_private_info *uspi,
318 struct ufs_buffer_head *ubh,
319 u64 blk)
320{
321 if (uspi->fs_magic == UFS2_MAGIC)
322 return ubh_get_addr64(ubh, blk);
323 else
324 return ubh_get_addr32(ubh, blk);
325}
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327#define ubh_blkmap(ubh,begin,bit) \
328 ((*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) >> ((bit) & 7)) & (0xff >> (UFS_MAXFRAG - uspi->s_fpb)))
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330/*
331 * Determine the number of available frags given a
332 * percentage to hold in reserve.
333 */
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700334static inline u64
335ufs_freespace(struct ufs_sb_private_info *uspi, int percentreserved)
336{
337 return ufs_blkstofrags(uspi->cs_total.cs_nbfree) +
338 uspi->cs_total.cs_nffree -
339 (uspi->s_dsize * (percentreserved) / 100);
340}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342/*
343 * Macros to access cylinder group array structures
344 */
345#define ubh_cg_blktot(ucpi,cylno) \
Evgeniy Dushistov9695ef12006-06-25 05:47:22 -0700346 (*((__fs32*)ubh_get_addr(UCPI_UBH(ucpi), (ucpi)->c_btotoff + ((cylno) << 2))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348#define ubh_cg_blks(ucpi,cylno,rpos) \
Evgeniy Dushistov9695ef12006-06-25 05:47:22 -0700349 (*((__fs16*)ubh_get_addr(UCPI_UBH(ucpi), \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 (ucpi)->c_boff + (((cylno) * uspi->s_nrpos + (rpos)) << 1 ))))
351
352/*
353 * Bitmap operations
354 * These functions work like classical bitmap operations.
355 * The difference is that we don't have the whole bitmap
356 * in one contiguous chunk of memory, but in several buffers.
357 * The parameters of each function are super_block, ufs_buffer_head and
358 * position of the beginning of the bitmap.
359 */
360#define ubh_setbit(ubh,begin,bit) \
361 (*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) |= (1 << ((bit) & 7)))
362
363#define ubh_clrbit(ubh,begin,bit) \
364 (*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) &= ~(1 << ((bit) & 7)))
365
366#define ubh_isset(ubh,begin,bit) \
367 (*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) & (1 << ((bit) & 7)))
368
369#define ubh_isclr(ubh,begin,bit) (!ubh_isset(ubh,begin,bit))
370
371#define ubh_find_first_zero_bit(ubh,begin,size) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,0)
372
373#define ubh_find_next_zero_bit(ubh,begin,size,offset) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,offset)
374static inline unsigned _ubh_find_next_zero_bit_(
375 struct ufs_sb_private_info * uspi, struct ufs_buffer_head * ubh,
376 unsigned begin, unsigned size, unsigned offset)
377{
378 unsigned base, count, pos;
379
380 size -= offset;
381 begin <<= 3;
382 offset += begin;
383 base = offset >> uspi->s_bpfshift;
384 offset &= uspi->s_bpfmask;
385 for (;;) {
386 count = min_t(unsigned int, size + offset, uspi->s_bpf);
387 size -= count - offset;
388 pos = ext2_find_next_zero_bit (ubh->bh[base]->b_data, count, offset);
389 if (pos < count || !size)
390 break;
391 base++;
392 offset = 0;
393 }
394 return (base << uspi->s_bpfshift) + pos - begin;
395}
396
397static inline unsigned find_last_zero_bit (unsigned char * bitmap,
398 unsigned size, unsigned offset)
399{
400 unsigned bit, i;
401 unsigned char * mapp;
402 unsigned char map;
403
404 mapp = bitmap + (size >> 3);
405 map = *mapp--;
406 bit = 1 << (size & 7);
407 for (i = size; i > offset; i--) {
408 if ((map & bit) == 0)
409 break;
410 if ((i & 7) != 0) {
411 bit >>= 1;
412 } else {
413 map = *mapp--;
414 bit = 1 << 7;
415 }
416 }
417 return i;
418}
419
420#define ubh_find_last_zero_bit(ubh,begin,size,offset) _ubh_find_last_zero_bit_(uspi,ubh,begin,size,offset)
421static inline unsigned _ubh_find_last_zero_bit_(
422 struct ufs_sb_private_info * uspi, struct ufs_buffer_head * ubh,
423 unsigned begin, unsigned start, unsigned end)
424{
425 unsigned base, count, pos, size;
426
427 size = start - end;
428 begin <<= 3;
429 start += begin;
430 base = start >> uspi->s_bpfshift;
431 start &= uspi->s_bpfmask;
432 for (;;) {
433 count = min_t(unsigned int,
434 size + (uspi->s_bpf - start), uspi->s_bpf)
435 - (uspi->s_bpf - start);
436 size -= count;
437 pos = find_last_zero_bit (ubh->bh[base]->b_data,
438 start, start - count);
439 if (pos > start - count || !size)
440 break;
441 base--;
442 start = uspi->s_bpf;
443 }
444 return (base << uspi->s_bpfshift) + pos - begin;
445}
446
447#define ubh_isblockclear(ubh,begin,block) (!_ubh_isblockset_(uspi,ubh,begin,block))
448
449#define ubh_isblockset(ubh,begin,block) _ubh_isblockset_(uspi,ubh,begin,block)
450static inline int _ubh_isblockset_(struct ufs_sb_private_info * uspi,
451 struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
452{
453 switch (uspi->s_fpb) {
454 case 8:
455 return (*ubh_get_addr (ubh, begin + block) == 0xff);
456 case 4:
457 return (*ubh_get_addr (ubh, begin + (block >> 1)) == (0x0f << ((block & 0x01) << 2)));
458 case 2:
459 return (*ubh_get_addr (ubh, begin + (block >> 2)) == (0x03 << ((block & 0x03) << 1)));
460 case 1:
461 return (*ubh_get_addr (ubh, begin + (block >> 3)) == (0x01 << (block & 0x07)));
462 }
463 return 0;
464}
465
466#define ubh_clrblock(ubh,begin,block) _ubh_clrblock_(uspi,ubh,begin,block)
467static inline void _ubh_clrblock_(struct ufs_sb_private_info * uspi,
468 struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
469{
470 switch (uspi->s_fpb) {
471 case 8:
472 *ubh_get_addr (ubh, begin + block) = 0x00;
473 return;
474 case 4:
475 *ubh_get_addr (ubh, begin + (block >> 1)) &= ~(0x0f << ((block & 0x01) << 2));
476 return;
477 case 2:
478 *ubh_get_addr (ubh, begin + (block >> 2)) &= ~(0x03 << ((block & 0x03) << 1));
479 return;
480 case 1:
481 *ubh_get_addr (ubh, begin + (block >> 3)) &= ~(0x01 << ((block & 0x07)));
482 return;
483 }
484}
485
486#define ubh_setblock(ubh,begin,block) _ubh_setblock_(uspi,ubh,begin,block)
487static inline void _ubh_setblock_(struct ufs_sb_private_info * uspi,
488 struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
489{
490 switch (uspi->s_fpb) {
491 case 8:
492 *ubh_get_addr(ubh, begin + block) = 0xff;
493 return;
494 case 4:
495 *ubh_get_addr(ubh, begin + (block >> 1)) |= (0x0f << ((block & 0x01) << 2));
496 return;
497 case 2:
498 *ubh_get_addr(ubh, begin + (block >> 2)) |= (0x03 << ((block & 0x03) << 1));
499 return;
500 case 1:
501 *ubh_get_addr(ubh, begin + (block >> 3)) |= (0x01 << ((block & 0x07)));
502 return;
503 }
504}
505
506static inline void ufs_fragacct (struct super_block * sb, unsigned blockmap,
507 __fs32 * fraglist, int cnt)
508{
509 struct ufs_sb_private_info * uspi;
510 unsigned fragsize, pos;
511
512 uspi = UFS_SB(sb)->s_uspi;
513
514 fragsize = 0;
515 for (pos = 0; pos < uspi->s_fpb; pos++) {
516 if (blockmap & (1 << pos)) {
517 fragsize++;
518 }
519 else if (fragsize > 0) {
520 fs32_add(sb, &fraglist[fragsize], cnt);
521 fragsize = 0;
522 }
523 }
524 if (fragsize > 0 && fragsize < uspi->s_fpb)
525 fs32_add(sb, &fraglist[fragsize], cnt);
526}
Evgeniy Dushistov54fb9962007-02-12 00:54:32 -0800527
528static inline void *ufs_get_direct_data_ptr(struct ufs_sb_private_info *uspi,
529 struct ufs_inode_info *ufsi,
530 unsigned blk)
531{
532 BUG_ON(blk > UFS_TIND_BLOCK);
533 return uspi->fs_magic == UFS2_MAGIC ?
534 (void *)&ufsi->i_u1.u2_i_data[blk] :
535 (void *)&ufsi->i_u1.i_data[blk];
536}
537
538static inline u64 ufs_data_ptr_to_cpu(struct super_block *sb, void *p)
539{
540 return UFS_SB(sb)->s_uspi->fs_magic == UFS2_MAGIC ?
541 fs64_to_cpu(sb, *(__fs64 *)p) :
542 fs32_to_cpu(sb, *(__fs32 *)p);
543}
544
545static inline void ufs_cpu_to_data_ptr(struct super_block *sb, void *p, u64 val)
546{
547 if (UFS_SB(sb)->s_uspi->fs_magic == UFS2_MAGIC)
548 *(__fs64 *)p = cpu_to_fs64(sb, val);
549 else
550 *(__fs32 *)p = cpu_to_fs32(sb, val);
551}
552
553static inline void ufs_data_ptr_clear(struct ufs_sb_private_info *uspi,
554 void *p)
555{
556 if (uspi->fs_magic == UFS2_MAGIC)
557 *(__fs64 *)p = 0;
558 else
559 *(__fs32 *)p = 0;
560}
561
562static inline int ufs_is_data_ptr_zero(struct ufs_sb_private_info *uspi,
563 void *p)
564{
565 if (uspi->fs_magic == UFS2_MAGIC)
566 return *(__fs64 *)p == 0;
567 else
568 return *(__fs32 *)p == 0;
569}