-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfatent.h
78 lines (62 loc) · 1.7 KB
/
fatent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright (C) 2008, OGAWA Hirofumi
* Released under GPL v2.
*/
#ifndef _EXFAT_FATENT_H
#define _EXFAT_FATENT_H
#include <linux/buffer_head.h>
struct exfat_ent {
struct buffer_head *bh;
u32 offset;
};
static inline void exfat_ent_init(struct exfat_ent *fatent)
{
fatent->bh = NULL;
}
static inline void exfat_ent_release(struct exfat_ent *fatent)
{
brelse(fatent->bh);
}
/* FIXME: should be outline those funcs? must rethink those */
static inline int exfat_ent_read(struct inode *inode,
struct exfat_ent *fatent,
u32 clusnr, u32 *result_clusnr)
{
struct super_block *sb = inode->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
sector_t blocknr;
__le32 *ent;
blocknr = sbi->fat_blocknr + (clusnr >> sbi->fpb_bits);
if (!fatent->bh || fatent->bh->b_blocknr != blocknr) {
brelse(fatent->bh);
fatent->bh = sb_bread(sb, blocknr);
if (!fatent->bh)
return -EIO;
}
ent = (__le32 *)fatent->bh->b_data;
*result_clusnr = le32_to_cpu(ent[clusnr & (sbi->fpb - 1)]);
return 0;
}
static inline int exfat_ent_prepare(struct inode *inode,
struct exfat_ent *fatent,
u32 clusnr, u32 *result_clusnr)
{
struct super_block *sb = inode->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
__le32 *ent;
fatent->bh = sb_bread(sb, sbi->fat_blocknr + (clusnr >> sbi->fpb_bits));
if (!fatent->bh)
return -EIO;
fatent->offset = clusnr & (sbi->fpb - 1);
ent = (__le32 *)fatent->bh->b_data;
*result_clusnr = le32_to_cpu(ent[fatent->offset]);
return 0;
}
static inline void exfat_ent_write(struct inode *inode,
struct exfat_ent *fatent,
u32 new_clusnr)
{
__le32 *ent = (__le32 *)fatent->bh->b_data;;
ent[fatent->offset] = cpu_to_le32(new_clusnr);
}
#endif /* !_EXFAT_FATENT_H */