stat

Issue with S_ISDIR() result in C (maybe because stat() isn't setting its struct properly?)

时光毁灭记忆、已成空白 提交于 2019-12-20 06:19:30
问题 I want my program to take a directory, then print the contents of that directory and state whether or not each item is a directory or not. If I give it a directory containing files F1.txt and F2.txt and folders D1, D2, and D3, it should print: F1.txt is not directory F2.txt is not directory D1 is directory D2 is directory D3 is directory char* curr[100]; DIR* dirp = opendir(name); struct dirent* x; struct stat fstat; //go to each file til readdir gives NULL while((x = readdir(dirp)) != NULL)

stat() giving wrong directory size in c

强颜欢笑 提交于 2019-12-20 02:16:05
问题 I need to find the size of a file or a directory whatever given in the commandline using stat(). It works fine for the files (both relative and absolute paths) but when I give a directory, it always returns the size as 512 or 1024. If I print the files in the directory it goes as follows : Name : . Name : .. Name : new Name : new.c but only the new and new.c files are actually in there. For this, the size is returned as 512 even if I place more files in the directory. Here s my code fragment:

Counting hard links to a file in Go

我只是一个虾纸丫 提交于 2019-12-19 03:37:03
问题 According to the man page for FileInfo, the following information is available when stat() ing a file in Go: type FileInfo interface { Name() string // base name of the file Size() int64 // length in bytes for regular files; system-dependent for others Mode() FileMode // file mode bits ModTime() time.Time // modification time IsDir() bool // abbreviation for Mode().IsDir() Sys() interface{} // underlying data source (can return nil) } How can I retrieve the number of hard links to a specific

《APUE》第四章笔记(1)

强颜欢笑 提交于 2019-12-19 01:25:23
1.引言 本章介绍文件系统的特征和文件的性质。从stat函数开始,逐个说明stat结构的每一个成员以了解文件的所有属性。在此过程中,还将会说明修改这些属性的各个函数,并更详细地查看UNIX文件系统的结构和符号连接,最后还介绍对目录进行操作的各个函数。 大概就是介绍以下几点: 1.stat函数和stat结构的每一个成员(这些都是文件的属性)。 2.修改每个属性的对应函数。(比如修改文件权限的chmod函数)。 3.UNIX文件系统的结构和符号链接 4.对目录进行操作的各个函数。 先介绍3个stat函数: #include <sys/stat.h> int stat(const char *pathname, struct stat *buf); //一旦给出pathname,stat函数就返回与此命名文件有关的信息结构 int fstat(int fd, struct stat *buf); //而fstat则获取文件描述符fd来打开文件信息 int lstat(const char *pathname, struct stat *buf); //lstat函数则类似stat,但当pathname是符号链接的时候,就返回符号连接的有关信息而不是文件信息(符号链接会在以后介绍) 第二个参数buf是指针,它指向一个由我们提供的stat结构,而这些函数呢就将信息写进stat结构中。

Get file size with stat syscall

…衆ロ難τιáo~ 提交于 2019-12-18 18:07:22
问题 I'm trying to get file size wit stat syscall with assembly (nasm): section .data encodeFile db "/home/user/file" section .bss stat resb 64 struc STAT .st_dev: resd 1 .st_ino: resd 1 .st_mode: resw 1 .st_nlink: resw 1 .st_uid: resw 1 .st_gid: resw 1 .st_rdev: resd 1 .st_size: resd 1 .st_atime: resd 1 .st_mtime: resd 1 .st_ctime: resd 1 .st_blksize: resd 1 .st_blocks: resd 1 endstruc _start: mov rax, 4 mov rdi, encodeFile mov rsi, stat syscall mov eax, dword [stat + STAT.st_size] There is 0 in

File stat() vs access() to check permissions on a directory

♀尐吖头ヾ 提交于 2019-12-18 15:54:37
问题 I have successfully used both stat() & access() separately to determine if a user has either read or read/write access to a directory. My question is: - Is there a preferred method ? I see a lot of examples using stat , but for my purpose, access seems to be more lightweight and serves purpose. - Are there any issues (e.g. - security) w/ one or the other ? - Any issues w/ my approach ? Here is some pseudo code (re-creating from memory w/o compiling) : // Using access(): bool

From stat().st_mtime to datetime?

99封情书 提交于 2019-12-18 01:29:11
问题 What is the most idiomatic/efficient way to convert from a modification time retrieved from stat() call to a datetime object? I came up with the following (python3): from datetime import datetime, timedelta, timezone from pathlib import Path path = Path('foo') path.touch() statResult = path.stat() epoch = datetime(1970, 1, 1, tzinfo=timezone.utc) modified = epoch + timedelta(seconds=statResult.st_mtime) print('modified', modified) Seems round a bout, and a bit surprising that I have to hard

How to use S_ISREG() and S_ISDIR() POSIX Macros?

为君一笑 提交于 2019-12-17 09:45:56
问题 This is a C program I wrote to recursively navigate and output directories and regular files. It compiles and runs fine on my Linux machine. But on Solaris, the dit->d_type == 8 check and the other similar ones don't work because there is no d_type field. An answer I've read to this problem is to use the S_ISREG() and S_ISDIR() macros, but they don't work at all the way I have them in my code currently. I commented out the lines that work on my Linux machine. #include <sys/types.h> #include

DB time实时过程分析

送分小仙女□ 提交于 2019-12-17 03:39:24
在我们查看awr报告的时候总是会有一个关键指标需要注意,那就是DB time,这个指标一般都是通过awr报告来看到的。 比如我们得到的awr报告头部显示的下面的信息,我们就清楚的知道DB time是1502.06 mins,相对于Elapsed time来说,将近有20倍的压力。这个问题肯定需要关注。 Snap Id Snap Time Sessions Curs/Sess --------- ------------------- -------- --------- Begin Snap: 6219 21-Jul-15 22:00:08 583 2.5 End Snap: 6220 21-Jul-15 23:00:44 639 2.4 Elapsed: 60.61 (mins) DB Time: 1,502.06 (mins) 当然我们也不大可能一下子生成几十个awr报告,然后就为了得到这个DB time值。 在之前的博客中也分享过如何来结合shell脚本抓取数据库的负载信息。 http://blog.itpub.net/23718752/viewspace-1168027/ 比如得到的结果如下: DB_NAME BEGIN_SNAP END_SNAP SNAPDATE LVL DURATION_MINS DBTIME --------- ---------- --------

Memcached常用指令

你。 提交于 2019-12-16 23:17:53
博文大纲: 一、存储常用的指令 1.set指令 2.add指令 3.replace指令 4.append指令 5.prepend指令 6.cas指令 二、常用的查找指令 1.get指令 2.gets指令 3.delete指令 4.incr指令 5.decr指令 6.stats指令 7.stats items指令 8.stats slabs指令 9.stats sizes指令 10.flush_all指令 一、存储常用的指令 常用的存储数据的指令有: set 命令是保存一个叫做 key 的数据到服务器上; add 命令是添加一个数据到服务器,但是服务器必须保证这个 key 是不存在的,能够保证数据不会被覆盖; replace 命令是替换一个已经存在的数据,如果数据不存在,就是类似 set 功能; 上述指令的语法格式都是一样的,只是指令不一样而已,语法如下: <命令> <键> <标记> <有效期> <数据长度> 各个参数含义如下: <命令>:就是add、set、replace等指令; <键> - key:就是保存在服务器上唯一的一个标识符,不可以与其他的key冲突,否则会覆盖掉原来的数据(使用set命令的话),这个key是为了能够准确的存取一个数据项目; <标记> - flag:标记的是一个16位的无符号整型数据,用来设置服务器跟客户端一些交互的操作; <有效期>