aboutsummaryrefslogtreecommitdiff
path: root/win32/mingw.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
* win32(symlink): fix logic to determine the type of the symlinkJohannes Schindelin2021-03-011-1/+10
| | | | | | | | | | | | | | | | | | | | On Windows, there are file symlinks and directory symlinks. When trying to `opendir()` a symlink marked as `file`, it will fail. Even if the target is a directory. Because it's the wrong symlink type. To address this, our `symlink()` function calls `stat(target, ...)` to see whether the target exists and is a directory. The problem is that this `target` can be a relative path, and the link path can _also_ be a relative path. Example: `symlink("dir", "uh/oh")`. In this example, the target might say `dir`, but it is relative to `uh/oh`, i.e. we need to `stat("uh/dir", ...)`. This is necessary to pass the `cp` tests because they first create such a directory symlink and then try to copy it while dereferencing symlinks, i.e. calling `opendir()` on the symlink. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
* win32: move is_absolute_path()Ron Yorston2021-03-011-0/+9
| | | | | Make is_absolute_path() a function rather than a macro and move it from ash.c into mingw.c.
* win32: workaround for lazy loading issue on Windows 7Ron Yorston2021-03-011-0/+14
| | | | | | | | Investigating why free(1) wasn't working on Windows 7 I found it's possible for LoadLibraryEx to fail with exactly the flags we're using. Work around this. This probably also explains GitHub issue #204.
* win32: update sysinfo(2) implementation (again)Ron Yorston2021-02-231-14/+31
| | | | | | | | | | Use another API call: EnumPageFiles(). This seems to provide more reliable information about page file usage than the previous ad hoc method. It also allows the call to GlobalMemoryStatusEx() to be removed. With these changes free(1) works sensibly on Windows XP, though not ReactOS.
* win32: update sysinfo(2) implementationRon Yorston2021-02-191-13/+23
| | | | | | | | | | Add a call to GetPerformanceInfo. Treat the SystemCache member of the PERFORMANCE_INFORMATION structure as buffer RAM. Deduct it from available RAM. The numbers reported by 'free' move about in vaguely sensible ways when I start and stop programs, though I still don't know if they're in any way accurate.
* win32: add uptime to sysinfo(2), enable uptime appletRon Yorston2021-02-191-3/+2
| | | | | | | | | | Fill the uptime member of the sysinfo structure. With this change we can: - use sysinfo(2) in the 'ps' applet; - enable the 'uptime' applet (though without useful support for load averages).
* free: implement sysinfo(2) and enable free(1)Ron Yorston2021-02-181-0/+24
| | | | | | | | | | | | | This is an experimental implementation of sysinfo(2)/free(1). It uses the WIN32 API GlobalMemoryStatusEx() to obtain information about memory. It seems that the 'total pagefile' value includes total RAM as well as pagefile and 'available pagefile' includes available RAM. So the RAM values are deducted. I've no idea what corresponds to Linux buffers and cache.
* win32: code shrinkRon Yorston2021-02-131-1/+1
| | | | | | | | Rewrite the recent change to tab completion so it only needs one call to sprintf. Then replace sprintf with strcpy/stpcpy, both there and in a couple of other places. Saves 40 bytes.
* win32: implement symlink(2)Ron Yorston2021-02-121-0/+35
| | | | | | | | | | | | | | | | | | | | | Provide an implementation of symlink(2). Calls to symlink(2) will fail in default Windows installations unless running with elevated privileges. Failure to create a symlink when extracting files from an archive is therefore treated as a non-fatal error. There are two ways to permit the creation of symlinks: - Edit security policy to give users the 'Create symbolic links' privilege. Unfortunately this doesn't work for users who are an Administrator. - Enable developer mode, which is available in later versions of Windows 10. The ability to create symlinks is not available in Windows XP or ReactOS.
* win32: allow symlinks to directories to be unlinkedRon Yorston2021-02-121-1/+13
| | | | | | Windows distinguishes between symlinks to directories and files. A symlink to a directory must be deleted by calling rmdir(2) rather than unlink(2).
* win32: make readlink(2) implementation unconditionalRon Yorston2021-02-121-4/+0
| | | | | | | There doesn't seem to be much advantage in having readlink(2) as a configuration option. Making it unconditional reduces divergence from upstream and allows the removal of a check for ENOSYS that's been in busybox-w32 since the start.
* tls: avoid unnecessary changes to POSIX build, part 2Ron Yorston2021-01-251-0/+9
| | | | | | | | | | | | | | On reflection, the previous commit may have been ill-advised. There are many calls to open_read_close() and most shouldn't be able to access special devices. (Though in practice only a few are enabled in busybox-w32.) Nonetheless, I've implemented a new mechanism which uses the macro MINGW_SPECIAL() to mark calls to functions that are allowed to access special devices. An unrelated change is to avoid compiling fputs_stdout() in coreutils/printf.c for the POSIX build.
* win32: make realpath() return an error if necessaryRon Yorston2020-12-121-1/+0
| | | | | | | | | | | | resolve_symlinks() uses GetFinalPathNameByHandleA which is loaded at runtime because it isn't available in all versions of Windows. If GetFinalPathNameByHandleA isn't available resolve_symlinks() (and hence realpath()) should return a NULL pointer to indicate an error, not the original path. Not returning NULL causes an infinite loop in do_lstat(). See GitHub issue #204.
* win32: make location of Unix-style absolute paths configurableRon Yorston2020-08-311-1/+1
| | | | | | | | | | | | | | | | | Previously busybox-w32 was enhanced so certain Unix-style absolute paths of the form '/dir/file' were treated as being relative to the system drive. (Notionally as reported by %SYSTEMDRIVE% but in fact derived from the API call GetSystemDirectory().) Make the location of such files configurable by the BB_SYSTEMROOT environment variable. - BB_SYSTEMROOT should probably only refer to a Windows-style absolute path, but this isn't checked. - Set BB_SYSTEMROOT using the Windows Control Panel or setx, not as a shell variable: the shell itself won't see the environment variable.
* ash, ls: improve support for 'c:path'Ron Yorston2020-08-281-15/+0
| | | | | | | | | | Revert commit 249f68e3c (win32: append '/' to bare drive name in opendir). Instead add better handling for paths of the form 'c:path' to ls and expmeta() in ash. Adds 64 bytes.
* win32: code shrink Unix-style path handlingRon Yorston2020-08-231-23/+7
| | | | | | | | Replace auto_add_system_drive() with alloc_system_drive() which leaves space for a possible filename extension. This makes it possible to drop alloc_win32_extension() and auto_win32_extension(). Saves 144 bytes.
* win32: use built-in applets for non-existent binaries with Unix-style pathsRon Yorston2020-08-131-0/+13
| | | | | | | | | | | | | | | | | | | | Shell scripts moved from Unix may contain hard-coded paths to binaries such as /bin/sh. A recent commit made it possible to execute such binaries reliably, but that does require them to be installed. As an alternative solution: if a binary with a standard Unix path prefix can't be found but is available as a built-in applet, run the applet. Add the function unix_path() to detect paths starting with /bin, /usr/bin, /sbin or /usr/sbin. Use this function in: - the 'which' applet - shellexec(), describe_command() and find_command() in ash - mingw_spawn_1() See GitHub issue #195.
* win32: handle Unix-style absolute paths for executablesRon Yorston2020-08-131-0/+15
| | | | | | | | | | | | | | | | | | | | | | As noted in commit 548ec7045 (win32: interpret absolute paths as relative to %SYSTEMDRIVE%) a path starting with a '/' in the Unix world is treated as relative to the current drive by Windows. To avoid ambiguity that commit considered certain such paths to be relative to %SYSTEMDRIVE%. Extend this to paths representing executables. Add the functions need_system_drive() and auto_add_system_drive() to detect the need for a system drive prefix and to add it if necessary. Use these functions in: - the 'which' applet - the find_executable() function - tab-completion code - PATH look-up, shellexec(), describe_command() and find_command() in ash - parse_interpreter() and mingw_spawn_1() With these changes executable paths starting with a slash are handled consistently, whatever the current drive.
* win32: use a static buffer in get_system_drive()Ron Yorston2020-08-131-14/+13
| | | | | | | Allocate static storage for the system drive string instead of making a new allocation on every call. This is easier to manage. Adds 16 bytes.
* win32: code shrinkRon Yorston2020-08-131-0/+8
| | | | | | | | | | Add a new function, has_path(), to detect that an executable name doesn't require a path look-up. Also, since is_absolute_path() is now only used in shell/ash.c move its definition there from include/mingw.h. Saves 128 bytes.
* win32: return raw file attributes in struct mingw_statRon Yorston2020-07-091-0/+4
| | | | | | Until now the emulated stat(2) system calls have only returned a synthesised Unix-style mode value. Also return the raw Windows file attributes.
* ash: improve handling of UNC pathsRon Yorston2020-06-301-1/+2
| | | | | | | | | | | | | | Be more strict about identifying UNC paths in unc_root_len(). In updatepwd() in ash: - Skip duplicate leading slashes unless the directory is a UNC path. - Rewrite detection and handling of the five possible types of path. This improves cases like 'cd ///' and 'cd /xyz' when the current directory is a UNC path. See GitHub issue #192.
* win32: enable globbing by defaultRon Yorston2020-06-141-1/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change how busybox.exe expands wildcards on the command line. When globbing is enabled at compile time provide an implementation of _setargv(), which is run early during startup of C programs. This: - enables globbing by setting _dowildcard to -1 - checks for the presence of the environment BB_GLOBBING - if it exists and is set to 0 disables globbing - if it doesn't exist sets BB_GLOBBING=0 but continues to apply Windows' globbing in the current process The consequences of this are: - When busybox.exe is initially run from a Command Prompt Windows' globbing is applied; - Windows' globbing is turned off for future child processes, thus allowing the shell re-execute busybox.exe without it interfering with wildcards; - this behaviour can be overridden by setting BB_GLOBBING explicitly. Globbing can still be disabled at compile time if required. In that case BB_GLOBBING has no effect. With these changes globbing can be enabled by default and BusyBox will do the right thing in most circumstances. (See GitHub issues #172 and #189.)
* win32: use lazy loading for certain DLLsRon Yorston2020-06-021-6/+21
| | | | | | | | | Only a handful of functions are used from shell32.dll, userenv.dll and psapi.dll. Mostly these functions are in out of the way places. By loading the functions only when required we can avoid the startup cost of linking the three DLLs in the common case that they aren't needed.
* dd: fix handling of 'conv=notrunc seek=N'Ron Yorston2020-05-201-3/+3
| | | | | | | | | | | | | | | | | | Commit e6680912a (dd: create a sparse file when seek=N is used) broke the use of 'conv=notrunc seek=N' to modify existing files. Rename seek_sparse() to make_sparse() and: - add an argument to specify the start of the sparse region; - call make_sparse() before ftruncate(); - call make_sparse() only if: * we can determine the size of the file; * the file is not open in append mode; * the file is being extended. This should fix GitHub issue #186.
* dd: create a sparse file when seek=N is usedRon Yorston2020-03-241-0/+17
| | | | | | | When the seek=N argument is used mark the file as sparse and set the range that is sparse. See https://stackoverflow.com/questions/4011508/how-to-create-a-sparse-file-on-ntfs
* win32: stat(2): return correct st_blocks for compressed/sparse filesRon Yorston2020-03-241-1/+13
| | | | | | Use GetCompressedFileSize to obtain the actual number of blocks for compressed or sparse files. Use this to return a more accurate value for st_blocks.
* win32: tidy up detection of device filesRon Yorston2020-02-161-9/+3
| | | | | | | Define NOT_DEVICE as -1 so the return value of index_in_strings() when no device name is matched is NOT_DEVICE. Make the logic in mingw_open() clearer.
* win32: rework device file detectionRon Yorston2020-02-151-6/+4
| | | | | | Improve get_dev_type() and use it to dectect /dev/null in mingw_xopen(). Saves 64 bytes.
* win32: code shrinkRon Yorston2020-02-131-11/+9
| | | | | Have bs_to_slash() return a pointer to its argument. This allows some calls to be chained, saving 32 bytes.
* date: code shrinkRon Yorston2020-02-111-6/+0
| | | | | | | Since we don't have a working clock_settime(2) there's no point in claiming to support the '-s' option. Saves 96 bytes
* mingw: fix off-by-one error in mingw_strftime()Ron Yorston2020-01-191-1/+1
| | | | | | | | | | | | When a format specification is replaced the loop variable 't' should point to the last character of the replacement string in the new format buffer. In an extreme case if the original format string is "%z" and tm->tm_isdst is negative to indicate that no DST information is available the replacement string will be empty and 't' will point to the location before the start of the new format buffer. This is OK.
* mingw: fix use after free in file_owner()Ron Yorston2020-01-191-9/+6
| | | | | The security descriptor was being freed before its contents were accessed.
* Build fixesFRP-3329-gcf0fa4d13Ron Yorston2020-01-081-1/+1
| | | | | | - Update configuration files - Omit unnecessary libraries - Replace fake stime(2) with fake clock_settime(2)
* win32: allow nanosecond precision in file timesRon Yorston2019-08-161-12/+29
| | | | | | Modern Linux kernels use struct timespec to represent file times, thus allowing nanosecond precision. Update the WIN32 emulation of struct stat and stat(2) to do the same.
* win32: try to make working directory names consistentRon Yorston2019-04-021-1/+26
| | | | | | | | | | | | | | | Standardise the path names used for the current working directory by: - resolving with realpath(3); - making the drive name or host name uppercase. The first only really works for physical drives; results for mapped drives are patchy. The standardisation is applied in two places: - at the end of updatepwd() in ash; - when a symbolic link is resolved in mingw_chdir().
* win32: track current directory of mapped drivesRon Yorston2019-04-011-4/+7
| | | | | | | | | | | Drives mapped to a network share or path didn't have their current directory tracked when using path names of the form 'c:path'. This was because commit 585d17d26 used realpath(3) to canonicalise paths in chdir(2). Use readlink(2) instead so that mapped drives aren't canonicalised but symlinks are resolved. See GitHub issue #147.
* win32: improved support for c:path path namesRon Yorston2019-03-301-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | Microsoft Windows permits path names of the form 'c:path', without a path separator after the colon. The system records a current directory for each drive and the path is interpreted relative to that. Since Windows API calls understand 'c:path' path names many commands in busybox-w32 already work with them. This commit adds the following: - The 'cd' shell built-in interprets 'c:path' path names correctly. Previously it treated them as relative to the shell's concept of the current working directory, not the current directory of the specified drive. - The 'pwd' shell built-in takes the '-a' option to list the current directory for all drives. - 'c:path' path names are subject to tab-completion. Paths of the form 'c:path' don't work for mapped network drives or paths that have been associated with a drive using SUBST. See GitHub issue #147.
* win32: interpret absolute paths as relative to %SYSTEMDRIVE%Ron Yorston2019-03-281-0/+56
| | | | | | | | | | | | | | | | | | | | | | BusyBox contains hardcoded references to absolute paths which are unique in the *nix world but on Microsoft Windows are interpreted as being on the current drive. To make these unique again consider them to be relative to %SYSTEMDRIVE%. Support this by adding functions to: - determine the system drive (not using the environment variable); - change a process's current directory to the root of the system drive; - make relative paths absolute before changing directory (if needed). The following applications have been modified: - ash references /etc/profile from the system drive; - dpkg places its data store on and installs files to the system drive; - rpm installs files to the system drive; - man looks for configuration files and man pages on the system drive. See GitHub issue #158.
* win32: share code to find root prefix of pathRon Yorston2019-03-231-0/+35
| | | | | | | Move unc_root_len() from ash to mingw32.c and use it in the new function root_len(), which can be used in make_directory(). This reduces changes to upstream code and saves a few bytes.
* win32: change stat(2) error code in certain casesRon Yorston2019-03-201-1/+0
| | | | | | | | | | | | | | | Commit 325fee1f9 (win32: change handling of trailing slashes in stat(2)) caused stat(2) to return EINVAL in some cases when ENOENT might have been more appropriate. This caused the command: rm -f dir/* to report an error when the directory was empty, contrary to its expected behaviour of saying nothing. Fixes GitHub issue #155.
* win32: add function to convert slashes to backslashesRon Yorston2019-03-151-5/+14
| | | | | | | | | There are now two places where slashes are converted to backslashes throughout a string so it makes sense to create a function to do this. To avoid confusion rename convert_slashes() to bs_to_slash() and call the new function slash_to_bs().
* win32: realpath(3): remove trailing slashRon Yorston2019-03-141-1/+4
| | | | | | | | | If the path is that of a drive mapped to a network share _fullpath() leaves the trailing slash on the drive name and it remains present after the call to resolve_symlinks(). Remove a trailing slash from the resolved path unless it's preceded by a colon.
* win32: consolidate file metadata optionsRon Yorston2019-03-121-8/+2
| | | | Merge FEATURE_IDENTIFY_OWNER into FEATURE_EXTRA_FILE_DATA.
* win32: changes to user idsRon Yorston2019-03-101-20/+30
| | | | | | | | | | | | | | | | Formalise the use of 0 as the uid of a process running with elevated privileges: - Rewrite getuid(2) to return DEFAULT_UID by default and 0 if the process has elevated privileges. - geteuid(2) and the corresponding functions for groups are aliases for getuid(2). - Change root's home directory to be whatever GetSystemDirectory() returns, probably C:/Windows/System32 in most cases. - Remove the special handling of geteuid(2) in the line editing code. With these changes the shell started by 'su' is a lot more like a *nix root shell.
* win32: add a function to detect running with elevated privilegesRon Yorston2019-03-091-0/+18
| | | | | Add is_admin() and use it to alter the command prompt in the line editor when running with admin privileges.
* win32: extend normalisation of paths in realpath(3)Ron Yorston2019-03-081-2/+20
| | | | | | | | | | | The code to normalise paths in resolve_symlinks(), which is used by realpath(3), was incomplete and unable to handle UNC paths. Make an ASCII version of normalize_ntpath() to extend the cases covered. This fixes a regression introduced by commit 585d17d26 (win32: canonicalize path in chdir(2)): it wasn't possible to change to a directory with a UNC path.
* win32: canonicalize path in chdir(2)Ron Yorston2019-03-061-0/+13
| | | | | | | | | | | | Provide an implementation of chdir(2) which canonicalizes the path to resolve symlinks. Otherwise changing to a symlinked directory confuses 'ls -l' because it thinks '.' is a link rather than a directory. OTOH, using 'cd' in the shell to change to a symlinked directory now results in a mismatch between the shell's idea of where we are and what's displayed in the prompt. But upstream BusyBox does that too so it must be OK.
* win32: implement readlink(2)Ron Yorston2019-03-061-0/+65
| | | | | | | | | | Provide an implementation of readlink(2) based on code from Git for Windows. This version only supports symbolic links, not mount points, as the latter seem to work well enough as-is. With this change the ls and stat applets can display the targets of symbolic links. The readlink applet has been enabled in the default configuration.
* win32: let realpath(3) succeed on WinXP/ReactOSRon Yorston2019-03-061-8/+14
| | | | | | Allow realpath(3) to return successfully on platforms that don't support GetFinalPathNameByHandleA(). It may still have done some useful work.