Beispiel #1
0
static int __init kernel_init(void * unused)
{
	lock_kernel();
	/*
	 * init can run on any cpu.
	 */
	set_cpus_allowed_ptr(current, cpu_all_mask);
	/*
	 * Tell the world that we're going to be the grim
	 * reaper of innocent orphaned children.
	 *
	 * We don't want people to have to make incorrect
	 * assumptions about where in the task array this
	 * can be found.
	 */
	init_pid_ns.child_reaper = current;

	cad_pid = task_pid(current);

	smp_prepare_cpus(setup_max_cpus);

	do_pre_smp_initcalls();
	start_boot_trace();

	smp_init();
	sched_init_smp();

	do_basic_setup();

	/*
	 * check if there is an early userspace init.  If yes, let it do all
	 * the work
	 */

	if (!ramdisk_execute_command)
		ramdisk_execute_command = "/init";

	if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
		ramdisk_execute_command = NULL;
		prepare_namespace();
	}

	/*
	 * Ok, we have completed the initial bootup, and
	 * we're essentially up and running. Get rid of the
	 * initmem segments and start the user-mode stuff..
	 */

	init_post();
	return 0;
}
int rdr_remove_file(char *filename)
{
	int ret;
	if (filename == NULL)
		return 0;
	ret = sys_access(filename, 0);
	if (0 == ret) {
		if (sys_unlink(filename)) {
			DUMP_LOG(0);
			return -1;
		}
	}
	return 0;
}
Beispiel #3
0
int
osf1_sys_access(struct lwp *l, const struct osf1_sys_access_args *uap, register_t *retval)
{
	struct sys_access_args a;
	unsigned long leftovers;

	SCARG(&a, path) = SCARG(uap, path);

	/* translate flags */
	SCARG(&a, flags) = emul_flags_translate(osf1_access_flags_xtab,
	    SCARG(uap, flags), &leftovers);
	if (leftovers != 0)
		return (EINVAL);

	return sys_access(l, &a, retval);
}
Beispiel #4
0
static int hifi_create_dir(char *path)
{
	int fd = -1;

	fd = sys_access(path, 0);
	if (0 != fd) {
		logi("need create dir %s.\n", path);
		fd	= sys_mkdir(path, 0755);
		if (fd < 0) {
			loge("create dir %s fail, ret: %d.\n", path, fd);
			return fd;
		}
		logi("create dir %s successed, fd: %d.\n", path, fd);
	}

	return 0;
}
int om_create_dir(char *path)
{
    int fd;

    /* 如果文件夹不存在,创建新文件夹*/
    fd = sys_access(path, 0); //F_OK, 检查文件是否存在
    if(0 != fd)
    {
        fd  = sys_mkdir(path, 0660);
        if(fd < 0)
        {
            bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_OM, "create om dir failed! ret = %d\n", fd);
            return fd;
        }
    }

    return BSP_OK;
}
Beispiel #6
0
/*
 * create a device node called <name> which points to
 * <devfs_name> if possible, otherwise find a device node
 * which matches <dev> and make <name> a symlink pointing to it.
 */
int __init create_dev(char *name, dev_t dev, char *devfs_name)
{
	char path[64];

	sys_unlink(name);
	if (devfs_name && devfs_name[0]) {
		if (strncmp(devfs_name, "/dev/", 5) == 0)
			devfs_name += 5;
		sprintf(path, "/dev/%s", devfs_name);
		if (sys_access(path, 0) == 0)
			return sys_symlink(devfs_name, name);
	}
	if (!dev)
		return -1;
	strcpy(path, "/dev");
	if (find_in_devfs(path, new_encode_dev(dev)) < 0)
		return -1;
	return sys_symlink(path + 5, name);
}
Beispiel #7
0
/*
 * eaccess() checks access to the given path using the effective
 * uid/gid rather than the real uid/gid.
 */
