<commit_before>/*-
 * Copyright (c) 1994-1995 <NAME>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer 
 *    in this position and unchanged.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software withough specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#include <sys/param.h>
#include <sys/conf.h>
#include <sys/dirent.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/proc.h>
#include <sys/mount.h>
#include <sys/namei.h>
#include <sys/stat.h>
#include <sys/systm.h>
#include <sys/vnode.h>

#include <machine/../linux/linux.h>
#include <machine/../linux/linux_proto.h>
#include <compat/linux/linux_util.h>

#include <sys/sysctl.h>

struct linux_newstat {
#ifdef __alpha__
	u_int	stat_dev;
	u_int	stat_ino;
	u_int	stat_mode;
	u_int	stat_nlink;
	u_int	stat_uid;
	u_int	stat_gid;
	u_int	stat_rdev;
	long	stat_size;
	u_long	stat_atime;
	u_long	stat_mtime;
	u_long	stat_ctime;
	u_int	stat_blksize;
	int		stat_blocks;
	u_int	stat_flags;
	u_int	stat_gen;
#else
	u_short	stat_dev;
	u_short	__pad1;
	u_long	stat_ino;
	u_short	stat_mode;
	u_short	stat_nlink;
	u_short	stat_uid;
	u_short	stat_gid;
	u_short	stat_rdev;
	u_short	__pad2;
	u_long	stat_size;
	u_long	stat_blksize;
	u_long	stat_blocks;
	u_long	stat_atime;
	u_long	__unused1;
	u_long	stat_mtime;
	u_long	__unused2;
	u_long	stat_ctime;
	u_long	__unused3;
	u_long	__unused4;
	u_long	__unused5;
#endif
};


struct linux_ustat 
{
	int	f_tfree;
	u_long	f_tinode;
	char	f_fname[6];
	char	f_fpack[6];
};

static int
newstat_copyout(struct stat *buf, void *ubuf)
{
	struct linux_newstat tbuf;

	tbuf.stat_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8);
	tbuf.stat_ino = buf->st_ino;
	tbuf.stat_mode = buf->st_mode;
	tbuf.stat_nlink = buf->st_nlink;
	tbuf.stat_uid = buf->st_uid;
	tbuf.stat_gid = buf->st_gid;
	tbuf.stat_rdev = buf->st_rdev;
	tbuf.stat_size = buf->st_size;
	tbuf.stat_atime = buf->st_atime;
	tbuf.stat_mtime = buf->st_mtime;
	tbuf.stat_ctime = buf->st_ctime;
	tbuf.stat_blksize = buf->st_blksize;
	tbuf.stat_blocks = buf->st_blocks;
	if (tbuf.stat_mode & S_IFCHR &&
		(umajor(buf->st_rdev) == 116 ||
		 umajor(buf->st_rdev) == 13)) {

		tbuf.stat_mode &= ~S_IFCHR;
		tbuf.stat_mode |= S_IFBLK;

		/* XXX this may not be quite right */
		/* Map major number to 0 */
		tbuf.stat_dev = uminor(buf->st_dev) & 0xf;
		tbuf.stat_rdev = buf->st_rdev & 0xff;<commit_msg>Instead of hard coding the major numbers for IDE and SCSI disks look in the device's cdevsw for the D_DISK flag.<commit_after>/*-
 * Copyright (c) 1994-1995 <NAME>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer 
 *    in this position and unchanged.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software withough specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#include <sys/param.h>
#include <sys/conf.h>
#include <sys/dirent.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/proc.h>
#include <sys/mount.h>
#include <sys/namei.h>
#include <sys/stat.h>
#include <sys/systm.h>
#include <sys/vnode.h>

#include <machine/../linux/linux.h>
#include <machine/../linux/linux_proto.h>
#include <compat/linux/linux_util.h>

#include <sys/sysctl.h>

struct linux_newstat {
#ifdef __alpha__
	u_int	stat_dev;
	u_int	stat_ino;
	u_int	stat_mode;
	u_int	stat_nlink;
	u_int	stat_uid;
	u_int	stat_gid;
	u_int	stat_rdev;
	long	stat_size;
	u_long	stat_atime;
	u_long	stat_mtime;
	u_long	stat_ctime;
	u_int	stat_blksize;
	int		stat_blocks;
	u_int	stat_flags;
	u_int	stat_gen;
#else
	u_short	stat_dev;
	u_short	__pad1;
	u_long	stat_ino;
	u_short	stat_mode;
	u_short	stat_nlink;
	u_short	stat_uid;
	u_short	stat_gid;
	u_short	stat_rdev;
	u_short	__pad2;
	u_long	stat_size;
	u_long	stat_blksize;
	u_long	stat_blocks;
	u_long	stat_atime;
	u_long	__unused1;
	u_long	stat_mtime;
	u_long	__unused2;
	u_long	stat_ctime;
	u_long	__unused3;
	u_long	__unused4;
	u_long	__unused5;
#endif
};


struct linux_ustat 
{
	int	f_tfree;
	u_long	f_tinode;
	char	f_fname[6];
	char	f_fpack[6];
};

static int
newstat_copyout(struct stat *buf, void *ubuf)
{
	struct linux_newstat tbuf;
	struct cdevsw *cdevsw;
	dev_t dev;

	tbuf.stat_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8);
	tbuf.stat_ino = buf->st_ino;
	tbuf.stat_mode = buf->st_mode;
	tbuf.stat_nlink = buf->st_nlink;
	tbuf.stat_uid = buf->st_uid;
	tbuf.stat_gid = buf->st_gid;
	tbuf.stat_rdev = buf->st_rdev;
	tbuf.stat_size = buf->st_size;
	tbuf.stat_atime = buf->st_atime;
	tbuf.stat_mtime = buf->st_mtime;
	tbuf.stat_ctime = buf->st_ctime;
	tbuf.stat_blksize = buf->st_blksize;
	tbuf.stat_blocks = buf->st_blocks;

	/* Lie about disk drives which are character devices
	 * in FreeBSD but block devices under Linux.
	 */
	if (tbuf.stat_mode & S_IFCHR &&
	    (dev = udev2dev(buf->st_rdev, 0)) != NODEV) {
		cdevsw = devsw(dev);
		if (cdevsw != NULL && (cdevsw->d_flags & D_DISK)) {
			tbuf.stat_mode &= ~S_IFCHR;
			tbuf.stat_mode |= S_IFBLK;

			/* XXX this may not be quite right */
			/* Map major number to 0 */
			tbuf.stat_dev = uminor(buf->st_dev) & 0xf;
			tbuf.stat_rdev = buf->st_rdev & 0xff;
		}
{'fraction_non_alphanumeric': 0.0967741935483871, 'fraction_numerical': 0.007271285034373348, 'mean_word_length': 4.242550242550243, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3688966', 'n_tokens_mistral': 2983, 'n_tokens_neox': 2830, 'n_words': 846}