static int read_eri(const char *path, eri_read_req_type* read_req_ptr, eri_read_rsp_type* read_rsp_ptr)
{
    int read;
//	size_t count;
    int read_size;
//	int ret;

    mm_segment_t oldfs;

#ifdef DEBUG_ERI
    printk(KERN_ERR "%s, UTS ERI READ Test START\n",__func__);
#endif

    oldfs = get_fs();
    set_fs(KERNEL_DS);

    memset(eri_buf,0,sizeof(byte) * 1400);

    read = sys_open((const char __user *)path, O_RDONLY , 0);

    if(read < 0) {
#ifdef DEBUG_ERI
        printk(KERN_ERR "%s, ERI File Open Fail\n",__func__);
#endif
        return -1;
    } else {
#ifdef DEBUG_ERI
        printk(KERN_ERR "%s, ERI File Open Success\n",__func__);
#endif
    }

    read_size = 0;

    while(sys_read(read, &eri_buf[read_size++], 1) == 1) {}

    memcpy(read_rsp_ptr->eri_data.user_eri_data, eri_buf, read_size);

    if(read_size <= 0) {
#ifdef DEBUG_ERI
        printk(KERN_ERR "%s, ERI File Read Fail\n",__func__);
#endif
        read_rsp_ptr->cmd_code = read_req_ptr->cmd_code;
        read_rsp_ptr->sub_cmd_code = read_req_ptr->sub_cmd_code;
        read_rsp_ptr->eri_data.eri_size = 0;
        read_rsp_ptr->status = 1;
    } else {
#ifdef DEBUG_ERI
        printk(KERN_ERR "%s, UTS ERI READ Test Make Rsp PACK\n",__func__);
#endif
        read_rsp_ptr->cmd_code = read_req_ptr->cmd_code;
        read_rsp_ptr->sub_cmd_code = read_req_ptr->sub_cmd_code;
        read_rsp_ptr->eri_data.eri_size = read_size - 1;
        read_rsp_ptr->status = 0;
    }
    set_fs(oldfs);
    sys_close(read);
    return read_size;
}
Example #2
0
static double read_value(int fd) {
  double value = 0.0;

  if (fd != SYSTEM_FD_INVALID) {
    sys_read(fd, (char*)&value, sizeof(double));
  }

  return value;
}
Example #3
0
ssize_t vfswrap_read(vfs_handle_struct *handle, files_struct *fsp, int fd, void *data, size_t n)
{
	ssize_t result;

	START_PROFILE_BYTES(syscall_read, n);
	result = sys_read(fd, data, n);
	END_PROFILE(syscall_read);
	return result;
}
Example #4
0
/* 565RLE image format: [count(2 bytes), rle(2 bytes)] */
int load_565rle_image(char *filename)
{
	struct fb_info *info;
	int fd, count, err = 0;
	unsigned max;
	unsigned short *data, *bits, *ptr;

	info = registered_fb[0];
	if (!info) {
		printk(KERN_WARNING "%s: Can not access framebuffer\n",
			__func__);
		return -ENODEV;
	}

	fd = sys_open(filename, O_RDONLY, 0);
	if (fd < 0) {
		printk(KERN_WARNING "%s: Can not open %s\n",
			__func__, filename);
		return -ENOENT;
	}
	count = sys_lseek(fd, (off_t)0, 2);
	if (count <= 0) {
		err = -EIO;
		goto err_logo_close_file;
	}
	sys_lseek(fd, (off_t)0, 0);
	data = kmalloc(count, GFP_KERNEL);
	if (!data) {
		printk(KERN_WARNING "%s: Can not alloc data\n", __func__);
		err = -ENOMEM;
		goto err_logo_close_file;
	}
	if (sys_read(fd, (char *)data, count) != count) {
		err = -EIO;
		goto err_logo_free_data;
	}

	max = fb_width(info) * fb_height(info);
	ptr = data;
	bits = (unsigned short *)(info->screen_base);
	while (count > 3) {
		unsigned n = ptr[0];
		if (n > max)
			break;
		memset16(bits, ptr[1], n << 1);
		bits += n;
		max -= n;
		ptr += 2;
		count -= 4;
	}

err_logo_free_data:
	kfree(data);
err_logo_close_file:
	sys_close(fd);
	return err;
}
// jprimero: these two battery functions should be replaced by the actual
// battery driver and should avoid reading the battery tempeature through sysfs
static int batt_get_temp(void *dev_data, long *temp)
{
    int ret = 0;
    //fd, count;
    //char buf[64];
    //mm_segment_t old_fs;
    long btemp;

    #if 0
    old_fs = get_fs();
    set_fs(KERNEL_DS);
    fd = sys_open("/sys/class/power_supply/battery/temp", O_RDONLY, 0644);
    
    if (fd >= 0) {
		count = sys_read(fd, buf, 64);
		if (count < 64)
			buf[count]='\0';
		ret = kstrol(buf, 10, &btemp);
		sys_close(fd);

		*temp = btemp*100; // jprimero: return temperature in millicelsius
		} else {
		    ret = -1;
		}
		
    set_fs(old_fs);
    #else
    #if 1
    //printk("*****btemp = %d***tps80031_init_flag = %d***\n",btemp,tps80031_init_flag);
    if(tps80031_init_flag)
    {
         //printk("****tps80031_get_battery_temp****\n");
         btemp = tps80031_get_battery_temp();   
    }
    else
    {
         ret = 0;
	  //printk("****228****\n");
	  	 *temp = -50000;
         return ret; 
    }
    
    if(btemp < 0)
    {
         ret = -16;
    }
    else
    {
         *temp = btemp*100;
	  //printk("******temp = %d******\n",btemp*100);
    }
    #endif
	#endif
    //printk("****241****\n");
	
    return ret;
}
Example #6
0
// yeah, lets do it
void killme()
{
char c='a';
int pid;

pid = sys_getpid();
for(;;) {
sys_read(0, &c, 1);
sys_kill(pid, 11);
}
}
static void slot_switch_init_work(struct work_struct *work)
{
	struct delayed_work *dw = container_of(work, struct delayed_work, work);
	struct slot_switch_wq *wq = container_of(dw, struct slot_switch_wq, work_q);
//	struct fsa9480_info *usbsw = wq->sdata;
	int fd;
	int ret;
	char buffer[2]={0};
	mm_segment_t fs;

	printk("[slot switch]: %s :: \n",__func__);

	fs = get_fs();
	set_fs(get_ds());

	if ((fd = sys_open("/efs/slot_switch.bin", O_CREAT|O_RDWR  ,0664)) < 0)
	{
		schedule_delayed_work(&wq->work_q, msecs_to_jiffies(2000));
		printk("[slot switch]: %s :: open failed %s ,fd=0x%x\n",__func__,"/efs/slot_switch.bin",fd);

		if(fd < 0){
			sys_close(fd);
			set_fs(fs);

		}
	} else {
		cancel_delayed_work(&wq->work_q);
		printk("[slot switch]: %s :: open success %s ,fd=0x%x\n",__func__,"/efs/slot_switch.bin",fd);
	}

	ret = sys_read(fd, buffer, 1);
	if(ret < 0) {
		printk("slot_switch READ FAIL!\n");
		sys_close(fd);
		set_fs(fs);
		return;
	}

	printk("slot switch buffer : %s\n", buffer);
#if 0//!defined(CONFIG_MACH_MELIUS_CHN_CTC) && !defined(CONFIG_MACH_CRATER_CHN_CTC)
	if (!strcmp(buffer, "0"))//SPRD
	{
		gpio_set_value(GPIO_SIM_SEL, 0);
		printk("set slot switch to %x\n", gpio_get_value(GPIO_SIM_SEL));
	} else if(!strcmp(buffer, "1")){//BCOM
		gpio_set_value(GPIO_SIM_SEL, 1);
		printk("set slot switch to %x\n", gpio_get_value(GPIO_SIM_SEL));
	}
#endif
	sys_close(fd);
	set_fs(fs);

	return;
}
Example #8
0
asmlinkage ssize_t sys_pread(unsigned int fd, char * buf,
			     size_t count, loff_t pos)
{
	ssize_t ret;
	struct file * file;
	struct vms_fd * vms_fd;
	ssize_t (*read)(struct file *, char *, size_t, loff_t *);

	ret = -EBADF;
	vms_fd = fget(fd);
	file = vms_fd->vfd$l_fd_p;
#if 0
	if (file && ((struct _fcb *)(file))->fcb$b_type==DYN$C_FCB)
	  goto do_fcb;
#else
	struct _rabdef * rab = file; // fget(fd);
	loff_t curpos =  512*(rab->rab$w_rfa[2] + (rab->rab$w_rfa[1] << 16)) + rab->rab$w_rfa[0];
#define SEEK_SET 0
	sys_lseek(fd, pos, SEEK_SET);
	ret = sys_read(fd, buf, count);
	sys_lseek(fd, curpos, SEEK_SET);
	return ret;
#endif
	if (!file)
		goto bad_file;
	if (!(file->f_mode & FMODE_READ))
		goto out;
	ret = -EINVAL;
	if (!file->f_op || !(read = file->f_op->read))
		goto out;
	if (pos < 0)
		goto out;
	ret = read(file, buf, count, &pos);
out:
bad_file:
	return ret;
#if 0
 do_fcb:
	{}

	struct _fcb * fcb;
	unsigned long offset;

	ret = -EBADF;
	file = fget(fd);
	fcb = file;
	offset = pos;
	ret = rms_kernel_read(file, offset, buf, count);
#if 0
	fcb->fcb$l_reserve1 += ret;
#endif
	return ret;
#endif
}
Example #9
0
void TestA()
{
    int ret;
    /*printk("-----------------------------------------\n");*/
    int fd = open("/",0,0);
    if(fd < 0)
    {
        printk("open error. fd = %d.", fd);
    }
    close(fd);

    struct m_inode *inode;
    fd = open("/sunkang",0,O_CREAT);
    if(fd < 0)
    {
        printk("open error. fd = %d.", fd);
    }
    else
    {
        inode = current->filp[fd]->f_inode;
        printk("sunkang inode num = %d",inode->i_num);
        close(fd);
    }
    if((fd = open("/sunkang/kamus",I_REGULAR,O_CREAT)) < 0)
    {
    }
    else
    {
        inode = current->filp[fd]->f_inode;
        printk("kamus inode num = %d mode = %x.",inode->i_num, inode->i_mode);
    }

    printk("---------------------------------------\n");
    char buf[] = "wo shi sunkang";
    sys_write(fd,buf, sizeof(buf));
    ret = close(fd);
    printk("close ret = %d.",ret);

    if((fd = open("/sunkang/kamus",I_REGULAR,0)) < 0)
    {
        printk("opern error.");
    }
    char abc[15] = {0};
    sys_read(fd,abc,sizeof(abc));
    printk("abc = %s\n",abc);
    close(fd);

    printk("[[email protected] prettyos]$ ");
    while(1)
    {
        printk("A");
        milli_delay(100);
    }
}
void read_log(char *filename, const struct touch_platform_data *pdata)
{
	int fd;
	char* buf = NULL;
	int rx_num = 0;
	int tx_num = 0;
	int data_pos = 0;
	int offset = 0;

	struct touch_platform_data *ppdata = (struct touch_platform_data*)pdata;

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

	fd = sys_open(filename, O_RDONLY, 0);
	buf = kzalloc(1024, GFP_KERNEL);

	TOUCH_INFO_MSG("[%s]read file open %s, fd : %d\n", __FUNCTION__, (fd >= 0)? "success": "fail", fd);

	if (fd >= 0) {
		TOUCH_INFO_MSG("[%s]open read_log funcion in /sns/touch/cap_diff_test.txt\n",__FUNCTION__);
		while(sys_read(fd, buf, 1024)) {

			TOUCH_INFO_MSG("[%s]sys_read success\n",__FUNCTION__);

			for(rx_num = 0; rx_num < (ppdata->rx_ch_count) - 1; rx_num++)
			{
				sscanf(buf + data_pos, "%d%n", &ppdata->rx_cap[rx_num], &offset);
				data_pos += offset;
			}

			for(tx_num = 0; tx_num < (ppdata->tx_ch_count) - 1; tx_num++)
			{
				sscanf(buf + data_pos, "%d%n", &ppdata->tx_cap[tx_num], &offset);
				data_pos += offset;
			}

			TOUCH_INFO_MSG("[%s]rx_num = %d, tx_num = %d\n", __FUNCTION__, rx_num, tx_num);
			TOUCH_INFO_MSG("[%s]rx_ch_count = %d, tx_ch_count = %d\n", __FUNCTION__, ppdata->rx_ch_count, ppdata->tx_ch_count);

			if((rx_num == (ppdata->rx_ch_count) -1) && (tx_num == (ppdata->tx_ch_count) -1))
				break;
		}

		sys_close(fd);
	}

	if(buf)
		kfree(buf);

	set_fs(old_fs);

}
Example #11
0
static ssize_t my_read(int I_iFd,unsigned char *O_pbBuf,unsigned int I_uiBufSize)
{
	ssize_t tRet;
#if defined(__UBOOT__) //[
	tRet = -1;
#elif defined(__KERNEL__)//[
	tRet = sys_read(I_iFd,O_pbBuf,I_uiBufSize);
#else//][!__KERNEL__
	tRet = read(I_iFd,O_pbBuf,I_uiBufSize);
#endif //] __KERNEL__
	return tRet;
}
static void uv_mntn_work(struct work_struct *work)
{
	char battery_capacity_info[16] = {0};
	PMIC_MNTN_DESC *pmic_mntn = NULL;
	long battery_capacity = 0;
	mm_segment_t fs = 0;
	struct irq_desc *desc = NULL ;
	/* 0:mask; 1:unmask; 2:undefined */
	static int uv_irq_flag = 2;
	static int battery_info_fd = -1;

	pmic_mntn = container_of(work, PMIC_MNTN_DESC, uv_mntn_delayed_work.work);

	desc = irq_to_desc(pmic_mntn->uv_irq);
	if (!desc) {
		pr_err("[%s]irq_to_desc failed\n", __func__);
		return ;
	}

	fs = get_fs();
	set_fs(KERNEL_DS);
	if (battery_info_fd < 0) {
		battery_info_fd = sys_open(PATH_BATTERY_CAPACITY, O_RDONLY, 0);
	}
	if (battery_info_fd >= 0) {
		sys_lseek(battery_info_fd, 0, SEEK_SET);
		if (sys_read(battery_info_fd, battery_capacity_info, sizeof(battery_capacity_info)) < 0) {
			sys_close(battery_info_fd);
			battery_info_fd = -1;
		}
	}
	set_fs(fs);

	kstrtol(battery_capacity_info, 0, &battery_capacity);
	if ((battery_capacity >= pmic_mntn->bat_cap_info.bat_cap_threshold)) {
		if (1 != uv_irq_flag) {
			pr_info("unmask uv irq,battery_capacity:%ld\n", battery_capacity);
			if (NULL != desc->irq_data.chip->irq_unmask)
				desc->irq_data.chip->irq_unmask(&desc->irq_data);
			uv_irq_flag = 1;
		}
	} else {
		if ((0 != uv_irq_flag)) {
			pr_info("mask uv irq,battery_capacity:%ld\n", battery_capacity);
			if (NULL != desc->irq_data.chip->irq_mask)
				desc->irq_data.chip->irq_mask(&desc->irq_data);
			uv_irq_flag = 0;
		}
	}

	schedule_delayed_work(&pmic_mntn->uv_mntn_delayed_work,
		round_jiffies_relative(msecs_to_jiffies(pmic_mntn->bat_cap_info.check_interval)));
}
Example #13
0
static void cpufreq_set_max_frequency(struct cpufreq_limit_data *limit, int boost)
{
	int fd;
	mm_segment_t old_fs;
	char buf[32];
	long sc_max_freq = 0, max_freq = 0;
	int cpu;

#if defined(CONFIG_ARM_NXP_CPUFREQ_BY_RESOURCE)
	limit->timer_chkcpu_mod = 1-limit->timer_chkcpu_mod;
	if (limit->timer_chkcpu_mod)
	{
		max_freq = cpuUsage_Process(limit, boost);
	}
	else
	{
		if(limit->pre_max_freq != 0)
			max_freq = limit->pre_max_freq;
		else
			max_freq = boost ? limit->aval_max_freq : limit->op_max_freq;
	}
	curMaxCpu = max_freq;
#else
	max_freq = boost ? limit->aval_max_freq : limit->op_max_freq;
#endif

	if (limit->pre_max_freq == max_freq)
		return;

	for_each_possible_cpu(cpu) {
		fd = sys_open(sys_scaling_path[cpu], O_RDWR, 0);
    	old_fs = get_fs();
   		if (0 > fd)
   			continue;

		set_fs(KERNEL_DS);
		sys_read(fd, (void*)buf, sizeof(buf));

		sc_max_freq = simple_strtoul(buf, NULL, 10);
		limit->pre_max_freq = max_freq;

		if (max_freq != sc_max_freq) {
			sprintf(buf, "%ld", max_freq);
			sys_write(fd, (void*)buf, sizeof(buf));
		}

		set_fs(old_fs);
		sys_close(fd);

		pr_debug("[cpu.%d scaling max: %ld khz -> %ld khz][%s]\n",
			cpu, sc_max_freq, max_freq, boost?"boost":"normal");
	}
}
Example #14
0
static void pmuL2_output_header(FILE *fp_out)
{
	unsigned int i;
	char path[4096], value[16];
	unsigned int tmp, first;

	sys_read("/sys/class/misc/met/pmu/l2/toggle_mode", value, 16, 0);
	if (value[0] == '1') {
		fputs("# mp_2pr: timestamp, l2_pmu_value1, ...\n", fp_out);
		fputs("met-info [000] 0.0: met_2pr_header: 0x2, 0x3\n", fp_out);
		fputs("# mp_2pw: timestamp, l2_pmu_value1, ...\n", fp_out);
		fputs("met-info [000] 0.0: met_2pw_header: 0x4, 0x5\n", fp_out);
	} else {
		first = 1;
		for (i=0; i<MAX_L2_PMU; i++) {
			snprintf(path, sizeof(path), "/sys/class/misc/met/pmu/l2/%d/mode", i);
			sys_read(path, value, 16, 0);
			switch (value[0]) {
			case '2': // polling
				snprintf(path, sizeof(path), "/sys/class/misc/met/pmu/l2/%d/event", i);
				sys_read(path, value, 16, 0);
				sscanf(value, "0x%x", &tmp);
				if (first != 0) {
					fputs("# mp_2p: timestamp, l2_pmu_value1, ...\n", fp_out);
					fputs("met-info [000] 0.0: met_2p_header: ", fp_out);
					fprintf(fp_out, "0x%x", tmp);
					first = 0;
				} else {
					fprintf(fp_out, ",0x%x", tmp);
				}
				break;
			}
		}
		if (first == 0) {
			fprintf(fp_out, "\n");
		}
	}

	return;
}
Example #15
0
/*
 * This routine tries to find a RAM disk image to load, and returns the
 * number of blocks to read for a non-compressed image, 0 if the image
 * is a compressed image, and -1 if an image with the right magic
 * numbers could not be found.
 *
 * We currently check for the following magic numbers:
 *	minix
 *	ext2
 *	romfs
 *	cramfs
 *	squashfs
 *	gzip
 */
