summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient/src/libglusterfsclient.h
blob: ad23e02a0cde0943e7c6dea1d1d88614dac4ffc3 (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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
/*
  Copyright (c) 2008, 2009 Gluster, Inc. <http://www.gluster.com>
  This file is part of GlusterFS.

  GlusterFS is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 3 of the License,
  or (at your option) any later version.

  GlusterFS is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see
  <http://www.gnu.org/licenses/>.
*/

#ifndef _LIBGLUSTERFSCLIENT_H
#define _LIBGLUSTERFSCLIENT_H

#ifndef __BEGIN_DECLS
#ifdef __cplusplus
#define __BEGIN_DECLS extern "C" {
#else
#define __BEGIN_DECLS
#endif
#endif

#ifndef __END_DECLS
#ifdef __cplusplus
#define __END_DECLS }
#else
#define __END_DECLS
#endif
#endif


__BEGIN_DECLS

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <sys/statfs.h>
#include <sys/statvfs.h>
#include <utime.h>
#include <sys/time.h>
#include <stdint.h>

typedef struct {
        struct iovec *vector;
        int           count;
        void         *iobref;
        void         *dictref;
} glusterfs_iobuf_t;


typedef
int (*glusterfs_readv_cbk_t) (int op_ret, int op_errno, glusterfs_iobuf_t *buf,
			      void *cbk_data);

typedef
int (*glusterfs_write_cbk_t) (int op_ret, int op_errno, void *cbk_data);

typedef
int (*glusterfs_get_cbk_t) (int op_ret, int op_errno, glusterfs_iobuf_t *buf,
			    struct stat *stbuf, void *cbk_data);


/* Data Interface
 * The first section describes the data structures required for
 * using libglusterfsclient.
 */

/* This structure needs to be filled up and
 * passed to te glusterfs_init function which uses
 * the params passed herein to initialize a glusterfs
 * client context and then connect to a glusterfs server.
 */
typedef struct {
        char          *logfile;         /* Path to the file which will store
                                           the log.
                                           */
        char          *loglevel;        /* The log level required for
                                           reporting various events within
                                           libglusterfsclient.
                                           */
        struct {
                char  *specfile;        /* Users can either open a volume or
                                           specfile and assign the pointer to
                                           specfp, or just refer to the volume
                                           /spec file path in specfile.
                                           */
                FILE  *specfp;
        };
        char          *volume_name;     /* The volume file could describe many
                                           volumes but the specific volume
                                           within that file is chosen by
                                           specifying the volume name here.
                                           */
        unsigned long  lookup_timeout;  /* libglusterclient provides the inode
                                           numbers to be cached by the library.
                                           The duration for which these are
                                           cached are defined by lookup_timeout
                                           . In Seconds.
                                           */
        unsigned long  stat_timeout;    /* The file attributes received from
                                           a stat syscall can also be cached
                                           for the duration specified in this
                                           member. In Seconds.
                                           */
} glusterfs_init_params_t;



/* This is the handle returned by glusterfs_init
 * once the initialization is complete.
 * Users should treat this as an opaque handle.
 */
typedef void * glusterfs_handle_t;



/* These identifiers are used as handles for files and dirs.
 * Users of libglusterfsclient should not in anyway try to interpret
 * the actual structures these will point to.
 */
typedef void * glusterfs_file_t;
typedef void * glusterfs_dir_t;


/* Function Call Interface */
/* libglusterfsclient initialization function.
 * @ctx : the structure described above filled with required values.
 * @fakefsid: User generated fsid to be used to identify this
 * volume.
 *
 * Returns NULL on failure and the non-NULL pointer on success.
 * On failure, the error description might be present in the logfile
 * depending on the log level.
 */
glusterfs_handle_t
glusterfs_init (glusterfs_init_params_t *ctx, uint32_t fakefsid);



/* Used to destroy a glusterfs client context and the
 * connection to the glusterfs server.
 *
 * @handle      : The glusterfs handle returned by glusterfs_init.
 */
int
glusterfs_fini (glusterfs_handle_t handle);



/* libglusterfs client provides two interfaces.
 * 1. handle-based interface
 * Functions that comprise the handle-based interface accept the
 * glusterfs_handle_t as the first argument. It specifies the
 * glusterfs client context over which to perform the operation.
 *
 * 2. Virtual Mount Point based interface:
 * Functions that do not require a handle to be given in order to
 * identify which client context to operate on. This interface
 * internally determines the corresponding client context for the
 * given path. The down-side is that a virtual mount point (VMP) needs to be
 * registered with the library. A VMP is just a string that maps to a
 * glusterfs_handle_t. The advantage of a VMP based interface is that
 * a user program using multiple client contexts does not need to
 * maintain its own mapping between paths and the corresponding
 * handles.
 */



/* glusterfs_mount is the function that allows users to register a VMP
 * along with the parameters, which will be used to initialize a
 * context. Applications calling glusterfs_mount do not need to
 * initialized a context using the glusterfs_init interface.
 *
 * @vmp         : The virtual mount point.
 * @ipars       : Initialization parameters populated as described
 *              earlier.
 *
 * Returns 0 on success, and -1 on failure.
 */
int
glusterfs_mount (char *vmp, glusterfs_init_params_t *ipars);



/* glusterfs_umount is the VMP equivalent of glusterfs_fini.
 *
 * @vmp         : The VMP which was initialized using glusterfs_mount.
 *
 * Returns 0 on sucess, and -1 on failure.
 */
int
glusterfs_umount (char *vmp);


/* glusterfs_umount_all unmounts all the mounts */
int
glusterfs_umount_all (void);


/* For smaller files, application can use just
 * glusterfs_get/glusterfs_get_async
 * to read the whole content. Limit of the file-sizes to be read in
 * glusterfs_get/glusterfs_get_async is passed in the size argument
 */

/* glusterfs_glh_get:
 * @handle : glusterfs handle
 * @path   : path to be looked upon
 * @size   : upper limit of file-sizes to be read in lookup
 * @stbuf  : attribute buffer
 */

int
glusterfs_glh_get (glusterfs_handle_t handle, const char *path, void *buf,
	       size_t size, struct stat *stbuf);

int
glusterfs_get (const char *path, void *buf, size_t size, struct stat *stbuf);

int
glusterfs_get_async (glusterfs_handle_t handle, const char *path, size_t size,
		     glusterfs_get_cbk_t cbk, void *cbk_data);



/* Opens a file. Corresponds to the open syscall.
 *
 * @handle      : Handle returned from glusterfs_init
 * @path        : Path to the file or directory on the glusterfs
 *              export. Must be absolute to the export on the server.
 * @flags       : flags to control open behaviour.
 * @...         : The mode_t argument that defines the mode for a new
 *              file, in case a new file is being created using the
 *              O_CREAT flag in @flags.
 *
 * Returns a non-NULL handle on success. NULL on failure and sets
 * errno accordingly.
 */
glusterfs_file_t
glusterfs_glh_open (glusterfs_handle_t handle, const char *path, int flags,
                        ...);


/* Opens a file without having to specify a handle.
 *
 * @path        : Path to the file to open in the glusterfs export.
 *              The path to the file in glusterfs export must be
 *              pre-fixed with the VMP string registered with
 *              glusterfs_mount.
 * @flags       : flags to control open behaviour.
 * @...         : The mode_t argument that defines the mode for a new
 *              file, in case a new file is being created using the
 *              O_CREAT flag in @flags.
 *
 * Returns 0 on success, -1 on failure with errno set accordingly.
 */
glusterfs_file_t
glusterfs_open (const char *path, int flags, ...);



/* Creates a file. Corresponds to the creat syscall.
 *
 * @handle      : Handle returned from glusterfs_init
 * @path        : Path to the file that needs to be created in the
 *              glusterfs export.
 * @mode        : File creation mode.
 *
 * Returns the file handle on success. NULL on error with errno set as
 * required.
 */
glusterfs_file_t
glusterfs_glh_creat (glusterfs_handle_t handle, const char *path, mode_t mode);



/* VMP-based creat.
 * @path        : Path to the file to be created. Must be
 *              pre-prepended with the VMP string registered with
 *              glusterfs_mount.
 * @mode        : File creation mode.
 *
 * Returns file handle on success. NULL handle on error with errno set
 * accordingly.
 */
glusterfs_file_t
glusterfs_creat (const char *path, mode_t mode);



/* Close the file identified by the handle.
 *
 * @fd          : Closes the file.
 *
 * Returns 0 on success, -1 on error with errno set accordingly.
 */
int
glusterfs_close (glusterfs_file_t fd);



/* Get struct stat for the file in path.
 *
 * @handle      : The handle that identifies a glusterfs client
 *              context.
 * @path        : The file for which we need to get struct stat.
 * @stbuf       : The buffer into which the file's stat is copied.
 *
 * Returns 0 on success and -1 on error with errno set accordingly.
 */
int
glusterfs_glh_stat (glusterfs_handle_t handle, const char *path,
                        struct stat *stbuf);


/* Get struct stat for file in path.
 *
 * @path        : The file for which struct stat is required.
 * @sbuf        : The buffer into which the stat structure is copied.
 *
 * Returns 0 on success and -1 on error with errno set accordingly.
 */
int
glusterfs_stat (const char *path, struct stat *buf);



/* Gets stat struct for the file.
 *
 * @handle      : The handle identifying a glusterfs client context.
 * @path        : Path to the file for which stat structure is
 *              required. If path is a symlink, the symlink is
 *              interpreted and the stat structure returned for the
 *              target of the link.
 * @buf         : The buffer into which the stat structure is copied.
 *
 * Returns 0 on success and -1 on error with errno set accordingly.
 */
int
glusterfs_glh_lstat (glusterfs_handle_t handle, const char *path,
                        struct stat *buf);



/* Gets stat struct for a file.
 *
 * @path        : The file to get the struct stat for.
 * @buf         : The receiving struct stat buffer.
 *
 * Returns 0 on success and -1 on error with errno set accordingly.
 */
int
glusterfs_lstat (const char *path, struct stat *buf);



/* Get stat structure for a file.
 *
 * @fd          : The file handle identifying a file on the glusterfs
 *              server.
 * @stbuf       : The buffer into which the stat data is copied.
 *
 * Returns 0 on success and -1 on error with errno set accordingly.
 */
int
glusterfs_fstat (glusterfs_file_t fd, struct stat *stbuf);

int
glusterfs_glh_setxattr (glusterfs_handle_t handle, const char *path,
                                const char *name, const void *value,
                                size_t size, int flags);

int
glusterfs_glh_lsetxattr (glusterfs_handle_t handle, const char *path,
                         const char *name, const void *value, size_t size,
                         int flags);

int
glusterfs_setxattr (const char *path, const char *name, const void *value,
                        size_t size, int flags);

int
glusterfs_lsetxattr (glusterfs_handle_t handle, const char *path,
                     const char *name, const void *value, size_t size,
                     int flags);

int
glusterfs_fsetxattr (glusterfs_file_t fd, const char *name, const void *value,
                     size_t size, int flags);

ssize_t
glusterfs_glh_getxattr (glusterfs_handle_t handle, const char *path,
		        const char *name, void *value, size_t size);

ssize_t
glusterfs_glh_lgetxattr (glusterfs_handle_t handle, const char *path,
		         const char *name, void *value, size_t size);

ssize_t
glusterfs_getxattr (const char *path, const char *name, void *value,
                        size_t size);

ssize_t
glusterfs_lgetxattr (const char *path, const char *name, void *value,
                     size_t size);

ssize_t
glusterfs_fgetxattr (glusterfs_file_t fd, const char *name, void *value,
		     size_t size);

ssize_t
glusterfs_listxattr (glusterfs_handle_t handle, const char *path, char *list,
                     size_t size);

ssize_t
glusterfs_llistxattr (glusterfs_handle_t handle, const char *path, char *list,
                      size_t size);

ssize_t
glusterfs_flistxattr (glusterfs_file_t fd, char *list, size_t size);

int
glusterfs_removexattr (glusterfs_handle_t handle, const char *path,
		       const char *name);

int
glusterfs_lremovexattr (glusterfs_handle_t handle, const char *path,
			const char *name);

int
glusterfs_fremovexattr (glusterfs_file_t fd, const char *name);



/* Read data from a file.
 * @fd          : Handle returned by glusterfs_open or
 *              glusterfs_glh_open.
 * @buf         : Buffer to read the data into.
 * @nbytes      : Number of bytes to read.
 *
 * Returns number of bytes actually read on success or -1 on error
 * with errno set to the appropriate error number.
 */
ssize_t
glusterfs_read (glusterfs_file_t fd, void *buf, size_t nbytes);



/* Read data into an array of buffers.
 *
 * @fd          : File handle returned by glusterfs_open or
 *              glusterfs_glh_open.
 * @vec         : Array of buffers into which the data is read.
 * @count       : Number of iovecs referred to by vec.
 *
 * Returns number of bytes read on success or -1 on error with errno
 * set appropriately.
 */
ssize_t
glusterfs_readv (glusterfs_file_t fd, const struct iovec *vec, int count);

int
glusterfs_read_async (glusterfs_file_t fd, size_t nbytes, off_t offset,
                      glusterfs_readv_cbk_t readv_cbk, void *cbk_data);



/* Write data into a file.
 *
 * @fd          : File handle returned from glusterfs_open or
 *              glusterfs_glh_open.
 * @buf         : Buffer which is written to the file.
 * @nbytes      : Number bytes of the @buf written to the file.
 *
 * On success, returns number of bytes written. On error, returns -1
 * with errno set appropriately.
 */
ssize_t
glusterfs_write (glusterfs_file_t fd, const void *buf, size_t nbytes);



/* Writes an array of buffers into a file.
 *
 * @fd          : The file handle returned from glusterfs_open or
 *              glusterfs_glh_open.
 * @vector      : Array of buffers to be written to the file.
 * @count       : Number of separate buffers in the @vector array.
 *
 * Returns number of bytes written on success or -1 on error with
 * errno set approriately.
 */
ssize_t
glusterfs_writev (glusterfs_file_t fd, const struct iovec *vector, int count);

int
glusterfs_write_async (glusterfs_file_t fd, const void *buf, size_t nbytes,
                       off_t offset, glusterfs_write_cbk_t write_cbk,
		       void *cbk_data);

int
glusterfs_writev_async (glusterfs_file_t fd, const struct iovec *vector,
			int count, off_t offset,
			glusterfs_write_cbk_t write_cbk, void *cbk_data);



/* Read from a file starting at a given offset.
 *
 * @fd          : File handle returned from glusterfs_open or
 *              glusterfs_glh_open.
 * @buf         : Buffer to read the data into.
 * @nbytes      : Number of bytes to read.
 * @offset      : The offset to start reading @nbytes from.
 *
 * Returns number of bytes read on success or -1 on error with errno
 * set appropriately.
 */
ssize_t
glusterfs_pread (glusterfs_file_t fd, void *buf, size_t nbytes, off_t offset);



/* Write to a file starting at a given offset.
 *
 * @fd          : Flie handle returned from glusterfs_open or
 *              glusterfs_glh_open.
 * @buf         : Buffer that will be written to the file.
 * @nbytes      : Number of bytes to write from @buf.
 * @offset      : The starting offset from where @nbytes will be
 *              written.
 *
 * Returns number of bytes written on success and -1 on error with
 * errno set appropriately.
 */
ssize_t
glusterfs_pwrite (glusterfs_file_t fd, const void *buf, size_t nbytes,
		  off_t offset);



/* Seek to an offset in the file.
 *
 * @fd          : File handle in which to seek to. File handle
 *              returned by glusterfs_open or glusterfs_glh_open.
 * @offset      : Offset to seek to in the given file.
 * @whence      : Determines how the offset is interpreted by this
 *              syscall. The behaviour is similar to the options
 *              provided by the POSIX lseek system call. See man lseek
 *              for more details.
 *
 * On success, returns the resulting absolute offset in the file after the seek
 * operation is performed. ON error, returns -1 with errno set
 * appropriately.
 */
off_t
glusterfs_lseek (glusterfs_file_t fd, off_t offset, int whence);



/* Create a directory.
 *
 * @handle      : The handle of the glusterfs context in which the
 *              directory needs to be created.
 * @path        : The absolute path within the glusterfs context where
 *              the directory needs to be created.
 * @mode        : The mode bits for the newly created directory.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_mkdir (glusterfs_handle_t handle, const char *path, mode_t mode);



/* Create a directory.
 *
 * @path        : Path to the directory that needs to be created. This
 *              path must be prefixed with the VMP of the particular glusterfs
 *              context.
 * @mode        : Mode flags for the newly created directory.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_mkdir (const char *path, mode_t mode);



/* Remove a directory.
 *
 * @handle      : Handle of the glusterfs context from which to remove
 *              the directory.
 * @path        : The path of the directory to be removed in the glusterfs
 *              context.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_rmdir (glusterfs_handle_t handle, const char *path);



/* Remove a directory.
 *
 * @path        : The absolute path to the directory to be removed.
 *              This path must be pre-fixed with the VMP of the
 *              particular glusterfs context in which this directory
 *              resides.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_rmdir (const char *path);



/* Read directory entries.
 *
 * @fd          : The handle of the directory to be read. This handle
 *              is the one returned by opendir.
 *
 * Returns the directory entry on success and NULL pointer on error
 * with errno set appropriately.
 */
void *
glusterfs_readdir (glusterfs_dir_t dirfd);



/* re-entrant version of glusterfs_readdir.
 *
 * @dirfd       : The handle of directory to be read. This handle is the one
 *                returned by opendir.
 * @entry       : Pointer to storage to store a directory entry. The storage
 *                pointed to by entry shall be large enough for a dirent with 
 *                an array of char d_name members containing at least
 *                {NAME_MAX}+1 elements.
 * @result      : Upon successful return, the pointer returned at *result shall
 *                have the same value as the argument entry. Upon reaching the
 *                end of the directory stream, this pointer shall have the
 *                value NULL.
 */
int
glusterfs_readdir_r (glusterfs_dir_t dirfd, struct dirent *entry,
                     struct dirent **result);

/* Close a directory handle.
 *
 * @fd          : The directory handle to be closed.
 *
 * Returns 0 on success and -1 on error with errno set to 0.
 */
int
glusterfs_closedir (glusterfs_dir_t dirfd);
/* FIXME: remove getdents */
int
glusterfs_getdents (glusterfs_dir_t fd, struct dirent *dirp,
		    unsigned int count);



/* Create device node.
 *
 * @handle      : glusterfs context in which to create the device
 *              node.
 * @pathname    : The absolute path of the device to be created in the
 *              given glusterfs context.
 *
 * @mode        : Mode flags to apply to the newly created node.
 * @dev         : Device numbers that will apply to the node.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_mknod(glusterfs_handle_t handle, const char *pathname,
                        mode_t mode, dev_t dev);



/* Create a device node.
 *
 * @pathname    : The full path of the node to be created. This path
 *              should be pre-pended with the VMP of the glusterfs
 *              context in which this node is to be created.
 * @mode        : Mode flags that will be applied to the newly created
 *              device file.
 * @dev         : The device numbers that will be associated with the
 *              device node.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_mknod(const char *pathname, mode_t mode, dev_t dev);



/* Returns the real absolute path of the given path.
 *
 * @handle              : The glusterfs context in which the path resides in.
 * @path                : The path to be resolved.
 * @resolved_path       : The resolved path is stored in this buffer
 *                      provided by the caller.
 *
 * Returns a pointer to resolved_path on success and NULL on error
 * with errno set appropriately.
 *
 * See man realpath for details.
 */
char *
glusterfs_glh_realpath (glusterfs_handle_t handle, const char *path,
                        char *resolved_path);


/* Returns the real absolute path of the given path.
 *
 * @path                : The path to be resolved. This path must be
 *                      pre-fixed with the VMP of the glusterfs
 *                      context in which the file resides.
 *
 * @resolved_path       : The resolved path is stored in this user
 *                      provided buffer.
 *
 * Returns a pointer to resolved_path on success, and NULL on error
 * with errno set appropriately.
 */
char *
glusterfs_realpath (const char *path, char *resolved_path);



/* Change mode flags on a path.
 *
 * @handle      : Handle of the glusterfs instance in which the path
 *              resides.
 * @path        : The path whose mode bits need to be changed.
 * @mode        : The new mode bits.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_chmod (glusterfs_handle_t handle, const char *path, mode_t mode);



/* Change mode flags on a path.
 *
 * @path        : The path whose mode bits need to be changed. The
 *              path should be pre-fixed with the VMP that identifies the
 *              glusterfs context within which the path resides.
 * @mode        : The new mode bits.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_chmod (const char *path, mode_t mode);



/* Change the owner of a path.
 * If @path is a symlink, it is dereferenced and the ownership change
 * happens on the target.
 *
 * @handle      : Handle of the glusterfs context in which the path
 *              resides.
 * @path        : The path whose owner needs to be changed.
 * @owner       : ID of the new owner.
 * @group       : ID of the new group.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_chown (glusterfs_handle_t handle, const char *path, uid_t owner,
                        gid_t group);



/* Change the owner of a path.
 *
 * If @path is a symlink, it is dereferenced and the ownership change
 * happens on the target.
 * @path        : The path whose owner needs to be changed. Path must
 *              be pre-fixed with the VMP that identifies the
 *              glusterfs context in which the path resides.
 * @owner       : ID of the new owner.
 * @group       : ID of the new group.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_chown (const char *path, uid_t owner, gid_t group);



/* Change the owner of the file.
 *
 * @fd          : Handle of the file whose owner needs to be changed.
 * @owner       : ID of the new owner.
 * @group       : ID of the new group.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_fchown (glusterfs_file_t fd, uid_t owner, gid_t group);



/* Open a directory.
 *
 * @handle      : Handle that identifies a glusterfs context.
 * @path        : Path to the directory in the glusterfs context.
 *
 * Returns a non-NULL handle on success and NULL on failure with errno
 * set appropriately.
 */
glusterfs_dir_t
glusterfs_glh_opendir (glusterfs_handle_t handle, const char *path);



/* Open a directory.
 *
 * @path        : Path to the directory. The path must be prepended
 *              with the VMP in order to identify the glusterfs
 *              context in which path resides.
 *
 * Returns a non-NULL handle on success and NULL on failure with errno
 * set appropriately.
 */
glusterfs_dir_t
glusterfs_opendir (const char *path);



/* Change the mode bits on an open file.
 *
 * @fd          : The file whose mode bits need to be changed.
 * @mode        : The new mode bits.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_fchmod (glusterfs_file_t fd, mode_t mode);



/* Sync the file contents to storage.
 *
 * @fd          : The file whose contents need to be sync'ed to
 *              storage.
 *
 * Return 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_fsync (glusterfs_file_t *fd);



/* Truncate an open file.
 *
 * @fd          : The file to truncate.
 * @length      : The length to truncate to.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_ftruncate (glusterfs_file_t fd, off_t length);



/* Create a hard link between two paths.
 *
 * @handle      : glusterfs context in which both paths should reside.
 * @oldpath     : The existing path to link to.
 * @newpath     : The new path which will be linked to @oldpath.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_link (glusterfs_handle_t handle, const char *oldpath,
                        const char *newpath);



/* Create a hard link between two paths.
 *
 * @oldpath     : The existing path to link to.
 * @newpath     : The new path which will be linked to @oldpath.
 *
 * Both paths should exist on the same glusterfs context and should be
 * prefixed with the same VMP.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_link (const char *oldpath, const char *newpath);



/* Get stats about the underlying file system.
 *
 * @handle      : Identifies the glusterfs context in which resides
 *              the given path.
 * @path        : stats are returned for the file system on which file
 *              is located.
 * @buf         : The buffer into which the stats are copied.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_statfs (glusterfs_handle_t handle, const char *path,
                        struct statfs *buf);



/* Get stats about the underlying file system.
 *
 * @path        : stats are returned for the file system on which file
 *              is located. @path must start with the VMP of the
 *              glusterfs context on which the file reside.
 * @buf         : The buffer into which the stats are copied.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_statfs (const char *path, struct statfs *buf);



/* Get stats about the underlying file system.
 *
 * @handle      : Identifies the glusterfs context in which resides
 *              the given path.
 * @path        : stats are returned for the file system on which file
 *              is located.
 * @buf         : The buffer into which the stats are copied.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_statvfs (glusterfs_handle_t handle, const char *path,
                   struct statvfs *buf);



/* Get stats about the underlying file system.
 *
 * @path        : stats are returned for the file system on which file
 *              is located. @path must start with the VMP of the
 *              glusterfs context on which the file reside.
 * @buf         : The buffer into which the stats are copied.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_statvfs (const char *path, struct statvfs *buf);



/* Set the atime and mtime values for a given path.
 *
 * @handle      : The handle identifying the glusterfs context.
 * @path        : The path for which the times need to be changed.
 * @times       : The array containing new time stamps for the file.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_utimes (glusterfs_handle_t handle, const char *path,
                        const struct timeval times[2]);



/* Set the atime and mtime values for a given path.
 *
 * @path        : The path for which the times need to be changed.
 * @times       : The array containing new time stamps for the file.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_utimes (const char *path, const struct timeval times[2]);



/* Set the atime and mtime values for a given path.
 *
 * @handle      : The handle identifying the glusterfs context.
 * @path        : The path for which the times need to be changed.
 * @buf         : The structure containing new time stamps for the file.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_utime (glusterfs_handle_t handle, const char *path,
                        const struct utimbuf *buf);



/* Set the atime and mtime values for a given path.
 *
 * @path        : The path for which the times need to be changed.
 * @buf         : The structure containing new time stamps for the file.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_utime (const char *path, const struct utimbuf *buf);



/*  Create  FIFO at the given path.
 *
 *  @handle     : The glusterfs context in which to create that FIFO.
 *  @path       : The path within the context where the FIFO is to be
 *              created.
 * @mode        : The mode bits for the newly create FIFO.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_mkfifo (glusterfs_handle_t handle, const char *path,
                        mode_t mode);



/*  Create  FIFO at the given path.
 *
 *  @path       : The path within the context where the FIFO is to be
 *              created. @path should begin with the VMP of the
 *              glusterfs context in which the FIFO needs to be
 *              created.
 * @mode        : The mode bits for the newly create FIFO.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_mkfifo (const char *path, mode_t mode);



/* Unlink a file.
 *
 * @handle      : Handle that identifies a glusterfs instance.
 * @path        : Path in the glusterfs instance that needs to be
 *              unlinked.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_unlink (glusterfs_handle_t handle, const char *path);



/* Unlink a file.
 *
 * @path        : Path in the glusterfs instance that needs to be
 *              unlinked.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_unlink (const char *path);



/* Create a symbolic link.
 *
 * @handle      : The handle identifying the glusterfs context.
 * @oldpath     : The existing path to which a symlink needs to be
 *              created.
 * @newpath     : The new path which will be symlinked to the
 *              @oldpath.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_symlink (glusterfs_handle_t handle, const char *oldpath,
                                const char *newpath);



/* Create a symbolic link.
 *
 * @oldpath     : The existing path to which a symlink needs to be
 *              created.
 * @newpath     : The new path which will be symlinked to the
 *              @oldpath.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_symlink (const char *oldpath, const char *newpath);



/* Read a symbolic link.
 *
 * @handle      : Handle identifying the glusterfs context.
 * @path        : The symlink that needs to be read.
 * @buf         : The buffer into which the target of @path will be
 *              stored.
 * @bufsize     : Size of the buffer allocated to @buf.
 *
 * Returns number of bytes copied into @buf and -1 on error with errno
 * set appropriately.
 */
ssize_t
glusterfs_glh_readlink (glusterfs_handle_t handle, const char *path, char *buf,
                                size_t bufsize);



/* Read a symbolic link.
 *
 * @path        : The symlink that needs to be read.
 * @buf         : The buffer into which the target of @path will be
 *              stored.
 * @bufsize     : Size of the buffer allocated to @buf.
 *
 * Returns number of bytes copied into @buf and -1 on error with errno
 * set appropriately.
 */
ssize_t
glusterfs_readlink (const char *path, char *buf, size_t bufsize);



/* Rename a file or directory.
 *
 * @handle      : The identifier of a glusterfs context.
 * @oldpath     : The path to be renamed.
 * @newpath     : The new name for the @oldpath.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_rename (glusterfs_handle_t handle, const char *oldpath,
                      const char *newpath);



/* Rename a file or directory.
 * @oldpath     : The path to be renamed.
 * @newpath     : The new name for the @oldpath.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_rename (const char *oldpath, const char *newpath);



/* Remove a file or directory in the given glusterfs context.
 *
 * @handle      : Handle identifying the glusterfs context.
 * @path        : Path of the file or directory to be removed.
 *
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_remove (glusterfs_handle_t handle, const char *path);



/* Remove a file or directory.
 *
 * @path        : Path of the file or directory to be removed. The
 *              path must be pre-fixed with the VMP.
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_remove (const char *path);



/* Change the owner of the given path.
 *
 * If @path is a symlink, the ownership change happens on the symlink.
 *
 * @handle      : Handle identifying the glusterfs client context.
 * @path        : Path whose owner needs to be changed.
 * @owner       : New owner ID
 * @group       : New Group ID
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */
int
glusterfs_glh_lchown (glusterfs_handle_t handle, const char *path, uid_t owner,
                      gid_t group);



/* Change the owner of the given path.
 *
 * If @path is a symlink, the ownership change happens on the symlink.
 *
 * @path        : Path whose owner needs to be changed.
 * @owner       : New owner ID
 * @group       : New Group ID
 *
 * Returns 0 on success and -1 on error with errno set appropriately.
 */

int
glusterfs_lchown (const char *path, uid_t owner, gid_t group);



/* Rewind directory stream pointer to beginning of the directory.
 *
 * @dirfd       : Directory handle returned by glusterfs_open on
 *              glusterfs_opendir.
 *
 * Returns no value.
 */
void
glusterfs_rewinddir (glusterfs_dir_t dirfd);



/* Seek to the given offset in the directory handle.
 *
 * @dirfd       : Directory handle returned by glusterfs_open on
 *              glusterfs_opendir.
 * @offset      : The offset to seek to.
 *
 * Returns no value.
 */
void
glusterfs_seekdir (glusterfs_dir_t dirfd, off_t offset);



/* Return the current offset in a directory stream.
 *
 * @dirfd       : Directory handle returned by glusterfs_open on
 *              glusterfs_opendir.
 *
 * Returns the offset in the directory or -1 on error with errno set
 * appropriately.
 */
off_t
glusterfs_telldir (glusterfs_dir_t dirfd);


/* Write count bytes from in_fd to out_fd, starting at *offset.
 * glusterfs_sendfile aims at eliminating memory copy at the end of
 * each read from in_fd, copying the file directly to out_fd from the buffer 
 * provided by glusterfs.
 *
 * @out_fd: file descriptor opened for writing
 *
 * @in_fd: glusterfs file handle to the file to be read from.
 *
 * @offset: If offset is not NULL, then it points to a variable holding the file
 *          offset  from  which  glusterfs_sendfile()  will  start reading data
 *          from in_fd.  When glusterfs_sendfile() returns, this variable will 
 *          be set to the offset of the byte following the last byte that was 
 *          read.  If offset is  not  NULL, then glusterfs_sendfile()  does  not
 *          modify the current file offset of in_fd; otherwise the current file
 *          offset is adjusted to reflect the number of bytes read from in_fd.
 *
 * @count:  number of bytes to copy between the file descriptors.
 */

ssize_t
glusterfs_sendfile (int out_fd, glusterfs_file_t in_fd, off_t *offset,
                    size_t count);

/* manipulate file descriptor
 * This api can have 3 forms similar to fcntl(2).
 *
 * int
 * glusterfs_fcntl (glusterfs_file_t fd, int cmd)
 *
 * int
 * glusterfs_fcntl (glusterfs_file_t fd, int cmd, long arg)
 *
 * int
 * glusterfs_fcntl (glusterfs_file_t fd, int cmd, struct flock *lock)
 *
 * @fd   : file handle returned by glusterfs_open or glusterfs_create.
 * @cmd  : Though the aim is to implement all possible commands supported by
 *         fcntl(2), currently following commands are supported.
 *         F_SETLK, F_SETLKW, F_GETLK -  used to acquire, release, and test for
 *                                       the existence of record locks (also 
 *                                       known as file-segment or file-region
 *                                       locks). More detailed explanation is
 *                                       found in 'man 2 fcntl'
 */
   
int
glusterfs_fcntl (glusterfs_file_t fd, int cmd, ...);

/*
 * Change the current working directory to @path
 * 
 * @path  : path to change the current working directory to.
 *
 * Returns 0 on success and -1 on failure with errno set appropriately.
 */
int
glusterfs_chdir (const char *path);

/*
 * Change the current working directory to the path @fd is opened on.
 *
 * @fd   : current working directory will be changed to path @fd is opened on.
 *
 * Returns 0 on success and -1 on  with errno set appropriately.
 */
int
glusterfs_fchdir (glusterfs_file_t fd);

/* copies the current working directory into @buf if it is big enough
 *
 * @buf: buffer to copy into it. If @buf is NULL, a buffer will be allocated.
 *       The size of the buffer will be @size if it is not zero, otherwise the
 *       size will be big enough to hold the current working directory.
 * @size: size of the buffer.
 *
 * Returns the pointer to buffer holding current working directory on success
 * and NULL on failure.
 */

char *
glusterfs_getcwd (char *buf, size_t size);

/*
 * Truncate the file to a specified length.
 *
 * @path   : path to the file.
 * @length : length to which the file has to be truncated.
 *
 * Returns 0 on success and -1 on failure with errno set appropriately 
 */

int
glusterfs_truncate (const char *path, off_t length);


/* FIXME: review the need for these apis */
/* added for log related initialization in booster fork implementation */
void
glusterfs_reset (void);

void
glusterfs_log_lock (void);

void
glusterfs_log_unlock (void);
/* Used to free the glusterfs_read_buf passed to the application from
   glusterfs_read_async_cbk
*/
void
glusterfs_free (glusterfs_iobuf_t *buf);

__END_DECLS

#endif /* !_LIBGLUSTERFSCLIENT_H */