Example #1
0
int
cloudabi_sys_fd_sync(struct thread *td, struct cloudabi_sys_fd_sync_args *uap)
{
	struct fsync_args fsync_args = {
		.fd = uap->fd
	};

	return (sys_fsync(td, &fsync_args));
}
int mntn_do_save_virtual_addr_log(unsigned char *viradd, unsigned int ulen, const char *ppath, const char *pfilename)
{
    int iret = 0;
    char    fullpath_arr[MNTN_FULLPATH_STRING_LEN + 1] = {0};
    long	fd = 0;
     int    bytes = 0;
    unsigned char    *pdatabuf = viradd;
    mm_segment_t old_fs = 0;

    if (NULL == pdatabuf || NULL == viradd || NULL == pfilename)
    {
        MNTN_FILESYS_PRINT(KERN_ERR"mntn_err: some parameter is NULL!\n");
        return -1;
    }   

    MNTN_FILESYS_PRINT(KERN_ERR"mntn_do_save_virtual_addr_log: viradd %p, length is %d\n", viradd, ulen);
    /*Write reset reason into history.log*/
    memset(fullpath_arr, 0, MNTN_FULLPATH_STRING_LEN);
    strncat(fullpath_arr, ppath, strlen(ppath));
    strncat(fullpath_arr, pfilename, strlen(pfilename));
    old_fs = get_fs();
    set_fs(KERNEL_DS);
    fd = sys_open(fullpath_arr, O_CREAT | O_RDWR, MNTN_LOG_FILE_PRO_VALUE);
    if (fd < 0)
    {
        MNTN_FILESYS_PRINT(KERN_ERR"mntn_err: Fail to open %s!, fd %lx\n", pfilename, fd);
	 set_fs(old_fs);
	 iret = -1;
	 goto oper_over2;
    }
   
    bytes = sys_write(fd, (void*)pdatabuf, ulen);
    if (bytes != ulen) 
    {
        MNTN_FILESYS_PRINT(KERN_ERR"mntn_err: Fail to write all the data into the file, %d/%d\n", bytes, ulen);
	 iret = -1;
	 goto oper_over1;
    }
    iret = sys_fsync(fd);
    if (iret < 0) 
    {
        MNTN_FILESYS_PRINT(KERN_ERR"mntn_err: Fail to sys_fsync data\n");
	 goto oper_over1;
    }
    iret += mntn_filesys_chown((const char *)fullpath_arr, MNTN_LOG_FILE_OWNER_UID, MNTN_LOG_FILE_OWNER_GID);
    if (0 != iret)
    {
        MNTN_FILESYS_PRINT(KERN_ERR"mntn_err: Fail to chown history.log!\n");
    }

oper_over1:
    (void)sys_close((unsigned int)fd);
oper_over2:
    set_fs(old_fs);
    MNTN_FILESYS_PRINT(KERN_ERR"mntn_do_save_virtual_addr_log: over\n");
    return iret;
}
Example #3
0
/*
 * This is just fsync() for now (just as it is in the Linux kernel)
 * Note: this is not implemented under Linux on Alpha and Arm
 *	but should still be defined in our syscalls.master.
 *	(syscall #148 on the arm)
 */
int
linux_sys_fdatasync(struct lwp *l, const struct linux_sys_fdatasync_args *uap, register_t *retval)
{
	/* {
		syscallarg(int) fd;
	} */

	return sys_fsync(l, (const void *)uap, retval);
}
Example #4
0
/** Handler for syncing in a FAF open file.
 *  @author Renaud Lottiaux
 *
 *  @param from    Node sending the request
 *  @param msgIn   Request message
 */
int handle_faf_fsync (struct rpc_desc* desc,
                      void *msgIn, size_t size)
{
	struct faf_rw_msg *msg = msgIn;
	long r = -EINVAL;

	r = sys_fsync (msg->server_fd);

	return r;
}
 static int apds9130_backup_crosstalk_data_fs(unsigned int val)
{
	int fd;
	int ret = 0;
	char buf[50];
    int count = 0;

	mm_segment_t old_fs = get_fs();

	memset(buf, 0, sizeof(buf));
	sprintf(buf, "%d", val);

	printk(KERN_INFO"%s Enter\n", __FUNCTION__ );
	printk(KERN_INFO"%s\n", buf);

	set_fs(KERNEL_DS);

/*[LGE_BSP_START][[email protected]] 2012-11-08 change save path*/
#if defined(APDS9130_PROXIMITY_CAL)
    fd = sys_open("/mpt/prox_calibration.dat",O_WRONLY|O_CREAT, 0664);
#else
    fd = sys_open("/persist/prox_calibration.dat",O_WRONLY|O_CREAT, 0664);
#endif
/*[LGE_BSP_END][[email protected]] 2012-11-08 change save path*/
	if(fd >=0)
	{
        printk(KERN_INFO"[%s]Calibration File Open Success", __func__);
        while((sys_write(fd,buf,sizeof(buf)) != sizeof(buf)) && (count < 3)) 
        {
            count++;
            msleep(100);
        }
        sys_fsync(fd);
        sys_close(fd);
        set_fs(old_fs);
        
        if(count == 3)
        {
            return -1;
        }
        
	}
	else
	{
        printk(KERN_ERR"[%s]fd open fail!!! fd = %d  ", __func__, fd);
        ret = -1;
        sys_close(fd);
        set_fs(old_fs);
        return ret;
	}

    return ret;
}
Example #6
0
/*
 * flush file system buffers by file descriptor.
 */
