-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcdfs.c
2270 lines (1304 loc) · 45.3 KB
/
cdfs.c
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
/*
2010, 2011 Stef Bon <[email protected]>
This program 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 2
of the License, or (at your option) any later version.
This program 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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "global-defines.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <err.h>
#include <sys/time.h>
#include <assert.h>
#include <syslog.h>
#include <time.h>
#include <inttypes.h>
// required??
#include <ctype.h>
#include <sys/types.h>
#include <pthread.h>
#include <sqlite3.h>
#ifdef HAVE_SETXATTR
#include <sys/xattr.h>
#endif
#ifndef ENOATTR
#define ENOATTR ENODATA /* No such attribute */
#endif
#include "logging.h"
#include "cdfs.h"
#include "cdfs-utils.h"
#include "fuse-loop-epoll-mt.h"
#include "entry-management.h"
#include "cdfs-options.h"
#include "cdfs-xattr.h"
#include "cdfs-cache.h"
#include "cdfs-cdromutils.h"
struct cdfs_commandline_options_struct cdfs_commandline_options;
struct cdfs_options_struct cdfs_options;
struct fuse_opt cdfs_help_options[] = {
CDFS_OPT("--device=%s", device, 0),
CDFS_OPT("device=%s", device, 0),
CDFS_OPT("--cache-directory=%s", cache_directory, 0),
CDFS_OPT("cache-directory=%s", cache_directory, 0),
CDFS_OPT("--progressfifo=%s", progressfifo, 0),
CDFS_OPT("progressfifo=%s", progressfifo, 0),
CDFS_OPT("logging=%i", logging, 0),
CDFS_OPT("--logging=%i", logging, 0),
CDFS_OPT("--cachebackend=%s", cachebackend, 0),
CDFS_OPT("cachebackend=%s", cachebackend, 0),
CDFS_OPT("--hashprogram=%s", hashprogram, 0),
CDFS_OPT("hashprogram=%s", hashprogram, 0),
CDFS_OPT("--discid=%s", discid, 0),
CDFS_OPT("discid=%s", discid, 0),
CDFS_OPT("--readaheadpolicy=%s", readaheadpolicy, 0),
CDFS_OPT("readaheadpolicy=%s", readaheadpolicy, 0),
FUSE_OPT_KEY("-V", KEY_VERSION),
FUSE_OPT_KEY("--version", KEY_VERSION),
FUSE_OPT_KEY("-h", KEY_HELP),
FUSE_OPT_KEY("--help", KEY_HELP),
FUSE_OPT_END
};
struct cdfs_device_struct cdfs_device;
static struct fuse_chan *cdfs_chan;
struct cdfs_entry_struct *root_entry;
unsigned long long inoctr = FUSE_ROOT_ID;
unsigned long long nrinodes = 0;
unsigned char loglevel=0;
static void cdfs_lookup(fuse_req_t req, fuse_ino_t parentino, const char *name)
{
struct fuse_entry_param e;
struct cdfs_entry_struct *entry;
struct cdfs_entry_struct *pentry;
struct cdfs_inode_struct *pinode;
int nreturn=0;
unsigned char entrycreated=0;
logoutput2("LOOKUP, name: %s", name);
entry=find_entry(parentino, name);
if ( ! entry ) {
pinode=find_inode(parentino);
if ( pinode ) {
pentry=pinode->alias;
// create the entry, assign the inode only when successfull
entry=create_entry(pentry, name, NULL);
if ( ! entry ) {
nreturn=-ENOMEM;
goto out;
}
} else {
nreturn=-ENOENT;
goto out;
}
entrycreated=1;
}
nreturn=stat_track(entry, &(e.attr));
if ( nreturn==-ENOENT) {
logoutput2("lookup: entry does not exist (ENOENT)");
if ( entrycreated==0 ) remove_entry_from_name_hash(entry);
remove_entry(entry);
e.ino = 0;
e.entry_timeout = cdfs_options.negative_timeout;
} else if ( nreturn<0 ) {
logoutput1("do_lookup: error (%i)", nreturn);
// some correction/action here?
} else {
// no error
if ( entrycreated==1 ) {
assign_inode(entry);
add_to_inode_hash_table(entry->inode);
add_to_name_hash_table(entry);
if ( entry->type==ENTRY_TYPE_TEMPORARY ) entry->type=ENTRY_TYPE_NORMAL;
}
entry->inode->nlookup++;
e.ino = entry->inode->ino;
e.attr.st_ino = e.ino;
e.generation = 0;
e.attr_timeout = cdfs_options.attr_timeout;
e.entry_timeout = cdfs_options.entry_timeout;
logoutput2("lookup return size: %zi", e.attr.st_size);
}
out:
logoutput1("lookup: return %i", nreturn);
if ( nreturn<0 ) {
fuse_reply_err(req, -nreturn);
} else {
fuse_reply_entry(req, &e);
}
}
static void cdfs_forget(fuse_req_t req, fuse_ino_t ino, unsigned long nlookup)
{
struct cdfs_inode_struct *inode;
inode = find_inode(ino);
if ( ! inode ) goto out;
logoutput0("FORGET");
if ( inode->nlookup < nlookup ) {
logoutput0("internal error: forget ino=%llu %llu from %llu", (unsigned long long) ino, (unsigned long long) nlookup, (unsigned long long) inode->nlookup);
}
inode->nlookup -= nlookup;
logoutput2("forget, current nlookup value %llu", (unsigned long long) inode->nlookup);
out:
fuse_reply_none(req);
}
static void cdfs_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
{
struct stat st;
struct cdfs_entry_struct *entry;
struct cdfs_inode_struct *inode;
int nreturn=0;
//
// fi not used yet here...
// otherwise the fi->fd could be used for getting the attr
//
logoutput0("GETATTR");
if ( fi ) {
logoutput2("fi not empty..");
}
// get the inode and the entry, they have to exist
inode=find_inode(ino);
if ( ! inode ) {
nreturn=-ENOENT;
goto out;
}
entry=inode->alias;
if ( ! entry ) {
nreturn=-ENOENT;
goto out;
}
nreturn=stat_track(entry, &st);
out:
logoutput1("getattr, return: %i", nreturn);
if (nreturn < 0) {
fuse_reply_err(req, -nreturn);
} else {
fuse_reply_attr(req, &st, cdfs_options.attr_timeout);
}
}
//
// determine the stat given a direntry
// possibly the corresponding entry does not exist, if so create it here
// return:
// 0 no error, just display the entry
// 1 no error, hide the entry
// negative: error
//
static int get_direntry_stat(struct cdfs_generic_dirp_struct *dirp)
{
int nreturn=0;
bool entrycreated=false;
char *name;
dirp->st.st_mode = dirp->direntry.d_type << 12;
name=dirp->direntry.d_name;
logoutput2("get_direntry_stat, name: %s", name);
if (strcmp(name, ".") == 0) {
dirp->st.st_ino = dirp->generic_fh.entry->inode->ino;
} else if (strcmp(name, "..") == 0) {
if (dirp->generic_fh.entry->type == ENTRY_TYPE_ROOT ) {
dirp->st.st_ino = FUSE_ROOT_ID;
} else {
dirp->st.st_ino = dirp->generic_fh.entry->parent->inode->ino;
}
} else {
//
// "normal entry": look there is already an entry for this, a leftover from the previous batch
//
if ( dirp->entry ) {
// check the current dirp->entry is the right one
if ( strcmp(dirp->entry->name, name)!=0 ) dirp->entry=NULL;
}
if ( ! dirp->entry ) dirp->entry = find_entry(dirp->generic_fh.entry->inode->ino, name);
if ( ! dirp->entry) {
// entry is not found: create a new one
dirp->entry = new_entry(dirp->generic_fh.entry->inode->ino, name);
if ( ! dirp->entry ) {
nreturn=-ENOMEM;
goto out;
}
entrycreated=true;
}
if ( ! dirp->entry->inode ) {
logoutput0("get_direntry_stat, inode not attached");
nreturn=-ENOENT;
}
dirp->st.st_ino = dirp->entry->inode->ino;
if ( entrycreated ) {
add_to_inode_hash_table(dirp->entry->inode);
add_to_name_hash_table(dirp->entry);
if ( dirp->entry->type==ENTRY_TYPE_TEMPORARY ) dirp->entry->type=ENTRY_TYPE_NORMAL;
}
}
out:
logoutput2("get_direntry_stat: return %i", nreturn);
return nreturn;
}
static inline struct cdfs_generic_dirp_struct *get_dirp(struct fuse_file_info *fi)
{
return (struct cdfs_generic_dirp_struct *) (uintptr_t) fi->fh;
}
static void free_dirp(struct cdfs_generic_dirp_struct *dirp)
{
free(dirp);
}
//
// open a directory to read the contents
// here the backend is an audio cdrom, with only one root directory, and
// no subdirectories
//
// so in practice this will be called only for the root
// it's not required to build an extra check we're in the root, the
// VFS will never allow this function to be called on something else than a directory
//
static void cdfs_opendir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
{
struct cdfs_generic_dirp_struct *dirp=NULL;
int nreturn=0;
struct cdfs_entry_struct *entry;;
struct cdfs_inode_struct *inode;
logoutput0("OPENDIR");
inode=find_inode(ino);
if ( ! inode ) {
nreturn=-ENOENT;
goto out;
}
entry=inode->alias;
if ( ! entry ) {
nreturn=-ENOENT;
goto out;
}
dirp = malloc(sizeof(struct cdfs_generic_dirp_struct));
if ( ! dirp ) {
nreturn=-ENOMEM;
goto out;
}
memset(dirp, 0, sizeof(struct cdfs_generic_dirp_struct));
dirp->entry=NULL;
dirp->upperfs_offset=0;
dirp->underfs_offset=1; /* start at 1: first track */
dirp->generic_fh.entry=entry;
dirp->direntry.d_name[0]='\0';
dirp->direntry.d_type=0;
// assign this object to fi->fh
fi->fh = (unsigned long) dirp;
out:
if ( nreturn<0 ) {
if ( dirp ) free_dirp(dirp);
fuse_reply_err(req, -nreturn);
} else {
fuse_reply_open(req, fi);
}
logoutput1("opendir, nreturn %i", nreturn);
}
//
// reads a "direntry" from the cdrom
// simply look at the underfs_offset to determine the track
// note: the direntry should already be allocated, and part
// of dirp (and thus not to be freed!)
//
// the first 1 <=...<= cdda_tracks(cdd) are just the tracks
// cdda_tracks(cdd)+1 is the .
// cdda_tracks(cdd)+2 is the ..
//
// return: 1 success, 0 end (nothing for error)
static int readdir_cdrom(struct cdfs_generic_dirp_struct *dirp)
{
int nreturn=0;
if ( dirp->underfs_offset <= cdfs_device.nrtracks ) {
dirp->direntry.d_type=DT_REG;
sprintf(dirp->direntry.d_name, "track-%.2d.wav", dirp->underfs_offset);
nreturn=1;
} else if ( dirp->underfs_offset==cdfs_device.nrtracks+1 ) {
dirp->direntry.d_type=DT_DIR;
sprintf(dirp->direntry.d_name, ".");
nreturn=1;
} else if ( dirp->underfs_offset==cdfs_device.nrtracks+2 ) {
dirp->direntry.d_type=DT_DIR;
sprintf(dirp->direntry.d_name, "..");
nreturn=1;
}
dirp->underfs_offset+=nreturn;
return nreturn;
}
static int do_readdir_localhost(fuse_req_t req, char *buf, size_t size, off_t upperfs_offset, struct cdfs_generic_dirp_struct *dirp)
{
size_t bufpos = 0;
int res, nreturn=0;
size_t entsize;
bool validentryfound=false;
bool direntryfrompreviousbatch=false;
logoutput0("DO_READDIR, offset: %"PRId64, upperfs_offset);
dirp->upperfs_offset=upperfs_offset;
if ( dirp->upperfs_offset==0 ) dirp->upperfs_offset=1;
if ( strlen(dirp->direntry.d_name)>0 ) direntryfrompreviousbatch=true;
while (bufpos < size ) {
//
// no valid entry found yet (the purpose here is to find valid entries right?)
// (or there is still on attached to dirp)
// search a new direntry
validentryfound=false;
// start a "search" through the directory stream to the first valid next entry
while ( ! validentryfound ) {
// read next entry (only when not one attached to dirp)
if ( strlen(dirp->direntry.d_name)==0 ) {
// read a direntry from the cdrom
direntryfrompreviousbatch=false;
res=readdir_cdrom(dirp);
if ( res==0 ) {
// no direntry from readdir, look at what's causing this
nreturn=0;
goto out;
}
}
if ( ! dirp->entry ) {
// translate it into a entry
res=get_direntry_stat(dirp);
if ( res<0 ) {
nreturn=res;
goto out;
}
}
validentryfound=true;
if ( dirp->entry ) {
// an entry is attached only when it's not . and ..
// but these will never be hidden, so these are always valid
if ( dirp->entry->hide==1 && cdfs_options.global_nohide==0 ) {
logoutput3("hide entry: %s", dirp->entry->name);
validentryfound=false;
}
}
}
// store the next offset (of course of the underlying fs)
// this is after the readdir, so is pointing to the next direntry
if ( ! direntryfrompreviousbatch ) {
// a valid direntry not from a previous batch is here, so the offset has to be increased
dirp->upperfs_offset+=1;
}
logoutput2("adding %s to dir buffer", dirp->direntry.d_name);
entsize = fuse_add_direntry(req, buf + bufpos, size - bufpos, dirp->direntry.d_name, &dirp->st, dirp->upperfs_offset);
// break when buffer is not large enough
// function fuse_add_direntry has not added it when buffer is too small to hold direntry,
// only returns the requested size
if (entsize > size - bufpos) {
// the direntry does not fit in buffer
// (keep the current direntry and entry attached)
break;
}
logoutput2("increasing buffer with %zi", entsize);
bufpos += entsize;
dirp->direntry.d_name[0]='\0';
dirp->direntry.d_type=0;
}
out:
if (nreturn<0) {
logoutput1("do_readdir, return: %i", nreturn);
// if a real error: return that
return nreturn;
} else {
logoutput1("do_readdir, return: %zu", bufpos);
return bufpos;
}
}
static void cdfs_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t offset, struct fuse_file_info *fi)
{
struct cdfs_generic_dirp_struct *dirp = get_dirp(fi);
char *buf;
int nreturn=0;
logoutput0("READDIR");
// look what readdir has to be called
buf = malloc(size);
if (buf == NULL) {
nreturn=-ENOMEM;
goto out;
}
nreturn=do_readdir_localhost(req, buf, size, offset, dirp);
out:
if (nreturn < 0 ) {
fuse_reply_err(req, -nreturn);
} else {
fuse_reply_buf(req, buf, nreturn);
}
logoutput1("readdir, nreturn %i", nreturn);
if ( buf ) free(buf);
}
static void cdfs_releasedir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
{
struct cdfs_generic_dirp_struct *dirp = get_dirp(fi);
(void) ino;
logoutput0("RELEASEDIR");
fuse_reply_err(req, 0);
free_dirp(dirp);
fi->fh=0;
}
static void cdfs_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
{
int flags = (fi->flags & O_ACCMODE);
int nreturn=0, fd=0, res;
struct cdfs_entry_struct *entry=NULL;
struct cdfs_inode_struct *inode=NULL;
int tracknr;
struct caching_data_struct *caching_data=NULL;
struct track_info_struct *track_info;
logoutput0("OPEN");
inode=find_inode(ino);
if ( ! inode ) {
nreturn=-ENOENT;
goto out;
}
entry=inode->alias;
if ( ! entry ) {
nreturn=-ENOENT;
goto out;
}
fi->direct_io=0;
//
// here look the buffer is present in the cache: if yes take that one
//
// if not what happens next:
//
// - whole buffer has to be cached -> command to the cdrom reader to read the whole buffer and wait for it to finish ( condition message...)
//
// - part(s) are already cached, just split in different commands to the cdrom reader
//
// what to do ??
// if buffer is from a till c
// and a to b ( a<b<c ) is cached and b to c not
// just reply with a - b and send a command to the cdrom reader to read b - c. (and let it do a cond broadcast.....)
//
tracknr=get_tracknr(entry->name);
if ( tracknr==0 ) {
nreturn=-ENOENT;
goto out;
}
// check and/or create the file in the cache
// get an fd of this file
// write the header to this file
// and create a initial cached_block for this
caching_data = ( struct caching_data_struct *) entry->data;
if ( ! caching_data ) {
// not found: probably the first time here
caching_data=create_caching_data();
if ( ! caching_data ) {
nreturn=-ENOMEM;
goto out;
}
// the cachefile is stored in the cachedirectory with the same name as the entry,,,, very simple
snprintf(caching_data->path, PATH_MAX, "%s/%s", cdfs_options.cache_directory, entry->name);
entry->data=(void *) caching_data;
caching_data->tracknr=tracknr;
track_info = (struct track_info_struct *) (cdfs_device.track_info + ( tracknr - 1 ) * sizeof(struct track_info_struct));
caching_data->size=get_size_track(tracknr);
caching_data->startsector=track_info->firstsector_lsn;
caching_data->endsector=track_info->lastsector;
nreturn=create_cache_file(caching_data, entry->name);
if ( nreturn<0 ) {
/* possible error creating file in cache */
goto out;
} else if ( nreturn==0 ) {
// existing file found
if ( cdfs_options.cachebackend == CDFS_CACHE_ADMIN_BACKEND_SQLITE ) {
nreturn=get_intervals_from_sqlite(caching_data);
}
} else if ( nreturn==1 ) {
//
// file created, did not exist...
// the first block should be the header
//
char *header=malloc(SIZE_RIFFHEADER);
if ( header ) {
write_wavheader(header, caching_data->size);
res=write_to_cached_file(caching_data, header, 0, SIZE_RIFFHEADER);
if ( res<0 ) {
nreturn=res;
goto out;
}
}
res=remove_all_intervals_sqlite(tracknr);
}
}
fd=open(caching_data->path, O_RDONLY);
if ( fd==-1 ) {
nreturn=-errno;
goto out;
}
fi->fh=fd;
fi->keep_cache=1;
fi->nonseekable=0;
out:
if (nreturn < 0) {
fuse_reply_err(req, -nreturn);
} else {
fuse_reply_open(req, fi);
}
logoutput1("open nreturn: %i", nreturn);
}
static void cdfs_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi)
{
int nreturn=0, res;
struct cdfs_entry_struct *entry=NULL;
struct cdfs_inode_struct *inode=NULL;
struct caching_data_struct *caching_data=NULL;
struct cached_block_struct *cached_block=NULL;
off_t off_exheader;
size_t headerlen=0, size_exheader;
int startsector, endsector, tmpsector;
char *buffer=NULL;
unsigned char buffalloc=0, cachereadlock=0;
bool notfound;
struct read_call_struct *read_call=NULL;
if ( size>0 ) {
logoutput0("READ, offset %"PRIu64" and size (>0) %zi", off, size);
} else {
logoutput0("READ, offset %"PRIu64" and size zero", off);
}
inode=find_inode(ino);
if ( ! inode ) {
nreturn=-ENOENT;
goto out;
}
entry=inode->alias;
if ( ! entry ) {
nreturn=-ENOENT;
goto out;
}
caching_data = ( struct caching_data_struct *) entry->data;
if ( ! caching_data ) {
nreturn=-EIO;
goto out;
}
buffer=malloc(size);
if ( ! buffer ) {
nreturn=-ENOMEM;
goto out;
}
buffalloc=1;
if ( off + size < SIZE_RIFFHEADER ) {
// bytes requested totally from header
// this header is already present in the cache file
res=pread(fi->fh, buffer, size, off);
if ( res<0 ) {
nreturn=-errno;
} else {
nreturn=res;
}
} else if ( caching_data->ready==1 ) {
// every available in cache: there is no need to investigate and possibly
// wait for sectors to become available ( and also not to read ahead)
res=pread(fi->fh, buffer, size, off);