int
xnx_eaccess(char *path, int mode)
{
	uid_t		ouid;
	gid_t		ogid;
	int		err;

	ouid = current->uid;
	ogid = current->gid;
	current->uid = current->euid;
	current->gid = current->egid;

	err = sys_access(path, mode);

	current->uid = ouid;
	current->gid = ogid;

	return err;
}
bool bsp_om_fs_check(void)
{
    int fd;
    mm_segment_t old_fs;

    old_fs = get_fs();
    set_fs(KERNEL_DS);

    fd = sys_access(OM_ROOT_PATH, 0); //F_OK, 检查文件是否存在
    if(0 != fd)
    {
        /*bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_OM, "[BSP_OM]:bsp_om_fs_check file system is invalid\n");*/
        set_fs(old_fs);
        return false;
    }

    om_fetal("om fs is ready\n");
    set_fs(old_fs);

    return true;
}
Beispiel #9
0
int open_exec(const char *filename)
{
	int ret, fd;

	if ( (ret = sys_open(filename, O_RDONLY, 0)) < 0 )
		return ret;

	fd = ret;

	/* fugly, but it works */
	char fd_filename[32] = "/proc/self/fd/";
	numcat(fd_filename, fd);

	if ( (ret = sys_access(fd_filename, X_OK)) < 0 )
	{
		sys_close(fd);
		return ret;
	}

	return fd;
}
static int __rdr_create_dir(char *path)
{
	int fd;

	mm_segment_t old_fs;
	old_fs = get_fs();
	set_fs(KERNEL_DS);

	fd = sys_access(path, 0);
	if (0 != fd) {
		pr_info("rdr: need create dir %s !\n", path);
		fd  = sys_mkdir(path, 0755);
		if (fd < 0) {
			pr_err("rdr: create dir %s failed! ret = %d\n",
					path, fd);
			set_fs(old_fs);
			return fd;
		}
		pr_info("rdr: create dir %s successed [%d]!!!\n", path, fd);
	}

	set_fs(old_fs);
	return 0;
}
/*this function used in little file , only write once.  */
int rdr_append_file(char *filename, void *address, u32 length, u32 max_size)
{
	int ret = 0;
	int fd;
	int bytes;
	int len;
	mm_segment_t old_fs;
	old_fs = get_fs();
	set_fs(KERNEL_DS);

	ret = rdr_create_dir(OM_ROOT_PATH);
	if (0 != ret) {
		pr_err("<%s()>, create dir [%s] failed! ret = %d\n",
				__func__, OM_ROOT_PATH, ret);
		goto out;
	}

	ret = sys_access(filename, 0);
	if (0 != ret) {
		fd = sys_open(filename, O_CREAT | O_RDWR, 0664);/*create file */
		if (fd < 0) {
			pr_err("<%s()>,createOopen fail,r:%d\n",
				__func__, fd);
			goto out;
		}
	} else {
		fd = sys_open(filename, O_APPEND | O_RDWR, 0664);
		if (fd < 0) {
			pr_err("<%s()>,appendOpen failed:r:%d\n", __func__, fd);
			goto out;
		}
	}

	len = sys_lseek(fd, 0, SEEK_END);
	if (len < 0) {
		pr_err("<%s()>, seek failed! ret = %d\n", __func__, len);
		ret = sys_close(fd);
		goto out;
	}

	if (len > max_size) {
		sys_close(fd);
		ret = sys_unlink(filename);
		if (0 != ret) {
			pr_err("<%s()>, remove failed!ret:%d\n", __func__, ret);
			goto out;
		}

		/*rebuild reset file*/
		fd = sys_open(filename, O_CREAT | O_RDWR, 0664);
		if (fd < 0) {
			pr_err("<%s()>, create failed! ret:%d\n", __func__, fd);
			goto out;
		}
	}

	bytes = sys_write(fd, address, length);
	if (bytes != length) {
		pr_err("<%s()>, write data failed! ret:%d\n", __func__, bytes);
		ret = sys_close(fd);
		goto out;
	}

	sys_fsync(fd);
	ret = sys_close(fd);
	if (0 != ret) {
		pr_err("<%s()>, close failed! ret = %d\n", __func__, ret);
		ret = -1;
		goto out;
	}

	ret = 0;

out:
	set_fs(old_fs);
	/*pr_info("rdr: <%s()>, save end. ret = %d\n", __func__, ret);*/
	return ret;
}
Beispiel #12
0
static int init(void * unused)
{
	lock_kernel();
	/*
	 * Tell the world that we're going to be the grim
	 * reaper of innocent orphaned children.
	 *
	 * We don't want people to have to make incorrect
	 * assumptions about where in the task array this
	 * can be found.
	 */
	child_reaper = current;

	/* Sets up cpus_possible() */
	smp_prepare_cpus(max_cpus);

	init_hardirqs();

	do_pre_smp_initcalls();

	fixup_cpu_present_map();
	smp_init();
	sched_init_smp();

	/*
	 * Do this before initcalls, because some drivers want to access
	 * firmware files.
	 */
	populate_rootfs();

	do_basic_setup();

	/*
	 * check if there is an early userspace init.  If yes, let it do all
	 * the work
	 */
	if (sys_access((const char __user *) "/init", 0) == 0)
		execute_command = "/init";
	else
		prepare_namespace();

	/*
	 * Ok, we have completed the initial bootup, and
	 * we're essentially up and running. Get rid of the
	 * initmem segments and start the user-mode stuff..
	 */
	free_initmem();
	unlock_kernel();
	system_state = SYSTEM_RUNNING;
	numa_default_policy();

	if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
		printk("Warning: unable to open an initial console.\n");

	(void) sys_dup(0);
	(void) sys_dup(0);
	
	/*
	 * We try each of these until one succeeds.
	 *
	 * The Bourne shell can be used instead of init if we are 
	 * trying to recover a really broken machine.
	 */
#ifdef CONFIG_KFI_BOOT_TIMING
	to_userspace();
#endif

	if (execute_command)
		run_init_process(execute_command);

	run_init_process("/sbin/init");
	run_init_process("/etc/init");
	run_init_process("/bin/init");
	run_init_process("/bin/sh");

	panic("No init found.  Try passing init= option to kernel.");
}
void log_file_size_check(char *filename)
{
	struct file *file;
	loff_t file_size = 0;
	int i = 0;
	char buf1[1024] = {0};
	char buf2[1024] = {0};
	mm_segment_t old_fs = get_fs();
	int ret = 0;

	set_fs(KERNEL_DS);

	if (filename) {
		file = filp_open(filename, O_RDONLY, 0666);
		sys_chmod(filename, 0666);
	} else {
		TOUCH_E("%s : filename is NULL, can not open FILE\n",
				__func__);
		goto error;
	}

	if (IS_ERR(file)) {
		TOUCH_I("%s : ERR(%ld) Open file error [%s]\n",
				__func__, PTR_ERR(file), filename);
		goto error;
	}

	file_size = vfs_llseek(file, 0, SEEK_END);
	TOUCH_I("%s : [%s] file_size = %lld\n",
			__func__, filename, file_size);

	filp_close(file, 0);

	if (file_size > MAX_LOG_FILE_SIZE) {
		TOUCH_I("%s : [%s] file_size(%lld) > MAX_LOG_FILE_SIZE(%d)\n",
				__func__, filename, file_size, MAX_LOG_FILE_SIZE);

		for (i = MAX_LOG_FILE_COUNT - 1; i >= 0; i--) {
			if (i == 0)
				sprintf(buf1, "%s", filename);
			else
				sprintf(buf1, "%s.%d", filename, i);

			ret = sys_access(buf1, 0);

			if (ret == 0) {
				TOUCH_I("%s : file [%s] exist\n", __func__, buf1);

				if (i == (MAX_LOG_FILE_COUNT - 1)) {
					if (sys_unlink(buf1) < 0) {
						TOUCH_E(
								"%s : failed to remove file [%s]\n",
								__func__, buf1);
						goto error;
					}

					TOUCH_I(
							"%s : remove file [%s]\n",
							__func__, buf1);
				} else {
					sprintf(buf2, "%s.%d", filename,
							(i + 1));

					if (sys_rename(buf1, buf2) < 0) {
						TOUCH_E(
								"%s : failed to rename file [%s] -> [%s]\n",
								__func__, buf1, buf2);
						goto error;
					}

					TOUCH_I(
							"%s : rename file [%s] -> [%s]\n",
							__func__, buf1, buf2);
				}
			} else {
				TOUCH_I("%s : file [%s] does not exist (ret = %d)\n", __func__, buf1, ret);
			}
		}
	}

error:
	set_fs(old_fs);
	return;
}
Beispiel #14
0
static int init(void * unused)
{
	lock_kernel();
	/*
	 * init can run on any cpu.
	 */
	set_cpus_allowed(current, CPU_MASK_ALL);
	/*
	 * Tell the world that we're going to be the grim
	 * reaper of innocent orphaned children.
	 *
	 * We don't want people to have to make incorrect
	 * assumptions about where in the task array this
	 * can be found.
	 */
	child_reaper = current;

	smp_prepare_cpus(max_cpus);

	do_pre_smp_initcalls();

	smp_init();
	sched_init_smp();

	cpuset_init_smp();

	/*
	 * Do this before initcalls, because some drivers want to access
	 * firmware files.
	 */
	populate_rootfs();

	do_basic_setup();

	/*
	 * check if there is an early userspace init.  If yes, let it do all
	 * the work
	 */

	if (!ramdisk_execute_command)
		ramdisk_execute_command = "/init";

	if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
		ramdisk_execute_command = NULL;
		prepare_namespace();
	}

	/*
	 * Ok, we have completed the initial bootup, and
	 * we're essentially up and running. Get rid of the
	 * initmem segments and start the user-mode stuff..
	 */
	free_initmem();
	unlock_kernel();
	mark_rodata_ro();
	system_state = SYSTEM_RUNNING;
	numa_default_policy();

	if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
		printk(KERN_WARNING "Warning: unable to open an initial console.\n");

	(void) sys_dup(0);
	(void) sys_dup(0);

	if (ramdisk_execute_command) {
		run_init_process(ramdisk_execute_command);
		printk(KERN_WARNING "Failed to execute %s\n",
				ramdisk_execute_command);
	}

	/*
	 * We try each of these until one succeeds.
	 *
	 * The Bourne shell can be used instead of init if we are 
	 * trying to recover a really broken machine.
	 */
	if (execute_command) {
		run_init_process(execute_command);
		printk(KERN_WARNING "Failed to execute %s.  Attempting "
					"defaults...\n", execute_command);
	}
	run_init_process("/sbin/init");
	run_init_process("/etc/init");
	run_init_process("/bin/init");
	run_init_process("/bin/sh");

	panic("No init found.  Try passing init= option to kernel.");
}
Beispiel #15
0
static int ATTRIB_NORET init(void * unused)
{
#ifdef TARGET_OS2
   LX_ReschedWaitOn();
   while(kernel_flag.lock<=0)
    schedule();
#endif
   lock_kernel();
   /*
    * Tell the world that we're going to be the grim
    * reaper of innocent orphaned children.
    *
    * We don't want people to have to make incorrect
    * assumptions about where in the task array this
    * can be found.
    */
   child_reaper = current;

   /* Sets up cpus_possible() */
   smp_prepare_cpus(max_cpus);

   do_pre_smp_initcalls();

   smp_init();

   /*
    * Do this before initcalls, because some drivers want to access
    * firmware files.
    */
   populate_rootfs();

   do_basic_setup();
   /*
    * check if there is an early userspace init.  If yes, let it do all
    * the work
    */
   if (sys_access("/init", 0) == 0)
      execute_command = "/init";
   else
      prepare_namespace();

   /*
    * Ok, we have completed the initial bootup, and
    * we're essentially up and running. Get rid of the
    * initmem segments and start the user-mode stuff..
    */
   free_initmem();
   unlock_kernel();
   system_state = SYSTEM_RUNNING;
#ifdef TARGET_OS2
   lx_sysstate|=LXSYSSTATE_SYSTEM_RUNNING;
#endif

   if (sys_open("/dev/console", O_RDWR, 0) < 0)
      printk("Warning: unable to open an initial console.\n");


   (void) sys_dup(0);
   (void) sys_dup(0);
#ifdef TARGET_OS2
   LX_set_sysstate(LXSYSSTATE_KERNEL_BOOT_FINISHED,0);
#endif

   /*
    * We try each of these until one succeeds.
    *
    * The Bourne shell can be used instead of init if we are
    * trying to recover a really broken machine.
    */

   if (execute_command)
      run_init_process(execute_command);

   run_init_process("/sbin/init");
   run_init_process("/etc/init");
   run_init_process("/bin/init");
   run_init_process("/bin/sh");

   panic("No init found.  Try passing init= option to kernel.");
}
/* Note: it is necessary to treat mode as an unsigned int,
 * with the corresponding cast to a signed int to insure that the 
 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
 * and the register representation of a signed int (msr in 64-bit mode) is performed.
 */
