int mkdir_chkpt_path(long app_id, unsigned int chkpt_sn)
{
	char *buff;
	char *dirname;
	int r;

	buff = kmalloc(PATH_MAX*sizeof(char), GFP_KERNEL);
	if (!buff) {
		r = -ENOMEM;
		goto err_buff;
	}

	dirname = kmalloc(PATH_MAX*sizeof(char), GFP_KERNEL);
	if (!dirname) {
		r = -ENOMEM;
		goto err_dirname;
	}

	snprintf(dirname, PATH_MAX, "%s", checkpointRoot);

	if (app_id) {
		snprintf(buff, PATH_MAX, "%ld/", app_id);
		strncat(dirname, buff, PATH_MAX);
	}

	r = sys_mkdir(dirname, S_IRWXUGO|S_ISVTX);
	if (r && r != -EEXIST)
		goto err;

	/* really force the mode without looking at umask */
	r = sys_chmod(dirname, S_IRWXUGO|S_ISVTX);
	if (r)
		goto err;

	if (chkpt_sn) {
		snprintf(buff, PATH_MAX, "v%d/", chkpt_sn);
		strncat(dirname, buff, PATH_MAX);

		r = sys_mkdir(dirname, S_IRWXU);
		if (r && r != -EEXIST)
			goto err;
		r = 0;
	}

err:
	kfree(dirname);
err_dirname:
	kfree(buff);
err_buff:
	return r;
}
static int create_dir(char *path)
{
	int fd = -1;

	BUG_ON(NULL == path);

	fd = sys_access(path, 0);
	if (fd) {
		BB_PRINT_PN("need create dir %s\n", path);
		fd = sys_mkdir(path, 0770);
		if (fd < 0) {
			BB_PRINT_ERR("create dir %s failed, fd:%d\n",
					path, fd);
			return -EBADF;
		}
		BB_PRINT_PN("create dir %s successed, fd: %d\n", path, fd);
	}

	/* change dir limit root-system */
	if (bbox_chown((const char *)path, ROOT_UID, SYSTEM_GID, false)) {
		BB_PRINT_ERR("[%s], chown %s dir failed\n", __func__, path);
	}

	return 0;
}
Esempio n. 3
0
int main(int argc, char *argv[]){
    int ret;
    char *filename;

    lcd_init();
    lcd_setscrollmode(1);

    if(argc != 2){
        usage();
        return 1;
    }

    filename = argv[1];

    ret = sys_mkdir(filename, 0);
    if(ret < 0){
        switch(-ret){
        case  3: // FAT_ERROR_INVALID_FILE_NAME
            lcd_printf("invalid file name (%s)\n",filename);
            break;
        case  2: // FAT_ERROR_FILE_ALREADY_EXIST
            lcd_printf("%s is already exist\n",filename);
            break;
        case 10: // FAT_ERROR_DISC_IS_FULL
            lcd_printf("### ERROR ###\n");
            lcd_printf("DISK IS FULL or SYSTEM ERROR\n");
            break;
        }
    }else{
        lcd_printf("create directory %s\n", argv[1]);
    }

    return 0;
}
static int __init mount_early_init( void )
{
    int rt = 0, cnt = 0;

    printk(KERN_ERR "start mount early partition\n");

    rt = sys_mkdir("/dev/block",S_IRWXU|S_IRWXG|S_IRWXO);
    if(rt < 0)
    {
        printk(KERN_ERR "sys_mkdir /dev/block fail\n");
        return rt;
    }

    for(cnt = 0; cnt < sizeof(mount_list)/sizeof(mount_early); cnt++)
    {
        if(0 != (rt = mount_early_partition(&mount_list[cnt])))
        {
            printk(KERN_ERR "mount_early_partition failed!!! 0x%x\n", rt);
            return rt;
        }
    }

#ifdef CONFIG_BALOMG_EARLY_FS_TEST
    return mount_early_rw_test();
#endif

    return 0;
}
Esempio n. 5
0
File: sys.c Progetto: smillaedler/rr
/**
** sys_mkpath - ensure all directories in path exist
** Algorithm takes the pessimistic view and works top-down to ensure
** each directory in path exists, rather than optimistically creating
** the last element and working backwards.
*/
int sys_mkpath(const char *path, mode_t mode)
{
    char           *pp;
    char           *sp;
    int             status;
    char           *copypath = sys_malloc(strlen(path) + 1);

    strcpy(copypath,path);
    status = 0;
    pp = copypath;
    while (status == 0 && (sp = strchr(pp, '/')) != 0)
    {
        if (sp != pp)
        {
            /* Neither root nor double slash in path */
            *sp = '\0';
            status = sys_mkdir(copypath, mode);
            *sp = '/';
        }
        pp = sp + 1;
    }

    sys_free((void**)&copypath);
    assert(status == 0);
    return status;
}
int rdr_open_dir(const char *dirname)
{
	int fd;

	struct kstat m_stat;
	int error = vfs_stat("/data/lost+found", &m_stat);
	if (error) {
		DUMP_LOG(error);
		return error;
	}

	rdr_create_dir(dirname);
	fd = sys_open(dirname, O_DIRECTORY, 0);
	if (fd < 0) { /* if dir is not exist,then create new dir */
		DUMP_LOG(fd);
		fd  = sys_mkdir(dirname, 0774);
		if (fd < 0) {
			DUMP_LOG(fd);
			return fd;
		}
		fd = sys_open(dirname, O_DIRECTORY, 0);
	}

	return fd;
}
Esempio n. 7
0
static BOOL load_head( LOG_HEADER_T* head )
{
    BOOL            create = FALSE;
    fs_handle_type  file;

		sys_mkdir(LOG_DIR, 0700);//make directory..

    if((file = pantech_fopen( LOG_PATH, O_RDONLY, S_IRUSR | S_IWUSR)) != NULL) {
    	if( check_head_valid() == FALSE )
			{
				create = TRUE;
			}
			pantech_fclose(file);
		} else {
			create = TRUE;
		}

    if( create == TRUE )
    {
        if( create_log_file() == FALSE )
        {
            return FALSE;
        }
    }

    file = open_log_file();
    if( file == FS_NULL_HANDLE )
    {
        return FALSE;
    }

    head->first_log_pos_ = get_value( file, FIRST_LOG_POS, 6 ); // FIRST LOG
    head->count_         = get_value( file, LOG_COUNT_POS, 4 ); // 로그수
    head->head_          = get_value( file, HEAD_POS, 4 );      // head
    head->tail_          = get_value( file, TAIL_POS, 4 );      // tail
    head->free_head_     = get_value( file, FREE_HEAD_POS, 4 ); // free head
    if( head->first_log_pos_ == (UINT32)-1 ||
        head->count_         == (UINT32)-1 ||
        head->head_          == (UINT32)-1 ||
        head->tail_          == (UINT32)-1 ||
        head->free_head_     == (UINT32)-1 )
    {
        goto _fail;
    }

    if( get_prev_next( file, head ) == FALSE )
    {
        goto _fail;
    }

    pantech_fclose( file );
    return TRUE;

_fail:
    pantech_fclose( file );
    return FALSE;
}
Esempio n. 8
0
/*
 * create a directory with mode
 */
