-
Notifications
You must be signed in to change notification settings - Fork 10
/
file.c
3070 lines (2815 loc) · 61.2 KB
/
file.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1991, 1992 Paul Kranenburg <[email protected]>
* Copyright (c) 1993 Branko Lankester <[email protected]>
* Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <[email protected]>
* Copyright (c) 1996-1999 Wichert Akkerman <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*/
#include "defs.h"
#include <dirent.h>
#ifdef LINUX
struct kernel_dirent {
unsigned long d_ino;
unsigned long d_off;
unsigned short d_reclen;
char d_name[1];
};
#else
# define kernel_dirent dirent
#endif
#ifdef LINUX
# ifdef LINUXSPARC
struct stat {
unsigned short st_dev;
unsigned int st_ino;
unsigned short st_mode;
short st_nlink;
unsigned short st_uid;
unsigned short st_gid;
unsigned short st_rdev;
unsigned int st_size;
int st_atime;
unsigned int __unused1;
int st_mtime;
unsigned int __unused2;
int st_ctime;
unsigned int __unused3;
int st_blksize;
int st_blocks;
unsigned int __unused4[2];
};
#if defined(SPARC64)
struct stat_sparc64 {
unsigned int st_dev;
unsigned long st_ino;
unsigned int st_mode;
unsigned int st_nlink;
unsigned int st_uid;
unsigned int st_gid;
unsigned int st_rdev;
long st_size;
long st_atime;
long st_mtime;
long st_ctime;
long st_blksize;
long st_blocks;
unsigned long __unused4[2];
};
#endif /* SPARC64 */
# define stat kernel_stat
# include <asm/stat.h>
# undef stat
# else
# undef dev_t
# undef ino_t
# undef mode_t
# undef nlink_t
# undef uid_t
# undef gid_t
# undef off_t
# undef loff_t
# define dev_t __kernel_dev_t
# define ino_t __kernel_ino_t
# define mode_t __kernel_mode_t
# define nlink_t __kernel_nlink_t
# define uid_t __kernel_uid_t
# define gid_t __kernel_gid_t
# define off_t __kernel_off_t
# define loff_t __kernel_loff_t
# include <asm/stat.h>
# undef dev_t
# undef ino_t
# undef mode_t
# undef nlink_t
# undef uid_t
# undef gid_t
# undef off_t
# undef loff_t
# define dev_t dev_t
# define ino_t ino_t
# define mode_t mode_t
# define nlink_t nlink_t
# define uid_t uid_t
# define gid_t gid_t
# define off_t off_t
# define loff_t loff_t
# endif
# ifdef HPPA /* asm-parisc/stat.h defines stat64 */
# undef stat64
# endif
# define stat libc_stat
# define stat64 libc_stat64
# include <sys/stat.h>
# undef stat
# undef stat64
/* These might be macros. */
# undef st_atime
# undef st_mtime
# undef st_ctime
# ifdef HPPA
# define stat64 hpux_stat64
# endif
#else
# include <sys/stat.h>
#endif
#include <fcntl.h>
#ifdef SVR4
# include <sys/cred.h>
#endif /* SVR4 */
#ifdef HAVE_SYS_VFS_H
#include <sys/vfs.h>
#endif
#ifdef HAVE_LINUX_XATTR_H
#include <linux/xattr.h>
#elif defined linux
#define XATTR_CREATE 1
#define XATTR_REPLACE 2
#endif
#ifdef FREEBSD
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/stat.h>
#endif
#if _LFS64_LARGEFILE && (defined(LINUX) || defined(SVR4))
# ifdef HAVE_INTTYPES_H
# include <inttypes.h>
# else
# define PRId64 "lld"
# define PRIu64 "llu"
# endif
#endif
#if HAVE_LONG_LONG_OFF_T
/*
* Ugly hacks for systems that have typedef long long off_t
*/
#define stat64 stat
#define HAVE_STAT64 1 /* Ugly hack */
#define sys_stat64 sys_stat
#define sys_fstat64 sys_fstat
#define sys_lstat64 sys_lstat
#define sys_lseek64 sys_lseek
#define sys_truncate64 sys_truncate
#define sys_ftruncate64 sys_ftruncate
#endif
#ifdef MAJOR_IN_SYSMACROS
#include <sys/sysmacros.h>
#endif
#ifdef MAJOR_IN_MKDEV
#include <sys/mkdev.h>
#endif
#ifdef HAVE_SYS_ASYNCH_H
#include <sys/asynch.h>
#endif
#ifdef SUNOS4
#include <ustat.h>
#endif
const struct xlat open_access_modes[] = {
{ O_RDONLY, "O_RDONLY" },
{ O_WRONLY, "O_WRONLY" },
{ O_RDWR, "O_RDWR" },
#ifdef O_ACCMODE
{ O_ACCMODE, "O_ACCMODE" },
#endif
{ 0, NULL },
};
const struct xlat open_mode_flags[] = {
{ O_CREAT, "O_CREAT" },
{ O_EXCL, "O_EXCL" },
{ O_NOCTTY, "O_NOCTTY" },
{ O_TRUNC, "O_TRUNC" },
{ O_APPEND, "O_APPEND" },
{ O_NONBLOCK, "O_NONBLOCK" },
#ifdef O_SYNC
{ O_SYNC, "O_SYNC" },
#endif
#ifdef O_ASYNC
{ O_ASYNC, "O_ASYNC" },
#endif
#ifdef O_DSYNC
{ O_DSYNC, "O_DSYNC" },
#endif
#ifdef O_RSYNC
{ O_RSYNC, "O_RSYNC" },
#endif
#if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
{ O_NDELAY, "O_NDELAY" },
#endif
#ifdef O_PRIV
{ O_PRIV, "O_PRIV" },
#endif
#ifdef O_DIRECT
{ O_DIRECT, "O_DIRECT" },
#endif
#ifdef O_LARGEFILE
# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
# undef O_LARGEFILE
# ifdef SPARC64
# define O_LARGEFILE 0x40000
# elif defined X86_64 || defined S390X
# define O_LARGEFILE 0100000
# endif
# endif
# ifdef O_LARGEFILE
{ O_LARGEFILE, "O_LARGEFILE" },
# endif
#endif
#ifdef O_DIRECTORY
{ O_DIRECTORY, "O_DIRECTORY" },
#endif
#ifdef O_NOFOLLOW
{ O_NOFOLLOW, "O_NOFOLLOW" },
#endif
#ifdef O_NOATIME
{ O_NOATIME, "O_NOATIME" },
#endif
#ifdef O_CLOEXEC
{ O_CLOEXEC, "O_CLOEXEC" },
#endif
#ifdef FNDELAY
{ FNDELAY, "FNDELAY" },
#endif
#ifdef FAPPEND
{ FAPPEND, "FAPPEND" },
#endif
#ifdef FMARK
{ FMARK, "FMARK" },
#endif
#ifdef FDEFER
{ FDEFER, "FDEFER" },
#endif
#ifdef FASYNC
{ FASYNC, "FASYNC" },
#endif
#ifdef FSHLOCK
{ FSHLOCK, "FSHLOCK" },
#endif
#ifdef FEXLOCK
{ FEXLOCK, "FEXLOCK" },
#endif
#ifdef FCREAT
{ FCREAT, "FCREAT" },
#endif
#ifdef FTRUNC
{ FTRUNC, "FTRUNC" },
#endif
#ifdef FEXCL
{ FEXCL, "FEXCL" },
#endif
#ifdef FNBIO
{ FNBIO, "FNBIO" },
#endif
#ifdef FSYNC
{ FSYNC, "FSYNC" },
#endif
#ifdef FNOCTTY
{ FNOCTTY, "FNOCTTY" },
#endif
#ifdef O_SHLOCK
{ O_SHLOCK, "O_SHLOCK" },
#endif
#ifdef O_EXLOCK
{ O_EXLOCK, "O_EXLOCK" },
#endif
{ 0, NULL },
};
#ifdef LINUX
#ifndef AT_FDCWD
# define AT_FDCWD -100
#endif
/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
* extension to get the right value. We do this by declaring fd as int here.
*/
static void
print_dirfd(int fd)
{
if (fd == AT_FDCWD)
tprintf("AT_FDCWD, ");
else
tprintf("%d, ", fd);
}
#endif
/*
* Pity stpcpy() is not standardized...
*/
static char *
str_append(char *dst, const char *src)
{
while ((*dst = *src++) != '\0')
dst++;
return dst;
}
/*
* low bits of the open(2) flags define access mode,
* other bits are real flags.
*/
const char *
sprint_open_modes(mode_t flags)
{
static char outstr[1024];
char *p;
char sep = 0;
const char *str;
const struct xlat *x;
p = str_append(outstr, "flags ");
str = xlookup(open_access_modes, flags & 3);
if (str) {
p = str_append(p, str);
flags &= ~3;
if (!flags)
return outstr;
sep = '|';
}
for (x = open_mode_flags; x->str; x++) {
if ((flags & x->val) == x->val) {
if (sep)
*p++ = sep;
p = str_append(p, x->str);
flags &= ~x->val;
if (!flags)
return outstr;
sep = '|';
}
}
/* flags is still nonzero */
if (sep)
*p++ = sep;
sprintf(p, "%#x", flags);
return outstr;
}
void
tprint_open_modes(mode_t flags)
{
tprintf("%s", sprint_open_modes(flags) + sizeof("flags"));
}
static int
decode_open(struct tcb *tcp, int offset)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[offset]);
tprintf(", ");
/* flags */
tprint_open_modes(tcp->u_arg[offset + 1]);
if (tcp->u_arg[offset + 1] & O_CREAT) {
/* mode */
tprintf(", %#lo", tcp->u_arg[offset + 2]);
}
}
return 0;
}
int
sys_open(struct tcb *tcp)
{
return decode_open(tcp, 0);
}
#ifdef LINUX
int
sys_openat(struct tcb *tcp)
{
if (entering(tcp))
print_dirfd(tcp->u_arg[0]);
return decode_open(tcp, 1);
}
#endif
#ifdef LINUXSPARC
static const struct xlat openmodessol[] = {
{ 0, "O_RDWR" },
{ 1, "O_RDONLY" },
{ 2, "O_WRONLY" },
{ 0x80, "O_NONBLOCK" },
{ 8, "O_APPEND" },
{ 0x100, "O_CREAT" },
{ 0x200, "O_TRUNC" },
{ 0x400, "O_EXCL" },
{ 0x800, "O_NOCTTY" },
{ 0x10, "O_SYNC" },
{ 0x40, "O_DSYNC" },
{ 0x8000, "O_RSYNC" },
{ 4, "O_NDELAY" },
{ 0x1000, "O_PRIV" },
{ 0, NULL },
};
int
solaris_open(struct tcb *tcp)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
tprintf(", ");
/* flags */
printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
if (tcp->u_arg[1] & 0x100) {
/* mode */
tprintf(", %#lo", tcp->u_arg[2]);
}
}
return 0;
}
#endif
int
sys_creat(struct tcb *tcp)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
tprintf(", %#lo", tcp->u_arg[1]);
}
return 0;
}
static const struct xlat access_flags[] = {
{ F_OK, "F_OK", },
{ R_OK, "R_OK" },
{ W_OK, "W_OK" },
{ X_OK, "X_OK" },
#ifdef EFF_ONLY_OK
{ EFF_ONLY_OK, "EFF_ONLY_OK" },
#endif
#ifdef EX_OK
{ EX_OK, "EX_OK" },
#endif
{ 0, NULL },
};
static int
decode_access(struct tcb *tcp, int offset)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[offset]);
tprintf(", ");
printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
}
return 0;
}
int
sys_access(struct tcb *tcp)
{
return decode_access(tcp, 0);
}
#ifdef LINUX
int
sys_faccessat(struct tcb *tcp)
{
if (entering(tcp))
print_dirfd(tcp->u_arg[0]);
return decode_access(tcp, 1);
}
#endif
int
sys_umask(struct tcb *tcp)
{
if (entering(tcp)) {
tprintf("%#lo", tcp->u_arg[0]);
}
return RVAL_OCTAL;
}
static const struct xlat whence[] = {
{ SEEK_SET, "SEEK_SET" },
{ SEEK_CUR, "SEEK_CUR" },
{ SEEK_END, "SEEK_END" },
{ 0, NULL },
};
#ifndef HAVE_LONG_LONG_OFF_T
#if defined (LINUX_MIPSN32)
int
sys_lseek(struct tcb *tcp)
{
long long offset;
int _whence;
if (entering(tcp)) {
tprintf("%ld, ", tcp->u_arg[0]);
offset = tcp->ext_arg[1];
_whence = tcp->u_arg[2];
if (_whence == SEEK_SET)
tprintf("%llu, ", offset);
else
tprintf("%lld, ", offset);
printxval(whence, _whence, "SEEK_???");
}
return RVAL_UDECIMAL;
}
#else /* !LINUX_MIPSN32 */
int
sys_lseek(struct tcb *tcp)
{
off_t offset;
int _whence;
if (entering(tcp)) {
tprintf("%ld, ", tcp->u_arg[0]);
offset = tcp->u_arg[1];
_whence = tcp->u_arg[2];
if (_whence == SEEK_SET)
tprintf("%lu, ", offset);
else
tprintf("%ld, ", offset);
printxval(whence, _whence, "SEEK_???");
}
return RVAL_UDECIMAL;
}
#endif /* LINUX_MIPSN32 */
#endif
#ifdef LINUX
int
sys_llseek(struct tcb *tcp)
{
if (entering(tcp)) {
/*
* This one call takes explicitly two 32-bit arguments hi, lo,
* rather than one 64-bit argument for which LONG_LONG works
* appropriate for the native byte order.
*/
if (tcp->u_arg[4] == SEEK_SET)
tprintf("%ld, %llu, ", tcp->u_arg[0],
(((long long int) tcp->u_arg[1]) << 32
| (unsigned long long) (unsigned) tcp->u_arg[2]));
else
tprintf("%ld, %lld, ", tcp->u_arg[0],
(((long long int) tcp->u_arg[1]) << 32
| (unsigned long long) (unsigned) tcp->u_arg[2]));
}
else {
long long int off;
if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
tprintf("%#lx, ", tcp->u_arg[3]);
else
tprintf("[%llu], ", off);
printxval(whence, tcp->u_arg[4], "SEEK_???");
}
return 0;
}
int
sys_readahead(struct tcb *tcp)
{
if (entering(tcp)) {
int argn;
tprintf("%ld, ", tcp->u_arg[0]);
argn = printllval(tcp, "%lld", 1);
tprintf(", %ld", tcp->u_arg[argn]);
}
return 0;
}
#endif
#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
int
sys_lseek64(struct tcb *tcp)
{
if (entering(tcp)) {
int argn;
tprintf("%ld, ", tcp->u_arg[0]);
if (tcp->u_arg[3] == SEEK_SET)
argn = printllval(tcp, "%llu, ", 1);
else
argn = printllval(tcp, "%lld, ", 1);
printxval(whence, tcp->u_arg[argn], "SEEK_???");
}
return RVAL_LUDECIMAL;
}
#endif
#ifndef HAVE_LONG_LONG_OFF_T
int
sys_truncate(struct tcb *tcp)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
tprintf(", %lu", tcp->u_arg[1]);
}
return 0;
}
#endif
#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
int
sys_truncate64(struct tcb *tcp)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
printllval(tcp, ", %llu", 1);
}
return 0;
}
#endif
#ifndef HAVE_LONG_LONG_OFF_T
int
sys_ftruncate(struct tcb *tcp)
{
if (entering(tcp)) {
tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
}
return 0;
}
#endif
#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
int
sys_ftruncate64(struct tcb *tcp)
{
if (entering(tcp)) {
tprintf("%ld, ", tcp->u_arg[0]);
printllval(tcp, "%llu", 1);
}
return 0;
}
#endif
/* several stats */
static const struct xlat modetypes[] = {
{ S_IFREG, "S_IFREG" },
{ S_IFSOCK, "S_IFSOCK" },
{ S_IFIFO, "S_IFIFO" },
{ S_IFLNK, "S_IFLNK" },
{ S_IFDIR, "S_IFDIR" },
{ S_IFBLK, "S_IFBLK" },
{ S_IFCHR, "S_IFCHR" },
{ 0, NULL },
};
static const char *
sprintmode(int mode)
{
static char buf[64];
const char *s;
if ((mode & S_IFMT) == 0)
s = "";
else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
sprintf(buf, "%#o", mode);
return buf;
}
sprintf(buf, "%s%s%s%s", s,
(mode & S_ISUID) ? "|S_ISUID" : "",
(mode & S_ISGID) ? "|S_ISGID" : "",
(mode & S_ISVTX) ? "|S_ISVTX" : "");
mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
if (mode)
sprintf(buf + strlen(buf), "|%#o", mode);
s = (*buf == '|') ? buf + 1 : buf;
return *s ? s : "0";
}
static char *
sprinttime(time_t t)
{
struct tm *tmp;
static char buf[32];
if (t == 0) {
strcpy(buf, "0");
return buf;
}
if ((tmp = localtime(&t)))
snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
else
snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
return buf;
}
#ifdef LINUXSPARC
typedef struct {
int tv_sec;
int tv_nsec;
} timestruct_t;
struct solstat {
unsigned st_dev;
int st_pad1[3]; /* network id */
unsigned st_ino;
unsigned st_mode;
unsigned st_nlink;
unsigned st_uid;
unsigned st_gid;
unsigned st_rdev;
int st_pad2[2];
int st_size;
int st_pad3; /* st_size, off_t expansion */
timestruct_t st_atime;
timestruct_t st_mtime;
timestruct_t st_ctime;
int st_blksize;
int st_blocks;
char st_fstype[16];
int st_pad4[8]; /* expansion area */
};
static void
printstatsol(struct tcb *tcp, long addr)
{
struct solstat statbuf;
if (umove(tcp, addr, &statbuf) < 0) {
tprintf("{...}");
return;
}
if (!abbrev(tcp)) {
tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
(unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
(unsigned long) (statbuf.st_dev & 0x3ffff),
(unsigned long) statbuf.st_ino,
sprintmode(statbuf.st_mode));
tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
(unsigned long) statbuf.st_nlink,
(unsigned long) statbuf.st_uid,
(unsigned long) statbuf.st_gid);
tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
}
else
tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
switch (statbuf.st_mode & S_IFMT) {
case S_IFCHR: case S_IFBLK:
tprintf("st_rdev=makedev(%lu, %lu), ",
(unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
(unsigned long) (statbuf.st_rdev & 0x3ffff));
break;
default:
tprintf("st_size=%u, ", statbuf.st_size);
break;
}
if (!abbrev(tcp)) {
tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
}
else
tprintf("...}");
}
#if defined (SPARC64)
static void
printstat_sparc64(struct tcb *tcp, long addr)
{
struct stat_sparc64 statbuf;
if (umove(tcp, addr, &statbuf) < 0) {
tprintf("{...}");
return;
}
if (!abbrev(tcp)) {
tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
(unsigned long) major(statbuf.st_dev),
(unsigned long) minor(statbuf.st_dev),
(unsigned long) statbuf.st_ino,
sprintmode(statbuf.st_mode));
tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
(unsigned long) statbuf.st_nlink,
(unsigned long) statbuf.st_uid,
(unsigned long) statbuf.st_gid);
tprintf("st_blksize=%lu, ",
(unsigned long) statbuf.st_blksize);
tprintf("st_blocks=%lu, ",
(unsigned long) statbuf.st_blocks);
}
else
tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
switch (statbuf.st_mode & S_IFMT) {
case S_IFCHR: case S_IFBLK:
tprintf("st_rdev=makedev(%lu, %lu), ",
(unsigned long) major(statbuf.st_rdev),
(unsigned long) minor(statbuf.st_rdev));
break;
default:
tprintf("st_size=%lu, ", statbuf.st_size);
break;
}
if (!abbrev(tcp)) {
tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
tprintf("}");
}
else
tprintf("...}");
}
#endif /* SPARC64 */
#endif /* LINUXSPARC */
static const struct xlat fileflags[] = {
#ifdef FREEBSD
{ UF_NODUMP, "UF_NODUMP" },
{ UF_IMMUTABLE, "UF_IMMUTABLE" },
{ UF_APPEND, "UF_APPEND" },
{ UF_OPAQUE, "UF_OPAQUE" },
{ UF_NOUNLINK, "UF_NOUNLINK" },
{ SF_ARCHIVED, "SF_ARCHIVED" },
{ SF_IMMUTABLE, "SF_IMMUTABLE" },
{ SF_APPEND, "SF_APPEND" },
{ SF_NOUNLINK, "SF_NOUNLINK" },
#elif UNIXWARE >= 2
#ifdef _S_ISMLD
{ _S_ISMLD, "_S_ISMLD" },
#endif
#ifdef _S_ISMOUNTED
{ _S_ISMOUNTED, "_S_ISMOUNTED" },
#endif
#endif
{ 0, NULL },
};
#ifdef FREEBSD
int
sys_chflags(struct tcb *tcp)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
tprintf(", ");
printflags(fileflags, tcp->u_arg[1], "UF_???");
}
return 0;
}
int
sys_fchflags(struct tcb *tcp)
{
if (entering(tcp)) {
tprintf("%ld, ", tcp->u_arg[0]);
printflags(fileflags, tcp->u_arg[1], "UF_???");
}
return 0;
}
#endif
#ifndef HAVE_LONG_LONG_OFF_T
static void
realprintstat(struct tcb *tcp, struct stat *statbuf)
{
if (!abbrev(tcp)) {
tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
(unsigned long) major(statbuf->st_dev),
(unsigned long) minor(statbuf->st_dev),
(unsigned long) statbuf->st_ino,
sprintmode(statbuf->st_mode));
tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
(unsigned long) statbuf->st_nlink,
(unsigned long) statbuf->st_uid,
(unsigned long) statbuf->st_gid);
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
#endif
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
#endif
}
else
tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
switch (statbuf->st_mode & S_IFMT) {
case S_IFCHR: case S_IFBLK:
#ifdef HAVE_STRUCT_STAT_ST_RDEV
tprintf("st_rdev=makedev(%lu, %lu), ",
(unsigned long) major(statbuf->st_rdev),
(unsigned long) minor(statbuf->st_rdev));
#else /* !HAVE_STRUCT_STAT_ST_RDEV */
tprintf("st_size=makedev(%lu, %lu), ",
(unsigned long) major(statbuf->st_size),
(unsigned long) minor(statbuf->st_size));
#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
break;
default:
tprintf("st_size=%lu, ", statbuf->st_size);
break;
}
if (!abbrev(tcp)) {
tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
#if HAVE_STRUCT_STAT_ST_FLAGS
tprintf(", st_flags=");
printflags(fileflags, statbuf->st_flags, "UF_???");
#endif
#if HAVE_STRUCT_STAT_ST_ACLCNT
tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
#endif
#if HAVE_STRUCT_STAT_ST_LEVEL
tprintf(", st_level=%ld", statbuf->st_level);
#endif
#if HAVE_STRUCT_STAT_ST_FSTYPE
tprintf(", st_fstype=%.*s",
(int) sizeof statbuf->st_fstype, statbuf->st_fstype);
#endif
#if HAVE_STRUCT_STAT_ST_GEN
tprintf(", st_gen=%u", statbuf->st_gen);
#endif
tprintf("}");
}
else
tprintf("...}");
}
static void
printstat(struct tcb *tcp, long addr)
{
struct stat statbuf;
if (!addr) {
tprintf("NULL");
return;
}
if (syserror(tcp) || !verbose(tcp)) {
tprintf("%#lx", addr);
return;
}
#ifdef LINUXSPARC
if (current_personality == 1) {
printstatsol(tcp, addr);
return;
}
#ifdef SPARC64
else if (current_personality == 2) {
printstat_sparc64(tcp, addr);
return;
}
#endif
#endif /* LINUXSPARC */