Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'pull-file' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull vfs file updates from Al Viro:
"struct file-related stuff"

* tag 'pull-file' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
dma_buf_getfile(): don't bother with ->f_flags reassignments
Change calling conventions for filldir_t
locks: fix TOCTOU race when granting write lease

+169 -169
+11
Documentation/filesystems/porting.rst
··· 922 922 no_llseek is gone; don't set .llseek to that - just leave it NULL instead. 923 923 Checks for "does that file have llseek(2), or should it fail with ESPIPE" 924 924 should be done by looking at FMODE_LSEEK in file->f_mode. 925 + 926 + --- 927 + 928 + *mandatory* 929 + 930 + filldir_t (readdir callbacks) calling conventions have changed. Instead of 931 + returning 0 or -E... it returns bool now. false means "no more" (as -E... used 932 + to) and true - "keep going" (as 0 in old calling conventions). Rationale: 933 + callers never looked at specific -E... values anyway. ->iterate() and 934 + ->iterate_shared() instance require no changes at all, all filldir_t ones in 935 + the tree converted.
+5 -5
arch/alpha/kernel/osf_sys.c
··· 108 108 int error; 109 109 }; 110 110 111 - static int 111 + static bool 112 112 osf_filldir(struct dir_context *ctx, const char *name, int namlen, 113 113 loff_t offset, u64 ino, unsigned int d_type) 114 114 { ··· 120 120 121 121 buf->error = -EINVAL; /* only used if we fail */ 122 122 if (reclen > buf->count) 123 - return -EINVAL; 123 + return false; 124 124 d_ino = ino; 125 125 if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) { 126 126 buf->error = -EOVERFLOW; 127 - return -EOVERFLOW; 127 + return false; 128 128 } 129 129 if (buf->basep) { 130 130 if (put_user(offset, buf->basep)) ··· 141 141 dirent = (void __user *)dirent + reclen; 142 142 buf->dirent = dirent; 143 143 buf->count -= reclen; 144 - return 0; 144 + return true; 145 145 Efault: 146 146 buf->error = -EFAULT; 147 - return -EFAULT; 147 + return false; 148 148 } 149 149 150 150 SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
+1 -1
drivers/dma-buf/dma-buf.c
··· 531 531 * value. 532 532 */ 533 533 inode->i_ino = atomic64_add_return(1, &dmabuf_inode); 534 + flags &= O_ACCMODE | O_NONBLOCK; 534 535 file = alloc_file_pseudo(inode, dma_buf_mnt, "dmabuf", 535 536 flags, &dma_buf_fops); 536 537 if (IS_ERR(file)) 537 538 goto err_alloc_file; 538 - file->f_flags = flags & (O_ACCMODE | O_NONBLOCK); 539 539 file->private_data = dmabuf; 540 540 file->f_path.dentry->d_fsdata = dmabuf; 541 541
+10 -13
fs/afs/dir.c
··· 24 24 static int afs_d_revalidate(struct dentry *dentry, unsigned int flags); 25 25 static int afs_d_delete(const struct dentry *dentry); 26 26 static void afs_d_iput(struct dentry *dentry, struct inode *inode); 27 - static int afs_lookup_one_filldir(struct dir_context *ctx, const char *name, int nlen, 27 + static bool afs_lookup_one_filldir(struct dir_context *ctx, const char *name, int nlen, 28 28 loff_t fpos, u64 ino, unsigned dtype); 29 - static int afs_lookup_filldir(struct dir_context *ctx, const char *name, int nlen, 29 + static bool afs_lookup_filldir(struct dir_context *ctx, const char *name, int nlen, 30 30 loff_t fpos, u64 ino, unsigned dtype); 31 31 static int afs_create(struct user_namespace *mnt_userns, struct inode *dir, 32 32 struct dentry *dentry, umode_t mode, bool excl); ··· 568 568 * - if afs_dir_iterate_block() spots this function, it'll pass the FID 569 569 * uniquifier through dtype 570 570 */ 571 - static int afs_lookup_one_filldir(struct dir_context *ctx, const char *name, 571 + static bool afs_lookup_one_filldir(struct dir_context *ctx, const char *name, 572 572 int nlen, loff_t fpos, u64 ino, unsigned dtype) 573 573 { 574 574 struct afs_lookup_one_cookie *cookie = ··· 584 584 585 585 if (cookie->name.len != nlen || 586 586 memcmp(cookie->name.name, name, nlen) != 0) { 587 - _leave(" = 0 [no]"); 588 - return 0; 587 + _leave(" = true [keep looking]"); 588 + return true; 589 589 } 590 590 591 591 cookie->fid.vnode = ino; 592 592 cookie->fid.unique = dtype; 593 593 cookie->found = 1; 594 594 595 - _leave(" = -1 [found]"); 596 - return -1; 595 + _leave(" = false [found]"); 596 + return false; 597 597 } 598 598 599 599 /* ··· 636 636 * - if afs_dir_iterate_block() spots this function, it'll pass the FID 637 637 * uniquifier through dtype 638 638 */ 639 - static int afs_lookup_filldir(struct dir_context *ctx, const char *name, 639 + static bool afs_lookup_filldir(struct dir_context *ctx, const char *name, 640 640 int nlen, loff_t fpos, u64 ino, unsigned dtype) 641 641 { 642 642 struct afs_lookup_cookie *cookie = 643 643 container_of(ctx, struct afs_lookup_cookie, ctx); 644 - int ret; 645 644 646 645 _enter("{%s,%u},%s,%u,,%llu,%u", 647 646 cookie->name.name, cookie->name.len, name, nlen, ··· 662 663 cookie->fids[1].unique = dtype; 663 664 cookie->found = 1; 664 665 if (cookie->one_only) 665 - return -1; 666 + return false; 666 667 } 667 668 668 - ret = cookie->nr_fids >= 50 ? -1 : 0; 669 - _leave(" = %d", ret); 670 - return ret; 669 + return cookie->nr_fids < 50; 671 670 } 672 671 673 672 /*
+16 -22
fs/ecryptfs/file.c
··· 53 53 }; 54 54 55 55 /* Inspired by generic filldir in fs/readdir.c */ 56 - static int 56 + static bool 57 57 ecryptfs_filldir(struct dir_context *ctx, const char *lower_name, 58 58 int lower_namelen, loff_t offset, u64 ino, unsigned int d_type) 59 59 { ··· 61 61 container_of(ctx, struct ecryptfs_getdents_callback, ctx); 62 62 size_t name_size; 63 63 char *name; 64 - int rc; 64 + int err; 65 + bool res; 65 66 66 67 buf->filldir_called++; 67 - rc = ecryptfs_decode_and_decrypt_filename(&name, &name_size, 68 - buf->sb, lower_name, 69 - lower_namelen); 70 - if (rc) { 71 - if (rc != -EINVAL) { 68 + err = ecryptfs_decode_and_decrypt_filename(&name, &name_size, 69 + buf->sb, lower_name, 70 + lower_namelen); 71 + if (err) { 72 + if (err != -EINVAL) { 72 73 ecryptfs_printk(KERN_DEBUG, 73 74 "%s: Error attempting to decode and decrypt filename [%s]; rc = [%d]\n", 74 - __func__, lower_name, rc); 75 - return rc; 75 + __func__, lower_name, err); 76 + return false; 76 77 } 77 78 78 79 /* Mask -EINVAL errors as these are most likely due a plaintext ··· 82 81 * the "lost+found" dentry in the root directory of an Ext4 83 82 * filesystem. 84 83 */ 85 - return 0; 84 + return true; 86 85 } 87 86 88 87 buf->caller->pos = buf->ctx.pos; 89 - rc = !dir_emit(buf->caller, name, name_size, ino, d_type); 88 + res = dir_emit(buf->caller, name, name_size, ino, d_type); 90 89 kfree(name); 91 - if (!rc) 90 + if (res) 92 91 buf->entries_written++; 93 - 94 - return rc; 92 + return res; 95 93 } 96 94 97 95 /** ··· 111 111 lower_file = ecryptfs_file_to_lower(file); 112 112 rc = iterate_dir(lower_file, &buf.ctx); 113 113 ctx->pos = buf.ctx.pos; 114 - if (rc < 0) 115 - goto out; 116 - if (buf.filldir_called && !buf.entries_written) 117 - goto out; 118 - if (rc >= 0) 119 - fsstack_copy_attr_atime(inode, 120 - file_inode(lower_file)); 121 - out: 114 + if (rc >= 0 && (buf.entries_written || !buf.filldir_called)) 115 + fsstack_copy_attr_atime(inode, file_inode(lower_file)); 122 116 return rc; 123 117 } 124 118
+3 -4
fs/exportfs/expfs.c
··· 248 248 * A rather strange filldir function to capture 249 249 * the name matching the specified inode number. 250 250 */ 251 - static int filldir_one(struct dir_context *ctx, const char *name, int len, 251 + static bool filldir_one(struct dir_context *ctx, const char *name, int len, 252 252 loff_t pos, u64 ino, unsigned int d_type) 253 253 { 254 254 struct getdents_callback *buf = 255 255 container_of(ctx, struct getdents_callback, ctx); 256 - int result = 0; 257 256 258 257 buf->sequence++; 259 258 if (buf->ino == ino && len <= NAME_MAX) { 260 259 memcpy(buf->name, name, len); 261 260 buf->name[len] = '\0'; 262 261 buf->found = 1; 263 - result = -1; 262 + return false; // no more 264 263 } 265 - return result; 264 + return true; 266 265 } 267 266 268 267 /**
+4 -4
fs/fat/dir.c
··· 705 705 } 706 706 707 707 #define FAT_IOCTL_FILLDIR_FUNC(func, dirent_type) \ 708 - static int func(struct dir_context *ctx, const char *name, int name_len, \ 708 + static bool func(struct dir_context *ctx, const char *name, int name_len, \ 709 709 loff_t offset, u64 ino, unsigned int d_type) \ 710 710 { \ 711 711 struct fat_ioctl_filldir_callback *buf = \ ··· 714 714 struct dirent_type __user *d2 = d1 + 1; \ 715 715 \ 716 716 if (buf->result) \ 717 - return -EINVAL; \ 717 + return false; \ 718 718 buf->result++; \ 719 719 \ 720 720 if (name != NULL) { \ ··· 750 750 put_user(short_len, &d1->d_reclen)) \ 751 751 goto efault; \ 752 752 } \ 753 - return 0; \ 753 + return true; \ 754 754 efault: \ 755 755 buf->result = -EFAULT; \ 756 - return -EFAULT; \ 756 + return false; \ 757 757 } 758 758 759 759 FAT_IOCTL_FILLDIR_FUNC(fat_ioctl_filldir, __fat_dirent)
+1 -6
fs/file_table.c
··· 324 324 } 325 325 fops_put(file->f_op); 326 326 put_pid(file->f_owner.pid); 327 - if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) 328 - i_readcount_dec(inode); 329 - if (mode & FMODE_WRITER) { 330 - put_write_access(inode); 331 - __mnt_drop_write(mnt); 332 - } 327 + put_file_access(file); 333 328 dput(dentry); 334 329 if (unlikely(mode & FMODE_NEED_UNMOUNT)) 335 330 dissolve_on_fput(mnt);
+3 -3
fs/gfs2/export.c
··· 66 66 char *name; 67 67 }; 68 68 69 - static int get_name_filldir(struct dir_context *ctx, const char *name, 69 + static bool get_name_filldir(struct dir_context *ctx, const char *name, 70 70 int length, loff_t offset, u64 inum, 71 71 unsigned int type) 72 72 { ··· 74 74 container_of(ctx, struct get_name_filldir, ctx); 75 75 76 76 if (inum != gnfd->inum.no_addr) 77 - return 0; 77 + return true; 78 78 79 79 memcpy(gnfd->name, name, length); 80 80 gnfd->name[length] = 0; 81 81 82 - return 1; 82 + return false; 83 83 } 84 84 85 85 static int gfs2_get_name(struct dentry *parent, char *name,
+10
fs/internal.h
··· 102 102 extern struct file *alloc_empty_file(int, const struct cred *); 103 103 extern struct file *alloc_empty_file_noaccount(int, const struct cred *); 104 104 105 + static inline void put_file_access(struct file *file) 106 + { 107 + if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) { 108 + i_readcount_dec(file->f_inode); 109 + } else if (file->f_mode & FMODE_WRITER) { 110 + put_write_access(file->f_inode); 111 + __mnt_drop_write(file->f_path.mnt); 112 + } 113 + } 114 + 105 115 /* 106 116 * super.c 107 117 */
+7 -9
fs/ksmbd/smb2pdu.c
··· 3776 3776 return 0; 3777 3777 } 3778 3778 3779 - static int __query_dir(struct dir_context *ctx, const char *name, int namlen, 3779 + static bool __query_dir(struct dir_context *ctx, const char *name, int namlen, 3780 3780 loff_t offset, u64 ino, unsigned int d_type) 3781 3781 { 3782 3782 struct ksmbd_readdir_data *buf; ··· 3790 3790 3791 3791 /* dot and dotdot entries are already reserved */ 3792 3792 if (!strcmp(".", name) || !strcmp("..", name)) 3793 - return 0; 3793 + return true; 3794 3794 if (ksmbd_share_veto_filename(priv->work->tcon->share_conf, name)) 3795 - return 0; 3795 + return true; 3796 3796 if (!match_pattern(name, namlen, priv->search_pattern)) 3797 - return 0; 3797 + return true; 3798 3798 3799 3799 d_info->name = name; 3800 3800 d_info->name_len = namlen; 3801 3801 rc = reserve_populate_dentry(d_info, priv->info_level); 3802 3802 if (rc) 3803 - return rc; 3804 - if (d_info->flags & SMB2_RETURN_SINGLE_ENTRY) { 3803 + return false; 3804 + if (d_info->flags & SMB2_RETURN_SINGLE_ENTRY) 3805 3805 d_info->out_buf_len = 0; 3806 - return 0; 3807 - } 3808 - return 0; 3806 + return true; 3809 3807 } 3810 3808 3811 3809 static void restart_ctx(struct dir_context *ctx)
+6 -8
fs/ksmbd/vfs.c
··· 1105 1105 return err; 1106 1106 } 1107 1107 1108 - static int __dir_empty(struct dir_context *ctx, const char *name, int namlen, 1108 + static bool __dir_empty(struct dir_context *ctx, const char *name, int namlen, 1109 1109 loff_t offset, u64 ino, unsigned int d_type) 1110 1110 { 1111 1111 struct ksmbd_readdir_data *buf; ··· 1113 1113 buf = container_of(ctx, struct ksmbd_readdir_data, ctx); 1114 1114 buf->dirent_count++; 1115 1115 1116 - if (buf->dirent_count > 2) 1117 - return -ENOTEMPTY; 1118 - return 0; 1116 + return buf->dirent_count <= 2; 1119 1117 } 1120 1118 1121 1119 /** ··· 1140 1142 return err; 1141 1143 } 1142 1144 1143 - static int __caseless_lookup(struct dir_context *ctx, const char *name, 1145 + static bool __caseless_lookup(struct dir_context *ctx, const char *name, 1144 1146 int namlen, loff_t offset, u64 ino, 1145 1147 unsigned int d_type) 1146 1148 { ··· 1149 1151 buf = container_of(ctx, struct ksmbd_readdir_data, ctx); 1150 1152 1151 1153 if (buf->used != namlen) 1152 - return 0; 1154 + return true; 1153 1155 if (!strncasecmp((char *)buf->private, name, namlen)) { 1154 1156 memcpy((char *)buf->private, name, namlen); 1155 1157 buf->dirent_count = 1; 1156 - return -EEXIST; 1158 + return false; 1157 1159 } 1158 - return 0; 1160 + return true; 1159 1161 } 1160 1162 1161 1163 /**
+4 -4
fs/nfsd/nfs4recover.c
··· 266 266 struct list_head names; 267 267 }; 268 268 269 - static int 269 + static bool 270 270 nfsd4_build_namelist(struct dir_context *__ctx, const char *name, int namlen, 271 271 loff_t offset, u64 ino, unsigned int d_type) 272 272 { ··· 275 275 struct name_list *entry; 276 276 277 277 if (namlen != HEXDIR_LEN - 1) 278 - return 0; 278 + return true; 279 279 entry = kmalloc(sizeof(struct name_list), GFP_KERNEL); 280 280 if (entry == NULL) 281 - return -ENOMEM; 281 + return false; 282 282 memcpy(entry->name, name, HEXDIR_LEN - 1); 283 283 entry->name[HEXDIR_LEN - 1] = '\0'; 284 284 list_add(&entry->list, &ctx->names); 285 - return 0; 285 + return true; 286 286 } 287 287 288 288 static int
+3 -3
fs/nfsd/vfs.c
··· 1854 1854 int full; 1855 1855 }; 1856 1856 1857 - static int nfsd_buffered_filldir(struct dir_context *ctx, const char *name, 1857 + static bool nfsd_buffered_filldir(struct dir_context *ctx, const char *name, 1858 1858 int namlen, loff_t offset, u64 ino, 1859 1859 unsigned int d_type) 1860 1860 { ··· 1866 1866 reclen = ALIGN(sizeof(struct buffered_dirent) + namlen, sizeof(u64)); 1867 1867 if (buf->used + reclen > PAGE_SIZE) { 1868 1868 buf->full = 1; 1869 - return -EINVAL; 1869 + return false; 1870 1870 } 1871 1871 1872 1872 de->namlen = namlen; ··· 1876 1876 memcpy(de->name, name, namlen); 1877 1877 buf->used += reclen; 1878 1878 1879 - return 0; 1879 + return true; 1880 1880 } 1881 1881 1882 1882 static __be32 nfsd_buffered_readdir(struct file *file, struct svc_fh *fhp,
+5 -5
fs/ocfs2/dir.c
··· 2032 2032 unsigned seen_other; 2033 2033 unsigned dx_dir; 2034 2034 }; 2035 - static int ocfs2_empty_dir_filldir(struct dir_context *ctx, const char *name, 2035 + static bool ocfs2_empty_dir_filldir(struct dir_context *ctx, const char *name, 2036 2036 int name_len, loff_t pos, u64 ino, 2037 2037 unsigned type) 2038 2038 { ··· 2052 2052 */ 2053 2053 if (name_len == 1 && !strncmp(".", name, 1) && pos == 0) { 2054 2054 p->seen_dot = 1; 2055 - return 0; 2055 + return true; 2056 2056 } 2057 2057 2058 2058 if (name_len == 2 && !strncmp("..", name, 2) && ··· 2060 2060 p->seen_dot_dot = 1; 2061 2061 2062 2062 if (p->dx_dir && p->seen_dot) 2063 - return 1; 2063 + return false; 2064 2064 2065 - return 0; 2065 + return true; 2066 2066 } 2067 2067 2068 2068 p->seen_other = 1; 2069 - return 1; 2069 + return false; 2070 2070 } 2071 2071 2072 2072 static int ocfs2_empty_dir_dx(struct inode *inode,
+7 -7
fs/ocfs2/journal.c
··· 2057 2057 enum ocfs2_orphan_reco_type orphan_reco_type; 2058 2058 }; 2059 2059 2060 - static int ocfs2_orphan_filldir(struct dir_context *ctx, const char *name, 2060 + static bool ocfs2_orphan_filldir(struct dir_context *ctx, const char *name, 2061 2061 int name_len, loff_t pos, u64 ino, 2062 2062 unsigned type) 2063 2063 { ··· 2066 2066 struct inode *iter; 2067 2067 2068 2068 if (name_len == 1 && !strncmp(".", name, 1)) 2069 - return 0; 2069 + return true; 2070 2070 if (name_len == 2 && !strncmp("..", name, 2)) 2071 - return 0; 2071 + return true; 2072 2072 2073 2073 /* do not include dio entry in case of orphan scan */ 2074 2074 if ((p->orphan_reco_type == ORPHAN_NO_NEED_TRUNCATE) && 2075 2075 (!strncmp(name, OCFS2_DIO_ORPHAN_PREFIX, 2076 2076 OCFS2_DIO_ORPHAN_PREFIX_LEN))) 2077 - return 0; 2077 + return true; 2078 2078 2079 2079 /* Skip bad inodes so that recovery can continue */ 2080 2080 iter = ocfs2_iget(p->osb, ino, 2081 2081 OCFS2_FI_FLAG_ORPHAN_RECOVERY, 0); 2082 2082 if (IS_ERR(iter)) 2083 - return 0; 2083 + return true; 2084 2084 2085 2085 if (!strncmp(name, OCFS2_DIO_ORPHAN_PREFIX, 2086 2086 OCFS2_DIO_ORPHAN_PREFIX_LEN)) ··· 2090 2090 * happen concurrently with unlink/rename */ 2091 2091 if (OCFS2_I(iter)->ip_next_orphan) { 2092 2092 iput(iter); 2093 - return 0; 2093 + return true; 2094 2094 } 2095 2095 2096 2096 trace_ocfs2_orphan_filldir((unsigned long long)OCFS2_I(iter)->ip_blkno); ··· 2099 2099 OCFS2_I(iter)->ip_next_orphan = p->head; 2100 2100 p->head = iter; 2101 2101 2102 - return 0; 2102 + return true; 2103 2103 } 2104 2104 2105 2105 static int ocfs2_queue_orphans(struct ocfs2_super *osb,
+4 -7
fs/open.c
··· 842 842 return 0; 843 843 } 844 844 845 - if (f->f_mode & FMODE_WRITE && !special_file(inode->i_mode)) { 845 + if ((f->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) { 846 + i_readcount_inc(inode); 847 + } else if (f->f_mode & FMODE_WRITE && !special_file(inode->i_mode)) { 846 848 error = get_write_access(inode); 847 849 if (unlikely(error)) 848 850 goto cleanup_file; ··· 884 882 goto cleanup_all; 885 883 } 886 884 f->f_mode |= FMODE_OPENED; 887 - if ((f->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) 888 - i_readcount_inc(inode); 889 885 if ((f->f_mode & FMODE_READ) && 890 886 likely(f->f_op->read || f->f_op->read_iter)) 891 887 f->f_mode |= FMODE_CAN_READ; ··· 937 937 if (WARN_ON_ONCE(error > 0)) 938 938 error = -EINVAL; 939 939 fops_put(f->f_op); 940 - if (f->f_mode & FMODE_WRITER) { 941 - put_write_access(inode); 942 - __mnt_drop_write(f->f_path.mnt); 943 - } 940 + put_file_access(f); 944 941 cleanup_file: 945 942 path_put(&f->f_path); 946 943 f->f_path.mnt = NULL;
+14 -14
fs/overlayfs/readdir.c
··· 170 170 return p; 171 171 } 172 172 173 - static int ovl_cache_entry_add_rb(struct ovl_readdir_data *rdd, 173 + static bool ovl_cache_entry_add_rb(struct ovl_readdir_data *rdd, 174 174 const char *name, int len, u64 ino, 175 175 unsigned int d_type) 176 176 { ··· 179 179 struct ovl_cache_entry *p; 180 180 181 181 if (ovl_cache_entry_find_link(name, len, &newp, &parent)) 182 - return 0; 182 + return true; 183 183 184 184 p = ovl_cache_entry_new(rdd, name, len, ino, d_type); 185 185 if (p == NULL) { 186 186 rdd->err = -ENOMEM; 187 - return -ENOMEM; 187 + return false; 188 188 } 189 189 190 190 list_add_tail(&p->l_node, rdd->list); 191 191 rb_link_node(&p->node, parent, newp); 192 192 rb_insert_color(&p->node, rdd->root); 193 193 194 - return 0; 194 + return true; 195 195 } 196 196 197 - static int ovl_fill_lowest(struct ovl_readdir_data *rdd, 197 + static bool ovl_fill_lowest(struct ovl_readdir_data *rdd, 198 198 const char *name, int namelen, 199 199 loff_t offset, u64 ino, unsigned int d_type) 200 200 { ··· 211 211 list_add_tail(&p->l_node, &rdd->middle); 212 212 } 213 213 214 - return rdd->err; 214 + return rdd->err == 0; 215 215 } 216 216 217 217 void ovl_cache_free(struct list_head *list) ··· 250 250 } 251 251 } 252 252 253 - static int ovl_fill_merge(struct dir_context *ctx, const char *name, 253 + static bool ovl_fill_merge(struct dir_context *ctx, const char *name, 254 254 int namelen, loff_t offset, u64 ino, 255 255 unsigned int d_type) 256 256 { ··· 528 528 goto out; 529 529 } 530 530 531 - static int ovl_fill_plain(struct dir_context *ctx, const char *name, 531 + static bool ovl_fill_plain(struct dir_context *ctx, const char *name, 532 532 int namelen, loff_t offset, u64 ino, 533 533 unsigned int d_type) 534 534 { ··· 540 540 p = ovl_cache_entry_new(rdd, name, namelen, ino, d_type); 541 541 if (p == NULL) { 542 542 rdd->err = -ENOMEM; 543 - return -ENOMEM; 543 + return false; 544 544 } 545 545 list_add_tail(&p->l_node, rdd->list); 546 546 547 - return 0; 547 + return true; 548 548 } 549 549 550 550 static int ovl_dir_read_impure(struct path *path, struct list_head *list, ··· 648 648 bool xinowarn; 649 649 }; 650 650 651 - static int ovl_fill_real(struct dir_context *ctx, const char *name, 651 + static bool ovl_fill_real(struct dir_context *ctx, const char *name, 652 652 int namelen, loff_t offset, u64 ino, 653 653 unsigned int d_type) 654 654 { ··· 1027 1027 inode_unlock(upper->d_inode); 1028 1028 } 1029 1029 1030 - static int ovl_check_d_type(struct dir_context *ctx, const char *name, 1030 + static bool ovl_check_d_type(struct dir_context *ctx, const char *name, 1031 1031 int namelen, loff_t offset, u64 ino, 1032 1032 unsigned int d_type) 1033 1033 { ··· 1036 1036 1037 1037 /* Even if d_type is not supported, DT_DIR is returned for . and .. */ 1038 1038 if (!strncmp(name, ".", namelen) || !strncmp(name, "..", namelen)) 1039 - return 0; 1039 + return true; 1040 1040 1041 1041 if (d_type != DT_UNKNOWN) 1042 1042 rdd->d_type_supported = true; 1043 1043 1044 - return 0; 1044 + return true; 1045 1045 } 1046 1046 1047 1047 /*
+34 -34
fs/readdir.c
··· 140 140 int result; 141 141 }; 142 142 143 - static int fillonedir(struct dir_context *ctx, const char *name, int namlen, 143 + static bool fillonedir(struct dir_context *ctx, const char *name, int namlen, 144 144 loff_t offset, u64 ino, unsigned int d_type) 145 145 { 146 146 struct readdir_callback *buf = ··· 149 149 unsigned long d_ino; 150 150 151 151 if (buf->result) 152 - return -EINVAL; 152 + return false; 153 153 buf->result = verify_dirent_name(name, namlen); 154 - if (buf->result < 0) 155 - return buf->result; 154 + if (buf->result) 155 + return false; 156 156 d_ino = ino; 157 157 if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) { 158 158 buf->result = -EOVERFLOW; 159 - return -EOVERFLOW; 159 + return false; 160 160 } 161 161 buf->result++; 162 162 dirent = buf->dirent; ··· 169 169 unsafe_put_user(namlen, &dirent->d_namlen, efault_end); 170 170 unsafe_copy_dirent_name(dirent->d_name, name, namlen, efault_end); 171 171 user_write_access_end(); 172 - return 0; 172 + return true; 173 173 efault_end: 174 174 user_write_access_end(); 175 175 efault: 176 176 buf->result = -EFAULT; 177 - return -EFAULT; 177 + return false; 178 178 } 179 179 180 180 SYSCALL_DEFINE3(old_readdir, unsigned int, fd, ··· 219 219 int error; 220 220 }; 221 221 222 - static int filldir(struct dir_context *ctx, const char *name, int namlen, 222 + static bool filldir(struct dir_context *ctx, const char *name, int namlen, 223 223 loff_t offset, u64 ino, unsigned int d_type) 224 224 { 225 225 struct linux_dirent __user *dirent, *prev; ··· 232 232 233 233 buf->error = verify_dirent_name(name, namlen); 234 234 if (unlikely(buf->error)) 235 - return buf->error; 235 + return false; 236 236 buf->error = -EINVAL; /* only used if we fail.. */ 237 237 if (reclen > buf->count) 238 - return -EINVAL; 238 + return false; 239 239 d_ino = ino; 240 240 if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) { 241 241 buf->error = -EOVERFLOW; 242 - return -EOVERFLOW; 242 + return false; 243 243 } 244 244 prev_reclen = buf->prev_reclen; 245 245 if (prev_reclen && signal_pending(current)) 246 - return -EINTR; 246 + return false; 247 247 dirent = buf->current_dir; 248 248 prev = (void __user *) dirent - prev_reclen; 249 249 if (!user_write_access_begin(prev, reclen + prev_reclen)) ··· 260 260 buf->current_dir = (void __user *)dirent + reclen; 261 261 buf->prev_reclen = reclen; 262 262 buf->count -= reclen; 263 - return 0; 263 + return true; 264 264 efault_end: 265 265 user_write_access_end(); 266 266 efault: 267 267 buf->error = -EFAULT; 268 - return -EFAULT; 268 + return false; 269 269 } 270 270 271 271 SYSCALL_DEFINE3(getdents, unsigned int, fd, ··· 307 307 int error; 308 308 }; 309 309 310 - static int filldir64(struct dir_context *ctx, const char *name, int namlen, 310 + static bool filldir64(struct dir_context *ctx, const char *name, int namlen, 311 311 loff_t offset, u64 ino, unsigned int d_type) 312 312 { 313 313 struct linux_dirent64 __user *dirent, *prev; ··· 319 319 320 320 buf->error = verify_dirent_name(name, namlen); 321 321 if (unlikely(buf->error)) 322 - return buf->error; 322 + return false; 323 323 buf->error = -EINVAL; /* only used if we fail.. */ 324 324 if (reclen > buf->count) 325 - return -EINVAL; 325 + return false; 326 326 prev_reclen = buf->prev_reclen; 327 327 if (prev_reclen && signal_pending(current)) 328 - return -EINTR; 328 + return false; 329 329 dirent = buf->current_dir; 330 330 prev = (void __user *)dirent - prev_reclen; 331 331 if (!user_write_access_begin(prev, reclen + prev_reclen)) ··· 342 342 buf->prev_reclen = reclen; 343 343 buf->current_dir = (void __user *)dirent + reclen; 344 344 buf->count -= reclen; 345 - return 0; 345 + return true; 346 346 347 347 efault_end: 348 348 user_write_access_end(); 349 349 efault: 350 350 buf->error = -EFAULT; 351 - return -EFAULT; 351 + return false; 352 352 } 353 353 354 354 SYSCALL_DEFINE3(getdents64, unsigned int, fd, ··· 397 397 int result; 398 398 }; 399 399 400 - static int compat_fillonedir(struct dir_context *ctx, const char *name, 400 + static bool compat_fillonedir(struct dir_context *ctx, const char *name, 401 401 int namlen, loff_t offset, u64 ino, 402 402 unsigned int d_type) 403 403 { ··· 407 407 compat_ulong_t d_ino; 408 408 409 409 if (buf->result) 410 - return -EINVAL; 410 + return false; 411 411 buf->result = verify_dirent_name(name, namlen); 412 - if (buf->result < 0) 413 - return buf->result; 412 + if (buf->result) 413 + return false; 414 414 d_ino = ino; 415 415 if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) { 416 416 buf->result = -EOVERFLOW; 417 - return -EOVERFLOW; 417 + return false; 418 418 } 419 419 buf->result++; 420 420 dirent = buf->dirent; ··· 427 427 unsafe_put_user(namlen, &dirent->d_namlen, efault_end); 428 428 unsafe_copy_dirent_name(dirent->d_name, name, namlen, efault_end); 429 429 user_write_access_end(); 430 - return 0; 430 + return true; 431 431 efault_end: 432 432 user_write_access_end(); 433 433 efault: 434 434 buf->result = -EFAULT; 435 - return -EFAULT; 435 + return false; 436 436 } 437 437 438 438 COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd, ··· 471 471 int error; 472 472 }; 473 473 474 - static int compat_filldir(struct dir_context *ctx, const char *name, int namlen, 474 + static bool compat_filldir(struct dir_context *ctx, const char *name, int namlen, 475 475 loff_t offset, u64 ino, unsigned int d_type) 476 476 { 477 477 struct compat_linux_dirent __user *dirent, *prev; ··· 484 484 485 485 buf->error = verify_dirent_name(name, namlen); 486 486 if (unlikely(buf->error)) 487 - return buf->error; 487 + return false; 488 488 buf->error = -EINVAL; /* only used if we fail.. */ 489 489 if (reclen > buf->count) 490 - return -EINVAL; 490 + return false; 491 491 d_ino = ino; 492 492 if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) { 493 493 buf->error = -EOVERFLOW; 494 - return -EOVERFLOW; 494 + return false; 495 495 } 496 496 prev_reclen = buf->prev_reclen; 497 497 if (prev_reclen && signal_pending(current)) 498 - return -EINTR; 498 + return false; 499 499 dirent = buf->current_dir; 500 500 prev = (void __user *) dirent - prev_reclen; 501 501 if (!user_write_access_begin(prev, reclen + prev_reclen)) ··· 511 511 buf->prev_reclen = reclen; 512 512 buf->current_dir = (void __user *)dirent + reclen; 513 513 buf->count -= reclen; 514 - return 0; 514 + return true; 515 515 efault_end: 516 516 user_write_access_end(); 517 517 efault: 518 518 buf->error = -EFAULT; 519 - return -EFAULT; 519 + return false; 520 520 } 521 521 522 522 COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
+10 -10
fs/reiserfs/xattr.c
··· 189 189 struct dentry *dentries[8]; 190 190 }; 191 191 192 - static int 192 + static bool 193 193 fill_with_dentries(struct dir_context *ctx, const char *name, int namelen, 194 194 loff_t offset, u64 ino, unsigned int d_type) 195 195 { ··· 200 200 WARN_ON_ONCE(!inode_is_locked(d_inode(dbuf->xadir))); 201 201 202 202 if (dbuf->count == ARRAY_SIZE(dbuf->dentries)) 203 - return -ENOSPC; 203 + return false; 204 204 205 205 if (name[0] == '.' && (namelen < 2 || 206 206 (namelen == 2 && name[1] == '.'))) 207 - return 0; 207 + return true; 208 208 209 209 dentry = lookup_one_len(name, dbuf->xadir, namelen); 210 210 if (IS_ERR(dentry)) { 211 211 dbuf->err = PTR_ERR(dentry); 212 - return PTR_ERR(dentry); 212 + return false; 213 213 } else if (d_really_is_negative(dentry)) { 214 214 /* A directory entry exists, but no file? */ 215 215 reiserfs_error(dentry->d_sb, "xattr-20003", ··· 218 218 dentry, dbuf->xadir); 219 219 dput(dentry); 220 220 dbuf->err = -EIO; 221 - return -EIO; 221 + return false; 222 222 } 223 223 224 224 dbuf->dentries[dbuf->count++] = dentry; 225 - return 0; 225 + return true; 226 226 } 227 227 228 228 static void ··· 797 797 struct dentry *dentry; 798 798 }; 799 799 800 - static int listxattr_filler(struct dir_context *ctx, const char *name, 800 + static bool listxattr_filler(struct dir_context *ctx, const char *name, 801 801 int namelen, loff_t offset, u64 ino, 802 802 unsigned int d_type) 803 803 { ··· 813 813 name); 814 814 if (!handler /* Unsupported xattr name */ || 815 815 (handler->list && !handler->list(b->dentry))) 816 - return 0; 816 + return true; 817 817 size = namelen + 1; 818 818 if (b->buf) { 819 819 if (b->pos + size > b->size) { 820 820 b->pos = -ERANGE; 821 - return -ERANGE; 821 + return false; 822 822 } 823 823 memcpy(b->buf + b->pos, name, namelen); 824 824 b->buf[b->pos + namelen] = 0; 825 825 } 826 826 b->pos += size; 827 827 } 828 - return 0; 828 + return true; 829 829 } 830 830 831 831 /*
+4 -4
fs/xfs/scrub/dir.c
··· 99 99 * we check the inode number to make sure it's sane, then we check that 100 100 * we can look up this filename. Finally, we check the ftype. 101 101 */ 102 - STATIC int 102 + STATIC bool 103 103 xchk_dir_actor( 104 104 struct dir_context *dir_iter, 105 105 const char *name, ··· 124 124 xfs_dir2_dataptr_to_db(mp->m_dir_geo, pos)); 125 125 126 126 if (xchk_should_terminate(sdc->sc, &error)) 127 - return error; 127 + return !error; 128 128 129 129 /* Does this inode number make sense? */ 130 130 if (!xfs_verify_dir_ino(mp, ino)) { ··· 191 191 * and return zero to xchk_directory. 192 192 */ 193 193 if (error == 0 && sdc->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) 194 - return -EFSCORRUPTED; 195 - return error; 194 + return false; 195 + return !error; 196 196 } 197 197 198 198 /* Scrub a directory btree record. */
+2 -2
fs/xfs/scrub/parent.c
··· 38 38 }; 39 39 40 40 /* Look for a single entry in a directory pointing to an inode. */ 41 - STATIC int 41 + STATIC bool 42 42 xchk_parent_actor( 43 43 struct dir_context *dc, 44 44 const char *name, ··· 62 62 if (xchk_should_terminate(spc->sc, &error)) 63 63 spc->cancelled = true; 64 64 65 - return error; 65 + return !error; 66 66 } 67 67 68 68 /* Count the number of dentries in the parent dir that point to this inode. */
+5 -4
include/linux/fs.h
··· 2038 2038 * the kernel specify what kind of dirent layout it wants to have. 2039 2039 * This allows the kernel to read directories into kernel space or 2040 2040 * to have different dirent layouts depending on the binary type. 2041 + * Return 'true' to keep going and 'false' if there are no more entries. 2041 2042 */ 2042 2043 struct dir_context; 2043 - typedef int (*filldir_t)(struct dir_context *, const char *, int, loff_t, u64, 2044 + typedef bool (*filldir_t)(struct dir_context *, const char *, int, loff_t, u64, 2044 2045 unsigned); 2045 2046 2046 2047 struct dir_context { ··· 3541 3540 const char *name, int namelen, 3542 3541 u64 ino, unsigned type) 3543 3542 { 3544 - return ctx->actor(ctx, name, namelen, ctx->pos, ino, type) == 0; 3543 + return ctx->actor(ctx, name, namelen, ctx->pos, ino, type); 3545 3544 } 3546 3545 static inline bool dir_emit_dot(struct file *file, struct dir_context *ctx) 3547 3546 { 3548 3547 return ctx->actor(ctx, ".", 1, ctx->pos, 3549 - file->f_path.dentry->d_inode->i_ino, DT_DIR) == 0; 3548 + file->f_path.dentry->d_inode->i_ino, DT_DIR); 3550 3549 } 3551 3550 static inline bool dir_emit_dotdot(struct file *file, struct dir_context *ctx) 3552 3551 { 3553 3552 return ctx->actor(ctx, "..", 2, ctx->pos, 3554 - parent_ino(file->f_path.dentry), DT_DIR) == 0; 3553 + parent_ino(file->f_path.dentry), DT_DIR); 3555 3554 } 3556 3555 static inline bool dir_emit_dots(struct file *file, struct dir_context *ctx) 3557 3556 {