static int nfs_file_write(struct inode *inode, struct file *file, char *buf, int count) { int result; int hunk; int i; int n; struct nfs_fattr fattr; char *data; int pos; if (!inode) { printk("nfs_file_write: inode = NULL\n"); return -EINVAL; } if (!S_ISREG(inode->i_mode)) { printk("nfs_file_write: write to non-file, mode %07o\n", inode->i_mode); return -EINVAL; } if (count <= 0) return 0; pos = file->f_pos; if (file->f_flags & O_APPEND) pos = inode->i_size; n = NFS_SERVER(inode)->wsize; data = (char *) kmalloc(n, GFP_KERNEL); for (i = 0; i < count; i += n) { hunk = count - i; if (hunk >= n) hunk = n; memcpy_fromfs(data, buf, hunk); result = nfs_proc_write(NFS_SERVER(inode), NFS_FH(inode), pos, hunk, data, &fattr); if (result < 0) { kfree_s(data, n); return result; } pos += hunk; buf += hunk; if (hunk < n) { i += hunk; break; } } file->f_pos = pos; kfree_s(data, n); nfs_refresh_inode(inode, &fattr); return i; }
static int nfs_file_write(struct inode *inode, struct file *file, char *buf, int count) { int result, hunk, i, n, pos; struct nfs_fattr fattr; if (!inode) { printk("nfs_file_write: inode = NULL\n"); return -EINVAL; } if (!S_ISREG(inode->i_mode)) { printk("nfs_file_write: write to non-file, mode %07o\n", inode->i_mode); return -EINVAL; } if (count <= 0) return 0; pos = file->f_pos; if (file->f_flags & O_APPEND) pos = inode->i_size; n = NFS_SERVER(inode)->wsize; for (i = 0; i < count; i += n) { hunk = count - i; if (hunk >= n) hunk = n; result = nfs_proc_write(NFS_SERVER(inode), NFS_FH(inode), pos, hunk, buf, &fattr); if (result < 0) return result; pos += hunk; buf += hunk; if (hunk < n) { i += hunk; break; } } file->f_pos = pos; nfs_refresh_inode(inode, &fattr); return i; }