Lines Matching full:file

10 #include <linux/file.h>
40 /* SLAB cache for file structures */
47 struct file *f = container_of(head, struct file, f_u.fu_rcuhead); in file_free_rcu()
53 static inline void file_free(struct file *f) in file_free()
95 /* Find an unused file structure and return a pointer to it.
96 * Returns NULL, if there are no more free file structures or
105 struct file *get_empty_filp(void) in get_empty_filp()
109 struct file * f; in get_empty_filp()
143 pr_info("VFS: file-max limit %lu reached\n", get_max_files()); in get_empty_filp()
155 * alloc_file - allocate and initialize a 'struct file'
156 * @mnt: the vfsmount on which the file will reside
157 * @dentry: the dentry representing the new file
158 * @mode: the mode with which the new file will be opened
159 * @fop: the 'struct file_operations' for the new file
162 * 'struct file'. Do so because of the same initialization
169 struct file *alloc_file(struct path *path, fmode_t mode, in alloc_file()
172 struct file *file; in alloc_file() local
174 file = get_empty_filp(); in alloc_file()
175 if (!file) in alloc_file()
178 file->f_path = *path; in alloc_file()
179 file->f_mapping = path->dentry->d_inode->i_mapping; in alloc_file()
180 file->f_mode = mode; in alloc_file()
181 file->f_op = fop; in alloc_file()
190 file_take_write(file); in alloc_file()
195 return file; in alloc_file()
200 * drop_file_write_access - give up ability to write to a file
201 * @file: the file to which we will stop writing
204 * to write to @file, along with access to write through
207 void drop_file_write_access(struct file *file) in drop_file_write_access() argument
209 struct vfsmount *mnt = file->f_path.mnt; in drop_file_write_access()
210 struct dentry *dentry = file->f_path.dentry; in drop_file_write_access()
217 if (file_check_writeable(file) != 0) in drop_file_write_access()
220 file_release_write(file); in drop_file_write_access()
224 /* the real guts of fput() - releasing the last reference to file
226 static void __fput(struct file *file) in __fput() argument
228 struct dentry *dentry = file->f_path.dentry; in __fput()
229 struct vfsmount *mnt = file->f_path.mnt; in __fput()
234 fsnotify_close(file); in __fput()
237 * in the file cleanup chain. in __fput()
239 eventpoll_release(file); in __fput()
240 locks_remove_flock(file); in __fput()
242 if (unlikely(file->f_flags & FASYNC)) { in __fput()
243 if (file->f_op && file->f_op->fasync) in __fput()
244 file->f_op->fasync(-1, file, 0); in __fput()
246 if (file->f_op && file->f_op->release) in __fput()
247 file->f_op->release(inode, file); in __fput()
248 security_file_free(file); in __fput()
249 ima_file_free(file); in __fput()
251 !(file->f_mode & FMODE_PATH))) { in __fput()
254 fops_put(file->f_op); in __fput()
255 put_pid(file->f_owner.pid); in __fput()
256 file_sb_list_del(file); in __fput()
257 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) in __fput()
259 if (file->f_mode & FMODE_WRITE) in __fput()
260 drop_file_write_access(file); in __fput()
261 file->f_path.dentry = NULL; in __fput()
262 file->f_path.mnt = NULL; in __fput()
263 file_free(file); in __fput()
268 void fput(struct file *file) in fput() argument
270 if (atomic_long_dec_and_test(&file->f_count)) in fput()
271 __fput(file); in fput()
276 struct file *fget(unsigned int fd) in fget()
278 struct file *file; in fget() local
282 file = fcheck_files(files, fd); in fget()
283 if (file) { in fget()
284 /* File object ref couldn't be taken */ in fget()
285 if (file->f_mode & FMODE_PATH || in fget()
286 !atomic_long_inc_not_zero(&file->f_count)) in fget()
287 file = NULL; in fget()
291 return file; in fget()
296 struct file *fget_raw(unsigned int fd) in fget_raw()
298 struct file *file; in fget_raw() local
302 file = fcheck_files(files, fd); in fget_raw()
303 if (file) { in fget_raw()
304 /* File object ref couldn't be taken */ in fget_raw()
305 if (!atomic_long_inc_not_zero(&file->f_count)) in fget_raw()
306 file = NULL; in fget_raw()
310 return file; in fget_raw()
316 * Lightweight file lookup - no refcnt increment if fd table isn't shared.
321 * to userspace (i.e. you cannot remember the returned struct file * after
323 * 2) You must not call filp_close on the returned struct file * in between
331 struct file *fget_light(unsigned int fd, int *fput_needed) in fget_light()
333 struct file *file; in fget_light() local
338 file = fcheck_files(files, fd); in fget_light()
339 if (file && (file->f_mode & FMODE_PATH)) in fget_light()
340 file = NULL; in fget_light()
343 file = fcheck_files(files, fd); in fget_light()
344 if (file) { in fget_light()
345 if (!(file->f_mode & FMODE_PATH) && in fget_light()
346 atomic_long_inc_not_zero(&file->f_count)) in fget_light()
350 file = NULL; in fget_light()
355 return file; in fget_light()
358 struct file *fget_raw_light(unsigned int fd, int *fput_needed) in fget_raw_light()
360 struct file *file; in fget_raw_light() local
365 file = fcheck_files(files, fd); in fget_raw_light()
368 file = fcheck_files(files, fd); in fget_raw_light()
369 if (file) { in fget_raw_light()
370 if (atomic_long_inc_not_zero(&file->f_count)) in fget_raw_light()
374 file = NULL; in fget_raw_light()
379 return file; in fget_raw_light()
382 void put_filp(struct file *file) in put_filp() argument
384 if (atomic_long_dec_and_test(&file->f_count)) { in put_filp()
385 security_file_free(file); in put_filp()
386 file_sb_list_del(file); in put_filp()
387 file_free(file); in put_filp()
391 static inline int file_list_cpu(struct file *file) in file_list_cpu() argument
394 return file->f_sb_list_cpu; in file_list_cpu()
401 static inline void __file_sb_list_add(struct file *file, struct super_block *sb) in __file_sb_list_add() argument
407 file->f_sb_list_cpu = cpu; in __file_sb_list_add()
412 list_add(&file->f_u.fu_list, list); in __file_sb_list_add()
416 * file_sb_list_add - add a file to the sb's file list
417 * @file: file to add
420 * Use this function to associate a file with the superblock of the inode it
423 void file_sb_list_add(struct file *file, struct super_block *sb) in file_sb_list_add() argument
426 __file_sb_list_add(file, sb); in file_sb_list_add()
431 * file_sb_list_del - remove a file from the sb's file list
432 * @file: file to remove
435 * Use this function to remove a file from its superblock.
437 void file_sb_list_del(struct file *file) in file_sb_list_del() argument
439 if (!list_empty(&file->f_u.fu_list)) { in file_sb_list_del()
440 lg_local_lock_cpu(files_lglock, file_list_cpu(file)); in file_sb_list_del()
441 list_del_init(&file->f_u.fu_list); in file_sb_list_del()
442 lg_local_unlock_cpu(files_lglock, file_list_cpu(file)); in file_sb_list_del()
486 struct file *f; in mark_files_ro()
518 filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0, in files_init()
522 * One file with associated inode and dcache is very roughly 1K. in files_init()