Project

General

Profile

Feature #14177 ยป file_stat_dev.patch

kubo (Takehiro Kubo), 12/13/2017 10:56 PM

View differences:

include/ruby/win32.h (working copy)
133 133
#define CLOCK_REALTIME  0
134 134
#define CLOCK_MONOTONIC 1
135
#undef rb_dev_t
136
#undef DEVT2NUM
137
#undef NUM2DEVT
138
#undef PRI_DEVT_PREFIX
139
typedef unsigned __int64 rb_dev_t;
140
#define DEVT2NUM(v) ULL2NUM(v)
141
#define NUM2DEVT(v) NUM2ULL(v)
142
#define PRI_DEVT_PREFIX PRI_LL_PREFIX
143

  
135 144
#undef utime
136 145
#undef lseek
137 146
#undef stat
......
172 181
#define unlink(p)		rb_w32_unlink(p)
173 182
#endif /* RUBY_EXPORT */
174
/* same with stati64 except the size of st_ino and nanosecond timestamps */
183
/* same with stati64 except the size of st_ino, st_dev, st_rdev and nanosecond timestamps */
175 184
struct stati128 {
176
  _dev_t st_dev;
185
  rb_dev_t st_dev;
177 186
  unsigned __int64 st_ino;
178 187
  __int64 st_inohigh;
179 188
  unsigned short st_mode;
......
181 190
  short st_nlink;
182 191
  short st_uid;
183 192
  short st_gid;
184
  _dev_t st_rdev;
193
  rb_dev_t st_rdev;
185 194
  __int64 st_size;
186 195
  __time64_t st_atime;
187 196
  long st_atimensec;
win32/win32.c (working copy)
5472 5472
	st->st_nlink = info.nNumberOfLinks;
5473 5473
	attr = info.dwFileAttributes;
5474 5474
	if (!get_ino(h, &fii)) {
5475
	    st->st_dev = st->st_rdev = fii.VolumeSerialNumber;
5475 5476
	    st->st_ino = *((unsigned __int64 *)&fii.FileId);
5476 5477
	    st->st_inohigh = *((__int64 *)&fii.FileId + 1);
5477 5478
	}
5478 5479
	else {
5480
	    st->st_dev = st->st_rdev = info.dwVolumeSerialNumber;
5479 5481
	    st->st_ino = ((__int64)info.nFileIndexHigh << 32) | info.nFileIndexLow;
5480 5482
	    st->st_inohigh = 0;
5481 5483
	}
......
5637 5639
	towupper(path[0]) - L'A' : _getdrive() - 1;
5638 5640
}
5639
static const WCHAR namespace_prefix[] = {L'\\', L'\\', L'?', L'\\'};
5640

  
5641 5641
/* License: Ruby's */
5642 5642
static int
5643 5643
winnt_stat(const WCHAR *path, struct stati128 *st, BOOL lstat)
......
5645 5645
{
5646 5646
    DWORD flags = lstat ? FILE_FLAG_OPEN_REPARSE_POINT : 0;
5647 5647
    HANDLE f;
5648
    WCHAR finalname[PATH_MAX];
5649 5648
    memset(st, 0, sizeof(*st));
5650 5649
    f = open_special(path, 0, flags);
5651 5650
    if (f != INVALID_HANDLE_VALUE) {
5652 5651
	DWORD attr = stati128_handle(f, st);
5653
	const DWORD len = get_final_path(f, finalname, numberof(finalname), 0);
5654 5652
	CloseHandle(f);
5655 5653
	if (attr & FILE_ATTRIBUTE_REPARSE_POINT) {
5656 5654
	    /* TODO: size in which encoding? */
......
5664 5662
	    if (check_valid_dir(path)) return -1;
5665 5663
	}
5666 5664
	st->st_mode = fileattr_to_unixmode(attr, path);
5667
	if (len) {
5668
	    finalname[min(len, numberof(finalname)-1)] = L'\0';
5669
	    path = finalname;
5670
	    if (wcsncmp(path, namespace_prefix, numberof(namespace_prefix)) == 0)
5671
		path += numberof(namespace_prefix);
5672
	}
5673 5665
    }
5674 5666
    else {
5675 5667
	if (stat_by_find(path, st)) return -1;
5668
	st->st_dev = st->st_rdev = path_drive(path);
5676 5669
    }
5677
    st->st_dev = st->st_rdev = path_drive(path);
5678

  
5679 5670
    return 0;
5680 5671
}