Lines Matching refs:file
11 #include <linux/file.h>
40 /* SLAB cache for file structures */
47 struct file *f = container_of(head, struct file, f_u.fu_rcuhead);
53 static inline void file_free(struct file *f)
96 static struct file *__alloc_file(int flags, const struct cred *cred)
98 struct file *f;
124 /* Find an unused file structure and return a pointer to it.
125 * Returns an error pointer if some error happend e.g. we over file
134 struct file *alloc_empty_file(int flags, const struct cred *cred)
137 struct file *f;
160 pr_info("VFS: file-max limit %lu reached\n", get_max_files());
171 struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred)
173 struct file *f = __alloc_file(flags, cred);
182 * alloc_file - allocate and initialize a 'struct file'
184 * @path: the (dentry, vfsmount) pair for the new file
185 * @flags: O_... flags with which the new file will be opened
186 * @fop: the 'struct file_operations' for the new file
188 static struct file *alloc_file(const struct path *path, int flags,
191 struct file *file;
193 file = alloc_empty_file(flags, current_cred());
194 if (IS_ERR(file))
195 return file;
197 file->f_path = *path;
198 file->f_inode = path->dentry->d_inode;
199 file->f_mapping = path->dentry->d_inode->i_mapping;
200 file->f_wb_err = filemap_sample_wb_err(file->f_mapping);
201 file->f_sb_err = file_sample_sb_err(file);
202 if ((file->f_mode & FMODE_READ) &&
204 file->f_mode |= FMODE_CAN_READ;
205 if ((file->f_mode & FMODE_WRITE) &&
207 file->f_mode |= FMODE_CAN_WRITE;
208 file->f_mode |= FMODE_OPENED;
209 file->f_op = fop;
210 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
212 return file;
215 struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt,
224 struct file *file;
233 file = alloc_file(&path, flags, fops);
234 if (IS_ERR(file)) {
238 return file;
242 struct file *alloc_file_clone(struct file *base, int flags,
245 struct file *f = alloc_file(&base->f_path, flags, fops);
253 /* the real guts of fput() - releasing the last reference to file
255 static void __fput(struct file *file)
257 struct dentry *dentry = file->f_path.dentry;
258 struct vfsmount *mnt = file->f_path.mnt;
259 struct inode *inode = file->f_inode;
260 fmode_t mode = file->f_mode;
262 if (unlikely(!(file->f_mode & FMODE_OPENED)))
267 fsnotify_close(file);
270 * in the file cleanup chain.
272 eventpoll_release(file);
273 locks_remove_file(file);
275 ima_file_free(file);
276 if (unlikely(file->f_flags & FASYNC)) {
277 if (file->f_op->fasync)
278 file->f_op->fasync(-1, file, 0);
280 if (file->f_op->release)
281 file->f_op->release(inode, file);
286 fops_put(file->f_op);
287 put_pid(file->f_owner.pid);
299 file_free(file);
306 struct file *f, *t;
314 __fput(container_of(work, struct file, f_u.fu_rcuhead));
321 * not left us with opened struct file waiting for __fput() - execve()
335 void fput_many(struct file *file, unsigned int refs)
337 if (atomic_long_sub_and_test(refs, &file->f_count)) {
341 init_task_work(&file->f_u.fu_rcuhead, ____fput);
342 if (!task_work_add(task, &file->f_u.fu_rcuhead, TWA_RESUME))
347 * fput to avoid leaking *file.
351 if (llist_add(&file->f_u.fu_llist, &delayed_fput_list))
356 void fput(struct file *file)
358 fput_many(file, 1);
365 * for this specific struct file it won't involve anything that would
369 void __fput_sync(struct file *file)
371 if (atomic_long_dec_and_test(&file->f_count)) {
374 __fput(file);
383 filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0,
389 * One file with associated inode and dcache is very roughly 1K. Per default