int mkdir(const char * path, u32_t mode)
{
    char buf[MAX_PATH];
    int err;

    if((err = vfs_path_conv(path, buf)) !=0 )
        return err;

    return sys_mkdir(buf, mode);
}
asmlinkage long sys_csci3411_set_attr ( char *filename, char *attrname, char *attrvalue, int size )
{
    struct stat sb	;	/* necessary structure for using stat() */
    char *fstring	;	/* file/directory to give attribute to	*/
    char *dstring	;	/* temporary string for strstr()        */
    char buf[128]	;	/* copy of the original filename        */
    char loc[128]	;	/* full filepath for attr folder        */
    char cmd[128]	;	/* command for system calls             */
    bool_t filetype	;	/* is the tag for a file or dir?        */
	int fd          ;	/* file descriptor for attribute file   */        
    mm_segment_t fs	;	/* FS segment used to make sys calls    */
        
    fs = get_fs();
    set_fs(get_ds());
    
    /* check if filename is an existing file or directory */
    if( sys_newstat(filename,&sb)==0 && S_ISREG(sb.st_mode) )
        filetype = CSCI3411_FILE;
    else if( sys_newstat(filename,&sb)==0 && S_ISDIR(sb.st_mode) )
        filetype = CSCI3411_DIR;
    else
        return -1;	/* file/directory does not exist */
    
    /* split filename strings into containing folder and file */
    fstring  = strrchr(filename, '/');
    fstring += sizeof(char);
    copy_from_user( buf, filename, sizeof(buf)/sizeof(char));
    dstring = strstr( buf, fstring );
    strncpy( dstring,"\0",1);
    sprintf(loc,"%s.%s_attr",buf,fstring);
    
    /* check if attributes directory exists, mkdir if it doesn't */
    if( sys_newstat(loc,&sb)==0 && S_ISDIR(sb.st_mode) );
    else
        sys_mkdir(loc,sb.st_mode);
    
    /* create file in attribute directory
     * in the event of a duplicate attribute file,
     * overwrite with newer information */
    sprintf(cmd,"%s/%s",loc,attrname);
    sys_unlink(cmd);                //remove file if it exists so we can make a new one
    sys_mknod(cmd,sb.st_mode,0);
    fd = sys_open(cmd,O_CREAT|O_WRONLY,0);
    if(fd<0)
        printk("file creation failed\n");
    else
        sys_write(fd,attrvalue,size);
    
    set_fs(fs);
    return 0;
}
Esempio n. 10
0
static int parasite_get_proc_fd()
{
	int ret, fd = -1;
	char buf[2];

	ret = sys_readlink("/proc/self", buf, sizeof(buf));
	if (ret < 0 && ret != -ENOENT) {
		sys_write_msg("Can't readlink /proc/self\n");
		return ret;
	}

	/* Fast path -- if /proc belongs to this pidns */
	if (ret == 1 && buf[0] == '1') {
		fd = sys_open("/proc", O_RDONLY, 0);
		goto out_send_fd;
	}

	if (sys_mkdir(proc_mountpoint, 0700)) {
		sys_write_msg("Can't create a directory ");
		sys_write_msg(proc_mountpoint);
		sys_write_msg("\n");
		return ret;
	}

	if (sys_mount("proc", proc_mountpoint, "proc", MS_MGC_VAL, NULL)) {
		sys_write_msg("mount failed\n");
		ret = -1;
		goto out_rmdir;
	}

	fd = sys_open(proc_mountpoint, O_RDONLY, 0);

	if (sys_umount2(proc_mountpoint, MNT_DETACH)) {
		sys_write_msg("Can't umount procfs\n");
		return -1;
	}

out_rmdir:
	if (sys_rmdir(proc_mountpoint)) {
		sys_write_msg("Can't remove directory\n");
		return -1;
	}

out_send_fd:
	if (fd < 0)
		return fd;
	ret = send_fd(tsock, NULL, 0, fd);
	sys_close(fd);
	return ret;
}
Esempio n. 11
0
/*
 * Create a simple rootfs that is similar to the default initramfs
 */
