Ejemplo n.º 1
0
static int dir_commit_chunk(struct page *page, unsigned from, unsigned to)
{
	struct inode *dir = (struct inode *)page->mapping->host;
	int err = 0;

	page->mapping->a_ops->commit_write(NULL, page, from, to);
	if (IS_DIRSYNC(dir))
		err = write_one_page(page, 1);
	else
		unlock_page(page);
	return err;
}
Ejemplo n.º 2
0
int btrfs_write_marked_extents(struct btrfs_root *root,
                               struct extent_io_tree *dirty_pages, int mark)
{
    int ret;
    int err = 0;
    int werr = 0;
    struct page *page;
    struct inode *btree_inode = root->fs_info->btree_inode;
    u64 start = 0;
    u64 end;
    unsigned long index;

    while (1) {
        ret = find_first_extent_bit(dirty_pages, start, &start, &end,
                                    mark);
        if (ret)
            break;
        while (start <= end) {
            cond_resched();

            index = start >> PAGE_CACHE_SHIFT;
            start = (u64)(index + 1) << PAGE_CACHE_SHIFT;
            page = find_get_page(btree_inode->i_mapping, index);
            if (!page)
                continue;

            btree_lock_page_hook(page);
            if (!page->mapping) {
                unlock_page(page);
                page_cache_release(page);
                continue;
            }

            if (PageWriteback(page)) {
                if (PageDirty(page))
                    wait_on_page_writeback(page);
                else {
                    unlock_page(page);
                    page_cache_release(page);
                    continue;
                }
            }
            err = write_one_page(page, 0);
            if (err)
                werr = err;
            page_cache_release(page);
        }
    }
    if (err)
        werr = err;
    return werr;
}
Ejemplo n.º 3
0
static int dir_commit_chunk(struct page *page, loff_t pos, unsigned len)
{
	struct address_space *mapping = page->mapping;
	struct inode *dir = mapping->host;
	int err = 0;

	block_write_end(NULL, mapping, pos, len, len, page, NULL);
	if (pos+len > dir->i_size) {
		i_size_write(dir, pos+len);
		mark_inode_dirty(dir);
	}
	if (IS_DIRSYNC(dir))
		err = write_one_page(page, 1);
	else
		unlock_page(page);
	return err;
}
Ejemplo n.º 4
0
/*
 * write out a page to a file
 */
