Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F3960310
d_off.c
jack_gandi.net
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
jack_gandi.net
Nov 9 2018, 10:07 AM
2018-11-09 10:07:26 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
d_off.c
View Options
#include
<dirent.h>
// struct dirent, DT_*
/* #include "/usr/src/sys/sys/dirent.h" // struct dirent, DT_* */
#include
<fcntl.h>
// O_*
#include
<stdio.h>
// printf
#include
<stdlib.h>
// EXIT_*
#include
<sys/stat.h>
// uint*_t
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)
#define BUF_SIZE sizeof(struct dirent)
#define BUF_SIZE 72
int
main
(
int
argc
,
char
*
argv
[])
{
int
fd
,
nread
;
char
buf
[
BUF_SIZE
];
struct
dirent
*
d
;
int
bpos
;
char
d_type
;
off_t
offset
,
start
,
before
,
after
;
fd
=
open
(
argc
>
1
?
argv
[
1
]
:
"."
,
O_RDONLY
|
O_DIRECTORY
);
if
(
fd
==
-1
)
handle_error
(
"open"
);
/*
* replace start with an offset to check for correctness
*/
start
=
0x0
;
lseek
(
fd
,
start
,
SEEK_SET
);
printf
(
"BUF_SIZE=%lu
\n
"
,
BUF_SIZE
);
printf
(
" inode# file type d_reclen d_namlen d_off lbefore lafter d_name
\n
"
);
for
(
;
;
)
{
before
=
lseek
(
fd
,
0x0
,
SEEK_CUR
);
nread
=
getdirentries
(
fd
,
buf
,
BUF_SIZE
,
&
offset
);
after
=
lseek
(
fd
,
0x0
,
SEEK_CUR
);
printf
(
"---------read=%d---- %#lx->%#lx
\n
"
,
nread
,
before
,
after
);
if
(
nread
==
-1
)
handle_error
(
"getdents"
);
if
(
nread
==
0
)
break
;
for
(
bpos
=
0
;
bpos
<
nread
;)
{
d
=
(
struct
dirent
*
)
(
buf
+
bpos
);
int
ok
=
after
==
d
->
d_off
;
printf
(
"%-6s "
,
ok
?
"OK"
:
"BROKEN"
);
printf
(
"%10lu"
,
d
->
d_ino
);
//d_type = *(buf + bpos + d->d_reclen - 1);
d_type
=
d
->
d_type
;
printf
(
" %-10s"
,
(
d_type
==
DT_REG
)
?
"regular"
:
(
d_type
==
DT_DIR
)
?
"directory"
:
(
d_type
==
DT_FIFO
)
?
"FIFO"
:
(
d_type
==
DT_SOCK
)
?
"socket"
:
(
d_type
==
DT_LNK
)
?
"symlink"
:
(
d_type
==
DT_BLK
)
?
"block dev"
:
(
d_type
==
DT_CHR
)
?
"char dev"
:
"???"
);
printf
(
" %4d"
,
d
->
d_reclen
);
printf
(
" %4d"
,
d
->
d_namlen
);
printf
(
" %#10llx"
,
(
long
long
)
d
->
d_off
);
printf
(
" %#10llx"
,
(
long
long
)
before
);
printf
(
" %#10llx"
,
(
long
long
)
after
);
printf
(
" %s
\n
"
,
d
->
d_name
);
bpos
+=
d
->
d_reclen
;
}
}
exit
(
EXIT_SUCCESS
);
}
File Metadata
Details
Attached
Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1634830
Default Alt Text
d_off.c (1 KB)
Attached To
Mode
D17917: d_off support for multiple filesystems
Attached
Detach File
Event Timeline
Log In to Comment