Exemplo n.º 1
0
irqreturn_t cvm_mmc_interrupt(int irq, void *dev_id)
{
	struct cvm_mmc_host *host = dev_id;
	struct mmc_request *req;
	unsigned long flags = 0;
	u64 emm_int, rsp_sts;
	bool host_done;

	if (host->need_irq_handler_lock)
		spin_lock_irqsave(&host->irq_handler_lock, flags);
	else
		__acquire(&host->irq_handler_lock);

	/* Clear interrupt bits (write 1 clears ). */
	emm_int = readq(host->base + MIO_EMM_INT(host));
	writeq(emm_int, host->base + MIO_EMM_INT(host));

	if (emm_int & MIO_EMM_INT_SWITCH_ERR)
		check_switch_errors(host);

	req = host->current_req;
	if (!req)
		goto out;

	rsp_sts = readq(host->base + MIO_EMM_RSP_STS(host));
	/*
	 * dma_val set means DMA is still in progress. Don't touch
	 * the request and wait for the interrupt indicating that
	 * the DMA is finished.
	 */
	if ((rsp_sts & MIO_EMM_RSP_STS_DMA_VAL) && host->dma_active)
		goto out;

	if (!host->dma_active && req->data &&
	    (emm_int & MIO_EMM_INT_BUF_DONE)) {
		unsigned int type = (rsp_sts >> 7) & 3;

		if (type == 1)
			do_read(host, req, rsp_sts & MIO_EMM_RSP_STS_DBUF);
		else if (type == 2)
			do_write(req);
	}
Exemplo n.º 2
0
Arquivo: ltpc.c Projeto: 274914765/C
static int ltpc_xmit(struct sk_buff *skb, struct net_device *dev)
{
    /* in kernel 1.3.xx, on entry skb->data points to ddp header,
     * and skb->len is the length of the ddp data + ddp header
     */

    struct net_device_stats *stats = &((struct ltpc_private *)dev->priv)->stats;

    int i;
    struct lt_sendlap cbuf;
    unsigned char *hdr;

    cbuf.command = LT_SENDLAP;
    cbuf.dnode = skb->data[0];
    cbuf.laptype = skb->data[2];
    skb_pull(skb,3);    /* skip past LLAP header */
    cbuf.length = skb->len;    /* this is host order */
    skb_reset_transport_header(skb);

    if(debug & DEBUG_UPPER) {
        printk("command ");
        for(i=0;i<6;i++)
            printk("%02x ",((unsigned char *)&cbuf)[i]);
        printk("\n");
    }

    hdr = skb_transport_header(skb);
    do_write(dev, &cbuf, sizeof(cbuf), hdr, skb->len);

    if(debug & DEBUG_UPPER) {
        printk("sent %d ddp bytes\n",skb->len);
        for (i = 0; i < skb->len; i++)
            printk("%02x ", hdr[i]);
        printk("\n");
    }

    stats->tx_packets++;
    stats->tx_bytes+=skb->len;

    dev_kfree_skb(skb);
    return 0;
}
Exemplo n.º 3
0
static int do_dump(int cmd, char *name, char *buf)
{
	struct gfsc_header h, *rh;
	char *reply;
	int reply_len;
	int fd, rv;

	init_header(&h, cmd, name, 0);

	reply_len = sizeof(struct gfsc_header) + GFSC_DUMP_SIZE;
	reply = malloc(reply_len);
	if (!reply) {
		rv = -1;
		goto out;
	}
	memset(reply, 0, reply_len);

	fd = do_connect(GFSC_QUERY_SOCK_PATH);
	if (fd < 0) {
		rv = fd;
		goto out;
	}

	rv = do_write(fd, &h, sizeof(h));
	if (rv < 0)
		goto out_close;

	/* won't always get back the full reply_len */
	do_read(fd, reply, reply_len);

	rh = (struct gfsc_header *)reply;
	rv = rh->data;
	if (rv < 0)
		goto out_close;

	memcpy(buf, (char *)reply + sizeof(struct gfsc_header),
	       GFSC_DUMP_SIZE);
 out_close:
	close(fd);
 out:
	return rv;
}
Exemplo n.º 4
0
static int sysfs_write(struct pci_dev *d, int pos, byte *buf, int len)
{
  int fd = sysfs_setup(d, 1);
  int res;

  if (fd < 0)
    return 0;
  res = do_write(d, fd, buf, len, pos);
  if (res < 0)
    {
      d->access->warning("sysfs_write: write failed: %s", strerror(errno));
      return 0;
    }
  else if (res != len)
    {
      d->access->warning("sysfs_write: tried to write %d bytes at %d, but only %d succeeded", len, pos, res);
      return 0;
    }
  return 1;
}
Exemplo n.º 5
0
void chat_client::do_write()
{
	asio::async_write(socket_,
		asio::buffer(write_msgs_.front().data(),
		write_msgs_.front().length()),
		[this](std::error_code ec, std::size_t /*length*/)
	{
		if (!ec)
		{
			write_msgs_.pop_front();
			if (!write_msgs_.empty())
			{
				do_write();
			}
		} else
		{
			socket_.close();
		}
	});
}
Exemplo n.º 6
0
static void do_flush(device_extension* Vcb) {
    LIST_ENTRY rollback;
    
    InitializeListHead(&rollback);
    
    FsRtlEnterFileSystem();

    ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);

    if (Vcb->need_write)
        do_write(Vcb, &rollback);
    
    free_trees(Vcb);
    
    clear_rollback(&rollback);

    ExReleaseResourceLite(&Vcb->tree_lock);

    FsRtlExitFileSystem();
}
void CompressedInetStreamSocket::write(const ByteStream& msg, Stats* stats)
{
    size_t outLen = 0;
    uint32_t len = msg.length();

    if (useCompression && (len > 512))
    {
        ByteStream smsg(alg.maxCompressedSize(len));

        alg.compress((char*) msg.buf(), len, (char*) smsg.getInputPtr(), &outLen);
        smsg.advanceInputPtr(outLen);

        if (outLen < len)
            do_write(smsg, COMPRESSED_BYTESTREAM_MAGIC, stats);
        else
            InetStreamSocket::write(msg, stats);
    }
    else
        InetStreamSocket::write(msg, stats);
}
Exemplo n.º 8
0
static uint32_t nand_dev_erase_file(nand_dev *dev, uint64_t addr, uint32_t total_len)
{
    uint32_t len = total_len;
    size_t write_len = dev->erase_size;
    int ret;

    do_lseek(dev->fd, addr, SEEK_SET);
    memset(dev->data, 0xff, dev->erase_size);
    while(len > 0) {
        if(len < write_len)
            write_len = len;
        ret = do_write(dev->fd, dev->data, write_len);
        if(ret < write_len) {
            XLOG( "nand_dev_write_file, write failed: %s\n", strerror(errno));
            break;
        }
        len -= write_len;
    }
    return total_len - len;
}
Exemplo n.º 9
0
/* empty the circular buffer by issuing random sized remove_cbuf
   calls, then write the result to stdout */