asmlinkage long compat_sys_access(const char __user * filename, u32 mode)
{
	return sys_access(filename, (int)mode);
}
int
ultrix_sys_access(struct lwp *l, const struct ultrix_sys_access_args *uap, register_t *retval)
{

	return sys_access(l, (const struct sys_access_args *)uap, retval);
}
int access(const char *filename, int mode)
{
  return sys_access(filename, mode);
}
Beispiel #19
0
static int __init kernel_init(void * unused)
{
	lock_kernel();

	/*
	 * init can allocate pages on any node
	 */
	set_mems_allowed(node_possible_map);

#ifdef 	CONFIG_SYS_HAS_CONTROL_CPU
	/*
	 * init can run on cpu0 only .
	 */
	set_cpus_allowed_ptr(current, cpumask_of(0));
#else
	/*
	 * init can run on any cpu .
	 */
	set_cpus_allowed_ptr(current, cpu_all_mask);
#endif
	/*
	 * Tell the world that we're going to be the grim
	 * reaper of innocent orphaned children.
	 *
	 * We don't want people to have to make incorrect
	 * assumptions about where in the task array this
	 * can be found.
	 */
	init_pid_ns.child_reaper = current;

	cad_pid = task_pid(current);

	smp_prepare_cpus(setup_max_cpus);

	do_pre_smp_initcalls();
	start_boot_trace();

	smp_init();
	sched_init_smp();

#ifdef 	CONFIG_SYS_HAS_CONTROL_CPU
	/* HeJianjun modified for bug 148, 
	 * we run linux local processes on only cpu0, other cpu's are just for running dapp */
	set_cpus_allowed_ptr(current, cpumask_of(0));
#endif

	do_basic_setup();

	/*
	 * check if there is an early userspace init.  If yes, let it do all
	 * the work
	 */

	if (!ramdisk_execute_command)
		ramdisk_execute_command = "/init";

	if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
		ramdisk_execute_command = NULL;
		prepare_namespace();
	}

	/*
	 * Ok, we have completed the initial bootup, and
	 * we're essentially up and running. Get rid of the
	 * initmem segments and start the user-mode stuff..
	 */

	init_post();
	return 0;
}
Beispiel #20
0
static int __init kernel_init(void * unused)
{
	lock_kernel();

	/*
	 * init can allocate pages on any node
	 */
	set_mems_allowed(node_possible_map);
	/*
	 * init can run on any cpu.
	 */
	set_cpus_allowed_ptr(current, cpu_all_mask);
	/*
	 * Tell the world that we're going to be the grim
	 * reaper of innocent orphaned children.
	 *
	 * We don't want people to have to make incorrect
	 * assumptions about where in the task array this
	 * can be found.
	 */
	init_pid_ns.child_reaper = current;

	cad_pid = task_pid(current);

	smp_prepare_cpus(setup_max_cpus);

	do_pre_smp_initcalls();
	start_boot_trace();

	smp_init();
	sched_init_smp();

	do_basic_setup();

	/*
	 * check if there is an early userspace init.  If yes, let it do all
	 * the work
	 */

	if (!ramdisk_execute_command)
		ramdisk_execute_command = "/init";

	if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
		ramdisk_execute_command = NULL;
		prepare_namespace();
	}
