Lines Matching full:file
11 #include <linux/file.h>
42 /* SLAB cache for file structures */
47 /* Container for backing file with optional real path */
49 struct file file; member
53 static inline struct backing_file *backing_file(struct file *f) in backing_file()
55 return container_of(f, struct backing_file, file); in backing_file()
58 struct path *backing_file_real_path(struct file *f) in backing_file_real_path()
66 struct file *f = container_of(head, struct file, f_rcuhead); in file_free_rcu()
75 static inline void file_free(struct file *f) in file_free()
116 .procname = "file-nr",
123 .procname = "file-max",
156 static int init_file(struct file *f, int flags, const struct cred *cred) in init_file()
178 /* Find an unused file structure and return a pointer to it.
179 * Returns an error pointer if some error happend e.g. we over file
188 struct file *alloc_empty_file(int flags, const struct cred *cred) in alloc_empty_file()
191 struct file *f; in alloc_empty_file()
223 pr_info("VFS: file-max limit %lu reached\n", get_max_files()); in alloc_empty_file()
232 * This is only for kernel internal use, and the allocate file must not be
233 * installed into file tables or such.
235 struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred) in alloc_empty_file_noaccount()
237 struct file *f; in alloc_empty_file_noaccount()
259 * This is only for kernel internal use, and the allocate file must not be
260 * installed into file tables or such.
262 struct file *alloc_empty_backing_file(int flags, const struct cred *cred) in alloc_empty_backing_file()
271 error = init_file(&ff->file, flags, cred); in alloc_empty_backing_file()
277 ff->file.f_mode |= FMODE_BACKING | FMODE_NOACCOUNT; in alloc_empty_backing_file()
278 return &ff->file; in alloc_empty_backing_file()
282 * alloc_file - allocate and initialize a 'struct file'
284 * @path: the (dentry, vfsmount) pair for the new file
285 * @flags: O_... flags with which the new file will be opened
286 * @fop: the 'struct file_operations' for the new file
288 static struct file *alloc_file(const struct path *path, int flags, in alloc_file()
291 struct file *file; in alloc_file() local
293 file = alloc_empty_file(flags, current_cred()); in alloc_file()
294 if (IS_ERR(file)) in alloc_file()
295 return file; in alloc_file()
297 file->f_path = *path; in alloc_file()
298 file->f_inode = path->dentry->d_inode; in alloc_file()
299 file->f_mapping = path->dentry->d_inode->i_mapping; in alloc_file()
300 file->f_wb_err = filemap_sample_wb_err(file->f_mapping); in alloc_file()
301 file->f_sb_err = file_sample_sb_err(file); in alloc_file()
303 file->f_mode |= FMODE_LSEEK; in alloc_file()
304 if ((file->f_mode & FMODE_READ) && in alloc_file()
306 file->f_mode |= FMODE_CAN_READ; in alloc_file()
307 if ((file->f_mode & FMODE_WRITE) && in alloc_file()
309 file->f_mode |= FMODE_CAN_WRITE; in alloc_file()
310 file->f_iocb_flags = iocb_flags(file); in alloc_file()
311 file->f_mode |= FMODE_OPENED; in alloc_file()
312 file->f_op = fop; in alloc_file()
313 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) in alloc_file()
315 return file; in alloc_file()
318 struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt, in alloc_file_pseudo()
327 struct file *file; in alloc_file_pseudo() local
336 file = alloc_file(&path, flags, fops); in alloc_file_pseudo()
337 if (IS_ERR(file)) { in alloc_file_pseudo()
341 return file; in alloc_file_pseudo()
345 struct file *alloc_file_clone(struct file *base, int flags, in alloc_file_clone()
348 struct file *f = alloc_file(&base->f_path, flags, fops); in alloc_file_clone()
356 /* the real guts of fput() - releasing the last reference to file
358 static void __fput(struct file *file) in __fput() argument
360 struct dentry *dentry = file->f_path.dentry; in __fput()
361 struct vfsmount *mnt = file->f_path.mnt; in __fput()
362 struct inode *inode = file->f_inode; in __fput()
363 fmode_t mode = file->f_mode; in __fput()
365 if (unlikely(!(file->f_mode & FMODE_OPENED))) in __fput()
370 fsnotify_close(file); in __fput()
373 * in the file cleanup chain. in __fput()
375 eventpoll_release(file); in __fput()
376 locks_remove_file(file); in __fput()
378 ima_file_free(file); in __fput()
379 if (unlikely(file->f_flags & FASYNC)) { in __fput()
380 if (file->f_op->fasync) in __fput()
381 file->f_op->fasync(-1, file, 0); in __fput()
383 if (file->f_op->release) in __fput()
384 file->f_op->release(inode, file); in __fput()
389 fops_put(file->f_op); in __fput()
390 put_pid(file->f_owner.pid); in __fput()
391 put_file_access(file); in __fput()
397 file_free(file); in __fput()
404 struct file *f, *t; in delayed_fput()
412 __fput(container_of(work, struct file, f_rcuhead)); in ____fput()
419 * not left us with opened struct file waiting for __fput() - execve()
433 void fput(struct file *file) in fput() argument
435 if (atomic_long_dec_and_test(&file->f_count)) { in fput()
439 init_task_work(&file->f_rcuhead, ____fput); in fput()
440 if (!task_work_add(task, &file->f_rcuhead, TWA_RESUME)) in fput()
445 * fput to avoid leaking *file. in fput()
449 if (llist_add(&file->f_llist, &delayed_fput_list)) in fput()
458 * for this specific struct file it won't involve anything that would
462 void __fput_sync(struct file *file) in __fput_sync() argument
464 if (atomic_long_dec_and_test(&file->f_count)) in __fput_sync()
465 __fput(file); in __fput_sync()
473 filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0, in files_init()
479 * One file with associated inode and dcache is very roughly 1K. Per default