mirror of
https://github.com/digarok/gsplus.git
synced 2025-02-20 02:28:57 +00:00
move win32 host to separate file. (in progress).
This commit is contained in:
parent
e6f9adc1de
commit
0bde878d05
220
src/host_fst.c
220
src/host_fst.c
@ -2,12 +2,6 @@
|
|||||||
* host_fst.c
|
* host_fst.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#define _WIN32_WINNT 0x0600 // vista+
|
|
||||||
#include <Windows.h>
|
|
||||||
#include <io.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define _BSD_SOURCE
|
#define _BSD_SOURCE
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -242,17 +236,17 @@ static word32 remove_fd(int fd) {
|
|||||||
rv = 0;
|
rv = 0;
|
||||||
|
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
if (head->fd >= PSEUDO_FD_BASE) pseudo_fd_free(head->fd);
|
||||||
switch (head->type) {
|
switch (head->type) {
|
||||||
case regular_file:
|
case regular_file:
|
||||||
case resource_file:
|
case resource_file:
|
||||||
ok = close(head->fd);
|
ok = close(head->fd);
|
||||||
|
if (ok < 0) rv = map_errno();
|
||||||
break;
|
break;
|
||||||
case directory_file:
|
case directory_file:
|
||||||
dir_free(head->dir);
|
dir_free(head->dir);
|
||||||
pseudo_fd_free(head->fd);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ok < 0) rv = map_errno();
|
|
||||||
free(head->path);
|
free(head->path);
|
||||||
free(head);
|
free(head);
|
||||||
break;
|
break;
|
||||||
@ -437,29 +431,6 @@ static void get_file_xinfo(const char *path, struct file_info *fi) {
|
|||||||
|
|
||||||
finder_info_to_filetype(fi->finder_info, &fi->file_type, &fi->aux_type);
|
finder_info_to_filetype(fi->finder_info, &fi->file_type, &fi->aux_type);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#elif defined _WIN32
|
|
||||||
static void get_file_xinfo(const char *path, struct file_info *fi) {
|
|
||||||
|
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
char *p = append_string(path, ":AFP_Resource");
|
|
||||||
if (stat(p, &st) == 0) {
|
|
||||||
fi->resource_eof = st.st_size;
|
|
||||||
fi->resource_blocks = st.st_blocks;
|
|
||||||
}
|
|
||||||
p = append_string(path, ":" XATTR_FINDERINFO_NAME);
|
|
||||||
int fd = open(p, O_RDONLY);
|
|
||||||
if (fd >= 0) {
|
|
||||||
int tmp = read(fd, fi->finder_info, 32);
|
|
||||||
if (tmp == 16 || tmp == 32) {
|
|
||||||
fi->has_fi = 1;
|
|
||||||
finder_info_to_filetype(fi->finder_info, &fi->file_type, &fi->aux_type);
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#elif defined(__sun)
|
#elif defined(__sun)
|
||||||
static void get_file_xinfo(const char *path, struct file_info *fi) {
|
static void get_file_xinfo(const char *path, struct file_info *fi) {
|
||||||
@ -603,59 +574,6 @@ static word32 set_file_info(const char *path, struct file_info *fi) {
|
|||||||
if (i) ok = setattrlist(path, &list, dates, i * sizeof(struct timespec), 0);
|
if (i) ok = setattrlist(path, &list, dates, i * sizeof(struct timespec), 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#elif defined _WIN32
|
|
||||||
|
|
||||||
|
|
||||||
static void UnixTimeToFileTime(time_t t, LARGE_INTEGER *out)
|
|
||||||
{
|
|
||||||
if (t) {
|
|
||||||
out->QuadPart = Int32x32To64(t, 10000000) + 116444736000000000;
|
|
||||||
} else {
|
|
||||||
out->QuadPart = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static word32 set_file_info(const char *path, struct file_info *fi) {
|
|
||||||
|
|
||||||
if (fi->has_fi && fi->storage_type != 0x0d) {
|
|
||||||
char *rpath = append_string(path, ":" XATTR_FINDERINFO_NAME);
|
|
||||||
int fd = open(rpath, O_WRONLY | O_CREAT, 0666);
|
|
||||||
if (fd < 0) return map_errno();
|
|
||||||
write(fd, fi->finder_info, 32);
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fi->create_date || fi->modified_date) {
|
|
||||||
// SetFileInformationByHandle can modify dates.
|
|
||||||
int fd = open(path, O_RDONLY); // ?
|
|
||||||
if (fd < 0) return 0;
|
|
||||||
|
|
||||||
// just use FILETIME in the file_info if WIN32?
|
|
||||||
|
|
||||||
FILE_BASIC_INFO fbi;
|
|
||||||
memset(&fbi, 0, sizeof(fbi));
|
|
||||||
|
|
||||||
if (fi->create_date) {
|
|
||||||
UnixTimeToFileTime(fi->create_date, &fbi.CreationTime);
|
|
||||||
}
|
|
||||||
if (fi->modified_date) {
|
|
||||||
LARGE_INTEGER ft;
|
|
||||||
UnixTimeToFileTime(fi->modified_date, &ft);
|
|
||||||
fbi.ChangeTime = ft;
|
|
||||||
fbi.LastAccessTime = ft;
|
|
||||||
fbi.LastWriteTime = ft;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
HANDLE h = (HANDLE)get_osfhandle(fd);
|
|
||||||
BOOL ok = SetFileInformationByHandle(h, FileBasicInfo, &fbi, sizeof(fbi));
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(__sun)
|
#elif defined(__sun)
|
||||||
static word32 set_file_info(const char *path, struct file_info *fi) {
|
static word32 set_file_info(const char *path, struct file_info *fi) {
|
||||||
|
|
||||||
@ -703,14 +621,14 @@ static word32 set_file_info(const char *path, struct file_info *fi) {
|
|||||||
|
|
||||||
static word32 set_file_info(const char *path, struct file_info *fi) {
|
static word32 set_file_info(const char *path, struct file_info *fi) {
|
||||||
|
|
||||||
if (fi.modified_date) {
|
if (fi->modified_date) {
|
||||||
|
|
||||||
struct timeval times[2];
|
struct timeval times[2];
|
||||||
|
|
||||||
memset(times, 0, sizeof(times));
|
memset(times, 0, sizeof(times));
|
||||||
|
|
||||||
times[0] = 0; // access
|
times[0] = 0; // access
|
||||||
times[1].tv_sec = fi.modified_date; // modified
|
times[1].tv_sec = fi->modified_date; // modified
|
||||||
|
|
||||||
int ok = utimes(path, times);
|
int ok = utimes(path, times);
|
||||||
if (ok < 0) return map_errno();
|
if (ok < 0) return map_errno();
|
||||||
@ -1012,14 +930,15 @@ static word32 fst_shutdown(void) {
|
|||||||
struct fd_entry *head = fd_head;
|
struct fd_entry *head = fd_head;
|
||||||
while (head) {
|
while (head) {
|
||||||
struct fd_entry *tmp = head->next;
|
struct fd_entry *tmp = head->next;
|
||||||
|
if (head->fd >= PSEUDO_FD_BASE) pseudo_fd_free(head->fd);
|
||||||
switch(head->type) {
|
switch(head->type) {
|
||||||
case regular_file:
|
case regular_file:
|
||||||
case resource_file:
|
case resource_file:
|
||||||
close(head->fd);
|
if (head->fd >= 0 && head->fd < PSEUDO_FD_BASE)
|
||||||
|
close(head->fd);
|
||||||
break;
|
break;
|
||||||
case directory_file:
|
case directory_file:
|
||||||
dir_free(head->dir);
|
dir_free(head->dir);
|
||||||
pseudo_fd_free(head->fd);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(head->path);
|
free(head->path);
|
||||||
@ -1453,121 +1372,6 @@ static int open_resource_fork(const char *path, word16 *access, word16 *error) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
|
|
||||||
#ifdef __CYGWIN__
|
|
||||||
|
|
||||||
#include <sys/cygwin.h>
|
|
||||||
|
|
||||||
int cygwin_open_attr(const char *path, const char *attr, word16 *access, word16 *error) {
|
|
||||||
|
|
||||||
char buffer[PATH_MAX];
|
|
||||||
ssize_t ok = cygwin_conv_path(CCP_POSIX_TO_WIN_A, path, buffer, sizeof(buffer));
|
|
||||||
if (ok < 0) {
|
|
||||||
*error = fstError;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
int uAccess = 0;
|
|
||||||
DWORD wAccess = 0;
|
|
||||||
|
|
||||||
char *rpath = append_string(path, attr);
|
|
||||||
|
|
||||||
HANDLE h = INVALID_HANDLE_VALUE;
|
|
||||||
for (;;) {
|
|
||||||
DWORD wCreate = 0;
|
|
||||||
|
|
||||||
switch(*access) {
|
|
||||||
case readEnableAllowWrite:
|
|
||||||
case readWriteEnable:
|
|
||||||
wAccess = GENERIC_READ | GENERIC_WRITE;
|
|
||||||
wCreate = OPEN_ALWAYS;
|
|
||||||
uAccess = O_RDWR;
|
|
||||||
break;
|
|
||||||
case readEnable:
|
|
||||||
wAccess = GENERIC_READ;
|
|
||||||
wCreate = OPEN_EXISTING;
|
|
||||||
uAccess = O_RDONLY;
|
|
||||||
break;
|
|
||||||
case writeEnable:
|
|
||||||
wAccess = GENERIC_WRITE;
|
|
||||||
wCreate = OPEN_ALWAYS;
|
|
||||||
uAccess = O_WRONLY;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
h = CreateFile(path, wAccess, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, wCreate, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
|
|
||||||
if (*access ==readEnableAllowWrite) {
|
|
||||||
if (h == INVALID_HANDLE_VALUE) {
|
|
||||||
*access = readEnable;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
*access = readEnable;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (h == INVALID_HANDLE_VALUE) {
|
|
||||||
// remap GetLastError()...
|
|
||||||
*error = fstError;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%s\n", rpath);
|
|
||||||
int fd = cygwin_attach_handle_to_fd(rpath, -1, h, 1, GENERIC_READ | GENERIC_WRITE);
|
|
||||||
if (fd < 0) {
|
|
||||||
*error = map_errno();
|
|
||||||
}
|
|
||||||
if (fd >= PSEUDO_FD_BASE) {
|
|
||||||
close(fd);
|
|
||||||
*error = tooManyFilesOpen;
|
|
||||||
fd = -1;
|
|
||||||
}
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
static int open_resource_fork(const char *path, word16 *access, word16 *error) {
|
|
||||||
|
|
||||||
#ifdef __CYGWIN__
|
|
||||||
return cygwin_open_attr(path, ":AFP_Resource", access, error);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char *rpath = append_string(path, ":AFP_Resource");
|
|
||||||
|
|
||||||
int fd = -1;
|
|
||||||
for (;;) {
|
|
||||||
|
|
||||||
switch(*access) {
|
|
||||||
case readEnableAllowWrite:
|
|
||||||
case readWriteEnable:
|
|
||||||
fd = open(rpath, O_RDWR | O_CREAT, 0666);
|
|
||||||
break;
|
|
||||||
case readEnable:
|
|
||||||
fd = open(rpath, O_RDONLY);
|
|
||||||
break;
|
|
||||||
case writeEnable:
|
|
||||||
fd = open(rpath, O_WRONLY | O_CREAT, 0666);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*access == readEnableAllowWrite) {
|
|
||||||
if (fd < 0) {
|
|
||||||
*access = readEnable;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
*access = readWriteEnable;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (fd < 0) {
|
|
||||||
*error = map_errno();
|
|
||||||
}
|
|
||||||
if (fd >= PSEUDO_FD_BASE) {
|
|
||||||
close(fd);
|
|
||||||
*error = tooManyFilesOpen;
|
|
||||||
fd = -1;
|
|
||||||
}
|
|
||||||
return fd;
|
|
||||||
}
|
}
|
||||||
#elif defined __sun
|
#elif defined __sun
|
||||||
static int open_resource_fork(const char *path, word16 *access, word16 *error) {
|
static int open_resource_fork(const char *path, word16 *access, word16 *error) {
|
||||||
@ -1824,9 +1628,9 @@ static word32 fst_read(int class) {
|
|||||||
|
|
||||||
if (transfer_count) {
|
if (transfer_count) {
|
||||||
if (class)
|
if (class)
|
||||||
set_memory32_c(pb + IORecGS_transferCount, ok, 0);
|
set_memory32_c(pb + IORecGS_transferCount, transfer_count, 0);
|
||||||
else
|
else
|
||||||
set_memory32_c(pb + FileIORec_transferCount, ok, 0);
|
set_memory32_c(pb + FileIORec_transferCount, transfer_count, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
@ -1899,8 +1703,12 @@ static word32 fst_flush(int class) {
|
|||||||
|
|
||||||
if (!e) return invalidRefNum;
|
if (!e) return invalidRefNum;
|
||||||
|
|
||||||
int ok = fsync(e->fd);
|
switch (e->type) {
|
||||||
|
case directory_file:
|
||||||
|
return badStoreType;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ok = fsync(e->fd);
|
||||||
if (ok < 0) return map_errno();
|
if (ok < 0) return map_errno();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
2445
src/win32_host_fst.c
Normal file
2445
src/win32_host_fst.c
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user