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 #define backing_file(f) container_of(f, struct backing_file, file)
57 const struct path *backing_file_user_path(const struct file *f) in backing_file_user_path()
63 void backing_file_set_user_path(struct file *f, const struct path *path) in backing_file_set_user_path()
69 static inline void file_free(struct file *f) in file_free()
114 .procname = "file-nr",
121 .procname = "file-max",
154 static int init_file(struct file *f, int flags, const struct cred *cred) in init_file()
171 * the respective member when opening the file. in init_file()
197 * refcount bumps we should reinitialize the reused file first. in init_file()
208 /* Find an unused file structure and return a pointer to it.
209 * Returns an error pointer if some error happend e.g. we over file
218 struct file *alloc_empty_file(int flags, const struct cred *cred) in alloc_empty_file()
221 struct file *f; in alloc_empty_file()
254 pr_info("VFS: file-max limit %lu reached\n", get_max_files()); in alloc_empty_file()
263 * This is only for kernel internal use, and the allocate file must not be
264 * installed into file tables or such.
266 struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred) in alloc_empty_file_noaccount()
268 struct file *f; in alloc_empty_file_noaccount()
290 * This is only for kernel internal use, and the allocate file must not be
291 * installed into file tables or such.
293 struct file *alloc_empty_backing_file(int flags, const struct cred *cred) in alloc_empty_backing_file()
302 error = init_file(&ff->file, flags, cred); in alloc_empty_backing_file()
308 ff->file.f_mode |= FMODE_BACKING | FMODE_NOACCOUNT; in alloc_empty_backing_file()
309 return &ff->file; in alloc_empty_backing_file()
313 * file_init_path - initialize a 'struct file' based on path
315 * @file: the file to set up
316 * @path: the (dentry, vfsmount) pair for the new file
317 * @fop: the 'struct file_operations' for the new file
319 static void file_init_path(struct file *file, const struct path *path, in file_init_path() argument
322 file->__f_path = *path; in file_init_path()
323 file->f_inode = path->dentry->d_inode; in file_init_path()
324 file->f_mapping = path->dentry->d_inode->i_mapping; in file_init_path()
325 file->f_wb_err = filemap_sample_wb_err(file->f_mapping); in file_init_path()
326 file->f_sb_err = file_sample_sb_err(file); in file_init_path()
328 file->f_mode |= FMODE_LSEEK; in file_init_path()
329 if ((file->f_mode & FMODE_READ) && in file_init_path()
331 file->f_mode |= FMODE_CAN_READ; in file_init_path()
332 if ((file->f_mode & FMODE_WRITE) && in file_init_path()
334 file->f_mode |= FMODE_CAN_WRITE; in file_init_path()
335 file->f_iocb_flags = iocb_flags(file); in file_init_path()
336 file->f_mode |= FMODE_OPENED; in file_init_path()
337 file->f_op = fop; in file_init_path()
338 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) in file_init_path()
343 * alloc_file - allocate and initialize a 'struct file'
345 * @path: the (dentry, vfsmount) pair for the new file
346 * @flags: O_... flags with which the new file will be opened
347 * @fop: the 'struct file_operations' for the new file
349 static struct file *alloc_file(const struct path *path, int flags, in alloc_file()
352 struct file *file; in alloc_file() local
354 file = alloc_empty_file(flags, current_cred()); in alloc_file()
355 if (!IS_ERR(file)) in alloc_file()
356 file_init_path(file, path, fop); in alloc_file()
357 return file; in alloc_file()
371 struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt, in alloc_file_pseudo()
377 struct file *file; in alloc_file_pseudo() local
383 file = alloc_file(&path, flags, fops); in alloc_file_pseudo()
384 if (IS_ERR(file)) { in alloc_file_pseudo()
387 return file; in alloc_file_pseudo()
393 file_set_fsnotify_mode(file, FMODE_NONOTIFY); in alloc_file_pseudo()
394 return file; in alloc_file_pseudo()
398 struct file *alloc_file_pseudo_noaccount(struct inode *inode, in alloc_file_pseudo_noaccount()
405 struct file *file; in alloc_file_pseudo_noaccount() local
411 file = alloc_empty_file_noaccount(flags, current_cred()); in alloc_file_pseudo_noaccount()
412 if (IS_ERR(file)) { in alloc_file_pseudo_noaccount()
415 return file; in alloc_file_pseudo_noaccount()
417 file_init_path(file, &path, fops); in alloc_file_pseudo_noaccount()
422 file_set_fsnotify_mode(file, FMODE_NONOTIFY); in alloc_file_pseudo_noaccount()
423 return file; in alloc_file_pseudo_noaccount()
427 struct file *alloc_file_clone(struct file *base, int flags, in alloc_file_clone()
430 struct file *f; in alloc_file_clone()
440 /* the real guts of fput() - releasing the last reference to file
442 static void __fput(struct file *file) in __fput() argument
444 struct dentry *dentry = file->f_path.dentry; in __fput()
445 struct vfsmount *mnt = file->f_path.mnt; in __fput()
446 struct inode *inode = file->f_inode; in __fput()
447 fmode_t mode = file->f_mode; in __fput()
449 if (unlikely(!(file->f_mode & FMODE_OPENED))) in __fput()
454 fsnotify_close(file); in __fput()
457 * in the file cleanup chain. in __fput()
459 eventpoll_release(file); in __fput()
460 locks_remove_file(file); in __fput()
462 security_file_release(file); in __fput()
463 if (unlikely(file->f_flags & FASYNC)) { in __fput()
464 if (file->f_op->fasync) in __fput()
465 file->f_op->fasync(-1, file, 0); in __fput()
467 if (file->f_op->release) in __fput()
468 file->f_op->release(inode, file); in __fput()
473 fops_put(file->f_op); in __fput()
474 file_f_owner_release(file); in __fput()
475 put_file_access(file); in __fput()
481 file_free(file); in __fput()
488 struct file *f, *t; in delayed_fput()
496 __fput(container_of(work, struct file, f_task_work)); in ____fput()
505 * not left us with opened struct file waiting for __fput() - execve()
518 static void __fput_deferred(struct file *file) in __fput_deferred() argument
522 if (unlikely(!(file->f_mode & (FMODE_BACKING | FMODE_OPENED)))) { in __fput_deferred()
523 file_free(file); in __fput_deferred()
528 init_task_work(&file->f_task_work, ____fput); in __fput_deferred()
529 if (!task_work_add(task, &file->f_task_work, TWA_RESUME)) in __fput_deferred()
534 * fput to avoid leaking *file. in __fput_deferred()
538 if (llist_add(&file->f_llist, &delayed_fput_list)) in __fput_deferred()
542 void fput(struct file *file) in fput() argument
544 if (unlikely(file_ref_put(&file->f_ref))) in fput()
545 __fput_deferred(file); in fput()
553 * for this specific struct file it won't involve anything that would
557 void __fput_sync(struct file *file) in __fput_sync() argument
559 if (file_ref_put(&file->f_ref)) in __fput_sync()
560 __fput(file); in __fput_sync()
570 void fput_close_sync(struct file *file) in fput_close_sync() argument
572 if (likely(file_ref_put_close(&file->f_ref))) in fput_close_sync()
573 __fput(file); in fput_close_sync()
582 void fput_close(struct file *file) in fput_close() argument
584 if (file_ref_put_close(&file->f_ref)) in fput_close()
585 __fput_deferred(file); in fput_close()
592 .freeptr_offset = offsetof(struct file, f_freeptr), in files_init()
595 filp_cachep = kmem_cache_create("filp", sizeof(struct file), &args, in files_init()
607 * One file with associated inode and dcache is very roughly 1K. Per default