void empty_buf(cbuf * thebuf)
{
    int want, got, j;
    char last = 0;
    buf_t destbuf[BSIZE];
    FILE *fptr;

    errlog(5,"Writer starting");
    fptr = stdout;
    got = 1;
    while (got) {
	want = (int)rnum(BSIZE);
	test_lookahead(thebuf);
	test_unget(thebuf);
	test_read(thebuf);
	got = remove_cbuf(thebuf, destbuf, want);
	do_write(destbuf, got);
    }

}
Exemplo n.º 10
0
static void connect_cb(uv_connect_t* req, int status) {
  int i;

  if (status) LOG(uv_strerror(uv_last_error()));
  ASSERT(status == 0);

  write_sockets++;
  req_free((uv_req_t*) req);

  maybe_connect_some();

  if (write_sockets == TARGET_CONNECTIONS) {
    start_stats_collection();

    /* Yay! start writing */
    for (i = 0; i < write_sockets; i++) {
      do_write(type == TCP ? (uv_stream_t*)&tcp_write_handles[i] : (uv_stream_t*)&pipe_write_handles[i]);
    }
  }
}
Exemplo n.º 11
0
static int chips_append(int argc, char **argv)
{
	if(argc != 2)
	{
		fprintf(stderr, "Usage: %s <file>\n", argv[0]);
		return -1;
	}
	int fd = do_open(argv[1]);
	if(fd < 0)
	{
		if(!fs_create(argv[1], POTATOES_DATA_FILE))	
		{
			fprintf(stderr, "Failed to create %s\n", argv[1]);
			return 1;
		}
		if((fd = do_open(argv[1])) < 0)
		{
			fprintf(stderr, "Failed to open %s\n", argv[1]);
			return 1;
		}
	}

	potatoes_file_info_t info;
	get_file_info(fd, &info);

	if(info.mode != POTATOES_DATA_FILE)
	{
		fprintf(stderr, "Not a file: %s\n", argv[1]);
		return 1;
	}

	char buf[512];
	int count;
	int off = info.size;
	while((count = read(0, buf, 512)) > 0)
	{
		do_write(fd, buf, count, off);
		off += count;
	}
	return 0;
}
Exemplo n.º 12
0
static void
g_socks4a_proxy_connect_async (GProxy               *proxy,
			       GIOStream            *io_stream,
			       GProxyAddress        *proxy_address,
			       GCancellable         *cancellable,
			       GAsyncReadyCallback   callback,
			       gpointer              user_data)
{
  GError *error = NULL;
  GTask *task;
  ConnectAsyncData *data;
  const gchar *hostname;
  guint16 port;
  const gchar *username;

  data = g_slice_new0 (ConnectAsyncData);
  data->io_stream = g_object_ref (io_stream);

  task = g_task_new (proxy, cancellable, callback, user_data);
  g_task_set_task_data (task, data, (GDestroyNotify) free_connect_data);

  hostname = g_proxy_address_get_destination_hostname (proxy_address);
  port = g_proxy_address_get_destination_port (proxy_address);
  username = g_proxy_address_get_username (proxy_address); 

  data->buffer = g_malloc0 (SOCKS4_CONN_MSG_LEN);
  data->length = set_connect_msg (data->buffer,
				  hostname, port, username,
				  &error);
  data->offset = 0;

  if (data->length < 0)
    {
      g_task_return_error (task, error);
      g_object_unref (task);
    }
  else
    {
      do_write (connect_msg_write_cb, task, data);
    }
}
Exemplo n.º 13
0
/*
 * Writes one request to disk
 */
