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