static int __init
identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)
{
	const int size = 512;
	struct minix_super_block *minixsb;
	struct ext2_super_block *ext2sb;
	struct romfs_super_block *romfsb;
	struct cramfs_super *cramfsb;
	struct squashfs_super_block *squashfsb;
	int nblocks = -1;
	unsigned char *buf;
	const char *compress_name;


	buf = kmalloc(size, GFP_KERNEL);
	if (!buf)
		return -1;

	minixsb = (struct minix_super_block *) buf;
	ext2sb = (struct ext2_super_block *) buf;
	romfsb = (struct romfs_super_block *) buf;
	cramfsb = (struct cramfs_super *) buf;
	squashfsb = (struct squashfs_super_block *) buf;
	memset(buf, 0xe5, size);

	/*
	 * Read block 0 to test for compressed kernel
	 */
	sys_lseek(fd, start_block * BLOCK_SIZE, 0);
	sys_read(fd, buf, size);

	*decompressor = decompress_method(buf, size, &compress_name);
	if (compress_name) {
		printk(KERN_NOTICE "RAMDISK: %s image found at block %d\n",
		       compress_name, start_block);
		if (!*decompressor)
			printk(KERN_EMERG
			       "RAMDISK: %s decompressor not configured!\n",
			       compress_name);
		nblocks = 0;
		goto done;
	}

	/* romfs is at block zero too */
	if (romfsb->word0 == ROMSB_WORD0 &&
	    romfsb->word1 == ROMSB_WORD1) {
		printk(KERN_NOTICE
		       "RAMDISK: romfs filesystem found at block %d\n",
		       start_block);
		nblocks = (ntohl(romfsb->size)+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
		goto done;
	}
Example #16
0
size_t rd_read(int fd, void *buf, size_t len)
{
  unsigned long bufleft;
  if(fd>=0) {
    return sys_read(fd,buf,len);
  } else {
    bufleft=rd_end-rd_ptr;
    if(len>bufleft) len=bufleft;
    memcpy(buf,rd_ptr,len);
    rd_ptr+=len;
    return len;
  }
}
Example #17
0
/*
 * Callback routine when the required locks are obtained.
 * Called from parent context
 */
static void ctdb_lock_handler(struct tevent_context *ev,
			    struct tevent_fd *tfd,
			    uint16_t flags,
			    void *private_data)
{
	struct lock_context *lock_ctx;
	char c;
	bool locked;
	double t;
	int id;

	lock_ctx = talloc_get_type_abort(private_data, struct lock_context);

	/* cancel the timeout event */
	TALLOC_FREE(lock_ctx->ttimer);

	t = timeval_elapsed(&lock_ctx->start_time);
	id = lock_bucket_id(t);

	/* Read the status from the child process */
	if (sys_read(lock_ctx->fd[0], &c, 1) != 1) {
		locked = false;
	} else {
		locked = (c == 0 ? true : false);
	}

	/* Update statistics */
	CTDB_INCREMENT_STAT(lock_ctx->ctdb, locks.num_calls);
	if (lock_ctx->ctdb_db) {
		CTDB_INCREMENT_DB_STAT(lock_ctx->ctdb_db, locks.num_calls);
	}

	if (locked) {
		if (lock_ctx->ctdb_db) {
			CTDB_INCREMENT_STAT(lock_ctx->ctdb, locks.buckets[id]);
			CTDB_UPDATE_LATENCY(lock_ctx->ctdb, lock_ctx->ctdb_db,
					    lock_type_str[lock_ctx->type], locks.latency,
					    lock_ctx->start_time);

			CTDB_UPDATE_DB_LATENCY(lock_ctx->ctdb_db, lock_type_str[lock_ctx->type], locks.latency, t);
			CTDB_INCREMENT_DB_STAT(lock_ctx->ctdb_db, locks.buckets[id]);
		}
	} else {
		CTDB_INCREMENT_STAT(lock_ctx->ctdb, locks.num_failed);
		if (lock_ctx->ctdb_db) {
			CTDB_INCREMENT_DB_STAT(lock_ctx->ctdb_db, locks.num_failed);
		}
	}

	process_callbacks(lock_ctx, locked);
}
static int get_ftm_portlock_item(void)
{
    int fd;
    mm_segment_t old_fs;
    int offset = (LGFTM_PORTLOCK_STATE + 1) * FTM_BLOCK_SIZE;
    int enable = DIAG_DISABLE;
    char c;

    old_fs = get_fs();
    set_fs(get_ds());

    fd = sys_open(ftmdev, O_RDWR, 0);
    if (fd < 0)
    {
        pr_err("%s: sys_open error(%d)\n", __func__, fd);
    }
    else
    {
        sys_lseek(fd, offset, 0);
        if (sys_read(fd, &c, 1) != 1)
            pr_err("%s: sys_read error\n", __func__);

        enable = c - '0';

        switch (enable)
        {
            case DIAG_ENABLE:
            case DIAG_DISABLE:
                break;

            default:
                pr_info("%s: portlock is not set\n", __func__);

                c = '1';
                sys_lseek(fd, offset, 0);
                if (sys_write(fd, &c, 1) != 1)
                    pr_err("%s: sys_write error\n", __func__);

                enable = DIAG_ENABLE;
                break;
        }

        sys_close(fd);
    }

    set_fs(old_fs);

    pr_info("%s: diag %s\n", __func__, enable ? "enabled" : "disabled");

    return enable;
}
Example #19
0
static int mma7660_load_cablic(const char *addr)
{
	int ret;
	long fd = sys_open(addr,O_RDONLY,0);

	if(fd < 0){
		printk("mma7660_load_offset: open file %s\n", CABLIC_FILE);
		return -1;
	}
	ret = sys_read(fd,(char __user *)cab_arry,sizeof(cab_arry));
	sys_close(fd);

	return ret;
}
asmlinkage long sys_csci3411_get_attr(char *filename, char *attrname, char *buf, int bufsize){
    struct stat sb  ;   /* necessary structure for using sys_newstat() */
	char *fstring   ;   /* file/directory to get attribute from */
	char *dstring   ;   /* temporary string for strstr()        */
	char loc[128]   ;   /* full filepath for attr folder        */
	char buff[128]  ;   /* temporary buffer for filename        */
	char cmd[128]   ;   /* buffer holds full path to attrname   */
    char attrvalue[128];/* Temporary buffer for attribute value */
    int attr_fd     ;   /* The file we are reading from         */
    bool_t filetype	;	/* is the tag for a file or dir?        */
    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( buff, filename, sizeof(buff)/sizeof(char));
	dstring = strstr( buff, fstring );
	strncpy( dstring,"\0",1);
	sprintf(loc,"%s.%s_attr",buff,fstring);
	
	// Check if the directory is valid
	if(!(sys_newstat(loc,&sb)==0 && S_ISDIR(sb.st_mode)))
		return -1;
	
	// Open the file and read its attrvalue if it exists
    sprintf(cmd,"%s/%s",loc,attrname);
	if(!(sys_newstat(cmd,&sb)==0 && S_ISREG(sb.st_mode)))
		return -1;
	attr_fd = sys_open(cmd, O_RDWR, 0);
	sys_read(attr_fd, attrvalue, sb.st_size);
	sys_close(attr_fd);
	
    // Copy the attrvalue to buf
	copy_to_user(buf, attrvalue, sb.st_size);

    set_fs(fs);
    // Return the size of the attribute value
	return(sb.st_size);
}
Example #21
0
File: if.c Project: HTshandou/newos
static int if_rx_thread(void *args)
{
	ifnet *i = args;
	cbuf *b;

	if(i->fd < 0)
		return -1;

	for(;;) {
		ssize_t len;

		len = sys_read(i->fd, i->rx_buf, 0, sizeof(i->rx_buf));
#if NET_CHATTY
		dprintf("if_rx_thread: got ethernet packet, size %Ld\n", (long long)len);
#endif
		if(len < 0) {
			thread_snooze(10000);
			continue;
		}
		if(len == 0)
			continue;

#if LOSE_RX_PACKETS
		if(rand() % 100 < LOSE_RX_PERCENTAGE) {
			dprintf("if_rx_thread: purposely lost packet, size %d\n", len);
			continue;
		}
#endif

		// check to see if we have a link layer address attached to us
		if(!i->link_addr) {
#if NET_CHATTY
			dprintf("if_rx_thread: dumping packet because of no link address (%p)\n", i);
#endif
			continue;
		}

		// for now just move it over into a cbuf
		b = cbuf_get_chain(len);
		if(!b) {
			dprintf("if_rx_thread: could not allocate cbuf to hold ethernet packet\n");
			continue;
		}
		cbuf_memcpy_to_chain(b, 0, i->rx_buf, len);

		i->link_input(b, i);
	}

	return 0;
}
Example #22
0
    static int os_read(int fd, void *buf, size_t len)
    {
	long rc;
	mm_segment_t oldfs = get_fs();
	set_fs(KERNEL_DS);
	rc = sys_read(fd, buf, len);
	set_fs(oldfs);
	if (rc) {
	    errno = -rc;
	    return -1;
	} else {
	    return 0;
	}
    }
int rdr_copy_file(char *dst, char *src)
{
	int fddst, fdsrc, ret = 0;
	char *buf;
	struct kstat m_stat;
	long cnt;

	if (0 != vfs_stat(src, &m_stat)) {
		pr_err("rdr:%s():stat failed\n", __func__);
		return -1;
	}

	buf = vmalloc(SZ_4K);
	if (buf == NULL) {
		pr_err("rdr:%s():malloc 4K failed\n", __func__);
		return -1;
	}
	fdsrc = sys_open(src, O_RDONLY, 0664);
	if (fdsrc < 0) {
		pr_err("rdr:%s():open src failed\n", __func__);
		ret = -2;
		goto out;
	}
	fddst = sys_open(dst, O_CREAT | O_WRONLY, 0664);
	if (fddst < 0) {
		pr_err("rdr:%s():open dst failed\n", __func__);
		sys_close(fdsrc);
		ret = -3;
		goto out;
	}
	while (1) {
		cnt = sys_read(fdsrc, buf, SZ_4K);
		if (cnt == 0)
			break;
		cnt = sys_write(fddst, buf, cnt);
		if (cnt <= 0) {
			pr_err("rdr:%s():write dst failed\n", __func__);
			ret = -4;
			goto close;
		}
	}

close:
	sys_close(fdsrc);
	sys_close(fddst);
out:
	vfree(buf);
	return ret;
}
Example #24
0
/*
 * This routine tries to find a RAM disk image to load, and returns the
 * number of blocks to read for a non-compressed image, 0 if the image
 * is a compressed image, and -1 if an image with the right magic
 * numbers could not be found.
 *
 * We currently check for the following magic numbers:
 *      squashfs
 * 	minix
 * 	ext2
 *	romfs
 *	cramfs
 * 	gzip
 */
static int __init 
identify_ramdisk_image(int fd, int start_block)
{
	const int size = 512;
	struct minix_super_block *minixsb;
	struct ext2_super_block *ext2sb;
	struct romfs_super_block *romfsb;
	struct cramfs_super *cramfsb;
	struct squashfs_super_block *squashfsb;
	int nblocks = -1;
	unsigned char *buf;

	buf = kmalloc(size, GFP_KERNEL);
	if (buf == 0)
		return -1;

	minixsb = (struct minix_super_block *) buf;
	ext2sb = (struct ext2_super_block *) buf;
	romfsb = (struct romfs_super_block *) buf;
	cramfsb = (struct cramfs_super *) buf;
	squashfsb = (struct squashfs_super_block *) buf;
	memset(buf, 0xe5, size);

	/*
	 * Read block 0 to test for gzipped kernel
	 */
	sys_lseek(fd, start_block * BLOCK_SIZE, 0);
	sys_read(fd, buf, size);

	/*
	 * If it matches the gzip magic numbers, return -1
	 */
	if (buf[0] == 037 && ((buf[1] == 0213) || (buf[1] == 0236))) {
		printk(KERN_NOTICE
		       "RAMDISK: Compressed image found at block %d\n",
		       start_block);
		nblocks = 0;
		goto done;
	}

	/* romfs is at block zero too */
	if (romfsb->word0 == ROMSB_WORD0 &&
	    romfsb->word1 == ROMSB_WORD1) {
		printk(KERN_NOTICE
		       "RAMDISK: romfs filesystem found at block %d\n",
		       start_block);
		nblocks = (ntohl(romfsb->size)+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
		goto done;
	}
Example #25
0
ssize_t __fs_read(struct _reent *r, int fd, char *buf, size_t count)
{
	int ret;
	struct __FILE * f = (struct __FILE *)fd;
	int offset = f->offset;
	if (offset >= f->size) {
		ret = 0;
	} else {
		size_t rdlen = f->size - offset < count ? f->size - offset : count;
		sys_seek(f->fd, f->offset, 0);
		ret = sys_read(f->fd, buf, rdlen);
		f->offset += ret;
	}
	return ret;
}
Example #26
0
File: net.c Project: mato/solo5
solo5_result_t solo5_net_read(uint8_t *buf, size_t size, size_t *read_size)
{
    assert(netfd >= 0);
    
    long nbytes = sys_read(netfd, (char *)buf, size);
    if (nbytes < 0) {
        if (nbytes == SYS_EAGAIN)
            return SOLO5_R_AGAIN;
        else
            return SOLO5_R_EUNSPEC;
    }

    *read_size = (size_t)nbytes;
    return SOLO5_R_OK;
}
Example #27
0
static bool recv_pcap_blob(TALLOC_CTX *mem_ctx, int fd, DATA_BLOB *pcap_blob)
{
	size_t blob_len;
	size_t ret;

	ret = sys_read(fd, &blob_len, sizeof(blob_len));
	if (ret != sizeof(blob_len)) {
		return false;
	}

	*pcap_blob = data_blob_talloc_named(mem_ctx, NULL, blob_len,
					   "cups pcap");
	if (pcap_blob->length != blob_len) {
		return false;
	}
	ret = sys_read(fd, pcap_blob->data, blob_len);
	if (ret != blob_len) {
		talloc_free(pcap_blob->data);
		return false;
	}

	DEBUG(10, ("successfully recvd blob of len %d\n", (int)ret));
	return true;
}
Example #28
0
static unsigned char* get(int* count, char* filename)
{
	unsigned char* ptr, *ptr2;
	struct stat sstat;
	int fd;
	int remaining;
	int sz, total=0;
	
	set_fs(KERNEL_DS);
	
	if (sys_newstat(filename, &sstat) < 0)
		return 0;
	
	*count = remaining = sstat.st_size;
	
	ptr = ptr2 = vmalloc(sstat.st_size+32);
	if (!ptr)
	{
		printk("lab: AIIIIIIIIIIIIIIIIIGHHH!! out of memory!!\n");
		printk("lab: I guess we just can't allocate 0x%08x bytes???\n", (unsigned int)sstat.st_size+32);
		return 0;
 	}
	
	if ((fd=sys_open(filename,O_RDONLY,0)) < 0)
	{
		printk("lab: uh. couldn't open the file.\n");
		vfree(ptr);
		return 0;
	}
	
	while (remaining)
	{
		sz = (1048576 < remaining) ? 1048576 : remaining;
		total += sz;
		if (sys_read(fd,ptr2,sz) < sz)
		{
			printk("lab: uh. couldn't read from the file.\n");
			sys_close(fd);
			vfree(ptr);
			return 0;
		}
		ptr2 += sz;
		remaining -= sz;
	}
	
	sys_close(fd);
	return ptr;
}
static int rk30_adc_battery_load_capacity(void)
{
	char value[4];
	int* p = (int *)value;
	long fd = sys_open(BATT_FILENAME,O_RDONLY,0);

	if(fd < 0){
		pr_bat("rk30_adc_battery_load_capacity: open file /data/bat_last_capacity.dat failed\n");
		return -1;
	}

	sys_read(fd,(char __user *)value,4);
	sys_close(fd);

	return (*p);
}
Example #30
0
int 
read(int fd, void *buf, size_t len)
{
    struct sys_read_args args;
    int res, error;
    SYSCALLARG(args,fd) = fd;
    SYSCALLARG(args,buf) = buf;
    SYSCALLARG(args,nbyte) = len;
    error = sys_read(&args, &res);
    if (error) {
        errno = error;
        return -1;
    } else {
        return res;
    }
}