packaging: install license for rpm package instead of license package
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / fs / exfat / exfat_blkdev.c
1 /*
2  *  Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
3  *
4  *  This program is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU General Public License
6  *  as published by the Free Software Foundation; either version 2
7  *  of the License, or (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #include <linux/blkdev.h>
20
21 #include "exfat_config.h"
22 #include "exfat_global.h"
23 #include "exfat_blkdev.h"
24 #include "exfat_data.h"
25 #include "exfat_api.h"
26 #include "exfat_super.h"
27
28 INT32 bdev_init(void)
29 {
30         return(FFS_SUCCESS);
31 }
32
33 INT32 bdev_shutdown(void)
34 {
35         return(FFS_SUCCESS);
36 }
37
38 INT32 bdev_open(struct super_block *sb)
39 {
40         BD_INFO_T *p_bd = &(EXFAT_SB(sb)->bd_info);
41
42         if (p_bd->opened) return(FFS_SUCCESS);
43
44         p_bd->sector_size      = bdev_logical_block_size(sb->s_bdev);
45         p_bd->sector_size_bits = my_log2(p_bd->sector_size);
46         p_bd->sector_size_mask = p_bd->sector_size - 1;
47         p_bd->num_sectors      = i_size_read(sb->s_bdev->bd_inode) >> p_bd->sector_size_bits;
48
49         p_bd->opened = TRUE;
50
51         return(FFS_SUCCESS);
52 }
53
54 INT32 bdev_close(struct super_block *sb)
55 {
56         BD_INFO_T *p_bd = &(EXFAT_SB(sb)->bd_info);
57
58         if (!p_bd->opened) return(FFS_SUCCESS);
59
60         p_bd->opened = FALSE;
61         return(FFS_SUCCESS);
62 }
63
64 INT32 bdev_read(struct super_block *sb, UINT32 secno, struct buffer_head **bh, UINT32 num_secs, INT32 read)
65 {
66         BD_INFO_T *p_bd = &(EXFAT_SB(sb)->bd_info);
67         FS_INFO_T *p_fs = &(EXFAT_SB(sb)->fs_info);
68 #if EXFAT_CONFIG_KERNEL_DEBUG
69         struct exfat_sb_info *sbi = EXFAT_SB(sb);
70         long flags = sbi->debug_flags;
71
72         if (flags & EXFAT_DEBUGFLAGS_ERROR_RW)  return (FFS_MEDIAERR);
73 #endif
74
75         if (!p_bd->opened) return(FFS_MEDIAERR);
76
77         if (*bh) __brelse(*bh);
78
79         if (read)
80                 *bh = __bread(sb->s_bdev, secno, num_secs << p_bd->sector_size_bits);
81         else
82                 *bh = __getblk(sb->s_bdev, secno, num_secs << p_bd->sector_size_bits);
83
84         if (*bh) return(FFS_SUCCESS);
85
86         WARN(!p_fs->dev_ejected,
87                 "[EXFAT] No bh, device seems wrong or to be ejected.\n");
88
89         return(FFS_MEDIAERR);
90 }
91
92 INT32 bdev_write(struct super_block *sb, UINT32 secno, struct buffer_head *bh, UINT32 num_secs, INT32 sync)
93 {
94         INT32 count;
95         struct buffer_head *bh2;
96         BD_INFO_T *p_bd = &(EXFAT_SB(sb)->bd_info);
97         FS_INFO_T *p_fs = &(EXFAT_SB(sb)->fs_info);
98 #if EXFAT_CONFIG_KERNEL_DEBUG
99         struct exfat_sb_info *sbi = EXFAT_SB(sb);
100         long flags = sbi->debug_flags;
101
102         if (flags & EXFAT_DEBUGFLAGS_ERROR_RW)  return (FFS_MEDIAERR);
103 #endif
104
105         if (!p_bd->opened) return(FFS_MEDIAERR);
106
107         if (secno == bh->b_blocknr) {
108                 set_buffer_uptodate(bh);
109                 mark_buffer_dirty(bh);
110
111                 if (sync && (sync_dirty_buffer(bh) != 0))
112                         return (FFS_MEDIAERR);
113         } else {
114                 count = num_secs << p_bd->sector_size_bits;
115
116                 bh2 = __getblk(sb->s_bdev, secno, count);
117
118                 if (bh2 == NULL)
119                         goto no_bh;
120
121                 lock_buffer(bh2);
122                 MEMCPY(bh2->b_data, bh->b_data, count);
123                 set_buffer_uptodate(bh2);
124                 mark_buffer_dirty(bh2);
125                 unlock_buffer(bh2);
126                 if (sync && (sync_dirty_buffer(bh2) != 0)) {
127                         __brelse(bh2);
128                         goto no_bh;
129                 }
130                 __brelse(bh2);
131         }
132
133         return(FFS_SUCCESS);
134
135 no_bh:
136         WARN(!p_fs->dev_ejected,
137                 "[EXFAT] No bh, device seems wrong or to be ejected.\n");
138
139         return (FFS_MEDIAERR);
140 }
141
142 INT32 bdev_sync(struct super_block *sb)
143 {
144         BD_INFO_T *p_bd = &(EXFAT_SB(sb)->bd_info);
145 #if EXFAT_CONFIG_KERNEL_DEBUG
146         struct exfat_sb_info *sbi = EXFAT_SB(sb);
147         long flags = sbi->debug_flags;
148
149         if (flags & EXFAT_DEBUGFLAGS_ERROR_RW)  return (FFS_MEDIAERR);
150 #endif
151
152         if (!p_bd->opened) return(FFS_MEDIAERR);
153
154         return sync_blockdev(sb->s_bdev);
155 }