mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	init: add an init_dup helper
Add a simple helper to grab a reference to a file and install it at the next available fd, and switch the early init code over to it. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
		
							parent
							
								
									235e57935b
								
							
						
					
					
						commit
						f073531070
					
				
					 3 changed files with 17 additions and 4 deletions
				
			
		
							
								
								
									
										12
									
								
								fs/init.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								fs/init.c
									
									
									
									
									
								
							| 
						 | 
					@ -8,6 +8,7 @@
 | 
				
			||||||
#include <linux/namei.h>
 | 
					#include <linux/namei.h>
 | 
				
			||||||
#include <linux/fs.h>
 | 
					#include <linux/fs.h>
 | 
				
			||||||
#include <linux/fs_struct.h>
 | 
					#include <linux/fs_struct.h>
 | 
				
			||||||
 | 
					#include <linux/file.h>
 | 
				
			||||||
#include <linux/init_syscalls.h>
 | 
					#include <linux/init_syscalls.h>
 | 
				
			||||||
#include <linux/security.h>
 | 
					#include <linux/security.h>
 | 
				
			||||||
#include "internal.h"
 | 
					#include "internal.h"
 | 
				
			||||||
| 
						 | 
					@ -251,3 +252,14 @@ int __init init_utimes(char *filename, struct timespec64 *ts)
 | 
				
			||||||
	path_put(&path);
 | 
						path_put(&path);
 | 
				
			||||||
	return error;
 | 
						return error;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int __init init_dup(struct file *file)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int fd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fd = get_unused_fd_flags(0);
 | 
				
			||||||
 | 
						if (fd < 0)
 | 
				
			||||||
 | 
							return fd;
 | 
				
			||||||
 | 
						fd_install(fd, get_file(file));
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,3 +16,4 @@ int __init init_unlink(const char *pathname);
 | 
				
			||||||
int __init init_mkdir(const char *pathname, umode_t mode);
 | 
					int __init init_mkdir(const char *pathname, umode_t mode);
 | 
				
			||||||
int __init init_rmdir(const char *pathname);
 | 
					int __init init_rmdir(const char *pathname);
 | 
				
			||||||
int __init init_utimes(char *filename, struct timespec64 *ts);
 | 
					int __init init_utimes(char *filename, struct timespec64 *ts);
 | 
				
			||||||
 | 
					int __init init_dup(struct file *file);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1467,10 +1467,10 @@ void __init console_on_rootfs(void)
 | 
				
			||||||
		pr_err("Warning: unable to open an initial console.\n");
 | 
							pr_err("Warning: unable to open an initial console.\n");
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	get_file_rcu_many(file, 2);
 | 
						init_dup(file);
 | 
				
			||||||
	fd_install(get_unused_fd_flags(0), file);
 | 
						init_dup(file);
 | 
				
			||||||
	fd_install(get_unused_fd_flags(0), file);
 | 
						init_dup(file);
 | 
				
			||||||
	fd_install(get_unused_fd_flags(0), file);
 | 
						fput(file);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static noinline void __init kernel_init_freeable(void)
 | 
					static noinline void __init kernel_init_freeable(void)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue