]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libhandle/jdm.c
2 * Copyright (c) 1995, 2001-2002 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2.1 of the GNU Lesser General Public License
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program; if not, write the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
24 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25 * Mountain View, CA 94043, or:
29 * For further information regarding this notice, see:
31 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 /* attributes.h (purposefully) unavailable to xfsprogs, make do */
37 struct attrlist_cursor
{ __u32 opaque
[4]; };
42 /* internal fshandle - typecast to a void for external use */
44 typedef struct fshandle
{
45 char fsh_space
[FSHANDLE_SZ
];
48 /* private file handle - for use by open_by_handle */
49 #define FILEHANDLE_SZ 24
50 #define FILEHANDLE_SZ_FOLLOWING 14
51 #define FILEHANDLE_SZ_PAD 2
52 typedef struct filehandle
{
53 fshandle_t fh_fshandle
; /* handle of fs containing this inode */
54 int16_t fh_sz_following
; /* bytes in handle after this member */
55 char fh_pad
[FILEHANDLE_SZ_PAD
]; /* padding, must be zeroed */
56 __uint32_t fh_gen
; /* generation count */
57 xfs_ino_t fh_ino
; /* 64 bit ino */
62 jdm_fill_filehandle( filehandle_t
*handlep
,
63 fshandle_t
*fshandlep
,
66 handlep
->fh_fshandle
= *fshandlep
;
67 handlep
->fh_sz_following
= FILEHANDLE_SZ_FOLLOWING
;
68 bzero(handlep
->fh_pad
, FILEHANDLE_SZ_PAD
);
69 handlep
->fh_gen
= statp
->bs_gen
;
70 handlep
->fh_ino
= statp
->bs_ino
;
74 jdm_getfshandle( char *mntpnt
)
76 fshandle_t
*fshandlep
;
78 char resolved
[MAXPATHLEN
];
81 ASSERT( sizeof( fshandle_t
) == FSHANDLE_SZ
);
82 ASSERT( sizeof( filehandle_t
) == FILEHANDLE_SZ
);
83 ASSERT( sizeof( filehandle_t
)
85 offsetofmember( filehandle_t
, fh_pad
)
87 FILEHANDLE_SZ_FOLLOWING
);
88 ASSERT( sizeofmember( filehandle_t
, fh_pad
) == FILEHANDLE_SZ_PAD
);
89 ASSERT( FILEHANDLE_SZ_PAD
== sizeof( int16_t ));
91 fshandlep
= 0; /* for lint */
92 fshandlesz
= sizeof( *fshandlep
);
94 if (!realpath( mntpnt
, resolved
))
97 if (path_to_fshandle( resolved
, ( void ** )&fshandlep
, &fshandlesz
))
100 assert( fshandlesz
== sizeof( *fshandlep
));
102 return ( jdm_fshandle_t
* )fshandlep
;
106 /* externally visible functions */
109 jdm_new_filehandle( jdm_filehandle_t
**handlep
,
111 jdm_fshandle_t
*fshandlep
,
114 /* allocate and fill filehandle */
115 *hlen
= sizeof(filehandle_t
);
116 *handlep
= (filehandle_t
*) malloc(*hlen
);
119 jdm_fill_filehandle(*handlep
, (fshandle_t
*) fshandlep
, statp
);
124 jdm_delete_filehandle( jdm_filehandle_t
*handlep
, size_t hlen
)
130 jdm_open( jdm_fshandle_t
*fshp
, xfs_bstat_t
*statp
, intgen_t oflags
)
132 register fshandle_t
*fshandlep
= ( fshandle_t
* )fshp
;
133 filehandle_t filehandle
;
136 jdm_fill_filehandle( &filehandle
, fshandlep
, statp
);
137 fd
= open_by_handle( ( void * )&filehandle
,
138 sizeof( filehandle
),
144 jdm_readlink( jdm_fshandle_t
*fshp
,
146 char *bufp
, size_t bufsz
)
148 register fshandle_t
*fshandlep
= ( fshandle_t
* )fshp
;
149 filehandle_t filehandle
;
152 jdm_fill_filehandle( &filehandle
, fshandlep
, statp
);
153 rval
= readlink_by_handle( ( void * )&filehandle
,
154 sizeof( filehandle
),
161 jdm_attr_multi( jdm_fshandle_t
*fshp
,
163 char *bufp
, int rtrvcnt
, int flags
)
165 register fshandle_t
*fshandlep
= ( fshandle_t
* )fshp
;
166 filehandle_t filehandle
;
169 jdm_fill_filehandle( &filehandle
, fshandlep
, statp
);
170 rval
= attr_multi_by_handle ( ( void * )&filehandle
,
171 sizeof( filehandle
),
178 jdm_attr_list( jdm_fshandle_t
*fshp
,
180 char *bufp
, size_t bufsz
, int flags
,
181 struct attrlist_cursor
*cursor
)
183 register fshandle_t
*fshandlep
= ( fshandle_t
* )fshp
;
184 filehandle_t filehandle
;
187 jdm_fill_filehandle( &filehandle
, fshandlep
, statp
);
188 rval
= attr_list_by_handle (( void * )&filehandle
,
189 sizeof( filehandle
),
190 bufp
, bufsz
, flags
, cursor
);