xref: /linux/fs/jffs2/writev.c (revision e5451c8f8330e03ad3cfa16048b4daf961af434f)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * JFFS2 -- Journalling Flash File System, Version 2.
31da177e4SLinus Torvalds  *
4c00c310eSDavid Woodhouse  * Copyright © 2001-2007 Red Hat, Inc.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * Created by David Woodhouse <dwmw2@infradead.org>
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * For licensing information, see the file 'LICENCE' in this directory.
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  */
111da177e4SLinus Torvalds 
121da177e4SLinus Torvalds #include <linux/kernel.h>
131da177e4SLinus Torvalds #include <linux/mtd/mtd.h>
141da177e4SLinus Torvalds #include "nodelist.h"
151da177e4SLinus Torvalds 
jffs2_flash_direct_writev(struct jffs2_sb_info * c,const struct kvec * vecs,unsigned long count,loff_t to,size_t * retlen)161da177e4SLinus Torvalds int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs,
171da177e4SLinus Torvalds 			      unsigned long count, loff_t to, size_t *retlen)
181da177e4SLinus Torvalds {
198acff5e9SFerenc Havasi 	if (!jffs2_is_writebuffered(c)) {
20e631ddbaSFerenc Havasi 		if (jffs2_sum_active()) {
21e631ddbaSFerenc Havasi 			int res;
22e631ddbaSFerenc Havasi 			res = jffs2_sum_add_kvec(c, vecs, count, (uint32_t) to);
23e631ddbaSFerenc Havasi 			if (res) {
24e631ddbaSFerenc Havasi 				return res;
25e631ddbaSFerenc Havasi 			}
261da177e4SLinus Torvalds 		}
278acff5e9SFerenc Havasi 	}
281da177e4SLinus Torvalds 
29*b0a31f7bSArtem Bityutskiy 	return mtd_writev(c->mtd, vecs, count, to, retlen);
30e631ddbaSFerenc Havasi }
31e631ddbaSFerenc Havasi 
jffs2_flash_direct_write(struct jffs2_sb_info * c,loff_t ofs,size_t len,size_t * retlen,const u_char * buf)32e631ddbaSFerenc Havasi int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
33e631ddbaSFerenc Havasi 			size_t *retlen, const u_char *buf)
34e631ddbaSFerenc Havasi {
35e631ddbaSFerenc Havasi 	int ret;
36eda95cbfSArtem Bityutskiy 	ret = mtd_write(c->mtd, ofs, len, retlen, buf);
37e631ddbaSFerenc Havasi 
38e631ddbaSFerenc Havasi 	if (jffs2_sum_active()) {
39e631ddbaSFerenc Havasi 		struct kvec vecs[1];
40e631ddbaSFerenc Havasi 		int res;
41e631ddbaSFerenc Havasi 
42e631ddbaSFerenc Havasi 		vecs[0].iov_base = (unsigned char *) buf;
43e631ddbaSFerenc Havasi 		vecs[0].iov_len = len;
44e631ddbaSFerenc Havasi 
45e631ddbaSFerenc Havasi 		res = jffs2_sum_add_kvec(c, vecs, 1, (uint32_t) ofs);
46e631ddbaSFerenc Havasi 		if (res) {
47e631ddbaSFerenc Havasi 			return res;
48e631ddbaSFerenc Havasi 		}
49e631ddbaSFerenc Havasi 	}
50e631ddbaSFerenc Havasi 	return ret;
51e631ddbaSFerenc Havasi }
52