static int process_request(tee_saved_request *sr)
{
	sr->time_dequeued = apr_time_now();
	set_filename(sr);
	if (!sr->filename)
		return 0;

	apr_file_t *file;
	apr_int32_t flags = APR_FOPEN_WRITE | APR_FOPEN_CREATE | APR_FOPEN_BUFFERED;
	apr_status_t rc = apr_file_open(&file, sr->filename, flags, APR_OS_DEFAULT, sr->pool);
	if (rc != APR_SUCCESS) {
		ap_log_error(APLOG_MARK, APLOG_ERR, 0, sr->server, "tee: Cannot create file %s: %s",
				sr->filename, tee_get_error_string(rc, sr->pool));
		return 0;
	}
	do_write(file, sr);
	sr->filesize = tee_get_file_pos(file);
	ap_log_error(APLOG_MARK, APLOG_INFO, 0, sr->server, "tee: File saved: %s (pid %d)", sr->filename, getpid());
	sr->time_written = apr_time_now();
	return 1;
}
Exemplo n.º 14
0
    void do_write() {
        boost::asio::async_write(
            socket_,
            boost::asio::buffer(
                write_msgs_.front()->data(),
                write_msgs_.front()->length()),
            [this](boost::system::error_code ec, std::size_t) {
                if (ec) {
                    std::cout << ec.message() << "\n";
                    if (ec != boost::asio::error::operation_aborted) {
                        socket_.close();
                    }
                    return;
                }

                write_msgs_.pop_front();
                if (!write_msgs_.empty()) {
                    do_write();
                }
            });
    }