#ifdef CONFIG_PREEMPT_RT
	WARN_ON(irqs_disabled());
#endif

#define DEBUG_COUNT (defined(CONFIG_DEBUG_RT_MUTEXES) + defined(CONFIG_IRQSOFF_TRACER) + defined(CONFIG_PREEMPT_TRACER) + defined(CONFIG_STACK_TRACER) + defined(CONFIG_INTERRUPT_OFF_HIST) + defined(CONFIG_PREEMPT_OFF_HIST) + defined(CONFIG_WAKEUP_LATENCY_HIST) + defined(CONFIG_DEBUG_SLAB) + defined(CONFIG_DEBUG_PAGEALLOC) + defined(CONFIG_LOCKDEP) + (defined(CONFIG_FTRACE) - defined(CONFIG_FTRACE_MCOUNT_RECORD)))

#if DEBUG_COUNT > 0
	printk(KERN_ERR "*****************************************************************************\n");
	printk(KERN_ERR "*                                                                           *\n");
#if DEBUG_COUNT == 1
	printk(KERN_ERR "*  REMINDER, the following debugging option is turned on in your .config:   *\n");
#else
	printk(KERN_ERR "*  REMINDER, the following debugging options are turned on in your .config: *\n");
#endif
	printk(KERN_ERR "*                                                                           *\n");