int fsync(int fd)
{
	struct file_t * fp;

	if(fd < 0)
		return -1;

	if((fp = get_fp(fd)) == NULL)
		return -1;

	return sys_fsync(fp);
}
Example #7
0
int
cloudabi_sys_fd_seek(struct thread *td, struct cloudabi_sys_fd_seek_args *uap)
{
	struct lseek_args lseek_args = {
		.fd	= uap->fd,
		.offset	= uap->offset
	};

	switch (uap->whence) {
	case CLOUDABI_WHENCE_CUR:
		lseek_args.whence = SEEK_CUR;
		break;
	case CLOUDABI_WHENCE_END:
		lseek_args.whence = SEEK_END;
		break;
	case CLOUDABI_WHENCE_SET:
		lseek_args.whence = SEEK_SET;
		break;
	default:
		return (EINVAL);
	}

	return (sys_lseek(td, &lseek_args));
}

int
cloudabi_sys_fd_stat_get(struct thread *td,
    struct cloudabi_sys_fd_stat_get_args *uap)
{

	/* Not implemented. */
	return (ENOSYS);
}

int
cloudabi_sys_fd_stat_put(struct thread *td,
    struct cloudabi_sys_fd_stat_put_args *uap)
{

	/* Not implemented. */
	return (ENOSYS);
}

int
cloudabi_sys_fd_sync(struct thread *td, struct cloudabi_sys_fd_sync_args *uap)
{
	struct fsync_args fsync_args = {
		.fd = uap->fd
	};

	return (sys_fsync(td, &fsync_args));
}
int rdr_loopwrite_close(int fd)
{
	int ret;
	sys_fsync(fd);
	ret = sys_close(fd);
	if (0 != ret) {
		pr_err("<%s()>, close failed! ret = %d\n", __func__, ret);
		ret = -1;
		goto out;
	}
out:
	return ret;
}
int rdr_save_8m(const char *dir, const char *name, char *postfix,
			const void *address, u32 length)
{
	int fd;
	long bytes;
	mm_segment_t old_fs;
	char xname[RDR_FNAME_LEN] = {0};

	if (NULL == dir || NULL == name || postfix == NULL) {
		pr_err("rdr:%s():file name and dir shouldnt null\n", __func__);
		return -1;
	}

	if ((strlen((const char *)dir) + strlen((const char *)name) +
		strlen(postfix) + 1) >= RDR_FNAME_LEN) {
		pr_err("rdr:%s():error:dir is too long, exit.\n", __func__);
		return -1;
	}

	old_fs = get_fs();
	set_fs(KERNEL_DS);

	memset(xname, 0, sizeof(xname));
	snprintf(xname, sizeof(xname), "%s%s/", dir, name);
	rdr_create_dir(xname);
	memset(xname, 0, sizeof(xname));
	snprintf(xname, sizeof(xname), "%s%s/%s.bin", dir, name, postfix);

	fd = sys_creat(xname, 0644);
	if (fd < 0) {
		pr_err("rdr:%s():create file %s err.\n", __func__, xname);
		set_fs(old_fs);
		return -1;
	}

	bytes = sys_write((unsigned int)fd, (const char *)address, length);
	if ((u32)bytes != length) {
		DUMP_LOG((int)bytes);
		rdr_file_close(fd);
		set_fs(old_fs);
		return -1;
	}
	sys_fsync(fd);
	rdr_file_close(fd);
	set_fs(old_fs);
	pr_info("rdr:save file %s success ...", xname);

	return 0;
}
static void rdr_audio_loopwrite_close(int fd)
{
	int ret = 0;

	BUG_ON(fd < 0);

	ret = sys_fsync(fd);
	if (ret < 0)
		pr_err("[%s]sys_fsync failed, ret is %d\n", __func__, ret);

	ret = sys_close(fd);
	if (ret)
		BB_PRINT_ERR("close file failed, ret: %d\n", ret);

	return;
}
Example #11
0
/*****************************************************************************
* 函 数 名  : file_save
*
* 功能描述  : 将指定地址数据保存到文件中
*
* 输入参数  : u32 export_file_name     导出文件名称
*             u32 export_virt_addr     导出数据虚拟地址
*             u32 count                导出数据大小
*
* 返 回 值  : s32  返回值:0为成功,-1为失败。
*
* 修改记录  : 2012年11月27日
*****************************************************************************/
long file_save(char* export_file_name, u32 export_virt_addr, u32 count)
{
    long ret = 0;
    long len = 0;
    unsigned int  fd = 0;

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

    ret = sys_open(export_file_name, O_RDWR | O_CREAT, 0666);

    if(ret < 0)
    {
        printk("open file %s error,ret:%#x\n",  export_file_name, fd);

        /*sys_fsync(fd);*/

        set_fs(old_fs);

        return -1;
    }

    fd = (unsigned int)ret;

    len = sys_write(fd,(char*)export_virt_addr,count);

    if(count != (unsigned long)len)
    {
        ret = -1;
        printk("write err, writlen=0x%x, wantted len=0x%x\n", (u32)len, (u32)count);
    }
    else
    {
        ret = 0;
        printk("save to %s success\n, pls use lsz %s to upload to securecrt\n", export_file_name, export_file_name);
    }

    sys_fsync(fd);

    set_fs(old_fs);

    return ret;

}
Example #12
0
int
cloudabi_sys_fd_datasync(struct thread *td,
    struct cloudabi_sys_fd_datasync_args *uap)
{
	struct fsync_args fsync_args = {
		.fd = uap->fd
	};

