26import java.time.Instant;
27import java.time.ZoneOffset;
47 type ( 0b0000000000000001 ),
49 mode ( 0b0000000000000010 ),
51 uid ( 0b0000000000001000 ),
52 gid ( 0b0000000000010000 ),
56 ino ( 0b0000000100000000 ),
57 size ( 0b0000001000000000 ),
60 fd ( 0b0001000000000000 );
62 Type(
final int v) { value = v; }
74 public boolean isSet(
final Type bit) {
return bit.value == (
mask & bit.value ); }
75 public void set(
final Type bit) {
mask = (short) (
mask | bit.value ); }
80 final StringBuilder out =
new StringBuilder();
81 for (
final Type dt :
Type.values()) {
83 if( 0 < count ) { out.append(
", "); }
84 out.append(dt.name()); count++;
91 return out.toString();
94 public boolean equals(
final Object other) {
98 return (other instanceof
Field) &&
99 this.mask == ((
Field)other).mask;
104 private final String link_target_path_;
106 private final Field has_fields_;
107 private final FMode mode_;
108 private final int fd_;
109 private final int uid_;
110 private final int gid_;
111 private final int errno_res_;
113 private final long size_;
115 private final Instant btime_;
116 private final Instant atime_;
117 private final Instant ctime_;
118 private final Instant mtime_;
125 link_target_path_ =
null;
127 has_fields_ =
new Field();
136 btime_ = Instant.ofEpochSecond(0, 0);
145 public boolean equals(
final Object other) {
151 return item_.
equals( o.item_ ) &&
152 has_fields_.equals(o.has_fields_) &&
154 uid_ == o.uid_ && gid_ == o.gid_ &&
155 errno_res_ == o.errno_res_ &&
157 btime_.equals( o.btime_ ) &&
158 atime_.equals( o.atime_ ) &&
159 ctime_.equals( o.ctime_ ) &&
160 mtime_.equals( o.mtime_ ) &&
162 ( link_target_path_.equals(o.link_target_path_) &&
163 link_target_.
equals(o.link_target_)
178 this( (byte)0, ctorImpl1(
path) );
196 this( (byte)0, ctorImpl3(
fd) );
199 private FileStats(
final byte dummy,
final long h) {
201 final String[] s3 = getString3DirItemLinkTargetPath(h);
202 item_ =
new DirItem(s3[0], s3[1]);
203 link_target_path_ = s3[2];
206 final int[] i6 = getInt6FieldsFModeFdUidGidErrno(h);
207 has_fields_ =
new Field(i6[0]);
208 mode_ =
new FMode(i6[1]);
215 final long[] l9 = getLong9SizeTimes(h);
217 btime_ = Instant.ofEpochSecond(l9[1+0*2+0], l9[1+0*2+1]);
218 atime_ = Instant.ofEpochSecond(l9[1+1*2+0], l9[1+1*2+1]);
219 ctime_ = Instant.ofEpochSecond(l9[1+2*2+0], l9[1+2*2+1]);
220 mtime_ = Instant.ofEpochSecond(l9[1+3*2+0], l9[1+3*2+1]);
223 final long lth = ctorLinkTargetImpl(h);
227 link_target_ =
new FileStats( (
byte)0, lth );
232 private static native
long ctorImpl1(
final String
path);
233 private static native
long ctorImpl2(
final String dirname,
final String basename);
234 private static native
long ctorImpl3(
final int fd);
235 private static native
void dtorImpl(
final long h);
236 private static native
int[] getInt6FieldsFModeFdUidGidErrno(
final long h);
237 private static native String[] getString3DirItemLinkTargetPath(
final long h);
238 private static native
long[] getLong9SizeTimes(
final long h);
239 private static native
long ctorLinkTargetImpl(
final long h);
297 while(
null != fs1 ) {
302 if(
null != link_count && link_count.length > 0 ) {
303 link_count[0] = count;
309 public boolean has(
final Field.
Type bit) {
return has_fields_.isSet(bit); }
328 public int fd() {
return fd_; }
331 public int uid() {
return uid_; }
334 public int gid() {
return gid_; }
341 public long size() {
return size_; }
344 public Instant
btime() {
return btime_; }
346 public Instant
atime() {
return atime_; }
348 public Instant
ctime() {
return ctime_; }
350 public Instant
mtime() {
return mtime_; }
356 public boolean ok() {
return 0 == errno_res_; }
368 public boolean has_fd() {
return 0 <= fd_; }
399 final String stored_path, link_detail;
401 if(
null != link_target_path_ ) {
402 stored_path =
" [-> "+link_target_path_+
"]";
404 stored_path =
new String();
406 final long link_count[] = { 0 };
408 if( 0 < link_count[0] ) {
409 link_detail =
" -(" + link_count[0] +
")-> '" + final_target_.
path() +
"'";
411 link_detail =
new String();
414 final StringBuilder res =
new StringBuilder(
"file_stats[");
416 .append(
", '"+item_.
path()+
"'"+stored_path+link_detail );
417 if( 0 == errno_res_ ) {
419 res.append(
", uid " ).append( uid_ );
422 res.append(
", gid " ).append( gid_ );
425 res.append(
", size " ).append( String.format(
"%,d", size_ ) );
428 res.append(
", btime " ).append( btime_.atZone(ZoneOffset.UTC) );
431 res.append(
", atime " ).append( atime_.atZone(ZoneOffset.UTC) );
434 res.append(
", ctime " ).append( ctime_.atZone(ZoneOffset.UTC) );
437 res.append(
", mtime " ).append( mtime_.atZone(ZoneOffset.UTC) );
441 res.append(
", errno " ).append( errno_res_ );
444 return res.toString();
Representing a directory item split into dirname() and basename().
boolean equals(final Object other)
String basename()
Return the basename, shall not be empty nor contain a dirname.
String dirname()
Returns the dirname, shall not be empty and denotes .
String path()
Returns a full unix path representation combining dirname() and basename().
Generic file type and POSIX protection mode bits as used in file_stats, touch(), mkdir() etc.
boolean isSet(final Bit bit)
boolean equals(final Object other)
FMode set(final Bit bit)
Sets the given bit and returns this instance for chaining.
boolean equals(final Object other)
boolean isSet(final Type bit)
Platform agnostic representation of POSIX ::lstat() and ::stat() for a given pathname.
boolean equals(final Object other)
int fd()
Returns the file descriptor if has_fd(), otherwise -1 for no file descriptor.
String path()
Returns the unix path representation.
Field fields()
Returns the retrieved field_t fields.
boolean is_file()
Returns true if entity is a file, might be in combination with is_link().
Instant mtime()
Returns the last modification time of this element since Unix Epoch.
FileStats(final DirItem item)
Instantiates a file_stats for the given dir_item.
Instant ctime()
Returns the last status change time of this element since Unix Epoch.
boolean ok()
Returns true if no error occurred.
boolean exists()
Returns true if entity does not exist, exclusive bit.
FileStats final_target(final long link_count[])
Returns the final target element, either a pointer to this instance if not a symbolic-link or the fin...
boolean has_access()
Returns true if entity gives no access to user, exclusive bit.
FMode prot_mode()
Returns the POSIX protection bit portion of fmode_t, i.e.
FileStats(final int fd)
Instantiates a file_stats for the given fd file descriptor.
int gid()
Returns the group id, owning the element.
boolean is_link()
Returns true if entity is a symbolic link, might be in combination with is_file(),...
String link_target_path()
Returns the stored link-target path this symbolic-link points to if instance is a symbolic-link,...
DirItem item()
Returns the dir_item.
FileStats link_target()
Returns the link-target this symbolic-link points to if instance is a symbolic-link,...
FileStats()
Instantiate an empty file_stats with fmode_t::not_existing set.
boolean is_fifo()
Returns true if entity is a fifo/pipe, might be in combination with is_link().
FMode mode()
Returns the FMode, file type and mode.
boolean is_socket()
Returns true if entity is a socket, might be in combination with is_link().
boolean has_fd()
Returns true if entity has a file descriptor.
Instant btime()
Returns the birth time of this element since Unix Epoch, i.e.
boolean is_block()
Returns true if entity is a block device, might be in combination with is_link().
boolean is_dir()
Returns true if entity is a directory, might be in combination with is_link().
Instant atime()
Returns the last access time of this element since Unix Epoch.
boolean has(final Field.Type bit)
Returns true if the given field_t fields were retrieved, otherwise false.
FMode type_mode()
Returns the type bit portion of fmode_t, i.e.
int uid()
Returns the user id, owning the element.
boolean is_char()
Returns true if entity is a character device, might be in combination with is_link().
int errno_res()
Returns the errno value occurred to produce this instance, or zero for no error.
long size()
Returns the size in bytes of this element if is_file(), otherwise zero.
FileStats(final String path)
Instantiates a file_stats for the given path.
file
Type: Entity is a file ), might be in combination with link.
protection_mask
12 bit protection bit mask 07777 for rwx_all | set_uid | set_gid | sticky .
dir
Type: Entity is a directory ), might be in combination with link.
not_existing
Type: Entity does not exist ), exclusive bit.
fifo
Type: Entity is a fifo/pipe ), might be in combination with link.
blk
Type: Entity is a block device ), might be in combination with link.
type_mask
Type mask for sock | blk | chr | fifo | dir | file | link | no_access | not_existing.
link
Type: Entity is a symbolic link ), might be in combination with file or dir ), fifo ),...
chr
Type: Entity is a character device ), might be in combination with link.
no_access
Type: Entity gives no access to user ), exclusive bit.
sock
Type: Entity is a socket, might be in combination with link.
mode
POSIX file protection mode bits.