#ifdef CONFIG_DEBUG_RT_MUTEXES
	printk(KERN_ERR "*        CONFIG_DEBUG_RT_MUTEXES                                            *\n");
#endif
#ifdef CONFIG_IRQSOFF_TRACER
	printk(KERN_ERR "*        CONFIG_IRQSOFF_TRACER                                              *\n");
#endif
#ifdef CONFIG_PREEMPT_TRACER
	printk(KERN_ERR "*        CONFIG_PREEMPT_TRACER                                              *\n");
#endif
#if defined(CONFIG_FTRACE) && !defined(CONFIG_FTRACE_MCOUNT_RECORD)
	printk(KERN_ERR "*        CONFIG_FTRACE                                                      *\n");
#endif
#ifdef CONFIG_INTERRUPT_OFF_HIST
	printk(KERN_ERR "*        CONFIG_INTERRUPT_OFF_HIST                                          *\n");
#endif
#ifdef CONFIG_PREEMPT_OFF_HIST
	printk(KERN_ERR "*        CONFIG_PREEMPT_OFF_HIST                                            *\n");
#endif
#ifdef CONFIG_WAKEUP_LATENCY_HIST
	printk(KERN_ERR "*        CONFIG_WAKEUP_LATENCY_HIST                                         *\n");
#endif
#ifdef CONFIG_DEBUG_SLAB
	printk(KERN_ERR "*        CONFIG_DEBUG_SLAB                                                  *\n");
#endif
#ifdef CONFIG_DEBUG_PAGEALLOC
	printk(KERN_ERR "*        CONFIG_DEBUG_PAGEALLOC                                             *\n");
#endif
#ifdef CONFIG_LOCKDEP
	printk(KERN_ERR "*        CONFIG_LOCKDEP                                                     *\n");
#endif
	printk(KERN_ERR "*                                                                           *\n");
#if DEBUG_COUNT == 1
	printk(KERN_ERR "*  it may increase runtime overhead and latencies.                          *\n");
#else
	printk(KERN_ERR "*  they may increase runtime overhead and latencies.                        *\n");
#endif
	printk(KERN_ERR "*                                                                           *\n");
	printk(KERN_ERR "*****************************************************************************\n");
