Questions tagged [stat]

The stat(2) system call on POSIX systems. For statistics, use the statistics instead.

The stat(2) system call is used to retrieve information about a named file (or directory).

Links:

For statistics, use the tag instead.

829 questions
7
votes
1 answer

C++ stat.h incomplete type and cannot be defined

I am having a very strange issue with stat.h At the top of my code, I have declarations: #include #include And function prototype: int FileSize(string szFileName); Finally, the function itself is defined as…
user788171
  • 16,753
  • 40
  • 98
  • 125
7
votes
3 answers

flags for st_mode of stat system call

I'm trying to understand the flags for the st_mode field of the stat structure of that stat command, but I'm having such a hard time! I found this example here, but I really don't understand this code fragment: if ( mode & S_IRUSR ) str[1] = 'r'; …
Christian Wagner
  • 261
  • 3
  • 5
  • 7
7
votes
1 answer

What is a 'whiteout' (S_IFWHT) in Unix?

One of the possible file types that can be obtained using stat(2) is S_IFWHT, also called a whiteout. What is it?
GingerBadger
  • 312
  • 3
  • 12
7
votes
1 answer

How to set a file's ctime with Python?

How can I set a Unix file's ctime? (I'd much prefer an answer in terms of Python. If there's no way to do it with standard Python, then I suppose C is OK too.) (Note: I know that one can use os.utime to set a file's atime and mtime. I am…
kjo
  • 33,683
  • 52
  • 148
  • 265
7
votes
2 answers

golang os *File.Readdir using lstat on all files. Can it be optimised?

I am writing a program that finds all sub-directories from a parent directory which contains a huge number of files using os.File.Readdir, but running an strace to see the count of systemcalls showed that the go version is using an lstat() on all…
nohup
  • 3,105
  • 3
  • 27
  • 52
7
votes
3 answers

S_IFMT and S_IFREG undefined with -std=c11 or -std=gnu11

It's my first time working with posix; I included: #include #include #include And I've this snippet. stat(pathname, &sb); if ((sb.st_mode & S_IFMT) == S_IFREG) { /* Handle regular file */ } But using GCC…
6
votes
3 answers

C: Checking the type of a file. Using lstat() and macros doesn't work

I use opendir() to open a directory and then readdir() and lstat() to get the stats of each file in that directory. Following this manpage I wrote the code under which doesn't work as thought. It does list all the files in the current directory but…
Pithikos
  • 18,827
  • 15
  • 113
  • 136
6
votes
1 answer

How to use statx syscall?

Ubuntu 18.04 I'm trying to use statx syscall introduced in the Linux Kernel 4.11. There is a manual entry: #include #include #include #include /* Definition of AT_* constants */ int…
Some Name
  • 8,555
  • 5
  • 27
  • 77
6
votes
1 answer

How can I asyncio schedule a filesystem stat operation?

Converting some code to using asyncio, I'd like to give back control to the asyncio.BaseEventLoop as quickly as possible. This means to avoid blocking waits. Without asyncio I'd use os.stat() or pathlib.Path.stat() to obtain e.g. the filesize. Is…
cfi
  • 10,915
  • 8
  • 57
  • 103
6
votes
1 answer

Read proc stat information

Hello I require following information about process with some PID: name, ppid, state, #ofOpenFiles, #ofThreads I know the example of /proc/pid/stat file is like : 15 (watchdog/1) S 2 0 0 0 -1 69239104 0 0 0 0 0 69 0 0 -100 0 1 0 6 0 0…
Jonzi
  • 141
  • 1
  • 2
  • 13
6
votes
1 answer

how to calculate row means in a data frame?

I have a dataframe with 1000 columns and 8 rows, I need to calculate row means.I tried this loop: final <- as.data.frame(matrix(nrow=8,ncol=1)) for(j in 1:8){ value<- mean(dataframe[j,]) final[j,]<-value } but got the following error: In…
vahab
  • 297
  • 2
  • 3
  • 9
6
votes
3 answers

Convert size_t to string

I'm trying to write a TCP server which a client can use to browse the server's directories. In addition to that I want to send the size of the directory if that is a regular file. The size of the file is saved into a size_t variable under a "stat"…
6
votes
2 answers

How to flush nfs attribute cache?

I need to find a way to flush the NFS attribute cache on the client side. stat() call reads ctime from attribute cache and not the actual value, takes upto 3 second for the actual value to be reflected in cache. using 'noac' option when mounting…
ramgo
  • 184
  • 1
  • 3
  • 10
6
votes
3 answers

Using Python's stat function to efficiently get owner, group and other permissions

Question: How do I efficiently use the stat function to get meaningful file permissions (User, Group and Other). Details: I am querying the file permissions like so: statInfo = os.stat permissions = stat.S_IMODE ( os.stat ( 'fooBar.txt' ).st_mode…
puk
  • 16,318
  • 29
  • 119
  • 199
5
votes
1 answer

c program, warning message passing argument 1 of ‘fstat’ makes integer from pointer without a cast

I'm getting back into c after a long hiatus. Here's a little program I've written to output a files size. It compiles, and it works correctly, and it's pretty much copied and pasted from the man page. But it gives me an annoying warning from gcc.…
Bryan Hunt
  • 3,685
  • 2
  • 24
  • 36