	/* Call into fsync(), as FreeBSD lacks fdatasync(). */
	return (sys_fsync(td, &fsync_args));
}

int
cloudabi_sys_fd_dup(struct thread *td, struct cloudabi_sys_fd_dup_args *uap)
{

	return (kern_dup(td, FDDUP_NORMAL, 0, uap->from, 0));
}

int
cloudabi_sys_fd_replace(struct thread *td,
    struct cloudabi_sys_fd_replace_args *uap)
{
	int error;

	/*
	 * CloudABI's equivalent to dup2(). CloudABI processes should
	 * not depend on hardcoded file descriptor layouts, but simply
	 * use the file descriptor numbers that are allocated by the
	 * kernel. Duplicating file descriptors to arbitrary numbers
	 * should not be done.
	 *
	 * Invoke kern_dup() with FDDUP_MUSTREPLACE, so that we return
	 * EBADF when duplicating to a nonexistent file descriptor. Also
	 * clear the return value, as this system call yields no return
	 * value.
	 */
	error = kern_dup(td, FDDUP_MUSTREPLACE, 0, uap->from, uap->to);
	td->td_retval[0] = 0;
	return (error);
}
Example #13
0
int
fsync(int fd) {
    return sys_fsync(fd);
}
/*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;
}
/*
 * Will be obsoleted ...
 */
int rdr_save_file(const char *dir, const char *file_header,
			const void *address, u32 length)
{
	int fd, ret;
	long bytes;
	mm_segment_t old_fs;
	char new_filename[RDR_FNAME_LEN] = {0};

	if (NULL == dir || NULL == file_header) {
		DUMP_LOG(0);
		return -1;
	}

	if ((strlen((const char *)dir) + strlen((const char *)file_header))
				>= RDR_FNAME_LEN) {
		DUMP_LOG(0);
		return -1;
	}

	old_fs = get_fs();
	set_fs(KERNEL_DS);

	fd = rdr_open_dir(dir);
	if (fd < 0) {
		DUMP_LOG(fd);
		set_fs(old_fs);
		return -1;
	}

	ret = del_old_file(dir, file_header, (unsigned int)fd, file_header);
	if (0 != ret) {
		DUMP_LOG(ret);
		rdr_file_close(fd);
		set_fs(old_fs);
		return -1;
	}

	rdr_file_close(fd);

	memset(new_filename, 0, sizeof(new_filename));
	snprintf(new_filename, sizeof(new_filename), "%s%s%02d.bin",
			dir, file_header, 0);

	fd = sys_creat(new_filename, 0644);
	if (fd < 0) {
		DUMP_LOG(fd);
		set_fs(old_fs);
		return -1;
	}

	bytes = sys_write((unsigned int)fd, (const char *)address, length);
	if ((u32)bytes != length) {
		DUMP_LOG((int)bytes);
		rdr_file_close(fd);
		set_fs(old_fs);
		return -1;
	}
	sys_fsync(fd);
	rdr_file_close(fd);
	set_fs(old_fs);
	pr_info("rdr:save file %s success ...", new_filename);

	return 0;
}