#endif
	/*
	 * Ok, we have completed the initial bootup, and
	 * we're essentially up and running. Get rid of the
	 * initmem segments and start the user-mode stuff..
	 */

	init_post();
	return 0;
}
int bsp_om_append_file(char *filename, void * address, u32 length, u32 max_size)
{
    int ret = BSP_OK;
    int fd;
    int bytes;
    int len;
    mm_segment_t old_fs;

    old_fs = get_fs();
    set_fs(KERNEL_DS);

    ret = om_create_dir(OM_ROOT_PATH);
    if(BSP_OK != ret)
    {
        om_error("<bsp_om_append_file>, create dir failed! ret = %d\n", ret);
        goto out;
    }

    /* open file */
    ret = sys_access(filename, 0);
    if(BSP_OK != ret)
    {
        /*create file */
        fd = sys_open(filename, O_CREAT|O_RDWR, 0755);
        if(fd < 0)
        {
            om_error("<bsp_om_append_file>, open failed while mode is create, ret = %d\n", fd);
            goto out;
        }
    }
    else
    {
        fd = sys_open(filename, O_APPEND|O_RDWR, 0755);
        if(fd < 0)
        {
            om_error("<bsp_om_append_file>, open failed while mode is append, ret = %d\n", fd);
            goto out;
        }
    }

    len = sys_lseek(fd, 0, SEEK_END);
    if(ERROR == len)
    {
        om_error("<bsp_om_append_file>, seek failed! ret = %d\n", len);
        (void)sys_close(fd);
        goto out;
    }

    if (len >= max_size)
    {
        sys_close(fd);
        ret = sys_unlink(filename);
        if (OK != ret)
        {
            om_error("<bsp_om_append_file>, remove failed! ret = %d\n", ret);
	        goto out;
        }

        /*重新建立reset文件*/
        fd = sys_open(filename, O_CREAT|O_RDWR, 0755);
        if(fd < 0)
        {
            om_error("<bsp_om_append_file>, create failed! ret = %d\n", fd);
            goto out;
        }
    }

    bytes = sys_write(fd, address, length);
    if(bytes != length)
    {
        om_error("<bsp_om_append_file>, write data failed! ret = %d\n", bytes);
        ret = BSP_ERROR;
        (void)sys_close(fd);
        goto out;
    }

    ret = sys_close(fd);
    if(0 != ret)
    {
        om_error("<bsp_om_append_file>, close failed! ret = %d\n", ret);
        ret = BSP_ERROR;
        goto out;
    }

    ret = BSP_OK;

out:
    set_fs(old_fs);
    return ret;
}
Beispiel #22
0
static int init(void * unused)
{
    int fdin, fdout, fderr;

    lock_kernel();
    /*
     * init can run on any cpu.
     */
    set_cpus_allowed(current, CPU_MASK_ALL);
    /*
     * Tell the world that we're going to be the grim
     * reaper of innocent orphaned children.
     *
     * We don't want people to have to make incorrect
     * assumptions about where in the task array this
     * can be found.
     */
    child_reaper = current;

    /* Sets up cpus_possible() */
    smp_prepare_cpus(max_cpus);

    do_pre_smp_initcalls();

    fixup_cpu_present_map();
    smp_init();
    sched_init_smp();

    cpuset_init_smp();

    /*
     * Do this before initcalls, because some drivers want to access
     * firmware files.
     */
    populate_rootfs();

    do_basic_setup();

    /*
     * check if there is an early userspace init.  If yes, let it do all
     * the work
     */
    if (sys_access((const char __user *) "/init", 0) == 0)
        execute_command = "/init";
    else
        prepare_namespace();

    /*
     * Ok, we have completed the initial bootup, and
     * we're essentially up and running. Get rid of the
     * initmem segments and start the user-mode stuff..
     */
    free_initmem();
    unlock_kernel();
    system_state = SYSTEM_RUNNING;
    numa_default_policy();

    fdin = sys_open((const char __user *) "/dev/console", O_RDWR, 0);
    if (fdin < 0) {
        printk(KERN_WARNING "Warning: unable to open /dev/console as initial console, res=%d.\n", fdin);
        fdin = sys_open((const char __user *) "/dev/null", O_RDWR, 0);
        if (fdin < 0) {
            panic("unable to open /dev/null as initial console, res=%d.\n", fdin);
        }
    }
    if (fdin != 0) {
        panic("initial console's stdin fd is not 0, but %d\n", fdin);
    }

    fdout = sys_dup(fdin);
    if (fdout < 0) {
        panic("can't dup initial console's stdout, res=%d\n", fdout);
    } else if (fdout != 1) {
        panic("initial console's stdout fd is not 1, but %d\n", fdout);
    }

    fderr = sys_dup(fdin);
    if (fderr < 0) {
        panic("can't dup initial console's stderr, res=%d\n", fderr);
    } else if (fderr != 2) {
        panic("initial console's stderr fd is not 2, but %d\n", fderr);
    }

    /*
     * We try each of these until one succeeds.
     *
     * The Bourne shell can be used instead of init if we are
     * trying to recover a really broken machine.
     */

    if (execute_command)
        run_init_process(execute_command);

    run_init_process("/sbin/init");
    run_init_process("/etc/init");
    run_init_process("/bin/init");
    run_init_process("/bin/sh");

    panic("No init found.  Try passing init= option to kernel.");
}
Beispiel #23
0
static int init(void * unused)
{

#ifdef CONFIG_STR8100_GNSD630
	__u32 data;

	/* 
	 * from original kernel image
	 * TODO: figure out what the commented out lines do
	 */

	/* 
	 * mode for gpio pins:
	 * 22 and 23: led mode
	 * 24: stays gpio. changes disk mode
	 */
	MISC_GPIOA_PIN_ENABLE_REG = 0x0;
	MISC_GPIOA_PIN_ENABLE_REG |= (0x3 << 22);

	
	/* 
	 * set some pins to input mode
	 * 13: device is connected to pc
	 * 0: reset button
	 */
	GPIOA_DIRECTION_REG = 0xffffdff0;

	/* 
	 * disk to standalone mode
	 */
	GPIOA_DATA_OUTPUT_REG = 0x010fffff;

	udelay(10);

	/*
	GPIOA_DATA_OUTPUT_REG |= 0x20000;
	GPIOA_DATA_OUTPUT_REG |= 0x20000000;
	*/

	/* set disk to device mode if connected to pc */
	HAL_GPIOA_READ_DATA_IN_STATUS(data);
	if (!(data & 0x00002000))
		GPIOA_DATA_OUTPUT_REG = 0x000fdfff;

	/*
	GPIOA_DATA_OUTPUT_REG |= 0x10000;
	*/
#endif
	lock_kernel();
	/*
	 * init can run on any cpu.
	 */
	set_cpus_allowed(current, CPU_MASK_ALL);
	/*
	 * Tell the world that we're going to be the grim
	 * reaper of innocent orphaned children.
	 *
	 * We don't want people to have to make incorrect
	 * assumptions about where in the task array this
	 * can be found.
	 */
	child_reaper = current;

	smp_prepare_cpus(max_cpus);

	do_pre_smp_initcalls();

	fixup_cpu_present_map();
	smp_init();
	sched_init_smp();

	cpuset_init_smp();

	/*
	 * Do this before initcalls, because some drivers want to access
	 * firmware files.
	 */
	populate_rootfs();

	do_basic_setup();

#ifdef CONFIG_STR8100_GNSD630
	/*
	GPIOA_DATA_OUTPUT_REG |= 0x20000;
	GPIOA_DATA_OUTPUT_REG |= 0x20000000;
	*/

	/* 
	 * setup gpio pins again. seems redundant
	 */
	MISC_GPIOA_PIN_ENABLE_REG = 0x0;
	MISC_GPIOA_PIN_ENABLE_REG |= (0x3 << 22);
#endif

	/*
	 * check if there is an early userspace init.  If yes, let it do all
	 * the work
	 */

	if (!ramdisk_execute_command)
		ramdisk_execute_command = "/init";

	if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
		ramdisk_execute_command = NULL;
		prepare_namespace();
	}

	/*
	 * Ok, we have completed the initial bootup, and
	 * we're essentially up and running. Get rid of the
	 * initmem segments and start the user-mode stuff..
	 */
	free_initmem();
	unlock_kernel();
	mark_rodata_ro();
	system_state = SYSTEM_RUNNING;
	numa_default_policy();

	if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
		printk(KERN_WARNING "Warning: unable to open an initial console.\n");

	(void) sys_dup(0);
	(void) sys_dup(0);

	if (ramdisk_execute_command) {
		run_init_process(ramdisk_execute_command);
		printk(KERN_WARNING "Failed to execute %s\n",
				ramdisk_execute_command);
	}

	/*
	 * We try each of these until one succeeds.
	 *
	 * The Bourne shell can be used instead of init if we are 
	 * trying to recover a really broken machine.
	 */
	if (execute_command) {
		run_init_process(execute_command);
		printk(KERN_WARNING "Failed to execute %s.  Attempting "
					"defaults...\n", execute_command);
	}
	run_init_process("/sbin/init");
	run_init_process("/etc/init");
	run_init_process("/bin/init");
	run_init_process("/bin/sh");

	panic("No init found.  Try passing init= option to kernel.");
}
static int __init kernel_init(void * unused)
{
	/*
	 * Wait until kthreadd is all set-up.
	 */
	wait_for_completion(&kthreadd_done);
	lock_kernel();

	/*
	 * init can allocate pages on any node
	 */
	set_mems_allowed(node_states[N_HIGH_MEMORY]);
	/*
	 * init can run on any cpu.
	 */
	set_cpus_allowed_ptr(current, cpu_all_mask);
	/*
	 * Tell the world that we're going to be the grim
	 * reaper of innocent orphaned children.
	 *
	 * We don't want people to have to make incorrect
	 * assumptions about where in the task array this
	 * can be found.
	 */
	init_pid_ns.child_reaper = current;

	cad_pid = task_pid(current);

	smp_prepare_cpus(setup_max_cpus);

	do_pre_smp_initcalls();
	start_boot_trace();

	smp_init();
	sched_init_smp();

	do_basic_setup();

	/* Open the /dev/console on the rootfs, this should never fail */
	if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
		printk(KERN_WARNING "Warning: unable to open an initial console.\n");

	(void) sys_dup(0);
	(void) sys_dup(0);
	/*
	 * check if there is an early userspace init.  If yes, let it do all
	 * the work
	 */

	if (!ramdisk_execute_command)
		ramdisk_execute_command = "/init";

	if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
		ramdisk_execute_command = NULL;
		prepare_namespace();
	}

	/*
	 * Ok, we have completed the initial bootup, and
	 * we're essentially up and running. Get rid of the
	 * initmem segments and start the user-mode stuff..
	 */

	init_post();
	return 0;
}
Beispiel #25
0
static int init(void * unused)
{
    lock_kernel();
    /*
     * init can run on any cpu.
     */
    set_cpus_allowed(current, CPU_MASK_ALL);
    /*
     * Tell the world that we're going to be the grim
     * reaper of innocent orphaned children.
     *
     * We don't want people to have to make incorrect
     * assumptions about where in the task array this
     * can be found.
     */
    child_reaper = current;

    smp_prepare_cpus(max_cpus);

    init_hardirqs();

    do_pre_smp_initcalls();

    smp_init();
    sched_init_smp();

    cpuset_init_smp();

    /*
     * Do this before initcalls, because some drivers want to access
     * firmware files.
     */
    populate_rootfs();

    do_basic_setup();

    /*
     * check if there is an early userspace init.  If yes, let it do all
     * the work
     */

    if (!ramdisk_execute_command)
        ramdisk_execute_command = "/init";

    if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
        ramdisk_execute_command = NULL;
        prepare_namespace();
    }
