diff options
Diffstat (limited to 'fs/ecryptfs/read_write.c')
-rw-r--r-- | fs/ecryptfs/read_write.c | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c index 272eaeb9a738..2150edf9a58e 100644 --- a/fs/ecryptfs/read_write.c +++ b/fs/ecryptfs/read_write.c | |||
@@ -142,8 +142,8 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset, | |||
142 | if (num_bytes > total_remaining_zeros) | 142 | if (num_bytes > total_remaining_zeros) |
143 | num_bytes = total_remaining_zeros; | 143 | num_bytes = total_remaining_zeros; |
144 | } | 144 | } |
145 | ecryptfs_page = ecryptfs_get1page(ecryptfs_file, | 145 | ecryptfs_page = ecryptfs_get_locked_page(ecryptfs_file, |
146 | ecryptfs_page_idx); | 146 | ecryptfs_page_idx); |
147 | if (IS_ERR(ecryptfs_page)) { | 147 | if (IS_ERR(ecryptfs_page)) { |
148 | rc = PTR_ERR(ecryptfs_page); | 148 | rc = PTR_ERR(ecryptfs_page); |
149 | printk(KERN_ERR "%s: Error getting page at " | 149 | printk(KERN_ERR "%s: Error getting page at " |
@@ -161,6 +161,7 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset, | |||
161 | printk(KERN_ERR "%s: Error decrypting " | 161 | printk(KERN_ERR "%s: Error decrypting " |
162 | "page; rc = [%d]\n", | 162 | "page; rc = [%d]\n", |
163 | __FUNCTION__, rc); | 163 | __FUNCTION__, rc); |
164 | ClearPageUptodate(ecryptfs_page); | ||
164 | page_cache_release(ecryptfs_page); | 165 | page_cache_release(ecryptfs_page); |
165 | goto out; | 166 | goto out; |
166 | } | 167 | } |
@@ -180,14 +181,15 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset, | |||
180 | } | 181 | } |
181 | kunmap_atomic(ecryptfs_page_virt, KM_USER0); | 182 | kunmap_atomic(ecryptfs_page_virt, KM_USER0); |
182 | flush_dcache_page(ecryptfs_page); | 183 | flush_dcache_page(ecryptfs_page); |
184 | SetPageUptodate(ecryptfs_page); | ||
185 | unlock_page(ecryptfs_page); | ||
183 | rc = ecryptfs_encrypt_page(ecryptfs_page); | 186 | rc = ecryptfs_encrypt_page(ecryptfs_page); |
187 | page_cache_release(ecryptfs_page); | ||
184 | if (rc) { | 188 | if (rc) { |
185 | printk(KERN_ERR "%s: Error encrypting " | 189 | printk(KERN_ERR "%s: Error encrypting " |
186 | "page; rc = [%d]\n", __FUNCTION__, rc); | 190 | "page; rc = [%d]\n", __FUNCTION__, rc); |
187 | page_cache_release(ecryptfs_page); | ||
188 | goto out; | 191 | goto out; |
189 | } | 192 | } |
190 | page_cache_release(ecryptfs_page); | ||
191 | pos += num_bytes; | 193 | pos += num_bytes; |
192 | } | 194 | } |
193 | if ((offset + size) > ecryptfs_file_size) { | 195 | if ((offset + size) > ecryptfs_file_size) { |
@@ -225,7 +227,6 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size, | |||
225 | ecryptfs_inode_to_private(ecryptfs_inode); | 227 | ecryptfs_inode_to_private(ecryptfs_inode); |
226 | ssize_t octets_read; | 228 | ssize_t octets_read; |
227 | mm_segment_t fs_save; | 229 | mm_segment_t fs_save; |
228 | size_t i; | ||
229 | int rc = 0; | 230 | int rc = 0; |
230 | 231 | ||
231 | mutex_lock(&inode_info->lower_file_mutex); | 232 | mutex_lock(&inode_info->lower_file_mutex); |
@@ -242,16 +243,6 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size, | |||
242 | rc = -EINVAL; | 243 | rc = -EINVAL; |
243 | } | 244 | } |
244 | mutex_unlock(&inode_info->lower_file_mutex); | 245 | mutex_unlock(&inode_info->lower_file_mutex); |
245 | for (i = 0; i < size; i += PAGE_CACHE_SIZE) { | ||
246 | struct page *data_page; | ||
247 | |||
248 | data_page = virt_to_page(data + i); | ||
249 | flush_dcache_page(data_page); | ||
250 | if (rc) | ||
251 | ClearPageUptodate(data_page); | ||
252 | else | ||
253 | SetPageUptodate(data_page); | ||
254 | } | ||
255 | return rc; | 246 | return rc; |
256 | } | 247 | } |
257 | 248 | ||
@@ -283,6 +274,7 @@ int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs, | |||
283 | virt = kmap(page_for_ecryptfs); | 274 | virt = kmap(page_for_ecryptfs); |
284 | rc = ecryptfs_read_lower(virt, offset, size, ecryptfs_inode); | 275 | rc = ecryptfs_read_lower(virt, offset, size, ecryptfs_inode); |
285 | kunmap(page_for_ecryptfs); | 276 | kunmap(page_for_ecryptfs); |
277 | flush_dcache_page(page_for_ecryptfs); | ||
286 | return rc; | 278 | return rc; |
287 | } | 279 | } |
288 | 280 | ||
@@ -331,8 +323,8 @@ int ecryptfs_read(char *data, loff_t offset, size_t size, | |||
331 | 323 | ||
332 | if (num_bytes > total_remaining_bytes) | 324 | if (num_bytes > total_remaining_bytes) |
333 | num_bytes = total_remaining_bytes; | 325 | num_bytes = total_remaining_bytes; |
334 | ecryptfs_page = ecryptfs_get1page(ecryptfs_file, | 326 | ecryptfs_page = ecryptfs_get_locked_page(ecryptfs_file, |
335 | ecryptfs_page_idx); | 327 | ecryptfs_page_idx); |
336 | if (IS_ERR(ecryptfs_page)) { | 328 | if (IS_ERR(ecryptfs_page)) { |
337 | rc = PTR_ERR(ecryptfs_page); | 329 | rc = PTR_ERR(ecryptfs_page); |
338 | printk(KERN_ERR "%s: Error getting page at " | 330 | printk(KERN_ERR "%s: Error getting page at " |
@@ -345,6 +337,7 @@ int ecryptfs_read(char *data, loff_t offset, size_t size, | |||
345 | if (rc) { | 337 | if (rc) { |
346 | printk(KERN_ERR "%s: Error decrypting " | 338 | printk(KERN_ERR "%s: Error decrypting " |
347 | "page; rc = [%d]\n", __FUNCTION__, rc); | 339 | "page; rc = [%d]\n", __FUNCTION__, rc); |
340 | ClearPageUptodate(ecryptfs_page); | ||
348 | page_cache_release(ecryptfs_page); | 341 | page_cache_release(ecryptfs_page); |
349 | goto out; | 342 | goto out; |
350 | } | 343 | } |
@@ -353,6 +346,9 @@ int ecryptfs_read(char *data, loff_t offset, size_t size, | |||
353 | ((char *)ecryptfs_page_virt + start_offset_in_page), | 346 | ((char *)ecryptfs_page_virt + start_offset_in_page), |
354 | num_bytes); | 347 | num_bytes); |
355 | kunmap_atomic(ecryptfs_page_virt, KM_USER0); | 348 | kunmap_atomic(ecryptfs_page_virt, KM_USER0); |
349 | flush_dcache_page(ecryptfs_page); | ||
350 | SetPageUptodate(ecryptfs_page); | ||
351 | unlock_page(ecryptfs_page); | ||
356 | page_cache_release(ecryptfs_page); | 352 | page_cache_release(ecryptfs_page); |
357 | pos += num_bytes; | 353 | pos += num_bytes; |
358 | data_offset += num_bytes; | 354 | data_offset += num_bytes; |