Changeset View
Standalone View
src/ioslaves/file/file_unix.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
48 | #include <KAuth> | 48 | #include <KAuth> | ||
49 | #include <KRandom> | 49 | #include <KRandom> | ||
50 | 50 | | |||
51 | #include "fdreceiver.h" | 51 | #include "fdreceiver.h" | ||
52 | #include "statjob.h" | 52 | #include "statjob.h" | ||
53 | 53 | | |||
54 | #if HAVE_STATX | 54 | #if HAVE_STATX | ||
55 | #include <sys/stat.h> | 55 | #include <sys/stat.h> | ||
56 | #include <sys/sysmacros.h> // for makedev() | ||||
56 | #endif | 57 | #endif | ||
57 | 58 | | |||
58 | //sendfile has different semantics in different platforms | 59 | //sendfile has different semantics in different platforms | ||
59 | #if HAVE_SENDFILE && defined Q_OS_LINUX | 60 | #if HAVE_SENDFILE && defined Q_OS_LINUX | ||
60 | #define USE_SENDFILE 1 | 61 | #define USE_SENDFILE 1 | ||
61 | #endif | 62 | #endif | ||
62 | 63 | | |||
63 | #ifdef USE_SENDFILE | 64 | #ifdef USE_SENDFILE | ||
▲ Show 20 Lines • Show All 214 Lines • ▼ Show 20 Line(s) | 269 | inline int STAT(const char* path, struct statx * buff, KIO::StatDetails details) { | |||
278 | if (details & KIO::StatTime) { | 279 | if (details & KIO::StatTime) { | ||
279 | // atime, mtime, btime | 280 | // atime, mtime, btime | ||
280 | mask |= STATX_ATIME | STATX_MTIME | STATX_BTIME; | 281 | mask |= STATX_ATIME | STATX_MTIME | STATX_BTIME; | ||
281 | } | 282 | } | ||
282 | // KIO::Inode is ignored as when STAT is called, the entry inode field has already been filled | 283 | // KIO::Inode is ignored as when STAT is called, the entry inode field has already been filled | ||
283 | return statx(AT_FDCWD, path, AT_STATX_SYNC_AS_STAT, mask, buff); | 284 | return statx(AT_FDCWD, path, AT_STATX_SYNC_AS_STAT, mask, buff); | ||
284 | } | 285 | } | ||
285 | inline static uint16_t stat_mode(struct statx &buf) { return buf.stx_mode; } | 286 | inline static uint16_t stat_mode(struct statx &buf) { return buf.stx_mode; } | ||
286 | inline static uint32_t stat_dev(struct statx &buf) { return buf.stx_dev_major; } | 287 | inline static dev_t stat_dev(struct statx &buf) { return makedev(buf.stx_dev_major, buf.stx_dev_minor); } | ||
meven: We should probably use `makedev` http://man7.org/linux/man-pages/man3/makedev.3.html in fact to… | |||||
I am not an expert on stat low-level system calls; but if the goal is to have a unique UDS_DEVICE_ID, we could leave it as uint32 which is what statx returns by default, it's system specific anyway, and a system will have statx or not... ahmadsamir: I am not an expert on stat low-level system calls; but if the goal is to have a unique… | |||||
* 100 is definitely wrong - maybe * 0x100, but ... TLDR: use makedev, and change the return type to dev_t. dev_t is defined as a 64bit type atleast on Linux, which matches the 32bit major/minor parts of buf.stx_dev_*. Traditionally, major/minor are used as low/high bytes of a 16 bit type, but these can easily exhausted on a larger system. So this is was makedev does: #define __SYSMACROS_DEFINE_MAKEDEV(DECL_TEMPL) \ __SYSMACROS_DECLARE_MAKEDEV (DECL_TEMPL) \ { \ __dev_t __dev; \ __dev = (((__dev_t) (__major & 0x00000fffu)) << 8); \ __dev |= (((__dev_t) (__major & 0xfffff000u)) << 32); \ __dev |= (((__dev_t) (__minor & 0x000000ffu)) << 0); \ __dev |= (((__dev_t) (__minor & 0xffffff00u)) << 12); \ return __dev; \ } bruns: ` * 100` is definitely wrong - maybe `* 0x100`, but ...
TLDR: use `makedev`, and change the… | |||||
287 | inline static uint64_t stat_ino(struct statx &buf) { return buf.stx_ino; } | 288 | inline static uint64_t stat_ino(struct statx &buf) { return buf.stx_ino; } | ||
288 | inline static uint64_t stat_size(struct statx &buf) { return buf.stx_size; } | 289 | inline static uint64_t stat_size(struct statx &buf) { return buf.stx_size; } | ||
289 | inline static uint32_t stat_uid(struct statx &buf) { return buf.stx_uid; } | 290 | inline static uint32_t stat_uid(struct statx &buf) { return buf.stx_uid; } | ||
290 | inline static uint32_t stat_gid(struct statx &buf) { return buf.stx_gid; } | 291 | inline static uint32_t stat_gid(struct statx &buf) { return buf.stx_gid; } | ||
291 | inline static int64_t stat_atime(struct statx &buf) { return buf.stx_atime.tv_sec; } | 292 | inline static int64_t stat_atime(struct statx &buf) { return buf.stx_atime.tv_sec; } | ||
292 | inline static int64_t stat_mtime(struct statx &buf) { return buf.stx_mtime.tv_sec; } | 293 | inline static int64_t stat_mtime(struct statx &buf) { return buf.stx_mtime.tv_sec; } | ||
293 | #else | 294 | #else | ||
294 | // regular stat struct | 295 | // regular stat struct | ||
295 | inline int LSTAT(const char* path, QT_STATBUF * buff, KIO::StatDetails details) { | 296 | inline int LSTAT(const char* path, QT_STATBUF * buff, KIO::StatDetails details) { | ||
296 | Q_UNUSED(details) | 297 | Q_UNUSED(details) | ||
297 | return QT_LSTAT(path, buff); | 298 | return QT_LSTAT(path, buff); | ||
298 | } | 299 | } | ||
299 | inline int STAT(const char* path, QT_STATBUF * buff, KIO::StatDetails details) { | 300 | inline int STAT(const char* path, QT_STATBUF * buff, KIO::StatDetails details) { | ||
300 | Q_UNUSED(details) | 301 | Q_UNUSED(details) | ||
301 | return QT_STAT(path, buff); | 302 | return QT_STAT(path, buff); | ||
302 | } | 303 | } | ||
303 | inline static mode_t stat_mode(QT_STATBUF &buf) { return buf.st_mode; } | 304 | inline static mode_t stat_mode(QT_STATBUF &buf) { return buf.st_mode; } | ||
304 | inline static dev_t stat_dev(QT_STATBUF &buf) { return buf.st_dev; } | 305 | inline static dev_t stat_dev(QT_STATBUF &buf) { return buf.st_dev; } | ||
Did you compare with the no-statx case ? meven: Did you compare with the no-statx case ?
We should try to have the same output. | |||||
This buf.st_dev is the decimal part in: whereas with statx it returns buf.stx_dev_major which is an uint32_t. ahmadsamir: This buf.st_dev is the decimal part in:
$ stat /usr/bin/file | grep Device
Device: 804h/2052d… | |||||
ahmadsamir: With makedev() now I get the same numbers. | |||||
305 | inline static ino_t stat_ino(QT_STATBUF &buf) { return buf.st_ino; } | 306 | inline static ino_t stat_ino(QT_STATBUF &buf) { return buf.st_ino; } | ||
306 | inline static off_t stat_size(QT_STATBUF &buf) { return buf.st_size; } | 307 | inline static off_t stat_size(QT_STATBUF &buf) { return buf.st_size; } | ||
307 | inline static uid_t stat_uid(QT_STATBUF &buf) { return buf.st_uid; } | 308 | inline static uid_t stat_uid(QT_STATBUF &buf) { return buf.st_uid; } | ||
308 | inline static gid_t stat_gid(QT_STATBUF &buf) { return buf.st_gid; } | 309 | inline static gid_t stat_gid(QT_STATBUF &buf) { return buf.st_gid; } | ||
309 | inline static time_t stat_atime(QT_STATBUF &buf) { return buf.st_atime; } | 310 | inline static time_t stat_atime(QT_STATBUF &buf) { return buf.st_atime; } | ||
310 | inline static time_t stat_mtime(QT_STATBUF &buf) { return buf.st_mtime; } | 311 | inline static time_t stat_mtime(QT_STATBUF &buf) { return buf.st_mtime; } | ||
311 | #endif | 312 | #endif | ||
312 | 313 | | |||
▲ Show 20 Lines • Show All 1078 Lines • Show Last 20 Lines |
We should probably use makedev http://man7.org/linux/man-pages/man3/makedev.3.html in fact to ensure to match original stat behavior.