#ifdef CONFIG_PREEMPT_RT
    WARN_ON(irqs_disabled());
#endif

#define DEBUG_COUNT (defined(CONFIG_DEBUG_RT_MUTEXES) + defined(CONFIG_DEBUG_PREEMPT) + defined(CONFIG_CRITICAL_PREEMPT_TIMING) + defined(CONFIG_CRITICAL_IRQSOFF_TIMING) + defined(CONFIG_LATENCY_TRACE) + defined(CONFIG_DEBUG_SLAB) + defined(CONFIG_DEBUG_PAGEALLOC) + defined(CONFIG_LOCKDEP))

#if DEBUG_COUNT > 0
    printk(KERN_ERR "*****************************************************************************\n");
    printk(KERN_ERR "*                                                                           *\n");
#if DEBUG_COUNT == 1
    printk(KERN_ERR "*  REMINDER, the following debugging option is turned on in your .config:   *\n");
#else
    printk(KERN_ERR "*  REMINDER, the following debugging options are turned on in your .config: *\n");
#endif
    printk(KERN_ERR "*                                                                           *\n");
#ifdef CONFIG_DEBUG_RT_MUTEXES
    printk(KERN_ERR "*        CONFIG_DEBUG_RT_MUTEXES                                             *\n");
#endif
#ifdef CONFIG_DEBUG_PREEMPT
    printk(KERN_ERR "*        CONFIG_DEBUG_PREEMPT                                               *\n");
