17 #define in_range(b,first,len) ((b)>=(first)&&(b)<(first)+(len))
43 return fs32_to_cpu(sb, usb1->
fs_u0.
fs_sun.fs_state);
51 return fs32_to_cpu(sb, usb3->
fs_un2.
fs_44.fs_state);
59 switch (UFS_SB(sb)->
s_flags & UFS_ST_MASK) {
62 usb1->
fs_u0.
fs_sun.fs_state = cpu_to_fs32(sb, value);
73 usb3->
fs_un2.
fs_44.fs_state = cpu_to_fs32(sb, value);
85 return fs32_to_cpu(sb, usb1->
fs_u1.
fs_sun.fs_npsect);
93 switch (UFS_SB(sb)->
s_flags & UFS_ST_MASK) {
109 return fs64_to_cpu(sb, tmp);
117 switch (UFS_SB(sb)->
s_flags & UFS_ST_MASK) {
133 return fs64_to_cpu(sb, tmp);
195 return fs32_to_cpu(sb, inode->
ui_u3.
ui_44.ui_uid);
198 return fs32_to_cpu(sb, inode->
ui_u3.
ui_sun.ui_uid);
201 return fs16_to_cpu(sb, inode->
ui_u1.
oldids.ui_suid);
208 switch (UFS_SB(sb)->
s_flags & UFS_UID_MASK) {
210 inode->
ui_u3.
ui_44.ui_uid = cpu_to_fs32(sb, value);
211 inode->
ui_u1.
oldids.ui_suid = cpu_to_fs16(sb, value);
214 inode->
ui_u3.
ui_sun.ui_uid = cpu_to_fs32(sb, value);
219 inode->
ui_u1.
oldids.ui_suid = cpu_to_fs16(sb, value);
227 switch (UFS_SB(sb)->
s_flags & UFS_UID_MASK) {
229 return fs32_to_cpu(sb, inode->
ui_u3.
ui_44.ui_gid);
232 return fs32_to_cpu(sb, inode->
ui_u3.
ui_sun.ui_gid);
235 return fs16_to_cpu(sb, inode->
ui_u1.
oldids.ui_sgid);
242 switch (UFS_SB(sb)->
s_flags & UFS_UID_MASK) {
244 inode->
ui_u3.
ui_44.ui_gid = cpu_to_fs32(sb, value);
245 inode->
ui_u1.
oldids.ui_sgid = cpu_to_fs16(sb, value);
248 inode->
ui_u3.
ui_sun.ui_gid = cpu_to_fs32(sb, value);
253 inode->
ui_u1.
oldids.ui_sgid = cpu_to_fs16(sb, value);
265 #define ubh_bread(sb,fragment,size) _ubh_bread_(uspi,sb,fragment,size)
275 #define ubh_ubhcpymem(mem,ubh,size) _ubh_ubhcpymem_(uspi,mem,ubh,size)
277 #define ubh_memcpyubh(ubh,mem,size) _ubh_memcpyubh_(uspi,ubh,mem,size)
283 static inline void ufs_put_locked_page(
struct page *
page)
304 #define ubh_get_usb_first(uspi) \
305 ((struct ufs_super_block_first *)get_usb_offset((uspi), 0))
307 #define ubh_get_usb_second(uspi) \
308 ((struct ufs_super_block_second *)get_usb_offset((uspi), UFS_SECTOR_SIZE))
310 #define ubh_get_usb_third(uspi) \
311 ((struct ufs_super_block_third *)get_usb_offset((uspi), 2*UFS_SECTOR_SIZE))
314 #define ubh_get_ucg(ubh) \
315 ((struct ufs_cylinder_group *)((ubh)->bh[0]->b_data))
322 #define ubh_get_addr8(ubh,begin) \
323 ((u8*)(ubh)->bh[(begin) >> uspi->s_fshift]->b_data + \
324 ((begin) & ~uspi->s_fmask))
326 #define ubh_get_addr16(ubh,begin) \
327 (((__fs16*)((ubh)->bh[(begin) >> (uspi->s_fshift-1)]->b_data)) + \
328 ((begin) & ((uspi->fsize>>1) - 1)))
330 #define ubh_get_addr32(ubh,begin) \
331 (((__fs32*)((ubh)->bh[(begin) >> (uspi->s_fshift-2)]->b_data)) + \
332 ((begin) & ((uspi->s_fsize>>2) - 1)))
334 #define ubh_get_addr64(ubh,begin) \
335 (((__fs64*)((ubh)->bh[(begin) >> (uspi->s_fshift-3)]->b_data)) + \
336 ((begin) & ((uspi->s_fsize>>3) - 1)))
338 #define ubh_get_addr ubh_get_addr8
350 #define ubh_blkmap(ubh,begin,bit) \
351 ((*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) >> ((bit) & 7)) & (0xff >> (UFS_MAXFRAG - uspi->s_fpb)))
362 (uspi->
s_dsize * (percentreserved) / 100);
368 #define ubh_cg_blktot(ucpi,cylno) \
369 (*((__fs32*)ubh_get_addr(UCPI_UBH(ucpi), (ucpi)->c_btotoff + ((cylno) << 2))))
371 #define ubh_cg_blks(ucpi,cylno,rpos) \
372 (*((__fs16*)ubh_get_addr(UCPI_UBH(ucpi), \
373 (ucpi)->c_boff + (((cylno) * uspi->s_nrpos + (rpos)) << 1 ))))
383 #define ubh_setbit(ubh,begin,bit) \
384 (*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) |= (1 << ((bit) & 7)))
386 #define ubh_clrbit(ubh,begin,bit) \
387 (*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) &= ~(1 << ((bit) & 7)))
389 #define ubh_isset(ubh,begin,bit) \
390 (*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) & (1 << ((bit) & 7)))
392 #define ubh_isclr(ubh,begin,bit) (!ubh_isset(ubh,begin,bit))
394 #define ubh_find_first_zero_bit(ubh,begin,size) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,0)
396 #define ubh_find_next_zero_bit(ubh,begin,size,offset) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,offset)
397 static inline unsigned _ubh_find_next_zero_bit_(
399 unsigned begin,
unsigned size,
unsigned offset)
409 count =
min_t(
unsigned int, size + offset, uspi->
s_bpf);
412 if (pos < count || !size)
417 return (base << uspi->
s_bpfshift) + pos - begin;
420 static inline unsigned find_last_zero_bit (
unsigned char *
bitmap,
424 unsigned char * mapp;
427 mapp = bitmap + (size >> 3);
429 bit = 1 << (size & 7);
430 for (i = size; i >
offset; i--) {
431 if ((map & bit) == 0)
443 #define ubh_find_last_zero_bit(ubh,begin,size,offset) _ubh_find_last_zero_bit_(uspi,ubh,begin,size,offset)
444 static inline unsigned _ubh_find_last_zero_bit_(
446 unsigned begin,
unsigned start,
unsigned end)
456 count =
min_t(
unsigned int,
460 pos = find_last_zero_bit (ubh->
bh[base]->b_data,
461 start, start - count);
462 if (pos > start - count || !size)
467 return (base << uspi->
s_bpfshift) + pos - begin;
470 #define ubh_isblockclear(ubh,begin,block) (!_ubh_isblockset_(uspi,ubh,begin,block))
472 #define ubh_isblockset(ubh,begin,block) _ubh_isblockset_(uspi,ubh,begin,block)
476 switch (uspi->
s_fpb) {
480 return (*
ubh_get_addr (ubh, begin + (block >> 1)) == (0x0f << ((block & 0x01) << 2)));
482 return (*
ubh_get_addr (ubh, begin + (block >> 2)) == (0x03 << ((block & 0x03) << 1)));
484 return (*
ubh_get_addr (ubh, begin + (block >> 3)) == (0x01 << (block & 0x07)));
489 #define ubh_clrblock(ubh,begin,block) _ubh_clrblock_(uspi,ubh,begin,block)
493 switch (uspi->
s_fpb) {
498 *
ubh_get_addr (ubh, begin + (block >> 1)) &= ~(0x0f << ((block & 0x01) << 2));
501 *
ubh_get_addr (ubh, begin + (block >> 2)) &= ~(0x03 << ((block & 0x03) << 1));
504 *
ubh_get_addr (ubh, begin + (block >> 3)) &= ~(0x01 << ((block & 0x07)));
509 #define ubh_setblock(ubh,begin,block) _ubh_setblock_(uspi,ubh,begin,block)
513 switch (uspi->
s_fpb) {
518 *
ubh_get_addr(ubh, begin + (block >> 1)) |= (0x0f << ((block & 0x01) << 2));
521 *
ubh_get_addr(ubh, begin + (block >> 2)) |= (0x03 << ((block & 0x03) << 1));
524 *
ubh_get_addr(ubh, begin + (block >> 3)) |= (0x01 << ((block & 0x07)));
529 static inline void ufs_fragacct (
struct super_block * sb,
unsigned blockmap,
533 unsigned fragsize,
pos;
535 uspi = UFS_SB(sb)->s_uspi;
538 for (pos = 0; pos < uspi->
s_fpb; pos++) {
539 if (blockmap & (1 << pos)) {
542 else if (fragsize > 0) {
543 fs32_add(sb, &fraglist[fragsize], cnt);
547 if (fragsize > 0 && fragsize < uspi->
s_fpb)
548 fs32_add(sb, &fraglist[fragsize], cnt);
563 return UFS_SB(sb)->s_uspi->fs_magic ==
UFS2_MAGIC ?
564 fs64_to_cpu(sb, *(
__fs64 *)p) :
565 fs32_to_cpu(sb, *(
__fs32 *)p);
570 if (UFS_SB(sb)->s_uspi->fs_magic ==
UFS2_MAGIC)
571 *(
__fs64 *)p = cpu_to_fs64(sb, val);
573 *(
__fs32 *)p = cpu_to_fs32(sb, val);