// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 1995, 1996 Gero Kuhlmann <[email protected]> * * Allow an NFS filesystem to be mounted as root. The way this works is: * (1) Use the IP autoconfig mechanism to set local IP addresses and routes. * (2) Construct the device string and the options string using DHCP * option 17 and/or kernel command line options. * (3) When mount_root() sets up the root file system, pass these strings * to the NFS client's regular mount interface via sys_mount(). * * * Changes: * * Alan Cox : Removed get_address name clash with FPU. * Alan Cox : Reformatted a bit. * Gero Kuhlmann : Code cleanup * Michael Rausch : Fixed recognition of an incoming RARP answer. * Martin Mares : (2.0) Auto-configuration via BOOTP supported. * Martin Mares : Manual selection of interface & BOOTP/RARP. * Martin Mares : Using network routes instead of host routes, * allowing the default configuration to be used * for normal operation of the host. * Martin Mares : Randomized timer with exponential backoff * installed to minimize network congestion. * Martin Mares : Code cleanup. * Martin Mares : (2.1) BOOTP and RARP made configuration options. * Martin Mares : Server hostname generation fixed. * Gerd Knorr : Fixed wired inode handling * Martin Mares : (2.2) "0.0.0.0" addresses from command line ignored. * Martin Mares : RARP replies not tested for server address. * Gero Kuhlmann : (2.3) Some bug fixes and code cleanup again (please * send me your new patches _before_ bothering * Linus so that I don' always have to cleanup * _afterwards_ - thanks) * Gero Kuhlmann : Last changes of Martin Mares undone. * Gero Kuhlmann : RARP replies are tested for specified server * again. However, it's now possible to have * different RARP and NFS servers. * Gero Kuhlmann : "0.0.0.0" addresses from command line are * now mapped to INADDR_NONE. * Gero Kuhlmann : Fixed a bug which prevented BOOTP path name * from being used (thanks to Leo Spiekman) * Andy Walker : Allow to specify the NFS server in nfs_root * without giving a path name * Swen Thümmler : Allow to specify the NFS options in nfs_root * without giving a path name. Fix BOOTP request * for domainname (domainname is NIS domain, not * DNS domain!). Skip dummy devices for BOOTP. * Jacek Zapala : Fixed a bug which prevented server-ip address * from nfsroot parameter from being used. * Olaf Kirch : Adapted to new NFS code. * Jakub Jelinek : Free used code segment. * Marko Kohtala : Fixed some bugs. * Martin Mares : Debug message cleanup * Martin Mares : Changed to use the new generic IP layer autoconfig * code. BOOTP and RARP moved there. * Martin Mares : Default path now contains host name instead of * host IP address (but host name defaults to IP * address anyway). * Martin Mares : Use root_server_addr appropriately during setup. * Martin Mares : Rewrote parameter parsing, now hopefully giving * correct overriding. * Trond Myklebust : Add in preliminary support for NFSv3 and TCP. * Fix bug in root_nfs_addr(). nfs_data.namlen * is NOT for the length of the hostname. * Hua Qin : Support for mounting root file system via * NFS over TCP. * Fabian Frederick: Option parser rebuilt (using parser lib) * Chuck Lever : Use super.c's text-based mount option parsing * Chuck Lever : Add "nfsrootdebug". */ #include <linux/types.h> #include <linux/string.h> #include <linux/init.h> #include <linux/nfs.h> #include <linux/nfs_fs.h> #include <linux/utsname.h> #include <linux/root_dev.h> #include <net/ipconfig.h> #include "internal.h" #define NFSDBG_FACILITY … /* Default path we try to mount. "%s" gets replaced by our IP address */ #define NFS_ROOT … /* Default NFSROOT mount options. */ #if defined(CONFIG_NFS_V2) #define NFS_DEF_OPTIONS … #elif defined(CONFIG_NFS_V3) #define NFS_DEF_OPTIONS … #else #define NFS_DEF_OPTIONS … #endif /* Parameters passed from the kernel command line */ static char nfs_root_parms[NFS_MAXPATHLEN + 1] __initdata = …; /* Text-based mount options passed to super.c */ static char nfs_root_options[256] __initdata = …; /* Address of NFS server */ static __be32 servaddr __initdata = …; /* Name of directory to mount */ static char nfs_export_path[NFS_MAXPATHLEN + 1] __initdata = …; /* server:export path string passed to super.c */ static char nfs_root_device[NFS_MAXPATHLEN + 1] __initdata = …; #ifdef NFS_DEBUG /* * When the "nfsrootdebug" kernel command line option is specified, * enable debugging messages for NFSROOT. */ static int __init nfs_root_debug(char *__unused) { … } __setup(…); #endif /* * Parse NFS server and directory information passed on the kernel * command line. * * nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>] * * If there is a "%s" token in the <root-dir> string, it is replaced * by the ASCII-representation of the client's IP address. */ static int __init nfs_root_setup(char *line) { … } __setup(…); static int __init root_nfs_copy(char *dest, const char *src, const size_t destlen) { … } static int __init root_nfs_cat(char *dest, const char *src, const size_t destlen) { … } /* * Parse out root export path and mount options from * passed-in string @incoming. * * Copy the export path into @exppath. */ static int __init root_nfs_parse_options(char *incoming, char *exppath, const size_t exppathlen) { … } /* * Decode the export directory path name and NFS options from * the kernel command line. This has to be done late in order to * use a dynamically acquired client IP address for the remote * root directory path. * * Returns zero if successful; otherwise -1 is returned. */ static int __init root_nfs_data(char *cmdline) { … } /** * nfs_root_data - Return prepared 'data' for NFSROOT mount * @root_device: OUT: address of string containing NFSROOT device * @root_data: OUT: address of string containing NFSROOT mount options * * Returns zero and sets @root_device and @root_data if successful, * otherwise -1 is returned. */ int __init nfs_root_data(char **root_device, char **root_data) { … }