Deleted Added
full compact
vfs_default.c (220791) vfs_default.c (220846)
1/*-
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed
6 * to Berkeley by John Heidemann of the UCLA Ficus project.
7 *
8 * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project

--- 19 unchanged lines hidden (view full) ---

28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed
6 * to Berkeley by John Heidemann of the UCLA Ficus project.
7 *
8 * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project

--- 19 unchanged lines hidden (view full) ---

28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/sys/kern/vfs_default.c 220791 2011-04-18 16:32:22Z mdf $");
36__FBSDID("$FreeBSD: head/sys/kern/vfs_default.c 220846 2011-04-19 16:36:24Z mdf $");
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/bio.h>
41#include <sys/buf.h>
42#include <sys/conf.h>
43#include <sys/event.h>
44#include <sys/kernel.h>

--- 815 unchanged lines hidden (view full) ---

860vop_stdallocate(struct vop_allocate_args *ap)
861{
862#ifdef __notyet__
863 struct statfs sfs;
864#endif
865 struct iovec aiov;
866 struct vattr vattr, *vap;
867 struct uio auio;
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/bio.h>
41#include <sys/buf.h>
42#include <sys/conf.h>
43#include <sys/event.h>
44#include <sys/kernel.h>

--- 815 unchanged lines hidden (view full) ---

860vop_stdallocate(struct vop_allocate_args *ap)
861{
862#ifdef __notyet__
863 struct statfs sfs;
864#endif
865 struct iovec aiov;
866 struct vattr vattr, *vap;
867 struct uio auio;
868 off_t len, cur, offset;
868 off_t fsize, len, cur, offset;
869 uint8_t *buf;
870 struct thread *td;
871 struct vnode *vp;
872 size_t iosize;
869 uint8_t *buf;
870 struct thread *td;
871 struct vnode *vp;
872 size_t iosize;
873 int error, locked;
873 int error;
874
875 buf = NULL;
876 error = 0;
874
875 buf = NULL;
876 error = 0;
877 locked = 1;
878 td = curthread;
879 vap = &vattr;
880 vp = ap->a_vp;
877 td = curthread;
878 vap = &vattr;
879 vp = ap->a_vp;
881 len = ap->a_len;
882 offset = ap->a_offset;
880 len = *ap->a_len;
881 offset = *ap->a_offset;
883
884 error = VOP_GETATTR(vp, vap, td->td_ucred);
885 if (error != 0)
886 goto out;
882
883 error = VOP_GETATTR(vp, vap, td->td_ucred);
884 if (error != 0)
885 goto out;
886 fsize = vap->va_size;
887 iosize = vap->va_blocksize;
888 if (iosize == 0)
889 iosize = BLKDEV_IOSIZE;
890 if (iosize > MAXPHYS)
891 iosize = MAXPHYS;
892 buf = malloc(iosize, M_TEMP, M_WAITOK);
893
894#ifdef __notyet__

--- 8 unchanged lines hidden (view full) ---

903 if (offset > sfs.f_maxfilesize || len > sfs.f_maxfilesize ||
904 offset + len > sfs.f_maxfilesize) {
905 error = EFBIG;
906 goto out;
907 }
908 } else
909#endif
910 if (offset + len > vap->va_size) {
887 iosize = vap->va_blocksize;
888 if (iosize == 0)
889 iosize = BLKDEV_IOSIZE;
890 if (iosize > MAXPHYS)
891 iosize = MAXPHYS;
892 buf = malloc(iosize, M_TEMP, M_WAITOK);
893
894#ifdef __notyet__

--- 8 unchanged lines hidden (view full) ---

903 if (offset > sfs.f_maxfilesize || len > sfs.f_maxfilesize ||
904 offset + len > sfs.f_maxfilesize) {
905 error = EFBIG;
906 goto out;
907 }
908 } else
909#endif
910 if (offset + len > vap->va_size) {
911 /*
912 * Test offset + len against the filesystem's maxfilesize.
913 */
911 VATTR_NULL(vap);
912 vap->va_size = offset + len;
913 error = VOP_SETATTR(vp, vap, td->td_ucred);
914 if (error != 0)
915 goto out;
914 VATTR_NULL(vap);
915 vap->va_size = offset + len;
916 error = VOP_SETATTR(vp, vap, td->td_ucred);
917 if (error != 0)
918 goto out;
919 VATTR_NULL(vap);
920 vap->va_size = fsize;
921 error = VOP_SETATTR(vp, vap, td->td_ucred);
922 if (error != 0)
923 goto out;
916 }
917
924 }
925
918 while (len > 0) {
919 if (should_yield()) {
920 VOP_UNLOCK(vp, 0);
921 locked = 0;
922 kern_yield(-1);
923 error = vn_lock(vp, LK_EXCLUSIVE);
924 if (error != 0)
925 break;
926 locked = 1;
927 error = VOP_GETATTR(vp, vap, td->td_ucred);
928 if (error != 0)
929 break;
930 }
931
926 for (;;) {
932 /*
933 * Read and write back anything below the nominal file
934 * size. There's currently no way outside the filesystem
935 * to know whether this area is sparse or not.
936 */
937 cur = iosize;
938 if ((offset % iosize) != 0)
939 cur -= (offset % iosize);
940 if (cur > len)
941 cur = len;
927 /*
928 * Read and write back anything below the nominal file
929 * size. There's currently no way outside the filesystem
930 * to know whether this area is sparse or not.
931 */
932 cur = iosize;
933 if ((offset % iosize) != 0)
934 cur -= (offset % iosize);
935 if (cur > len)
936 cur = len;
942 if (offset < vap->va_size) {
937 if (offset < fsize) {
943 aiov.iov_base = buf;
944 aiov.iov_len = cur;
945 auio.uio_iov = &aiov;
946 auio.uio_iovcnt = 1;
947 auio.uio_offset = offset;
948 auio.uio_resid = cur;
949 auio.uio_segflg = UIO_SYSSPACE;
950 auio.uio_rw = UIO_READ;

--- 20 unchanged lines hidden (view full) ---

971 auio.uio_td = td;
972
973 error = VOP_WRITE(vp, &auio, 0, td->td_ucred);
974 if (error != 0)
975 break;
976
977 len -= cur;
978 offset += cur;
938 aiov.iov_base = buf;
939 aiov.iov_len = cur;
940 auio.uio_iov = &aiov;
941 auio.uio_iovcnt = 1;
942 auio.uio_offset = offset;
943 auio.uio_resid = cur;
944 auio.uio_segflg = UIO_SYSSPACE;
945 auio.uio_rw = UIO_READ;

--- 20 unchanged lines hidden (view full) ---

966 auio.uio_td = td;
967
968 error = VOP_WRITE(vp, &auio, 0, td->td_ucred);
969 if (error != 0)
970 break;
971
972 len -= cur;
973 offset += cur;
974 if (len == 0)
975 break;
976 if (should_yield())
977 break;
979 }
980
981 out:
978 }
979
980 out:
982 KASSERT(locked || error != 0, ("How'd I get unlocked with no error?"));
983 if (locked && error != 0)
984 VOP_UNLOCK(vp, 0);
981 *ap->a_len = len;
982 *ap->a_offset = offset;
985 free(buf, M_TEMP);
986 return (error);
987}
988
989/*
990 * vfs default ops
991 * used to fill the vfs function table to get reasonable default return values.
992 */

--- 143 unchanged lines hidden ---
983 free(buf, M_TEMP);
984 return (error);
985}
986
987/*
988 * vfs default ops
989 * used to fill the vfs function table to get reasonable default return values.
990 */

--- 143 unchanged lines hidden ---