Exemplo n.º 15
0
static void handle_events( int _epollfd, struct epoll_event* _events, int _num, int _listenfd, char* _buf )
{
	int fd = 0;
	for( int i = 0; i < _num; ++i )
	{
		fd = _events[i].data.fd;
		//根据描述符的类型和事件类型进行处理
		if( (fd == _listenfd) && (_events[i].events & EPOLLIN) )
		{
			handle_accept( _epollfd, _listenfd );
		}
		else if( _events[i].events & EPOLLIN )
		{
			do_read( _epollfd, fd, _buf );
		}
		else if( _events[i].events & EPOLLOUT )
		{
			do_write( _epollfd, fd, _buf );
		}
	}
}
Exemplo n.º 16
0
int gfsc_fs_leave(struct gfsc_mount_args *ma, int reason)
{
	char msg[sizeof(struct gfsc_header) + sizeof(struct gfsc_mount_args)];
	struct gfsc_header *h = (struct gfsc_header *)msg;
	char *name = strstr(ma->table, ":") + 1;
	int fd;

	init_header(h, GFSC_CMD_FS_LEAVE, name,
		    sizeof(struct gfsc_mount_args));

	h->data = reason;

	memcpy(msg + sizeof(struct gfsc_header), ma,
	       sizeof(struct gfsc_mount_args));

	fd = do_connect(GFSC_SOCK_PATH);
	if (fd < 0)
		return fd;

	return do_write(fd, msg, sizeof(msg));
}
Exemplo n.º 17
0
bool tuntap::send_packet(dbuf &buf, size_t len)
{
#ifdef WINDOWS
	if(sent_sync || HasOverlappedIoCompleted(&send_overlapped)) {
		std::swap(buf, send_buf);
		if(buf.size() < send_buf.size())
			buf.resize(send_buf.size());
		do_write(len);
		return true;
	}
	// else previous async send has not completed
	return false; 
#else
	ssize_t nwritten = write(fd, buf, len);
	if(nwritten > 0)
		return true;
	if(errno == EWOULDBLOCK || errno == EAGAIN)
		return false;
	throw e_check_sock_err("write to tuntap failed", true);
#endif
}
Exemplo n.º 18
0
void handle_whois(puser users, int socket, char * buffer) {
	char * name = malloc(MAXLEN);
	char timebuf[20];
	int k;
	memset(name, '0', MAXLEN);
	sscanf(buffer, "/whois %s", name);
	k = search_name(users, name);

	if (k != -1) {
		time_t time = users[k].timez;
		strftime(timebuf, 20, "%Y/%m/%[email protected]%H:%M:%S", localtime(&time));
		sprintf(buffer,
				"[Server] : %s is connected since %s with IP address %s and port number %i\n",
				name, timebuf, iptoa(users[k].ip), users[k].port);
	} else {
		sprintf(buffer, "[Server] : %s appears not to be a logged on user\n",
				name);
	}

	do_write(socket, buffer);
}
Exemplo n.º 19
0
/**
 * do_test - Write, Read and Verify
 * @serial:	Serial Test Context
 * @bytes:	amount of data to transfer
 */
static int do_test(struct usb_serial_test *serial, uint32_t bytes)
{
	int			ret;

	ret = do_write(serial, bytes);
	if (ret < 0)
		goto err;

	ret = do_read(serial, bytes);
	if (ret < 0)
		goto err;

	ret = do_verify(serial, bytes);
	if (ret < 0)
		goto err;

	return 0;

err:
	return ret;
}
Exemplo n.º 20
0
int test_write(const char* filename)
{
    MXFFile* mxfFile = NULL;
    
    
    if (!mxf_disk_file_open_new(filename, &mxfFile))
    {
        mxf_log_error("Failed to create '%s'" LOG_LOC_FORMAT, filename, LOG_LOC_PARAMS);
        return 0;
    }

    /* TEST */
    CHK_OFAIL(do_write(mxfFile));
    
    mxf_file_close(&mxfFile);
    return 1;
    
fail:
    mxf_file_close(&mxfFile);
    return 0;
}
Exemplo n.º 21
0
void tcp_writer::do_write()
{
    boost::asio::async_write(socket_,
                             boost::asio::buffer(write_msgs_.front().data(), write_msgs_.front().length()),
                             [this](boost::system::error_code ec, std::size_t)
    {
        if(!ec)
        {
            write_msgs_.pop_front();
            if (!write_msgs_.empty())
            {
                do_write();
            }
        }
        else
        {
            socket_.close();
        }
    });

}
Exemplo n.º 22
0
/* handle_client_message stores the user input into buffer buf while protecting the application from a buffer overflow
   and sends the message contained into the buffer buf to the server */