#endif
#ifdef CONFIG_CRITICAL_PREEMPT_TIMING
    printk(KERN_ERR "*        CONFIG_CRITICAL_PREEMPT_TIMING                                     *\n");
#endif
#ifdef CONFIG_CRITICAL_IRQSOFF_TIMING
    printk(KERN_ERR "*        CONFIG_CRITICAL_IRQSOFF_TIMING                                     *\n");
#endif
#ifdef CONFIG_LATENCY_TRACE
    printk(KERN_ERR "*        CONFIG_LATENCY_TRACE                                               *\n");
#endif
#ifdef CONFIG_DEBUG_SLAB
    printk(KERN_ERR "*        CONFIG_DEBUG_SLAB                                                  *\n");
#endif
#ifdef CONFIG_DEBUG_PAGEALLOC
    printk(KERN_ERR "*        CONFIG_DEBUG_PAGEALLOC                                             *\n");
#endif
#ifdef CONFIG_LOCKDEP
    printk(KERN_ERR "*        CONFIG_LOCKDEP                                                     *\n");
#endif
    printk(KERN_ERR "*                                                                           *\n");
#if DEBUG_COUNT == 1
    printk(KERN_ERR "*  it may increase runtime overhead and latencies.                          *\n");
#else
    printk(KERN_ERR "*  they may increase runtime overhead and latencies.                        *\n");
#endif
    printk(KERN_ERR "*                                                                           *\n");
    printk(KERN_ERR "*****************************************************************************\n");
#endif
    /*
     * Ok, we have completed the initial bootup, and
     * we're essentially up and running. Get rid of the
     * initmem segments and start the user-mode stuff..
     */
    free_initmem();
    unlock_kernel();
    mark_rodata_ro();
    system_state = SYSTEM_RUNNING;
    numa_default_policy();

    if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
        printk(KERN_WARNING "Warning: unable to open an initial console.\n");

    (void) sys_dup(0);
    (void) sys_dup(0);

    if (ramdisk_execute_command) {
        run_init_process(ramdisk_execute_command);
        printk(KERN_WARNING "Failed to execute %s\n",
               ramdisk_execute_command);
    }
#ifdef CONFIG_PREEMPT_RT
    WARN_ON(irqs_disabled());
#endif

    /*
     * We try each of these until one succeeds.
     *
     * The Bourne shell can be used instead of init if we are
     * trying to recover a really broken machine.
     */
    if (execute_command) {
        run_init_process(execute_command);
        printk(KERN_WARNING "Failed to execute %s.  Attempting "
               "defaults...\n", execute_command);
    }
    run_init_process("/sbin/init");
    run_init_process("/etc/init");
    run_init_process("/bin/init");
    run_init_process("/bin/sh");

    panic("No init found.  Try passing init= option to kernel.");
}