]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/kern_symfile.c
xnu-7195.81.3.tar.gz
[apple/xnu.git] / bsd / kern / kern_symfile.c
index 2ec92f29a12fa1ed779341acf2c7ee92779d5432..720ebf9bfcc3f503b5ced00081a1ebe30ed4dd17 100644 (file)
@@ -62,8 +62,9 @@
 #include <pexpert/pexpert.h>
 #include <IOKit/IOPolledInterface.h>
 
-#define HIBERNATE_MIN_PHYSICAL_LBA    (34)
-#define HIBERNATE_MIN_FILE_SIZE       (1024*1024)
+#define HIBERNATE_MIN_PHYSICAL_LBA_512    (34)
+#define HIBERNATE_MIN_PHYSICAL_LBA_4096   (6)
+#define HIBERNATE_MIN_FILE_SIZE           (1024*1024)
 
 /* This function is called from kern_sysctl in the current process context;
  * it is exported with the System6.0.exports, but this appears to be a legacy
@@ -161,7 +162,7 @@ kern_ioctl_file_extents(struct kern_direct_file_io_ref_t * ref, u_long theIoctl,
                        fileblk = blkno * ref->blksize;
                } else if ((ref->vp->v_type == VBLK) || (ref->vp->v_type == VCHR)) {
                        fileblk = offset;
-                       filechunk = ref->filelength;
+                       filechunk = (unsigned long)((ref->filelength > ULONG_MAX) ? ULONG_MAX: ref->filelength);
                }
 
                if (DKIOCUNMAP == theIoctl) {
@@ -233,7 +234,8 @@ kern_open_file_for_direct_io(const char * name,
        uint32_t          blksize;
        off_t             maxiocount, count, segcount, wbctotal;
        boolean_t         locked = FALSE;
-       int               fmode, cmode;
+       int               fmode;
+       mode_t                    cmode;
        struct            nameidata nd;
        u_int32_t         ndflags;
        off_t             mpFree;
@@ -379,7 +381,11 @@ kern_open_file_for_direct_io(const char * name,
                goto out;
        }
 
-       minoffset = HIBERNATE_MIN_PHYSICAL_LBA * ref->blksize;
+       if (ref->blksize == 4096) {
+               minoffset = HIBERNATE_MIN_PHYSICAL_LBA_4096 * ref->blksize;
+       } else {
+               minoffset = HIBERNATE_MIN_PHYSICAL_LBA_512 * ref->blksize;
+       }
 
        if (ref->vp->v_type != VREG) {
                error = do_ioctl(p1, p2, DKIOCGETBLOCKCOUNT, (caddr_t) &fileblk);
@@ -430,7 +436,7 @@ kern_open_file_for_direct_io(const char * name,
                        fileblk = blkno * ref->blksize;
                } else if ((ref->vp->v_type == VBLK) || (ref->vp->v_type == VCHR)) {
                        fileblk = f_offset;
-                       filechunk = f_offset ? 0 : ref->filelength;
+                       filechunk = f_offset ? 0 : (unsigned long)ref->filelength;
                }
 
                physoffset = 0;
@@ -616,8 +622,9 @@ out:
 int
 kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, void * addr, size_t len, int ioflag)
 {
+       assert(len <= INT32_MAX);
        return vn_rdwr(UIO_WRITE, ref->vp,
-                  addr, len, offset,
+                  addr, (int)len, offset,
                   UIO_SYSSPACE, ioflag | IO_SYNC | IO_NODELOCKED | IO_UNIT,
                   vfs_context_ucred(ref->ctx), (int *) 0,
                   vfs_context_proc(ref->ctx));
@@ -626,8 +633,9 @@ kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, void * add
 int
 kern_read_file(struct kern_direct_file_io_ref_t * ref, off_t offset, void * addr, size_t len, int ioflag)
 {
+       assert(len <= INT32_MAX);
        return vn_rdwr(UIO_READ, ref->vp,
-                  addr, len, offset,
+                  addr, (int)len, offset,
                   UIO_SYSSPACE, ioflag | IO_SYNC | IO_NODELOCKED | IO_UNIT,
                   vfs_context_ucred(ref->ctx), (int *) 0,
                   vfs_context_proc(ref->ctx));