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
|
'\" t
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
.\" Parts Copyright (c) 1995 Nicolai Langfeldt (janl@ifi.uio.no), 1/1/95
.\" and Copyright (c) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Modified by Michael Haardt <michael@moria.de>
.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
.\" Modified 1995-05-18 by Todd Larason <jtl@molehill.org>
.\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
.\" Modified 1995-01-09 by Richard Kettlewell <richard@greenend.org.uk>
.\" Modified 1998-05-13 by Michael Haardt <michael@cantor.informatik.rwth-aachen.de>
.\" Modified 1999-07-06 by aeb & Albert Cahalan
.\" Modified 2000-01-07 by aeb
.\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
.\" 2007-06-08 mtk: Added example program
.\" 2007-07-05 mtk: Added details on underlying system call interfaces
.\"
.\" Japanese Version Copyright (c) 1998-1999 HANATAKA Shinya
.\" all rights reserved.
.\" Translated 1998-06-21, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\" Modified 1999-04-16, HANATAKA Shinya
.\" Updated 2000-01-03, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2000-10-06, Kentaro Shirakata
.\" Updated 2001-04-09, Kentaro Shirakata
.\" Updated 2001-06-25, Kentaro Shirakata
.\" Updated 2005-02-28, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\" Updated 2005-09-06, Akihiro MOTOKI
.\" Updated 2005-11-19, Akihiro MOTOKI, catch up to LDP v2.14
.\" Updated 2006-07-21, Akihiro MOTOKI, LDP v2.36
.\" Updated 2007-06-13, Akihiro MOTOKI, LDP v2.55
.\"
.\"WORD: status
.\"WORD: directory ǥ쥯ȥ
.\"WORD: open ץ
.\"WORD: implement
.\"WORD: owner ͭ
.\"WORD: group 롼
.\"WORD: user 桼
.\"WORD: other ¾
.\"WORD: hard link count ϡɡ
.\"WORD: symbolic link ܥå
.\"WORD: socket å
.\"WORD: device ǥХ
.\"WORD: sticky bit ƥåӥå
.\"WORD: mandatory locking å
.\"
.TH STAT 2 2007-07-26 "Linux" "Linux Programmer's Manual"
.SH ̾
stat, fstat, lstat \- եξ֤
.SH
.B #include <sys/types.h>
.br
.B #include <sys/stat.h>
.br
.B #include <unistd.h>
.sp
.BI "int stat(const char *" path ", struct stat *" buf );
.br
.BI "int fstat(int " fd ", struct stat *" buf );
.br
.BI "int lstat(const char *" path ", struct stat *" buf );
.sp
.in -4n
glibc εǽޥ
.RB ( feature_test_macros (7)
):
.in
.sp
.BR lstat ():
_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
.SH
.PP
δؿϥեˤĤƤξ֤
ե뤽ΤΤФ륢ĤɬפȤʤ
\(em
.BR stat ()
.BR lstat ()
ξˤ
\(em
Υեػ
.I path
ƤΥǥ쥯ȥФ¹ () ĤɬפǤ롣
.PP
.BR stat ()
.I path
ǻꤵ줿եξ֤
.I buf
سǼ롣
.BR lstat ()
.BR stat ()
ƱǤ뤬
.I path
ܥåξ硢ȤƤեǤϤʤ
Ȥξ֤ۤʤ롣
.BR fstat ()
.BR stat ()
Ʊ
֤եե롦ǥץ
.I fd
ǻꤹ롣
.PP
ΥƥॳϤ⡢̤
.I stat
¤Τ֤
.I stat
¤ΤˤϰʲΥեɤޤޤƤ:
.PP
.in +4n
.nf
struct stat {
dev_t st_dev; /* ե뤬ǥХ ID */
ino_t st_ino; /* inode ֹ */
mode_t st_mode; /* ݸ */
nlink_t st_nlink; /* ϡɥο */
uid_t st_uid; /* ͭԤΥ桼 ID */
gid_t st_gid; /* ͭԤΥ롼 ID */
dev_t st_rdev; /* ǥХ ID (üեξ) */
off_t st_size; /* ΤΥ (Хñ) */
blksize_t st_blksize; /* ե륷ƥ I/O Ǥ
֥å */
blkcnt_t st_blocks; /* Ƥ줿֥å */
time_t st_atime; /* ǽ */
time_t st_mtime; /* ǽ */
time_t st_ctime; /* ǽѹ */
};
.fi
.in
.PP
.I st_dev
եɤϡΥե뤬¸ߤǥХ
.I st_rdev
եɤϡΥե (inode) ɽǥХ
.I st_size
եɤϡ(̾Υե뤫ܥåξ)
ե礭Хñ̤Ǽ
ܥå礭ϡܥå˴ޤޤƤ
ѥ̾Ĺ (Ǹ NULL ХȤϴޤޤʤ) Ǥ롣
.I st_blocks
եɤϡե礭 512 ХȤΥ֥åñ̤Ǽ
եɤϡե˳Ƥ줿֥å 512 Хñ̤Ǽ
(ե˷꤬褦ʾ硢ͤ
.IR st_size /512
꾮ʤ뤳Ȥ⤢)
.I st_blksize
եɤϡΨŪ˥ե롦ƥ I/O Ǥֹޤ
֥å (äȾñ̤ǥե˽ߤԤȡ
ɤ߽Ф----ƽߤȤäΨưˤʤäƤޤ⤷ʤ)
.PP
Ƥ Linux Υե롦ƥबƤλ֥եɤ
Ƥ櫓ǤϤʤ
ե륢
.I st_atime
եɤʤ褦ʤǥޥȤǤե륷ƥ⤢롣
.RB ( mount (8)
"noatime" ץ)
.I st_atime
եɤϥե륢äѹ
(㤨С
.BR execve (2),
.BR mknod (2),
.BR pipe (2),
.BR utime (2)
Ѥ
.BR read (2)
1 ХȰʾɤ߹ʤ)
.BR mmap (2)
ʤɤ¾Υ롼Ǥϡ
.I st_atime
Ϲ뤳Ȥ⤢СǤʤ⤢롣
.I st_mtime
եɤϡե뤬줿ѹ
(㤨С
.BR mknod (2),
.BR truncate (2),
.BR utime (2)
Ѥ
.BR write (2)
1 ХȰʾߤʤ)
ˡǥ쥯ȥ
.I st_mtime
ϡΥǥ쥯ȥ
ե뤬줿줿ꤹѹ롣
.I st_mtime
եɤ
ͭԤ䥰롼פϡɡ⡼ɤѹǤѹ
.I ʤ
.I st_ctime
եɤϽߤ inode
(ͭԡ롼ס⡼ɤʤ)
ˤäѹ롣
.PP
ʲ POSIX ޥϡ
.I st_mode
ե
ǻѤե̤ΥåΤƤ :
.RS 4
.TP 1.2i
.BR S_ISREG (m)
̾Υե뤫?
.TP
.BR S_ISDIR (m)
ǥ쥯ȥ꤫?
.TP
.BR S_ISCHR (m)
饯ǥХ?
.TP
.BR S_ISBLK (m)
֥åǥХ?
.TP
.BR S_ISFIFO (m)
FIFO (̾դѥ) ?
.TP
.BR S_ISLNK (m)
ܥå? (POSIX.1-1996 ˤϤʤ)
.TP
.BR S_ISSOCK (m)
åȤ? (POSIX.1-1996 ˤϤʤ)
.RE
.PP
ʲΥե饰
.I st_mode
եѤƤ:
.in +4n
.TS
lB l l.
S_IFMT 0170000 ե̤ӥåΰɽӥåȥޥ
S_IFSOCK 0140000 å
S_IFLNK 0120000 ܥå
S_IFREG 0100000 ̾Υե
S_IFBLK 0060000 ֥åǥХ
S_IFDIR 0040000 ǥ쥯ȥ
S_IFCHR 0020000 饯ǥХ
S_IFIFO 0010000 FIFO
S_ISUID 0004000 set-user-ID bit
S_ISGID 0002000 set-group-ID bit ()
S_ISVTX 0001000 ƥåӥå ()
S_IRWXU 00700 եͭԤΥѤΥӥåȥޥ
S_IRUSR 00400 ͭԤɤ߹ߵ
S_IWUSR 00200 ͭԤνߵ
S_IXUSR 00100 ͭԤμ¹Ե
S_IRWXG 00070 롼פΥѤΥӥåȥޥ
S_IRGRP 00040 롼פɤ߹ߵ
S_IWGRP 00020 롼פνߵ
S_IXGRP 00010 롼פμ¹Ե
S_IRWXO 00007 ¾ (others) ΥѤΥӥåȥޥ
S_IROTH 00004 ¾ͤɤ߹ߵ
S_IWOTH 00002 ¾ͤνߵ
S_IXOTH 00001 ¾ͤμ¹Ե
.TE
.in
.P
set-group-ID bit
.RB ( S_ISGID )
ˤϤĤüʻˡ:
ǥ쥯ȥꤷˤϡΥǥ쥯ȥ꤬ BSD ǻѤ
ȤĤޤꡢΥǥ쥯ȥ˺줿եΥ롼ID
ץμ¸ (effective) 롼ID ǤϤʤǥ쥯ȥ
롼ID Ѿ롣ޤΥǥ쥯ȥ˺줿ǥ쥯ȥˤ
.B S_ISGID
ӥåȤꤵ롣롼¹ԥӥå
.RB ( S_IXGRP )
ꤵƤʤեꤵ줿ϡ
set-group-ID ӥåȤϥե/쥳ɤ
Ū (mandatory) åɽ
.P
ǥ쥯ȥ˥ƥåӥå (S_ISVTX) ꤵ줿ϡ
Υǥ쥯ȥΥե̾ѹꡢǤΤϡ
ΥեνͭԤΥǥ쥯ȥνͭԤøץ
Ȥʤ롣
.SH ֤
0 ֤顼ξ \-1 ֤
.I errno
Ŭڤͤꤵ롣
.SH 顼
.TP
.B EACCES
.I path
°ǥ쥯ȥȤξ̤Υǥ쥯ȥΤ줫
Ф븡Ĥʤä
.RB ( path_resolution (7)
⻲ȤΤ)
.TP
.B EBADF
.I fd
Ǥ롣
.TP
.B EFAULT
ɥ쥹ְäƤ롣
.TP
.B ELOOP
ѥéݤ˲褹٤ܥå¿
.TP
.B ENAMETOOLONG
ե̾Ĺ롣
.TP
.B ENOENT
ѥ
.I path
ιǤ¸ߤʤѥ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 XPG2 Ǥ 0 0100000
ξ̤Υե
1000 S_IFIFO p| 010000 FIFO (̾դѥ)
2000 S_IFCHR c 020000 饯üե (V7)
3000 S_IFMPC 030000 ¿Ų줿饯üե (V7)
4000 S_IFDIR d/ 040000 ǥ쥯ȥ (V7)
5000 S_IFNAM 050000 XENIX Ĥ̾դ
üե
\fIst_rdev\fP 1,2 Ƕ̤:
0001 S_INSEM s 000001 XENIX IFNAMΥޥե
0002 S_INSHD m 000002 XENIX IFNAMζͭǡ
6000 S_IFBLK b 060000 ֥åüե (V7)
7000 S_IFMPB 070000 ¿Ų줿֥åüե (V7)
8000 S_IFREG - 100000 ̾ե (V7)
9000 S_IFCMP 110000 VxFS ̥ե
9000 S_IFNWK n 110000 ͥåȥüե (HP-UX)
a000 S_IFLNK l@ 120000 ܥå (BSD)
b000 S_IFSHAD 130000 Solaris ACL Τα줿 inode
(桼֤ϸʤ)
c000 S_IFSOCK s= 140000 å (BSD; VxFS "S_IFSOC")
d000 S_IFDOOR D> 150000 Solaris ɥե
e000 S_IFWHT w% 160000 BSD ե (inode Ѥʤ)
0200 S_ISVTX 001000 `ƥåӥå':Ѹ
åפ˻Ĥ (V7)
ͽ (SVID-v2)
ǥ쥯ȥʳ: եå
ʤ (SunOS)
ǥ쥯ȥ: ¥ե饰 (SVID-v4.2)
0400 S_ISGID 002000 ¹Ի set-group-ID (V7)
ǥ쥯ȥФƤ GID ã
BSD Ѥ
0400 S_ENFMT 002000 SysV ե롦å
(S_ISGID ȶͭ)
0800 S_ISUID 004000 ¹Ի set-user-ID (V7)
0800 S_CDF 004000 ǥ쥯ȥ꤬¸ե (HP-UX)
.TE
ƥå ޥɤ Version 32V AT&T UNIX о줷
.SH
.SS Linux Ǥ
ͥ 2.5.48 ʹߤǤϡ
.I stat
¤Τ 3ĤΥեΥॹ״ϢΥեɤ
ʥñ̤٤бƤ롣
glibc ǤϡƥեɤΥʥäξ
.I st_atim.tv_nsec
.I st_atimensec
ȤäǻȤǤ롣
ǽޥ
.B _BSD_SOURCE
.B _SVID_SOURCE
Ƥˤ
.I st_atim.tv_nsec
ηǡʳξˤ
.I st_atimensec
ηȤʤ롣
ä٤ॹפݡȤƤʤե륷ƥǤϡ
ΥʥäΥեɤ 0 ꤵ롣
.I /proc
ǥ쥯ȥʲˤեΤۤȤɤǤϡ
.BR stat ()
ƤӽФݤˡ
.I st_size
եɤ˥ե륵֤ʤ
.I st_size
եɤˤ 0 ֤롣
.SS ظΥͥ롦ե
֤ηвȤȤˡ
.I stat
¤ΤΥ礭ʤꡢαƶ
.BR stat ()
ˤ 3ĤΥС¸ߤ:
.IR sys_stat ()
(åȤ
.IR __NR_oldstat )
.IR sys_newstat ()
(åȤ
.IR __NR_stat )
.IR sys_stat64 ()
(ͥ 2.4 Ƴ; åȤ
.IR __NR_stat64 ).
glibc
.BR stat ()
åѡؿϤξܺ٤ץꥱ鱣äƤ롣
Ūˤϡͥ뤬Ƥ륷ƥॳΤǿΥС
ưŤХʥξˤɬפ˱֤줿ƹ (repack) 롣
.BR fstat ()
.BR lstat ()
ˤĤƤƱͤǤ롣
.\"
.\" A note from Andries Brouwer, July 2007
.\"
.\" > Is the story not rather more complicated for some calls like
.\" > stat(2)?
.\"
.\" Yes and no, mostly no. See /usr/include/sys/stat.h .
.\"
.\" The idea is here not so much that syscalls change, but that
.\" the definitions of struct stat and of the types dev_t and mode_t change.
.\" This means that libc (even if it does not call the kernel
.\" but only calls some internal function) must know what the
.\" format of dev_t or of struct stat is.
.\" The communication between the application and libc goes via
.\" the include file <sys/stat.h> that defines a _STAT_VER and
.\" _MKNOD_VER describing the layout of the data that user space
.\" uses. Each (almost each) occurrence of stat() is replaced by
.\" an occurrence of xstat() where the first parameter of xstat()
.\" is this version number _STAT_VER.
.\"
.\" Now, also the definitions used by the kernel change.
.\" But glibc copes with this in the standard way, and the
.\" struct stat as returned by the kernel is repacked into
.\" the struct stat as expected by the application.
.\" Thus, _STAT_VER and this setup cater for the application-libc
.\" interface, rather than the libc-kernel interface.
.\"
.\" (Note that the details depend on gcc being used as c compiler.)
.SH
ʲΥץ
.BR stat ()
ƤӽФ֤äƤ
.I stat
¤ΤΥեɤΤĤɽ롣
.nf
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
struct stat sb;
if (argc != 2) {
fprintf(stderr, "Usage: %s <pathname>\\n", argv[0]);
exit(EXIT_FAILURE);
}
if (stat(argv[1], &sb) == \-1) {
perror("stat");
exit(EXIT_SUCCESS);
}
printf("File type: ");
switch (sb.st_mode & S_IFMT) {
case S_IFBLK: printf("block device\\n"); break;
case S_IFCHR: printf("character device\\n"); break;
case S_IFDIR: printf("directory\\n"); break;
case S_IFIFO: printf("FIFO/pipe\\n"); break;
case S_IFLNK: printf("symlink\\n"); break;
case S_IFREG: printf("regular file\\n"); break;
case S_IFSOCK: printf("socket\\n"); break;
default: printf("unknown?\\n"); break;
}
printf("I\-node number: %ld\\n", (long) sb.st_ino);
printf("Mode: %lo (octal)\\n",
(unsigned long) sb.st_mode);
printf("Link count: %ld\\n", (long) sb.st_nlink);
printf("Ownership: UID=%ld GID=%ld\\n",
(long) sb.st_uid, (long) sb.st_gid);
printf("Preferred I/O block size: %ld bytes\\n",
(long) sb.st_blksize);
printf("File size: %lld bytes\\n",
(long long) sb.st_size);
printf("Blocks allocated: %lld\\n",
(long long) sb.st_blocks);
printf("Last inode change: %s", ctime(&sb.st_ctime));
printf("Last file access: %s", ctime(&sb.st_atime));
printf("Last file modification: %s", ctime(&sb.st_mtime));
exit(EXIT_SUCCESS);
}
.fi
.SH Ϣ
.BR access (2),
.BR chmod (2),
.BR chown (2),
.BR fstatat (2),
.BR readlink (2),
.BR utime (2),
.BR capabilities (7)
|