aboutsummaryrefslogtreecommitdiffstats
path: root/libhandle/jdm.c
blob: d2b9781a84236f3dc5c2bb1c70b5be211a9cb27c (plain)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// SPDX-License-Identifier: LGPL-2.1
/*
 * Copyright (c) 1995, 2001-2002, 2005 Silicon Graphics, Inc.
 * All Rights Reserved.
 */

#include "platform_defs.h"
#include "xfs.h"
#include "handle.h"
#include "jdm.h"
#include "parent.h"

/* internal fshandle - typecast to a void for external use */
#define FSHANDLE_SZ		8
typedef struct fshandle {
	char fsh_space[FSHANDLE_SZ];
} fshandle_t;

/* private file handle - for use by open_by_fshandle */
#define FILEHANDLE_SZ		24
#define FILEHANDLE_SZ_FOLLOWING	14
#define FILEHANDLE_SZ_PAD	2
typedef struct filehandle {
	fshandle_t fh_fshandle;		/* handle of fs containing this inode */
	int16_t fh_sz_following;	/* bytes in handle after this member */
	char fh_pad[FILEHANDLE_SZ_PAD];	/* padding, must be zeroed */
	uint32_t fh_gen;		/* generation count */
	xfs_ino_t fh_ino;		/* 64 bit ino */
} filehandle_t;


static void
jdm_fill_filehandle( filehandle_t *handlep,
		     fshandle_t *fshandlep,
		     xfs_bstat_t *statp )
{
	handlep->fh_fshandle = *fshandlep;
	handlep->fh_sz_following = FILEHANDLE_SZ_FOLLOWING;
	memset(handlep->fh_pad, 0, FILEHANDLE_SZ_PAD);
	handlep->fh_gen = statp->bs_gen;
	handlep->fh_ino = statp->bs_ino;
}

jdm_fshandle_t *
jdm_getfshandle( char *mntpnt )
{
	fshandle_t *fshandlep;
	size_t fshandlesz;
	char resolved[MAXPATHLEN];

	/* sanity checks */
	ASSERT( sizeof( fshandle_t ) == FSHANDLE_SZ );
	ASSERT( sizeof( filehandle_t ) == FILEHANDLE_SZ );
	ASSERT( sizeof( filehandle_t )
		-
		offsetofmember( filehandle_t, fh_pad )
		==
		FILEHANDLE_SZ_FOLLOWING );
	ASSERT( sizeofmember( filehandle_t, fh_pad ) == FILEHANDLE_SZ_PAD );
	ASSERT( FILEHANDLE_SZ_PAD == sizeof( int16_t ));

	fshandlep = NULL; /* for lint */
	fshandlesz = sizeof( *fshandlep );

	if (!realpath( mntpnt, resolved ))
		return NULL;

	if (path_to_fshandle( resolved, ( void ** )&fshandlep, &fshandlesz ))
		return NULL;

	assert( fshandlesz == sizeof( *fshandlep ));

	return ( jdm_fshandle_t * )fshandlep;
}


/* externally visible functions */

void
jdm_new_filehandle( jdm_filehandle_t **handlep,
		    size_t *hlen,
		    jdm_fshandle_t *fshandlep,
		    xfs_bstat_t *statp)
{
	/* allocate and fill filehandle */
	*hlen = sizeof(filehandle_t);
	*handlep = (filehandle_t *) malloc(*hlen);

	if (*handlep)
		jdm_fill_filehandle(*handlep, (fshandle_t *) fshandlep, statp);
}

/* ARGSUSED */
void
jdm_delete_filehandle( jdm_filehandle_t *handlep, size_t hlen )
{
	free(handlep);
}

intgen_t
jdm_open( jdm_fshandle_t *fshp, xfs_bstat_t *statp, intgen_t oflags )
{
	fshandle_t *fshandlep = ( fshandle_t * )fshp;
	filehandle_t filehandle;
	intgen_t fd;

	jdm_fill_filehandle( &filehandle, fshandlep, statp );
	fd = open_by_fshandle( ( void * )&filehandle,
			     sizeof( filehandle ),
			     oflags );
	return fd;
}

intgen_t
jdm_readlink( jdm_fshandle_t *fshp,
	      xfs_bstat_t *statp,
	      char *bufp, size_t bufsz )
{
	fshandle_t *fshandlep = ( fshandle_t * )fshp;
	filehandle_t filehandle;
	intgen_t rval;

	jdm_fill_filehandle( &filehandle, fshandlep, statp );
	rval = readlink_by_handle( ( void * )&filehandle,
				   sizeof( filehandle ),
				   ( void * )bufp,
				   bufsz );
	return rval;
}

int
jdm_attr_multi(	jdm_fshandle_t *fshp,
		xfs_bstat_t *statp,
		char *bufp, int rtrvcnt, int flags)
{
	fshandle_t *fshandlep = ( fshandle_t * )fshp;
	filehandle_t filehandle;
	int rval;

	jdm_fill_filehandle( &filehandle, fshandlep, statp );
	rval = attr_multi_by_handle ( ( void * )&filehandle,
				      sizeof( filehandle ),
				      (void *) bufp,
				      rtrvcnt, flags);
	return rval;
}

int
jdm_attr_list(	jdm_fshandle_t *fshp,
		xfs_bstat_t *statp,
		char *bufp, size_t bufsz, int flags,
		struct attrlist_cursor *cursor)
{
	fshandle_t *fshandlep = ( fshandle_t * )fshp;
	filehandle_t filehandle;
	int rval;

	/* prevent needless EINVAL from the kernel */
	if (bufsz > XFS_XATTR_LIST_MAX)
		bufsz = XFS_XATTR_LIST_MAX;

	jdm_fill_filehandle( &filehandle, fshandlep, statp );
	rval = attr_list_by_handle (( void * )&filehandle,
			sizeof( filehandle ),
			bufp, bufsz, flags, cursor);
	return rval;
}

int
jdm_parents( jdm_fshandle_t *fshp,
		xfs_bstat_t *statp,
		parent_t *bufp, size_t bufsz,
		unsigned int *count)
{
	errno = EOPNOTSUPP;
	return -1;
}

int
jdm_parentpaths( jdm_fshandle_t *fshp,
		xfs_bstat_t *statp,
		parent_t *bufp, size_t bufsz,
		unsigned int *count)
{
	errno = EOPNOTSUPP;
	return -1;
}