Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 58076
b: refs/heads/master
c: 240e2df
h: refs/heads/master
v: v3
  • Loading branch information
Michael Halcrow authored and Linus Torvalds committed Jun 28, 2007
1 parent 7933115 commit 6c9b1e1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b75ae8603568ae18f270213693758c78fb8a29ff
refs/heads/master: 240e2df5c740d73fc08cac9989872212deb2d20e
2 changes: 2 additions & 0 deletions trunk/fs/ecryptfs/ecryptfs_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -580,5 +580,7 @@ void
ecryptfs_write_header_metadata(char *virt,
struct ecryptfs_crypt_stat *crypt_stat,
size_t *written);
int ecryptfs_write_zeros(struct file *file, pgoff_t index, int start,
int num_zeros);

#endif /* #ifndef ECRYPTFS_KERNEL_H */
19 changes: 19 additions & 0 deletions trunk/fs/ecryptfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,25 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)
goto out_fput;
}
} else { /* new_length < i_size_read(inode) */
pgoff_t index = 0;
int end_pos_in_page = -1;

if (new_length != 0) {
index = ((new_length - 1) >> PAGE_CACHE_SHIFT);
end_pos_in_page = ((new_length - 1) & ~PAGE_CACHE_MASK);
}
if (end_pos_in_page != (PAGE_CACHE_SIZE - 1)) {
if ((rc = ecryptfs_write_zeros(&fake_ecryptfs_file,
index,
(end_pos_in_page + 1),
((PAGE_CACHE_SIZE - 1)
- end_pos_in_page)))) {
printk(KERN_ERR "Error attempting to zero out "
"the remainder of the end page on "
"reducing truncate; rc = [%d]\n", rc);
goto out_fput;
}
}
vmtruncate(inode, new_length);
rc = ecryptfs_write_inode_size_to_metadata(
lower_file, lower_dentry->d_inode, inode, dentry,
Expand Down
53 changes: 29 additions & 24 deletions trunk/fs/ecryptfs/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ static struct page *ecryptfs_get1page(struct file *file, int index)
return read_mapping_page(mapping, index, (void *)file);
}

static
int write_zeros(struct file *file, pgoff_t index, int start, int num_zeros);

/**
* ecryptfs_fill_zeros
* @file: The ecryptfs file
Expand Down Expand Up @@ -101,10 +98,13 @@ int ecryptfs_fill_zeros(struct file *file, loff_t new_length)
if (old_end_page_index == new_end_page_index) {
/* Start and end are in the same page; we just need to
* set a portion of the existing page to zero's */
rc = write_zeros(file, index, (old_end_pos_in_page + 1),
(new_end_pos_in_page - old_end_pos_in_page));
rc = ecryptfs_write_zeros(file, index,
(old_end_pos_in_page + 1),
(new_end_pos_in_page
- old_end_pos_in_page));
if (rc)
ecryptfs_printk(KERN_ERR, "write_zeros(file=[%p], "
ecryptfs_printk(KERN_ERR, "ecryptfs_write_zeros("
"file=[%p], "
"index=[0x%.16x], "
"old_end_pos_in_page=[d], "
"(PAGE_CACHE_SIZE - new_end_pos_in_page"
Expand All @@ -117,10 +117,10 @@ int ecryptfs_fill_zeros(struct file *file, loff_t new_length)
goto out;
}
/* Fill the remainder of the previous last page with zeros */
rc = write_zeros(file, index, (old_end_pos_in_page + 1),
rc = ecryptfs_write_zeros(file, index, (old_end_pos_in_page + 1),
((PAGE_CACHE_SIZE - 1) - old_end_pos_in_page));
if (rc) {
ecryptfs_printk(KERN_ERR, "write_zeros(file=[%p], "
ecryptfs_printk(KERN_ERR, "ecryptfs_write_zeros(file=[%p], "
"index=[0x%.16x], old_end_pos_in_page=[d], "
"(PAGE_CACHE_SIZE - old_end_pos_in_page)=[d]) "
"returned [%d]\n", file, index,
Expand All @@ -131,9 +131,10 @@ int ecryptfs_fill_zeros(struct file *file, loff_t new_length)
index++;
while (index < new_end_page_index) {
/* Fill all intermediate pages with zeros */
rc = write_zeros(file, index, 0, PAGE_CACHE_SIZE);
rc = ecryptfs_write_zeros(file, index, 0, PAGE_CACHE_SIZE);
if (rc) {
ecryptfs_printk(KERN_ERR, "write_zeros(file=[%p], "
ecryptfs_printk(KERN_ERR, "ecryptfs_write_zeros("
"file=[%p], "
"index=[0x%.16x], "
"old_end_pos_in_page=[d], "
"(PAGE_CACHE_SIZE - new_end_pos_in_page"
Expand All @@ -149,9 +150,9 @@ int ecryptfs_fill_zeros(struct file *file, loff_t new_length)
}
/* Fill the portion at the beginning of the last new page with
* zero's */
rc = write_zeros(file, index, 0, (new_end_pos_in_page + 1));
rc = ecryptfs_write_zeros(file, index, 0, (new_end_pos_in_page + 1));
if (rc) {
ecryptfs_printk(KERN_ERR, "write_zeros(file="
ecryptfs_printk(KERN_ERR, "ecryptfs_write_zeros(file="
"[%p], index=[0x%.16x], 0, "
"new_end_pos_in_page=[%d]"
"returned [%d]\n", file, index,
Expand Down Expand Up @@ -400,22 +401,26 @@ ecryptfs_prepare_write_no_truncate(struct file *file, struct page *page,
static int ecryptfs_prepare_write(struct file *file, struct page *page,
unsigned from, unsigned to)
{
loff_t pos;
int rc = 0;

if (from == 0 && to == PAGE_CACHE_SIZE)
goto out; /* If we are writing a full page, it will be
up to date. */
if (!PageUptodate(page))
rc = ecryptfs_do_readpage(file, page, page->index);
pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
if (pos > i_size_read(page->mapping->host)) {
rc = ecryptfs_truncate(file->f_path.dentry, pos);
if (rc) {
printk(KERN_ERR "Error on attempt to "
"truncate to (higher) offset [%lld];"
" rc = [%d]\n", pos, rc);
goto out;
if (page->index != 0) {
loff_t end_of_prev_pg_pos =
(((loff_t)page->index << PAGE_CACHE_SHIFT) - 1);

if (end_of_prev_pg_pos > i_size_read(page->mapping->host)) {
rc = ecryptfs_truncate(file->f_path.dentry,
end_of_prev_pg_pos);
if (rc) {
printk(KERN_ERR "Error on attempt to "
"truncate to (higher) offset [%lld];"
" rc = [%d]\n", end_of_prev_pg_pos, rc);
goto out;
}
}
}
out:
Expand Down Expand Up @@ -753,7 +758,7 @@ static int ecryptfs_commit_write(struct file *file, struct page *page,
}

/**
* write_zeros
* ecryptfs_write_zeros
* @file: The ecryptfs file
* @index: The index in which we are writing
* @start: The position after the last block of data
Expand All @@ -763,8 +768,8 @@ static int ecryptfs_commit_write(struct file *file, struct page *page,
*
* (start + num_zeros) must be less than or equal to PAGE_CACHE_SIZE
*/
static
int write_zeros(struct file *file, pgoff_t index, int start, int num_zeros)
int
ecryptfs_write_zeros(struct file *file, pgoff_t index, int start, int num_zeros)
{
int rc = 0;
struct page *tmp_page;
Expand Down

0 comments on commit 6c9b1e1

Please sign in to comment.