Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

file.c 36KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  1. /*
  2. * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
  3. * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
  4. * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
  5. * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. The name of the author may not be used to endorse or promote products
  17. * derived from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  21. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "defs.h"
  31. #if defined(SPARC) || defined(SPARC64)
  32. struct stat {
  33. unsigned short st_dev;
  34. unsigned int st_ino;
  35. unsigned short st_mode;
  36. short st_nlink;
  37. unsigned short st_uid;
  38. unsigned short st_gid;
  39. unsigned short st_rdev;
  40. unsigned int st_size;
  41. int st_atime;
  42. unsigned int __unused1;
  43. int st_mtime;
  44. unsigned int __unused2;
  45. int st_ctime;
  46. unsigned int __unused3;
  47. int st_blksize;
  48. int st_blocks;
  49. unsigned int __unused4[2];
  50. };
  51. # if defined(SPARC64)
  52. struct stat_sparc64 {
  53. unsigned int st_dev;
  54. unsigned long st_ino;
  55. unsigned int st_mode;
  56. unsigned int st_nlink;
  57. unsigned int st_uid;
  58. unsigned int st_gid;
  59. unsigned int st_rdev;
  60. long st_size;
  61. long st_atime;
  62. long st_mtime;
  63. long st_ctime;
  64. long st_blksize;
  65. long st_blocks;
  66. unsigned long __unused4[2];
  67. };
  68. # endif /* SPARC64 */
  69. # define stat kernel_stat
  70. # include <asm/stat.h>
  71. # undef stat
  72. #elif defined(X32)
  73. struct stat {
  74. unsigned long long st_dev;
  75. unsigned long long st_ino;
  76. unsigned long long st_nlink;
  77. unsigned int st_mode;
  78. unsigned int st_uid;
  79. unsigned int st_gid;
  80. unsigned int __pad0;
  81. unsigned long long st_rdev;
  82. long long st_size;
  83. long long st_blksize;
  84. long long st_blocks;
  85. unsigned long long st_atime;
  86. unsigned long long st_atime_nsec;
  87. unsigned long long st_mtime;
  88. unsigned long long st_mtime_nsec;
  89. unsigned long long st_ctime;
  90. unsigned long long st_ctime_nsec;
  91. long long __unused[3];
  92. };
  93. struct stat64 {
  94. unsigned long long st_dev;
  95. unsigned char __pad0[4];
  96. unsigned long __st_ino;
  97. unsigned int st_mode;
  98. unsigned int st_nlink;
  99. unsigned long st_uid;
  100. unsigned long st_gid;
  101. unsigned long long st_rdev;
  102. unsigned char __pad3[4];
  103. long long st_size;
  104. unsigned long st_blksize;
  105. unsigned long long st_blocks;
  106. unsigned long st_atime;
  107. unsigned long st_atime_nsec;
  108. unsigned long st_mtime;
  109. unsigned int st_mtime_nsec;
  110. unsigned long st_ctime;
  111. unsigned long st_ctime_nsec;
  112. unsigned long long st_ino;
  113. } __attribute__((packed));
  114. # define HAVE_STAT64 1
  115. struct __old_kernel_stat {
  116. unsigned short st_dev;
  117. unsigned short st_ino;
  118. unsigned short st_mode;
  119. unsigned short st_nlink;
  120. unsigned short st_uid;
  121. unsigned short st_gid;
  122. unsigned short st_rdev;
  123. unsigned int st_size;
  124. unsigned int st_atime;
  125. unsigned int st_mtime;
  126. unsigned int st_ctime;
  127. };
  128. #else
  129. # undef dev_t
  130. # undef ino_t
  131. # undef mode_t
  132. # undef nlink_t
  133. # undef uid_t
  134. # undef gid_t
  135. # undef off_t
  136. # undef loff_t
  137. # define dev_t __kernel_dev_t
  138. # define ino_t __kernel_ino_t
  139. # define mode_t __kernel_mode_t
  140. # define nlink_t __kernel_nlink_t
  141. # define uid_t __kernel_uid_t
  142. # define gid_t __kernel_gid_t
  143. # define off_t __kernel_off_t
  144. # define loff_t __kernel_loff_t
  145. # include <asm/stat.h>
  146. # undef dev_t
  147. # undef ino_t
  148. # undef mode_t
  149. # undef nlink_t
  150. # undef uid_t
  151. # undef gid_t
  152. # undef off_t
  153. # undef loff_t
  154. # define dev_t dev_t
  155. # define ino_t ino_t
  156. # define mode_t mode_t
  157. # define nlink_t nlink_t
  158. # define uid_t uid_t
  159. # define gid_t gid_t
  160. # define off_t off_t
  161. # define loff_t loff_t
  162. #endif
  163. #define stat libc_stat
  164. #define stat64 libc_stat64
  165. #include <sys/stat.h>
  166. #undef stat
  167. #undef stat64
  168. /* These might be macros. */
  169. #undef st_atime
  170. #undef st_mtime
  171. #undef st_ctime
  172. #include <fcntl.h>
  173. #ifdef MAJOR_IN_SYSMACROS
  174. # include <sys/sysmacros.h>
  175. #endif
  176. #ifdef MAJOR_IN_MKDEV
  177. # include <sys/mkdev.h>
  178. #endif
  179. #ifdef O_LARGEFILE
  180. # if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
  181. # undef O_LARGEFILE
  182. # ifdef SPARC64
  183. # define O_LARGEFILE 0x40000
  184. # elif defined X86_64 || defined S390X
  185. # define O_LARGEFILE 0100000
  186. # endif
  187. # endif
  188. #endif
  189. #include "xlat/open_access_modes.h"
  190. #include "xlat/open_mode_flags.h"
  191. #ifndef AT_FDCWD
  192. # define AT_FDCWD -100
  193. #endif
  194. /* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
  195. * extension to get the right value. We do this by declaring fd as int here.
  196. */
  197. void
  198. print_dirfd(struct tcb *tcp, int fd)
  199. {
  200. if (fd == AT_FDCWD)
  201. tprints("AT_FDCWD, ");
  202. else {
  203. printfd(tcp, fd);
  204. tprints(", ");
  205. }
  206. }
  207. /*
  208. * low bits of the open(2) flags define access mode,
  209. * other bits are real flags.
  210. */
  211. const char *
  212. sprint_open_modes(int flags)
  213. {
  214. static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
  215. char *p;
  216. char sep;
  217. const char *str;
  218. const struct xlat *x;
  219. sep = ' ';
  220. p = stpcpy(outstr, "flags");
  221. str = xlookup(open_access_modes, flags & 3);
  222. if (str) {
  223. *p++ = sep;
  224. p = stpcpy(p, str);
  225. flags &= ~3;
  226. if (!flags)
  227. return outstr;
  228. sep = '|';
  229. }
  230. for (x = open_mode_flags; x->str; x++) {
  231. if ((flags & x->val) == x->val) {
  232. *p++ = sep;
  233. p = stpcpy(p, x->str);
  234. flags &= ~x->val;
  235. if (!flags)
  236. return outstr;
  237. sep = '|';
  238. }
  239. }
  240. /* flags is still nonzero */
  241. *p++ = sep;
  242. sprintf(p, "%#x", flags);
  243. return outstr;
  244. }
  245. void
  246. tprint_open_modes(int flags)
  247. {
  248. tprints(sprint_open_modes(flags) + sizeof("flags"));
  249. }
  250. static int
  251. decode_open(struct tcb *tcp, int offset)
  252. {
  253. if (entering(tcp)) {
  254. printpath(tcp, tcp->u_arg[offset]);
  255. tprints(", ");
  256. /* flags */
  257. tprint_open_modes(tcp->u_arg[offset + 1]);
  258. if (tcp->u_arg[offset + 1] & O_CREAT) {
  259. /* mode */
  260. tprintf(", %#lo", tcp->u_arg[offset + 2]);
  261. }
  262. }
  263. return RVAL_FD;
  264. }
  265. int
  266. sys_open(struct tcb *tcp)
  267. {
  268. return decode_open(tcp, 0);
  269. }
  270. int
  271. sys_openat(struct tcb *tcp)
  272. {
  273. if (entering(tcp))
  274. print_dirfd(tcp, tcp->u_arg[0]);
  275. return decode_open(tcp, 1);
  276. }
  277. #if defined(SPARC) || defined(SPARC64)
  278. #include "xlat/openmodessol.h"
  279. int
  280. solaris_open(struct tcb *tcp)
  281. {
  282. if (entering(tcp)) {
  283. printpath(tcp, tcp->u_arg[0]);
  284. tprints(", ");
  285. /* flags */
  286. printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
  287. if (tcp->u_arg[1] & 0x100) {
  288. /* mode */
  289. tprintf(", %#lo", tcp->u_arg[2]);
  290. }
  291. }
  292. return 0;
  293. }
  294. #endif
  295. int
  296. sys_creat(struct tcb *tcp)
  297. {
  298. if (entering(tcp)) {
  299. printpath(tcp, tcp->u_arg[0]);
  300. tprintf(", %#lo", tcp->u_arg[1]);
  301. }
  302. return RVAL_FD;
  303. }
  304. #include "xlat/access_flags.h"
  305. static int
  306. decode_access(struct tcb *tcp, int offset)
  307. {
  308. if (entering(tcp)) {
  309. printpath(tcp, tcp->u_arg[offset]);
  310. tprints(", ");
  311. printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
  312. }
  313. return 0;
  314. }
  315. int
  316. sys_access(struct tcb *tcp)
  317. {
  318. return decode_access(tcp, 0);
  319. }
  320. int
  321. sys_faccessat(struct tcb *tcp)
  322. {
  323. if (entering(tcp))
  324. print_dirfd(tcp, tcp->u_arg[0]);
  325. return decode_access(tcp, 1);
  326. }
  327. int
  328. sys_umask(struct tcb *tcp)
  329. {
  330. if (entering(tcp)) {
  331. tprintf("%#lo", tcp->u_arg[0]);
  332. }
  333. return RVAL_OCTAL;
  334. }
  335. #include "xlat/whence_codes.h"
  336. /* Linux kernel has exactly one version of lseek:
  337. * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
  338. * In kernel, off_t is always the same as (kernel's) long
  339. * (see include/uapi/asm-generic/posix_types.h),
  340. * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
  341. * Use test/x32_lseek.c to test lseek decoding.
  342. */
  343. #if defined(LINUX_MIPSN32) || defined(X32)
  344. int
  345. sys_lseek(struct tcb *tcp)
  346. {
  347. long long offset;
  348. int whence;
  349. if (entering(tcp)) {
  350. printfd(tcp, tcp->u_arg[0]);
  351. offset = tcp->ext_arg[1];
  352. whence = tcp->u_arg[2];
  353. if (whence == SEEK_SET)
  354. tprintf(", %llu, ", offset);
  355. else
  356. tprintf(", %lld, ", offset);
  357. printxval(whence_codes, whence, "SEEK_???");
  358. }
  359. return RVAL_LUDECIMAL;
  360. }
  361. #else
  362. int
  363. sys_lseek(struct tcb *tcp)
  364. {
  365. long offset;
  366. int whence;
  367. if (entering(tcp)) {
  368. printfd(tcp, tcp->u_arg[0]);
  369. offset = tcp->u_arg[1];
  370. whence = tcp->u_arg[2];
  371. if (whence == SEEK_SET)
  372. tprintf(", %lu, ", offset);
  373. else
  374. tprintf(", %ld, ", offset);
  375. printxval(whence_codes, whence, "SEEK_???");
  376. }
  377. return RVAL_UDECIMAL;
  378. }
  379. #endif
  380. /* llseek syscall takes explicitly two ulong arguments hi, lo,
  381. * rather than one 64-bit argument for which LONG_LONG works
  382. * appropriate for the native byte order.
  383. *
  384. * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
  385. *
  386. * hi,lo are "unsigned longs" and combined exactly this way in kernel:
  387. * ((loff_t) hi << 32) | lo
  388. * Note that for architectures with kernel's long wider than userspace long
  389. * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
  390. * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
  391. * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
  392. */
  393. int
  394. sys_llseek(struct tcb *tcp)
  395. {
  396. if (entering(tcp)) {
  397. printfd(tcp, tcp->u_arg[0]);
  398. if (tcp->u_arg[4] == SEEK_SET)
  399. tprintf(", %llu, ",
  400. ((long long) tcp->u_arg[1]) << 32 |
  401. (unsigned long long) (unsigned) tcp->u_arg[2]);
  402. else
  403. tprintf(", %lld, ",
  404. ((long long) tcp->u_arg[1]) << 32 |
  405. (unsigned long long) (unsigned) tcp->u_arg[2]);
  406. }
  407. else {
  408. long long off;
  409. if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
  410. tprintf("%#lx, ", tcp->u_arg[3]);
  411. else
  412. tprintf("[%llu], ", off);
  413. printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
  414. }
  415. return 0;
  416. }
  417. int
  418. sys_readahead(struct tcb *tcp)
  419. {
  420. if (entering(tcp)) {
  421. int argn;
  422. printfd(tcp, tcp->u_arg[0]);
  423. argn = printllval(tcp, ", %lld", 1);
  424. tprintf(", %ld", tcp->u_arg[argn]);
  425. }
  426. return 0;
  427. }
  428. int
  429. sys_truncate(struct tcb *tcp)
  430. {
  431. if (entering(tcp)) {
  432. printpath(tcp, tcp->u_arg[0]);
  433. tprintf(", %lu", tcp->u_arg[1]);
  434. }
  435. return 0;
  436. }
  437. int
  438. sys_truncate64(struct tcb *tcp)
  439. {
  440. if (entering(tcp)) {
  441. printpath(tcp, tcp->u_arg[0]);
  442. printllval(tcp, ", %llu", 1);
  443. }
  444. return 0;
  445. }
  446. int
  447. sys_ftruncate(struct tcb *tcp)
  448. {
  449. if (entering(tcp)) {
  450. printfd(tcp, tcp->u_arg[0]);
  451. tprintf(", %lu", tcp->u_arg[1]);
  452. }
  453. return 0;
  454. }
  455. int
  456. sys_ftruncate64(struct tcb *tcp)
  457. {
  458. if (entering(tcp)) {
  459. printfd(tcp, tcp->u_arg[0]);
  460. printllval(tcp, ", %llu", 1);
  461. }
  462. return 0;
  463. }
  464. /* several stats */
  465. #include "xlat/modetypes.h"
  466. static const char *
  467. sprintmode(int mode)
  468. {
  469. static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
  470. + sizeof(int)*3
  471. + /*paranoia:*/ 8];
  472. const char *s;
  473. if ((mode & S_IFMT) == 0)
  474. s = "";
  475. else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
  476. sprintf(buf, "%#o", mode);
  477. return buf;
  478. }
  479. s = buf + sprintf(buf, "%s%s%s%s", s,
  480. (mode & S_ISUID) ? "|S_ISUID" : "",
  481. (mode & S_ISGID) ? "|S_ISGID" : "",
  482. (mode & S_ISVTX) ? "|S_ISVTX" : "");
  483. mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
  484. if (mode)
  485. sprintf((char*)s, "|%#o", mode);
  486. s = (*buf == '|') ? buf + 1 : buf;
  487. return *s ? s : "0";
  488. }
  489. static char *
  490. sprinttime(time_t t)
  491. {
  492. struct tm *tmp;
  493. static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
  494. if (t == 0) {
  495. strcpy(buf, "0");
  496. return buf;
  497. }
  498. tmp = localtime(&t);
  499. if (tmp)
  500. snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
  501. tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
  502. tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  503. else
  504. snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
  505. return buf;
  506. }
  507. #if defined(SPARC) || defined(SPARC64)
  508. typedef struct {
  509. int tv_sec;
  510. int tv_nsec;
  511. } timestruct_t;
  512. struct solstat {
  513. unsigned st_dev;
  514. int st_pad1[3]; /* network id */
  515. unsigned st_ino;
  516. unsigned st_mode;
  517. unsigned st_nlink;
  518. unsigned st_uid;
  519. unsigned st_gid;
  520. unsigned st_rdev;
  521. int st_pad2[2];
  522. int st_size;
  523. int st_pad3; /* st_size, off_t expansion */
  524. timestruct_t st_atime;
  525. timestruct_t st_mtime;
  526. timestruct_t st_ctime;
  527. int st_blksize;
  528. int st_blocks;
  529. char st_fstype[16];
  530. int st_pad4[8]; /* expansion area */
  531. };
  532. static void
  533. printstatsol(struct tcb *tcp, long addr)
  534. {
  535. struct solstat statbuf;
  536. if (umove(tcp, addr, &statbuf) < 0) {
  537. tprints("{...}");
  538. return;
  539. }
  540. if (!abbrev(tcp)) {
  541. tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
  542. (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
  543. (unsigned long) (statbuf.st_dev & 0x3ffff),
  544. (unsigned long) statbuf.st_ino,
  545. sprintmode(statbuf.st_mode));
  546. tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
  547. (unsigned long) statbuf.st_nlink,
  548. (unsigned long) statbuf.st_uid,
  549. (unsigned long) statbuf.st_gid);
  550. tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
  551. tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
  552. }
  553. else
  554. tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
  555. switch (statbuf.st_mode & S_IFMT) {
  556. case S_IFCHR: case S_IFBLK:
  557. tprintf("st_rdev=makedev(%lu, %lu), ",
  558. (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
  559. (unsigned long) (statbuf.st_rdev & 0x3ffff));
  560. break;
  561. default:
  562. tprintf("st_size=%u, ", statbuf.st_size);
  563. break;
  564. }
  565. if (!abbrev(tcp)) {
  566. tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
  567. tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
  568. tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
  569. }
  570. else
  571. tprints("...}");
  572. }
  573. # if defined(SPARC64)
  574. static void
  575. printstat_sparc64(struct tcb *tcp, long addr)
  576. {
  577. struct stat_sparc64 statbuf;
  578. if (umove(tcp, addr, &statbuf) < 0) {
  579. tprints("{...}");
  580. return;
  581. }
  582. if (!abbrev(tcp)) {
  583. tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
  584. (unsigned long) major(statbuf.st_dev),
  585. (unsigned long) minor(statbuf.st_dev),
  586. (unsigned long) statbuf.st_ino,
  587. sprintmode(statbuf.st_mode));
  588. tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
  589. (unsigned long) statbuf.st_nlink,
  590. (unsigned long) statbuf.st_uid,
  591. (unsigned long) statbuf.st_gid);
  592. tprintf("st_blksize=%lu, ",
  593. (unsigned long) statbuf.st_blksize);
  594. tprintf("st_blocks=%lu, ",
  595. (unsigned long) statbuf.st_blocks);
  596. }
  597. else
  598. tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
  599. switch (statbuf.st_mode & S_IFMT) {
  600. case S_IFCHR: case S_IFBLK:
  601. tprintf("st_rdev=makedev(%lu, %lu), ",
  602. (unsigned long) major(statbuf.st_rdev),
  603. (unsigned long) minor(statbuf.st_rdev));
  604. break;
  605. default:
  606. tprintf("st_size=%lu, ", statbuf.st_size);
  607. break;
  608. }
  609. if (!abbrev(tcp)) {
  610. tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
  611. tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
  612. tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
  613. }
  614. else
  615. tprints("...}");
  616. }
  617. # endif /* SPARC64 */
  618. #endif /* SPARC[64] */
  619. #if defined POWERPC64
  620. struct stat_powerpc32 {
  621. unsigned int st_dev;
  622. unsigned int st_ino;
  623. unsigned int st_mode;
  624. unsigned short st_nlink;
  625. unsigned int st_uid;
  626. unsigned int st_gid;
  627. unsigned int st_rdev;
  628. unsigned int st_size;
  629. unsigned int st_blksize;
  630. unsigned int st_blocks;
  631. unsigned int st_atime;
  632. unsigned int st_atime_nsec;
  633. unsigned int st_mtime;
  634. unsigned int st_mtime_nsec;
  635. unsigned int st_ctime;
  636. unsigned int st_ctime_nsec;
  637. unsigned int __unused4;
  638. unsigned int __unused5;
  639. };
  640. static void
  641. printstat_powerpc32(struct tcb *tcp, long addr)
  642. {
  643. struct stat_powerpc32 statbuf;
  644. if (umove(tcp, addr, &statbuf) < 0) {
  645. tprints("{...}");
  646. return;
  647. }
  648. if (!abbrev(tcp)) {
  649. tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
  650. major(statbuf.st_dev), minor(statbuf.st_dev),
  651. statbuf.st_ino,
  652. sprintmode(statbuf.st_mode));
  653. tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
  654. statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
  655. tprintf("st_blksize=%u, ", statbuf.st_blksize);
  656. tprintf("st_blocks=%u, ", statbuf.st_blocks);
  657. }
  658. else
  659. tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
  660. switch (statbuf.st_mode & S_IFMT) {
  661. case S_IFCHR: case S_IFBLK:
  662. tprintf("st_rdev=makedev(%lu, %lu), ",
  663. (unsigned long) major(statbuf.st_rdev),
  664. (unsigned long) minor(statbuf.st_rdev));
  665. break;
  666. default:
  667. tprintf("st_size=%u, ", statbuf.st_size);
  668. break;
  669. }
  670. if (!abbrev(tcp)) {
  671. tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
  672. tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
  673. tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
  674. }
  675. else
  676. tprints("...}");
  677. }
  678. #endif /* POWERPC64 */
  679. #include "xlat/fileflags.h"
  680. static void
  681. realprintstat(struct tcb *tcp, struct stat *statbuf)
  682. {
  683. if (!abbrev(tcp)) {
  684. tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
  685. (unsigned long) major(statbuf->st_dev),
  686. (unsigned long) minor(statbuf->st_dev),
  687. (unsigned long) statbuf->st_ino,
  688. sprintmode(statbuf->st_mode));
  689. tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
  690. (unsigned long) statbuf->st_nlink,
  691. (unsigned long) statbuf->st_uid,
  692. (unsigned long) statbuf->st_gid);
  693. #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  694. tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
  695. #endif
  696. #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  697. tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
  698. #endif
  699. }
  700. else
  701. tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
  702. switch (statbuf->st_mode & S_IFMT) {
  703. case S_IFCHR: case S_IFBLK:
  704. #ifdef HAVE_STRUCT_STAT_ST_RDEV
  705. tprintf("st_rdev=makedev(%lu, %lu), ",
  706. (unsigned long) major(statbuf->st_rdev),
  707. (unsigned long) minor(statbuf->st_rdev));
  708. #else /* !HAVE_STRUCT_STAT_ST_RDEV */
  709. tprintf("st_size=makedev(%lu, %lu), ",
  710. (unsigned long) major(statbuf->st_size),
  711. (unsigned long) minor(statbuf->st_size));
  712. #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
  713. break;
  714. default:
  715. tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
  716. break;
  717. }
  718. if (!abbrev(tcp)) {
  719. tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
  720. tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
  721. tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
  722. #if HAVE_STRUCT_STAT_ST_FLAGS
  723. tprints(", st_flags=");
  724. printflags(fileflags, statbuf->st_flags, "UF_???");
  725. #endif
  726. #if HAVE_STRUCT_STAT_ST_ACLCNT
  727. tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
  728. #endif
  729. #if HAVE_STRUCT_STAT_ST_LEVEL
  730. tprintf(", st_level=%ld", statbuf->st_level);
  731. #endif
  732. #if HAVE_STRUCT_STAT_ST_FSTYPE
  733. tprintf(", st_fstype=%.*s",
  734. (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
  735. #endif
  736. #if HAVE_STRUCT_STAT_ST_GEN
  737. tprintf(", st_gen=%u", statbuf->st_gen);
  738. #endif
  739. tprints("}");
  740. }
  741. else
  742. tprints("...}");
  743. }
  744. #ifndef X32
  745. static void
  746. printstat(struct tcb *tcp, long addr)
  747. {
  748. struct stat statbuf;
  749. if (!addr) {
  750. tprints("NULL");
  751. return;
  752. }
  753. if (syserror(tcp) || !verbose(tcp)) {
  754. tprintf("%#lx", addr);
  755. return;
  756. }
  757. #if defined(SPARC) || defined(SPARC64)
  758. if (current_personality == 1) {
  759. printstatsol(tcp, addr);
  760. return;
  761. }
  762. #ifdef SPARC64
  763. else if (current_personality == 2) {
  764. printstat_sparc64(tcp, addr);
  765. return;
  766. }
  767. #endif
  768. #endif /* SPARC[64] */
  769. #if defined POWERPC64
  770. if (current_personality == 1) {
  771. printstat_powerpc32(tcp, addr);
  772. return;
  773. }
  774. #endif
  775. if (umove(tcp, addr, &statbuf) < 0) {
  776. tprints("{...}");
  777. return;
  778. }
  779. realprintstat(tcp, &statbuf);
  780. }
  781. #else /* X32 */
  782. # define printstat printstat64
  783. #endif
  784. #if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64)
  785. /*
  786. * Linux x86_64 has unified `struct stat' but its i386 biarch needs
  787. * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
  788. * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
  789. * __GNUC__ is needed for the required __attribute__ below.
  790. *
  791. * Similarly, aarch64 has a unified `struct stat' but its arm personality
  792. * needs `struct stat64' (which also expects a 32-bit `long' but which
  793. * shouldn't be packed).
  794. */
  795. struct stat64 {
  796. unsigned long long st_dev;
  797. unsigned char __pad0[4];
  798. unsigned int __st_ino;
  799. unsigned int st_mode;
  800. unsigned int st_nlink;
  801. unsigned int st_uid;
  802. unsigned int st_gid;
  803. unsigned long long st_rdev;
  804. unsigned char __pad3[4];
  805. long long st_size;
  806. unsigned int st_blksize;
  807. unsigned long long st_blocks;
  808. unsigned int st_atime;
  809. unsigned int st_atime_nsec;
  810. unsigned int st_mtime;
  811. unsigned int st_mtime_nsec;
  812. unsigned int st_ctime;
  813. unsigned int st_ctime_nsec;
  814. unsigned long long st_ino;
  815. }
  816. # if defined X86_64
  817. __attribute__((packed))
  818. # define STAT64_SIZE 96
  819. #else
  820. # define STAT64_SIZE 104
  821. # endif
  822. ;
  823. # define HAVE_STAT64 1
  824. #endif
  825. #ifdef HAVE_STAT64
  826. static void
  827. printstat64(struct tcb *tcp, long addr)
  828. {
  829. #ifdef X32
  830. struct stat statbuf;
  831. #else
  832. struct stat64 statbuf;
  833. #endif
  834. #ifdef STAT64_SIZE
  835. (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
  836. #endif
  837. if (!addr) {
  838. tprints("NULL");
  839. return;
  840. }
  841. if (syserror(tcp) || !verbose(tcp)) {
  842. tprintf("%#lx", addr);
  843. return;
  844. }
  845. #if defined(SPARC) || defined(SPARC64)
  846. if (current_personality == 1) {
  847. printstatsol(tcp, addr);
  848. return;
  849. }
  850. # ifdef SPARC64
  851. else if (current_personality == 2) {
  852. printstat_sparc64(tcp, addr);
  853. return;
  854. }
  855. # endif
  856. #endif /* SPARC[64] */
  857. #if defined AARCH64
  858. if (current_personality != 0) {
  859. printstat(tcp, addr);
  860. return;
  861. }
  862. #endif
  863. #if defined X86_64
  864. if (current_personality != 1) {
  865. printstat(tcp, addr);
  866. return;
  867. }
  868. #endif
  869. if (umove(tcp, addr, &statbuf) < 0) {
  870. tprints("{...}");
  871. return;
  872. }
  873. if (!abbrev(tcp)) {
  874. tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
  875. (unsigned long) major(statbuf.st_dev),
  876. (unsigned long) minor(statbuf.st_dev),
  877. (unsigned long long) statbuf.st_ino,
  878. sprintmode(statbuf.st_mode));
  879. tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
  880. (unsigned long) statbuf.st_nlink,
  881. (unsigned long) statbuf.st_uid,
  882. (unsigned long) statbuf.st_gid);
  883. #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  884. tprintf("st_blksize=%lu, ",
  885. (unsigned long) statbuf.st_blksize);
  886. #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
  887. #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  888. tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
  889. #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
  890. }
  891. else
  892. tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
  893. switch (statbuf.st_mode & S_IFMT) {
  894. case S_IFCHR: case S_IFBLK:
  895. #ifdef HAVE_STRUCT_STAT_ST_RDEV
  896. tprintf("st_rdev=makedev(%lu, %lu), ",
  897. (unsigned long) major(statbuf.st_rdev),
  898. (unsigned long) minor(statbuf.st_rdev));
  899. #else /* !HAVE_STRUCT_STAT_ST_RDEV */
  900. tprintf("st_size=makedev(%lu, %lu), ",
  901. (unsigned long) major(statbuf.st_size),
  902. (unsigned long) minor(statbuf.st_size));
  903. #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
  904. break;
  905. default:
  906. tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
  907. break;
  908. }
  909. if (!abbrev(tcp)) {
  910. tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
  911. tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
  912. tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
  913. #if HAVE_STRUCT_STAT_ST_FLAGS
  914. tprints(", st_flags=");
  915. printflags(fileflags, statbuf.st_flags, "UF_???");
  916. #endif
  917. #if HAVE_STRUCT_STAT_ST_ACLCNT
  918. tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
  919. #endif
  920. #if HAVE_STRUCT_STAT_ST_LEVEL
  921. tprintf(", st_level=%ld", statbuf.st_level);
  922. #endif
  923. #if HAVE_STRUCT_STAT_ST_FSTYPE
  924. tprintf(", st_fstype=%.*s",
  925. (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
  926. #endif
  927. #if HAVE_STRUCT_STAT_ST_GEN
  928. tprintf(", st_gen=%u", statbuf.st_gen);
  929. #endif
  930. tprints("}");
  931. }
  932. else
  933. tprints("...}");
  934. }
  935. #endif /* HAVE_STAT64 */
  936. #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
  937. static void
  938. convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
  939. {
  940. newbuf->st_dev = oldbuf->st_dev;
  941. newbuf->st_ino = oldbuf->st_ino;
  942. newbuf->st_mode = oldbuf->st_mode;
  943. newbuf->st_nlink = oldbuf->st_nlink;
  944. newbuf->st_uid = oldbuf->st_uid;
  945. newbuf->st_gid = oldbuf->st_gid;
  946. newbuf->st_rdev = oldbuf->st_rdev;
  947. newbuf->st_size = oldbuf->st_size;
  948. newbuf->st_atime = oldbuf->st_atime;
  949. newbuf->st_mtime = oldbuf->st_mtime;
  950. newbuf->st_ctime = oldbuf->st_ctime;
  951. newbuf->st_blksize = 0; /* not supported in old_stat */
  952. newbuf->st_blocks = 0; /* not supported in old_stat */
  953. }
  954. static void
  955. printoldstat(struct tcb *tcp, long addr)
  956. {
  957. struct __old_kernel_stat statbuf;
  958. struct stat newstatbuf;
  959. if (!addr) {
  960. tprints("NULL");
  961. return;
  962. }
  963. if (syserror(tcp) || !verbose(tcp)) {
  964. tprintf("%#lx", addr);
  965. return;
  966. }
  967. # if defined(SPARC) || defined(SPARC64)
  968. if (current_personality == 1) {
  969. printstatsol(tcp, addr);
  970. return;
  971. }
  972. # endif
  973. if (umove(tcp, addr, &statbuf) < 0) {
  974. tprints("{...}");
  975. return;
  976. }
  977. convertoldstat(&statbuf, &newstatbuf);
  978. realprintstat(tcp, &newstatbuf);
  979. }
  980. #endif
  981. int
  982. sys_stat(struct tcb *tcp)
  983. {
  984. if (entering(tcp)) {
  985. printpath(tcp, tcp->u_arg[0]);
  986. tprints(", ");
  987. } else {
  988. printstat(tcp, tcp->u_arg[1]);
  989. }
  990. return 0;
  991. }
  992. #ifdef X32
  993. static void
  994. printstat64_x32(struct tcb *tcp, long addr)
  995. {
  996. struct stat64 statbuf;
  997. if (!addr) {
  998. tprints("NULL");
  999. return;
  1000. }
  1001. if (syserror(tcp) || !verbose(tcp)) {
  1002. tprintf("%#lx", addr);
  1003. return;
  1004. }
  1005. if (umove(tcp, addr, &statbuf) < 0) {
  1006. tprints("{...}");
  1007. return;
  1008. }
  1009. if (!abbrev(tcp)) {
  1010. tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
  1011. (unsigned long) major(statbuf.st_dev),
  1012. (unsigned long) minor(statbuf.st_dev),
  1013. (unsigned long long) statbuf.st_ino,
  1014. sprintmode(statbuf.st_mode));
  1015. tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
  1016. (unsigned long) statbuf.st_nlink,
  1017. (unsigned long) statbuf.st_uid,
  1018. (unsigned long) statbuf.st_gid);
  1019. tprintf("st_blksize=%lu, ",
  1020. (unsigned long) statbuf.st_blksize);
  1021. tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
  1022. }
  1023. else
  1024. tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
  1025. switch (statbuf.st_mode & S_IFMT) {
  1026. case S_IFCHR: case S_IFBLK:
  1027. tprintf("st_rdev=makedev(%lu, %lu), ",
  1028. (unsigned long) major(statbuf.st_rdev),
  1029. (unsigned long) minor(statbuf.st_rdev));
  1030. break;
  1031. default:
  1032. tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
  1033. break;
  1034. }
  1035. if (!abbrev(tcp)) {
  1036. tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
  1037. tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
  1038. tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
  1039. tprints("}");
  1040. }
  1041. else
  1042. tprints("...}");
  1043. }
  1044. #endif /* X32 */
  1045. int
  1046. sys_stat64(struct tcb *tcp)
  1047. {
  1048. #ifdef HAVE_STAT64
  1049. if (entering(tcp)) {
  1050. printpath(tcp, tcp->u_arg[0]);
  1051. tprints(", ");
  1052. } else {
  1053. # ifdef X32
  1054. printstat64_x32(tcp, tcp->u_arg[1]);
  1055. # else
  1056. printstat64(tcp, tcp->u_arg[1]);
  1057. # endif
  1058. }
  1059. return 0;
  1060. #else
  1061. return printargs(tcp);
  1062. #endif
  1063. }
  1064. #ifndef AT_SYMLINK_NOFOLLOW
  1065. # define AT_SYMLINK_NOFOLLOW 0x100
  1066. #endif
  1067. #ifndef AT_REMOVEDIR
  1068. # define AT_REMOVEDIR 0x200
  1069. #endif
  1070. #ifndef AT_SYMLINK_FOLLOW
  1071. # define AT_SYMLINK_FOLLOW 0x400
  1072. #endif
  1073. #ifndef AT_NO_AUTOMOUNT
  1074. # define AT_NO_AUTOMOUNT 0x800
  1075. #endif
  1076. #ifndef AT_EMPTY_PATH
  1077. # define AT_EMPTY_PATH 0x1000
  1078. #endif
  1079. #include "xlat/at_flags.h"
  1080. int
  1081. sys_newfstatat(struct tcb *tcp)
  1082. {
  1083. if (entering(tcp)) {
  1084. print_dirfd(tcp, tcp->u_arg[0]);
  1085. printpath(tcp, tcp->u_arg[1]);
  1086. tprints(", ");
  1087. } else {
  1088. #ifdef POWERPC64
  1089. if (current_personality == 0)
  1090. printstat(tcp, tcp->u_arg[2]);
  1091. else
  1092. printstat64(tcp, tcp->u_arg[2]);
  1093. #elif defined HAVE_STAT64
  1094. printstat64(tcp, tcp->u_arg[2]);
  1095. #else
  1096. printstat(tcp, tcp->u_arg[2]);
  1097. #endif
  1098. tprints(", ");
  1099. printflags(at_flags, tcp->u_arg[3], "AT_???");
  1100. }
  1101. return 0;
  1102. }
  1103. #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
  1104. int
  1105. sys_oldstat(struct tcb *tcp)
  1106. {
  1107. if (entering(tcp)) {
  1108. printpath(tcp, tcp->u_arg[0]);
  1109. tprints(", ");
  1110. } else {
  1111. printoldstat(tcp, tcp->u_arg[1]);
  1112. }
  1113. return 0;
  1114. }
  1115. #endif
  1116. int
  1117. sys_fstat(struct tcb *tcp)
  1118. {
  1119. if (entering(tcp)) {
  1120. printfd(tcp, tcp->u_arg[0]);
  1121. tprints(", ");
  1122. } else {
  1123. printstat(tcp, tcp->u_arg[1]);
  1124. }
  1125. return 0;
  1126. }
  1127. int
  1128. sys_fstat64(struct tcb *tcp)
  1129. {
  1130. #ifdef HAVE_STAT64
  1131. if (entering(tcp)) {
  1132. printfd(tcp, tcp->u_arg[0]);
  1133. tprints(", ");
  1134. } else {
  1135. # ifdef X32
  1136. printstat64_x32(tcp, tcp->u_arg[1]);
  1137. # else
  1138. printstat64(tcp, tcp->u_arg[1]);
  1139. # endif
  1140. }
  1141. return 0;
  1142. #else
  1143. return printargs(tcp);
  1144. #endif
  1145. }
  1146. #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
  1147. int
  1148. sys_oldfstat(struct tcb *tcp)
  1149. {
  1150. if (entering(tcp)) {
  1151. printfd(tcp, tcp->u_arg[0]);
  1152. tprints(", ");
  1153. } else {
  1154. printoldstat(tcp, tcp->u_arg[1]);
  1155. }
  1156. return 0;
  1157. }
  1158. #endif
  1159. #if defined(SPARC) || defined(SPARC64)
  1160. int
  1161. sys_xstat(struct tcb *tcp)
  1162. {
  1163. if (entering(tcp)) {
  1164. tprintf("%ld, ", tcp->u_arg[0]);
  1165. printpath(tcp, tcp->u_arg[1]);
  1166. tprints(", ");
  1167. } else {
  1168. # ifdef _STAT64_VER
  1169. if (tcp->u_arg[0] == _STAT64_VER)
  1170. printstat64(tcp, tcp->u_arg[2]);
  1171. else
  1172. # endif
  1173. printstat(tcp, tcp->u_arg[2]);
  1174. }
  1175. return 0;
  1176. }
  1177. int
  1178. sys_fxstat(struct tcb *tcp)
  1179. {
  1180. if (entering(tcp))
  1181. tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
  1182. else {
  1183. # ifdef _STAT64_VER
  1184. if (tcp->u_arg[0] == _STAT64_VER)
  1185. printstat64(tcp, tcp->u_arg[2]);
  1186. else
  1187. # endif
  1188. printstat(tcp, tcp->u_arg[2]);
  1189. }
  1190. return 0;
  1191. }
  1192. int
  1193. sys_lxstat(struct tcb *tcp)
  1194. {
  1195. if (entering(tcp)) {
  1196. tprintf("%ld, ", tcp->u_arg[0]);
  1197. printpath(tcp, tcp->u_arg[1]);
  1198. tprints(", ");
  1199. } else {
  1200. # ifdef _STAT64_VER
  1201. if (tcp->u_arg[0] == _STAT64_VER)
  1202. printstat64(tcp, tcp->u_arg[2]);
  1203. else
  1204. # endif
  1205. printstat(tcp, tcp->u_arg[2]);
  1206. }
  1207. return 0;
  1208. }
  1209. int
  1210. sys_xmknod(struct tcb *tcp)
  1211. {
  1212. int mode = tcp->u_arg[2];
  1213. if (entering(tcp)) {
  1214. tprintf("%ld, ", tcp->u_arg[0]);
  1215. printpath(tcp, tcp->u_arg[1]);
  1216. tprintf(", %s", sprintmode(mode));
  1217. switch (mode & S_IFMT) {
  1218. case S_IFCHR: case S_IFBLK:
  1219. tprintf(", makedev(%lu, %lu)",
  1220. (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
  1221. (unsigned long) (tcp->u_arg[3] & 0x3ffff));
  1222. break;
  1223. default:
  1224. break;
  1225. }
  1226. }
  1227. return 0;
  1228. }
  1229. #endif /* SPARC[64] */
  1230. /* directory */
  1231. int
  1232. sys_chdir(struct tcb *tcp)
  1233. {
  1234. if (entering(tcp)) {
  1235. printpath(tcp, tcp->u_arg[0]);
  1236. }
  1237. return 0;
  1238. }
  1239. int
  1240. sys_link(struct tcb *tcp)
  1241. {
  1242. if (entering(tcp)) {
  1243. printpath(tcp, tcp->u_arg[0]);
  1244. tprints(", ");
  1245. printpath(tcp, tcp->u_arg[1]);
  1246. }
  1247. return 0;
  1248. }
  1249. int
  1250. sys_linkat(struct tcb *tcp)
  1251. {
  1252. if (entering(tcp)) {
  1253. print_dirfd(tcp, tcp->u_arg[0]);
  1254. printpath(tcp, tcp->u_arg[1]);
  1255. tprints(", ");
  1256. print_dirfd(tcp, tcp->u_arg[2]);
  1257. printpath(tcp, tcp->u_arg[3]);
  1258. tprints(", ");
  1259. printflags(at_flags, tcp->u_arg[4], "AT_???");
  1260. }
  1261. return 0;
  1262. }
  1263. int
  1264. sys_unlinkat(struct tcb *tcp)
  1265. {
  1266. if (entering(tcp)) {
  1267. print_dirfd(tcp, tcp->u_arg[0]);
  1268. printpath(tcp, tcp->u_arg[1]);
  1269. tprints(", ");
  1270. printflags(at_flags, tcp->u_arg[2], "AT_???");
  1271. }
  1272. return 0;
  1273. }
  1274. int
  1275. sys_symlinkat(struct tcb *tcp)
  1276. {
  1277. if (entering(tcp)) {
  1278. printpath(tcp, tcp->u_arg[0]);
  1279. tprints(", ");
  1280. print_dirfd(tcp, tcp->u_arg[1]);
  1281. printpath(tcp, tcp->u_arg[2]);
  1282. }
  1283. return 0;
  1284. }
  1285. static int
  1286. decode_readlink(struct tcb *tcp, int offset)
  1287. {
  1288. if (entering(tcp)) {
  1289. printpath(tcp, tcp->u_arg[offset]);
  1290. tprints(", ");
  1291. } else {
  1292. if (syserror(tcp))
  1293. tprintf("%#lx", tcp->u_arg[offset + 1]);
  1294. else
  1295. /* Used to use printpathn(), but readlink
  1296. * neither includes NUL in the returned count,
  1297. * nor actually writes it into memory.
  1298. * printpathn() would decide on printing
  1299. * "..." continuation based on garbage
  1300. * past return buffer's end.
  1301. */
  1302. printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
  1303. tprintf(", %lu", tcp->u_arg[offset + 2]);
  1304. }
  1305. return 0;
  1306. }
  1307. int
  1308. sys_readlink(struct tcb *tcp)
  1309. {
  1310. return decode_readlink(tcp, 0);
  1311. }
  1312. int
  1313. sys_readlinkat(struct tcb *tcp)
  1314. {
  1315. if (entering(tcp))
  1316. print_dirfd(tcp, tcp->u_arg[0]);
  1317. return decode_readlink(tcp, 1);
  1318. }
  1319. static void
  1320. decode_renameat(struct tcb *tcp)
  1321. {
  1322. print_dirfd(tcp, tcp->u_arg[0]);
  1323. printpath(tcp, tcp->u_arg[1]);
  1324. tprints(", ");
  1325. print_dirfd(tcp, tcp->u_arg[2]);
  1326. printpath(tcp, tcp->u_arg[3]);
  1327. }
  1328. int
  1329. sys_renameat(struct tcb *tcp)
  1330. {
  1331. if (entering(tcp)) {
  1332. decode_renameat(tcp);
  1333. }
  1334. return 0;
  1335. }
  1336. #include "xlat/rename_flags.h"
  1337. int
  1338. sys_renameat2(struct tcb *tcp)
  1339. {
  1340. if (entering(tcp)) {
  1341. decode_renameat(tcp);
  1342. tprints(", ");
  1343. printflags(rename_flags, tcp->u_arg[4], "RENAME_??");
  1344. }
  1345. return 0;
  1346. }
  1347. int
  1348. sys_chown(struct tcb *tcp)
  1349. {
  1350. if (entering(tcp)) {
  1351. printpath(tcp, tcp->u_arg[0]);
  1352. printuid(", ", tcp->u_arg[1]);
  1353. printuid(", ", tcp->u_arg[2]);
  1354. }
  1355. return 0;
  1356. }
  1357. int
  1358. sys_fchownat(struct tcb *tcp)
  1359. {
  1360. if (entering(tcp)) {
  1361. print_dirfd(tcp, tcp->u_arg[0]);
  1362. printpath(tcp, tcp->u_arg[1]);
  1363. printuid(", ", tcp->u_arg[2]);
  1364. printuid(", ", tcp->u_arg[3]);
  1365. tprints(", ");
  1366. printflags(at_flags, tcp->u_arg[4], "AT_???");
  1367. }
  1368. return 0;
  1369. }
  1370. int
  1371. sys_fchown(struct tcb *tcp)
  1372. {
  1373. if (entering(tcp)) {
  1374. printfd(tcp, tcp->u_arg[0]);
  1375. printuid(", ", tcp->u_arg[1]);
  1376. printuid(", ", tcp->u_arg[2]);
  1377. }
  1378. return 0;
  1379. }
  1380. static int
  1381. decode_chmod(struct tcb *tcp, int offset)
  1382. {
  1383. if (entering(tcp)) {
  1384. printpath(tcp, tcp->u_arg[offset]);
  1385. tprintf(", %#lo", tcp->u_arg[offset + 1]);
  1386. }
  1387. return 0;
  1388. }
  1389. int
  1390. sys_chmod(struct tcb *tcp)
  1391. {
  1392. return decode_chmod(tcp, 0);
  1393. }
  1394. int
  1395. sys_fchmodat(struct tcb *tcp)
  1396. {
  1397. if (entering(tcp))
  1398. print_dirfd(tcp, tcp->u_arg[0]);
  1399. return decode_chmod(tcp, 1);
  1400. }
  1401. int
  1402. sys_fchmod(struct tcb *tcp)
  1403. {
  1404. if (entering(tcp)) {
  1405. printfd(tcp, tcp->u_arg[0]);
  1406. tprintf(", %#lo", tcp->u_arg[1]);
  1407. }
  1408. return 0;
  1409. }
  1410. #ifdef ALPHA
  1411. int
  1412. sys_osf_utimes(struct tcb *tcp)
  1413. {
  1414. if (entering(tcp)) {
  1415. printpath(tcp, tcp->u_arg[0]);
  1416. tprints(", ");
  1417. printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
  1418. }
  1419. return 0;
  1420. }
  1421. #endif
  1422. static int
  1423. decode_utimes(struct tcb *tcp, int offset, int special)
  1424. {
  1425. if (entering(tcp)) {
  1426. printpath(tcp, tcp->u_arg[offset]);
  1427. tprints(", ");
  1428. if (tcp->u_arg[offset + 1] == 0)
  1429. tprints("NULL");
  1430. else {
  1431. tprints("{");
  1432. printtv_bitness(tcp, tcp->u_arg[offset + 1],
  1433. BITNESS_CURRENT, special);
  1434. tprints(", ");
  1435. printtv_bitness(tcp, tcp->u_arg[offset + 1]
  1436. + sizeof(struct timeval),
  1437. BITNESS_CURRENT, special);
  1438. tprints("}");
  1439. }
  1440. }
  1441. return 0;
  1442. }
  1443. int
  1444. sys_utimes(struct tcb *tcp)
  1445. {
  1446. return decode_utimes(tcp, 0, 0);
  1447. }
  1448. int
  1449. sys_futimesat(struct tcb *tcp)
  1450. {
  1451. if (entering(tcp))
  1452. print_dirfd(tcp, tcp->u_arg[0]);
  1453. return decode_utimes(tcp, 1, 0);
  1454. }
  1455. int
  1456. sys_utimensat(struct tcb *tcp)
  1457. {
  1458. if (entering(tcp)) {
  1459. print_dirfd(tcp, tcp->u_arg[0]);
  1460. decode_utimes(tcp, 1, 1);
  1461. tprints(", ");
  1462. printflags(at_flags, tcp->u_arg[3], "AT_???");
  1463. }
  1464. return 0;
  1465. }
  1466. int
  1467. sys_utime(struct tcb *tcp)
  1468. {
  1469. union {
  1470. long utl[2];
  1471. int uti[2];
  1472. long paranoia_for_huge_wordsize[4];
  1473. } u;
  1474. unsigned wordsize;
  1475. if (entering(tcp)) {
  1476. printpath(tcp, tcp->u_arg[0]);
  1477. tprints(", ");
  1478. wordsize = current_wordsize;
  1479. if (!tcp->u_arg[1])
  1480. tprints("NULL");
  1481. else if (!verbose(tcp))
  1482. tprintf("%#lx", tcp->u_arg[1]);
  1483. else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
  1484. tprints("[?, ?]");
  1485. else if (wordsize == sizeof u.utl[0]) {
  1486. tprintf("[%s,", sprinttime(u.utl[0]));
  1487. tprintf(" %s]", sprinttime(u.utl[1]));
  1488. }
  1489. else if (wordsize == sizeof u.uti[0]) {
  1490. tprintf("[%s,", sprinttime(u.uti[0]));
  1491. tprintf(" %s]", sprinttime(u.uti[1]));
  1492. }
  1493. else
  1494. tprintf("<decode error: unsupported wordsize %d>",
  1495. wordsize);
  1496. }
  1497. return 0;
  1498. }
  1499. static int
  1500. decode_mknod(struct tcb *tcp, int offset)
  1501. {
  1502. int mode = tcp->u_arg[offset + 1];
  1503. if (entering(tcp)) {
  1504. printpath(tcp, tcp->u_arg[offset]);
  1505. tprintf(", %s", sprintmode(mode));
  1506. switch (mode & S_IFMT) {
  1507. case S_IFCHR:
  1508. case S_IFBLK:
  1509. #if defined(SPARC) || defined(SPARC64)
  1510. if (current_personality == 1)
  1511. tprintf(", makedev(%lu, %lu)",
  1512. (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
  1513. (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
  1514. else
  1515. #endif
  1516. tprintf(", makedev(%lu, %lu)",
  1517. (unsigned long) major(tcp->u_arg[offset + 2]),
  1518. (unsigned long) minor(tcp->u_arg[offset + 2]));
  1519. break;
  1520. default:
  1521. break;
  1522. }
  1523. }
  1524. return 0;
  1525. }
  1526. int
  1527. sys_mknod(struct tcb *tcp)
  1528. {
  1529. return decode_mknod(tcp, 0);
  1530. }
  1531. int
  1532. sys_mknodat(struct tcb *tcp)
  1533. {
  1534. if (entering(tcp))
  1535. print_dirfd(tcp, tcp->u_arg[0]);
  1536. return decode_mknod(tcp, 1);
  1537. }