diff options
Diffstat (limited to 'mdk-stage1')
40 files changed, 765 insertions, 2548 deletions
diff --git a/mdk-stage1/.gitignore b/mdk-stage1/.gitignore new file mode 100644 index 000000000..fe2469cea --- /dev/null +++ b/mdk-stage1/.gitignore @@ -0,0 +1,13 @@ +*.o +dhcp-client +init +probe-modules +rescue-gui +stage1 +pci-resource/pci-ids.h +usb-resource/usb-ids.h +pcmcia-resource/pcmcia-ids.h +pcmcia/lex_config.c +pcmcia/libpcmcia.a +pcmcia/yacc_config.c +pcmcia/yacc_config.h diff --git a/mdk-stage1/Makefile b/mdk-stage1/Makefile index 893b40351..1d66d22fe 100644 --- a/mdk-stage1/Makefile +++ b/mdk-stage1/Makefile @@ -2,8 +2,6 @@ # # mdk-stage1 - the program that will load second-stage install # - # $Id: Makefile 271082 2010-10-13 18:55:00Z tv $ - # # Pixel (pixel) (mostly done by Guillaume Cottenceau) # # Copyright 2000-2004 Mandriva @@ -15,33 +13,12 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -VERSION=1.78 +VERSION=2.62 PRODUCT=drakx-installer-binaries # # Portions from Erik Troan (ewt@redhat.com) Copyright 1996 Red Hat Software # - #***************************************************************************** - # - # Currently: - # - # ix86 - # init with dietlibc - # stage1 with dietlibc - # - # ppc - # init with dietlibc - # stage1 with glibc - # - # ia64 - # init with glibc - # stage1 with glibc - # - # x86-64 - # init with dietlibc - # stage1 with dietlibc - # - #***************************************************************************** top_dir = . @@ -50,61 +27,39 @@ include $(top_dir)/Makefile.common include $(top_dir)/../Makefile.config ARCHDIR=$(ARCH) ifeq (i386, $(ARCH)) -ARCHDIR=i586 +ARCHDIR=i686 endif DEFS = -DDISTRIB_NAME=\"$(DISTRIB_NAME)\" -DDISTRIB_VERSION=\"$(DISTRIB_VERSION)\" -DDISTRIB_TYPE=\"$(DISTRIB_TYPE)\" -DDISTRIB_DESCR=\"$(DISTRIB_DESCR)\" $(ADDITIONAL_DEFS) -D_FILE_OFFSET_BITS=64 -DARCH=\"$(ARCHDIR)\" -DCONFIG_USE_ZLIB -COMPILE = $(CC) $(DEFS) $(CFLAGS) +COMPILE = $(CC) $(DEFS) $(CFLAGS) -Wno-error=format-truncation -INIT_DEFS = INITSRC = init.c -ifneq (DIETLIBC, $(L)) -INIT_DEFS += $(GLIBC_INCLUDES) -endif STAGE1_DEFS=-DDISABLE_KA -INITOBJS = $(subst .c,.o,$(INITSRC)) +INITOBJS = $(INITSRC:.c=.o) #- frontends NEWT_FRONTEND_SRC = newt-frontend.c -NEWT_FRONTEND_LIBS = libnewt.a libslang.a +NEWT_FRONTEND_LIBS = -lnewt -lslang STDIO_FRONTEND_SRC = stdio-frontend.c STDIO_FRONTEND_LIBS = -STDIO_FRONTEND_LIBS = -FRONTEND_OBJS = $(subst .c,.o,$($(F)_FRONTEND_SRC)) +FRONTEND_OBJS = $($(F)_FRONTEND_SRC:.c=.o) -ifeq (DIETLIBC, $(L)) -FRONTEND_LINK = $(FRONTEND_OBJS) $(patsubst %,/usr/lib/dietlibc/lib-$(ARCH)/%,$($(F)_FRONTEND_LIBS)) -else FRONTEND_LINK = $(FRONTEND_OBJS) $($(F)_FRONTEND_LIBS) -endif -STAGE1_STATIC_LIBS = -STAGE1_STATIC_USR_LIBS = libz.a libldetect.a libkmod.a libpci.a liblzma.a libsysfs.a -STAGE1_OWN_LIBS = -ifeq (DIETLIBC, $(L)) -STAGE1_OWN_LIBS = $(patsubst %,/usr/lib/dietlibc/lib-$(ARCH)/%,$(STAGE1_STATIC_USR_LIBS) $(STAGE1_STATIC_LIBS)) -else -STAGE1_OWN_LIBS = $(patsubst %,/usr/$(LIB)/%,$(STAGE1_STATIC_USR_LIBS)) $(patsubst %,/$(LIB)/%,$(STAGE1_STATIC_LIBS)) -endif +STAGE1_OWN_LIBS = -lz -lldetect -lkmod -lpci -llzma -lsysfs -ifeq (DIETLIBC, $(L)) -STAGE1_NETWORK_LIBS = /usr/lib/dietlibc/lib-$(ARCH)/librpc.a -else -STAGE1_NETWORK_LIBS = /usr/$(LIB)/libresolv.a -endif - #- stage1 itself STAGE1SRC = stage1.c log.c utils.c params.c tools.c modules.c probing.c mount.c automatic.c frontend-common.c lomount.c thirdparty.c zlibsupport.c CDROMSRC = cdrom.c DISKSRC = disk.c directory.c partition.c -NETWORKSRC = network.c nfsmount.c dhcp.c url.c dns.c adsl.c directory.c wireless.c +NETWORKSRC = network.c dhcp.c url.c dns.c adsl.c directory.c wireless.c #KASRC = ka.c # use sort to remove duplicates @@ -126,24 +81,13 @@ STAGE1OBJS-NETWORK-STANDALONE = $(subst .c,-NETWORK-STANDALONE.o,$(STAGE1SRC) $( NETWORK_STANDALONE_DEFS = -DDISABLE_CDROM -DDISABLE_DISK -DENABLE_NETWORK_STANDALONE -DDISABLE_KA -STAGE1OBJS-FULL = $(subst .c,-FULL.o,$(STAGE1_ALLSRC)) +STAGE1OBJS-FULL = $(STAGE1_ALLSRC:.c=-FULL.o) BINS = init stage1 dhcp-client rescue-gui probe-modules -DIRS += pci-resource usb-resource -ifeq (i386, $(ARCH)) -DIRS += pcmcia pcmcia-resource -endif -ifeq (x86_64, $(ARCH)) -DIRS += pcmcia pcmcia-resource -endif - - -ifeq (i386,$(ARCH)) -PCMCIA_LIB = pcmcia/libpcmcia.a -PCMCIA_DEFS = -DENABLE_PCMCIA -endif -ifeq (x86_64,$(ARCH)) +OTHERS = pci-ids.h usb-ids.h +ifneq (,$(filter $(ARCH),i386 x86_64)) +OTHERS += pcmcia-ids.h pcmcia PCMCIA_LIB = pcmcia/libpcmcia.a PCMCIA_DEFS = -DENABLE_PCMCIA endif @@ -151,40 +95,49 @@ endif USB_DEFS_GEN = -DENABLE_USB USB_DEFS = -DENABLE_USB -DDISABLE_PCIADAPTERS -all: dirs $(BINS) +all: $(OTHERS) $(BINS) -dirs: - @for n in . $(DIRS); do \ - [ "$$n" = "." ] || make -C $$n || exit 1 ;\ - done +pci-ids.h: /usr/share/ldetect-lst/pcitable.gz update-pci-ids.pl + perl update-pci-ids.pl > $@ || { rm -f $@; exit 1; } + +usb-ids.h: /usr/share/ldetect-lst/usbtable.gz update-usb-ids.pl + perl update-usb-ids.pl > $@ || rm -f $@ -init: $(INITOBJS) $(STAGE1_LIBC) - $(DIET) $(CC) $(LDFLAGS) -o $@ $^ +pcmcia-ids.h: update-pcmcia-ids.pl + perl update-pcmcia-ids.pl > $@ || { rm -f $@; exit 1; } + +pcmcia/libpcmcia.a: + make -j -C pcmcia + +probing.c: pci-ids.h + +init: $(INITOBJS) + $(CC) $(LDFLAGS) -o $@ $^ $(STRIPCMD) $@ -stage1: $(STAGE1OBJS-FULL) $(STAGE1_OWN_LIBS) $(STAGE1_NETWORK_LIBS) $(FRONTEND_LINK) $(PCMCIA_LIB) $(STAGE1_LIBC) - $(DIET) $(CC) $(LDFLAGS) -o $@ $^ +stage1: $(STAGE1OBJS-FULL) $(STAGE1_OWN_LIBS) $(FRONTEND_LINK) $(PCMCIA_LIB) + $(CC) $(LDFLAGS) -o $@ $^ $(STRIPCMD) $@ -dhcp-client: $(STAGE1OBJS-NETWORK-STANDALONE) $(STAGE1_OWN_LIBS) $(STAGE1_NETWORK_LIBS) $(FRONTEND_LINK) $(STAGE1_LIBC) - $(DIET) $(CC) $(LDFLAGS) -o $@ $^ +dhcp-client: $(STAGE1OBJS-NETWORK-STANDALONE) $(STAGE1_OWN_LIBS) $(FRONTEND_LINK) + $(CC) $(LDFLAGS) -o $@ $^ $(STRIPCMD) $@ $(INITOBJS): %.o: %.c - $(COMPILE) $(INIT_DEFS) -c $< + $(COMPILE) -c $< $(STAGE1OBJS-NETWORK): %-NETWORK.o: %.c - $(DIET) $(COMPILE) $(INCLUDES) $(NETWORK_DEFS) $(PCMCIA_DEFS) $(USB_DEFS_GEN) -DENABLE_ADDITIONAL_MODULES -c $< -o $@ + $(COMPILE) $(INCLUDES) $(NETWORK_DEFS) $(PCMCIA_DEFS) $(USB_DEFS_GEN) -DENABLE_ADDITIONAL_MODULES -c $< -o $@ $(STAGE1OBJS-NETWORK-STANDALONE): %-NETWORK-STANDALONE.o: %.c - $(DIET) $(COMPILE) $(INCLUDES) $(NETWORK_STANDALONE_DEFS) $(USB_DEFS_GEN) -c $< -o $@ + $(COMPILE) $(INCLUDES) $(NETWORK_STANDALONE_DEFS) $(USB_DEFS_GEN) -c $< -o $@ $(STAGE1OBJS-FULL): %-FULL.o: %.c - $(DIET) $(COMPILE) $(INCLUDES) -DSPAWN_SHELL $(USB_DEFS_GEN) $(PCMCIA_DEFS) $(STAGE1_DEFS) -c $< -o $@ + $(COMPILE) $(INCLUDES) -DSPAWN_SHELL $(USB_DEFS_GEN) $(PCMCIA_DEFS) $(STAGE1_DEFS) -c $< -o $@ .c.o: - $(DIET) $(COMPILE) $(INCLUDES) -c $< + $(COMPILE) $(INCLUDES) -c $< clean: localclean @@ -193,40 +146,22 @@ clean: localclean done localclean: - rm -f *.o .depend *.rdz *.img $(BINS) + rm -f *.o .depend *.rdz *.img pci-ids.h pcmcia-ids.h usb-ids.h $(BINS) -rescue-gui: rescue-gui.o frontend-common.o params.o utils.o log.o automatic.o $(FRONTEND_LINK) $(STAGE1_LIBC) - $(DIET) $(CC) $(LDFLAGS) -o $@ $^ +rescue-gui: rescue-gui.o frontend-common.o params.o utils.o log.o automatic.o $(FRONTEND_LINK) + $(CC) $(LDFLAGS) -o $@ $^ $(STRIPCMD) $@ -probe-modules: probe-modules.o probing-FULL.o modules-FULL.o params-FULL.o utils-FULL.o log-FULL.o automatic-FULL.o frontend-common-FULL.o stdio-frontend.o zlibsupport-FULL.o $(STAGE1_OWN_LIBS) $(PCMCIA_LIB) $(STAGE1_LIBC) - $(DIET) $(CC) $(LDFLAGS) -o $@ $^ +probe-modules: probe-modules.o probing-FULL.o modules-FULL.o params-FULL.o utils-FULL.o log-FULL.o automatic-FULL.o frontend-common-FULL.o stdio-frontend.o zlibsupport-FULL.o $(STAGE1_OWN_LIBS) $(PCMCIA_LIB) + $(CC) $(LDFLAGS) -o $@ $^ $(STRIPCMD) $@ dist: tar tar: rm -rf $(PRODUCT)*.tar* $(PRODUCT)-$(VERSION) - @if [ -e "../.svn" ]; then \ - $(MAKE) dist-svn; \ - elif [ -e "../.git" ]; then \ - $(MAKE) dist-git; \ - else \ - echo "Unknown SCM (not SVN nor GIT)";\ - exit 1; \ - fi; - $(info $(PRODUCT)-$(VERSION).tar.xz is ready) - -dist-svn: - mkdir -p $(PRODUCT)-$(VERSION) - svn export -q -rBASE . $(PRODUCT)-$(VERSION)/mdk-stage1 - svn export -q -rBASE ../kernel $(PRODUCT)-$(VERSION)/kernel - cp ../Makefile.config $(PRODUCT)-$(VERSION)/ - tar cfa $(PRODUCT)-$(VERSION).tar.xz $(PRODUCT)-$(VERSION) - rm -rf $(PRODUCT)-$(VERSION) - -dist-git: @cd ..; git archive --prefix=$(PRODUCT)-$(VERSION)/ HEAD mdk-stage1 kernel Makefile.config | xz >mdk-stage1/$(PRODUCT)-$(VERSION).tar.xz; + $(info $(PRODUCT)-$(VERSION).tar.xz is ready) .depend: $(CPP) $(CFLAGS) -M $(ALLSRC) > .depend diff --git a/mdk-stage1/Makefile.common b/mdk-stage1/Makefile.common index 34c010905..f2c70273a 100644 --- a/mdk-stage1/Makefile.common +++ b/mdk-stage1/Makefile.common @@ -15,8 +15,7 @@ #***************************************************************************** ARCH := $(patsubst i%86,i386,$(shell uname -m)) -ARCH := $(patsubst sparc%,sparc,$(ARCH)) -ARCH := $(patsubst arm%,arm,$(ARCH)) +ARCH := $(ARCH:arm%=arm) # DEBUG = 1 @@ -27,22 +26,6 @@ else F = NEWT endif -# diet libc syscalls are broken on mips -ifneq (mips, $(ARCH)) -# diet libc eabi support is mostly broken -ifneq (arm, $(ARCH)) -DIET = $(shell test -x /usr/bin/diet && echo diet) -endif -endif - - -ifeq ($(DIET), diet) - #- default lib is dietlibc (honoured by main Makefile whenever possible) -L = DIETLIBC -else -L = GLIBC -endif - ifdef DEBUG OPTFLAGS = -g -DDEBUG else @@ -50,23 +33,11 @@ OPTFLAGS = -Os endif #- flags used by all stuff -CFLAGS = $(OPTFLAGS) -pipe -Wall -fomit-frame-pointer -fno-strict-aliasing - -ifneq (ppc, $(ARCH)) -ifneq (sparc, $(ARCH)) -CFLAGS += -Werror -endif -endif - -DIETLIBC_INCLUDES = -I/usr/lib/dietlibc/include -I. -DIETLIBC_LIBC = /usr/lib/dietlibc/lib-$(ARCH)/libcompat.a -GLIBC_INCLUDES = -I. -INCLUDES = $($(L)_INCLUDES) +CFLAGS = $(OPTFLAGS) -pipe -Wall -fomit-frame-pointer -fno-strict-aliasing -Werror -GLIBC_LDFLAGS = -static -LDFLAGS = $($(L)_LDFLAGS) +INCLUDES = -I. -STAGE1_LIBC = $($(L)_LIBC) +LDFLAGS = ifdef DEBUG STRIPCMD = echo not stripping diff --git a/mdk-stage1/NEWS b/mdk-stage1/NEWS index da824352a..714ea3129 100644 --- a/mdk-stage1/NEWS +++ b/mdk-stage1/NEWS @@ -1,3 +1,267 @@ +- Replace i586 with i686 in files + +2.62 + +- Sync list_modules with kernel 6.4 + +2.61 + +- Sync with kernel 6.0 +- Increase MEM_LIMIT_* to match current stage2 size +- Fix the detection of available memory +- Fix a build failure with -Werror=address + +2.60 + +- Sync with kernel 5.17 +- Sync with kernel 5.18 +- Sync with kernel 5.19 +- Sync with kernel 6.0 +- Sync with kernel 6.1 + +2.59 + +- use 'nolock' option for NFS + +2.58 + +- fix 'disk' method after kernel-5.15 breakage + +2.57 + +- http server: allow to specify a port different than default "80" (mga#28367) + +2.56 + +- load exfat module to mount exfat (mga#28371) + +2.55 + +- recognize rtw89_pci HID driver + +2.53 + +- recognize amd_sfh HID driver + +2.52 + +- recognize more rtw88_* +- sync with kernel 5.10 + +2.51 + +- configure wpa_supplicant to try both nl80211 and wext interfaces + o some old wireless driver modules may only support wext +- improve help for entering wireless keys/passphrases + o note that ASCII strings can now be used for WEP keys (mga#21042) + +2.50 + +- add support for WPA/WPA2 (mga#9541) + +2.49 + +- sync with kernel 5.9 + +2.48 + +- sync with kernel 5.8 + +2.47 + +- sync with kernel 5.6/5.7 + +2.46 + +- make NVME code really generic and reuse if for most other disks + +2.45 + +- fix NVME code to work for disks with no vendor + +2.44 + +- add support for NVME disks + +2.43 + +- sync with kernel 5.5 + +2.42 + +- sync with kernel 5.4 + +2.41 + +- sync with kernel 5.3 + +2.40 + +- recognize 8821ce (mga#24605) + +2.39 + +- add AMD PCIe MP2 I2C detection + +2.38 + +- sync with kernel 5.1 + +2.37 + +- sync with kernel 5.0 + +2.36 + +- suppress mount error messages when probing for media (mga#24142) +- better gcc8 workarounds + +2.35 + +- fix compiling with gcc8 +- compile with -Wno-error=format-truncation for now + +2.34 + +- mounting: + o let libblk guess the right fs type rather than manually trying a long list + of potential fses + o use regular mount tool rather than manual system calls + o use regular mount tool for NFS too (support NFSv4, ...) + +2.33 + +- advertize "ext4" rather than "ext2" +- check for builtin modules in /sys/fs too (eg: ext4) +- support auto-install with "method:disk,disk:xxx,part:xxxY,dir:zzz" + +2.32 + +- list_modules: don't include vboxvideo (mga#23467) + +2.31 + +- sync with kernel 4.1[89] + +2.30 + +- add missing smartpqi driver (mga#23305) + +2.29 +- add missing Mellanox drivers (mga#23263) + +2.28 +- sync with kernel 4.1[5-7] + +2.27 +- further sync with kernel 4.14 + +2.26 +- sync with kernel 4.14 + +2.25 +- fix build with gcc7 + +2.24 +- recognize 8812au (mga#21043) + +2.23 +- recognize new kernel-4.8 drivers + +2.22 +- recognize new kernel-4.9 drivers + +2.21 +- recognize new kernel-4.7 drivers + +2.20 +- fix description of network interfaces (mga#15638) + +2.19 +- recognize some missing wireless drivers (mga#16768) + +2.18 +- recognize new kernel-4.6 drivers + +2.17 +- recognize new kernel-4.4 drivers + +2.16 +- recognize new kernel-4.3 drivers + +2.15 +- recognize new kernel-4.1 drivers + +2.14 +- network.c: fix -Werror=logical-not-parentheses + +2.13 +- mount again debugfs for ldetect (mga#14435) + (regression in 1.83) + +2.12 +- recognize new kernel-3.19 drivers + +2.11 +- recognize new kernel-3.18 drivers (mga#14799) + +2.10 +- include new 3.18 USB host drivers (mga#14799) + +2.9 +- glibc 2.20 wants _DEFAULT_SOURCE instead of _BSD_SOURCE + +2.8 +- recognize new kernel-3.17 drivers + +2.7 +- recognize hyper-v network card + +2.6 +- recognize new kernel-3.16 drivers + +2.5 +- stop creating /dev entries now that we use udev + +2.4 +- fix building with "make -j24" + +2.3 +- recognize new kernel-3.15 drivers + +2.2 +- drop support for supermount (dead since 2007) +- recognize new kernel-3.14 drivers + +2.1 +- drop support for SPARC +- support dynamic linking only +- use getaddrinfo() with glibc too now that use the dynamic library + +2.0 +- kernel modules and firmware is needed during stage2, so move and symlink + (symlinks are only for if you umount state2 /usr and want a still working initrd) + mga#11600 mga#11601 + +1.83 +- do initrd symlinking in 'init' rather than 'stage1' (stage1 is now run earlier) +- build init and stage1 as a shared library (due to bugs in directory handling + in dietlibc as exposed in libkmod but also because glibc is already include in + dracut) + +1.82 +- detect new kernel-3.12 modules + +1.81 +- sync with kernel-3.11 (might fix mga#11377) + +1.80 +- include latest list_modules.pl + (might fix mga#11377) + +1.79 +- fix compiling with gcc-4.8 + 1.78 - probe virtual drivers too (mga#9546) (install from Xen hd not supported yet) diff --git a/mdk-stage1/config-stage1.h b/mdk-stage1/config-stage1.h index 4d27a58c9..e3409df98 100644 --- a/mdk-stage1/config-stage1.h +++ b/mdk-stage1/config-stage1.h @@ -22,9 +22,9 @@ /* If we have more than that amount of memory (in Mbytes), we assume we can load the second stage as a ramdisk */ -#define MEM_LIMIT_DRAKX 68 +#define MEM_LIMIT_DRAKX 192 /* If we have more than that amount of memory (in Mbytes), we preload the second stage as a ramdisk */ -#define MEM_LIMIT_DRAKX_PRELOAD 100 +#define MEM_LIMIT_DRAKX_PRELOAD 256 /* If we have more than that amount of memory (in Mbytes), we assume we can load the rescue as a ramdisk */ #define MEM_LIMIT_RESCUE 40 @@ -42,7 +42,7 @@ /* the remote media is mounted in MEDIA_LOCATION, and - IMAGE_LOCATION is a symlink image -> image/mdk/mirror/dir - - IMAGE_LOCATION is a symlink image -> loop/i586 and iso file is loopback mounted in LOOP_LOCATION + - IMAGE_LOCATION is a symlink image -> loop/i686 and iso file is loopback mounted in LOOP_LOCATION */ #define MEDIA_LOCATION_REL "media" #define MEDIA_LOCATION IMAGE_LOCATION_DIR MEDIA_LOCATION_REL diff --git a/mdk-stage1/dhcp.c b/mdk-stage1/dhcp.c index a4cc07446..678031e85 100644 --- a/mdk-stage1/dhcp.c +++ b/mdk-stage1/dhcp.c @@ -213,7 +213,7 @@ static void parse_reply(struct bootp_request * breq, struct interface_info * int unsigned char * chptr; unsigned char option, length; - if (breq->bootfile && strlen(breq->bootfile) > 0) { + if (strlen(breq->bootfile) > 0) { if (IS_NETAUTO) add_to_env("KICKSTART", breq->bootfile); else @@ -587,7 +587,7 @@ enum return_type perform_dhcp(struct interface_info * intf) log_message("DHCP: telling server to use name = %s", dhcp_hostname); } - memset(&client_addr.sin_addr, 0, sizeof(&client_addr.sin_addr)); + memset(&client_addr.sin_addr, 0, sizeof(client_addr.sin_addr)); client_addr.sin_family = AF_INET; client_addr.sin_port = htons(BOOTP_CLIENT_PORT); /* bootp client */ diff --git a/mdk-stage1/disk.c b/mdk-stage1/disk.c index d9fd92b99..51a033639 100644 --- a/mdk-stage1/disk.c +++ b/mdk-stage1/disk.c @@ -45,6 +45,13 @@ static enum return_type try_automatic_with_partition(char *dev) { enum return_type results; int mounted; + char *dir= get_auto_value("directory"); + char location_full[500]; + strcpy(location_full, MEDIA_LOCATION); + if (dir) { + strcat(location_full, "/"); + strcat(location_full, dir); + } wait_message("Trying to access " DISTRIB_NAME " disk (partition %s)", dev); mounted = !try_mount(dev, MEDIA_LOCATION); remove_wait_message(); @@ -52,11 +59,13 @@ static enum return_type try_automatic_with_partition(char *dev) { create_IMAGE_LOCATION(MEDIA_LOCATION); if (image_has_stage2()) { results = try_with_directory(MEDIA_LOCATION, "disk", "disk-iso"); - if (results == RETURN_OK) { - if (!KEEP_MOUNTED) - umount(MEDIA_LOCATION); - return RETURN_OK; - } + } else { + results = try_with_directory(location_full, "disk", "disk-iso"); + } + if (results == RETURN_OK) { + if (!KEEP_MOUNTED) + umount(MEDIA_LOCATION); + return RETURN_OK; } } if (mounted) @@ -69,6 +78,7 @@ static enum return_type try_automatic_with_disk(char *disk, char *model) { char * parts_comments[50]; enum return_type results; char **dev; + char *part = get_auto_value("partition"); wait_message("Trying to access " DISTRIB_NAME " disk (drive %s)", model); if (list_partitions(disk, parts, parts_comments)) { stg1_error_message("Could not read partitions information."); @@ -77,10 +87,13 @@ static enum return_type try_automatic_with_disk(char *disk, char *model) { remove_wait_message(); dev = parts; while (dev && *dev) { + if (part && strcmp(part, *dev) != 0) + goto next; results = try_automatic_with_partition(*dev); if (results == RETURN_OK) { return RETURN_OK; } + next: dev++; } return RETURN_ERROR; @@ -90,11 +103,15 @@ static enum return_type try_automatic(char ** medias, char ** medias_models) { char ** model = medias_models; char ** ptr = medias; + char *disk = get_auto_value("disk"); while (ptr && *ptr) { enum return_type results; + if (disk && strcmp(disk, *ptr) != 0) + goto next; results = try_automatic_with_disk(*ptr, *model); if (results == RETURN_OK) return RETURN_OK; + next: ptr++; model++; } @@ -134,7 +151,7 @@ static enum return_type try_with_device(char *dev_name) /* in testing mode, assume the partition is already mounted on MEDIA_LOCATION */ if (!IS_TESTING && try_mount(choice, MEDIA_LOCATION)) { - stg1_error_message("I can't find a valid filesystem (tried: ext2, vfat, ntfs, reiserfs). " + stg1_error_message("I can't find a valid filesystem (tried: ext4, vfat, ntfs, reiserfs). " "Make sure the partition has been cleanly unmounted."); return try_with_device(dev_name); } diff --git a/mdk-stage1/dns.c b/mdk-stage1/dns.c index 488b4844e..f711758aa 100644 --- a/mdk-stage1/dns.c +++ b/mdk-stage1/dns.c @@ -21,10 +21,6 @@ #include <stdlib.h> -// dietlibc can do hostname lookup, whereas glibc can't when linked statically :-( - -#if defined(__dietlibc__) - #include <unistd.h> #include <string.h> #include <stdio.h> @@ -92,145 +88,3 @@ char * mygethostbyaddr(char * ipnum) return strdup(hbuf); else return NULL; } - -#elif defined(__GLIBC__) - -#include <alloca.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <resolv.h> -#include <arpa/nameser.h> -#include <arpa/inet.h> -#include <stdlib.h> -#include <string.h> - -#include "log.h" - -#include "dns.h" - -/* This is dumb, but glibc doesn't like to do hostname lookups w/o libc.so */ - -union dns_response { - HEADER hdr; - u_char buf[PACKETSZ]; -} ; - -static int do_query(char * query, int queryType, char ** domainName, struct in_addr * ipNum) -{ - int len, ancount, type; - u_char * data, * end; - char name[MAXDNAME]; - union dns_response response; - -#ifdef __sparc__ - /* from jj: */ - /* We have to wait till ethernet negotiation is done */ - _res.retry = 3; -#else - _res.retry = 2; -#endif - - - len = res_search(query, C_IN, queryType, (void *) &response, sizeof(response)); - if (len <= 0) - return -1; - - if (ntohs(response.hdr.rcode) != NOERROR) - return -1; - - ancount = ntohs(response.hdr.ancount); - if (ancount < 1) - return -1; - - data = response.buf + sizeof(HEADER); - end = response.buf + len; - - /* skip the question */ - data += dn_skipname(data, end) + QFIXEDSZ; - - /* parse the answer(s) */ - while (--ancount >= 0 && data < end) { - - /* skip the domain name portion of the RR record */ - data += dn_skipname(data, end); - - /* get RR information */ - GETSHORT(type, data); - data += INT16SZ; /* skipp class */ - data += INT32SZ; /* skipp TTL */ - GETSHORT(len, data); - - if (type == T_PTR) { - /* we got a pointer */ - len = dn_expand(response.buf, end, data, name, sizeof(name)); - if (len <= 0) return -1; - if (queryType == T_PTR && domainName) { - /* we wanted a pointer */ - *domainName = malloc(strlen(name) + 1); - strcpy(*domainName, name); - return 0; - } - } else if (type == T_A) { - /* we got an address */ - if (queryType == T_A && ipNum) { - /* we wanted an address */ - memcpy(ipNum, data, sizeof(*ipNum)); - return 0; - } - } - - /* move ahead to next RR */ - data += len; - } - - return -1; -} - -char * mygethostbyaddr(char * ipnum) { - int rc; - char * result; - char * strbuf; - char * chptr; - char * splits[4]; - int i; - - _res.retry = 1; - - strbuf = alloca(strlen(ipnum) + 1); - strcpy(strbuf, ipnum); - - ipnum = alloca(strlen(strbuf) + 20); - - for (i = 0; i < 4; i++) { - chptr = strbuf; - while (*chptr && *chptr != '.') - chptr++; - *chptr = '\0'; - - if (chptr - strbuf > 3) return NULL; - splits[i] = strbuf; - strbuf = chptr + 1; - } - - sprintf(ipnum, "%s.%s.%s.%s.in-addr.arpa", splits[3], splits[2], splits[1], splits[0]); - - rc = do_query(ipnum, T_PTR, &result, NULL); - - if (rc) - return NULL; - else - return result; -} - -int mygethostbyname(char * name, struct in_addr * addr) { - int rc = do_query(name, T_A, NULL, addr); - if (!rc) - log_message("is-at %s", inet_ntoa(*addr)); - return rc; -} - -#else - -#error "Unsupported C library" - -#endif diff --git a/mdk-stage1/doc/README b/mdk-stage1/doc/README index 65e0174b4..28b81b39e 100644 --- a/mdk-stage1/doc/README +++ b/mdk-stage1/doc/README @@ -106,7 +106,7 @@ of the easiest way is to grab a local copy of the Distribution on one of your local hard drives, and to install from that location. At present time, you can install from IDE or SCSI drives, from Linux -(ext2), Windows (vfat) or Reiserfs partition. +(ext4), Windows (vfat) or Reiserfs partition. In that case, you'll need to use the "hd.img" image file. The dialogs will ask you to choose the DISK drive to use to install from, then the diff --git a/mdk-stage1/doc/TECH-INFOS b/mdk-stage1/doc/TECH-INFOS index 49c9c59b8..81d559a7f 100644 --- a/mdk-stage1/doc/TECH-INFOS +++ b/mdk-stage1/doc/TECH-INFOS @@ -6,7 +6,7 @@ This feature is used to replace redhat kickstart. It uses the kernel parameter "automatic" with keywords separated with commas and colons, on the following genres: - automatic=method:nfs,network:static,ip:192.168.1.24,server:192.168.1.7,directory:/stable/i586 + automatic=method:nfs,network:static,ip:192.168.1.24,server:192.168.1.7,directory:/stable/i686 automatic=method:ftp,network:dhcp,server:ftp.ciril.fr,directory:/pub/linux/mandriva-devel/cooker @@ -89,9 +89,9 @@ commandline), please find each keyword short-alias counterpart in file This gives for example for: - automatic=method:nfs,network:static,ip:192.168.1.24,server:192.168.1.7,directory:/stable/i586 + automatic=method:nfs,network:static,ip:192.168.1.24,server:192.168.1.7,directory:/stable/i686 ==> - automatic=met:nfs,net:static,ip:192.168.1.24,ser:192.168.1.7,dir:/stable/i586 + automatic=met:nfs,net:static,ip:192.168.1.24,ser:192.168.1.7,dir:/stable/i686 diff --git a/mdk-stage1/doc/WHY-DIETLIBC b/mdk-stage1/doc/WHY-DIETLIBC deleted file mode 100644 index e7c526b49..000000000 --- a/mdk-stage1/doc/WHY-DIETLIBC +++ /dev/null @@ -1,50 +0,0 @@ -(the dietlibc is a replacement for the glibc, which aim is to produce -smaller statically linked binaries) - - -The use for dietlibc in the stage1 was clear because currently used -install process on x86 is from a 1.44 Mbytes floppy. On this floppy we -need to fit the kernel, modules (scsi and network access), and the code to -do the basic things to load the stage2. The only part on which we could -progress was the code. - -As always, figures demonstrate evidences. Here are the size of the -binaries used for the cdrom, disk, network and full floppy installs, using -newt as the UI library: - - - with glibc - --rwxr-xr-x 1 gc gc 569448 May 15 15:29 stage1-cdrom --rwxr-xr-x 1 gc gc 572264 May 15 15:29 stage1-disk --rwxr-xr-x 1 gc gc 624712 May 15 15:30 stage1-network --rwxr-xr-x 1 gc gc 720360 May 15 15:29 stage1-full - - - with dietlibc - --rwxr-xr-x 1 gc gc 169332 May 15 14:26 stage1-cdrom --rwxr-xr-x 1 gc gc 172180 May 15 14:26 stage1-disk --rwxr-xr-x 1 gc gc 198612 May 15 14:26 stage1-network --rwxr-xr-x 1 gc gc 251764 May 15 14:26 stage1-full - - -The `stage1-full' binary has code for many things, most notably: data -decrunching (bzlib), archive extraction (in-house format), module loading -(insmod from busybox), PCI detection, ide and scsi handling, -cdrom/disk/loopback mounting, DHCP client negociation (redhat+grub), NFS -mounting (util-linux), FTP and HTTP transmission (redhat), pcmcia -initializing (pcmcia-cs), UI interaction (slang/newt); with use of the -dietlibc, the binary is only 250 kbytes! - - -Due to the modular coding, it is also possible to choose to not use -slang/newt as the UI, but a stdio-only UI. In that case, the binaries get -even smaller: - --rwxr-xr-x 1 gc gc 104500 May 15 15:46 stage1-cdrom* --rwxr-xr-x 1 gc gc 107348 May 15 15:46 stage1-disk* --rwxr-xr-x 1 gc gc 133972 May 15 15:47 stage1-network* --rwxr-xr-x 1 gc gc 187348 May 15 15:46 stage1-full* - - - -gc [Tue May 15 15:58:34 2001]
\ No newline at end of file diff --git a/mdk-stage1/init.c b/mdk-stage1/init.c index 3f912c2ac..7c48f64ec 100644 --- a/mdk-stage1/init.c +++ b/mdk-stage1/init.c @@ -22,6 +22,7 @@ #include <stdlib.h> #include <unistd.h> #include <stdio.h> +#include <dirent.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> @@ -51,20 +52,15 @@ static inline long reboot(unsigned int command) #include "config-stage1.h" #include <linux/cdrom.h> -#if defined(__powerpc__) -#define TIOCSCTTY 0x540E -#endif - -#define BINARY "/sbin/stage1" #define BINARY_STAGE2 "/usr/bin/runinstall2" char * env[] = { "PATH=/usr/bin:/bin:/sbin:/usr/sbin:/mnt/sbin:/mnt/usr/sbin:/mnt/bin:/mnt/usr/bin", - "LD_LIBRARY_PATH=/lib:/usr/lib:/mnt/lib:/mnt/usr/lib:/usr/X11R6/lib:/mnt/usr/X11R6/lib" -#if defined(__x86_64__) || defined(__ppc64__) - ":/lib64:/usr/lib64:/usr/X11R6/lib64:/mnt/lib64:/mnt/usr/lib64:/mnt/usr/X11R6/lib64" + "LD_LIBRARY_PATH=/lib:/usr/lib:/mnt/lib:/mnt/usr/lib" +#if defined(__x86_64__) + ":/lib64:/usr/lib64:/mnt/lib64:/mnt/usr/lib64" #endif , "HOME=/", @@ -284,7 +280,9 @@ char* strcat(register char* s,register const char* t) char *dest=s; s+=strlen(s); for (;;) { - if (!(*s = *t)) break; ++s; ++t; + if (!(*s = *t)) + break; + ++s; ++t; } return dest; } @@ -378,7 +376,86 @@ int in_reboot(void) return 0; } -int exit_value_proceed = 66; +int recursive_remove(char *file); +int recursive_remove(char *file) +{ + struct stat sb; + + if (lstat(file, &sb) != 0) { + printf("failed to stat %s: %d\n", file, errno); + return -1; + } + + /* only descend into subdirectories if device is same as dir */ + if (S_ISDIR(sb.st_mode)) { + char * strBuf = alloca(strlen(file) + 1024); + DIR * dir; + struct dirent * d; + + if (!(dir = opendir(file))) { + printf("error opening %s: %d\n", file, errno); + return -1; + } + while ((d = readdir(dir))) { + if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) + continue; + + strcpy(strBuf, file); + strcat(strBuf, "/"); + strcat(strBuf, d->d_name); + + if (recursive_remove(strBuf) != 0) { + closedir(dir); + return -1; + } + } + closedir(dir); + + if (rmdir(file)) { + printf("failed to rmdir %s: %d\n", file, errno); + return -1; + } + } else { + if (unlink(file) != 0) { + printf("failed to remove %s: %d\n", file, errno); + return -1; + } + } + return 0; +} + + +int create_initial_fs_symlinks(char* symlinks) +{ + FILE *f; + char buf[5000]; + + if (!(f = fopen(symlinks, "rb"))) { + printf("Error opening symlink definitions file '%s'\n", symlinks); + return -1; + } + while (fgets(buf, sizeof(buf), f)) { + char oldpath[500], newpath[500]; + struct stat sb; + + buf[strlen(buf)-1] = '\0'; // trim \n + if (sscanf(buf, "%s %s", oldpath, newpath) != 2) { + snprintf(oldpath, sizeof(oldpath), "%s%s", STAGE2_LOCATION, buf); + snprintf(newpath, sizeof(newpath), "%s", buf); + } + if (lstat(newpath, &sb) == 0) + recursive_remove(newpath); + printf("Creating symlink %s -> %s\n", oldpath, newpath); + if (symlink(oldpath, newpath)) { + printf("Error creating symlink\n"); + return -1; + } + } + fclose(f); + return 0; +} + + int exit_value_restart = 0x35; int main(int argc, char **argv) @@ -386,7 +463,6 @@ int main(int argc, char **argv) pid_t installpid, childpid; int wait_status; int fd; - int counter = 0; int abnormal_termination = 0; if (argc > 1 && argv[1][0] >= '0' && argv[1][0] <= '9') { @@ -404,22 +480,10 @@ int main(int argc, char **argv) printf("*** TESTING MODE *** (pid is %d)\n", getpid()); - if (!testing) { - if (mount("/proc", "/proc", "proc", 0, NULL)) - fatal_error("Unable to mount proc filesystem"); - if (mount("none", "/sys", "sysfs", 0, NULL)) - fatal_error("Unable to mount sysfs filesystem"); + // needed for ldetect: + if (!testing) if (mount("none", "/sys/kernel/debug", "debugfs", MS_NOSUID, "mode=0755")) fatal_error("Unable to mount debugfs filesystem"); - if (mount("none", "/dev", "devtmpfs", 0, NULL)) - fatal_error("Unable to mount dev filesystem"); - mkdir("/dev/pts", 0755); - if (mount("/dev/pts", "/dev/pts", "devpts", MS_NOSUID|MS_NOEXEC, "gid=5,mode=0620")) - fatal_error("Unable to mount /dev/pts devpts filesystem"); - mkdir("/dev/shm", 0755); - if (mount("/dev/shm", "/dev/shm", "tmpfs", MS_NOSUID|MS_NODEV, "mode=1777")) - fatal_error("Unable to mount /dev/shm tmpfs filesystem"); - } /* ignore Control-C and keyboard stop signals */ @@ -454,57 +518,66 @@ int main(int argc, char **argv) if (!testing) doklog(); - /* Go into normal init mode - keep going, and then do a orderly shutdown - when: + if (create_initial_fs_symlinks(STAGE2_LOCATION "/usr/share/symlinks") != 0) + fatal_error("Fatal error finishing initialization (could not create symlinks)."); - 1) install exits - 2) we receive a SIGHUP - */ + /* kernel modules and firmware is needed by stage2, so move them to the root */ + if (rename("/usr/lib/modules", "/modules")) + fatal_error("Cannot rename modules folder"); - do { - if (counter == 1) { - printf("proceeding, please wait...\n"); - } + if (rename("/usr/lib/firmware", "/firmware")) + fatal_error("Cannot rename firmware folder"); - if (!(installpid = fork())) { - /* child */ - char * child_argv[2]; - child_argv[0] = counter == 0 ? BINARY : BINARY_STAGE2; - child_argv[1] = NULL; + /* Add some symlinks so stage1 is still valid on it's own - not strictly needed */ + if (symlink("/modules", "/usr/lib/modules")) + fatal_error("Cannot symlink modules folder"); - execve(child_argv[0], child_argv, env); - printf("error in exec of %s :-( [%d]\n", child_argv[0], errno); - return 0; - } + if (symlink("/firmware", "/usr/lib/firmware")) + fatal_error("Cannot symlink firmware folder"); - do { - childpid = wait4(-1, &wait_status, 0, NULL); - } while (childpid != installpid); + if (mount(STAGE2_LOCATION "/usr", "/usr", "none", MS_BIND|MS_RDONLY, NULL)) + fatal_error("Unable to bind mount /usr filesystem from rescue or installer stage2"); - counter++; - } while (WIFEXITED(wait_status) && WEXITSTATUS(wait_status) == exit_value_restart); - /* allow Ctrl Alt Del to reboot */ - reboot(LINUX_REBOOT_CMD_CAD_ON); + if (access("/run/drakx/run-init", R_OK) == 0) { + /* This is typically used in rescue mode */ + char * child_argv[2] = { "/sbin/init", NULL }; - if (in_reboot()) { - // any exitcode is valid if we're in_reboot - } else if (WIFEXITED(wait_status) && WEXITSTATUS(wait_status) == exit_value_proceed) { kill(klog_pid, 9); printf("proceeding, please wait...\n"); + execve(child_argv[0], child_argv, env); + fatal_error("failed to exec /sbin/init"); + } + + /* This is installer mode */ + do { + printf("proceeding, please wait...\n"); - { - char * child_argv[2] = { "/sbin/init", NULL }; + if (!(installpid = fork())) { + /* child */ + char * child_argv[2] = { BINARY_STAGE2, NULL }; execve(child_argv[0], child_argv, env); + printf("error in exec of %s :-( [%d]\n", child_argv[0], errno); + return 0; } - fatal_error("failed to exec /sbin/init"); - } else if (!WIFEXITED(wait_status) || WEXITSTATUS(wait_status) != 0) { + + do { + childpid = wait4(-1, &wait_status, 0, NULL); + } while (childpid != installpid); + } while (WIFEXITED(wait_status) && WEXITSTATUS(wait_status) == exit_value_restart); + + /* allow Ctrl Alt Del to reboot */ + reboot(LINUX_REBOOT_CMD_CAD_ON); + + if (in_reboot()) { + // any exitcode is valid if we're in_reboot + } else if (!WIFEXITED(wait_status) || WEXITSTATUS(wait_status) != 0) { printf("exited abnormally :-( "); if (WIFSIGNALED(wait_status)) printf("-- received signal %d", WTERMSIG(wait_status)); printf("\n"); abnormal_termination = 1; - } + } if (!abnormal_termination) { int i; diff --git a/mdk-stage1/ka.c b/mdk-stage1/ka.c index 670abe5af..7b9d98fbe 100644 --- a/mdk-stage1/ka.c +++ b/mdk-stage1/ka.c @@ -44,7 +44,7 @@ static void my_pause(void) { static enum return_type ka_wait_for_stage2(int count) { char * ramdisk = "/dev/ram3"; /* warning, verify that this file exists in the initrd*/ - char * ka_launch[] = { "/ka/ka-d-client", "-w","-s","getstage2","-e","(cd /tmp/stage2; tar -x -f - )", NULL }; /* The command line for ka_launch */ + char * ka_launch[] = { "/ka/ka-d-client", "-w","-s","getstage2","-e","(cd " STAGE2_LOCATION "; tar -x -f - )", NULL }; /* The command line for ka_launch */ char * mkfs_launch[] = { "/sbin/mke2fs", "-m", "0", ramdisk, NULL}; /* The mkfs command for formating the ramdisk */ log_message("KA: Preparing to receive stage 2...."); diff --git a/mdk-stage1/modules.c b/mdk-stage1/modules.c index 214069286..76177302e 100644 --- a/mdk-stage1/modules.c +++ b/mdk-stage1/modules.c @@ -221,6 +221,12 @@ int module_already_present(const char * name) answ = 1; free(path); } + if (!answ) { + asprintf(&path, "/sys/fs/%s", name); + if (!stat(path, &sb)) + answ = 1; + free(path); + } return answ; } @@ -353,7 +359,6 @@ enum insmod_return my_modprobe(const char * mod_name, enum driver_type type __at sprintf(alias, "alias %s %s", *new_net_devices, mod_name); add_modules_conf(alias); log_message("NET: %s", alias); - net_discovered_interface(*new_net_devices); already_present: new_net_devices++; diff --git a/mdk-stage1/mount.c b/mdk-stage1/mount.c index d1b290a70..14b2b2fc2 100644 --- a/mdk-stage1/mount.c +++ b/mdk-stage1/mount.c @@ -19,10 +19,12 @@ * */ +// for asprintf: +#define _GNU_SOURCE +#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> -#include <stdio.h> #include <sys/mount.h> #include <sys/stat.h> #include <sys/types.h> @@ -37,138 +39,16 @@ /* WARNING: this won't work if the argument is not /dev/ based */ int ensure_dev_exists(const char * dev) { - int major, minor; - int type = S_IFBLK; /* my default type is block. don't forget to change for chars */ - const char * name; struct stat buf; - char * ptr; - name = &dev[5]; /* we really need that dev be passed as /dev/something.. */ - if (!stat(dev, &buf)) return 0; /* if the file already exists, we assume it's correct */ - if (ptr_begins_static_str(name, "sd")) { - /* SCSI disks */ - major = 8; - minor = (name[2] - 'a') << 4; - if (name[3] && name[4]) { - minor += 10 + (name[4] - '0'); - if (name[3] > 1 || name[4] > 5) { - log_message("I don't know how to create device %s, please post bugreport to me!", dev); - return -1; - } - } else if (name[3]) - minor += (name[3] - '0'); - } else if (ptr_begins_static_str(name, "vd")) { - /* Virtual disks */ - major = 252; - minor = (name[2] - 'a') << 4; - if (name[3] && name[4]) { - minor += 10 + (name[4] - '0'); - if (name[3] > 1 || name[4] > 5) { - log_message("I don't know how to create device %s, please post bugreport to me!", dev); - return -1; - } - } else if (name[3]) - minor += (name[3] - '0'); - } else if (ptr_begins_static_str(name, "xvd")) { - /* Virtual disks */ - major = 202; - minor = (name[2] - 'a') << 4; - if (name[4] && name[5]) { - minor += 10 + (name[5] - '0'); - if (name[4] > 1 || name[5] > 5) { - log_message("I don't know how to create device %s, please post bugreport to me!", dev); - return -1; - } - } else if (name[4]) - minor += (name[4] - '0'); - } else if (ptr_begins_static_str(name, "hd")) { - /* IDE disks/cd's */ - if (name[2] == 'a') - major = 3, minor = 0; - else if (name[2] == 'b') - major = 3, minor = 64; - else if (name[2] == 'c') - major = 22, minor = 0; - else if (name[2] == 'd') - major = 22, minor = 64; - else if (name[2] == 'e') - major = 33, minor = 0; - else if (name[2] == 'f') - major = 33, minor = 64; - else if (name[2] == 'g') - major = 34, minor = 0; - else if (name[2] == 'h') - major = 34, minor = 64; - else if (name[2] == 'i') - major = 56, minor = 0; - else if (name[2] == 'j') - major = 56, minor = 64; - else if (name[2] == 'k') - major = 57, minor = 0; - else if (name[2] == 'l') - major = 57, minor = 64; - else if (name[2] == 'm') - major = 88, minor = 0; - else if (name[2] == 'n') - major = 88, minor = 64; - else if (name[2] == 'o') - major = 89, minor = 0; - else if (name[2] == 'p') - major = 89, minor = 64; - else if (name[2] == 'q') - major = 90, minor = 0; - else if (name[2] == 'r') - major = 90, minor = 64; - else if (name[2] == 's') - major = 91, minor = 0; - else if (name[2] == 't') - major = 91, minor = 64; - else - return -1; - - if (name[3] && name[4]) - minor += 10 + (name[4] - '0'); - else if (name[3]) - minor += (name[3] - '0'); - } else if (ptr_begins_static_str(name , "sr")) { - /* SCSI cd's */ - major = 11; - minor = name[2] - '0'; - } else if (ptr_begins_static_str(name, "ida/") || - ptr_begins_static_str(name, "cciss/")) { - /* Compaq Smart Array "ida/c0d0{p1}" */ - ptr = strchr(name, '/'); - mkdir("/dev/ida", 0755); - mkdir("/dev/cciss", 0755); - major = ptr_begins_static_str(name, "ida/") ? 72 : 104 + charstar_to_int(ptr+2); - ptr = strchr(ptr, 'd'); - minor = 16 * charstar_to_int(ptr+1); - ptr = strchr(ptr, 'p'); - minor += charstar_to_int(ptr+1); - } else if (ptr_begins_static_str(name, "rd/")) { - /* DAC960 "rd/cXdXXpX" */ - mkdir("/dev/rd", 0755); - major = 48 + charstar_to_int(name+4); - ptr = strchr(name+4, 'd'); - minor = 8 * charstar_to_int(ptr+1); - ptr = strchr(ptr, 'p'); - minor += charstar_to_int(ptr+1); - } else if (ptr_begins_static_str(name, "loop")) { - major = 7; - minor = name[4] - '0'; - } else if (ptr_begins_static_str(name, "chloop")) { - major = 100; - minor = name[6] - '0'; - } else { - log_message("I don't know how to create device %s, please post bugreport to me!", dev); - return -1; - } + // give udev some time to create nodes if module was just insmoded: + system("udevadm settle"); - if (mknod(dev, type | 0600, makedev(major, minor))) { - log_perror(dev); + if (!stat(dev, &buf)) { + log_message("I don't know how to create device %s, please post bugreport to me!", dev); return -1; } @@ -179,7 +59,6 @@ int ensure_dev_exists(const char * dev) /* mounts, creating the device if needed+possible */ int my_mount(char *dev, char *location, char *fs, int force_rw) { - unsigned long flags = MS_MGC_VAL | (force_rw ? 0 : MS_RDONLY); char * opts = NULL; struct stat buf; int rc; @@ -211,59 +90,20 @@ int my_mount(char *dev, char *location, char *fs, int force_rw) } } - if (!strcmp(fs, "supermount")) { - my_modprobe("supermount", ANY_DRIVER_TYPE, NULL); - my_modprobe("isofs", ANY_DRIVER_TYPE, NULL); - opts = alloca(500); - sprintf(opts, "dev=%s,fs=iso9660,tray_lock=always", dev); - dev = "none"; - } - #ifndef DISABLE_MEDIAS - if (!strcmp(fs, "vfat")) { - my_modprobe("nls_cp437", ANY_DRIVER_TYPE, NULL); - my_modprobe("nls_iso8859_1", ANY_DRIVER_TYPE, NULL); - my_modprobe("vfat", ANY_DRIVER_TYPE, NULL); + if (!strcmp(fs, "nfs")) + opts = "nolock"; + if (!strcmp(fs, "vfat")) opts = "check=relaxed"; - } - - if (!strcmp(fs, "ntfs")) { - my_modprobe("ntfs", ANY_DRIVER_TYPE, NULL); - } - - if (!strcmp(fs, "reiserfs")) - my_modprobe("reiserfs", ANY_DRIVER_TYPE, NULL); - - if (!strcmp(fs, "reiser4")) - my_modprobe("reiser4", ANY_DRIVER_TYPE, NULL); - - if (!strcmp(fs, "jfs")) - my_modprobe("jfs", ANY_DRIVER_TYPE, NULL); - - if (!strcmp(fs, "xfs")) - my_modprobe("xfs", ANY_DRIVER_TYPE, NULL); - - if (!strcmp(fs, "ext4")) - my_modprobe("ext4", ANY_DRIVER_TYPE, NULL); - - if (!strcmp(fs, "btrfs")) - my_modprobe("btrfs", ANY_DRIVER_TYPE, NULL); - #endif - if (!strcmp(fs, "iso9660")) - my_modprobe("isofs", ANY_DRIVER_TYPE, NULL); - -#ifndef DISABLE_NETWORK - if (!strcmp(fs, "nfs")) { - my_modprobe("nfs", ANY_DRIVER_TYPE, NULL); - log_message("preparing nfsmount for %s", dev); - rc = nfsmount_prepare(dev, &opts); - if (rc != 0) - return rc; + char *cmd; + rc = asprintf(&cmd, "mount %s %s -t %s -o %s%s > /dev/null 2>&1", dev, location, fs, (force_rw ? "" : "ro,"), (opts ? opts : "")); + if (rc == -1) { + log_perror("asprint allocation failure"); + rmdir(location); + return rc; } -#endif - - rc = mount(dev, location, fs, flags, opts); + rc = system(cmd); if (rc != 0) { log_perror("mount failed"); rmdir(location); diff --git a/mdk-stage1/mount.h b/mdk-stage1/mount.h index e0d924901..dc8d674c3 100644 --- a/mdk-stage1/mount.h +++ b/mdk-stage1/mount.h @@ -22,10 +22,6 @@ #ifndef _MOUNT_H_ #define _MOUNT_H_ -#ifndef DISABLE_NETWORK -#include "nfsmount.h" -#endif - int my_mount(char *dev, char *location, char *fs, int force_rw); int ensure_dev_exists(const char * dev); diff --git a/mdk-stage1/mount_rpcgen.h b/mdk-stage1/mount_rpcgen.h deleted file mode 100644 index d70ccaf9d..000000000 --- a/mdk-stage1/mount_rpcgen.h +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Please do not edit this file. - * It was generated using rpcgen. - */ - -#ifndef _MOUNT_H_RPCGEN -#define _MOUNT_H_RPCGEN - -#include <rpc/rpc.h> - -#define MNTPATHLEN 1024 -#define MNTNAMLEN 255 -#define FHSIZE 32 - -typedef char fhandle[FHSIZE]; -#ifdef __cplusplus -extern "C" bool_t xdr_fhandle(XDR *, fhandle); -#elif __STDC__ -extern bool_t xdr_fhandle(XDR *, fhandle); -#else /* Old Style C */ -bool_t xdr_fhandle(); -#endif /* Old Style C */ - - -struct fhstatus { - u_int fhs_status; - union { - fhandle fhs_fhandle; - } fhstatus_u; -}; -typedef struct fhstatus fhstatus; -#ifdef __cplusplus -extern "C" bool_t xdr_fhstatus(XDR *, fhstatus*); -#elif __STDC__ -extern bool_t xdr_fhstatus(XDR *, fhstatus*); -#else /* Old Style C */ -bool_t xdr_fhstatus(); -#endif /* Old Style C */ - - -typedef char *dirpath; -#ifdef __cplusplus -extern "C" bool_t xdr_dirpath(XDR *, dirpath*); -#elif __STDC__ -extern bool_t xdr_dirpath(XDR *, dirpath*); -#else /* Old Style C */ -bool_t xdr_dirpath(); -#endif /* Old Style C */ - - -typedef char *name; -#ifdef __cplusplus -extern "C" bool_t xdr_name(XDR *, name*); -#elif __STDC__ -extern bool_t xdr_name(XDR *, name*); -#else /* Old Style C */ -bool_t xdr_name(); -#endif /* Old Style C */ - - -typedef struct mountbody *mountlist; -#ifdef __cplusplus -extern "C" bool_t xdr_mountlist(XDR *, mountlist*); -#elif __STDC__ -extern bool_t xdr_mountlist(XDR *, mountlist*); -#else /* Old Style C */ -bool_t xdr_mountlist(); -#endif /* Old Style C */ - - -struct mountbody { - name ml_hostname; - dirpath ml_directory; - mountlist ml_next; -}; -typedef struct mountbody mountbody; -#ifdef __cplusplus -extern "C" bool_t xdr_mountbody(XDR *, mountbody*); -#elif __STDC__ -extern bool_t xdr_mountbody(XDR *, mountbody*); -#else /* Old Style C */ -bool_t xdr_mountbody(); -#endif /* Old Style C */ - - -typedef struct groupnode *groups; -#ifdef __cplusplus -extern "C" bool_t xdr_groups(XDR *, groups*); -#elif __STDC__ -extern bool_t xdr_groups(XDR *, groups*); -#else /* Old Style C */ -bool_t xdr_groups(); -#endif /* Old Style C */ - - -struct groupnode { - name gr_name; - groups gr_next; -}; -typedef struct groupnode groupnode; -#ifdef __cplusplus -extern "C" bool_t xdr_groupnode(XDR *, groupnode*); -#elif __STDC__ -extern bool_t xdr_groupnode(XDR *, groupnode*); -#else /* Old Style C */ -bool_t xdr_groupnode(); -#endif /* Old Style C */ - - -typedef struct exportnode *exports; -#ifdef __cplusplus -extern "C" bool_t xdr_exports(XDR *, exports*); -#elif __STDC__ -extern bool_t xdr_exports(XDR *, exports*); -#else /* Old Style C */ -bool_t xdr_exports(); -#endif /* Old Style C */ - - -struct exportnode { - dirpath ex_dir; - groups ex_groups; - exports ex_next; -}; -typedef struct exportnode exportnode; -#ifdef __cplusplus -extern "C" bool_t xdr_exportnode(XDR *, exportnode*); -#elif __STDC__ -extern bool_t xdr_exportnode(XDR *, exportnode*); -#else /* Old Style C */ -bool_t xdr_exportnode(); -#endif /* Old Style C */ - - -#define MOUNTPROG ((u_long)100005) -#define MOUNTVERS ((u_long)1) - -#ifdef __cplusplus -#define MOUNTPROC_NULL ((u_long)0) -extern "C" void * mountproc_null_1(void *, CLIENT *); -extern "C" void * mountproc_null_1_svc(void *, struct svc_req *); -#define MOUNTPROC_MNT ((u_long)1) -extern "C" fhstatus * mountproc_mnt_1(dirpath *, CLIENT *); -extern "C" fhstatus * mountproc_mnt_1_svc(dirpath *, struct svc_req *); -#define MOUNTPROC_DUMP ((u_long)2) -extern "C" mountlist * mountproc_dump_1(void *, CLIENT *); -extern "C" mountlist * mountproc_dump_1_svc(void *, struct svc_req *); -#define MOUNTPROC_UMNT ((u_long)3) -extern "C" void * mountproc_umnt_1(dirpath *, CLIENT *); -extern "C" void * mountproc_umnt_1_svc(dirpath *, struct svc_req *); -#define MOUNTPROC_UMNTALL ((u_long)4) -extern "C" void * mountproc_umntall_1(void *, CLIENT *); -extern "C" void * mountproc_umntall_1_svc(void *, struct svc_req *); -#define MOUNTPROC_EXPORT ((u_long)5) -extern "C" exports * mountproc_export_1(void *, CLIENT *); -extern "C" exports * mountproc_export_1_svc(void *, struct svc_req *); -#define MOUNTPROC_EXPORTALL ((u_long)6) -extern "C" exports * mountproc_exportall_1(void *, CLIENT *); -extern "C" exports * mountproc_exportall_1_svc(void *, struct svc_req *); - -#elif __STDC__ -#define MOUNTPROC_NULL ((u_long)0) -extern void * mountproc_null_1(void *, CLIENT *); -extern void * mountproc_null_1_svc(void *, struct svc_req *); -#define MOUNTPROC_MNT ((u_long)1) -extern fhstatus * mountproc_mnt_1(dirpath *, CLIENT *); -extern fhstatus * mountproc_mnt_1_svc(dirpath *, struct svc_req *); -#define MOUNTPROC_DUMP ((u_long)2) -extern mountlist * mountproc_dump_1(void *, CLIENT *); -extern mountlist * mountproc_dump_1_svc(void *, struct svc_req *); -#define MOUNTPROC_UMNT ((u_long)3) -extern void * mountproc_umnt_1(dirpath *, CLIENT *); -extern void * mountproc_umnt_1_svc(dirpath *, struct svc_req *); -#define MOUNTPROC_UMNTALL ((u_long)4) -extern void * mountproc_umntall_1(void *, CLIENT *); -extern void * mountproc_umntall_1_svc(void *, struct svc_req *); -#define MOUNTPROC_EXPORT ((u_long)5) -extern exports * mountproc_export_1(void *, CLIENT *); -extern exports * mountproc_export_1_svc(void *, struct svc_req *); -#define MOUNTPROC_EXPORTALL ((u_long)6) -extern exports * mountproc_exportall_1(void *, CLIENT *); -extern exports * mountproc_exportall_1_svc(void *, struct svc_req *); - -#else /* Old Style C */ -#define MOUNTPROC_NULL ((u_long)0) -extern void * mountproc_null_1(); -extern void * mountproc_null_1_svc(); -#define MOUNTPROC_MNT ((u_long)1) -extern fhstatus * mountproc_mnt_1(); -extern fhstatus * mountproc_mnt_1_svc(); -#define MOUNTPROC_DUMP ((u_long)2) -extern mountlist * mountproc_dump_1(); -extern mountlist * mountproc_dump_1_svc(); -#define MOUNTPROC_UMNT ((u_long)3) -extern void * mountproc_umnt_1(); -extern void * mountproc_umnt_1_svc(); -#define MOUNTPROC_UMNTALL ((u_long)4) -extern void * mountproc_umntall_1(); -extern void * mountproc_umntall_1_svc(); -#define MOUNTPROC_EXPORT ((u_long)5) -extern exports * mountproc_export_1(); -extern exports * mountproc_export_1_svc(); -#define MOUNTPROC_EXPORTALL ((u_long)6) -extern exports * mountproc_exportall_1(); -extern exports * mountproc_exportall_1_svc(); -#endif /* Old Style C */ - -#endif /* !_MOUNT_H_RPCGEN */ diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c index 4d7f1ac6c..ab512399a 100644 --- a/mdk-stage1/network.c +++ b/mdk-stage1/network.c @@ -291,7 +291,7 @@ static int save_netinfo(struct interface_info * intf) fprintf(f, "NETWORKING=yes\n"); fprintf(f, "FORWARD_IPV4=false\n"); - if (hostname && !intf->boot_proto == BOOTPROTO_DHCP) + if (hostname && !(intf->boot_proto == BOOTPROTO_DHCP)) fprintf(f, "HOSTNAME=%s\n", hostname); if (gateway.s_addr != 0) fprintf(f, "GATEWAY=%s\n", inet_ntoa(gateway)); @@ -1108,7 +1108,7 @@ enum return_type ftp_prepare(void) if (use_http_proxy) { add_to_env("METHOD", "http"); - sprintf(location_full, "ftp://%s%s", ftp_hostname, answers[1]); + snprintf(location_full, sizeof(location_full), "ftp://%s%s", ftp_hostname, answers[1]); if (need_arch) strcat(location_full, "/" ARCH); add_to_env("URLPREFIX", location_full); diff --git a/mdk-stage1/nfs_mount4.h b/mdk-stage1/nfs_mount4.h deleted file mode 100644 index 85650773a..000000000 --- a/mdk-stage1/nfs_mount4.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * We want to be able to compile mount on old kernels in such a way - * that the binary will work well on more recent kernels. - * Thus, if necessary we teach nfsmount.c the structure of new fields - * that will come later. - * - * Moreover, the new kernel includes conflict with glibc includes - * so it is easiest to ignore the kernel altogether (at compile time). - */ - -#define NFS_MOUNT_VERSION 4 - -struct nfs2_fh { - char data[32]; -}; -struct nfs3_fh { - unsigned short size; - unsigned char data[64]; -}; - -struct nfs_mount_data { - int version; /* 1 */ - int fd; /* 1 */ - struct nfs2_fh old_root; /* 1 */ - int flags; /* 1 */ - int rsize; /* 1 */ - int wsize; /* 1 */ - int timeo; /* 1 */ - int retrans; /* 1 */ - int acregmin; /* 1 */ - int acregmax; /* 1 */ - int acdirmin; /* 1 */ - int acdirmax; /* 1 */ - struct sockaddr_in addr; /* 1 */ - char hostname[256]; /* 1 */ - int namlen; /* 2 */ - unsigned int bsize; /* 3 */ - struct nfs3_fh root; /* 4 */ -}; - -/* bits in the flags field */ - -#define NFS_MOUNT_SOFT 0x0001 /* 1 */ -#define NFS_MOUNT_INTR 0x0002 /* 1 */ -#define NFS_MOUNT_SECURE 0x0004 /* 1 */ -#define NFS_MOUNT_POSIX 0x0008 /* 1 */ -#define NFS_MOUNT_NOCTO 0x0010 /* 1 */ -#define NFS_MOUNT_NOAC 0x0020 /* 1 */ -#define NFS_MOUNT_TCP 0x0040 /* 2 */ -#define NFS_MOUNT_VER3 0x0080 /* 3 */ -#define NFS_MOUNT_KERBEROS 0x0100 /* 3 */ -#define NFS_MOUNT_NONLM 0x0200 /* 3 */ -#define NFS_MOUNT_BROKEN_SUID 0x0400 /* 4 */ - diff --git a/mdk-stage1/nfsmount.c b/mdk-stage1/nfsmount.c deleted file mode 100644 index 0345098f9..000000000 --- a/mdk-stage1/nfsmount.c +++ /dev/null @@ -1,735 +0,0 @@ - /* - * Guillaume Cottenceau (gc) - * - * Copyright 2003 Mandriva - * - * This software may be freely redistributed under the terms of the GNU - * public license. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * basing on nfsmount.c from util-linux-2.11z: - * - use our logging facilities - * - use our host resolving stuff - * - remove unneeded code - */ - -/* - * nfsmount.c -- Linux NFS mount - * Copyright (C) 1993 Rick Sladkey <jrs@world.std.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Wed Feb 8 12:51:48 1995, biro@yggdrasil.com (Ross Biro): allow all port - * numbers to be specified on the command line. - * - * Fri, 8 Mar 1996 18:01:39, Swen Thuemmler <swen@uni-paderborn.de>: - * Omit the call to connect() for Linux version 1.3.11 or later. - * - * Wed Oct 1 23:55:28 1997: Dick Streefland <dick_streefland@tasking.com> - * Implemented the "bg", "fg" and "retry" mount options for NFS. - * - * 1999-02-22 Arkadiusz Miśkiewicz <misiek@pld.ORG.PL> - * - added Native Language Support - * - * Modified by Olaf Kirch and Trond Myklebust for new NFS code, - * plus NFSv3 stuff. - * - * 2003-04-14 David Black <david.black@xilinx.com> - * - added support for multiple hostname NFS mounts - */ - -/* - * nfsmount.c,v 1.1.1.1 1993/11/18 08:40:51 jrs Exp - */ - -#define HAVE_rpcsvc_nfs_prot_h -#define HAVE_inet_aton - -#include <unistd.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <netdb.h> -#include <time.h> -#include <rpc/rpc.h> -#include <rpc/pmap_prot.h> -#include <rpc/pmap_clnt.h> -#include <sys/socket.h> -#include <sys/time.h> -#include <sys/utsname.h> -#include <sys/stat.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <values.h> - -#include "nfsmount.h" - -#ifdef HAVE_rpcsvc_nfs_prot_h -#include <rpcsvc/nfs_prot.h> -#else -#include <linux/nfs.h> -#define nfsstat nfs_stat -#endif - -#include "nfs_mount4.h" - -#include "log.h" -#include "dns.h" - -#ifndef NFS_PORT -#define NFS_PORT 2049 -#endif -#ifndef NFS_FHSIZE -#define NFS_FHSIZE 32 -#endif - -static char *nfs_strerror(int stat); - -#define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r)) - -#define MAX_NFSPROT ((nfs_mount_version >= 4) ? 3 : 2) - -bool_t -xdr_fhandle3 (XDR *xdrs, fhandle3 *objp) -{ - if (!xdr_bytes (xdrs, (char **)&objp->fhandle3_val, (u_int *) &objp->fhandle3_len, FHSIZE3)) - return FALSE; - return TRUE; -} - -bool_t -xdr_mountstat3 (XDR *xdrs, mountstat3 *objp) -{ - if (!xdr_enum (xdrs, (enum_t *) objp)) - return FALSE; - return TRUE; -} - -bool_t -xdr_mountres3_ok (XDR *xdrs, mountres3_ok *objp) -{ - if (!xdr_fhandle3 (xdrs, &objp->fhandle)) - return FALSE; - if (!xdr_array (xdrs, (char **)&objp->auth_flavours.auth_flavours_val, (u_int *) &objp->auth_flavours.auth_flavours_len, ~0, - sizeof (int), (xdrproc_t) xdr_int)) - return FALSE; - return TRUE; -} - -bool_t -xdr_mountres3 (XDR *xdrs, mountres3 *objp) -{ - if (!xdr_mountstat3 (xdrs, &objp->fhs_status)) - return FALSE; - switch (objp->fhs_status) { - case MNT_OK: - if (!xdr_mountres3_ok (xdrs, &objp->mountres3_u.mountinfo)) - return FALSE; - break; - default: - break; - } - return TRUE; -} - -bool_t -xdr_dirpath (XDR *xdrs, dirpath *objp) -{ - if (!xdr_string (xdrs, objp, MNTPATHLEN)) - return FALSE; - return TRUE; -} - -bool_t -xdr_fhandle (XDR *xdrs, fhandle objp) -{ - if (!xdr_opaque (xdrs, objp, FHSIZE)) - return FALSE; - return TRUE; -} - -bool_t -xdr_fhstatus (XDR *xdrs, fhstatus *objp) -{ - if (!xdr_u_int (xdrs, &objp->fhs_status)) - return FALSE; - switch (objp->fhs_status) { - case 0: - if (!xdr_fhandle (xdrs, objp->fhstatus_u.fhs_fhandle)) - return FALSE; - break; - default: - break; - } - return TRUE; -} - - -static int -linux_version_code(void) { - struct utsname my_utsname; - int p, q, r; - - if (uname(&my_utsname) == 0) { - p = atoi(strtok(my_utsname.release, ".")); - q = atoi(strtok(NULL, ".")); - r = atoi(strtok(NULL, ".")); - return MAKE_VERSION(p,q,r); - } - return 0; -} - -/* - * Unfortunately, the kernel prints annoying console messages - * in case of an unexpected nfs mount version (instead of - * just returning some error). Therefore we'll have to try - * and figure out what version the kernel expects. - * - * Variables: - * NFS_MOUNT_VERSION: these nfsmount sources at compile time - * nfs_mount_version: version this source and running kernel can handle - */ -static int -find_kernel_nfs_mount_version(void) { - static int kernel_version = -1; - int nfs_mount_version = NFS_MOUNT_VERSION; - - if (kernel_version == -1) - kernel_version = linux_version_code(); - - if (kernel_version) { - if (kernel_version < MAKE_VERSION(2,1,32)) - nfs_mount_version = 1; - else if (kernel_version < MAKE_VERSION(2,2,18)) - nfs_mount_version = 3; - else if (kernel_version < MAKE_VERSION(2,3,0)) - nfs_mount_version = 4; /* since 2.2.18pre9 */ - else if (kernel_version < MAKE_VERSION(2,3,99)) - nfs_mount_version = 3; - else - nfs_mount_version = 4; /* since 2.3.99pre4 */ - } - if (nfs_mount_version > NFS_MOUNT_VERSION) - nfs_mount_version = NFS_MOUNT_VERSION; - log_message("nfsmount: kernel_nfs_mount_version: %d", nfs_mount_version); - return nfs_mount_version; -} - -static struct pmap * -get_mountport(struct sockaddr_in *server_addr, - long unsigned prog, - long unsigned version, - long unsigned proto, - long unsigned port, - int nfs_mount_version) -{ - struct pmaplist *pmap; - static struct pmap p = {0, 0, 0, 0}; - - if (version > MAX_NFSPROT) - version = MAX_NFSPROT; - if (!prog) - prog = MOUNTPROG; - p.pm_prog = prog; - p.pm_vers = version; - p.pm_prot = proto; - p.pm_port = port; - - server_addr->sin_port = PMAPPORT; - pmap = pmap_getmaps(server_addr); - - while (pmap) { - if (pmap->pml_map.pm_prog != prog) - goto next; - if (!version && p.pm_vers > pmap->pml_map.pm_vers) - goto next; - if (version > 2 && pmap->pml_map.pm_vers != version) - goto next; - if (version && version <= 2 && pmap->pml_map.pm_vers > 2) - goto next; - if (pmap->pml_map.pm_vers > MAX_NFSPROT || - (proto && p.pm_prot && pmap->pml_map.pm_prot != proto) || - (port && pmap->pml_map.pm_port != port)) - goto next; - memcpy(&p, &pmap->pml_map, sizeof(p)); - next: - pmap = pmap->pml_next; - } - if (!p.pm_vers) - p.pm_vers = MOUNTVERS; - if (!p.pm_prot) - p.pm_prot = IPPROTO_TCP; - return &p; -} - - - -int nfsmount_prepare(const char *spec, char **mount_opts) -{ - char hostdir[1024]; - CLIENT *mclient; - char *hostname, *dirname, *mounthost = NULL; - struct timeval total_timeout; - enum clnt_stat clnt_stat; - static struct nfs_mount_data data; - int nfs_mount_version; - struct sockaddr_in server_addr; - struct sockaddr_in mount_server_addr; - struct pmap *pm_mnt; - int msock, fsock; - struct timeval retry_timeout; - union { - struct fhstatus nfsv2; - struct mountres3 nfsv3; - } status; - char *s; - int port, mountport, proto, soft, intr; - int posix, nocto, noac, broken_suid, nolock; - int tcp; - int mountprog, mountvers, nfsprog, nfsvers; - int retval; - time_t t; - time_t prevt; - - nfs_mount_version = find_kernel_nfs_mount_version(); - - retval = -1; - msock = fsock = -1; - mclient = NULL; - if (strlen(spec) >= sizeof(hostdir)) { - log_message("nfsmount: excessively long host:dir argument"); - goto fail; - } - strcpy(hostdir, spec); - if ((s = strchr(hostdir, ':'))) { - hostname = hostdir; - dirname = s + 1; - *s = '\0'; - } else { - log_message("nfsmount: directory to mount not in host:dir format"); - goto fail; - } - - server_addr.sin_family = AF_INET; -#ifdef HAVE_inet_aton - if (!inet_aton(hostname, &server_addr.sin_addr)) -#endif - { - if (mygethostbyname(hostname, &server_addr.sin_addr)) { - log_message("nfsmount: can't get address for %s", hostname); - goto fail; - } - } - - memcpy (&mount_server_addr, &server_addr, sizeof (mount_server_addr)); - - - - /* Set default options. - * rsize/wsize are set to 8192 to enable nfs install on - * old i586 machines - * timeo is filled in after we know whether it'll be TCP or UDP. */ - memset(&data, 0, sizeof(data)); - data.rsize = 8192; - data.wsize = 8192; - data.retrans = 30; - data.acregmin = 3; - data.acregmax = 60; - data.acdirmin = 30; - data.acdirmax = 60; -#if NFS_MOUNT_VERSION >= 2 - data.namlen = NAME_MAX; -#endif - - soft = 1; - intr = 0; - posix = 0; - nocto = 0; - nolock = 1; - broken_suid = 0; - noac = 0; - tcp = 0; - - mountprog = MOUNTPROG; - mountvers = 0; - port = 0; - mountport = 0; - nfsprog = NFS_PROGRAM; - nfsvers = 0; - - - -retry_mount: - proto = (tcp) ? IPPROTO_TCP : IPPROTO_UDP; - - data.flags = (soft ? NFS_MOUNT_SOFT : 0) - | (intr ? NFS_MOUNT_INTR : 0) - | (posix ? NFS_MOUNT_POSIX : 0) - | (nocto ? NFS_MOUNT_NOCTO : 0) - | (noac ? NFS_MOUNT_NOAC : 0); -#if NFS_MOUNT_VERSION >= 2 - if (nfs_mount_version >= 2) - data.flags |= (tcp ? NFS_MOUNT_TCP : 0); -#endif -#if NFS_MOUNT_VERSION >= 3 - if (nfs_mount_version >= 3) - data.flags |= (nolock ? NFS_MOUNT_NONLM : 0); -#endif -#if NFS_MOUNT_VERSION >= 4 - if (nfs_mount_version >= 4) - data.flags |= (broken_suid ? NFS_MOUNT_BROKEN_SUID : 0); -#endif - if (nfsvers > MAX_NFSPROT) { - log_message("NFSv%d not supported!", nfsvers); - return 0; - } - if (mountvers > MAX_NFSPROT) { - log_message("NFSv%d not supported!", nfsvers); - return 0; - } - if (nfsvers && !mountvers) - mountvers = (nfsvers < 3) ? 1 : nfsvers; - if (nfsvers && nfsvers < mountvers) - mountvers = nfsvers; - - /* Adjust options if none specified */ - if (!data.timeo) - data.timeo = tcp ? 70 : 7; - -#ifdef NFS_MOUNT_DEBUG - log_message("rsize = %d, wsize = %d, timeo = %d, retrans = %d", - data.rsize, data.wsize, data.timeo, data.retrans); - log_message("acreg (min, max) = (%d, %d), acdir (min, max) = (%d, %d)", - data.acregmin, data.acregmax, data.acdirmin, data.acdirmax); - log_message("port = %d, retry = %d, flags = %.8x", - port, retry, data.flags); - log_message("mountprog = %d, mountvers = %d, nfsprog = %d, nfsvers = %d", - mountprog, mountvers, nfsprog, nfsvers); - log_message("soft = %d, intr = %d, posix = %d, nocto = %d, noac = %d", - (data.flags & NFS_MOUNT_SOFT) != 0, - (data.flags & NFS_MOUNT_INTR) != 0, - (data.flags & NFS_MOUNT_POSIX) != 0, - (data.flags & NFS_MOUNT_NOCTO) != 0, - (data.flags & NFS_MOUNT_NOAC) != 0); -#if NFS_MOUNT_VERSION >= 2 - log_message("tcp = %d", - (data.flags & NFS_MOUNT_TCP) != 0); -#endif -#endif - - data.version = nfs_mount_version; - *mount_opts = (char *) &data; - - - /* create mount deamon client */ - /* See if the nfs host = mount host. */ - if (mounthost) { - if (mounthost[0] >= '0' && mounthost[0] <= '9') { - mount_server_addr.sin_family = AF_INET; - mount_server_addr.sin_addr.s_addr = inet_addr(hostname); - } else { - if (mygethostbyname(mounthost, &mount_server_addr.sin_addr)) { - log_message("nfsmount: can't get address for %s", mounthost); - goto fail; - } - } - } - - /* - * The following loop implements the mount retries. On the first - * call, "running_bg" is 0. When the mount times out, and the - * "bg" option is set, the exit status EX_BG will be returned. - * For a backgrounded mount, there will be a second call by the - * child process with "running_bg" set to 1. - * - * The case where the mount point is not present and the "bg" - * option is set, is treated as a timeout. This is done to - * support nested mounts. - * - * The "retry" count specified by the user is the number of - * minutes to retry before giving up. - * - * Only the first error message will be displayed. - */ - retry_timeout.tv_sec = 3; - retry_timeout.tv_usec = 0; - total_timeout.tv_sec = 20; - total_timeout.tv_usec = 0; - prevt = 0; - t = 30; - - - /* be careful not to use too many CPU cycles */ - if (t - prevt < 30) - sleep(30); - - pm_mnt = get_mountport(&mount_server_addr, - mountprog, - mountvers, - proto, - mountport, - nfs_mount_version); - - /* contact the mount daemon via TCP */ - mount_server_addr.sin_port = htons(pm_mnt->pm_port); - msock = RPC_ANYSOCK; - - switch (pm_mnt->pm_prot) { - case IPPROTO_UDP: - mclient = clntudp_create(&mount_server_addr, - pm_mnt->pm_prog, - pm_mnt->pm_vers, - retry_timeout, - &msock); - if (mclient) - break; - mount_server_addr.sin_port = - htons(pm_mnt->pm_port); - msock = RPC_ANYSOCK; - case IPPROTO_TCP: - mclient = clnttcp_create(&mount_server_addr, - pm_mnt->pm_prog, - pm_mnt->pm_vers, - &msock, 0, 0); - break; - default: - mclient = 0; - } - - if (mclient) { - /* try to mount hostname:dirname */ - mclient->cl_auth = authunix_create_default(); - - /* make pointers in xdr_mountres3 NULL so - * that xdr_array allocates memory for us - */ - memset(&status, 0, sizeof(status)); - - log_message("nfsmount: doing client call in nfs version: %ld", pm_mnt->pm_vers); - if (pm_mnt->pm_vers == 3) - clnt_stat = clnt_call(mclient, - MOUNTPROC3_MNT, - (xdrproc_t) xdr_dirpath, - (caddr_t) &dirname, - (xdrproc_t) xdr_mountres3, - (caddr_t) &status, - total_timeout); - else - clnt_stat = clnt_call(mclient, - MOUNTPROC_MNT, - (xdrproc_t) xdr_dirpath, - (caddr_t) &dirname, - (xdrproc_t) xdr_fhstatus, - (caddr_t) &status, - total_timeout); - - if (clnt_stat == RPC_SUCCESS) - goto succeeded; - - if (prevt == 0) - log_message("could not call server: probably protocol or version error"); - auth_destroy(mclient->cl_auth); - clnt_destroy(mclient); - mclient = 0; - close(msock); - } else { - log_message("could not create rpc client: host probably not found or NFS server is down"); - } - prevt = t; - - goto fail; - - succeeded: - nfsvers = (pm_mnt->pm_vers < 2) ? 2 : pm_mnt->pm_vers; - - if (nfsvers == 2) { - if (status.nfsv2.fhs_status != 0) { - log_message("nfsmount: %s:%s failed, reason given by server: %s", - hostname, dirname, nfs_strerror(status.nfsv2.fhs_status)); - goto fail; - } - memcpy(data.root.data, - (char *) status.nfsv2.fhstatus_u.fhs_fhandle, - NFS_FHSIZE); -#if NFS_MOUNT_VERSION >= 4 - data.root.size = NFS_FHSIZE; - memcpy(data.old_root.data, - (char *) status.nfsv2.fhstatus_u.fhs_fhandle, - NFS_FHSIZE); -#endif - } else { -#if NFS_MOUNT_VERSION >= 4 - fhandle3 *fhandle; - if (status.nfsv3.fhs_status != 0) { - log_message("nfsmount: %s:%s failed, reason given by server: %s", - hostname, dirname, nfs_strerror(status.nfsv3.fhs_status)); - goto fail; - } - fhandle = &status.nfsv3.mountres3_u.mountinfo.fhandle; - memset(data.old_root.data, 0, NFS_FHSIZE); - memset(&data.root, 0, sizeof(data.root)); - data.root.size = fhandle->fhandle3_len; - memcpy(data.root.data, - (char *) fhandle->fhandle3_val, - fhandle->fhandle3_len); - - data.flags |= NFS_MOUNT_VER3; -#endif - } - - /* create nfs socket for kernel */ - - if (tcp) { - if (nfs_mount_version < 3) { - log_message("NFS over TCP is not supported."); - goto fail; - } - fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - } else - fsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (fsock < 0) { - log_perror("nfs socket"); - goto fail; - } - if (bindresvport(fsock, 0) < 0) { - log_perror("nfs bindresvport"); - goto fail; - } - if (port == 0) { - server_addr.sin_port = PMAPPORT; - port = pmap_getport(&server_addr, nfsprog, nfsvers, - tcp ? IPPROTO_TCP : IPPROTO_UDP); -#if 1 - /* Here we check to see if user is mounting with the - * tcp option. If so, and if the portmap returns a - * '0' for port (service unavailable), we then notify - * the user, and retry with udp. - */ - if (port == 0 && tcp == 1) { - log_message("NFS server reported TCP not available, retrying with UDP..."); - tcp = 0; - goto retry_mount; - } -#endif - - if (port == 0) - port = NFS_PORT; -#ifdef NFS_MOUNT_DEBUG - else - log_message("used portmapper to find NFS port"); -#endif - } -#ifdef NFS_MOUNT_DEBUG - log_message("using port %d for nfs deamon", port); -#endif - server_addr.sin_port = htons(port); - /* - * connect() the socket for kernels 1.3.10 and below only, - * to avoid problems with multihomed hosts. - * --Swen - */ - if (linux_version_code() <= 66314 - && connect(fsock, (struct sockaddr *) &server_addr, - sizeof (server_addr)) < 0) { - log_perror("nfs connect"); - goto fail; - } - - /* prepare data structure for kernel */ - - data.fd = fsock; - memcpy((char *) &data.addr, (char *) &server_addr, sizeof(data.addr)); - strncpy(data.hostname, hostname, sizeof(data.hostname)); - - /* clean up */ - - auth_destroy(mclient->cl_auth); - clnt_destroy(mclient); - close(msock); - return 0; - - /* abort */ - - fail: - if (msock != -1) { - if (mclient) { - auth_destroy(mclient->cl_auth); - clnt_destroy(mclient); - } - close(msock); - } - if (fsock != -1) - close(fsock); - return retval; -} - -/* - * We need to translate between nfs status return values and - * the local errno values which may not be the same. - * - * Andreas Schwab <schwab@LS5.informatik.uni-dortmund.de>: change errno: - * "after #include <errno.h> the symbol errno is reserved for any use, - * it cannot even be used as a struct tag or field name". - */ - -#ifndef EDQUOT -#define EDQUOT ENOSPC -#endif - -static struct { - enum nfsstat stat; - int errnum; -} nfs_errtbl[] = { - { NFS_OK, 0 }, - { NFSERR_PERM, EPERM }, - { NFSERR_NOENT, ENOENT }, - { NFSERR_IO, EIO }, - { NFSERR_NXIO, ENXIO }, - { NFSERR_ACCES, EACCES }, - { NFSERR_EXIST, EEXIST }, - { NFSERR_NODEV, ENODEV }, - { NFSERR_NOTDIR, ENOTDIR }, - { NFSERR_ISDIR, EISDIR }, -#ifdef NFSERR_INVAL - { NFSERR_INVAL, EINVAL }, /* that Sun forgot */ -#endif - { NFSERR_FBIG, EFBIG }, - { NFSERR_NOSPC, ENOSPC }, - { NFSERR_ROFS, EROFS }, - { NFSERR_NAMETOOLONG, ENAMETOOLONG }, - { NFSERR_NOTEMPTY, ENOTEMPTY }, - { NFSERR_DQUOT, EDQUOT }, - { NFSERR_STALE, ESTALE }, -#ifdef EWFLUSH - { NFSERR_WFLUSH, EWFLUSH }, -#endif - /* Throw in some NFSv3 values for even more fun (HP returns these) */ - { 71, EREMOTE }, - - { -1, EIO } -}; - -static char *nfs_strerror(int stat) -{ - int i; - static char buf[256]; - - for (i = 0; nfs_errtbl[i].stat != (unsigned)-1; i++) { - if (nfs_errtbl[i].stat == (unsigned)stat) - return strerror(nfs_errtbl[i].errnum); - } - sprintf(buf, "unknown nfs status return value: %d", stat); - return buf; -} - diff --git a/mdk-stage1/nfsmount.h b/mdk-stage1/nfsmount.h deleted file mode 100644 index a27e8a8d7..000000000 --- a/mdk-stage1/nfsmount.h +++ /dev/null @@ -1,331 +0,0 @@ -/* - * Please do not edit this file. - * It was generated using rpcgen. - */ - -#ifndef _NFSMOUNT_H_RPCGEN -#define _NFSMOUNT_H_RPCGEN - -#include <rpc/rpc.h> - -int nfsmount_prepare(const char *spec, char **mount_opts); - - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Sun RPC is a product of Sun Microsystems, Inc. and is provided for - * unrestricted use provided that this legend is included on all tape - * media and as a part of the software program in whole or part. Users - * may copy or modify Sun RPC without charge, but are not authorized - * to license or distribute it to anyone else except as part of a product or - * program developed by the user or with the express written consent of - * Sun Microsystems, Inc. - * - * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. - * - * Sun RPC is provided with no support and without any obligation on the - * part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. - * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC - * OR ANY PART THEREOF. - * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. - * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 - */ -/* - * Copyright (c) 1985, 1990 by Sun Microsystems, Inc. - */ - -/* from @(#)mount.x 1.3 91/03/11 TIRPC 1.0 */ -#ifndef _rpcsvc_mount_h -#define _rpcsvc_mount_h -#include <asm/types.h> -#define MNTPATHLEN 1024 -#define MNTNAMLEN 255 -#define FHSIZE 32 -#define FHSIZE3 64 - -typedef char fhandle[FHSIZE]; - -typedef struct { - u_int fhandle3_len; - char *fhandle3_val; -} fhandle3; - -enum mountstat3 { - MNT_OK = 0, - MNT3ERR_PERM = 1, - MNT3ERR_NOENT = 2, - MNT3ERR_IO = 5, - MNT3ERR_ACCES = 13, - MNT3ERR_NOTDIR = 20, - MNT3ERR_INVAL = 22, - MNT3ERR_NAMETOOLONG = 63, - MNT3ERR_NOTSUPP = 10004, - MNT3ERR_SERVERFAULT = 10006, -}; -typedef enum mountstat3 mountstat3; - -struct fhstatus { - u_int fhs_status; - union { - fhandle fhs_fhandle; - } fhstatus_u; -}; -typedef struct fhstatus fhstatus; - -struct mountres3_ok { - fhandle3 fhandle; - struct { - u_int auth_flavours_len; - int *auth_flavours_val; - } auth_flavours; -}; -typedef struct mountres3_ok mountres3_ok; - -struct mountres3 { - mountstat3 fhs_status; - union { - mountres3_ok mountinfo; - } mountres3_u; -}; -typedef struct mountres3 mountres3; - -typedef char *dirpath; - -typedef char *name; - -typedef struct mountbody *mountlist; - -struct mountbody { - name ml_hostname; - dirpath ml_directory; - mountlist ml_next; -}; -typedef struct mountbody mountbody; - -typedef struct groupnode *groups; - -struct groupnode { - name gr_name; - groups gr_next; -}; -typedef struct groupnode groupnode; - -typedef struct exportnode *exports; - -struct exportnode { - dirpath ex_dir; - groups ex_groups; - exports ex_next; -}; -typedef struct exportnode exportnode; - -struct ppathcnf { - int pc_link_max; - short pc_max_canon; - short pc_max_input; - short pc_name_max; - short pc_path_max; - short pc_pipe_buf; - u_char pc_vdisable; - char pc_xxx; - short pc_mask[2]; -}; -typedef struct ppathcnf ppathcnf; -#endif /*!_rpcsvc_mount_h*/ - -#define MOUNTPROG 100005 -#define MOUNTVERS 1 - -#if defined(__STDC__) || defined(__cplusplus) -#define MOUNTPROC_NULL 0 -extern void * mountproc_null_1(void *, CLIENT *); -extern void * mountproc_null_1_svc(void *, struct svc_req *); -#define MOUNTPROC_MNT 1 -extern fhstatus * mountproc_mnt_1(dirpath *, CLIENT *); -extern fhstatus * mountproc_mnt_1_svc(dirpath *, struct svc_req *); -#define MOUNTPROC_DUMP 2 -extern mountlist * mountproc_dump_1(void *, CLIENT *); -extern mountlist * mountproc_dump_1_svc(void *, struct svc_req *); -#define MOUNTPROC_UMNT 3 -extern void * mountproc_umnt_1(dirpath *, CLIENT *); -extern void * mountproc_umnt_1_svc(dirpath *, struct svc_req *); -#define MOUNTPROC_UMNTALL 4 -extern void * mountproc_umntall_1(void *, CLIENT *); -extern void * mountproc_umntall_1_svc(void *, struct svc_req *); -#define MOUNTPROC_EXPORT 5 -extern exports * mountproc_export_1(void *, CLIENT *); -extern exports * mountproc_export_1_svc(void *, struct svc_req *); -#define MOUNTPROC_EXPORTALL 6 -extern exports * mountproc_exportall_1(void *, CLIENT *); -extern exports * mountproc_exportall_1_svc(void *, struct svc_req *); -extern int mountprog_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t); - -#else /* K&R C */ -#define MOUNTPROC_NULL 0 -extern void * mountproc_null_1(); -extern void * mountproc_null_1_svc(); -#define MOUNTPROC_MNT 1 -extern fhstatus * mountproc_mnt_1(); -extern fhstatus * mountproc_mnt_1_svc(); -#define MOUNTPROC_DUMP 2 -extern mountlist * mountproc_dump_1(); -extern mountlist * mountproc_dump_1_svc(); -#define MOUNTPROC_UMNT 3 -extern void * mountproc_umnt_1(); -extern void * mountproc_umnt_1_svc(); -#define MOUNTPROC_UMNTALL 4 -extern void * mountproc_umntall_1(); -extern void * mountproc_umntall_1_svc(); -#define MOUNTPROC_EXPORT 5 -extern exports * mountproc_export_1(); -extern exports * mountproc_export_1_svc(); -#define MOUNTPROC_EXPORTALL 6 -extern exports * mountproc_exportall_1(); -extern exports * mountproc_exportall_1_svc(); -extern int mountprog_1_freeresult (); -#endif /* K&R C */ -#define MOUNTVERS_POSIX 2 - -#if defined(__STDC__) || defined(__cplusplus) -extern void * mountproc_null_2(void *, CLIENT *); -extern void * mountproc_null_2_svc(void *, struct svc_req *); -extern fhstatus * mountproc_mnt_2(dirpath *, CLIENT *); -extern fhstatus * mountproc_mnt_2_svc(dirpath *, struct svc_req *); -extern mountlist * mountproc_dump_2(void *, CLIENT *); -extern mountlist * mountproc_dump_2_svc(void *, struct svc_req *); -extern void * mountproc_umnt_2(dirpath *, CLIENT *); -extern void * mountproc_umnt_2_svc(dirpath *, struct svc_req *); -extern void * mountproc_umntall_2(void *, CLIENT *); -extern void * mountproc_umntall_2_svc(void *, struct svc_req *); -extern exports * mountproc_export_2(void *, CLIENT *); -extern exports * mountproc_export_2_svc(void *, struct svc_req *); -extern exports * mountproc_exportall_2(void *, CLIENT *); -extern exports * mountproc_exportall_2_svc(void *, struct svc_req *); -#define MOUNTPROC_PATHCONF 7 -extern ppathcnf * mountproc_pathconf_2(dirpath *, CLIENT *); -extern ppathcnf * mountproc_pathconf_2_svc(dirpath *, struct svc_req *); -extern int mountprog_2_freeresult (SVCXPRT *, xdrproc_t, caddr_t); - -#else /* K&R C */ -extern void * mountproc_null_2(); -extern void * mountproc_null_2_svc(); -extern fhstatus * mountproc_mnt_2(); -extern fhstatus * mountproc_mnt_2_svc(); -extern mountlist * mountproc_dump_2(); -extern mountlist * mountproc_dump_2_svc(); -extern void * mountproc_umnt_2(); -extern void * mountproc_umnt_2_svc(); -extern void * mountproc_umntall_2(); -extern void * mountproc_umntall_2_svc(); -extern exports * mountproc_export_2(); -extern exports * mountproc_export_2_svc(); -extern exports * mountproc_exportall_2(); -extern exports * mountproc_exportall_2_svc(); -#define MOUNTPROC_PATHCONF 7 -extern ppathcnf * mountproc_pathconf_2(); -extern ppathcnf * mountproc_pathconf_2_svc(); -extern int mountprog_2_freeresult (); -#endif /* K&R C */ -#define MOUNT_V3 3 - -#if defined(__STDC__) || defined(__cplusplus) -#define MOUNTPROC3_NULL 0 -extern void * mountproc3_null_3(void *, CLIENT *); -extern void * mountproc3_null_3_svc(void *, struct svc_req *); -#define MOUNTPROC3_MNT 1 -extern mountres3 * mountproc3_mnt_3(dirpath *, CLIENT *); -extern mountres3 * mountproc3_mnt_3_svc(dirpath *, struct svc_req *); -#define MOUNTPROC3_DUMP 2 -extern mountlist * mountproc3_dump_3(void *, CLIENT *); -extern mountlist * mountproc3_dump_3_svc(void *, struct svc_req *); -#define MOUNTPROC3_UMNT 3 -extern void * mountproc3_umnt_3(dirpath *, CLIENT *); -extern void * mountproc3_umnt_3_svc(dirpath *, struct svc_req *); -#define MOUNTPROC3_UMNTALL 4 -extern void * mountproc3_umntall_3(void *, CLIENT *); -extern void * mountproc3_umntall_3_svc(void *, struct svc_req *); -#define MOUNTPROC3_EXPORT 5 -extern exports * mountproc3_export_3(void *, CLIENT *); -extern exports * mountproc3_export_3_svc(void *, struct svc_req *); -extern int mountprog_3_freeresult (SVCXPRT *, xdrproc_t, caddr_t); - -#else /* K&R C */ -#define MOUNTPROC3_NULL 0 -extern void * mountproc3_null_3(); -extern void * mountproc3_null_3_svc(); -#define MOUNTPROC3_MNT 1 -extern mountres3 * mountproc3_mnt_3(); -extern mountres3 * mountproc3_mnt_3_svc(); -#define MOUNTPROC3_DUMP 2 -extern mountlist * mountproc3_dump_3(); -extern mountlist * mountproc3_dump_3_svc(); -#define MOUNTPROC3_UMNT 3 -extern void * mountproc3_umnt_3(); -extern void * mountproc3_umnt_3_svc(); -#define MOUNTPROC3_UMNTALL 4 -extern void * mountproc3_umntall_3(); -extern void * mountproc3_umntall_3_svc(); -#define MOUNTPROC3_EXPORT 5 -extern exports * mountproc3_export_3(); -extern exports * mountproc3_export_3_svc(); -extern int mountprog_3_freeresult (); -#endif /* K&R C */ - -/* the xdr functions */ - -#if defined(__STDC__) || defined(__cplusplus) -extern bool_t xdr_fhandle (XDR *, fhandle); -extern bool_t xdr_fhandle3 (XDR *, fhandle3*); -extern bool_t xdr_mountstat3 (XDR *, mountstat3*); -extern bool_t xdr_fhstatus (XDR *, fhstatus*); -extern bool_t xdr_mountres3_ok (XDR *, mountres3_ok*); -extern bool_t xdr_mountres3 (XDR *, mountres3*); -extern bool_t xdr_dirpath (XDR *, dirpath*); -extern bool_t xdr_name (XDR *, name*); -extern bool_t xdr_mountlist (XDR *, mountlist*); -extern bool_t xdr_mountbody (XDR *, mountbody*); -extern bool_t xdr_groups (XDR *, groups*); -extern bool_t xdr_groupnode (XDR *, groupnode*); -extern bool_t xdr_exports (XDR *, exports*); -extern bool_t xdr_exportnode (XDR *, exportnode*); -extern bool_t xdr_ppathcnf (XDR *, ppathcnf*); - -#else /* K&R C */ -extern bool_t xdr_fhandle (); -extern bool_t xdr_fhandle3 (); -extern bool_t xdr_mountstat3 (); -extern bool_t xdr_fhstatus (); -extern bool_t xdr_mountres3_ok (); -extern bool_t xdr_mountres3 (); -extern bool_t xdr_dirpath (); -extern bool_t xdr_name (); -extern bool_t xdr_mountlist (); -extern bool_t xdr_mountbody (); -extern bool_t xdr_groups (); -extern bool_t xdr_groupnode (); -extern bool_t xdr_exports (); -extern bool_t xdr_exportnode (); -extern bool_t xdr_ppathcnf (); - -#endif /* K&R C */ - -#ifdef __cplusplus -} -#endif - -#endif /* !_NFSMOUNT_H_RPCGEN */ - diff --git a/mdk-stage1/partition.c b/mdk-stage1/partition.c index 83bfc5ce6..cb59f0514 100644 --- a/mdk-stage1/partition.c +++ b/mdk-stage1/partition.c @@ -74,7 +74,7 @@ static const char * detect_partition_type(char * dev) struct partition_detection_info partitions_signatures[] = { { "Linux Swap", { 4086, "SWAP-SPACE" }, { 0, NULL }, { 0, NULL } }, { "Linux Swap", { 4086, "SWAPSPACE2" }, { 0, NULL }, { 0, NULL } }, - { "Ext2", { 0x438, "\x53\xEF" }, { 0, NULL }, { 0, NULL } }, + { "Ext4", { 0x438, "\x53\xEF" }, { 0, NULL }, { 0, NULL } }, { "ReiserFS", { 0x10034, "ReIsErFs" }, { 0, NULL }, { 0, NULL } }, { "ReiserFS", { 0x10034, "ReIsEr2Fs" }, { 0, NULL }, { 0, NULL } }, { "XFS", { 0, "XFSB" }, { 0x200, "XAGF" }, { 0x400, "XAGI" } }, diff --git a/mdk-stage1/pci-resource/Makefile b/mdk-stage1/pci-resource/Makefile deleted file mode 100644 index c8214ddc1..000000000 --- a/mdk-stage1/pci-resource/Makefile +++ /dev/null @@ -1,25 +0,0 @@ - #****************************************************************************** - # - # $Id: Makefile 253685 2009-03-06 14:27:29Z tv $ - # - # Guillaume Cottenceau (gc) - # - # Copyright 2000 Mandriva - # - # This software may be freely redistributed under the terms of the GNU - # public license. - # - # You should have received a copy of the GNU General Public License - # along with this program; if not, write to the Free Software - # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - # - #***************************************************************************** - - -all: pci-ids.h - -pci-ids.h: /usr/share/ldetect-lst/pcitable.gz update-pci-ids.pl - perl update-pci-ids.pl > $@ || { rm -f $@; exit 1; } - -clean: - rm -f pci-ids.h diff --git a/mdk-stage1/pcmcia-resource/Makefile b/mdk-stage1/pcmcia-resource/Makefile deleted file mode 100644 index b27eb2f0b..000000000 --- a/mdk-stage1/pcmcia-resource/Makefile +++ /dev/null @@ -1,24 +0,0 @@ - #****************************************************************************** - # - # Olivier Blin (blino) - # - # Copyright 2006 Mandriva - # - # This software may be freely redistributed under the terms of the GNU - # public license. - # - # You should have received a copy of the GNU General Public License - # along with this program; if not, write to the Free Software - # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - # - #***************************************************************************** - -TARGET=pcmcia-ids.h - -all: $(TARGET) - -$(TARGET): - perl update-pcmcia-ids.pl > $@ || { rm -f $@; exit 1; } - -clean: - rm -f $(TARGET) diff --git a/mdk-stage1/pcmcia/Makefile b/mdk-stage1/pcmcia/Makefile index 5d077aac8..6b8bf0cb8 100644 --- a/mdk-stage1/pcmcia/Makefile +++ b/mdk-stage1/pcmcia/Makefile @@ -27,7 +27,7 @@ all: $(TARGET) pcmcia_probe.o clean: rm -f *.o $(TARGET) lex_config.c yacc_config.c yacc_config.h -FLAGS = -D__linux__ -Wall -Werror -Wno-deprecated-declarations -Os -fomit-frame-pointer -pipe -c -I.. -D_BSD_SOURCE +FLAGS = -D__linux__ -Wall -Werror -Wno-deprecated-declarations -Os -fomit-frame-pointer -pipe -c -I.. -D_DEFAULT_SOURCE # (blino) make sure yynewerror and yyerrlab are uselessly used FLAGS += -Dlint LFLAGS += --nounput @@ -46,7 +46,7 @@ $(TARGET): $(OBJS) yacc_config.h ranlib $@ $(OBJS): %.o: %.c - $(DIET) gcc $(FLAGS) $(INCLUDES) -c $< -o $@ + gcc $(FLAGS) $(INCLUDES) -c $< -o $@ pcmcia_probe.o: probe.c - $(DIET) gcc -fPIC $(FLAGS) $(INCLUDES) -c $< -o $@ + gcc -fPIC $(FLAGS) $(INCLUDES) -c $< -o $@ diff --git a/mdk-stage1/probing.c b/mdk-stage1/probing.c index 1cdadd591..f956bb348 100644 --- a/mdk-stage1/probing.c +++ b/mdk-stage1/probing.c @@ -40,23 +40,27 @@ #include <fnmatch.h> #include <sys/socket.h> #include <net/if.h> +#include <linux/sockios.h> +#include <linux/ethtool.h> #include <sys/ioctl.h> #include <sys/mount.h> #include <pci/pci.h> #include <libldetect.h> +#include <errno.h> +#include <glob.h> #include "stage1.h" #include "log.h" #include "utils.h" #include "frontend.h" #include "modules.h" -#include "pci-resource/pci-ids.h" +#include "pci-ids.h" #ifdef ENABLE_USB -#include "usb-resource/usb-ids.h" +#include "usb-ids.h" #endif #ifdef ENABLE_PCMCIA #include "sysfs/libsysfs.h" -#include "pcmcia-resource/pcmcia-ids.h" +#include "pcmcia-ids.h" #endif #include "probing.h" @@ -82,54 +86,31 @@ static void warning_insmod_failed(enum insmod_return r) } #ifndef DISABLE_NETWORK -struct net_description_elem -{ - char * intf_name; - char * intf_description; -}; -static struct net_description_elem net_descriptions[50]; -static int net_descr_number = 0; -static char * intf_descr_for_discover = NULL; -static char * net_intf_too_early_name[50]; /* for modules providing more than one net intf */ -static int net_intf_too_early_number = 0; -static int net_intf_too_early_ptr = 0; - const char * safe_descr(const char * text) { return text ? text : "unknown"; } -void prepare_intf_descr(const char * intf_descr) +char * get_net_intf_description(char * intf_name) { - intf_descr_for_discover = strdup(intf_descr); -} + struct ifreq ifr; + struct ethtool_drvinfo drvinfo; + int s = socket(AF_INET, SOCK_DGRAM, 0); + char *res; -void net_discovered_interface(char * intf_name) -{ - if (!intf_descr_for_discover) { - net_intf_too_early_name[net_intf_too_early_number++] = strdup(intf_name); - return; - } - if (!intf_name) { - if (net_intf_too_early_ptr >= net_intf_too_early_number) { - log_message("NET: was expecting another network interface (broken net module?)"); - return; - } - net_descriptions[net_descr_number].intf_name = net_intf_too_early_name[net_intf_too_early_ptr++]; - } - else - net_descriptions[net_descr_number].intf_name = strdup(intf_name); - net_descriptions[net_descr_number].intf_description = strdup(intf_descr_for_discover); - intf_descr_for_discover = NULL; - net_descr_number++; -} + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, intf_name, IFNAMSIZ); -char * get_net_intf_description(char * intf_name) -{ - int i; - for (i = 0; i < net_descr_number ; i++) - if (!strcmp(net_descriptions[i].intf_name, intf_name)) - return net_descriptions[i].intf_description; - return strdup("unknown"); + drvinfo.cmd = ETHTOOL_GDRVINFO; + ifr.ifr_data = (caddr_t) &drvinfo; + + if (ioctl(s, SIOCETHTOOL, &ifr) != -1) { + res = drvinfo.driver; + } else { + perror("SIOCETHTOOL"); + res = "unknown"; + } + close(s); + return strdup(res); } #endif @@ -283,13 +264,11 @@ void discovered_device(enum driver_type type, const char * description, const ch #endif #ifndef DISABLE_NETWORK if (type == NETWORK_DEVICES) { + log_message("NET: Loading driver for network device %s", description); wait_message("Loading driver for network device:\n \n%s", description); - prepare_intf_descr(description); failed = my_modprobe(driver, NETWORK_DEVICES, NULL); warning_insmod_failed(failed); remove_wait_message(); - if (intf_descr_for_discover) /* for modules providing more than one net intf */ - net_discovered_interface(NULL); } #endif #ifdef ENABLE_USB @@ -483,7 +462,7 @@ void probe_that_type(enum driver_type type, enum media_bus bus __attribute__ ((u for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { struct sysfs_attribute *modalias_attr; - char keyfile[256]; + char keyfile[300]; int i, id; if (dent->d_name[0] == '.') @@ -560,13 +539,38 @@ void probe_that_type(enum driver_type type, enum media_bus bus __attribute__ ((u static struct media_info * medias = NULL; +// Read a short string from a file and strips it, intended for sysfs attributes +static ssize_t read_attribute(char *path, char *buf) { + ssize_t l = 0; + int fd = open(path, O_RDONLY); + buf[0] = '\0'; + if (fd == -1) { + log_message("Failed to open %s for reading", path); + } else { + ssize_t n = read(fd, buf, 32); + if (n == -1) { + log_message("Couldn't read file (%s)", path); + } else { + // Strip whitespaces and newline + for (int i = n-1; i >= 0; i--) { + if (buf[i] == '\n' || buf[i] == ' ') + continue; + l = i+1; + break; + } + buf[l] = '\0'; + } + close(fd); + } + log_message("Content of %s was %s", path, buf); + return l; +} + void find_media(enum media_bus bus) { - char b[50]; char buf[5000]; struct media_info tmp[50]; int count = 0; - int fd; if (medias) free(medias); /* that does not free the strings, by the way */ @@ -575,265 +579,6 @@ void find_media(enum media_bus bus) probe_that_type(MEDIA_ADAPTERS, bus); /* ----------------------------------------------- */ - if (bus != BUS_IDE && bus != BUS_ANY) - goto find_media_after_ide; - log_message("looking for ide media"); - - strcpy(b, "/proc/ide/hd"); - for (b[12] = 'a'; b[12] <= 't'; b[12]++) { - int i; - char ide_disk[] = "disk"; - char ide_cdrom[] = "cdrom"; - char ide_tape[] = "tape"; - char ide_floppy[] = "floppy"; - - /* first, test if file exists (will tell if attached medium exists) */ - b[13] = '\0'; - if (access(b, R_OK)) - continue; - - tmp[count].name = strdup("hda"); - tmp[count].name[2] = b[12]; - - /* media type */ - strcpy(b + 13, "/media"); - fd = open(b, O_RDONLY); - if (fd == -1) { - log_message("failed to open %s for reading", b); - continue; - } - - i = read(fd, buf, sizeof(buf)); - if (i == -1) { - log_message("failed to read %s", b); - continue; - } - buf[i] = '\0'; - close(fd); - - if (ptr_begins_static_str(buf, ide_disk)) - tmp[count].type = DISK; - else if (ptr_begins_static_str(buf, ide_cdrom)) - tmp[count].type = CDROM; - else if (ptr_begins_static_str(buf, ide_tape)) - tmp[count].type = TAPE; - else if (ptr_begins_static_str(buf, ide_floppy)) - tmp[count].type = FLOPPY; - else - tmp[count].type = UNKNOWN_MEDIA; - - /* media model */ - strcpy(b + 13, "/model"); - fd = open(b, O_RDONLY); - if (fd == -1) { - log_message("failed to open %s for reading", b); - continue; - } - - i = read(fd, buf, sizeof(buf)); - if (i <= 0) { - log_message("failed to read %s", b); - tmp[count].model = strdup("(none)"); - } - else { - buf[i-1] = '\0'; /* eat the \n */ - tmp[count].model = strdup(buf); - } - close(fd); - - log_message("IDE/%d: %s is a %s", tmp[count].type, tmp[count].name, tmp[count].model); - count++; - } - - find_media_after_ide: - /* ----------------------------------------------- */ - if (bus != BUS_SCSI && bus != BUS_USB && bus != BUS_PCMCIA && bus != BUS_ANY) - goto find_media_after_scsi; - log_message("looking for scsi media"); - - fd = open("/proc/scsi/scsi", O_RDONLY); - if (fd != -1) { - FILE * f; - - enum { SCSI_TOP, SCSI_HOST, SCSI_VENDOR, SCSI_TYPE } state = SCSI_TOP; - char * start, * chptr, * next, * end; - char scsi_disk_count = 'a'; - char scsi_cdrom_count = '0'; - char scsi_tape_count = '0'; - - char scsi_no_devices[] = "Attached devices: none"; - char scsi_some_devices[] = "Attached devices:"; - char scsi_host[] = "Host: "; - char scsi_vendor[] = " Vendor: "; - - int i = read(fd, &buf, sizeof(buf)-1); - if (i < 1) { - close(fd); - goto end_scsi; - } - close(fd); - buf[i] = '\0'; - - if (ptr_begins_static_str(buf, scsi_no_devices)) - goto end_scsi; - - start = buf; - while (*start) { - char tmp_model[50]; - char tmp_name[10]; - - chptr = start; - while (*chptr != '\n') chptr++; - *chptr = '\0'; - next = chptr + 1; - - switch (state) { - case SCSI_TOP: - if (!ptr_begins_static_str(start, scsi_some_devices)) - goto end_scsi; - state = SCSI_HOST; - break; - - case SCSI_HOST: - if (!ptr_begins_static_str(start, scsi_host)) - goto end_scsi; - state = SCSI_VENDOR; - break; - - case SCSI_VENDOR: - if (!ptr_begins_static_str(start, scsi_vendor)) - goto end_scsi; - - /* (1) Grab Vendor info */ - start += 10; - end = chptr = strstr(start, "Model:"); - if (!chptr) - goto end_scsi; - - chptr--; - while (*chptr == ' ') - chptr--; - if (*chptr == ':') { - chptr++; - *(chptr + 1) = '\0'; - strcpy(tmp_model,"(unknown)"); - } else { - *(chptr + 1) = '\0'; - strcpy(tmp_model, start); - } - - /* (2) Grab Model info */ - start = end; - start += 7; - - chptr = strstr(start, "Rev:"); - if (!chptr) - goto end_scsi; - - chptr--; - while (*chptr == ' ') chptr--; - *(chptr + 1) = '\0'; - - strcat(tmp_model, " "); - strcat(tmp_model, start); - - tmp[count].model = strdup(tmp_model); - - state = SCSI_TYPE; - - break; - - case SCSI_TYPE: - if (strncmp(" Type:", start, 7)) - goto end_scsi; - *tmp_name = '\0'; - - if (strstr(start, "Direct-Access")) { - sprintf(tmp_name, "sd%c", scsi_disk_count++); - tmp[count].type = DISK; - } else if (strstr(start, "Sequential-Access")) { - sprintf(tmp_name, "st%c", scsi_tape_count++); - tmp[count].type = TAPE; - } else if (strstr(start, "CD-ROM")) { - sprintf(tmp_name, "sr%c", scsi_cdrom_count++); - tmp[count].type = CDROM; - } - - if (!(f = fopen("/proc/partitions", "rb")) || !fgets(buf, sizeof(buf), f) || !fgets(buf, sizeof(buf), f)) { - log_message("Couldn't open /proc/partitions"); - } else { - while (fgets(buf, sizeof(buf), f)) { - char name[100]; - int major, minor, blocks; - struct stat statbuf; - char *ptr; - memset(name, 0, sizeof(name)); - strcpy(name, "/dev/"); - sscanf(buf, " %d %d %d %s", &major, &minor, &blocks, &name[5]); - if (streq(&name[5], tmp_name) && tmp[count].type == DISK && ((blocks == 1048575) || (blocks == 1440))) - tmp[count].type = FLOPPY; - /* Try to create all devices while we have major/minor */ - if ((ptr = strchr(&name[5], '/'))) { - *ptr = '\0'; - if (stat(name, &statbuf)) - mkdir(name, 0755); - *ptr = '/'; - } - if (stat(name, &statbuf) && mknod(name, S_IFBLK | 0600, makedev(major, minor))) { - log_perror(name); - } - } - fclose(f); - } - - if (*tmp_name) { - tmp[count].name = strdup(tmp_name); - log_message("SCSI/%d: %s is a %s", tmp[count].type, tmp[count].name, tmp[count].model); - count++; - } - - state = SCSI_HOST; - } - - start = next; - } - - end_scsi:; - } - - /* ----------------------------------------------- */ - log_message("looking for Compaq Smart Array media"); - { - char * procfiles[] = { "/proc/driver/cpqarray/ida0", "/proc/driver/cciss/cciss0", // 2.4 style - "/proc/array/ida", "/proc/cciss/cciss", // 2.2 style - NULL }; - static char cpq_descr[] = "Compaq RAID logical disk"; - char ** procfile; - FILE * f; - - for (procfile = procfiles; procfile && *procfile; procfile++) { - if((f = fopen(*procfile, "rb"))) { - while (fgets(buf, sizeof(buf), f)) { - if (ptr_begins_static_str(buf, "ida/") || ptr_begins_static_str(buf, "cciss/")) { - char * end = strchr(buf, ':'); - if (!end) - log_message("Inconsistency in %s, line:\n%s", *procfile, buf); - else { - *end = '\0'; - tmp[count].name = strdup(buf); - tmp[count].type = DISK; - tmp[count].model = cpq_descr; - log_message("CPQ: found %s", tmp[count].name); - count++; - } - } - } - fclose(f); - } - } - } - - /* ----------------------------------------------- */ log_message("looking for DAC960"); { FILE * f; @@ -864,41 +609,95 @@ void find_media(enum media_bus bus) } } /* ----------------------------------------------- */ - log_message("looking for VirtIO"); + log_message("looking for other disks"); { - int fd, i; - char b[50]; - char *name = b+11; - strcpy(b, "/sys/block/vd"); - for (b[13] = 'a'; b[13] <= 'c'; b[13]++) { - /* first, test if file exists (will tell if attached medium exists) */ - b[14] = '\0'; - if (access(b, R_OK)) + glob_t globbuf; + // TODO: We should switch everything to here, and later switch to ignoring + // some types of disks (ram, loop, ...) rather than a list to accept. + glob("/sys/block/nvme*", 0, NULL, &globbuf); + glob("/sys/block/vd*", GLOB_APPEND, NULL, &globbuf); + glob("/sys/block/cciss*", GLOB_APPEND, NULL, &globbuf); + glob("/sys/block/fd*", GLOB_APPEND, NULL, &globbuf); + glob("/sys/block/sd*", GLOB_APPEND, NULL, &globbuf); + glob("/sys/block/st*", GLOB_APPEND, NULL, &globbuf); + glob("/sys/block/sr*", GLOB_APPEND, NULL, &globbuf); + + for (int i = 0; i < globbuf.gl_pathc; i++) { + char *name, *pathend; + char path[64]; + char model[64]; + int vendor_length = 0; + + strncpy(path, globbuf.gl_pathv[i], sizeof(path)); + name = strdup(path + 11); + + // Replace ! with /, for example for cciss!c0d0 devices + char * c = name; + while((c = strchr(c, '!')) != NULL) { + *c = '/'; + c++; + } + + pathend = path + strlen(path); + + // Check if this device had been handled by other code + int exists = 0; + for (int j = 0; j < count; j++) { + if (!strcmp(name, tmp[j].name)) { + exists = 1; + break; + } + } + if (exists) { + free(name); continue; + } + + strcpy(model, "Unknown Disk"); - tmp[count].name = strdup(name); - tmp[count].type = DISK; //UNKNOWN_MEDIA; - tmp[count].model = strdup("VirtIO disk"); + strcpy(pathend, "/device/vendor"); + vendor_length = read_attribute(path, model); - /* media type */ - strcpy(b + 14, "/capability"); - fd = open(b, O_RDONLY); - if (fd == -1) { - log_message("failed to open %s for reading", b); - //continue; + if (vendor_length) { + strcat(model, " "); + vendor_length++; } - i = read(fd, buf, sizeof(buf)); - if (i == -1) { - log_message("Couldn't read capabilities file (%s)", b); - } else { - if (!strcmp(buf, "10")) - tmp[count].type = DISK; + + strcpy(pathend, "/device/model"); + read_attribute(path, model+vendor_length); + + strcpy(pathend, "/capability"); + read_attribute(path, buf); + long caps = strtol(buf, NULL, 16); + + // GENHD_FL_UP (0x0010): indicated that the block device is “up” but the kernel has removed that info + if (caps && 0) { + log_message("Ignoring device %s (not up)", name); + free(name); + continue; + } + + if (caps & 0x0400) { + log_message("Ignoring device %s (hidden)", name); + free(name); + continue; + } + + tmp[count].type = DISK; + if (caps & 0x0008 || !strncmp(name, "sr", 2)) { + tmp[count].type = CDROM; + } else if (!strncmp(name, "fd", 2)) { + tmp[count].type = FLOPPY; + } else if (!strncmp(name, "st", 2)) { + tmp[count].type = TAPE; } + tmp[count].name = name; + tmp[count].model = strdup(model); count++; } + globfree(&globbuf); } - find_media_after_scsi: /* ----------------------------------------------- */ tmp[count].name = NULL; diff --git a/mdk-stage1/probing.h b/mdk-stage1/probing.h index 63c44a4cb..702c9d056 100644 --- a/mdk-stage1/probing.h +++ b/mdk-stage1/probing.h @@ -37,9 +37,7 @@ enum media_bus { BUS_IDE, BUS_SCSI, BUS_USB, BUS_PCMCIA, BUS_ANY }; void find_media(enum media_bus bus); void get_medias(enum media_type media, char *** names, char *** models, enum media_bus bus); char ** get_net_devices(void); -void net_discovered_interface(char * intf_name); char * get_net_intf_description(char * intf_name); -void prepare_intf_descr(const char * intf_descr); void probe_that_type(enum driver_type type, enum media_bus bus); /* Make sure the MATCH_ALL value is greater than all possible values diff --git a/mdk-stage1/rescue-gui.c b/mdk-stage1/rescue-gui.c index 7d5b0a423..c7aae6126 100644 --- a/mdk-stage1/rescue-gui.c +++ b/mdk-stage1/rescue-gui.c @@ -47,9 +47,9 @@ static inline long reboot(void) char * env[] = { "PATH=/usr/bin:/bin:/sbin:/usr/sbin:/mnt/sbin:/mnt/usr/sbin:/mnt/bin:/mnt/usr/bin", - "LD_LIBRARY_PATH=/lib:/usr/lib:/mnt/lib:/mnt/usr/lib:/usr/X11R6/lib:/mnt/usr/X11R6/lib" -#if defined(__x86_64__) || defined(__ppc64__) - ":/lib64:/usr/lib64:/usr/X11R6/lib64:/mnt/lib64:/mnt/usr/lib64:/mnt/usr/X11R6/lib64" + "LD_LIBRARY_PATH=/lib:/usr/lib:/mnt/lib:/mnt/usr/lib" +#if defined(__x86_64__) + ":/lib64:/usr/lib64:/mnt/lib64:/mnt/usr/lib64" #endif , "HOME=/", @@ -153,7 +153,7 @@ void unmount_filesystems(void) for (i = nb = 0; i < numfs; i++) if (fs[i].mounted) { printf("\t%s umount failed\n", fs[i].name); - if (strcmp(fs[i].fs, "ext2") == 0) nb++; /* don't count not-ext2 umount failed */ + if (strcmp(fs[i].fs, "ext4") == 0) nb++; /* don't count not-ext4 umount failed */ } if (nb) { diff --git a/mdk-stage1/stage1.c b/mdk-stage1/stage1.c index 4bed00057..94bb1e0df 100644 --- a/mdk-stage1/stage1.c +++ b/mdk-stage1/stage1.c @@ -121,7 +121,7 @@ static pid_t shell_pid = 0; static void spawn_shell(void) { int fd; - char * shell_name[] = { "/sbin/sh", NULL }; + char * shell_name[] = { "/bin/sh", NULL }; log_message("spawning a shell"); @@ -344,39 +344,8 @@ static void method_select_and_prepare(void) } #endif -static enum return_type create_initial_fs_symlinks(char* symlinks) -{ - FILE *f; - char buf[5000]; - - if (scall(!(f = fopen(symlinks, "rb")), "fopen")) - return RETURN_ERROR; - while (fgets(buf, sizeof(buf), f)) { - char oldpath[500], newpath[500]; - buf[strlen(buf)-1] = '\0'; // trim \n - if (sscanf(buf, "%s %s", oldpath, newpath) != 2) { - sprintf(oldpath, "%s%s", STAGE2_LOCATION, buf); - sprintf(newpath, "%s", buf); - } - recursiveRemove_if_it_exists(newpath); - log_message("creating symlink %s -> %s", oldpath, newpath); - if (scall(symlink(oldpath, newpath), "symlink")) - return RETURN_ERROR; - } - fclose(f); - return RETURN_OK; -} - void finish_preparing(void) { - recursiveRemove("/init"); - - if (create_initial_fs_symlinks(STAGE2_LOCATION "/usr/share/symlinks") != RETURN_OK) - stg1_fatal_message("Fatal error finishing initialization."); - - /* /tmp/syslog is used by the second init, so it must be copied now, not in stage2 */ - /* we remove it to ensure the old one is not copied over it in stage2 */ - #ifdef SPAWN_SHELL if (shell_pid != 0) { int fd; @@ -468,7 +437,7 @@ int main(int argc __attribute__ ((unused)), char **argv __attribute__ ((unused)) if (IS_RESCUE) return 66; /* ask init to exec new init */ - else - return 0x35; /* ask init to run stage2 binary */ + + return 0; #endif } diff --git a/mdk-stage1/thirdparty.c b/mdk-stage1/thirdparty.c index 38200357c..78bbf485a 100644 --- a/mdk-stage1/thirdparty.c +++ b/mdk-stage1/thirdparty.c @@ -244,7 +244,7 @@ static void thirdparty_load_pcitable(const char *modules_location) char pcitable_filename[100]; FILE * f = NULL; - sprintf(pcitable_filename, "%s/pcitable", modules_location); + snprintf(pcitable_filename, sizeof(pcitable_filename), "%s/pcitable", modules_location); if (!(f = fopen(pcitable_filename, "rb"))) { log_message("third_party: no external pcitable found"); return; diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c index aca40c971..2e27688ea 100644 --- a/mdk-stage1/tools.c +++ b/mdk-stage1/tools.c @@ -148,65 +148,6 @@ enum return_type copy_file(char * from, char * to, void (*callback_func)(int ove } } -enum return_type recursiveRemove(char *file) -{ - struct stat sb; - - if (lstat(file, &sb) != 0) { - log_message("failed to stat %s: %d", file, errno); - return RETURN_ERROR; - } - - /* only descend into subdirectories if device is same as dir */ - if (S_ISDIR(sb.st_mode)) { - char * strBuf = alloca(strlen(file) + 1024); - DIR * dir; - struct dirent * d; - - if (!(dir = opendir(file))) { - log_message("error opening %s: %d", file, errno); - return RETURN_ERROR; - } - while ((d = readdir(dir))) { - if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) - continue; - - strcpy(strBuf, file); - strcat(strBuf, "/"); - strcat(strBuf, d->d_name); - - if (recursiveRemove(strBuf) != 0) { - closedir(dir); - return RETURN_ERROR; - } - } - closedir(dir); - - if (rmdir(file)) { - log_message("failed to rmdir %s: %d", file, errno); - return RETURN_ERROR; - } - } else { - if (unlink(file) != 0) { - log_message("failed to remove %s: %d", file, errno); - return RETURN_ERROR; - } - } - return RETURN_OK; -} - -enum return_type recursiveRemove_if_it_exists(char *file) -{ - struct stat sb; - - if (lstat(file, &sb) != 0) { - /* if file doesn't exist, simply return OK */ - return RETURN_OK; - } - - return recursiveRemove(file); -} - enum return_type mount_compressed_image(char *compressed_image, char *location_mount) { if (lomount(compressed_image, location_mount, NULL, 1)) { @@ -267,21 +208,12 @@ enum return_type load_compressed_fd(int fd, int size) return preload_mount_compressed_fd(fd, size, COMPRESSED_NAME(""), STAGE2_LOCATION); } -// FIXME: guess right module from partition type (using libblkid?) int try_mount(char * dev, char * location) { char device_fullname[50]; snprintf(device_fullname, sizeof(device_fullname), "/dev/%s", dev); - if (my_mount(device_fullname, location, "ext4", 0) == -1 && - my_mount(device_fullname, location, "btrfs", 0) == -1 && - my_mount(device_fullname, location, "vfat", 0) == -1 && - my_mount(device_fullname, location, "ntfs", 0) == -1 && - my_mount(device_fullname, location, "reiserfs", 0) == -1 && - my_mount(device_fullname, location, "reiser4", 0) == -1 && - my_mount(device_fullname, location, "jfs", 0) == -1 && - my_mount(device_fullname, location, "xfs", 0) == -1 && - my_mount(device_fullname, location, "iso9660", 0) == -1) { + if (my_mount(device_fullname, location, "auto", 0) == -1) { return 1; } diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h index 1b08e42ca..87c0c1d49 100644 --- a/mdk-stage1/tools.h +++ b/mdk-stage1/tools.h @@ -29,8 +29,6 @@ int image_has_stage2(); enum return_type create_IMAGE_LOCATION(char *location_full); int ramdisk_possible(void); enum return_type copy_file(char * from, char * to, void (*callback_func)(int overall)); -enum return_type recursiveRemove(char *file); -enum return_type recursiveRemove_if_it_exists(char *file); enum return_type preload_mount_compressed_fd(int compressed_fd, int image_size, char *image_name, char *location_mount); enum return_type mount_compressed_image(char *compressed_image, char *location_mount); enum return_type mount_compressed_image_may_preload(char *image_name, char *location_mount, int preload); diff --git a/mdk-stage1/pci-resource/update-pci-ids.pl b/mdk-stage1/update-pci-ids.pl index 84191a9d6..1b084ea80 100755 --- a/mdk-stage1/pci-resource/update-pci-ids.pl +++ b/mdk-stage1/update-pci-ids.pl @@ -12,7 +12,7 @@ my %t = ( ); foreach my $type (keys %t) { - my @modules = chomp_(`perl ../../kernel/modules.pl pci_modules4stage1 "$t{$type}"`) + my @modules = chomp_(`perl ../kernel/modules.pl pci_modules4stage1 "$t{$type}"`) or die "unable to get PCI modules"; print "#ifndef DISABLE_".uc($type)." diff --git a/mdk-stage1/pcmcia-resource/update-pcmcia-ids.pl b/mdk-stage1/update-pcmcia-ids.pl index 67e0ca9a7..9eb25c66e 100755 --- a/mdk-stage1/pcmcia-resource/update-pcmcia-ids.pl +++ b/mdk-stage1/update-pcmcia-ids.pl @@ -25,7 +25,7 @@ my %t = ( ); foreach my $type (keys %t) { - my @modules = chomp_(`perl ../../kernel/modules.pl pci_modules4stage1 "$t{$type}"`) + my @modules = chomp_(`perl ../kernel/modules.pl pci_modules4stage1 "$t{$type}"`) or die "unable to get PCMCIA modules"; print "#ifndef DISABLE_".uc($type)." diff --git a/mdk-stage1/usb-resource/update-usb-ids.pl b/mdk-stage1/update-usb-ids.pl index 9d6ca1cfc..1ea45f9df 100755 --- a/mdk-stage1/usb-resource/update-usb-ids.pl +++ b/mdk-stage1/update-usb-ids.pl @@ -4,7 +4,7 @@ use lib '../kernel'; use strict; use MDK::Common; -my @modules = chomp_(`perl ../../kernel/modules.pl pci_modules4stage1 "bus/usb"`) +my @modules = chomp_(`perl ../kernel/modules.pl pci_modules4stage1 "bus/usb"`) or die "unable to get USB controller modules"; print "char *usb_controller_modules[] = { "; @@ -13,7 +13,7 @@ print "}; unsigned int usb_controller_modules_len = sizeof(usb_controller_modules) / sizeof(char *); "; -@modules = chomp_(`perl ../../kernel/modules.pl pci_modules4stage1 "network/usb disk/usb"`) +@modules = chomp_(`perl ../kernel/modules.pl pci_modules4stage1 "network/usb disk/usb"`) or die "unable to get USB modules"; print "char *usb_modules[] = { diff --git a/mdk-stage1/url.c b/mdk-stage1/url.c index 3d2846649..14f1e25d6 100644 --- a/mdk-stage1/url.c +++ b/mdk-stage1/url.c @@ -398,9 +398,10 @@ char *str_ftp_error(int error) } -static int _http_download_file(char * hostname, char * remotename, int * size, char * proxyprotocol, char * proxyname, char * proxyport, int recursion) +static int _http_download_file(char * hostport, char * remotename, int * size, char * proxyprotocol, char * proxyname, char * proxyport, int recursion) { char * buf; + char * hostname = strdup(hostport); char headers[4096]; char * nextChar = headers; int statusCode; @@ -418,8 +419,15 @@ static int _http_download_file(char * hostname, char * remotename, int * size, c http_server_name = proxyname; http_server_port = atoi(proxyport); } else { - http_server_name = hostname; - http_server_port = 80; + char *port = strchr(hostname, ':'); + if (port) { + *port = '\0'; + http_server_name = hostname; + http_server_port = atoi(++port); + } else { + http_server_name = hostname; + http_server_port = 80; + } } log_message("HTTP: connecting to server %s:%i (%s)", @@ -430,6 +438,7 @@ static int _http_download_file(char * hostname, char * remotename, int * size, c sock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); if (sock < 0) { + free(hostname); return FTPERR_FAILED_CONNECT; } @@ -439,6 +448,7 @@ static int _http_download_file(char * hostname, char * remotename, int * size, c if (connect(sock, (struct sockaddr *) &destPort, sizeof(destPort))) { close(sock); + free(hostname); return FTPERR_FAILED_CONNECT; } @@ -446,6 +456,7 @@ static int _http_download_file(char * hostname, char * remotename, int * size, c : asprintf_("GET %s HTTP/1.0\r\nHost: %s\r\n\r\n", remotename, hostname); write(sock, buf, strlen(buf)); + free(hostname); /* This is fun; read the response a character at a time until we: diff --git a/mdk-stage1/usb-resource/Makefile b/mdk-stage1/usb-resource/Makefile deleted file mode 100644 index e21832a3f..000000000 --- a/mdk-stage1/usb-resource/Makefile +++ /dev/null @@ -1,25 +0,0 @@ - #****************************************************************************** - # - # $Id: Makefile 253685 2009-03-06 14:27:29Z tv $ - # - # Guillaume Cottenceau (gc) - # - # Copyright 2000 Mandriva - # - # This software may be freely redistributed under the terms of the GNU - # public license. - # - # You should have received a copy of the GNU General Public License - # along with this program; if not, write to the Free Software - # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - # - #***************************************************************************** - - -all: usb-ids.h - -usb-ids.h: /usr/share/ldetect-lst/usbtable.gz update-usb-ids.pl - perl update-usb-ids.pl > $@ || rm -f $@ - -clean: - rm -f usb-ids.h diff --git a/mdk-stage1/utils.c b/mdk-stage1/utils.c index af5ee9af3..6ad3a8f6f 100644 --- a/mdk-stage1/utils.c +++ b/mdk-stage1/utils.c @@ -21,6 +21,7 @@ #include <unistd.h> #include <ctype.h> #include <dirent.h> +#include <sys/sysinfo.h> #include <sys/utsname.h> #include "utils.h" @@ -83,9 +84,12 @@ int line_counts(const char * buf) { int total_memory(void) { int value; - - /* drakx powered: use /proc/kcore and rounds every 4 Mbytes */ - value = 4 * ((int)((float)file_size("/proc/kcore") / 1024 / 1024 / 4 + 0.5)); + struct sysinfo sys_info; + if (sysinfo(&sys_info) < 0) { + log_perror("sysinfo"); + return 0; + } + value = sys_info.totalram * sys_info.mem_unit / 1024 / 1024; log_message("Total Memory: %d Mbytes", value); return value; @@ -162,14 +166,6 @@ char * asprintf_(const char *msg, ...) return strdup(""); } -int scall_(int retval, char * msg, char * file, int line) -{ - char tmp[5000]; - sprintf(tmp, "%s(%s:%d) failed", msg, file, line); - if (retval) - log_perror(tmp); - return retval; -} void lowercase(char *s) { diff --git a/mdk-stage1/utils.h b/mdk-stage1/utils.h index d42c52d06..b8a77b0ad 100644 --- a/mdk-stage1/utils.h +++ b/mdk-stage1/utils.h @@ -27,9 +27,7 @@ void add_to_env(char * name, char * value); char ** list_directory(char * direct); int string_array_length(char ** a); char * asprintf_(const char *msg, ...); -int scall_(int retval, char * msg, char * file, int line); char *my_dirname(char *path); -#define scall(retval, msg) scall_(retval, msg, __FILE__, __LINE__) void lowercase(char *s); #define ptr_begins_static_str(pointer,static_str) (!strncmp(pointer,static_str,sizeof(static_str)-1)) diff --git a/mdk-stage1/wireless.c b/mdk-stage1/wireless.c index c9e363048..2fde04f84 100644 --- a/mdk-stage1/wireless.c +++ b/mdk-stage1/wireless.c @@ -1,7 +1,9 @@ /* * Olivier Blin (oblin) + * Martin Whitaker (martinw) * * Copyright 2005 Mandriva + * Copyright 2020 Mageia * * This software may be freely redistributed under the terms of the GNU * public license. @@ -16,7 +18,9 @@ #include <sys/types.h> #include <sys/socket.h> #include <errno.h> +#include <signal.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <unistd.h> #include <linux/types.h> @@ -29,11 +33,10 @@ #include "utils.h" #include "wireless.h" -static int wireless_ioctl(int socket, const char *ifname, int request, struct iwreq *wrq); -static int wireless_set_mode_managed(int socket, const char *ifname); -static int wireless_disable_key(int socket, const char *ifname); -static int wireless_set_restricted_key(int socket, const char *ifname, const char *key); -static int wireless_set_essid(int socket, const char *ifname, const char *essid); +#define WPA_SUPPLICANT_CONF "/etc/wpa_supplicant.conf" +#define WPA_SUPPLICANT_CTRL "/var/run/wpa_supplicant" +#define WPA_SUPPLICANT_LOG "/var/log/wpa_supplicant.log" +#define WPA_SUPPLICANT_PID "/var/run/wpa_supplicant.pid" int wireless_open_socket() { @@ -57,104 +60,101 @@ int wireless_is_aware(int socket, const char *ifname) return wireless_ioctl(socket, ifname, SIOCGIWNAME, &wrq) == 0; } -static int wireless_set_mode_managed(int socket, const char *ifname) -{ - struct iwreq wrq; - - wrq.u.mode = IW_MODE_INFRA; /* managed */ - - return wireless_ioctl(socket, ifname, SIOCSIWMODE, &wrq) == 0; -} - -static int wireless_set_essid(int socket, const char *ifname, const char *essid) -{ - struct iwreq wrq; - - wrq.u.essid.flags = 1; - wrq.u.essid.pointer = (void *) essid; - wrq.u.essid.length = strlen(essid) + 1; - - return wireless_ioctl(socket, ifname, SIOCSIWESSID, &wrq) == 0; -} - -static int wireless_disable_key(int socket, const char *ifname) -{ - struct iwreq wrq; - - wrq.u.data.flags = IW_ENCODE_DISABLED; - wrq.u.data.pointer = NULL; - wrq.u.data.length = 0; - - return wireless_ioctl(socket, ifname, SIOCSIWENCODE, &wrq) == 0; -} - -static int wireless_set_restricted_key(int socket, const char *ifname, const char *key) -{ - struct iwreq wrq; - char real_key[IW_ENCODING_TOKEN_MAX]; - int key_len = 0; - unsigned int tmp; - - while (sscanf(key + 2*key_len, "%2X", &tmp) == 1) - real_key[key_len++] = (char) tmp; - - wrq.u.data.flags = IW_ENCODE_RESTRICTED; - wrq.u.data.pointer = (char *) real_key; - wrq.u.data.length = key_len; - - return wireless_ioctl(socket, ifname, SIOCSIWENCODE, &wrq) == 0; -} - enum return_type configure_wireless(const char *ifname) { enum return_type results; - char * questions[] = { "ESSID", "WEP key", NULL }; - char * questions_auto[] = { "essid", "wep_key" }; + char * security[] = { "No security", "WEP", "WPA/WPA2 Personal", NULL }; + char * security_auto[] = { "none", "wep", "wpa_psk", NULL }; + char * choice = NULL; + char * message = NULL; + char * questions[] = { "ESSID", "", NULL }; + char * questions_auto[] = { "essid", "" }; + char * key_mgmt = NULL; static char ** answers = NULL; - int wsock = wireless_open_socket(); + FILE * fd; + char cmd[256]; + int status; + int wsock = wireless_open_socket(); if (!wireless_is_aware(wsock, ifname)) { log_message("interface %s doesn't support wireless", ifname); wireless_close_socket(wsock); return RETURN_OK; } + wireless_close_socket(wsock); - results = ask_from_entries_auto("Please enter your wireless settings. " - "The ESSID is your wireless network identifier. " - "The WEP key must be entered in hexadecimal, without any separator.", - questions, &answers, 32, questions_auto, NULL); + results = ask_from_list_auto("Please select your wireless security mode.", + security, &choice, "wireless_security", security_auto); if (results != RETURN_OK) { - wireless_close_socket(wsock); return RETURN_BACK; } - if (!wireless_set_mode_managed(wsock, ifname)) { - stg1_error_message("unable to set mode Managed on device \"%s\": %s", ifname, strerror(errno)); - wireless_close_socket(wsock); - return RETURN_ERROR; + if (streq(choice, security[2])) { + message = "Please enter your wireless settings. " + "The ESSID is your wireless network identifier. " + "The passphrase must be a string of between 8 and 63 ASCII characters."; + questions[1] = "passphrase"; + questions_auto[1] = "wpa_psk"; + key_mgmt = "WPA-PSK"; + } else if (streq(choice, security[1])) { + message = "Please enter your wireless settings. " + "The ESSID is your wireless network identifier. " + "The WEP key must be either a string of 10 or 26 hexadecimal digits, without any separators, " + "or a string of 5 or 13 ASCII characters enclosed in double quote marks (e.g. \"12345\")."; + questions[1] = "WEP key"; + questions_auto[1] = "wep_key"; + key_mgmt = "NONE"; + } else { + message = "Please enter your wireless settings. " + "The ESSID is your wireless network identifier."; + questions[1] = NULL; + questions_auto[1] = NULL; + key_mgmt = "NONE"; + } + results = ask_from_entries_auto(message, questions, &answers, 32, questions_auto, NULL); + if (results != RETURN_OK) { + return RETURN_BACK; } - if (answers[1] && !streq(answers[1], "")) { - log_message("setting WEP key \"%s\" on device \"%s\"", answers[1], ifname); - if (!wireless_set_restricted_key(wsock, ifname, answers[1])) { - stg1_error_message("unable to set WEP key \"%s\" on device \"%s\": %s", answers[1], ifname, strerror(errno)); - return RETURN_ERROR; - } - } else { - log_message("disabling WEP key on device \"%s\"", ifname); - if (!wireless_disable_key(wsock, ifname)) { - stg1_error_message("unable to disable WEP key on device \"%s\": %s", ifname, strerror(errno)); - return RETURN_ERROR; + fd = fopen(WPA_SUPPLICANT_PID, "r"); + if (fd) { + unsigned pid = 0; + unsigned count = fscanf(fd, "%u", &pid); + fclose(fd); + if (count == 1 && pid > 1) { + log_message("terminating wpa_supplicant (pid %u)", pid); + kill(pid, SIGQUIT); + sleep(1); } } - /* most devices perform discovery when ESSID is set, it needs to be last */ - log_message("setting ESSID \"%s\" on device \"%s\"", answers[0], ifname); - if (!wireless_set_essid(wsock, ifname, answers[0])) { - stg1_error_message("unable to set ESSID \"%s\" on device \"%s\": %s", answers[0], ifname, strerror(errno)); + fd = fopen(WPA_SUPPLICANT_CONF, "w"); + if (fd == NULL) { + stg1_error_message("unable to create " WPA_SUPPLICANT_CONF ": %s", strerror(errno)); + return RETURN_ERROR; + } + fprintf(fd, "ctrl_interface=" WPA_SUPPLICANT_CTRL "\n"); + fprintf(fd, "ap_scan=1\n"); + fprintf(fd, "network={\n"); + fprintf(fd, " key_mgmt=%s\n", key_mgmt); + fprintf(fd, " scan_ssid=1\n"); + fprintf(fd, " ssid=\"%s\"\n", answers[0]); + if (streq(choice, security[2])) { + fprintf(fd, " psk=\"%s\"\n", answers[1]); + } else if (streq(choice, security[1])) { + fprintf(fd, " wep_key0=%s\n", answers[1]); + } + fprintf(fd, "}\n"); + fclose(fd); + + snprintf(cmd, sizeof(cmd), "/usr/sbin/wpa_supplicant -D nl80211,wext -B -i %s -c %s -f %s -P %s", + ifname, WPA_SUPPLICANT_CONF, WPA_SUPPLICANT_LOG, WPA_SUPPLICANT_PID); + log_message("running %s", cmd); + status = system(cmd); + if (status != 0) { + stg1_error_message("unable to start wpa_supplicant daemon for interface \"%s\": %d", ifname, status); return RETURN_ERROR; } - wireless_close_socket(wsock); return RETURN_OK; } |
