-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjbFS.c
2090 lines (1888 loc) · 83.2 KB
/
jbFS.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
/*
FUSE: Filesystem in Userspace
Operating Systems - CS 3224
HW 2 - Filesystem
* Initialized from fusemp_fh.c
* Programmer: Joseph Bieselin
gcc -Wall jbFS.c `pkg-config fuse --cflags --libs` -o jbFS
*/
#define FUSE_USE_VERSION 26
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#define _GNU_SOURCE
#include <fuse.h>
//#include <ulockmgr.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <sys/time.h>
// Filesystem Constants (these can be changed later)
#define MAX_NUM_BLOCKS 10000 // number of blocks in the filesystem
#define MAX_FILE_SIZE 1638400 // max size in bytes of a file
#define BLOCK_SIZE 4096 // size in bytes of a block
#define MAX_BLOCK_DIGITS 10 // the number of digits in MAX_NUM_BLOCKS won't exceed MAX_BLOCK_DIGITS-1
#define MAX_PATH_LENGTH 100 // the number of chars a file's pathname could be
#define MAX_FILENAME_LEN 3800// based on how large a filename could fit in root dir if it were the only entry
#define FREE_START 1 // start of the free block list
#define FREE_END 25 // end of the free block list (must be enough blocks between start and end to hold values representing MAX_NUM_BLOCKS)
#define ROOT 26 // block for root dir
#define BLOCKS_IN_FREE 400 // number of free blocks to store in the free block list files on filesystem creation
#define UID 1 // user id (does not matter too much for this filesystem)
#define GID 1 // group id (does not matter too much for this filesystem)
#define DIR_UID 1000 // user id for a directory
#define DIR_GID 1000 // group id for a directory
// Other Constants
#define FILES_DIR "/fusedata" // directory to put fusedata.X files
#define LOG_FILE "~/Desktop/log.txt" // log file
void logmsg(const char *s)
{
FILE *f = fopen(LOG_FILE, "a");
fprintf(f, "%s\n\n", s);
fclose(f);
}
// Return true if the passed in cstring is a file that exists; false otherwise
int file_exists(const char* name)
{
struct stat buf;
int status;
status = stat(name, &buf);
return status == 0;
}
// takes in a buffer with data already in it and writes it to the file stream, returning a non-zero error value if the buffer contents were not fully written
static int write_to_file(char *buf, FILE *file_stream)
{
// write 1 entry of strlen(buf) size bytes from buf to the file_stream (if 1 entry of that size bytes was not written, there was an error)
if ( fwrite(buf, strlen(buf), 1, file_stream) != 1 ) {
logmsg("FAILURE:\twrite_to_file\tfwrite");
return -errno;
}
return 0;
}
// writes BLOCK_SIZE number of 0's to the file; returns 0 on success, -1 on failure
static int reset_block(FILE *fd)
{
rewind(fd);
char buf[BLOCK_SIZE + 1];
int char_zero = '0';
memset(buf, char_zero, BLOCK_SIZE);
if (write_to_file(buf, fd) != 0) {
logmsg("reset_block failed to reset file");
return -1;
}
rewind(fd);
return 0;
}
/* count the number of times ch appears in the string
* Function was created by stackoverflow user 'Jon' and can be found at the URL below:
* http://stackoverflow.com/questions/7349053/counting-the-number-of-times-a-character-occurs-in-a-string-in-c
*/
int count_chars(const char* string, char ch)
{
int count = 0;
for(; *string; count += (*string++ == ch)) ;
return count;
}
// adds the free block number back to the appropriate free block list file and returns 0 upon success
static int add_free_block(unsigned int free_block_num)
{
// get the free block file number that the free block should go back into and open that file
unsigned int free_block_file_num = free_block_num / BLOCKS_IN_FREE;
free_block_file_num++;
// open the fusedata.X file associated with the free block number passed
char *fusedata_str = (char *) calloc(1, MAX_PATH_LENGTH);
sprintf(fusedata_str, "fusedata.%u", free_block_file_num);
FILE *free_block_file = fopen(fusedata_str, "r+");
// set up some variables
char *temp = (char *) calloc(1, BLOCK_SIZE);
char *buf; // = (char *) calloc(1, BLOCK_SIZE); // free(buf) not needed because strtok passes back a pointer to the contents of the string being tokenized
// get the entire contents of the free block file into a temp variable
fread(temp, BLOCK_SIZE, 1, free_block_file);
rewind(free_block_file);
// tokenize the file contents by commas
buf = strtok(temp, ",");
// if the file was all 0's, just add the free_block_num along with a comma to the beginning
if (strlen(buf) == BLOCK_SIZE) {
char *free_block_num_str = (char *) calloc(1, BLOCK_SIZE);
sprintf(free_block_num_str, "%u,", free_block_num);
if ( write_to_file(free_block_num_str, free_block_file) != 0) {
free(temp); free(free_block_num_str); free(fusedata_str); fclose(free_block_file);
printf("FAILURE:\tadd_free_block\tstrlen(buf)==BLOCK_SIZE\twrite_to_file");
return -1;
}
free(temp); free(free_block_num_str); free(fusedata_str); fclose(free_block_file);
return 0;
} else {
// new_file_content will contain all previous blocks in the free block list plus the new number passed in
char *new_file_content = (char *) calloc(1, BLOCK_SIZE);
unsigned int some_free_block;
while( buf != NULL ) {
// turn the number into an int to test if it is just a 0
some_free_block = atoi(buf);
// if it's not a 0, add it the string that will be written back to the file
if (some_free_block != 0) {
strcat(new_file_content, buf);
strcat(new_file_content, ",");
}
// get the next value in between commas
buf = strtok(NULL, ",");
}
// put the new free_block_num along with a comma at the end of free block list in this file
sprintf(temp, "%u,", free_block_num);
strcat(new_file_content, temp);
if ( write_to_file(new_file_content, free_block_file) != 0 ) {
free(temp); free(buf); free(new_file_content); free(fusedata_str); fclose(free_block_file);
printf("FAILURE:\tadd_free_block\telse statement\twrite_to_file");
return -1;
}
free(temp); free(buf); free(new_file_content); free(fusedata_str); fclose(free_block_file);
return 0;
}
}
// removes the next free block from the file and returns 0 upon success
static int remove_next_free_block(unsigned int next_free_block, char *buf, FILE *fd)
{
rewind(fd);
// get the length of digits of the first free block number in the file
unsigned int next_free_block_len;
char *next_free_block_str = (char *) calloc(1, BLOCK_SIZE);
sprintf(next_free_block_str, "%u", next_free_block);
next_free_block_len = strlen(next_free_block_str);
// append 0's to the contents of the file to replace the length of the free block number and the comma following it
int i;
for (i = 0; i <= next_free_block_len; ++i) {
strcat(buf, "0");
}
// put the buffer without the removed free block back into the file
if ( write_to_file(buf, fd) != 0 ) {
logmsg("FAILURE:\tremove_next_free_block\twrite_to_file");
free(next_free_block_str);
return -1;
}
// the next free block was successfully removed and the free file list block was updated
free(next_free_block_str);
rewind(fd);
return 0;
}
// returns an int that is the number of the next free block; if there are no free blocks, return -1
static int next_free_block()
{
// set up variables
int i;
unsigned int next_free_block;
char *fusedata_str = (char *) calloc(1, MAX_PATH_LENGTH);
FILE *free_block_file;
char *temp = (char *) calloc(1, BLOCK_SIZE);
char *buf = (char *) calloc(1, BLOCK_SIZE);
char *next_free_block_str;
unsigned int temp_int;
// loop through all free block list files if necessary
for (i = FREE_START; i <= FREE_END; ++i) {
// append the number of the start of the free block list file and then open it
sprintf(fusedata_str, "fusedata.%d", i);
free_block_file = fopen(fusedata_str, "r+");
// get the entire contents of the free block file
fread(temp, BLOCK_SIZE, 1, free_block_file);
rewind(free_block_file);
// tokenize the file contents by commas
next_free_block_str = strtok(temp, ",");
// if there were no free blocks in the file, continue to the next file
if (strlen(next_free_block_str) == BLOCK_SIZE) {
fclose(free_block_file);
continue;
} else {
// put the next_free_block in a variable that will be returned
next_free_block = atoi(next_free_block_str);
// get the next_free_block after the first one in this list
next_free_block_str = strtok(NULL, ",");
// keep going so long as that is not the end of the string
while ( next_free_block_str != NULL ) {
temp_int = atoi(next_free_block_str);
// if the tokenized string was not a zero, add that to the buffer along with a comma
if (temp_int != 0) {
strcat(buf, next_free_block_str);
strcat(buf, ",");
}
next_free_block_str = strtok(NULL, ",");
}
remove_next_free_block(next_free_block, buf, free_block_file);
free(temp); free(buf); free(next_free_block_str); fclose(free_block_file);
return next_free_block;
}
}
free(temp); free(buf);
// we got through all the free block files and there were no free blocks to return
return -1;
}
// creates an inode block with a location that points to the file_block number; returns 0 on success
static int create_inode(unsigned int inode_block, unsigned int file_block)
{
// open the fusedata block corresponding to this new inode_block number
char inode_block_str[BLOCK_SIZE + 1];
sprintf(inode_block_str, "fusedata.%u", inode_block);
FILE *fd = fopen(inode_block_str, "r+");
/* file inode format:
* {size:0, uid:1, gid:1, mode:33261, linkcount:1, atime:332442342, ctime:332442342, mtime:332442342,
* indirect:0, location:2444}
* size of the file is initially 0, there is only 1 link to the file at creation, there is no
* indirect initially because we don't know how large the file will be yet
*/
// get creation time of this inode in reference to the Epoch
char creation_time_str[21]; // For 2014, time since Epoch would be 10 digits (so 20 possible digits is okay for now)
sprintf(creation_time_str, "%lu", time(NULL)); // put the an unsigned int representing time directly into the creation_time_str string
char buf[BLOCK_SIZE + 1];
sprintf(buf, "{size:0, uid:%d, gid:%d, mode:33261, linkcount:1, atime:%s, ctime:%s, mtime:%s, indirect:0, location:%u}", UID, GID, creation_time_str, creation_time_str, creation_time_str, file_block);
if ( write_to_file(buf, fd) != 0 ) {
logmsg("FAILURE:\tcreate_inode\twrite_to_file");
fclose(fd);
return -1;
}
return 0;
}
// creates a directory inode block with to 2 links in inode_dict ('.' to self, '..' to parent); returns 0 on success
static int create_dir(unsigned int dir_block, unsigned int parent_block)
{
// open the fusedata block corresponding to this new dir_block number
char dir_block_str[BLOCK_SIZE + 1];
sprintf(dir_block_str, "fusedata.%u", dir_block);
FILE *fd = fopen(dir_block_str, "r+");
/* directory format:
* {size:BLOCK_SIZE, uid:1000, gid:1000, mode:16877, atime:332442342, ctime:332442342, mtime:332442342, linkcount:2,
* filename_to_inode_dict: {d:.:dir_block,d:..:parent_block}}
* size of the block is the block size, there is only 2 links initially (this dir and the parent dir)
*/
// get creation time of this directory in reference to the Epoch
char creation_time_str[21]; // For 2014, time since Epoch would be 10 digits (so 20 possible digits is okay for now)
sprintf(creation_time_str, "%lu", time(NULL)); // put the an unsigned int representing time directly into the creation_time_str string
char buf[BLOCK_SIZE + 1];
sprintf(buf, "{size:%d, uid:%d, gid:%d, mode:16877, atime:%s, ctime:%s, mtime:%s, linkcount:2, filename_to_inode_dict: {d:.:%u,d:..:%u}}", BLOCK_SIZE, DIR_UID, DIR_GID, creation_time_str, creation_time_str, creation_time_str, dir_block, parent_block);
if ( write_to_file(buf, fd) != 0 ) {
logmsg("FAILURE:\tcreate_inode\twrite_to_file");
fclose(fd);
return -1;
}
fclose(fd);
return 0;
}
// type (0==dir, 1==file); when atime, ctime, or mtime is 1, the passed in FILE stream's respective time fields get updated; returns a 1 if the new file size will be too large
static int update_time(unsigned int type, unsigned int atime, unsigned int ctime, unsigned int mtime, FILE *fd)
{
// get the current time
char new_time[BLOCK_SIZE];
sprintf(new_time, "%lu,", time(NULL));
// variables to be used in fscanf function of the file stream
char buf[BLOCK_SIZE + 1];
char size[BLOCK_SIZE]; char uid[BLOCK_SIZE]; char gid[BLOCK_SIZE]; char mode[BLOCK_SIZE]; char linkcount[BLOCK_SIZE];
char atime_str[BLOCK_SIZE]; int old_atime;
char ctime_str[BLOCK_SIZE]; int old_ctime;
char mtime_str[BLOCK_SIZE]; int old_mtime;
char fname_inode[BLOCK_SIZE]; char inodes[BLOCK_SIZE];
char indirect[BLOCK_SIZE]; char location[BLOCK_SIZE];
char temp[10];
// format will be for a directory
if (type == 0) {
// for whichever time value is equal to 1, update that time field with the new_time set at the beginning of the function
if (atime == 1) {
fscanf(fd, "%s %s %s %s %6c%i%*c %6c%i%*c %6c%i%*c %s %s %s", size, uid, gid, mode, atime_str, &old_atime, ctime_str, &old_ctime, mtime_str, &old_mtime, linkcount, fname_inode, inodes);
if (sprintf(buf, "%s %s %s %s atime:%s ctime:%i, mtime:%i, %s %s %s", size, uid, gid, mode, new_time, old_ctime, old_mtime, linkcount, fname_inode, inodes) > BLOCK_SIZE) {
return 1;
}
rewind(fd);
if ( write_to_file(buf, fd) != 0 ) {
return -1;
}
fread(temp, 1, 1, fd); rewind(fd);
}
if (ctime == 1) {
fscanf(fd, "%s %s %s %s %6c%i%*c %6c%i%*c %6c%i%*c %s %s %s", size, uid, gid, mode, atime_str, &old_atime, ctime_str, &old_ctime, mtime_str, &old_mtime, linkcount, fname_inode, inodes);
if (sprintf(buf, "%s %s %s %s atime:%i, ctime:%s mtime:%i, %s %s %s", size, uid, gid, mode, old_atime, new_time, old_mtime, linkcount, fname_inode, inodes) > BLOCK_SIZE) {
return 1;
}
rewind(fd);
if ( write_to_file(buf, fd) != 0 ) {
return -1;
}
fread(temp, 1, 1, fd); rewind(fd);
}
if (mtime == 1) {
fscanf(fd, "%s %s %s %s %6c%i%*c %6c%i%*c %6c%i%*c %s %s %s", size, uid, gid, mode, atime_str, &old_atime, ctime_str, &old_ctime, mtime_str, &old_mtime, linkcount, fname_inode, inodes);
if (sprintf(buf, "%s %s %s %s atime:%i, ctime:%i, mtime:%s %s %s %s", size, uid, gid, mode, old_atime, old_ctime, new_time, linkcount, fname_inode, inodes) > BLOCK_SIZE) {
return 1;
}
rewind(fd);
if ( write_to_file(buf, fd) != 0 ) {
return -1;
}
fread(temp, 1, 1, fd); rewind(fd);
}
return 0;
} else { // format will be for a file
// for whichever time value is equal to 1, update that time field with the new_time set at the beginning of the function
if (atime == 1) {
fscanf(fd, "%s %s %s %s %s %6c%i%*c %6c%i%*c %6c%i%*c %s %s", size, uid, gid, mode, linkcount, atime_str, &old_atime, ctime_str, &old_ctime, mtime_str, &old_mtime, indirect, location);
if (sprintf(buf, "%s %s %s %s %s atime:%s ctime:%i, mtime:%i, %s %s", size, uid, gid, mode, linkcount, new_time, old_ctime, old_mtime, indirect, location) > BLOCK_SIZE) {
return 1;
}
rewind(fd);
if ( write_to_file(buf, fd) != 0 ) {
return -1;
}
fread(temp, 1, 1, fd); rewind(fd);
}
if (ctime == 1) {
fscanf(fd, "%s %s %s %s %s %6c%i%*c %6c%i%*c %6c%i%*c %s %s", size, uid, gid, mode, linkcount, atime_str, &old_atime, ctime_str, &old_ctime, mtime_str, &old_mtime, indirect, location);
if (sprintf(buf, "%s %s %s %s %s atime:%i, ctime:%s mtime:%i, %s %s", size, uid, gid, mode, linkcount, old_atime, new_time, old_mtime, indirect, location) > BLOCK_SIZE) {
return 1;
}
rewind(fd);
if ( write_to_file(buf, fd) != 0 ) {
return -1;
}
fread(temp, 1, 1, fd); rewind(fd);
}
if (mtime == 1) {
fscanf(fd, "%s %s %s %s %s %6c%i%*c %6c%i%*c %6c%i%*c %s %s", size, uid, gid, mode, linkcount, atime_str, &old_atime, ctime_str, &old_ctime, mtime_str, &old_mtime, indirect, location);
if (sprintf(buf, "%s %s %s %s %s atime:%i, ctime:%i, mtime:%s %s %s", size, uid, gid, mode, linkcount, old_atime, old_ctime, new_time, indirect, location) > BLOCK_SIZE) {
return 1;
}
rewind(fd);
if ( write_to_file(buf, fd) != 0 ) {
return -1;
}
fread(temp, 1, 1, fd); rewind(fd);
}
return 0;
}
}
// returns the block number if name and type match the entry; name = file/dir name to search for, type (0==dir, 1==file), entry = "type:name:block_number"
static int compare_dir_entry(char *name, unsigned int type, char *entry)
{
// entry_vals shall contain three indexes: 0 = type ('f' or 'd'), 1 = name, 2 = block_number
char *entry_vals[3];
int i = 0;
entry_vals[i] = strtok(entry, ":");
while (entry_vals[i++] != NULL) {
entry_vals[i] = strtok(NULL, ":");
}
// if type we are looking for matches the type of this entry, check the name
if ( ( (type == 0) && (strcmp("d", entry_vals[0]) == 0) ) || ( (type == 1) && (strcmp("f", entry_vals[0]) == 0) ) ) {
// if the passed in name matches the entry's name, return the entry's block_number
if ( strcmp(name, entry_vals[1]) == 0 ) {
int block_num = atoi(entry_vals[2]);
//return entry_vals[2];
return block_num;
}
}
// either the types did not match or the names did not match, so return -1
return -1;
}
// searches for name inside of the fusedata.X block corresponding to dir_block; type (0==dir, 1==file); return the block number if name is found and the types match
static int search_dir(char *name, unsigned int type, unsigned int dir_block)
{
// open the file corresponding to fusedata.dir_block
char block_str[BLOCK_SIZE];
sprintf(block_str, "fusedata.%u", dir_block);
FILE *fd = fopen(block_str, "r+");
// update the access time of the directory since we are searching through it
int temp = update_time(0, 1, 0, 0, fd);
if (temp == 1) {
logmsg("FAILURE:\tsearch_dir\tupdate_time\tno more space");
return temp;
} else if (temp == -1) {
logmsg("FAILURE:\tsearch_dir\tupdate_time\tfailed to write");
return temp;
}
// if update_time did not return a -1 or 1, it was successful
// read the file block into a char array that will be parsed
char file_contents[BLOCK_SIZE + 1];
fread(file_contents, BLOCK_SIZE, 1, fd);
// tokenize the directory contents by the brackets
int i = 0;
char *dir_entries[3]; // 3 because there is 1) dir info, 2) dir entries (which is what is needed), 3) 0's after the closing '}' chars
dir_entries[i] = strtok(file_contents, "{}");
while (dir_entries[i++] != NULL) {
dir_entries[i] = strtok(NULL, "{}");
}
// dir_entries[1] contains the directory entries; the number of entires is the number of commas + 1
int num_entries = count_chars(dir_entries[1], ',');
++num_entries;
char *entry_names[num_entries];
// tokenize the entries by commas to get each type, name, and block number
i = 0;
entry_names[i] = strtok(dir_entries[1], ","); // each index will contain: "type:name:number" --> type = 'f' or 'd' for file or dir, name = the name of the entry to compare too, number = block number of the entry
while (entry_names[i++] != NULL) {
entry_names[i] = strtok(NULL, ",");
}
int temp_block = -1;
for (i = 0; i < num_entries; ++i) {
// compare a directory entry and return the block number of the entry if it is found
temp_block = compare_dir_entry(name, type, entry_names[i]);
if (temp_block > 0) {
break; // we found a match for our file/directory, so break
}
}
// if the directory/file name was not found, temp will equal -1; otherwise, it will equal the block number of the found entry
fclose(fd);
return temp_block;
}
// searches the path for a directory/file specified by type (0==dir, 1==file); returns the block number corresponding to the directory/file inode, 0 if the dir/file does not exist, or -1 if the path was not valid
static int search_path(const char *the_path, unsigned int type)
{
// if one backslash is passed, return the root's block number
if ( strcmp(the_path, "/") == 0 ) {
if (type == 0) {
return ROOT;
} else {
logmsg("ERROR:\tsearch_path\tROOT FILE\tENOENT");
errno = ENOENT;
return -errno;
}
}
char path[BLOCK_SIZE + 1];
strcpy(path, the_path);
// parts_to_path will be 1 if the search path is similar to "/dir"; it will be 2 if the search path is similar to "/other/dir"
int parts_to_path = count_chars(path, '/');
// create an array of strings to contain all parts of the path
char *path_parts[parts_to_path - 1];
//char *temp_str;
int i = 0;
// tokenize the path and put the contents into a string array
path_parts[i] = strtok(path, "/");
//temp_str = strtok(path, "/");
while (path_parts[i++] != NULL) {
path_parts[i] = strtok(NULL, "/");
}
i = 0;
int block_num;
// if there is more than one '/' in the path, the first part of the name inside the root dir will be a directory
if ( parts_to_path > 1 ) {
block_num = search_dir(path_parts[i], 0, ROOT);
} else { // we are looking for something in root, so find it based whatever the passed in type was
block_num = search_dir(path_parts[i], type, ROOT);
}
// if we are looking at root dir and the file/dir was not found, return 0
if ( (parts_to_path == 1) && (block_num == -1) ) {
return 0;
} else if ( (parts_to_path == 1) && (block_num > 0) ) { // there was only 1 element to search for in root and it was found
return block_num;
}
// we are looking in sub-directories of root, so until we get to the last element of the path, we are looking for directory names
if ( block_num == -1 ) {
return -1; // return -1 because the first directory in path inside of root was not found
}
// if the last element of path_parts is NULL (possibly because the passed in path had an ending "/" for no reason, i.e. "/file/path/"), decrement parts_to_path so the last element isn't searched
if ( path_parts[parts_to_path - 1] == NULL)
--parts_to_path;
// search for "/" delimited element from the passed in path, returning the block number of the element if found; return -1 if an illegitimate directory is passed in the path, or 0 if all elements were legitimate except for the last element
for (i = 1; i < parts_to_path; ++i) {
// if the last element of the path is the next part to be searched
if ( i == (parts_to_path - 1) ) {
block_num = search_dir(path_parts[i], type, block_num);
// if file/dir was not found, it does not exist so return 0
if (block_num == -1) {
return 0;
} else { // the final element was found so return the block number
return block_num;
}
} else { // we are not at the last element of the path, so we are searching for directory names
block_num = search_dir(path_parts[i], 0, block_num);
// the directory name was not found, so the path is invalid; return a -1
if (block_num == -1) {
return -1;
} else { // the directory name was found, but we have not reached the end of path, so continue
continue;
}
}
}
return 0;
}
// returns a char string based on type; type (0==directory path leading up to last element of path, 1==last element of path)
char *get_element(int type, const char *the_path, char *return_str)
{
char path[BLOCK_SIZE + 1];
strcpy(path, the_path);
// parts_to_path will be 1 if the search path is similar to "/dir"; it will be 2 if the search path is similar to "/other/dir"
int parts_to_path = count_chars(path, '/');
// if there was only one '/' and we are looking for a directory, return root
if ( (parts_to_path == 1) && (type == 0) ) {
strcpy(return_str, "/");
return return_str;
}
// create an array of strings to contain all parts of the path
char *path_parts[parts_to_path - 1];
int i = 0;
// tokenize the path and put the contents into a string array
path_parts[i] = strtok(path, "/");
while (path_parts[i++] != NULL) {
path_parts[i] = strtok(NULL, "/");
}
// if the last element of path_parts is NULL, ignore it since an extra "/" may have been passed to path
if ( path_parts[parts_to_path - 1] == NULL ) {
--parts_to_path;
}
// if there was only one '/' and we are looking for a directory, return root
if ( (parts_to_path == 1) && (type == 0) ) {
strcpy(return_str, "/");
return return_str;
}
// if we just want the last element, return the last element
if (type == 1) {
strcpy(return_str, path_parts[parts_to_path - 1]);
return return_str;
} else { // return all the elements with "/" separation leading up to the last element
//char dir_path[BLOCK_SIZE + 1];
strcpy(return_str, "/");
for (i = 0; i < (parts_to_path - 2); ++i) {
strcat(return_str, path_parts[i]);
strcat(return_str, "/");
}
strcat(return_str, path_parts[i]);
return return_str;
}
}
// updates to a directory's file_to_inode_dict; returns -1 if there is a write error, 1 if the write would cause the directory block to surpass the BLOCK_SIZE limit, 0 if successful
static int add_dict_entry(char type, char *name, int inode_block, FILE *fd)
{
char buf[BLOCK_SIZE + 1];
// get the contents of the file
char file_contents[BLOCK_SIZE + 1];
fread(file_contents, BLOCK_SIZE, 1, fd);
rewind(fd);
char *parts[3]; // 3 because the file is split into 3 groupings based on the "{}" delimiter characters
int i = 0;
// tokenize the file contents by the "{}" delimiter characters; parts[1]: directory info, parts[2]: previous inodes in file; parts[3]: 0's at end of file
parts[i] = strtok(file_contents, "{}");
while (parts[i++] != NULL) {
parts[i] = strtok(NULL, "{}");
}
// copy the info about the directory into a char array so we can update the link count
char parts_0[BLOCK_SIZE + 1];
// get the original directory info, updating the linkcount, and put it into the parts_0 char array
char size[BLOCK_SIZE]; char uid[BLOCK_SIZE]; char gid[BLOCK_SIZE]; char mode[BLOCK_SIZE];
char linkcount_str[BLOCK_SIZE]; int linkcount;
char atime_str[BLOCK_SIZE]; char ctime_str[BLOCK_SIZE]; char mtime_str[BLOCK_SIZE];
char fname_inode[BLOCK_SIZE]; //char inodes[BLOCK_SIZE];
//char indirect[BLOCK_SIZE]; char location[BLOCK_SIZE];
//char temp[10];
// format will be for a directory
// increment the linkcount for a directory because a new inode was added to its dict
fscanf(fd, "%s %s %s %s %s %s %s %10c%i%*c %s", size, uid, gid, mode, atime_str, ctime_str, mtime_str, linkcount_str, &linkcount, fname_inode);
// increment the linkcount to account for the new directory entry if the entry is a directory because the new directory's '..' will point to this directory
if (type == 'd') {
++linkcount;
}
sprintf(parts_0, "%s %s %s %s %s %s %s linkcount:%i, %s", size, uid, gid, mode, atime_str, ctime_str, mtime_str, linkcount, fname_inode);
rewind(fd);
// add the directory's info back along with appropriate "{}" chars, and add the new inode entry to the end of the previous entries
if (sprintf(buf, "%s {%s,%c:%s:%i}}", parts_0, parts[1], type, name, inode_block) > BLOCK_SIZE) {
logmsg("ERROR:\tadd_dict_entry\tsprintf\tbuf too large");
return 1;
}
if ( write_to_file(buf, fd) != 0 ) {
logmsg("FAILURE:\tadd_dict_entry\twrite_to_file");
return -1;
}
// successfully wrote the new directory inode dictionary entry to the directory block
return 0;
}
// attemps to add a to a directory's file_to_inode_dict; returns -1 if there is a write error, 1 if the write would cause the directory block to surpass the BLOCK_SIZE limit, 0 if successful
static int add_to_dir_dict(char type, char *name, int inode_block, char *dir_path)
{
// open the directory's file
int dir_block_num = search_path(dir_path, 0);
char dir_block[MAX_PATH_LENGTH + 1];
sprintf(dir_block, "/fusedata/fusedata.%i", dir_block_num);
FILE *fd = fopen(dir_block, "r+");
update_time(0, 1, 1, 0, fd); // update the atime and ctime of this directory
rewind(fd);
// get the result of trying to add the entry
int result = add_dict_entry(type, name, inode_block, fd);
fclose(fd);
return result;
}
// decrement the link count and possibly remove the file if link count drops to 0; returns -1 on error, 0 on success
static int unlink_inode(FILE *fd, int inode_num)
{
// decrement the linkcount of the inode since a directory entry is removed
// variables to be used in fscanf function of the file stream
char buf[BLOCK_SIZE + 1];
char size[BLOCK_SIZE]; char uid[BLOCK_SIZE]; char gid[BLOCK_SIZE]; char mode[BLOCK_SIZE];
char linkcount_str[BLOCK_SIZE]; int linkcount;
char atime_str[BLOCK_SIZE]; char ctime_str[BLOCK_SIZE]; char mtime_str[BLOCK_SIZE];
char indirect[BLOCK_SIZE]; int indirect_val;
char location[BLOCK_SIZE]; int location_val;
char temp[10];
// update the time fields of the inode
update_time(1, 1, 1, 0, fd);
fread(temp, 1, 1, fd); rewind(fd);
// get and decrement the link count and write the data back to the file with the updated link count
// reset the file to all 0's so the new data is present, but if link count drops to 0, we must also add the blocks back to the free block list and set all the blocks to all 0's
fscanf(fd, "%s %s %s %s %10c%i%*c %s %s %s %9c%i%*c %9c%i%*c", size, uid, gid, mode, linkcount_str, &linkcount, atime_str, ctime_str, mtime_str, indirect, &indirect_val, location, &location_val);
--linkcount; // decrement the linkcount to account for the removed link to the file
// reset file to 0's
if (reset_block(fd) == -1) {
return -1;
}
char *temp1;
char temp2[BLOCK_SIZE + 1];
FILE *temp_fh;
int temp_int;
char temp_filename[BLOCK_SIZE + 1];
if (linkcount == 0) { // add the inode back to the free block list, reset the data the inode points to in files and add those inode(s) back to the free block list
sprintf(temp2, "%s/fusedata.%i", FILES_DIR, location_val);
temp_fh = fopen(temp2, "r+");
if (indirect_val == 0) {
// open the block at location_val and reset its data to all 0's
reset_block(temp_fh);
// put location_val back on the free block list
add_free_block(location_val);
} else { // indirect == 1 & the location holds other inodes filled with data
// read the contents of the indirect file, and for each comma separated value, open that value's block and reset it to 0's, then add that value back to the free block list
fread(buf, BLOCK_SIZE, 1, temp_fh);
fclose(temp_fh);
temp1 = strtok(buf, ",");
while (temp1 != NULL) {
temp_int = atoi(temp1);
if (temp_int != 0) {
// reset the fusedata.X block of the file data and give that file block number back to the free block list
sprintf(temp_filename, "%s/fusedata.%i", FILES_DIR, temp_int);
temp_fh = fopen(temp_filename, "r+");
reset_block(temp_fh);
fclose(temp_fh);
add_free_block(temp_int);
}
temp1 = strtok(NULL, ",");
}
}
fclose(temp_fh);
}
if (sprintf(buf, "%s %s %s %s linkcount:%i, %s %s %s indirect:%i, location:%i}", size, uid, gid, mode, linkcount, atime_str, ctime_str, mtime_str, indirect_val, location_val) > BLOCK_SIZE) {
logmsg("ERROR:\tjb_link\tlinkcount++\tEFBIG");
errno = EFBIG;
return -errno;
}
rewind(fd);
if ( write_to_file(buf, fd) != 0 ) {
logmsg("FAILURE:\tjb_link\tlinkcount++\tEIO");
errno = EIO;
return -errno;
}
fread(temp, 1, 1, fd); rewind(fd);
fclose(fd);
return 0;
}
// return a file's attribute; type (0==dir, 1==file), attr (0==linkcount, 1==size, 2==atime, 3==ctime, 4==mtime); return -1 if something goes wrong
static int get_file_attr(int type, int attr, FILE *fd)
{
char temp[BLOCK_SIZE + 1];
int links; int size; unsigned int a_time; unsigned int c_time; unsigned int m_time;
rewind(fd);
update_time(type, 1, 0, 0, fd);
rewind(fd);
// set the values for links, size, atime, ctime, and mtime
if ( type == 0 ) { // parse through a directory formatted file descriptor
fscanf(fd, "%6c%i%*c %s %s %s %6c%u%*c %6c%u%*c %6c%u%*c %10c%i", temp, &size, temp, temp, temp, temp, &a_time, temp, &c_time, temp, &m_time, temp, &links);
} else { // parse through a file formatted file descriptor
fscanf(fd, "%6c%i%*c %s %s %s %10c%i%*c %6c%u%*c %6c%u%*c %6c%u%*c", temp, &size, temp, temp, temp, temp, &links, temp, &a_time, temp, &c_time, temp, &m_time);
}
switch (attr)
{
case 0: // linkcount
return links;
case 1: // size
return size;
case 2: // atime
return a_time;
case 3: // ctime
return c_time;
case 4: // mtime
return m_time;
default:
return -1;
}
return -1;
}
// ----------------------------------- FUNCTIONS FOR jb_init -------------------------------------
// Create the super-block (fusedata.0)
static int create_superblock(char *buf)
{
FILE *superblock = fopen("fusedata.0", "w+");
if (!superblock) {
return -errno;
}
// fill superblock with 0's initially
if ( write_to_file(buf, superblock) != 0 ) {
logmsg("FAILURE:\tcreate_superblock\twrite_to_file\tbuf");
return -errno;
}
rewind(superblock); // set position indicator of file stream to the beginning of the file
// get creation time of this filesystem in reference to the Epoch
char *creation_time_str = (char *) malloc(20); // For 2014, time since Epoch would be 10 digits (so 20 possible digits is okay for now)
sprintf(creation_time_str, "%lu", time(NULL)); // put the an unsigned int representing time directly into the creation_time_str string
/* format of super-block:
* {creationTime:1376483073,mounted:50,devId:20,freeStart:1,freeEnd:25,root:26,maxBlocks:10000}
*
* createtime is created above, mounted increments with each mount (allocate a large set of bytes for this),
* devid is always 20, freestart is the first block containing the list of free blocks,
* freeend is the last block containing the list of free blocks, root is the block after freeend,
* maxblocks is arbitrary but was set to 10000 at first creation of this block OS
*/
// mounted:1 because this is the first mount; freeStart, freeEnd, root, and maxBlocks will be defined constants for each new creation of a filesystem
char *data = (char *) malloc(BLOCK_SIZE);
sprintf(data, "{creationTime: %s, mounted: 1, devId: 20, freeStart: %u, freeEnd: %u, root: %u, maxBlocks: %u}", creation_time_str, FREE_START, FREE_END, ROOT, MAX_NUM_BLOCKS);
if ( write_to_file(data, superblock) != 0 ) {
logmsg("FAILURE:\tcreate_superblock\twrite_to_file\tdata");
free(creation_time_str); free(data); fclose(superblock);
return -errno;
}
fclose(superblock);
free(creation_time_str); free(data);
return 0;
}
// Set up comma separated values of free blocks after root
static int create_free_block_list(char *fusedata_digit, char *fusedata_str, unsigned int fusedata_digit_len)
{
// the first block containing the free block list is a special case because it must not include the superblock, the blocks containing the free block list, or root
sprintf(fusedata_digit, "%d", FREE_START); // fusedata_digit will hold the digit of the first block that holds the free block list
strcpy(fusedata_str, "fusedata."); // initialize fusedata_str to contain "fusedata."
strcat(fusedata_str, fusedata_digit); // fusedata_str will now contain "fusedata.i" where 'i' is a digit of a block that holds the free block list
FILE *free_start_file = fopen(fusedata_str, "r+"); // create the fusedata.FREE_START file
if (!free_start_file) {
return -errno;
}
char *data = (char *) malloc(BLOCK_SIZE);
// increment over 'i' up to BLOCKS_IN_FREE - 1 to write that free block to the free block list
int i;
for (i = ROOT + 1; i < BLOCKS_IN_FREE; ++i) {
sprintf(data, "%u,", i);
if ( write_to_file(data, free_start_file) != 0 ) {
logmsg("FAILURE:\tcreate_free_block_list\twrite_to_file\tfree_start_file");
free(data); fclose(free_start_file);
return -errno;
}
}
fclose(free_start_file);
// every block after the starting one has BLOCKS_IN_FREE free blocks per block
FILE *free_block_file;
// increment over 'j' to create the free block list for each file from FREE_START + 1 up to FREE_END
int j;
for (j = FREE_START + 1; j <= FREE_END; ++j) {
// get the fusedata.X file name where each increment of 'j' is 'X'
sprintf(fusedata_digit, "%d", j);
strcpy(fusedata_str, "fusedata.");
strcat(fusedata_str, fusedata_digit);
// open the fusedata.X file for reading and writing
free_block_file = fopen(fusedata_str, "r+");
if (!free_block_file) {
return -errno;
}
// continue incrementing 'i' because 'i' left off where the next free block list should start
for ( ; i < BLOCKS_IN_FREE * j; ++i) {
sprintf(data, "%u,", i);
if ( write_to_file(data, free_block_file) != 0 ) {
logmsg("FAILURE:\tcreate_free_block_list\twrite_to_file\tfree_block_file");
free(data); fclose(free_block_file);
return -errno;
}
}
fclose(free_block_file);
}
return 0;
}
// Set up the root directory's initial structure
static int create_root(char *fusedata_digit, char *fusedata_str)
{
// open the root directory block file
sprintf(fusedata_digit, "%d", ROOT);
strcpy(fusedata_str, "fusedata.");
strcat(fusedata_str, fusedata_digit);
FILE *root_file = fopen(fusedata_str, "r+"); // open the fusedata.ROOT file
if (!root_file) {
return -errno;
}
char *data = (char *) malloc(BLOCK_SIZE);
char *creation_time_str = (char *) malloc(20); // For 2014, time since Epoch would be 10 digits (so 20 possible digits is okay for now)
sprintf(creation_time_str, "%lu", time(NULL)); // put the an unsigned int representing time directly into the creation_time_str string
/* format of root-block:
* {size:0, uid:1, gid:1, mode:16877, atime:1323630836, ctime:1323630836, mtime:1323630836, linkcount:2, filename_to_inode_dict: {d:.:26,d:..:26}}
* mode:16877 converts to 40755 in octal; the 40000 refers to the fact that this is a directory
*
* size is initially 0, uid, gid, & mode will not change for this filesystem;
* atime (access time), ctime (inode or file change time), mtime (file modification time) are all the same when root is initialized;
* linkcount is 2 because '.' and '..' point to root, and filename_to_inode_dict denotes the links to inodes root has stored
*/
sprintf(data, "{size:0, uid:%d, gid:%d, mode:16877, atime:%s, ctime:%s, mtime:%s, linkcount:2, filename_to_inode_dict: {d:.:%d,d:..:%d}}", UID, GID, creation_time_str, creation_time_str, creation_time_str, ROOT, ROOT);
if ( write_to_file(data, root_file) != 0 ) {
logmsg("FAILURE:\tcreate_root\twrite_to_file");
free(data); free(creation_time_str); fclose(root_file);
return -errno;
}
fclose(root_file);
return 0;
}
// Creates fusedata.1 to fusedata.X blocks (X is MAX_NUM_BLOCKS-1)
static int create_blocks(char *buf, char *fusedata_digit, char *fusedata_str, unsigned int fusedata_digit_len)
{
int i;
for (i = 1; i < MAX_NUM_BLOCKS; ++i) {
sprintf(fusedata_digit, "%d", i); // fusedata_digit will hold from 0 --> MAX_NUM_BLOCKS-1
strcpy(fusedata_str, "fusedata."); // initialize fusedata_str to contain "fusedata." on every loop to concat the block number onto it
strcat(fusedata_str, fusedata_digit); // fusedata_str will now contain "fusedata.i" where 'i' goes up to MAX_NUM_BLOCKS-1
FILE *fd = fopen(fusedata_str, "w+"); // create the fusedata.X file
if (!fd) {
return -errno;
}
if ( write_to_file(buf, fd) != 0 ) {
fclose(fd);
return -errno;
}
fclose(fd);
}
// create the free block list
if ( create_free_block_list(fusedata_digit, fusedata_str, fusedata_digit_len) != 0 ) {
logmsg("FAILURE:\tcreate_blocks\tcreate_free_blocklist");
return -errno;
}
// create root
if ( create_root(fusedata_digit, fusedata_str) != 0 ) {
logmsg("FAILURE:\tcreate_blocks\tcreate_root");
return -errno;
}
return 0;
}
// Essentially just updates the number of times mounted and writes that back to the fusedata.0 file
static int update_superblock()
{
char *temp = (char *) malloc(BLOCK_SIZE); // used to store string values that are already known and thus just need to pass over in the file stream
FILE *superblock = fopen("fusedata.0", "r+"); // open the super-block with read + write permissions (but don't overwrite the file)
if (!superblock) {
return -errno;
}
char *creation_time_str = (char *) malloc(20); // For 2014, time since Epoch would be 10 digits (so 20 possible digits is okay for now)
unsigned int mount_num;
// we know certain contents in the file such as "{creationTime:", "mounted:", "devId:", "20,", "freeStart:", "1,", etc... so just put those in temp
// we don't know the creation_time which is the second specifier, and we need the number of times mounted to increment it and write back to the file which is the fifth specifier
fscanf(superblock, "%s %s %s %u %s %s %s %s %s %s %s %s %s %s %s", temp, creation_time_str, temp, &mount_num, temp, temp, temp, temp, temp, temp, temp, temp, temp, temp, temp);
mount_num++; // increment the number of times mounted since the filesystem is being mounted again
rewind(superblock); // point the file stream back to the beginning to overwrite the data with the new mount number
// the %s for the actual created time was scanned as a string so the ',' char following it is also put into creation_time_str
sprintf(temp, "{creationTime: %s mounted: %u, devId: 20, freeStart: %u, freeEnd: %u, root: %u, maxBlocks: %u}", creation_time_str, mount_num, FREE_START, FREE_END, ROOT, MAX_NUM_BLOCKS);
if ( write_to_file(temp, superblock) != 0) {
logmsg("FAILURE:\tupdate_superblock\twrite_to_file");
free(temp); free(creation_time_str); fclose(superblock);
return -errno;
}
//fprintf(superblock, "{creationTime: %s mounted: %u devId: 20, freeStart: %u, freeEnd: %u, root: %u, maxBlocks: %u}", creation_time_str, mount_num, FREE_START, FREE_END, ROOT, MAX_NUM_BLOCKS);
fclose(superblock);
free(temp); free(creation_time_str);
return 0;
}
// ----------------------------------- FUNCTIONS FOR jb_init -------------------------------------
// ------------------------------------- FUSE FUNCTIONS -----------------------------------------
/*
* Return file attributes.
* For the pathname, this should fill in the elements of "stat".
* If a field is meaningless (e.g., st_ino) then it should be set to 0.
*
* stat
* ----
* Return info about a file.
* ino_t st_ino inode number (ignored unless 'use_ino' mount option is given)
* mode_t st_mode protection
* nlink_t st_nlink number of hard links
* off_t st_size total size, in bytes
* clkcnt_t st_blocks number of __Byte blocks allocated
* time_t st_atime time of last access
* time_t st_mtime time of last modification
* time_t st_ctime time of last status change
*
* Following POSIX macros are defined to check the file type using the st_mode field:
* S_ISREG - regular file?
* S_ISDIR - directory?
* S_ISBLK - block device?
*/
static int jb_getattr(const char *path, struct stat *stbuf)
{
// initialize the stat struct to all 0's because this function will set its values
memset(stbuf, 0, sizeof(struct stat));
// search_path will return -1 if the path has invalid directory references, 0 if the file does not exist, or a block_number if the file already exists
int file_ref = search_path(path, 0);
// if file_ref is less than 1 (i.e. 0 or -1) the file path does not exist, so look for the path as a file
if (file_ref < 1) {
logmsg("ERROR:\tjb_getattr\tfile_ref\tENOENT");
// search for the path as a file
file_ref = search_path(path, 1);
if (file_ref < 1) {
logmsg("ERROR:\tjb_getattr\tfile_ref\tENOENT");
errno = ENOENT;
return -errno;
}
}
// file_ref holds a number that is the fusedata block of the directory/file inode
char fusedata_str[BLOCK_SIZE + 1];
sprintf(fusedata_str, "/fusedata/fusedata.%i", file_ref);