diff options
Diffstat (limited to 'lib/libspl/os/linux')
-rw-r--r-- | lib/libspl/os/linux/getexecname.c | 33 | ||||
-rw-r--r-- | lib/libspl/os/linux/gethostid.c | 84 | ||||
-rw-r--r-- | lib/libspl/os/linux/getmntany.c | 188 | ||||
-rw-r--r-- | lib/libspl/os/linux/zone.c | 63 |
4 files changed, 0 insertions, 368 deletions
diff --git a/lib/libspl/os/linux/getexecname.c b/lib/libspl/os/linux/getexecname.c deleted file mode 100644 index dc4fe26ca550..000000000000 --- a/lib/libspl/os/linux/getexecname.c +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-License-Identifier: CDDL-1.0 -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or https://opensource.org/licenses/CDDL-1.0. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -#include <limits.h> -#include <stdint.h> -#include <unistd.h> -#include "../../libspl_impl.h" - -__attribute__((visibility("hidden"))) ssize_t -getexecname_impl(char *execname) -{ - return (readlink("/proc/self/exe", execname, PATH_MAX)); -} diff --git a/lib/libspl/os/linux/gethostid.c b/lib/libspl/os/linux/gethostid.c deleted file mode 100644 index d39f3dda3b8d..000000000000 --- a/lib/libspl/os/linux/gethostid.c +++ /dev/null @@ -1,84 +0,0 @@ -// SPDX-License-Identifier: CDDL-1.0 -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or https://opensource.org/licenses/CDDL-1.0. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright (c) 2017, Lawrence Livermore National Security, LLC. - */ - -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/systeminfo.h> - -static unsigned long -get_spl_hostid(void) -{ - FILE *f; - unsigned long hostid; - char *env; - - /* - * Allow the hostid to be subverted for testing. - */ - env = getenv("ZFS_HOSTID"); - if (env) - return (strtoull(env, NULL, 0)); - - f = fopen("/proc/sys/kernel/spl/hostid", "re"); - if (!f) - return (0); - - if (fscanf(f, "%lx", &hostid) != 1) - hostid = 0; - - fclose(f); - - return (hostid); -} - -unsigned long -get_system_hostid(void) -{ - unsigned long hostid = get_spl_hostid(); - uint32_t system_hostid; - - /* - * We do not use gethostid(3) because it can return a bogus ID, - * depending on the libc and /etc/hostid presence, - * and the kernel and userspace must agree. - * See comments above hostid_read() in the SPL. - */ - if (hostid == 0) { - int fd = open("/etc/hostid", O_RDONLY | O_CLOEXEC); - if (fd >= 0) { - if (read(fd, &system_hostid, sizeof (system_hostid)) - != sizeof (system_hostid)) - hostid = 0; - else - hostid = system_hostid; - (void) close(fd); - } - } - - return (hostid & HOSTID_MASK); -} diff --git a/lib/libspl/os/linux/getmntany.c b/lib/libspl/os/linux/getmntany.c deleted file mode 100644 index ee1cdf59b9e5..000000000000 --- a/lib/libspl/os/linux/getmntany.c +++ /dev/null @@ -1,188 +0,0 @@ -// SPDX-License-Identifier: CDDL-1.0 -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or https://opensource.org/licenses/CDDL-1.0. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. - * Copyright 2006 Ricardo Correia. All rights reserved. - * Use is subject to license terms. - */ - -/* Copyright (c) 1988 AT&T */ -/* All Rights Reserved */ - -#include <stdio.h> -#include <string.h> -#include <mntent.h> -#include <sys/errno.h> -#include <sys/mnttab.h> - -#include <sys/types.h> -#include <sys/sysmacros.h> -#include <sys/stat.h> -#include <unistd.h> -#include <libzutil.h> - -#define BUFSIZE (MNT_LINE_MAX + 2) - -static __thread char buf[BUFSIZE]; - -#define DIFF(xx) ( \ - (mrefp->xx != NULL) && \ - (mgetp->xx == NULL || strcmp(mrefp->xx, mgetp->xx) != 0)) - -int -getmntany(FILE *fp, struct mnttab *mgetp, struct mnttab *mrefp) -{ - int ret; - - while ( - ((ret = _sol_getmntent(fp, mgetp)) == 0) && ( - DIFF(mnt_special) || DIFF(mnt_mountp) || - DIFF(mnt_fstype) || DIFF(mnt_mntopts))) { } - - return (ret); -} - -int -_sol_getmntent(FILE *fp, struct mnttab *mgetp) -{ - struct mntent mntbuf; - struct mntent *ret; - - ret = getmntent_r(fp, &mntbuf, buf, BUFSIZE); - - if (ret != NULL) { - mgetp->mnt_special = mntbuf.mnt_fsname; - mgetp->mnt_mountp = mntbuf.mnt_dir; - mgetp->mnt_fstype = mntbuf.mnt_type; - mgetp->mnt_mntopts = mntbuf.mnt_opts; - return (0); - } - - if (feof(fp)) - return (-1); - - return (MNT_TOOLONG); -} - -static int -getextmntent_impl(FILE *fp, struct extmnttab *mp, uint64_t *mnt_id) -{ - int ret; - struct stat64 st; - - *mnt_id = 0; - ret = _sol_getmntent(fp, (struct mnttab *)mp); - if (ret == 0) { -#ifdef HAVE_STATX_MNT_ID - struct statx stx; - if (statx(AT_FDCWD, mp->mnt_mountp, - AT_STATX_SYNC_AS_STAT | AT_SYMLINK_NOFOLLOW, - STATX_MNT_ID, &stx) == 0 && (stx.stx_mask & STATX_MNT_ID)) - *mnt_id = stx.stx_mnt_id; -#endif - if (stat64(mp->mnt_mountp, &st) != 0) { - mp->mnt_major = 0; - mp->mnt_minor = 0; - return (ret); - } - mp->mnt_major = major(st.st_dev); - mp->mnt_minor = minor(st.st_dev); - } - - return (ret); -} - -int -getextmntent(const char *path, struct extmnttab *entry, struct stat64 *statbuf) -{ - struct stat64 st; - FILE *fp; - int match; - boolean_t have_mnt_id = B_FALSE; - uint64_t target_mnt_id = 0; - uint64_t entry_mnt_id; -#ifdef HAVE_STATX_MNT_ID - struct statx stx; -#endif - - if (strlen(path) >= MAXPATHLEN) { - (void) fprintf(stderr, "invalid object; pathname too long\n"); - return (-1); - } - - /* - * Search for the path in /proc/self/mounts. Rather than looking for the - * specific path, which can be fooled by non-standard paths (i.e. ".." - * or "//"), we stat() the path and search for the corresponding - * (major,minor) device pair. - */ - if (stat64(path, statbuf) != 0) { - (void) fprintf(stderr, "cannot open '%s': %s\n", - path, zfs_strerror(errno)); - return (-1); - } - -#ifdef HAVE_STATX_MNT_ID - if (statx(AT_FDCWD, path, AT_STATX_SYNC_AS_STAT | AT_SYMLINK_NOFOLLOW, - STATX_MNT_ID, &stx) == 0 && (stx.stx_mask & STATX_MNT_ID)) { - have_mnt_id = B_TRUE; - target_mnt_id = stx.stx_mnt_id; - } -#endif - - if ((fp = fopen(MNTTAB, "re")) == NULL) { - (void) fprintf(stderr, "cannot open %s\n", MNTTAB); - return (-1); - } - - /* - * Search for the given (major,minor) pair in the mount table. - */ - - match = 0; - while (getextmntent_impl(fp, entry, &entry_mnt_id) == 0) { - if (have_mnt_id) { - match = (entry_mnt_id == target_mnt_id); - } else { - match = makedev(entry->mnt_major, entry->mnt_minor) == - statbuf->st_dev; - } - if (match) - break; - } - (void) fclose(fp); - - if (!match) { - (void) fprintf(stderr, "cannot find mountpoint for '%s'\n", - path); - return (-1); - } - - if (stat64(entry->mnt_mountp, &st) != 0) { - entry->mnt_major = 0; - entry->mnt_minor = 0; - return (-1); - } - - return (0); -} diff --git a/lib/libspl/os/linux/zone.c b/lib/libspl/os/linux/zone.c deleted file mode 100644 index f1520676753e..000000000000 --- a/lib/libspl/os/linux/zone.c +++ /dev/null @@ -1,63 +0,0 @@ -// SPDX-License-Identifier: CDDL-1.0 -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or https://opensource.org/licenses/CDDL-1.0. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2006 Ricardo Correia. All rights reserved. - * Use is subject to license terms. - */ - -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include <stdlib.h> -#include <limits.h> -#include <string.h> - -#include <zone.h> - -zoneid_t -getzoneid(void) -{ - char path[PATH_MAX]; - char buf[128] = { '\0' }; - char *cp; - - int c = snprintf(path, sizeof (path), "/proc/self/ns/user"); - /* This API doesn't have any error checking... */ - if (c < 0 || c >= sizeof (path)) - return (GLOBAL_ZONEID); - - ssize_t r = readlink(path, buf, sizeof (buf) - 1); - if (r < 0) - return (GLOBAL_ZONEID); - - cp = strchr(buf, '['); - if (cp == NULL) - return (GLOBAL_ZONEID); - cp++; - - unsigned long n = strtoul(cp, NULL, 10); - if (n == ULONG_MAX && errno == ERANGE) - return (GLOBAL_ZONEID); - zoneid_t z = (zoneid_t)n; - - return (z); -} |