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()
251 pr_info("VFS: file-max limit %lu reached\n", get_max_files()); in alloc_empty_file()
260 * This is only for kernel internal use, and the allocate file must not be
261 * installed into file tables or such.
263 struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred) in alloc_empty_file_noaccount()
265 struct file *f; in alloc_empty_file_noaccount()
287 * This is only for kernel internal use, and the allocate file must not be
288 * installed into file tables or such.
290 struct file *alloc_empty_backing_file(int flags, const struct cred *cred) in alloc_empty_backing_file()
299 error = init_file(&ff->file, flags, cred); in alloc_empty_backing_file()
305 ff->file.f_mode |= FMODE_BACKING | FMODE_NOACCOUNT; in alloc_empty_backing_file()
306 return &ff->file; in alloc_empty_backing_file()
310 * file_init_path - initialize a 'struct file' based on path
312 * @file: the file to set up
313 * @path: the (dentry, vfsmount) pair for the new file
314 * @fop: the 'struct file_operations' for the new file
316 static void file_init_path(struct file *file, const struct path *path, in file_init_path() argument
319 file->f_path = *path; in file_init_path()
320 file->f_inode = path->dentry->d_inode; in file_init_path()
321 file->f_mapping = path->dentry->d_inode->i_mapping; in file_init_path()
322 file->f_wb_err = filemap_sample_wb_err(file->f_mapping); in file_init_path()
323 file->f_sb_err = file_sample_sb_err(file); in file_init_path()
325 file->f_mode |= FMODE_LSEEK; in file_init_path()
326 if ((file->f_mode & FMODE_READ) && in file_init_path()
328 file->f_mode |= FMODE_CAN_READ; in file_init_path()
329 if ((file->f_mode & FMODE_WRITE) && in file_init_path()
331 file->f_mode |= FMODE_CAN_WRITE; in file_init_path()
332 file->f_iocb_flags = iocb_flags(file); in file_init_path()
333 file->f_mode |= FMODE_OPENED; in file_init_path()
334 file->f_op = fop; in file_init_path()
335 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) in file_init_path()
340 * alloc_file - allocate and initialize a 'struct file'
342 * @path: the (dentry, vfsmount) pair for the new file
343 * @flags: O_... flags with which the new file will be opened
344 * @fop: the 'struct file_operations' for the new file
346 static struct file *alloc_file(const struct path *path, int flags, in alloc_file()
349 struct file *file; in alloc_file() local
351 file = alloc_empty_file(flags, current_cred()); in alloc_file()
352 if (!IS_ERR(file)) in alloc_file()
353 file_init_path(file, path, fop); in alloc_file()
354 return file; in alloc_file()
368 struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt, in alloc_file_pseudo()
374 struct file *file; in alloc_file_pseudo() local
380 file = alloc_file(&path, flags, fops); in alloc_file_pseudo()
381 if (IS_ERR(file)) { in alloc_file_pseudo()
384 return file; in alloc_file_pseudo()
390 file_set_fsnotify_mode(file, FMODE_NONOTIFY); in alloc_file_pseudo()
391 return file; in alloc_file_pseudo()
395 struct file *alloc_file_pseudo_noaccount(struct inode *inode, in alloc_file_pseudo_noaccount()
402 struct file *file; in alloc_file_pseudo_noaccount() local
408 file = alloc_empty_file_noaccount(flags, current_cred()); in alloc_file_pseudo_noaccount()
409 if (IS_ERR(file)) { in alloc_file_pseudo_noaccount()
412 return file; in alloc_file_pseudo_noaccount()
414 file_init_path(file, &path, fops); in alloc_file_pseudo_noaccount()
419 file_set_fsnotify_mode(file, FMODE_NONOTIFY); in alloc_file_pseudo_noaccount()
420 return file; in alloc_file_pseudo_noaccount()
424 struct file *alloc_file_clone(struct file *base, int flags, in alloc_file_clone()
427 struct file *f; in alloc_file_clone()
437 /* the real guts of fput() - releasing the last reference to file
439 static void __fput(struct file *file) in __fput() argument
441 struct dentry *dentry = file->f_path.dentry; in __fput()
442 struct vfsmount *mnt = file->f_path.mnt; in __fput()
443 struct inode *inode = file->f_inode; in __fput()
444 fmode_t mode = file->f_mode; in __fput()
446 if (unlikely(!(file->f_mode & FMODE_OPENED))) in __fput()
451 fsnotify_close(file); in __fput()
454 * in the file cleanup chain. in __fput()
456 eventpoll_release(file); in __fput()
457 locks_remove_file(file); in __fput()
459 security_file_release(file); in __fput()
460 if (unlikely(file->f_flags & FASYNC)) { in __fput()
461 if (file->f_op->fasync) in __fput()
462 file->f_op->fasync(-1, file, 0); in __fput()
464 if (file->f_op->release) in __fput()
465 file->f_op->release(inode, file); in __fput()
470 fops_put(file->f_op); in __fput()
471 file_f_owner_release(file); in __fput()
472 put_file_access(file); in __fput()
478 file_free(file); in __fput()
485 struct file *f, *t; in delayed_fput()
493 __fput(container_of(work, struct file, f_task_work)); in ____fput()
502 * not left us with opened struct file waiting for __fput() - execve()
515 static void __fput_deferred(struct file *file) in __fput_deferred() argument
519 if (unlikely(!(file->f_mode & (FMODE_BACKING | FMODE_OPENED)))) { in __fput_deferred()
520 file_free(file); in __fput_deferred()
525 init_task_work(&file->f_task_work, ____fput); in __fput_deferred()
526 if (!task_work_add(task, &file->f_task_work, TWA_RESUME)) in __fput_deferred()
531 * fput to avoid leaking *file. in __fput_deferred()
535 if (llist_add(&file->f_llist, &delayed_fput_list)) in __fput_deferred()
539 void fput(struct file *file) in fput() argument
541 if (unlikely(file_ref_put(&file->f_ref))) in fput()
542 __fput_deferred(file); in fput()
550 * for this specific struct file it won't involve anything that would
554 void __fput_sync(struct file *file) in __fput_sync() argument
556 if (file_ref_put(&file->f_ref)) in __fput_sync()
557 __fput(file); in __fput_sync()
567 void fput_close_sync(struct file *file) in fput_close_sync() argument
569 if (likely(file_ref_put_close(&file->f_ref))) in fput_close_sync()
570 __fput(file); in fput_close_sync()
579 void fput_close(struct file *file) in fput_close() argument
581 if (file_ref_put_close(&file->f_ref)) in fput_close()
582 __fput_deferred(file); in fput_close()
589 .freeptr_offset = offsetof(struct file, f_freeptr), in files_init()
592 filp_cachep = kmem_cache_create("filp", sizeof(struct file), &args, in files_init()
604 * One file with associated inode and dcache is very roughly 1K. Per default