static int write_page(struct bitmap *bitmap, struct page *page, int wait)
{
    int ret = -ENOMEM;

    if (bitmap->file == NULL)
        return write_sb_page(bitmap->mddev, bitmap->offset, page, wait);

    flush_dcache_page(page); /* make sure visible to anyone reading the file */

    if (wait)
        lock_page(page);
    else {
        if (TestSetPageLocked(page))
            return -EAGAIN; /* already locked */
        if (PageWriteback(page)) {
            unlock_page(page);
            return -EAGAIN;
        }
    }

    ret = page->mapping->a_ops->prepare_write(bitmap->file, page, 0, PAGE_SIZE);
    if (!ret)
        ret = page->mapping->a_ops->commit_write(bitmap->file, page, 0,
                PAGE_SIZE);
    if (ret) {
        unlock_page(page);
        return ret;
    }

    set_page_dirty(page); /* force it to be written out */

    if (!wait) {
        /* add to list to be waited for by daemon */
        struct page_list *item = mempool_alloc(bitmap->write_pool, GFP_NOIO);
        item->page = page;
        get_page(page);
        spin_lock(&bitmap->write_lock);
        list_add(&item->list, &bitmap->complete_pages);
        spin_unlock(&bitmap->write_lock);
        md_wakeup_thread(bitmap->writeback_daemon);
    }
    return write_one_page(page, wait);
}
Ejemplo n.º 5
0
//主程序
void main(void)
{
    uint i = 0;
    uint timercount = 0;
    uchar packNO = 1;
    uint bufferPoint = 0;
    uint crc;     
#ifdef  UPDATE_USB    
    uchar s;
    uint j;
    unsigned long UpdateSize = 0;
    uint LabCount = 0,lastdatanum = 0;     
    uchar string[50] = {0};
#endif   
 
//初始化M128的USART0   
    UBRR0L = BAUD_L;            //Set baud rate 
    UBRR0H = BAUD_H; 
    UCSR0B = ((1<<RXEN0)|(1<<TXEN0));        //接收器与发送器使能;
    UCSR0C = (1<<USBS0)|(3<<UCSZ00);        //设置帧格式: 8 个数据位, 1 个停止位;
#ifdef  UPDATE_USB    
//初始化M128的USART1    
    UBRR1L = 8;
    UBRR1H = 0;
    UCSR1B = ((1<<RXEN1)|(1<<TXEN1));        //接收器与发送器使能;
    UCSR1C = (1<<USBS1)|(3<<UCSZ10);        //设置帧格式: 8 个数据位, 1 个停止位;
#endif    
//初始化M128的T/C0,15ms自动重载
    OCR0 = 0x75;
    TCCR0 = 0x0F;                                                               
    TCNT0 = 0;  
    
    DDRB.0 = 1;
    PORTB.0 = 1;  
    /*
    USART_Send_string(a4String1);
    while(uart_getchar()!='O');
    while(uart_getchar()!='K');
    USART_Send_string(a4String2);  
    while(uart_getchar()!='O');
    while(uart_getchar()!='K');  
    */
    USART_Send_string(startupString);//向PC机发送开始提示信息  
    while(1)
    {    
        if(uart_getchar()=='d')break;
        if(TIFR&0x02)
        {
            if(++timercount>500) //若没有进入串口升级模式,则进入U盘升级模式 200*15ms=3s
            {     
#ifdef  UPDATE_USB
    
                sprintf((char*)string,"Enter the USB_Disk Update!\n",UpdateSize);
                USART_Send_string(string);      
                //++++++++++++++++初始化CH376S++++++++++++++++++++++++       
                //CH376_PORT_INIT( );  /* 接口硬件初始化 */
	            xWriteCH376Cmd(CMD11_CHECK_EXIST);  /* 测试单片机与CH376之间的通讯接口 */
	            xWriteCH376Data(0x65);  
	            s = xReadCH376Data( );
	            if (s != 0x9A) 
                    uart_putchar(ERR_USB_UNKNOWN);  /* 通讯接口不正常,可能原因有:接口连接异常,其它设备影响(片选不唯一),串口波特率,一直在复位,晶振不工作 */
	            xWriteCH376Cmd(CMD11_SET_USB_MODE);  /* 设备USB工作模式 */
	            xWriteCH376Data(0x06);
	            s = xReadCH376Data( );
	            if (s != CMD_RET_SUCCESS)  
                {
                    sprintf((char*)string,"USB_Disk is wrong init!\n",UpdateSize);
                    USART_Send_string(string); 
                    quit();
                }   
                //++++++++++++++++++++++END+++++++++++++++++++++++++++++++++
                //检查U盘是否连接好
                i = 0;
                while(CH376DiskConnect() != USB_INT_SUCCESS)
                {
                    if(++i > 5)
                    {   
                        sprintf((char*)string,"USB_Disk is not Connection!\n",UpdateSize);
                        USART_Send_string(string); 
                        quit(); 
                    }
                    delay_ms(100);
                }                  
                i = 0;
                // 对于检测到USB设备的,最多等待10*50mS 
                if(CH376DiskMount() != USB_INT_SUCCESS)
                {
                    if(++i > 5)
                    {
                        sprintf((char*)string,"USB_Disk Test Wrong!\n",UpdateSize);
                        USART_Send_string(string); 
                        quit();
                    }
                    delay_ms(100);   
                }        
                //打开升级文件
                s = CH376FileOpen("J8A-1.U");//每台机子,对应升级文件。
                if (s == ERR_MISS_FILE) //没有找到升级文件则退出
                {
                    CH376FileClose(TRUE);
                    sprintf((char*)string,"I can't fined the Update_File!\n",UpdateSize);
                    USART_Send_string(string);
                    quit();     
                }           
                UpdateSize = CH376GetFileSize(); 
                sprintf((char*)string,"The Update_File size is :%dl\n",UpdateSize); 
                USART_Send_string(string);   
                
                LabCount = UpdateSize/SPM_PAGESIZE;
                lastdatanum = UpdateSize%SPM_PAGESIZE;
                if(lastdatanum) 
                    LabCount++;  
                if(LabCount > (512-32))//mega128的flash页数 
                {
                    sprintf((char*)string,"The Update_File size is too big!",UpdateSize); 
                    USART_Send_string(string);
                    CH376FileClose(FALSE); 
                    quit();
                }
                //读取升级文件数据          
                for(i = 0; i < LabCount; i++)
                {     
                       
                    if(lastdatanum && (i == (LabCount - 1)))     
                    {                                    
                        CH376ByteRead(data, lastdatanum, NULL); 
                        for(j = lastdatanum; j < SPM_PAGESIZE; j++)
                            data[j] = 0xFF;
                    }
                    else
                        CH376ByteRead(data, SPM_PAGESIZE, NULL);        
                    write_one_page();   
                    address = address + SPM_PAGESIZE;    //Flash页加1
                }
                //write_one_page();         //收到256字节写入一页Flash中
                //address = address + SPM_PAGESIZE;    //Flash页加1
                //关闭文件                     
                CH376FileClose(FALSE);
#endif
                quit();
            }
            TIFR=TIFR|0x02;
        }
    }
    //每秒向PC机发送一个控制字符"C",等待控制字〈soh〉
    while(uart_getchar()!= XMODEM_SOH)        //receive the start of Xmodem
    {
         if(TIFR & 0x02)              //timer0 over flow
        {
            if(++timercount > 100)                   //wait about 1 second
            {
                uart_putchar(XMODEM_RECIEVING_WAIT_CHAR);   //send a "C"
                timercount = 0;
            }
            TIFR = TIFR&0x02;
        }
    }
    //开始接收数据块
    do
    {
        if ((packNO == uart_waitchar()) && (packNO ==(~uart_waitchar())))
        {    //核对数据块编号正确
            for(i=0;i<128;i++)             //接收128个字节数据
            {
                data[bufferPoint]= uart_waitchar();
                bufferPoint++;    
            }
            crc = (uint)(uart_waitchar())<<8;
            crc = crc | uart_waitchar();        //接收2个字节的CRC效验字
            if(calcrc(&data[bufferPoint-128],128) == crc)    //CRC校验验证
            {    //正确接收128个字节数据
                while(bufferPoint >= SPM_PAGESIZE)
                {    //正确接受256个字节的数据
                    write_one_page();         //收到256字节写入一页Flash中
                    address = address + SPM_PAGESIZE;    //Flash页加1
                    bufferPoint = 0;
                }    
                uart_putchar(XMODEM_ACK);      //正确收到一个数据块
                packNO++;                      //数据块编号加1
            }
            else
            {
                uart_putchar(XMODEM_NAK);     //要求重发数据块
            }
        }
        else
        {
            uart_putchar(XMODEM_NAK);           //要求重发数据块
        }
    }while(uart_waitchar()!=XMODEM_EOT);          //循环接收,直到全部发完
    uart_putchar(XMODEM_ACK);                    //通知PC机全部收到
    
    if(bufferPoint) write_one_page();        //把剩余的数据写入Flash中
    quit();                //退出Bootloader程序,从0x0000处执行应用程序       
}
Ejemplo n.º 6
0
Archivo: write.c Proyecto: krzk/linux
/*
 * prepare to perform part of a write to a page
 */
