Lines Matching refs:file
2 * memfd_create system call and file sealing support
7 * This file is released under the GPL.
13 #include <linux/file.h>
68 struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx)
184 static unsigned int *memfd_file_seals_ptr(struct file *file)
186 if (shmem_file(file))
187 return &SHMEM_I(file_inode(file))->seals;
190 if (is_file_hugepages(file))
191 return &HUGETLBFS_I(file_inode(file))->seals;
204 static int memfd_add_seals(struct file *file, unsigned int seals)
206 struct inode *inode = file_inode(file);
212 * Sealing allows multiple parties to share a tmpfs or hugetlbfs file
213 * but restrict access to a specific subset of file operations. Seals
221 * may prevent some kinds of access to the file. Currently, the
223 * SEAL_SEAL: Prevent further seals from being set on this file
224 * SEAL_SHRINK: Prevent the file from shrinking
225 * SEAL_GROW: Prevent the file from growing
226 * SEAL_WRITE: Prevent write access to the file
227 * SEAL_EXEC: Prevent modification of the exec bits in the file mode
230 * must prevent seals from being removed. Therefore, sealing a file
231 * only adds a given set of seals to the file, it never touches
239 * no plan to support it on other file types.
242 if (!(file->f_mode & FMODE_WRITE))
249 file_seals = memfd_file_seals_ptr(file);
261 error = mapping_deny_writable(file->f_mapping);
265 error = memfd_wait_for_pins(file->f_mapping);
267 mapping_allow_writable(file->f_mapping);
286 static int memfd_get_seals(struct file *file)
288 unsigned int *seals = memfd_file_seals_ptr(file);
293 long memfd_fcntl(struct file *file, unsigned int cmd, unsigned int arg)
299 error = memfd_add_seals(file, arg);
302 error = memfd_get_seals(file);
371 int memfd_check_seals_mmap(struct file *file, vm_flags_t *vm_flags_ptr)
374 unsigned int *seals_ptr = memfd_file_seals_ptr(file);
432 static struct file *alloc_file(const char *name, unsigned int flags)
435 struct file *file;
438 file = hugetlb_file_setup(name, 0, VM_NORESERVE,
443 file = shmem_file_setup(name, 0, VM_NORESERVE);
445 if (IS_ERR(file))
446 return file;
447 file->f_mode |= FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE;
448 file->f_flags |= O_LARGEFILE;
451 struct inode *inode = file_inode(file);
454 file_seals = memfd_file_seals_ptr(file);
461 file_seals = memfd_file_seals_ptr(file);
466 return file;
473 struct file *file;
491 file = alloc_file(name, flags);
492 if (IS_ERR(file)) {
493 error = PTR_ERR(file);
497 fd_install(fd, file);