File: bsdstat.c

package info (click to toggle)
ibcs 971113-5
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,096 kB
  • ctags: 2,079
  • sloc: ansic: 14,910; makefile: 310; sh: 203; asm: 47; perl: 18; pascal: 2
file content (113 lines) | stat: -rw-r--r-- 2,039 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
/*
 *  linux/ibcs/bsdstat.c
 *
 *  Copyright (C) 1994  Mike Jagdis
 *
 * $Id: bsdstat.c,v 1.7 1995/12/12 10:31:04 mike Exp $
 * $Source: /usr/CVS/ibcs/iBCSemul/bsdstat.c,v $
 */

#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/bsd.h>
#include <ibcs/ibcs.h>


void
cp_bsd_stat(struct inode *inode, struct bsd_stat *st)
{
	struct bsd_stat 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 = inode->i_atime;
	tmp.st_mtime = inode->i_mtime;
	tmp.st_ctime = inode->i_ctime;
	tmp.st_blksize = inode->i_blksize;
	tmp.st_blocks = inode->i_blocks;
	tmp.st_flags = inode->i_flags;
	tmp.st_gen = 0;

	memcpy_tofs(st, &tmp, sizeof(struct bsd_stat));
}


int
bsd_stat(char *filename, struct bsd_stat *st)
{
	struct inode *inode;
	int error;

	error = verify_area(VERIFY_WRITE, st, sizeof(struct bsd_stat));
	if (error)
		return error;

	error = namei(filename, &inode);
	if (error)
		return error;

	cp_bsd_stat(inode, st);
	iput(inode);

	return 0;
}

int
bsd_lstat(char *filename, struct bsd_stat *st)
{
	struct inode *inode;
	int error;

	error = verify_area(VERIFY_WRITE, st, sizeof(struct bsd_stat));
	if (error)
		return error;

	error = lnamei(filename, &inode);
	if (error)
		return error;

	cp_bsd_stat(inode, st);
	iput(inode);

	return 0;
}

int
bsd_fstat(unsigned int fd, struct bsd_stat *st)
{
	struct file *f;
	struct inode *inode;
	int error;

	error = verify_area(VERIFY_WRITE, st, sizeof(struct bsd_stat));
	if (error)
		return error;

	if (fd >= NR_OPEN || !(f=current->FD[fd]) || !(inode=f->f_inode))
		return -EBADF;

	cp_bsd_stat(inode, st);

	return 0;
}