Lines Matching full:file

11 #include <linux/file.h>
41 /* SLAB cache for file structures */
46 /* Container for backing file with optional user path */
48 struct file file; member
52 static inline struct backing_file *backing_file(struct file *f) in backing_file()
54 return container_of(f, struct backing_file, file); in backing_file()
57 struct path *backing_file_user_path(struct file *f) in backing_file_user_path()
63 static inline void file_free(struct file *f) in file_free()
108 .procname = "file-nr",
115 .procname = "file-max",
148 static int init_file(struct file *f, int flags, const struct cred *cred) in init_file()
165 * the respective member when opening the file. in init_file()
175 * refcount bumps we should reinitialize the reused file first. in init_file()
181 /* Find an unused file structure and return a pointer to it.
182 * Returns an error pointer if some error happend e.g. we over file
191 struct file *alloc_empty_file(int flags, const struct cred *cred) in alloc_empty_file()
194 struct file *f; in alloc_empty_file()
226 pr_info("VFS: file-max limit %lu reached\n", get_max_files()); in alloc_empty_file()
235 * This is only for kernel internal use, and the allocate file must not be
236 * installed into file tables or such.
238 struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred) in alloc_empty_file_noaccount()
240 struct file *f; in alloc_empty_file_noaccount()
262 * This is only for kernel internal use, and the allocate file must not be
263 * installed into file tables or such.
265 struct file *alloc_empty_backing_file(int flags, const struct cred *cred) in alloc_empty_backing_file()
274 error = init_file(&ff->file, flags, cred); in alloc_empty_backing_file()
280 ff->file.f_mode |= FMODE_BACKING | FMODE_NOACCOUNT; in alloc_empty_backing_file()
281 return &ff->file; in alloc_empty_backing_file()
285 * file_init_path - initialize a 'struct file' based on path
287 * @file: the file to set up
288 * @path: the (dentry, vfsmount) pair for the new file
289 * @fop: the 'struct file_operations' for the new file
291 static void file_init_path(struct file *file, const struct path *path, in file_init_path() argument
294 file->f_path = *path; in file_init_path()
295 file->f_inode = path->dentry->d_inode; in file_init_path()
296 file->f_mapping = path->dentry->d_inode->i_mapping; in file_init_path()
297 file->f_wb_err = filemap_sample_wb_err(file->f_mapping); in file_init_path()
298 file->f_sb_err = file_sample_sb_err(file); in file_init_path()
300 file->f_mode |= FMODE_LSEEK; in file_init_path()
301 if ((file->f_mode & FMODE_READ) && in file_init_path()
303 file->f_mode |= FMODE_CAN_READ; in file_init_path()
304 if ((file->f_mode & FMODE_WRITE) && in file_init_path()
306 file->f_mode |= FMODE_CAN_WRITE; in file_init_path()
307 file->f_iocb_flags = iocb_flags(file); in file_init_path()
308 file->f_mode |= FMODE_OPENED; in file_init_path()
309 file->f_op = fop; in file_init_path()
310 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) in file_init_path()
315 * alloc_file - allocate and initialize a 'struct file'
317 * @path: the (dentry, vfsmount) pair for the new file
318 * @flags: O_... flags with which the new file will be opened
319 * @fop: the 'struct file_operations' for the new file
321 static struct file *alloc_file(const struct path *path, int flags, in alloc_file()
324 struct file *file; in alloc_file() local
326 file = alloc_empty_file(flags, current_cred()); in alloc_file()
327 if (!IS_ERR(file)) in alloc_file()
328 file_init_path(file, path, fop); in alloc_file()
329 return file; in alloc_file()
345 struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt, in alloc_file_pseudo()
351 struct file *file; in alloc_file_pseudo() local
357 file = alloc_file(&path, flags, fops); in alloc_file_pseudo()
358 if (IS_ERR(file)) { in alloc_file_pseudo()
362 return file; in alloc_file_pseudo()
366 struct file *alloc_file_pseudo_noaccount(struct inode *inode, in alloc_file_pseudo_noaccount()
373 struct file *file; in alloc_file_pseudo_noaccount() local
379 file = alloc_empty_file_noaccount(flags, current_cred()); in alloc_file_pseudo_noaccount()
380 if (IS_ERR(file)) { in alloc_file_pseudo_noaccount()
383 return file; in alloc_file_pseudo_noaccount()
385 file_init_path(file, &path, fops); in alloc_file_pseudo_noaccount()
386 return file; in alloc_file_pseudo_noaccount()
390 struct file *alloc_file_clone(struct file *base, int flags, in alloc_file_clone()
393 struct file *f; in alloc_file_clone()
403 /* the real guts of fput() - releasing the last reference to file
405 static void __fput(struct file *file) in __fput() argument
407 struct dentry *dentry = file->f_path.dentry; in __fput()
408 struct vfsmount *mnt = file->f_path.mnt; in __fput()
409 struct inode *inode = file->f_inode; in __fput()
410 fmode_t mode = file->f_mode; in __fput()
412 if (unlikely(!(file->f_mode & FMODE_OPENED))) in __fput()
417 fsnotify_close(file); in __fput()
420 * in the file cleanup chain. in __fput()
422 eventpoll_release(file); in __fput()
423 locks_remove_file(file); in __fput()
425 security_file_release(file); in __fput()
426 if (unlikely(file->f_flags & FASYNC)) { in __fput()
427 if (file->f_op->fasync) in __fput()
428 file->f_op->fasync(-1, file, 0); in __fput()
430 if (file->f_op->release) in __fput()
431 file->f_op->release(inode, file); in __fput()
436 fops_put(file->f_op); in __fput()
437 file_f_owner_release(file); in __fput()
438 put_file_access(file); in __fput()
444 file_free(file); in __fput()
451 struct file *f, *t; in delayed_fput()
459 __fput(container_of(work, struct file, f_task_work)); in ____fput()
466 * not left us with opened struct file waiting for __fput() - execve()
480 void fput(struct file *file) in fput() argument
482 if (atomic_long_dec_and_test(&file->f_count)) { in fput()
485 if (unlikely(!(file->f_mode & (FMODE_BACKING | FMODE_OPENED)))) { in fput()
486 file_free(file); in fput()
490 init_task_work(&file->f_task_work, ____fput); in fput()
491 if (!task_work_add(task, &file->f_task_work, TWA_RESUME)) in fput()
496 * fput to avoid leaking *file. in fput()
500 if (llist_add(&file->f_llist, &delayed_fput_list)) in fput()
509 * for this specific struct file it won't involve anything that would
513 void __fput_sync(struct file *file) in __fput_sync() argument
515 if (atomic_long_dec_and_test(&file->f_count)) in __fput_sync()
516 __fput(file); in __fput_sync()
526 .freeptr_offset = offsetof(struct file, f_freeptr), in files_init()
529 filp_cachep = kmem_cache_create("filp", sizeof(struct file), &args, in files_init()
536 * One file with associated inode and dcache is very roughly 1K. Per default