char handle_client_message(struct info* pinfo, char outbuf[SIZE_BUFFER])
{
	struct pollfd fds[2];

	memset(outbuf, 0, SIZE_BUFFER);
    
    fds[0].fd = 0; // STDIN
    fds[0].events = POLLIN;

    fds[1].fd = pinfo->fd[0];
    fds[1].events = POLLIN;

    /* Checks if there is data waiting in stdin */
    poll(fds, 2, -1);
    
    /* if there is, fgets is executed */
    if(fds[0].revents == POLLIN)
    {
		fgets(outbuf, SIZE_BUFFER, stdin);
		pthread_mutex_lock( &(pinfo->mutex) );
		if(pinfo->req == 1)
		{
			write(pinfo->fd[1], outbuf, strlen(outbuf));
		}
		else
		{
			if(strlen(outbuf) > 1)
				do_write(pinfo->sock, outbuf);
		}
		pthread_mutex_unlock( &(pinfo->mutex) );
	}
    else if(pinfo->req == 0 && fds[1].revents == POLLIN) {
    	read(pinfo->fd[0], outbuf, SIZE_BUFFER);
    	if(!strncmp(outbuf, "quit", 4))
    		return 1;
    }

    return 0;
}
Exemplo n.º 23
0
int main(int argc, const char * const *argv)
{
    int reader = 0;
    apr_status_t status;
    char optchar;
    const char *optarg;
    apr_getopt_t *opt;

    if (apr_initialize() != APR_SUCCESS)
        errmsg("Could not initialize APR.\n");
    atexit(apr_terminate);

    if (apr_pool_create(&pool, NULL) != APR_SUCCESS)
        errmsg("Could not create global pool.\n");

    if (apr_getopt_init(&opt, pool, argc, argv) != APR_SUCCESS)
        errmsg("Could not parse options.\n");

    while ((status = apr_getopt(opt, "rf:", &optchar, &optarg)) == APR_SUCCESS) {
        if (optchar == 'r')
            ++reader;
        else if (optchar == 'f')
            testfile = optarg;
    }
    if (status != APR_SUCCESS && status != APR_EOF) {
        char msgbuf[80];

        fprintf(stderr, "error: %s\n",
                apr_strerror(status, msgbuf, sizeof msgbuf));
        exit(1);
    }

    if (reader)
        do_read();
    else
        do_write();

    return 0;
}
Exemplo n.º 24
0
char *
gfs_pio_flush(GFS_File gf)
{
	char *e = gfs_pio_check_view_default(gf);
	size_t written;

	if (e != NULL)
		return (e);

	CHECK_WRITABLE(gf);

	if ((gf->mode & GFS_FILE_MODE_BUFFER_DIRTY) != 0) {
		e = do_write(gf, gf->buffer, gf->length, &written);
		if (e != NULL)
			return (e);
		gf->mode &= ~GFS_FILE_MODE_BUFFER_DIRTY;
	}
	if (gf->p >= gf->length)
		gfs_pio_purge(gf);

	return (NULL);
}
Exemplo n.º 25
0
/*
typedef struct write_args 
{
    int     fd;
    void   *buf;
    size_t  nbytes;
} write_args_t;
 */ 