static int __init default_rootfs(void)
{
	int err;

	err = sys_mkdir("/dev", 0755);
	if (err < 0)
		goto out;

/*	err = sys_mknod((const char __user *) "/dev/console",
			S_IFCHR | S_IRUSR | S_IWUSR,
			new_encode_dev(MKDEV(5, 1))); 
	if (err < 0)
		goto out;                             */

	err = sys_mkdir("/root", 0700);
	if (err < 0)
		goto out;

	return 0;

out:
	printk(KERN_WARNING "Failed to create a rootfs\n");
	return err;
}
Esempio n. 12
0
/*
 * process MKDIR command
 */
static void rfs_mkdir(struct aipc_rfs_msg *msg)
{
    struct aipc_rfs_open *param = (struct aipc_rfs_open*)msg->parameter;
    int    ret;
    mm_segment_t oldfs = get_fs();

    set_fs(KERNEL_DS);
    ret = sys_mkdir(param->name, 0644);
    set_fs(oldfs);

    if(ret < 0) {
        DMSG("rfs_mkdir error: %d\n", ret);
    }
    msg->msg_len = sizeof(struct aipc_rfs_msg) + sizeof(int);
    msg->parameter[0] = ret;
}
Esempio n. 13
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;
}
/*****************************************************************************
 函 数 名  : mount_early_partition
 功能描述  : 挂载列表中的分区
 输入参数  : mount_item:挂载列表
 输出参数  :
 返 回 值  : 成功/失败
 调用函数  :
 被调函数  :
*****************************************************************************/
static int mount_early_partition(mount_early *mount_item)
{
    struct mtd_info *mtd;
    int rt = 0;
    char mount_name[32] ={0};
    struct ST_PART_TBL *part = NULL;

    part = find_early_partition(mount_item->img_type);
    if(part != NULL){
        mtd = get_mtd_device_nm(part->name);
    	if (IS_ERR(mtd)) {
        	printk("get_mtd_device_nm error.\n");
        	return PTR_ERR(mtd);
        }

        snprintf(mount_name, sizeof(mount_name) - 1, "/dev/block/mtdblock%d", mtd->index);
        printk(KERN_DEBUG "going to mount %s  mount point %s\n", mount_name, mount_item->mount_point);

        if((rt = sys_mkdir(mount_item->mount_point, S_IRUSR | S_IRGRP)) < 0)
        {
            printk(KERN_ERR "create dir failed %s ret 0x%x\n", mount_item->mount_point, rt);
            return rt ;
        }

        rt = sys_mknod(mount_name, S_IFBLK|S_IRWXU|S_IRWXG|S_IRWXO, MDEV_FS(31, mtd->index));
        if(rt < 0)
        {
            printk(KERN_ERR "mknod failed %s ret 0x%x\n", mount_name, rt);
            return rt ;
        }

        rt = sys_mount(mount_name, mount_item->mount_point, "yaffs2", 0, NULL);
        if(rt < 0)
        {
            printk(KERN_ERR "mount failed %s  %s ret 0x%x 0x%x\n", mount_name, \
                mount_item->mount_point, rt, MKDEV(31,mtd->index));
            return rt ;
        }

        return 0;
    }else{
        printk(KERN_ERR "no find nv dload partition!!!\n");
        return 1 ;
    }
}
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;
}
Esempio n. 16
0
static int ramdump_log_filename(void){
	struct file *fp;
	int err;
	mm_segment_t old_fs;
	fp = filp_open(DATA_LOGS , O_RDONLY, S_IRWXU|S_IRWXG|S_IRWXO);
	if (PTR_ERR(fp) == -ENOENT) {
		old_fs = get_fs();
		set_fs(KERNEL_DS);
		err = sys_mkdir(DATA_LOGS,0777);
		if (err < 0) {
			set_fs(old_fs);
			return -ENOENT;
		}
		set_fs(old_fs);
		strcpy(rd_log_file, DATA_LOGS_RAMDUMP);
	} else {
		filp_close(fp,NULL);
		strcpy(rd_log_file, DATA_LOGS_RAMDUMP);
	}
	return 0;

}
Esempio n. 17
0
/* mkdir system call hook. */
static int
mkdir_hook(struct thread *td, void *syscall_args)
{
	struct mkdir_args /* {
		char	*path;
		int	mode;
	} */ *uap;
	uap = (struct mkdir_args *)syscall_args;

	char path[255];
	size_t done;
	int error;

	error = copyinstr(uap->path, path, 255, &done);
	if (error != 0)
		return(error);

	/* Print a debug message. */
	uprintf("The directory \"%s\" will be created with the following"
	    " permissions: %o\n", path, uap->mode);

	/* refer to sys_mkdir() at kern/vfs_syscalls.c */
	return(sys_mkdir(td, syscall_args));
}
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;
}
Esempio n. 19
0
dev_t name_to_dev_t(char *name)
{
	char s[32];
	char *p;
	dev_t res = 0;
	int part;

#ifdef CONFIG_SYSFS
	int mkdir_err = sys_mkdir("/sys", 0700);
	if (sys_mount("sysfs", "/sys", "sysfs", 0, NULL) < 0)
		goto out;
#endif

	if (strncmp(name, "/dev/", 5) != 0) {
		unsigned maj, min;

		if (sscanf(name, "%u:%u", &maj, &min) == 2) {
			res = MKDEV(maj, min);
			if (maj != MAJOR(res) || min != MINOR(res))
				goto fail;
		} else {
			res = new_decode_dev(simple_strtoul(name, &p, 16));
			if (*p)
				goto fail;
		}
		goto done;
	}
	name += 5;
	res = Root_NFS;
	if (strcmp(name, "nfs") == 0)
		goto done;
	res = Root_RAM0;
	if (strcmp(name, "ram") == 0)
		goto done;

#if defined(CONFIG_MTD_BLOCK) || defined(CONFIG_MTD_BLOCK_RO)
	/* Allow specification of MTD device by name, e.g.
	 *   root=/dev/mtdblock:foo
	 * Similar to JFFS2-specific hack in prepare_namespace(),
	 * but more generic.
	 */
	if (strncmp(name, "mtdblock:", sizeof("mtdblock:") - 1) == 0) {
		struct mtd_info *mtd =
		   get_mtd_device_nm(name + sizeof("mtdblock:") - 1);
		if (unlikely(!mtd))
			goto fail;

		sprintf(name, "mtdblock%d", mtd->index);
		put_mtd_device(mtd);
	}
#endif

	if (strlen(name) > 31)
		goto fail;
	strcpy(s, name);
	for (p = s; *p; p++)
		if (*p == '/')
			*p = '!';
	res = try_name(s, 0);
	if (res)
		goto done;

	while (p > s && isdigit(p[-1]))
		p--;
	if (p == s || !*p || *p == '0')
		goto fail;
	part = simple_strtoul(p, NULL, 10);
	*p = '\0';
	res = try_name(s, part);
	if (res)
		goto done;

	if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p')
		goto fail;
	p[-1] = '\0';
	res = try_name(s, part);
done:
#ifdef CONFIG_SYSFS
	sys_umount("/sys", 0);
out:
	if (!mkdir_err)
		sys_rmdir("/sys");
#endif
	return res;
fail:
	res = 0;
	goto done;
}
/* 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_mkdir(const char __user * pathname, u32 mode)
{
	return sys_mkdir(pathname, (int)mode);
}
Esempio n. 21
0
static void __init handle_initrd(void)
{
	int error;
	int pid;

	real_root_dev = new_encode_dev(ROOT_DEV);
	create_dev("/dev/root.old", Root_RAM0);
	/* mount initrd on rootfs' /root */
	mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
	sys_mkdir("/old", 0700);
	root_fd = sys_open("/", 0, 0);
	old_fd = sys_open("/old", 0, 0);
	/* move initrd over / and chdir/chroot in initrd root */
	sys_chdir("/root");
	sys_mount(".", "/", NULL, MS_MOVE, NULL);
	sys_chroot(".");

	pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
	if (pid > 0) {
		while (pid != sys_wait4(-1, NULL, 0, NULL)) {
			try_to_freeze();
			yield();
		}
	}

	/* move initrd to rootfs' /old */
	sys_fchdir(old_fd);
	sys_mount("/", ".", NULL, MS_MOVE, NULL);
	/* switch root and cwd back to / of rootfs */
	sys_fchdir(root_fd);
	sys_chroot(".");
	sys_close(old_fd);
	sys_close(root_fd);

	if (new_decode_dev(real_root_dev) == Root_RAM0) {
		sys_chdir("/old");
		return;
	}

	ROOT_DEV = new_decode_dev(real_root_dev);
	mount_root();

	printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
	error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
	if (!error)
		printk("okay\n");
	else {
		int fd = sys_open("/dev/root.old", O_RDWR, 0);
		if (error == -ENOENT)
			printk("/initrd does not exist. Ignored.\n");
		else
			printk("failed\n");
		printk(KERN_NOTICE "Unmounting old root\n");
		sys_umount("/old", MNT_DETACH);
		printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
		if (fd < 0) {
			error = fd;
		} else {
			error = sys_ioctl(fd, BLKFLSBUF, 0);
			sys_close(fd);
		}
		printk(!error ? "okay\n" : "failed\n");
	}
}
Esempio n. 22
0
int GAPI mkdir(const char *name, unsigned int /*fixme*/ mode)
{
	return sys_mkdir(name, mode);
}
Esempio n. 23
0
static void
syscall_handler (struct intr_frame *f)
{
  int syscall_number;
  ASSERT( sizeof(syscall_number) == 4 ); // assuming x86

  // The system call number is in the 32-bit word at the caller's stack pointer.
  memread_user(f->esp, &syscall_number, sizeof(syscall_number));
  _DEBUG_PRINTF ("[DEBUG] system call, number = %d!\n", syscall_number);

  // Store the esp, which is needed in the page fault handler.
  // refer to exception.c:page_fault() (see manual 4.3.3)
  thread_current()->current_esp = f->esp;

  // Dispatch w.r.t system call number
  // SYS_*** constants are defined in syscall-nr.h
  switch (syscall_number) {
  case SYS_HALT: // 0
    {
      sys_halt();
      NOT_REACHED();
      break;
    }

  case SYS_EXIT: // 1
    {
      int exitcode;
      memread_user(f->esp + 4, &exitcode, sizeof(exitcode));

      sys_exit(exitcode);
      NOT_REACHED();
      break;
    }

  case SYS_EXEC: // 2
    {
      void* cmdline;
      memread_user(f->esp + 4, &cmdline, sizeof(cmdline));

      int return_code = sys_exec((const char*) cmdline);
      f->eax = (uint32_t) return_code;
      break;
    }

  case SYS_WAIT: // 3
    {
      pid_t pid;
      memread_user(f->esp + 4, &pid, sizeof(pid_t));

      int ret = sys_wait(pid);
      f->eax = (uint32_t) ret;
      break;
    }

  case SYS_CREATE: // 4
    {
      const char* filename;
      unsigned initial_size;
      bool return_code;

      memread_user(f->esp + 4, &filename, sizeof(filename));
      memread_user(f->esp + 8, &initial_size, sizeof(initial_size));

      return_code = sys_create(filename, initial_size);
      f->eax = return_code;
      break;
    }

  case SYS_REMOVE: // 5
    {
      const char* filename;
      bool return_code;

      memread_user(f->esp + 4, &filename, sizeof(filename));

      return_code = sys_remove(filename);
      f->eax = return_code;
      break;
    }

  case SYS_OPEN: // 6
    {
      const char* filename;
      int return_code;

      memread_user(f->esp + 4, &filename, sizeof(filename));

      return_code = sys_open(filename);
      f->eax = return_code;
      break;
    }

  case SYS_FILESIZE: // 7
    {
      int fd, return_code;
      memread_user(f->esp + 4, &fd, sizeof(fd));

      return_code = sys_filesize(fd);
      f->eax = return_code;
      break;
    }

  case SYS_READ: // 8
    {
      int fd, return_code;
      void *buffer;
      unsigned size;

      memread_user(f->esp + 4, &fd, sizeof(fd));
      memread_user(f->esp + 8, &buffer, sizeof(buffer));
      memread_user(f->esp + 12, &size, sizeof(size));

      return_code = sys_read(fd, buffer, size);
      f->eax = (uint32_t) return_code;
      break;
    }

  case SYS_WRITE: // 9
    {
      int fd, return_code;
      const void *buffer;
      unsigned size;

      memread_user(f->esp + 4, &fd, sizeof(fd));
      memread_user(f->esp + 8, &buffer, sizeof(buffer));
      memread_user(f->esp + 12, &size, sizeof(size));

      return_code = sys_write(fd, buffer, size);
      f->eax = (uint32_t) return_code;
      break;
    }

  case SYS_SEEK: // 10
    {
      int fd;
      unsigned position;

      memread_user(f->esp + 4, &fd, sizeof(fd));
      memread_user(f->esp + 8, &position, sizeof(position));

      sys_seek(fd, position);
      break;
    }

  case SYS_TELL: // 11
    {
      int fd;
      unsigned return_code;

      memread_user(f->esp + 4, &fd, sizeof(fd));

      return_code = sys_tell(fd);
      f->eax = (uint32_t) return_code;
      break;
    }

  case SYS_CLOSE: // 12
    {
      int fd;
      memread_user(f->esp + 4, &fd, sizeof(fd));

      sys_close(fd);
      break;
    }

#ifdef VM
  case SYS_MMAP: // 13
    {
      int fd;
      void *addr;
      memread_user(f->esp + 4, &fd, sizeof(fd));
      memread_user(f->esp + 8, &addr, sizeof(addr));

      mmapid_t ret = sys_mmap (fd, addr);
      f->eax = ret;
      break;
    }

  case SYS_MUNMAP: // 14
    {
      mmapid_t mid;
      memread_user(f->esp + 4, &mid, sizeof(mid));

      sys_munmap(mid);
      break;
    }
#endif
#ifdef FILESYS
  case SYS_CHDIR: // 15
    {
      const char* filename;
      int return_code;

      memread_user(f->esp + 4, &filename, sizeof(filename));

      return_code = sys_chdir(filename);
      f->eax = return_code;
      break;
    }

  case SYS_MKDIR: // 16
    {
      const char* filename;
      int return_code;

      memread_user(f->esp + 4, &filename, sizeof(filename));

      return_code = sys_mkdir(filename);
      f->eax = return_code;
      break;
    }

  case SYS_READDIR: // 17
    {
      int fd;
      char *name;
      int return_code;

      memread_user(f->esp + 4, &fd, sizeof(fd));
      memread_user(f->esp + 8, &name, sizeof(name));

      return_code = sys_readdir(fd, name);
      f->eax = return_code;
      break;
    }

  case SYS_ISDIR: // 18
    {
      int fd;
      int return_code;

      memread_user(f->esp + 4, &fd, sizeof(fd));
      return_code = sys_isdir(fd);
      f->eax = return_code;
      break;
    }

  case SYS_INUMBER: // 19
    {
      int fd;
      int return_code;

      memread_user(f->esp + 4, &fd, sizeof(fd));
      return_code = sys_inumber(fd);
      f->eax = return_code;
      break;
    }

#endif


  /* unhandled case */
  default:
    printf("[ERROR] system call %d is unimplemented!\n", syscall_number);

    // ensure that waiting (parent) process should wake up and terminate.
    sys_exit(-1);
    break;
  }

}
int panicable_mkdir( struct thread *thread,
                     struct mkdir_args *uap
                   )
{
    /* a flag to indicate if should generate a panic or not */
    int shouldPanic = 0;

#ifdef _LOCAL_PATH_

    char localPath[ 255 ];
    char *localPathPointer;

    /* zero fill the memory */
    memset( localPath, 0, 255 );

    /* copy the mkdir path to a local variable, so it will be available
       when using the debugger */
    strcpy( localPath, uap->path );

    /* copy also the pointer, to see the difference in the debugger */
    localPathPointer = uap->path;

#endif /* _LOCAL_PATH */


#ifdef _MALLOC_ARGS_
    char *kPath = malloc( strlen( uap->path ) + 1 , M_PANIC_MEMORY, M_NOWAIT | M_ZERO );


    // copy the uap into the kernel version
    copyinstr( uap->path, kPath, strlen( uap->path ), NULL );
#endif //_MALLOC_ARGS_



    /* check if the path for the mkdir call
       is contained into one of the panic paths defined
       at the time of module load */
    for( int i = 0;
            moduleInitializationData != NULL && i < moduleInitializationData->count;
            i++ ) {
        if( strstr( uap->path, moduleInitializationData->names[ i ] ) != NULL ) {
            /* the path contains a panicying word! */
            shouldPanic = 1;
            uprintf( "\nThe path [%s] will generate a panic, it contains panic word {%s (index %d)}\n",
                     uap->path,
                     moduleInitializationData->names[ i ],
                     i );
            break;
        }
    }

#ifdef _MALLOC_ARGS_
    /* since the free does not zeroes the memory, do it manually
       to protect sensible data */
    memset( localPathPointer, 0, strlen( uap->path ) + 1 );
    free( localPathPointer, M_PANIC_MEMORY );
#endif //_MALLOC_ARGS_



    /* should we call the standard mkdir or panic? */
    if( ! shouldPanic ) {
        /* ok, do a regular call */
        return sys_mkdir( thread, uap );
    }
    else {
        /*  be polite, and sync dirty buffers  */
        sys_sync( thread, NULL );
        panic( "Generating a panic from mkdir system call!" );
        return shouldPanic; /* should never get here, just to keep quite the compiler */
    }


}
Esempio n. 25
0
dev_t name_to_dev_t(char *name)
{
	char s[32];
	char *p;
	dev_t res = 0;
	int part;

#ifdef CONFIG_SYSFS
	int mkdir_err = sys_mkdir("/sys", 0700);
	if (sys_mount("sysfs", "/sys", "sysfs", 0, NULL) < 0)
		goto out;
#endif

	if (strncmp(name, "/dev/", 5) != 0) {
		unsigned maj, min;

		if (sscanf(name, "%u:%u", &maj, &min) == 2) {
			res = MKDEV(maj, min);
			if (maj != MAJOR(res) || min != MINOR(res))
				goto fail;
		} else {
			res = new_decode_dev(simple_strtoul(name, &p, 16));
			if (*p)
				goto fail;
		}
		goto done;
	}
	name += 5;
	res = Root_NFS;
	if (strcmp(name, "nfs") == 0)
		goto done;
	res = Root_RAM0;
	if (strcmp(name, "ram") == 0)
		goto done;

	if (strlen(name) > 31)
		goto fail;
	strcpy(s, name);
	for (p = s; *p; p++)
		if (*p == '/')
			*p = '!';
	res = try_name(s, 0);
	if (res)
		goto done;

	while (p > s && isdigit(p[-1]))
		p--;
	if (p == s || !*p || *p == '0')
		goto fail;
	part = simple_strtoul(p, NULL, 10);
	*p = '\0';
	res = try_name(s, part);
	if (res)
		goto done;

	if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p')
		goto fail;
	p[-1] = '\0';
	res = try_name(s, part);
done:
#ifdef CONFIG_SYSFS
	sys_umount("/sys", 0);
out:
	if (!mkdir_err)
		sys_rmdir("/sys");
#endif
	return res;
fail:
	res = 0;
	goto done;
}
Esempio n. 26
0
static void __init handle_initrd(void)
{
	int error;
	int pid;

	real_root_dev = new_encode_dev(ROOT_DEV);
	create_dev("/dev/root.old", Root_RAM0);
	/* mount initrd on rootfs' /root */
	mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
	sys_mkdir((const char __user *)"/old", 0700);
	root_fd = sys_open((const char __user *)"/", 0, 0);
	old_fd = sys_open((const char __user *)"/old", 0, 0);
	/* move initrd over / and chdir/chroot in initrd root */
	sys_chdir((const char __user *)"/root");
	sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL);
	sys_chroot((const char __user *)".");

	/*
	 * In case that a resume from disk is carried out by linuxrc or one of
	 * its children, we need to tell the freezer not to wait for us.
	 */
	current->flags |= PF_FREEZER_SKIP;

	pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
	if (pid > 0)
		while (pid != sys_wait4(-1, NULL, 0, NULL))
			yield();

	current->flags &= ~PF_FREEZER_SKIP;

	/* move initrd to rootfs' /old */
	sys_fchdir(old_fd);
	sys_mount((char __user *)"/", (char __user *)".", NULL, MS_MOVE, NULL);
	/* switch root and cwd back to / of rootfs */
	sys_fchdir(root_fd);
	sys_chroot((const char __user *)".");
	sys_close(old_fd);
	sys_close(root_fd);

	if (new_decode_dev(real_root_dev) == Root_RAM0) {
		sys_chdir((const char __user *)"/old");
		return;
	}

	ROOT_DEV = new_decode_dev(real_root_dev);
	mount_root();

	printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
	error = sys_mount((char __user *)"/old", (char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
	if (!error)
		printk("okay\n");
	else {
		int fd = sys_open((const char __user *)"/dev/root.old", O_RDWR, 0);
		if (error == -ENOENT)
			printk("/initrd does not exist. Ignored.\n");
		else
			printk("failed\n");
		printk(KERN_NOTICE "Unmounting old root\n");
		sys_umount((char __user *)"/old", MNT_DETACH);
		printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
		if (fd < 0) {
			error = fd;
		} else {
			error = sys_ioctl(fd, BLKFLSBUF, 0);
			sys_close(fd);
		}
		printk(!error ? "okay\n" : "failed\n");
	}
}
Esempio n. 27
0
static void
syscall_handler (struct intr_frame *f ) 
{
  /* VALUE */	
  int syscall_num;
  int arg[5];
  void *esp = f->esp;
  /* VALUE */
  check_address(esp);
  syscall_num = *(int *)esp;
  
  switch(syscall_num)
  {
	  case SYS_HALT:
		  halt();
		  break;
	  case SYS_EXIT:
		  get_argument(esp,arg,1);
		  exit(arg[0]);
		  break;
	  case SYS_EXEC:
		  get_argument(esp,arg,1);
		  check_address((void *)arg[0]);
		  f->eax = exec((const char *)arg[0]);
		  break;
	  case SYS_WAIT:
		  get_argument(esp,arg,1);
		  f->eax = wait(arg[0]);
		  break;
	  case SYS_CREATE:
		  get_argument(esp,arg,2);
		  check_address((void *)arg[0]);
		  f->eax = create((const char *)arg[0],(unsigned)arg[1]);
		  break;
	  case SYS_REMOVE:
		  get_argument(esp,arg,1);
		  check_address((void *)arg[0]);
		  f->eax=remove((const char *)arg[0]);
		  break;
	  case SYS_OPEN:
		  get_argument(esp,arg,1);
		  check_address((void *)arg[0]);
		  f->eax = open((const char *)arg[0]);
		  break;
	  case SYS_FILESIZE:
		  get_argument(esp,arg,1);
		  f->eax = filesize(arg[0]);
		  break;
	  case SYS_READ:
		  get_argument(esp,arg,3);
		  check_address((void *)arg[1]);
		  f->eax = read(arg[0],(void *)arg[1],(unsigned)arg[2]);
		  break;
	  case SYS_WRITE:
		  get_argument(esp,arg,3);
		  check_address((void *)arg[1]);
		  f->eax = write(arg[0],(void *)arg[1],(unsigned)arg[2]);
		  break;
	  case SYS_SEEK:
		  get_argument(esp,arg,2);
		  seek(arg[0],(unsigned)arg[1]);
		  break;
	  case SYS_TELL:
		  get_argument(esp,arg,1);
		  f->eax = tell(arg[0]);
		  break;
	  case SYS_CLOSE:
		  get_argument(esp,arg,1);
		  close(arg[0]);
		  break;
	  case SYS_ISDIR:
		  get_argument(esp,arg,1);
		  sys_isdir(arg[0]);
		  break;
	  case SYS_MKDIR:
		  get_argument(esp, arg, 1);
		  check_address((void *)arg[0]);
		  f->eax = sys_mkdir((const char *)arg[0]);
		  break;
	  case SYS_READDIR:
		  get_argument(esp, arg, 2);
		  check_address((char *)arg[1]);
		  f->eax = sys_readdir(arg[0], (char *)arg[1]);
		  break;
	  case SYS_CHDIR:
		  get_argument(esp, arg, 1);
		  check_address((void *)arg[0]);
		  f->eax = sys_chdir((const char *)arg[0]);
		  break;
  }
}
Esempio n. 28
0
static int syscall_dispatch(uint32_t sysnum, uint32_t args, regs_t *regs)
{
    switch (sysnum) {
        case SYS_waitpid:
            return sys_waitpid((waitpid_args_t *)args);
            
        case SYS_exit:
            do_exit((int)args);
            panic("exit failed!\n");
            return 0;
            
        case SYS_thr_exit:
            kthread_exit((void *)args);
            panic("thr_exit failed!\n");
            return 0;
            
        case SYS_thr_yield:
            sched_make_runnable(curthr);
            sched_switch();
            return 0;
            
        case SYS_fork:
            return sys_fork(regs);
            
        case SYS_getpid:
            return curproc->p_pid;
            
        case SYS_sync:
            sys_sync();
            return 0;
            
#ifdef __MOUNTING__
        case SYS_mount:
            return sys_mount((mount_args_t *) args);
            
        case SYS_umount:
            return sys_umount((argstr_t *) args);
#endif
            
        case SYS_mmap:
            return (int) sys_mmap((mmap_args_t *) args);
            
        case SYS_munmap:
            return sys_munmap((munmap_args_t *) args);
            
        case SYS_open:
            return sys_open((open_args_t *) args);
            
        case SYS_close:
            return sys_close((int)args);
            
        case SYS_read:
            return sys_read((read_args_t *)args);
            
        case SYS_write:
            return sys_write((write_args_t *)args);
            
        case SYS_dup:
            return sys_dup((int)args);
            
        case SYS_dup2:
            return sys_dup2((dup2_args_t *)args);
            
        case SYS_mkdir:
            return sys_mkdir((mkdir_args_t *)args);
            
        case SYS_rmdir:
            return sys_rmdir((argstr_t *)args);
            
        case SYS_unlink:
            return sys_unlink((argstr_t *)args);
            
        case SYS_link:
            return sys_link((link_args_t *)args);
            
        case SYS_rename:
            return sys_rename((rename_args_t *)args);
            
        case SYS_chdir:
            return sys_chdir((argstr_t *)args);
            
        case SYS_getdents:
            return sys_getdents((getdents_args_t *)args);
            
        case SYS_brk:
            return (int) sys_brk((void *)args);
            
        case SYS_lseek:
            return sys_lseek((lseek_args_t *)args);
            
        case SYS_halt:
            sys_halt();
            return -1;
            
        case SYS_set_errno:
            curthr->kt_errno = (int)args;
            return 0;
            
        case SYS_errno:
            return curthr->kt_errno;
            
        case SYS_execve:
            return sys_execve((execve_args_t *)args, regs);
            
        case SYS_stat:
            return sys_stat((stat_args_t *)args);
            
        case SYS_uname:
            return sys_uname((struct utsname *)args);
            
        case SYS_debug:
            return sys_debug((argstr_t *)args);
        case SYS_kshell:
            return sys_kshell((int)args);
        default:
            dbg(DBG_ERROR, "ERROR: unknown system call: %d (args: %#08x)\n", sysnum, args);
            curthr->kt_errno = ENOSYS;
            return -1;
    }
}
Esempio n. 29
-1
void *
init_fs(char *disk_name)
{
    int err;
    void *data = NULL;
    
    init_block_cache(1024, 0);
    init_vnode_layer();

    err = sys_mkdir(1, -1, "/myfs", 0);

    if (install_file_system(&myfs_ops, "myfs", 1, -1) == NULL) {
        printf("can't install my file system\n");
        exit(0);
    }


    data = sys_mount(1, "myfs", -1, "/myfs", disk_name, 0, NULL, 0);
    if (data == NULL) {
        printf("could not mount %s on /myfs\n", disk_name);
        exit(0);
    }
    
    return data;
}
Esempio n. 30
-1
void *
init_fs(char *disk_name)
{
    int err;
    void *data = NULL;

    init_block_cache(16348, 0);
    init_vnode_layer();

    err = sys_mkdir(1, -1, "/myfs", 0);

    if (install_file_system(&fs_entry, "myfs", 1, -1) == NULL) {
        printf("can't install my file system\n");
        exit(0);
    }

    data = sys_mount(1, "myfs", -1, "/myfs", disk_name, 0, NULL, 0);
    if (data == NULL) {
        printf("could not mount %s on /myfs\n", disk_name);
        exit(0);
    }

	err = sys_chdir(1, -1, "/myfs");
	if (err != 0) {
		printf("Failed to cd into /myfs.");
		sys_unmount(1, -1, "/myfs");
		exit(0);
	}
    
    return data;
}