Lines Matching full:file
11 #include <linux/file.h>
42 /* SLAB cache for file structures */
47 /* Container for backing file with optional user 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_user_path(struct file *f) in backing_file_user_path()
64 static inline void file_free(struct file *f) in file_free()
109 .procname = "file-nr",
116 .procname = "file-max",
148 static int init_file(struct file *f, int flags, const struct cred *cred) in init_file()
169 * refcount bumps we should reinitialize the reused file first. in init_file()
175 /* Find an unused file structure and return a pointer to it.
176 * Returns an error pointer if some error happend e.g. we over file
185 struct file *alloc_empty_file(int flags, const struct cred *cred) in alloc_empty_file()
188 struct file *f; in alloc_empty_file()
220 pr_info("VFS: file-max limit %lu reached\n", get_max_files()); in alloc_empty_file()
229 * This is only for kernel internal use, and the allocate file must not be
230 * installed into file tables or such.
232 struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred) in alloc_empty_file_noaccount()
234 struct file *f; in alloc_empty_file_noaccount()
256 * This is only for kernel internal use, and the allocate file must not be
257 * installed into file tables or such.
259 struct file *alloc_empty_backing_file(int flags, const struct cred *cred) in alloc_empty_backing_file()
268 error = init_file(&ff->file, flags, cred); in alloc_empty_backing_file()
274 ff->file.f_mode |= FMODE_BACKING | FMODE_NOACCOUNT; in alloc_empty_backing_file()
275 return &ff->file; in alloc_empty_backing_file()
279 * alloc_file - allocate and initialize a 'struct file'
281 * @path: the (dentry, vfsmount) pair for the new file
282 * @flags: O_... flags with which the new file will be opened
283 * @fop: the 'struct file_operations' for the new file
285 static struct file *alloc_file(const struct path *path, int flags, in alloc_file()
288 struct file *file; in alloc_file() local
290 file = alloc_empty_file(flags, current_cred()); in alloc_file()
291 if (IS_ERR(file)) in alloc_file()
292 return file; in alloc_file()
294 file->f_path = *path; in alloc_file()
295 file->f_inode = path->dentry->d_inode; in alloc_file()
296 file->f_mapping = path->dentry->d_inode->i_mapping; in alloc_file()
297 file->f_wb_err = filemap_sample_wb_err(file->f_mapping); in alloc_file()
298 file->f_sb_err = file_sample_sb_err(file); in alloc_file()
300 file->f_mode |= FMODE_LSEEK; in alloc_file()
301 if ((file->f_mode & FMODE_READ) && in alloc_file()
303 file->f_mode |= FMODE_CAN_READ; in alloc_file()
304 if ((file->f_mode & FMODE_WRITE) && in alloc_file()
306 file->f_mode |= FMODE_CAN_WRITE; in alloc_file()
307 file->f_iocb_flags = iocb_flags(file); in alloc_file()
308 file->f_mode |= FMODE_OPENED; in alloc_file()
309 file->f_op = fop; in alloc_file()
310 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) in alloc_file()
312 return file; in alloc_file()
315 struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt, in alloc_file_pseudo()
321 struct file *file; in alloc_file_pseudo() local
328 file = alloc_file(&path, flags, fops); in alloc_file_pseudo()
329 if (IS_ERR(file)) { in alloc_file_pseudo()
333 return file; in alloc_file_pseudo()
337 struct file *alloc_file_clone(struct file *base, int flags, in alloc_file_clone()
340 struct file *f = alloc_file(&base->f_path, flags, fops); in alloc_file_clone()
348 /* the real guts of fput() - releasing the last reference to file
350 static void __fput(struct file *file) in __fput() argument
352 struct dentry *dentry = file->f_path.dentry; in __fput()
353 struct vfsmount *mnt = file->f_path.mnt; in __fput()
354 struct inode *inode = file->f_inode; in __fput()
355 fmode_t mode = file->f_mode; in __fput()
357 if (unlikely(!(file->f_mode & FMODE_OPENED))) in __fput()
362 fsnotify_close(file); in __fput()
365 * in the file cleanup chain. in __fput()
367 eventpoll_release(file); in __fput()
368 locks_remove_file(file); in __fput()
370 ima_file_free(file); in __fput()
371 if (unlikely(file->f_flags & FASYNC)) { in __fput()
372 if (file->f_op->fasync) in __fput()
373 file->f_op->fasync(-1, file, 0); in __fput()
375 if (file->f_op->release) in __fput()
376 file->f_op->release(inode, file); in __fput()
381 fops_put(file->f_op); in __fput()
382 put_pid(file->f_owner.pid); in __fput()
383 put_file_access(file); in __fput()
389 file_free(file); in __fput()
396 struct file *f, *t; in delayed_fput()
404 __fput(container_of(work, struct file, f_task_work)); in ____fput()
411 * not left us with opened struct file waiting for __fput() - execve()
425 void fput(struct file *file) in fput() argument
427 if (atomic_long_dec_and_test(&file->f_count)) { in fput()
430 if (unlikely(!(file->f_mode & (FMODE_BACKING | FMODE_OPENED)))) { in fput()
431 file_free(file); in fput()
435 init_task_work(&file->f_task_work, ____fput); in fput()
436 if (!task_work_add(task, &file->f_task_work, TWA_RESUME)) in fput()
441 * fput to avoid leaking *file. in fput()
445 if (llist_add(&file->f_llist, &delayed_fput_list)) in fput()
454 * for this specific struct file it won't involve anything that would
458 void __fput_sync(struct file *file) in __fput_sync() argument
460 if (atomic_long_dec_and_test(&file->f_count)) in __fput_sync()
461 __fput(file); in __fput_sync()
469 filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0, in files_init()
476 * One file with associated inode and dcache is very roughly 1K. Per default