Changeset View
Standalone View
src/ioslaves/file/file_unix.cpp
Show First 20 Lines • Show All 277 Lines • ▼ Show 20 Line(s) | 268 | inline int STAT(const char* path, struct statx * buff, KIO::StatDetails details) { | |||
---|---|---|---|---|---|
278 | if (details & KIO::StatTime) { | 278 | if (details & KIO::StatTime) { | ||
279 | // atime, mtime, btime | 279 | // atime, mtime, btime | ||
280 | mask |= STATX_ATIME | STATX_MTIME | STATX_BTIME; | 280 | mask |= STATX_ATIME | STATX_MTIME | STATX_BTIME; | ||
281 | } | 281 | } | ||
282 | // KIO::Inode is ignored as when STAT is called, the entry inode field has already been filled | 282 | // 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); | 283 | return statx(AT_FDCWD, path, AT_STATX_SYNC_AS_STAT, mask, buff); | ||
284 | } | 284 | } | ||
285 | inline static uint16_t stat_mode(struct statx &buf) { return buf.stx_mode; } | 285 | 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; } | 286 | inline static uint32_t stat_dev(struct statx &buf) { return (buf.stx_dev_major * 100) + 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; } | 287 | 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; } | 288 | 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; } | 289 | 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; } | 290 | 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; } | 291 | 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; } | 292 | inline static int64_t stat_mtime(struct statx &buf) { return buf.stx_mtime.tv_sec; } | ||
293 | #else | 293 | #else | ||
294 | // regular stat struct | 294 | // regular stat struct | ||
295 | inline int LSTAT(const char* path, QT_STATBUF * buff, KIO::StatDetails details) { | 295 | inline int LSTAT(const char* path, QT_STATBUF * buff, KIO::StatDetails details) { | ||
296 | Q_UNUSED(details) | 296 | Q_UNUSED(details) | ||
297 | return QT_LSTAT(path, buff); | 297 | return QT_LSTAT(path, buff); | ||
298 | } | 298 | } | ||
299 | inline int STAT(const char* path, QT_STATBUF * buff, KIO::StatDetails details) { | 299 | inline int STAT(const char* path, QT_STATBUF * buff, KIO::StatDetails details) { | ||
300 | Q_UNUSED(details) | 300 | Q_UNUSED(details) | ||
301 | return QT_STAT(path, buff); | 301 | return QT_STAT(path, buff); | ||
302 | } | 302 | } | ||
303 | inline static mode_t stat_mode(QT_STATBUF &buf) { return buf.st_mode; } | 303 | 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; } | 304 | 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; } | 305 | 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; } | 306 | 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; } | 307 | 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; } | 308 | 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; } | 309 | 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; } | 310 | inline static time_t stat_mtime(QT_STATBUF &buf) { return buf.st_mtime; } | ||
311 | #endif | 311 | #endif | ||
312 | 312 | | |||
▲ 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.