Lines Matching refs:fd

676  * @fd:		a win_fd structure that will be filled
689 static int ntfs_device_win32_getgeo(HANDLE handle, win32_fd *fd)
705 fd->geo_cylinders = ((DISK_GEOMETRY*)&b)->Cylinders.QuadPart;
706 fd->geo_sectors = ((DISK_GEOMETRY*)&b)->SectorsPerTrack;
707 fd->geo_size = ((DISK_GEOMETRY_EX*)&b)->DiskSize.QuadPart;
708 fd->geo_sector_size = NTFS_BLOCK_SIZE;
711 fd->geo_cylinders = ddi->Int13.MaxCylinders;
712 fd->geo_sectors = ddi->Int13.SectorsPerTrack;
713 fd->geo_heads = ddi->Int13.MaxHeads;
716 fd->geo_cylinders = ddi->ExInt13.ExCylinders;
717 fd->geo_sectors = ddi->ExInt13.ExSectorsPerTrack;
718 fd->geo_heads = ddi->ExInt13.ExHeads;
725 fd->geo_heads = -1;
730 fd->geo_cylinders = ((DISK_GEOMETRY*)&b)->Cylinders.QuadPart;
731 fd->geo_sectors = ((DISK_GEOMETRY*)&b)->SectorsPerTrack;
732 fd->geo_size = fd->geo_cylinders * fd->geo_sectors *
735 fd->geo_sector_size = ((DISK_GEOMETRY*)&b)->BytesPerSector;
740 fd->geo_cylinders = -1;
741 fd->geo_sectors = -1;
742 fd->geo_size = -1;
743 fd->geo_sector_size = NTFS_BLOCK_SIZE;
747 static int ntfs_device_win32_getntgeo(HANDLE handle, win32_fd *fd)
756 fd->geo_cylinders = 0;
757 fd->geo_sectors = 0;
758 fd->geo_size = 1073741824;
759 fd->geo_sectors = fd->geo_size >> 9;
760 fd->geo_sector_size = NTFS_BLOCK_SIZE;
768 fd->geo_cylinders = geo.Cylinders.QuadPart + 1;
769 fd->geo_sectors = fd->geo_cylinders
771 fd->geo_size = fd->geo_sectors*geo.BytesPerSector;
772 fd->geo_sector_size = geo.BytesPerSector;
781 fd->geo_size = bytes;
782 fd->geo_sectors = bytes/geo.BytesPerSector;
791 * @fd: pointer to win32 file device in which to put the result
797 static __inline__ int ntfs_device_win32_open_file(char *filename, win32_fd *fd,
817 /* fill fd */
818 fd->handle = handle;
819 fd->part_start = 0;
820 fd->part_length = ntfs_device_win32_getsize(handle);
821 fd->pos = 0;
822 fd->part_hidden_sectors = -1;
823 fd->geo_size = -1; /* used as a marker that this is a file */
824 fd->vol_handle = INVALID_HANDLE_VALUE;
825 fd->geo_sector_size = 512; /* will be adjusted from the boot sector */
826 fd->ntdll = FALSE;
833 * @fd: pointer to win32 file device in which to put the result
839 static __inline__ int ntfs_device_win32_open_drive(int drive_id, win32_fd *fd,
853 ntfs_device_win32_getgeo(handle, fd);
855 if (fd->geo_size == -1)
856 fd->geo_size = ntfs_device_win32_getdisklength(handle);
857 /* fill fd */
858 fd->ntdll = FALSE;
859 fd->handle = handle;
860 fd->part_start = 0;
861 fd->part_length = fd->geo_size;
862 fd->pos = 0;
863 fd->part_hidden_sectors = -1;
864 fd->vol_handle = INVALID_HANDLE_VALUE;
871 * @fd: pointer to win32 file device in which to put the result
878 win32_fd *fd, int flags)
928 ntfs_device_win32_getntgeo(handle, fd);
929 fd->ntdll = TRUE;
941 /* fill fd */
942 fd->handle = handle;
943 fd->part_start = 0;
944 fd->part_length = fd->geo_size;
945 fd->pos = 0;
946 fd->part_hidden_sectors = -1;
947 fd->vol_handle = INVALID_HANDLE_VALUE;
1121 * @fd: win32 file device to return
1127 * When fails, fd contents may have not been preserved.
1130 unsigned int partition_id, win32_fd *fd, int flags)
1150 ntfs_device_win32_getgeo(handle, fd);
1151 fd->handle = handle;
1152 fd->pos = 0;
1153 fd->part_start = part_start;
1154 fd->part_length = part_length;
1155 fd->part_hidden_sectors = hidden_sectors;
1156 fd->geo_sector_size = 512;
1157 fd->ntdll = FALSE;
1160 fd->geo_size = tmp;
1162 fd->geo_size = fd->part_length;
1170 fd->vol_handle = vol_handle;
1182 fd->vol_handle = INVALID_HANDLE_VALUE;
1211 win32_fd fd;
1230 err = ntfs_device_win32_open_file(dev->d_name, &fd, flags);
1235 err = ntfs_device_win32_open_drive(drive_id, &fd, flags);
1240 err = ntfs_device_win32_open_partition(drive_id, part, &fd,
1246 err = ntfs_device_win32_open_lowlevel(drive_id, &fd,
1257 dev, fd.part_start);
1262 memcpy(dev->d_private, &fd, sizeof(win32_fd));
1286 win32_fd *fd = (win32_fd *)dev->d_private;
1294 abs_ofs = fd->pos + offset;
1298 if (fd->part_length == -1) {
1304 abs_ofs = fd->part_length + offset;
1312 || (fd->ntdll && (abs_ofs > fd->part_length))) {
1317 fd->pos = abs_ofs;
1323 * @fd: win32 device descriptor obtained via ->open
1330 * error returns -1 and errno set. Transfer starts from position @pos on @fd.
1336 * - Does not use/set @fd->pos.
1338 static s64 ntfs_device_win32_pio(win32_fd *fd, const s64 pos,
1351 if (fd->vol_handle != INVALID_HANDLE_VALUE && pos < fd->geo_size) {
1353 handle = fd->vol_handle;
1356 handle = fd->handle;
1357 li.QuadPart += fd->part_start;
1360 if (fd->ntdll) {
1369 res = NtWriteFile(fd->handle,(HANDLE)NULL,
1374 res = NtReadFile(fd->handle,(HANDLE)NULL,
1405 fd->geo_sector_size = (boot[11] & 255)
1414 * @fd: win32 device descriptor obtained via ->open
1426 * - Does not use/set @fd->pos.
1428 static inline s64 ntfs_device_win32_pread_simple(win32_fd *fd, const s64 pos,
1431 return ntfs_device_win32_pio(fd, pos, count, b, (void*)NULL);
1446 win32_fd *fd = (win32_fd *)dev->d_private;
1450 old_pos = fd->pos;
1451 old_ofs = ofs = old_pos & (fd->geo_sector_size - 1);
1452 to_read = (ofs + count + fd->geo_sector_size - 1) &
1453 ~(s64)(fd->geo_sector_size - 1);
1460 ntfs_log_trace("fd = %p, b = %p, count = 0x%llx, pos = 0x%llx, "
1461 "ofs = %i, to_read = 0x%llx.\n", fd, b,
1464 if (!((unsigned long)b & (fd->geo_sector_size - 1)) && !old_ofs &&
1465 !(count & (fd->geo_sector_size - 1)))
1476 if (fd->vol_handle != INVALID_HANDLE_VALUE && old_pos < fd->geo_size) {
1477 s64 vol_to_read = fd->geo_size - old_pos;
1479 br = ntfs_device_win32_pread_simple(fd,
1480 old_pos & ~(s64)(fd->geo_sector_size - 1),
1490 fd->pos += br;
1491 ofs = fd->pos & (fd->geo_sector_size - 1);
1496 i = ntfs_device_win32_pread_simple(fd,
1497 fd->pos & ~(s64)(fd->geo_sector_size - 1), to_read,
1510 fd->pos = old_pos + br;
1528 * -1 if not, and errno set. Note if error fd->vol_handle is trashed.
1532 win32_fd *fd = (win32_fd *)dev->d_private;
1540 if (fd->vol_handle != INVALID_HANDLE_VALUE) {
1542 ntfs_device_win32_dismount(fd->vol_handle);
1543 ntfs_device_win32_unlock(fd->vol_handle);
1545 if (!CloseHandle(fd->vol_handle))
1548 if (fd->ntdll) {
1549 ntfs_device_win32_setlock(fd->handle,FSCTL_UNLOCK_VOLUME);
1550 rvl = NtClose(fd->handle) == STATUS_SUCCESS;
1552 rvl = CloseHandle(fd->handle);
1554 free(fd);
1557 if (fd->ntdll)
1582 win32_fd *fd = (win32_fd *)dev->d_private;
1584 if ((fd->vol_handle != INVALID_HANDLE_VALUE) &&
1585 !FlushFileBuffers(fd->vol_handle)) {
1589 if (!FlushFileBuffers(fd->handle)) {
1606 * @fd: win32 device descriptor obtained via ->open
1618 * - Does not use/set @fd->pos.
1620 static inline s64 ntfs_device_win32_pwrite_simple(win32_fd *fd, const s64 pos,
1623 return ntfs_device_win32_pio(fd, pos, count, (void*)NULL, b);
1639 win32_fd *fd = (win32_fd *)dev->d_private;
1644 old_pos = fd->pos;
1645 old_ofs = ofs = old_pos & (fd->geo_sector_size - 1);
1646 to_write = (ofs + count + fd->geo_sector_size - 1) &
1647 ~(s64)(fd->geo_sector_size - 1);
1654 ntfs_log_trace("fd = %p, b = %p, count = 0x%llx, pos = 0x%llx, "
1655 "ofs = %i, to_write = 0x%llx.\n", fd, b,
1667 if (!((unsigned long)b & (fd->geo_sector_size - 1)) && !old_ofs &&
1668 !(count & (fd->geo_sector_size - 1)))
1682 i = ntfs_device_win32_pread_simple(fd,
1683 old_pos & ~(s64)(fd->geo_sector_size - 1),
1684 fd->geo_sector_size, readbuffer);
1685 if (i != fd->geo_sector_size) {
1698 if ((end & (fd->geo_sector_size - 1)) &&
1699 ((to_write > fd->geo_sector_size) || !ofs)) {
1700 i = ntfs_device_win32_pread_simple(fd,
1701 end & ~(s64)(fd->geo_sector_size - 1),
1702 fd->geo_sector_size, readbuffer +
1703 to_write - fd->geo_sector_size);
1704 if (i != fd->geo_sector_size) {
1714 if (fd->vol_handle != INVALID_HANDLE_VALUE && old_pos < fd->geo_size) {
1715 s64 vol_to_write = fd->geo_size - old_pos;
1717 bw = ntfs_device_win32_pwrite_simple(fd,
1718 old_pos & ~(s64)(fd->geo_sector_size - 1),
1728 fd->pos += bw;
1729 ofs = fd->pos & (fd->geo_sector_size - 1);
1734 i = ntfs_device_win32_pwrite_simple(fd,
1735 fd->pos & ~(s64)(fd->geo_sector_size - 1), to_write,
1748 fd->pos = old_pos + bw;
1770 win32_fd *fd = (win32_fd *)dev->d_private;
1776 switch (GetFileType(fd->handle)) {
1791 buf->st_size = fd->part_length;
1808 * -1 if not, and errno set. Note if error fd->handle is trashed.
1813 win32_fd *fd = (win32_fd *)dev->d_private;
1815 argp->heads = fd->geo_heads;
1816 argp->sectors = fd->geo_sectors;
1817 argp->cylinders = fd->geo_cylinders;
1818 argp->start = fd->part_hidden_sectors;
1831 * -1 if not, and errno set. Note if error fd->handle is trashed.
1835 win32_fd *fd = (win32_fd *)dev->d_private;
1839 if (DeviceIoControl(fd->handle, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
1854 win32_fd *fd = (win32_fd *)dev->d_private;
1862 if (fd->part_length >= 0) {
1863 *(int *)argp = (int)(fd->part_length / 512);
1872 if (fd->part_length >= 0) {
1873 *(s64 *)argp = fd->part_length;
1887 if (fd && !fd->ntdll) {
1888 *(int*)argp = fd->geo_sector_size;
1910 win32_fd *fd;
1913 fd = (win32_fd*)dev->d_private;
1914 if (!((count | offset) & (fd->geo_sector_size - 1))) {
1915 got = ntfs_device_win32_pio(fd, offset, count, b, (void*)NULL);
1930 win32_fd *fd;
1933 fd = (win32_fd*)dev->d_private;
1934 if (!((count | offset) & (fd->geo_sector_size - 1))) {
1935 put = ntfs_device_win32_pio(fd, offset, count, (void*)NULL, b);
1967 int ntfs_win32_set_sparse(int fd)
1973 handle = get_osfhandle(fd);
2022 win32_fd *fd;
2026 fd = (win32_fd*)dev->d_private;
2027 if (fd && !fd->ntdll)
2028 ret = win32_ftruncate(fd->handle, size);
2032 int ntfs_win32_ftruncate(int fd, s64 size)
2037 handle = get_osfhandle(fd);