]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: LGPL-2.1 |
e9688c1d | 2 | /* |
da23017d NS |
3 | * Copyright (c) 1995, 2001-2002, 2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
e9688c1d NS |
5 | */ |
6 | ||
dcabd4e7 | 7 | #include "platform_defs.h" |
6b803e5a CH |
8 | #include "xfs.h" |
9 | #include "handle.h" | |
10 | #include "jdm.h" | |
11 | #include "parent.h" | |
e9688c1d NS |
12 | |
13 | /* internal fshandle - typecast to a void for external use */ | |
14 | #define FSHANDLE_SZ 8 | |
15 | typedef struct fshandle { | |
16 | char fsh_space[FSHANDLE_SZ]; | |
17 | } fshandle_t; | |
18 | ||
a3cbe7cd | 19 | /* private file handle - for use by open_by_fshandle */ |
e9688c1d NS |
20 | #define FILEHANDLE_SZ 24 |
21 | #define FILEHANDLE_SZ_FOLLOWING 14 | |
22 | #define FILEHANDLE_SZ_PAD 2 | |
23 | typedef struct filehandle { | |
24 | fshandle_t fh_fshandle; /* handle of fs containing this inode */ | |
25 | int16_t fh_sz_following; /* bytes in handle after this member */ | |
26 | char fh_pad[FILEHANDLE_SZ_PAD]; /* padding, must be zeroed */ | |
14f8b681 | 27 | uint32_t fh_gen; /* generation count */ |
e9688c1d NS |
28 | xfs_ino_t fh_ino; /* 64 bit ino */ |
29 | } filehandle_t; | |
30 | ||
89184fbc | 31 | |
e9688c1d NS |
32 | static void |
33 | jdm_fill_filehandle( filehandle_t *handlep, | |
89184fbc | 34 | fshandle_t *fshandlep, |
b46789e2 | 35 | struct xfs_bstat *statp) |
e9688c1d NS |
36 | { |
37 | handlep->fh_fshandle = *fshandlep; | |
38 | handlep->fh_sz_following = FILEHANDLE_SZ_FOLLOWING; | |
dab9b8d6 | 39 | memset(handlep->fh_pad, 0, FILEHANDLE_SZ_PAD); |
e9688c1d NS |
40 | handlep->fh_gen = statp->bs_gen; |
41 | handlep->fh_ino = statp->bs_ino; | |
42 | } | |
43 | ||
44 | jdm_fshandle_t * | |
45 | jdm_getfshandle( char *mntpnt ) | |
46 | { | |
47 | fshandle_t *fshandlep; | |
48 | size_t fshandlesz; | |
dfc130f3 | 49 | char resolved[MAXPATHLEN]; |
e9688c1d NS |
50 | |
51 | /* sanity checks */ | |
52 | ASSERT( sizeof( fshandle_t ) == FSHANDLE_SZ ); | |
53 | ASSERT( sizeof( filehandle_t ) == FILEHANDLE_SZ ); | |
54 | ASSERT( sizeof( filehandle_t ) | |
55 | - | |
56 | offsetofmember( filehandle_t, fh_pad ) | |
57 | == | |
58 | FILEHANDLE_SZ_FOLLOWING ); | |
59 | ASSERT( sizeofmember( filehandle_t, fh_pad ) == FILEHANDLE_SZ_PAD ); | |
60 | ASSERT( FILEHANDLE_SZ_PAD == sizeof( int16_t )); | |
61 | ||
5e656dbb | 62 | fshandlep = NULL; /* for lint */ |
e9688c1d | 63 | fshandlesz = sizeof( *fshandlep ); |
dfc130f3 RC |
64 | |
65 | if (!realpath( mntpnt, resolved )) | |
66 | return NULL; | |
67 | ||
e9688c1d NS |
68 | if (path_to_fshandle( resolved, ( void ** )&fshandlep, &fshandlesz )) |
69 | return NULL; | |
dfc130f3 | 70 | |
e9688c1d | 71 | assert( fshandlesz == sizeof( *fshandlep )); |
dfc130f3 | 72 | |
e9688c1d NS |
73 | return ( jdm_fshandle_t * )fshandlep; |
74 | } | |
75 | ||
89184fbc AG |
76 | |
77 | /* externally visible functions */ | |
78 | ||
79 | void | |
80 | jdm_new_filehandle( jdm_filehandle_t **handlep, | |
81 | size_t *hlen, | |
82 | jdm_fshandle_t *fshandlep, | |
b46789e2 | 83 | struct xfs_bstat *statp) |
89184fbc AG |
84 | { |
85 | /* allocate and fill filehandle */ | |
86 | *hlen = sizeof(filehandle_t); | |
87 | *handlep = (filehandle_t *) malloc(*hlen); | |
88 | ||
89 | if (*handlep) | |
90 | jdm_fill_filehandle(*handlep, (fshandle_t *) fshandlep, statp); | |
91 | } | |
92 | ||
93 | /* ARGSUSED */ | |
94 | void | |
95 | jdm_delete_filehandle( jdm_filehandle_t *handlep, size_t hlen ) | |
96 | { | |
97 | free(handlep); | |
98 | } | |
99 | ||
e9688c1d | 100 | intgen_t |
b46789e2 | 101 | jdm_open( jdm_fshandle_t *fshp, struct xfs_bstat *statp, intgen_t oflags ) |
e9688c1d | 102 | { |
0c2a7d46 | 103 | fshandle_t *fshandlep = ( fshandle_t * )fshp; |
e9688c1d NS |
104 | filehandle_t filehandle; |
105 | intgen_t fd; | |
106 | ||
107 | jdm_fill_filehandle( &filehandle, fshandlep, statp ); | |
a3cbe7cd | 108 | fd = open_by_fshandle( ( void * )&filehandle, |
e9688c1d NS |
109 | sizeof( filehandle ), |
110 | oflags ); | |
111 | return fd; | |
112 | } | |
113 | ||
114 | intgen_t | |
115 | jdm_readlink( jdm_fshandle_t *fshp, | |
b46789e2 | 116 | struct xfs_bstat *statp, |
e9688c1d NS |
117 | char *bufp, size_t bufsz ) |
118 | { | |
0c2a7d46 | 119 | fshandle_t *fshandlep = ( fshandle_t * )fshp; |
e9688c1d NS |
120 | filehandle_t filehandle; |
121 | intgen_t rval; | |
122 | ||
123 | jdm_fill_filehandle( &filehandle, fshandlep, statp ); | |
124 | rval = readlink_by_handle( ( void * )&filehandle, | |
125 | sizeof( filehandle ), | |
126 | ( void * )bufp, | |
127 | bufsz ); | |
128 | return rval; | |
129 | } | |
14290264 NS |
130 | |
131 | int | |
132 | jdm_attr_multi( jdm_fshandle_t *fshp, | |
b46789e2 | 133 | struct xfs_bstat *statp, |
14290264 NS |
134 | char *bufp, int rtrvcnt, int flags) |
135 | { | |
0c2a7d46 | 136 | fshandle_t *fshandlep = ( fshandle_t * )fshp; |
14290264 NS |
137 | filehandle_t filehandle; |
138 | int rval; | |
139 | ||
140 | jdm_fill_filehandle( &filehandle, fshandlep, statp ); | |
141 | rval = attr_multi_by_handle ( ( void * )&filehandle, | |
142 | sizeof( filehandle ), | |
143 | (void *) bufp, | |
144 | rtrvcnt, flags); | |
145 | return rval; | |
146 | } | |
147 | ||
148 | int | |
149 | jdm_attr_list( jdm_fshandle_t *fshp, | |
b46789e2 | 150 | struct xfs_bstat *statp, |
14290264 NS |
151 | char *bufp, size_t bufsz, int flags, |
152 | struct attrlist_cursor *cursor) | |
153 | { | |
0c2a7d46 | 154 | fshandle_t *fshandlep = ( fshandle_t * )fshp; |
14290264 NS |
155 | filehandle_t filehandle; |
156 | int rval; | |
157 | ||
aa23a327 | 158 | /* prevent needless EINVAL from the kernel */ |
54e724c0 JT |
159 | if (bufsz > XFS_XATTR_LIST_MAX) |
160 | bufsz = XFS_XATTR_LIST_MAX; | |
aa23a327 | 161 | |
14290264 NS |
162 | jdm_fill_filehandle( &filehandle, fshandlep, statp ); |
163 | rval = attr_list_by_handle (( void * )&filehandle, | |
164 | sizeof( filehandle ), | |
165 | bufp, bufsz, flags, cursor); | |
166 | return rval; | |
167 | } | |
258b00ea TS |
168 | |
169 | int | |
60ac13e8 | 170 | jdm_parents( jdm_fshandle_t *fshp, |
b46789e2 | 171 | struct xfs_bstat *statp, |
258b00ea | 172 | parent_t *bufp, size_t bufsz, |
60ac13e8 | 173 | unsigned int *count) |
258b00ea | 174 | { |
258b00ea TS |
175 | errno = EOPNOTSUPP; |
176 | return -1; | |
258b00ea TS |
177 | } |
178 | ||
179 | int | |
60ac13e8 | 180 | jdm_parentpaths( jdm_fshandle_t *fshp, |
b46789e2 | 181 | struct xfs_bstat *statp, |
258b00ea | 182 | parent_t *bufp, size_t bufsz, |
60ac13e8 | 183 | unsigned int *count) |
258b00ea | 184 | { |
258b00ea TS |
185 | errno = EOPNOTSUPP; |
186 | return -1; | |
258b00ea | 187 | } |