File: stat.c

package info (click to toggle)
ibcs 971113-3
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,108 kB
  • ctags: 2,061
  • sloc: ansic: 14,910; makefile: 280; sh: 203; asm: 47; perl: 18; pascal: 2
file content (148 lines) | stat: -rw-r--r-- 3,528 bytes parent folder | download | duplicates (2)
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
/*
 *  linux/ibcs/stat.c
 *
 *  Copyright (C) 1991, 1992  Linus Torvalds
 *
 *  Hacked by Eric Youngdale for iBCS.
 *  Added to by Drew Sullivan.
 *
 * $Id: stat.c,v 1.12 1997/05/12 23:13:40 jaggy Exp $
 * $Source: /usr/CVS/ibcs/iBCSemul/stat.c,v $
 */
#define __KERNEL__ 1

#include <linux/config.h>

#include <linux/module.h>
#include <linux/version.h>

#include <asm/segment.h>
#ifndef KERNEL_DS
#include <linux/segment.h>
#endif

#include <linux/errno.h>
#include <linux/stat.h>
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/mm.h>

#include <ibcs/ibcs.h>


#ifdef __sparc__
static void cp_ibcs_stat(struct inode * inode, struct ibcs_stat * statbuf)
{
	struct ibcs_stat tmp;

	memset ((void *) &tmp, 0, sizeof (tmp));
	tmp.st_dev = inode->i_dev;
	tmp.st_ino = inode->i_ino;
	tmp.st_mode = inode->i_mode;
	tmp.st_nlink = inode->i_nlink;
	tmp.st_uid = inode->i_uid;
	tmp.st_gid = inode->i_gid;
	tmp.st_rdev = inode->i_rdev;
	tmp.st_size = inode->i_size;
	tmp.st_atime.tv_sec = inode->i_atime;
	tmp.st_mtime.tv_sec = inode->i_mtime;
	tmp.st_ctime.tv_sec = inode->i_ctime;
	tmp.st_blksize = inode->i_blksize;
	tmp.st_blocks  = inode->i_blocks;
	memcpy_tofs(statbuf,&tmp,sizeof(tmp));
}

#else /* if not sparc... */

/*
 * Believe it or not, the original stat structure is compatible with ibcs2.
 * The xstat struct used by SVr4 is different than our new struct, but we will
 * deal with that later
 */
static void cp_ibcs_stat(struct inode * inode, struct ibcs_stat * statbuf)
{
	struct ibcs_stat tmp;

	/* Note that we have to fold a long inode number down to a short.
	 * This must match what happens in coff:ibcs_read() and
	 * open.c:ibcs_getdents() since code that figures out cwd needs
	 * the inodes to match. Because it must match read() on a
	 * directory we have to avoid the situation where we end up
	 * with a zero inode value. A zero inode value in a read()
	 * on a directory indicates an empty directory slot.
	 */
	if ((unsigned long)inode->i_ino & 0xffff)
		tmp.st_ino = (unsigned long)inode->i_ino & 0xffff;
	else
		tmp.st_ino = 0xfffe;

	tmp.st_dev = inode->i_dev;
	tmp.st_mode = inode->i_mode;
	tmp.st_nlink = inode->i_nlink;
	tmp.st_uid = inode->i_uid;
	tmp.st_gid = inode->i_gid;
	tmp.st_rdev = inode->i_rdev;
	tmp.st_size = inode->i_size;
	tmp.st_atime = inode->i_atime;
	tmp.st_mtime = inode->i_mtime;
	tmp.st_ctime = inode->i_ctime;
	memcpy_tofs(statbuf,&tmp,sizeof(tmp));
}
#endif /* not sparc */

#ifdef __cplusplus
extern "C" 
#endif
int ibcs_stat(char * filename, struct ibcs_stat * statbuf)
{
	struct inode * inode;
	int error;

	error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
	if (error)
		return error;
	error = namei(filename,&inode);
	if (error)
		return error;
	cp_ibcs_stat(inode,statbuf);
	iput(inode);
	return 0;
}

#ifdef __cplusplus
extern "C" 
#endif
int ibcs_lstat(char * filename, struct ibcs_stat * statbuf)
{
	struct inode * inode;
	int error;

	error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
	if (error)
		return error;
	error = lnamei(filename,&inode);
	if (error)
		return error;
	cp_ibcs_stat(inode,statbuf);
	iput(inode);
	return 0;
}

#ifdef __cplusplus
extern "C" 
#endif
int ibcs_fstat(unsigned int fd, struct ibcs_stat * statbuf)
{
	struct file * f;
	struct inode * inode;
	int error;

	error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
	if (error)
		return error;
	if (fd >= NR_OPEN || !(f=current->FD[fd]) || !(inode=f->f_inode))
		return -EBADF;
	cp_ibcs_stat(inode,statbuf);
	return 0;
}