static int
sys_write(write_args_t *arg)
{
        /*NOT_YET_IMPLEMENTED("VM: sys_write");*/

        /* copy_from_user() the write_args_t */
        write_args_t            karg;
        int                     err;
        if ((err = copy_from_user(&karg, arg, sizeof(write_args_t))) < 0) 
        {
                curthr->kt_errno = -err;
                return -1;
        }
        /* page_alloc() a temporary buffer */
        void *temp_buffer = page_alloc();
        if (temp_buffer == NULL)
        {
                curthr->kt_errno = ENOMEM;
                return -1;
        }
        /* call do_write(), and copy_to_user() the read bytes */
        int ret;
        if( (ret = do_write(karg.fd, temp_buffer, karg.nbytes)) < 0 )
        {
                page_free(temp_buffer);
                curthr->kt_errno = -ret;
                return -1;
        }
        if ( (err = copy_to_user(arg->buf, temp_buffer, ret)) < 0 ) 
        {
                page_free(temp_buffer);
                curthr->kt_errno = -err;
                return -1;
        }
        /* sys_write goes well here, page_free() the tmeporary buffer,
           return the number of bytes actually write */
        page_free(temp_buffer);
        return ret;
}
Exemplo n.º 26
0
static int test_content(SSL *ssl) {
  static const char *const str1 = "GET / HTTP/1.0\r\n\r\n";
  static const char *const str2 =
      "200 Ok\r\nContent-type: text-plain\r\n\r\nHi yourself!";
  char buf[512];
  int ret;

  ret = do_read(ssl, buf, sizeof(buf));
  if (ret < 0 || (size_t) ret != strlen(str1)) return 0;

  printf("Got: %.*s\n", ret, buf);
  if (memcmp(buf, str1, ret)) {
    return 0;
  }

  ret = do_write(ssl, str2, strlen(str2));
  if (ret < 0 || (size_t) ret != strlen(str2)) return 0;

  usleep(100000);

  return 1;
}
Exemplo n.º 27
0
void h2o_socket_write(h2o_socket_t *sock, h2o_iovec_t *bufs, size_t bufcnt, h2o_socket_cb cb)
{
    if (sock->ssl == NULL) {
        do_write(sock, bufs, bufcnt, cb);
    } else {
        assert(sock->ssl->output.bufs.size == 0);
        /* fill in the data */
        for (; bufcnt != 0; ++bufs, --bufcnt) {
            size_t off = 0;
            while (off != bufs[0].len) {
                int ret;
                size_t sz = bufs[0].len - off;
                if (sz > 1400)
                    sz = 1400;
                ret = SSL_write(sock->ssl->ssl, bufs[0].base + off, (int)sz);
                assert(ret == sz);
                off += sz;
            }
        }
        flush_pending_ssl(sock, cb);
    }
}
Exemplo n.º 28
0
        void client_net_io::connect()
        {
            session_state closed_state = SS_CLOSED;

            if (_state.compare_exchange_strong(closed_state, SS_CONNECTING))
            {
                boost::asio::ip::tcp::endpoint ep(
                    boost::asio::ip::address_v4(ntohl(_remote_addr.ip)), _remote_addr.port);

                add_reference();
                _socket.async_connect(ep, [this](boost::system::error_code ec)
                {
                    if (!ec)
                    {
                        _reconnect_count = 0;
                        _state = SS_CONNECTED;

                        dinfo("client session %s:%d connected",
                            _remote_addr.name.c_str(),
                            static_cast<int>(_remote_addr.port)
                            );

                        set_options();

                        do_write();
                        do_read();                        
                    }
                    else
                    {
                        derror("network client session connect failed, error = %s",
                            ec.message().c_str()
                            );
                        on_failure();
                    }
                    release_reference();
                });
            }
        }
Exemplo n.º 29
0
		void session::do_read()
		{
			auto self(shared_from_this());
			socket_.async_read_some(boost::asio::buffer(buffer_, max_length),
				[this, self](boost::system::error_code ec, std::size_t bytes_transferred)
			{
				if (!ec)
				{

					RemoteUserAction::Parse_Result result = user_action_.Parse(
						buffer_, buffer_ + bytes_transferred);

					if (result == RemoteUserAction::Parse_Result::indeterminate){
						//do nothing
					}
					else{
						std::string immediatelyReply;
						if (result == RemoteUserAction::Parse_Result::Good)
						{
							immediatelyReply = "Valid Action is received, responsing...";
							//send (UserAction Object) to fifo queue for handling...
							GetFIFOActionQueue().Push_back(user_action_);
						}
						else if (result == RemoteUserAction::Parse_Result::Bad){
							immediatelyReply = "Invalid Action is received, ignored...";	
						}
						do_write(immediatelyReply.c_str(), immediatelyReply.length());
						user_action_.Reset();//start to receive new Action Request
					}

					do_read();
				}
				else{
					assert(false);
					on_socket_error();
				}
			});
		}
Exemplo n.º 30
0
static uint32_t nand_dev_write_file(nand_dev *dev, uint32_t data, uint64_t addr, uint32_t total_len)
{
    uint32_t len = total_len;
    size_t write_len = dev->erase_size;
    int ret;

    NAND_UPDATE_WRITE_THRESHOLD(total_len);

    lseek(dev->fd, addr, SEEK_SET);
    while(len > 0) {
        if(len < write_len)
            write_len = len;
        cpu_memory_rw_debug(cpu_single_env, data, dev->data, write_len, 0);
        ret = do_write(dev->fd, dev->data, write_len);
        if(ret < write_len) {
            XLOG("nand_dev_write_file, write failed: %s\n", strerror(errno));
            break;
        }
        data += write_len;
        len -= write_len;
    }
    return total_len - len;
}