53 static inline unsigned nilfs_chunk_size(
struct inode *
inode)
55 return inode->
i_sb->s_blocksize;
58 static inline void nilfs_put_page(
struct page *
page)
64 static inline unsigned long dir_pages(
struct inode *
inode)
73 static unsigned nilfs_last_byte(
struct inode *inode,
unsigned long page_nr)
75 unsigned last_byte = inode->
i_size;
83 static int nilfs_prepare_chunk(
struct page *
page,
unsigned from,
unsigned to)
89 static void nilfs_commit_chunk(
struct page *
page,
91 unsigned from,
unsigned to)
93 struct inode *
dir = mapping->
host;
96 unsigned nr_dirty, copied;
101 if (pos + copied > dir->
i_size)
102 i_size_write(dir, pos + copied);
110 static void nilfs_check_page(
struct page *page)
112 struct inode *dir = page->
mapping->host;
114 unsigned chunk_size = nilfs_chunk_size(dir);
121 if ((dir->
i_size >> PAGE_CACHE_SHIFT) == page->
index) {
123 if (limit & (chunk_size - 1))
130 rec_len = nilfs_rec_len_from_disk(p->
rec_len);
138 if (((offs + rec_len - 1) ^ offs) & ~(chunk_size-1))
144 SetPageChecked(page);
151 "size of directory #%lu is not a multiple of chunk size",
156 error =
"rec_len is smaller than minimal";
159 error =
"unaligned directory entry";
162 error =
"rec_len is too small for name_len";
165 error =
"directory entry across blocks";
167 nilfs_error(sb,
"nilfs_check_page",
"bad entry in directory #%lu: %s - "
168 "offset=%lu, inode=%lu, rec_len=%d, name_len=%d",
169 dir->
i_ino, error, (page->
index<<PAGE_CACHE_SHIFT)+offs,
176 "entry in directory #%lu spans the page boundary"
177 "offset=%lu, inode=%lu",
178 dir->
i_ino, (page->
index<<PAGE_CACHE_SHIFT)+offs,
181 SetPageChecked(page);
185 static struct page *nilfs_get_page(
struct inode *dir,
unsigned long n)
188 struct page *page = read_mapping_page(mapping, n,
NULL);
192 if (!PageChecked(page))
193 nilfs_check_page(page);
200 nilfs_put_page(page);
201 return ERR_PTR(-
EIO);
225 nilfs_rec_len_from_disk(p->
rec_len));
252 static void nilfs_set_de_type(
struct nilfs_dir_entry *de,
struct inode *inode)
261 loff_t pos = filp->
f_pos;
262 struct inode *inode = filp->f_dentry->d_inode;
266 unsigned long npages = dir_pages(inode);
268 unsigned char *types =
NULL;
274 types = nilfs_filetype_table;
276 for ( ; n < npages; n++, offset = 0) {
279 struct page *page = nilfs_get_page(inode, n);
290 limit = kaddr + nilfs_last_byte(inode, n) -
292 for ( ; (
char *)de <= limit; de = nilfs_next_entry(de)) {
295 "zero-length directory entry");
297 nilfs_put_page(page);
307 offset = (
char *)de - kaddr;
309 (n<<PAGE_CACHE_SHIFT) | offset,
312 nilfs_put_page(page);
318 nilfs_put_page(page);
337 struct page **res_page)
339 const unsigned char *name = qstr->
name;
343 unsigned long npages = dir_pages(dir);
344 struct page *page =
NULL;
360 page = nilfs_get_page(dir, n);
364 kaddr += nilfs_last_byte(dir, n) - reclen;
365 while ((
char *) de <= kaddr) {
368 "zero-length directory entry");
369 nilfs_put_page(page);
372 if (nilfs_match(namelen, name, de))
374 de = nilfs_next_entry(de);
376 nilfs_put_page(page);
383 "dir %lu size %lld exceeds block count %llu",
388 }
while (n != start);
400 struct page *page = nilfs_get_page(dir, 0);
404 de = nilfs_next_entry(
428 struct page *page,
struct inode *inode)
430 unsigned from = (
char *) de - (
char *)
page_address(page);
431 unsigned to = from + nilfs_rec_len_from_disk(de->
rec_len);
436 err = nilfs_prepare_chunk(page, from, to);
439 nilfs_set_de_type(de, inode);
440 nilfs_commit_chunk(page, mapping, from, to);
441 nilfs_put_page(page);
450 struct inode *dir = dentry->
d_parent->d_inode;
451 const unsigned char *name = dentry->
d_name.name;
453 unsigned chunk_size = nilfs_chunk_size(dir);
456 struct page *page =
NULL;
458 unsigned long npages = dir_pages(dir);
469 for (n = 0; n <= npages; n++) {
472 page = nilfs_get_page(dir, n);
478 dir_end = kaddr + nilfs_last_byte(dir, n);
481 while ((
char *)de <= kaddr) {
482 if ((
char *)de == dir_end) {
485 rec_len = chunk_size;
486 de->
rec_len = nilfs_rec_len_to_disk(chunk_size);
492 "zero-length directory entry");
497 if (nilfs_match(namelen, name, de))
500 rec_len = nilfs_rec_len_from_disk(de->
rec_len);
501 if (!de->
inode && rec_len >= reclen)
503 if (rec_len >= name_len + reclen)
508 nilfs_put_page(page);
516 err = nilfs_prepare_chunk(page, from, to);
523 de1->
rec_len = nilfs_rec_len_to_disk(rec_len - name_len);
524 de->
rec_len = nilfs_rec_len_to_disk(name_len);
530 nilfs_set_de_type(de, inode);
531 nilfs_commit_chunk(page, page->
mapping, from, to);
536 nilfs_put_page(page);
551 struct inode *inode = mapping->
host;
553 unsigned from = ((
char *)dir - kaddr) & ~(nilfs_chunk_size(inode) - 1);
554 unsigned to = ((
char *)dir - kaddr) +
555 nilfs_rec_len_from_disk(dir->
rec_len);
560 while ((
char *)de < (
char *)dir) {
563 "zero-length directory entry");
568 de = nilfs_next_entry(de);
573 err = nilfs_prepare_chunk(page, from, to);
576 pde->
rec_len = nilfs_rec_len_to_disk(to - from);
578 nilfs_commit_chunk(page, mapping, from, to);
581 nilfs_put_page(page);
591 struct page *page = grab_cache_page(mapping, 0);
592 unsigned chunk_size = nilfs_chunk_size(inode);
600 err = nilfs_prepare_chunk(page, 0, chunk_size);
606 memset(kaddr, 0, chunk_size);
612 nilfs_set_de_type(de, inode);
619 nilfs_set_de_type(de, inode);
621 nilfs_commit_chunk(page, mapping, 0, chunk_size);
632 struct page *page =
NULL;
633 unsigned long i, npages = dir_pages(inode);
635 for (i = 0; i < npages; i++) {
639 page = nilfs_get_page(inode, i);
647 while ((
char *)de <= kaddr) {
650 "zero-length directory entry "
651 "(kaddr=%p, de=%p)\n", kaddr, de);
654 if (de->
inode != 0) {
656 if (de->
name[0] !=
'.')
664 }
else if (de->
name[1] !=
'.')
667 de = nilfs_next_entry(de);
669 nilfs_put_page(page);
674 nilfs_put_page(page);
681 .readdir = nilfs_readdir,