2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
19 static mode_t
__prot_a2u(ULONG protect
);
20 static uid_t
__id_a2u(UWORD id
);
23 int __stat(BPTR lock
, struct stat
*sb
)
25 struct FileInfoBlock
*fib
;
27 fib
= AllocDosObject(DOS_FIB
, NULL
);
31 errno
= IoErr2errno(IoErr());
36 if (!Examine(lock
, fib
))
38 errno
= IoErr2errno(IoErr());
39 FreeDosObject(DOS_FIB
, fib
);
44 sb
->st_dev
= (dev_t
)((struct FileHandle
*)lock
)->fh_Device
;
45 sb
->st_ino
= (ino_t
)fib
->fib_DiskKey
;
46 sb
->st_size
= (off_t
)fib
->fib_Size
;
47 sb
->st_blocks
= (long)fib
->fib_NumBlocks
;
50 sb
->st_mtime
= (fib
->fib_Date
.ds_Days
* 24*60 + fib
->fib_Date
.ds_Minute
+ __gmtoffset
) * 60 +
51 fib
->fib_Date
.ds_Tick
/ TICKS_PER_SECOND
+ OFFSET_FROM_1970
;
52 sb
->st_uid
= __id_a2u(fib
->fib_OwnerUID
);
53 sb
->st_gid
= __id_a2u(fib
->fib_OwnerGID
);
54 sb
->st_mode
= __prot_a2u(fib
->fib_Protection
);
59 if (Info(lock
, &info
))
61 sb
->st_blksize
= info
.id_BytesPerBlock
;
65 /* The st_blksize is just a guideline anyway, so we set it
66 to 1024 in case Info() didn't succeed */
67 sb
->st_blksize
= 1024;
71 switch (fib
->fib_DirEntryType
)
74 /* don't use S_IFIFO, we don't have a mkfifo() call ! */
75 sb
->st_mode
|= S_IFCHR
;
81 sb
->st_mode
|= S_IFDIR
;
86 sb
->st_mode
|= S_IFLNK
;
91 sb
->st_mode
|= S_IFDIR
;
99 sb
->st_mode
|= S_IFREG
;
102 FreeDosObject(DOS_FIB
, fib
);
108 static mode_t
__prot_a2u(ULONG protect
)
112 if ((protect
& FIBF_SCRIPT
))
114 /* The following three flags are low-active! */
115 if (!(protect
& FIBF_EXECUTE
))
117 if (!(protect
& FIBF_WRITE
))
119 if (!(protect
& FIBF_READ
))
121 if ((protect
& FIBF_GRP_EXECUTE
))
123 if ((protect
& FIBF_GRP_WRITE
))
125 if ((protect
& FIBF_GRP_READ
))
127 if ((protect
& FIBF_OTR_EXECUTE
))
129 if ((protect
& FIBF_OTR_WRITE
))
131 if ((protect
& FIBF_OTR_READ
))
138 static uid_t
__id_a2u(UWORD id
)