_stat怎么用?如何定义?谢谢!在线等

来源:学生作业帮助网 编辑:作业帮 时间:2024/10/04 03:53:41
_stat怎么用?如何定义?谢谢!在线等
xX}oF* VIӴR-S4A7^m Y}qN$„hte`loA T2qRŞ;۱ϱ,D|ww5)Vֹ.4Wno7>]{.>l^m?+[}c\Ϳrlݼ|o5$$?q_ZWF[ Qֽ*)Rjgll [i%reQ3Aj:1"Fu Q-C"ZN0ߋb0UؙF|Tv* ׋EC}(ğV2[aaDhñQ;( ٳzN6BYCch0ͤC{vVdQ'"}0+P}#g<FtTEhX6l GTJl\;%m@/\3SL2J̤)k.{<24 :`BԘ!Y3Eg, ïAݣR0v_oFȶ?܃nڷp}EErsuaha Yo@+#_|<߾sw /2`K9t_j OM4WlpeF ' aQF3)}fhv5+A?ﴢ AAln7q/nYkjmnk~keV(X[޹~t2Zs/>o:$vUPԾ,&꾽5b3x0~Ò DjuSNJ푴EȞm`CeتD/yCs8 AHQ^Va5u<aA;:hn e6@i!΄K=%t1(z|YA|28DAZCq0):#0"2F"ĬTB/NYᘅ .ezQ|JQ5 P= u@*D&Mji'ېxOE JIE@%('eoga(ǣZ_ƺw<"\?P6LDTah"}OWkW]";jוJWA/mF7,PF HvbNq6D=Q\3 ٪K붧s>6}iFT<iEjCI|*㜗G=R<7 d@rh2E$u [ !CC`MXմDو BBjCUwl<ӕ [kZa6.'0lpD nfP?Pܻ N1 W@ 怘Dً~]ž~8Bu #5T  q jE :0y`s3`ovٸ S8{dH!}\j/V̎)|i^$`!YM=%TbJQuQ~H9a'~ㄑBMMTfjXwP_?J1zVjkUZz1EQ1zG߼h9&XWn8T#YL[ƑS^щǏ12IW\#9t61P7,2ՉoWJҷ#aiA1b]nrUY=GwɷG\$Eub;]szXtJX7C^>ȷd}F(ܑb Z^WSQ}cnm1)| #EvM?&

_stat怎么用?如何定义?谢谢!在线等
_stat怎么用?如何定义?谢谢!在线等

_stat怎么用?如何定义?谢谢!在线等
stat() -- 获取文件大小
2007年12月26日 星期三 16:19
#include
#include //exit()
#include //strerror()
#include //errno
#include //stat()
#include
int main(int argc, char * argv[])
{
char *filename;
struct stat buf;
if (argc != 2) {
printf("Please input filename\n");
exit(-1);
}
filename = argv[1];
if (stat(filename, &buf) < 0) {
printf("Mesg: %s\n", strerror(errno));
exit(-1);
}
printf("%s's size is %-4d bytes\n", filename, buf.st_size);
printf("%s's t_blksize is %-4d bytes\n", filename, buf.st_blksize);
printf("%s's blocks is %-4d blocks\n", filename, buf.st_blocks);
}
----------------------------------------------------
$ gcc test.c
$ ./a.out zengxiaolong
zengxiaolong's size is 13 bytes
zengxiaolong's t_blksize is 4096 bytes
zengxiaolong's blocks is 8 blocks
注: 文件zengxiaolong的实际内容为13个字节,占用4KB大小的磁盘空间(1 blocks -- 一块为4KB)
stat, fstat, lstat - get file status
----------------------------------------------------
#include
#include
#include
int stat (const char *path, struct stat *buf);
int fstat(int filedes, struct stat *buf);
int lstat(const char *path, struct stat *buf);
lstat函数与stat类似,但是当文件是一个符号连接时,lstat返回该符号连接的有关信息,而不是由该符号连接引用的文件的信息.
struct--stat
----------------------------------------------------
struct stat {
mode_t st_mode; // file type & mode(permissions)
ino_t st_ino; // i-node number(serial number)
dev_t st_dev; // device number(filesystem)
dev_t st_rdev; // device number for specials files
nlink_t st_nlink; // number of links
uid_t st_uid; // user ID of owner
gid_t st_gid; // group ID of owner
off_t st_size; // size in bytes, for regular files
time_t st_atime; // time of last access
time_t st_mtime; // time of last modification
time_t st_ctime; // time of last file status change
long st_blksize; // best I/O block size
long st_blocks; -// number of 512-byte blocks allocated
};
struct--inode
----------------------------------------------------
/usr/src/linux/include/linux/fs.h
struct inode {
struct hlist_node -----------i_hash;
struct list_head ------------i_list;
struct list_head ------------i_sb_list;
struct list_head ----------i_dentry;
unsigned long ----------i_ino;
atomic_t ----------i_count;
umode_t --------------i_mode;
unsigned int i_nlink;
uid_t --------------i_uid;
gid_t --------------i_gid;
dev_t ------------ --i_rdev;
loff_t -------------- i_size;
struct timespec i_atime;
struct timespec ----------i_mtime;
struct timespec ----------i_ctime;
unsigned int ----------i_blkbits;
unsigned long ------------i_version;
blkcnt_t --------------i_blocks;
unsigned short --------------i_bytes;
spinlock_t ----------i_lock;
struct mutex i_mutex;
struct rw_semaphore i_alloc_sem;
struct inode_operations *i_op;
const struct file_operations *i_fop;
struct super_block *i_sb;
struct file_lock *i_flock;
struct address_space *i_mapping;
struct address_space i_data;
#ifdef CONFIG_QUOTA
struct dquot *i_dquot[MAXQUOTAS];
#endif
struct list_head i_devices;
union {
struct pipe_inode_info *i_pipe;
struct block_device *i_bdev;
struct cdev *i_cdev;
};
int i_cindex;
__u32 i_generation;
#ifdef CONFIG_DNOTIFY
unsigned long i_dnotify_mask;
struct dnotify_struct *i_dnotify;
#endif

#ifdef CONFIG_INOTIFY
struct list_head inotify_watches;
struct mutex inotify_mutex;
#endif
unsigned long i_state;
unsigned long dirtied_when;
unsigned int i_flags;
atomic_t i_writecount;
#ifdef CONFIG_SECURITY
void *i_security;
#endif
void *i_private;
#ifdef __NEED_I_SIZE_ORDERED
seqcount_t i_size_seqcount;
#endif
};
struct--stat
----------------------------------------------------
/usr/src/linux/include/asm-i386/stat.h
struct stat {
unsigned long --st_dev;
unsigned long --st_ino;
unsigned short -st_mode;
unsigned short -st_nlink;
unsigned short -st_uid;
unsigned short -st_gid;
unsigned long --st_rdev;
unsigned long --st_size;
unsigned long --st_blksize;
unsigned long --st_blocks;
unsigned long --st_atime;
unsigned long --st_atime_nsec;
unsigned long --st_mtime;
unsigned long --st_mtime_nsec;
unsigned long --st_ctime;
unsigned long --st_ctime_nsec;
unsigned long --__unused4;
unsigned long --__unused5;
};