Lines Matching full:file
11 #include <linux/file.h>
40 /* SLAB cache for file structures */
46 /* Container for backing file with optional user path */
48 struct file file; member
55 static inline struct backing_file *backing_file(struct file *f) in backing_file()
57 return container_of(f, struct backing_file, file); in backing_file()
60 struct path *backing_file_user_path(struct file *f) in backing_file_user_path()
66 static inline void file_free(struct file *f) in file_free()
111 .procname = "file-nr",
118 .procname = "file-max",
151 static int init_file(struct file *f, int flags, const struct cred *cred) in init_file()
168 * the respective member when opening the file. in init_file()
194 * refcount bumps we should reinitialize the reused file first. in init_file()
205 /* Find an unused file structure and return a pointer to it.
206 * Returns an error pointer if some error happend e.g. we over file
215 struct file *alloc_empty_file(int flags, const struct cred *cred) in alloc_empty_file()
218 struct file *f; in alloc_empty_file()
250 pr_info("VFS: file-max limit %lu reached\n", get_max_files()); in alloc_empty_file()
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_file_noaccount(int flags, const struct cred *cred) in alloc_empty_file_noaccount()
264 struct file *f; in alloc_empty_file_noaccount()
286 * This is only for kernel internal use, and the allocate file must not be
287 * installed into file tables or such.
289 struct file *alloc_empty_backing_file(int flags, const struct cred *cred) in alloc_empty_backing_file()
298 error = init_file(&ff->file, flags, cred); in alloc_empty_backing_file()
304 ff->file.f_mode |= FMODE_BACKING | FMODE_NOACCOUNT; in alloc_empty_backing_file()
305 return &ff->file; in alloc_empty_backing_file()
309 * file_init_path - initialize a 'struct file' based on path
311 * @file: the file to set up
312 * @path: the (dentry, vfsmount) pair for the new file
313 * @fop: the 'struct file_operations' for the new file
315 static void file_init_path(struct file *file, const struct path *path, in file_init_path() argument
318 file->f_path = *path; in file_init_path()
319 file->f_inode = path->dentry->d_inode; in file_init_path()
320 file->f_mapping = path->dentry->d_inode->i_mapping; in file_init_path()
321 file->f_wb_err = filemap_sample_wb_err(file->f_mapping); in file_init_path()
322 file->f_sb_err = file_sample_sb_err(file); in file_init_path()
324 file->f_mode |= FMODE_LSEEK; in file_init_path()
325 if ((file->f_mode & FMODE_READ) && in file_init_path()
327 file->f_mode |= FMODE_CAN_READ; in file_init_path()
328 if ((file->f_mode & FMODE_WRITE) && in file_init_path()
330 file->f_mode |= FMODE_CAN_WRITE; in file_init_path()
331 file->f_iocb_flags = iocb_flags(file); in file_init_path()
332 file->f_mode |= FMODE_OPENED; in file_init_path()
333 file->f_op = fop; in file_init_path()
334 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) in file_init_path()
339 * alloc_file - allocate and initialize a 'struct file'
341 * @path: the (dentry, vfsmount) pair for the new file
342 * @flags: O_... flags with which the new file will be opened
343 * @fop: the 'struct file_operations' for the new file
345 static struct file *alloc_file(const struct path *path, int flags, in alloc_file()
348 struct file *file; in alloc_file() local
350 file = alloc_empty_file(flags, current_cred()); in alloc_file()
351 if (!IS_ERR(file)) in alloc_file()
352 file_init_path(file, path, fop); in alloc_file()
353 return file; in alloc_file()
367 struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt, in alloc_file_pseudo()
373 struct file *file; in alloc_file_pseudo() local
379 file = alloc_file(&path, flags, fops); in alloc_file_pseudo()
380 if (IS_ERR(file)) { in alloc_file_pseudo()
383 return file; in alloc_file_pseudo()
389 file_set_fsnotify_mode(file, FMODE_NONOTIFY); in alloc_file_pseudo()
390 return file; in alloc_file_pseudo()
394 struct file *alloc_file_pseudo_noaccount(struct inode *inode, in alloc_file_pseudo_noaccount()
401 struct file *file; in alloc_file_pseudo_noaccount() local
407 file = alloc_empty_file_noaccount(flags, current_cred()); in alloc_file_pseudo_noaccount()
408 if (IS_ERR(file)) { in alloc_file_pseudo_noaccount()
411 return file; in alloc_file_pseudo_noaccount()
413 file_init_path(file, &path, fops); in alloc_file_pseudo_noaccount()
418 file_set_fsnotify_mode(file, FMODE_NONOTIFY); in alloc_file_pseudo_noaccount()
419 return file; in alloc_file_pseudo_noaccount()
423 struct file *alloc_file_clone(struct file *base, int flags, in alloc_file_clone()
426 struct file *f; in alloc_file_clone()
436 /* the real guts of fput() - releasing the last reference to file
438 static void __fput(struct file *file) in __fput() argument
440 struct dentry *dentry = file->f_path.dentry; in __fput()
441 struct vfsmount *mnt = file->f_path.mnt; in __fput()
442 struct inode *inode = file->f_inode; in __fput()
443 fmode_t mode = file->f_mode; in __fput()
445 if (unlikely(!(file->f_mode & FMODE_OPENED))) in __fput()
450 fsnotify_close(file); in __fput()
453 * in the file cleanup chain. in __fput()
455 eventpoll_release(file); in __fput()
456 locks_remove_file(file); in __fput()
458 security_file_release(file); in __fput()
459 if (unlikely(file->f_flags & FASYNC)) { in __fput()
460 if (file->f_op->fasync) in __fput()
461 file->f_op->fasync(-1, file, 0); in __fput()
463 if (file->f_op->release) in __fput()
464 file->f_op->release(inode, file); in __fput()
469 fops_put(file->f_op); in __fput()
470 file_f_owner_release(file); in __fput()
471 put_file_access(file); in __fput()
477 file_free(file); in __fput()
484 struct file *f, *t; in delayed_fput()
492 __fput(container_of(work, struct file, f_task_work)); in ____fput()
501 * not left us with opened struct file waiting for __fput() - execve()
514 void fput(struct file *file) in fput() argument
516 if (file_ref_put(&file->f_ref)) { in fput()
519 if (unlikely(!(file->f_mode & (FMODE_BACKING | FMODE_OPENED)))) { in fput()
520 file_free(file); in fput()
524 init_task_work(&file->f_task_work, ____fput); in fput()
525 if (!task_work_add(task, &file->f_task_work, TWA_RESUME)) in fput()
530 * fput to avoid leaking *file. in fput()
534 if (llist_add(&file->f_llist, &delayed_fput_list)) in fput()
543 * for this specific struct file it won't involve anything that would
547 void __fput_sync(struct file *file) in __fput_sync() argument
549 if (file_ref_put(&file->f_ref)) in __fput_sync()
550 __fput(file); in __fput_sync()
560 .freeptr_offset = offsetof(struct file, f_freeptr), in files_init()
563 filp_cachep = kmem_cache_create("filp", sizeof(struct file), &args, in files_init()
575 * One file with associated inode and dcache is very roughly 1K. Per default