int afs_write_begin(struct file *file, struct address_space *mapping,
		    loff_t pos, unsigned len, unsigned flags,
		    struct page **pagep, void **fsdata)
{
	struct afs_vnode *vnode = AFS_FS_I(file_inode(file));
	struct page *page;
	struct key *key = afs_file_key(file);
	unsigned long priv;
	unsigned f, from = pos & (PAGE_SIZE - 1);
	unsigned t, to = from + len;
	pgoff_t index = pos >> PAGE_SHIFT;
	int ret;

	_enter("{%x:%u},{%lx},%u,%u",
	       vnode->fid.vid, vnode->fid.vnode, index, from, to);

	/* We want to store information about how much of a page is altered in
	 * page->private.
	 */
	BUILD_BUG_ON(PAGE_SIZE > 32768 && sizeof(page->private) < 8);

	page = grab_cache_page_write_begin(mapping, index, flags);
	if (!page)
		return -ENOMEM;

	if (!PageUptodate(page) && len != PAGE_SIZE) {
		ret = afs_fill_page(vnode, key, pos & PAGE_MASK, PAGE_SIZE, page);
		if (ret < 0) {
			unlock_page(page);
			put_page(page);
			_leave(" = %d [prep]", ret);
			return ret;
		}
		SetPageUptodate(page);
	}

	/* page won't leak in error case: it eventually gets cleaned off LRU */
	*pagep = page;

try_again:
	/* See if this page is already partially written in a way that we can
	 * merge the new write with.
	 */
	t = f = 0;
	if (PagePrivate(page)) {
		priv = page_private(page);
		f = priv & AFS_PRIV_MAX;
		t = priv >> AFS_PRIV_SHIFT;
		ASSERTCMP(f, <=, t);
	}

	if (f != t) {
		if (PageWriteback(page)) {
			trace_afs_page_dirty(vnode, tracepoint_string("alrdy"),
					     page->index, priv);
			goto flush_conflicting_write;
		}
		/* If the file is being filled locally, allow inter-write
		 * spaces to be merged into writes.  If it's not, only write
		 * back what the user gives us.
		 */
		if (!test_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags) &&
		    (to < f || from > t))
			goto flush_conflicting_write;
		if (from < f)
			f = from;
		if (to > t)
			t = to;
	} else {
		f = from;
		t = to;
	}

	priv = (unsigned long)t << AFS_PRIV_SHIFT;
	priv |= f;
	trace_afs_page_dirty(vnode, tracepoint_string("begin"),
			     page->index, priv);
	SetPagePrivate(page);
	set_page_private(page, priv);
	_leave(" = 0");
	return 0;

	/* The previous write and this write aren't adjacent or overlapping, so
	 * flush the page out.
	 */
flush_conflicting_write:
	_debug("flush conflict");
	ret = write_one_page(page);
	if (ret < 0) {
		_leave(" = %d", ret);
		return ret;
	}

	ret = lock_page_killable(page);
	if (ret < 0) {
		_leave(" = %d", ret);
		return ret;
	}
	goto try_again;
}