This repository has been archived by the owner on Nov 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
fuse.c
737 lines (649 loc) · 18.3 KB
/
fuse.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
#include "fuse.h"
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <fuse.h>
#include <libgen.h>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
#include <dirent.h>
#include <time.h>
#include <zlib.h>
#include <ftw.h>
#include <sys/types.h>
#include <pthread.h>
static char xpath[PATH_MAX] = "\0";
static char openpath[PATH_MAX] = "\0";
static pthread_mutex_t phoenixfs_mutexlock = PTHREAD_MUTEX_INITIALIZER;
void *phoenixfs_init(struct fuse_conn_info *conn)
{
return ROOTENV;
}
static int phoenixfs_getattr(const char *path, struct stat *stbuf)
{
struct file_record *fr;
struct dir_record *dr;
int rev;
rev = parse_pathspec(xpath, path);
build_xpath(openpath, xpath, rev);
PHOENIXFS_DBG("getattr:: %s %d", openpath, rev);
/* Try underlying FS */
if (lstat(openpath, stbuf) < 0) {
/* Try fstree */
if (!(dr = find_dr(xpath))) {
if (!(fr = find_fr(xpath, rev)))
return -ENOENT;
else {
memset(stbuf, 0, sizeof(struct stat));
fill_stat(stbuf, fr);
return 0;
}
}
memset(stbuf, 0, sizeof(struct stat));
stbuf->st_mode = S_IFDIR | 0755;
}
return 0;
}
static int phoenixfs_fgetattr(const char *path, struct stat *stbuf,
struct fuse_file_info *fi)
{
PHOENIXFS_DBG("fgetattr:: %s", path);
if (fstat(fi->fh, stbuf) < 0)
return -errno;
return 0;
}
static int phoenixfs_opendir(const char *path, struct fuse_file_info *fi)
{
struct dir_record *dr;
DIR *dp;
PHOENIXFS_DBG("opendir:: %s", path);
build_xpath(xpath, path, 0);
/* Try underlying fs */
if (!(dp = opendir(xpath))) {
/* Try fstree */
if (!(dr = find_dr(path)))
return -ENOENT;
else {
/* Make the directory and open it */
mkdir(xpath, S_IRUSR | S_IWUSR | S_IXUSR);
dp = opendir(xpath);
}
}
fi->fh = (intptr_t) dp;
return 0;
}
static int phoenixfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fi)
{
DIR *dp;
struct dirent *de;
struct stat st;
void *record;
struct node *iter_root, *iter;
struct vfile_record *vfr;
struct dir_record *dr;
register int i;
dp = (DIR *) (uintptr_t) fi->fh;
if (!(de = readdir(dp)))
return -errno;
/* Fill directories from backing FS */
do {
/* Hide the .git directory, and enumerate only directories */
if (strcmp(de->d_name, ".git") && de->d_type == DT_DIR) {
PHOENIXFS_DBG("readdir:: fs: %s", de->d_name);
if (filler(buf, de->d_name, NULL, 0))
return -ENOMEM;
}
} while ((de = readdir(dp)) != NULL);
/* Fill files from fstree */
if (!(dr = find_dr(path)) || !dr->vroot) {
PHOENIXFS_DBG("readdir:: fstree: blank");
return 0;
}
iter_root = dr->vroot;
iter = dr->vroot;
/* Use only the leaves */
while (!iter->is_leaf)
iter = iter->pointers[0];
while (1) {
for (i = 0; i < iter->num_keys; i++) {
if (!(record = find(iter_root, iter->keys[i], 0)))
PHOENIXFS_DBG("readdir:: key listing issue");
vfr = (struct vfile_record *) record;
fill_stat(&st, vfr->history[vfr->HEAD]);
PHOENIXFS_DBG("readdir:: tree fill: %s", (const char *) vfr->name);
if (filler(buf, (const char *) vfr->name, &st, 0))
return -ENOMEM;
}
if (iter->pointers && iter->pointers[BTREE_ORDER - 1] != NULL)
iter = iter->pointers[BTREE_ORDER - 1];
else
break;
}
return 0;
}
static int phoenixfs_releasedir(const char *path, struct fuse_file_info *fi)
{
if (closedir((DIR *) (uintptr_t) fi->fh) < 0)
return -errno;
return 0;
}
static int phoenixfs_access(const char *path, int mask)
{
PHOENIXFS_DBG("access:: %s", path);
build_xpath(xpath, path, 0);
if (access(xpath, mask) < 0)
return -errno;
return 0;
}
static int phoenixfs_symlink(const char *path, const char *link)
{
char xlink[PATH_MAX];
PHOENIXFS_DBG("symlink:: %s to %s", link, path);
sprintf(xpath, "%s/%s", ROOTENV->fsback, path);
build_xpath(xlink, link, 0);
if (symlink(xpath, xlink) < 0)
return -errno;
fstree_insert_update_file(link, path);
return 0;
}
static int phoenixfs_rename(const char *path, const char *newpath)
{
char xnewpath[PATH_MAX];
struct dir_record *dr;
struct vfile_record *vfr, *new_vfr;
char *filename, *newfilename;
uint16_t key = ~0;
size_t length;
uint8_t start_rev, rev_nr;
PHOENIXFS_DBG("rename:: %s to %s", path, newpath);
build_xpath(xpath, path, 0);
build_xpath(xnewpath, newpath, 0);
if (rename(xpath, xnewpath) < 0)
return -errno;
/* Update fstree */
filename = split_basename(path, xpath);
if (!(dr = find_dr(xpath))) {
PHOENIXFS_DBG("rename:: Missing dr for %s", xpath);
return 0;
}
/* Find the old vfr to copy out data from and remove */
length = (size_t) strlen((char *) filename);
key = compute_crc32(key, (const unsigned char *) filename, length);
if (!(vfr = find(dr->vroot, key, 0))) {
PHOENIXFS_DBG("rename:: Missing vfr for %s", path);
return 0;
}
/* Make a new vfr and copy out history from old vfr */
newfilename = split_basename(path, NULL);
new_vfr = make_vfr(newfilename);
/* Compute start_rev and rev_nr */
if (vfr->HEAD < 0) {
start_rev = 0;
rev_nr = 0;
} else if (vfr->history[(vfr->HEAD + 1) % REV_TRUNCATE]) {
/* History is full, and is probably wrapping around */
start_rev = (vfr->HEAD + 1) % REV_TRUNCATE;
rev_nr = 20;
} else {
/* History is not completely filled */
start_rev = 0;
rev_nr = vfr->HEAD + 1;
}
PHOENIXFS_DBG("rename:: copying %d revisions", rev_nr);
while (start_rev < rev_nr) {
new_vfr->history[start_rev] = vfr->history[start_rev];
start_rev = (start_rev + 1) % REV_TRUNCATE;
}
new_vfr->HEAD = rev_nr - 1;
insert_vfr(dr, new_vfr);
/* Remove old vfr */
dr->vroot = remove_entry(dr->vroot, key);
return 0;
}
static int phoenixfs_link(const char *path, const char *newpath)
{
static char xnewpath[PATH_MAX];
PHOENIXFS_DBG("link:: %s to %s", path, newpath);
build_xpath(xpath, path, 0);
build_xpath(xnewpath, newpath, 0);
if (link(xpath, xnewpath) < 0)
return -errno;
return 0;
}
static int phoenixfs_chmod(const char *path, mode_t mode)
{
PHOENIXFS_DBG("chmod:: %s", path);
build_xpath(xpath, path, 0);
if (chmod(xpath, mode) < 0)
return -errno;
return 0;
}
static int phoenixfs_chown(const char *path, uid_t uid, gid_t gid)
{
/* chown is a no-op */
return 0;
}
static int phoenixfs_truncate(const char *path, off_t newsize)
{
PHOENIXFS_DBG("truncate:: %s to %lld", path, (long long int)newsize);
build_xpath(xpath, path, 0);
if (truncate(xpath, newsize) < 0)
return -errno;
return 0;
}
static int phoenixfs_utime(const char *path, struct utimbuf *ubuf)
{
PHOENIXFS_DBG("utime:: %s", path);
build_xpath(xpath, path, 0);
if (utime(xpath, ubuf) < 0)
return -errno;
return 0;
}
static int phoenixfs_open(const char *path, struct fuse_file_info *fi)
{
int rev, fd;
FILE *infile, *fsfile;
char fspath[PATH_MAX];
struct file_record *fr;
char sha1_digest[40];
rev = parse_pathspec(xpath, path);
build_xpath(fspath, xpath, 0);
/* Skip zinflate for entries not in fstree */
if (!(fr = find_fr(xpath, rev)))
goto END;
/* Build openpath by hand */
print_sha1(sha1_digest, fr->sha1);
sprintf(openpath, "%s/.git/loose/%s", ROOTENV->fsback, sha1_digest);
if (access(openpath, F_OK) < 0) {
/* Try extracting from packfile */
sprintf(xpath, "%s/.git/loose", ROOTENV->fsback);
if (unpack_entry(fr->sha1, xpath) < 0)
return -ENOENT;
else
PHOENIXFS_DBG("open:: pack %s", sha1_digest);
}
else
PHOENIXFS_DBG("open:: loose %s", sha1_digest);
/* zinflate openpath onto fspath */
PHOENIXFS_DBG("open:: zinflate %s onto %s", sha1_digest, fspath);
if (!(infile = fopen(openpath, "rb")) ||
!(fsfile = fopen(fspath, "wb+")))
return -errno;
if (zinflate(infile, fsfile) != Z_OK)
PHOENIXFS_DBG("open:: zinflate issue");
fclose(infile);
fclose(fsfile);
END:
if ((fd = open(fspath, fi->flags)) < 0)
return -errno;
fi->fh = fd;
return 0;
}
static int phoenixfs_mknod(const char *path, mode_t mode, dev_t dev)
{
PHOENIXFS_DBG("mknod:: %s", path);
build_xpath(xpath, path, 0);
if (mknod(xpath, mode, dev) < 0)
return -errno;
return 0;
}
/**
* If this method is not implemented or under Linux kernel
* versions earlier than 2.6.15, the mknod() and open() methods
* will be called instead.
*/
static int phoenixfs_create(const char *path, mode_t mode,
struct fuse_file_info *fi)
{
int fd;
/* Always pass through to underlying filesystem */
PHOENIXFS_DBG("create:: %s", path);
build_xpath(xpath, path, 0);
if ((fd = creat(xpath, mode)) < 0)
return -errno;
fi->fh = fd;
return 0;
}
static int phoenixfs_read(const char *path, char *buf, size_t size,
off_t offset, struct fuse_file_info *fi)
{
ssize_t read_bytes;
PHOENIXFS_DBG("read:: %s", path);
pthread_mutex_lock(&phoenixfs_mutexlock);
if ((read_bytes = pread(fi->fh, buf, size, offset)) < 0) {
pthread_mutex_unlock(&phoenixfs_mutexlock);
return -errno;
}
pthread_mutex_unlock(&phoenixfs_mutexlock);
return read_bytes;
}
static int phoenixfs_write(const char *path, const char *buf, size_t size,
off_t offset, struct fuse_file_info *fi)
{
ssize_t written_bytes;
PHOENIXFS_DBG("write:: %s", path);
pthread_mutex_lock(&phoenixfs_mutexlock);
if ((written_bytes = pwrite(fi->fh, buf, size, offset)) < 0) {
pthread_mutex_unlock(&phoenixfs_mutexlock);
return -errno;
}
pthread_mutex_unlock(&phoenixfs_mutexlock);
return written_bytes;
}
static int phoenixfs_statfs(const char *path, struct statvfs *statv)
{
PHOENIXFS_DBG("statfs:: %s", path);
build_xpath(xpath, path, 0);
if (statvfs(xpath, statv) < 0)
return -errno;
return 0;
}
static int phoenixfs_release(const char *path, struct fuse_file_info *fi)
{
struct file_record *fr;
FILE *infile, *outfile;
struct stat st;
unsigned char sha1[20];
char sha1_digest[40];
char outfilename[40];
char inpath[PATH_MAX];
char outpath[PATH_MAX];
int rev, ret;
pthread_mutex_lock(&phoenixfs_mutexlock);
/* Don't recursively backup history */
if ((rev = parse_pathspec(xpath, path))) {
PHOENIXFS_DBG("release:: history: %s", path);
/* Inflate the original version back onto the filesystem */
if (!(fr = find_fr(xpath, 0))) {
PHOENIXFS_DBG("release:: Can't find revision 0!");
pthread_mutex_unlock(&phoenixfs_mutexlock);
return 0;
}
print_sha1(sha1_digest, fr->sha1);
sprintf(inpath, "%s/.git/loose/%s", ROOTENV->fsback, sha1_digest);
build_xpath(outpath, xpath, 0);
if (!(infile = fopen(inpath, "rb")) ||
!(outfile = fopen(outpath, "wb+"))) {
pthread_mutex_unlock(&phoenixfs_mutexlock);
return -errno;
}
PHOENIXFS_DBG("release:: history: zinflate %s onto %s",
sha1_digest, outpath);
rewind(infile);
rewind(outfile);
if (zinflate(infile, outfile) != Z_OK)
PHOENIXFS_DBG("release:: zinflate issue");
fflush(outfile);
fclose(infile);
fclose(outfile);
if (close(fi->fh) < 0) {
PHOENIXFS_DBG("release:: can't really close");
pthread_mutex_unlock(&phoenixfs_mutexlock);
return -errno;
}
pthread_mutex_unlock(&phoenixfs_mutexlock);
return 0;
}
/* Attempt to create a backup */
build_xpath(xpath, path, 0);
if (!(infile = fopen(xpath, "rb")) ||
(lstat(xpath, &st) < 0)) {
pthread_mutex_unlock(&phoenixfs_mutexlock);
return -errno;
}
if ((ret = sha1_file(infile, st.st_size, sha1)) < 0) {
fclose(infile);
pthread_mutex_unlock(&phoenixfs_mutexlock);
return ret;
}
print_sha1(outfilename, sha1);
sprintf(outpath, "%s/.git/loose/%s", ROOTENV->fsback, outfilename);
if (!access(outpath, F_OK)) {
/* SHA1 match; don't overwrite file as an optimization */
PHOENIXFS_DBG("release:: not overwriting: %s", outpath);
goto END;
}
if (!(outfile = fopen(outpath, "wb"))) {
fclose(infile);
pthread_mutex_unlock(&phoenixfs_mutexlock);
return -errno;
}
/* Rewind and seek back */
rewind(infile);
PHOENIXFS_DBG("release:: zdeflate %s onto %s", xpath, outfilename);
if (zdeflate(infile, outfile, -1) != Z_OK)
PHOENIXFS_DBG("release:: zdeflate issue");
mark_for_packing(sha1, st.st_size);
fclose(outfile);
END:
fclose(infile);
if (close(fi->fh) < 0) {
PHOENIXFS_DBG("release:: can't really close");
return -errno;
}
/* Update the fstree */
fstree_insert_update_file(path, NULL);
pthread_mutex_unlock(&phoenixfs_mutexlock);
return 0;
}
static int phoenixfs_fsync(const char *path,
int datasync, struct fuse_file_info *fi)
{
PHOENIXFS_DBG("fsync:: %s", path);
if (datasync) {
if (fdatasync(fi->fh) < 0)
return -errno;
} else
if (fsync(fi->fh) < 0)
return -errno;
return 0;
}
static int phoenixfs_ftruncate(const char *path,
off_t offset, struct fuse_file_info *fi)
{
PHOENIXFS_DBG("ftruncate:: %s", path);
build_xpath(xpath, path, 0);
if (ftruncate(fi->fh, offset) < 0)
return -errno;
return 0;
}
static int phoenixfs_readlink(const char *path, char *link, size_t size)
{
/* Always pass through to underlying filesystem */
PHOENIXFS_DBG("readlink:: %s", path);
build_xpath(xpath, path, 0);
if (readlink(xpath, link, size - 1) < 0)
return -errno;
return 0;
}
static int phoenixfs_mkdir(const char *path, mode_t mode)
{
PHOENIXFS_DBG("mkdir:: %s", path);
build_xpath(xpath, path, 0);
if (mkdir(xpath, mode) < 0)
return -errno;
return 0;
}
static int phoenixfs_unlink(const char *path)
{
/* Always pass through to underlying filesystem */
PHOENIXFS_DBG("unlink:: %s", path);
fstree_remove_file(path);
build_xpath(xpath, path, 0);
if (unlink(xpath) < 0)
return -errno;
return 0;
}
static int phoenixfs_rmdir(const char *path)
{
/* Always pass through to underlying filesystem */
PHOENIXFS_DBG("rmdir:: %s", path);
build_xpath(xpath, path, 0);
if (rmdir(xpath) < 0)
return -errno;
return 0;
}
static void phoenixfs_destroy(void *userdata)
{
FILE *outfile;
/* Persist the fstree */
sprintf(xpath, "%s/.git/fstree", ROOTENV->fsback);
if (!(outfile = fopen(xpath, "wb"))) {
PHOENIXFS_DBG("destroy:: Can't open .git/fstree to persist");
return;
}
PHOENIXFS_DBG("destroy:: dumping fstree");
fstree_dump_tree(outfile);
fclose(outfile);
PHOENIXFS_DBG("destroy:: packing loose objects");
sprintf(xpath, "%s/.git/loose", ROOTENV->fsback);
dump_packing_info(xpath);
}
static struct fuse_operations phoenixfs_oper = {
.init = phoenixfs_init,
.getattr = phoenixfs_getattr,
.fgetattr = phoenixfs_fgetattr,
.open = phoenixfs_open,
.mknod = phoenixfs_mknod,
.releasedir = phoenixfs_releasedir,
.create = phoenixfs_create,
.read = phoenixfs_read,
.write = phoenixfs_write,
.statfs = phoenixfs_statfs,
.access = phoenixfs_access,
.getdir = NULL,
.readdir = phoenixfs_readdir,
.opendir = phoenixfs_opendir,
.readlink = phoenixfs_readlink,
.mkdir = phoenixfs_mkdir,
.rmdir = phoenixfs_rmdir,
.unlink = phoenixfs_unlink,
.fsync = phoenixfs_fsync,
.release = phoenixfs_release,
.ftruncate = phoenixfs_ftruncate,
.symlink = phoenixfs_symlink,
.link = phoenixfs_link,
.chown = phoenixfs_chown,
.chmod = phoenixfs_chmod,
.rename = phoenixfs_rename,
.truncate = phoenixfs_truncate,
.utime = phoenixfs_utime,
#if 0
.setxattr = phoenixfs_setxattr;
.getxattr = phoenixfs_getxattr;
.listxattr = phoenixfs_listxattr;
.removexattr = phoenixfs_removexattr;
.fsyncdir = phoenixfs_fsyncdir,
.lock = phoenixfs_lock,
.flush = phoenixfs_flush,
.utimens = phoenixfs_utimens,
.bmap = phoenixfs_bmap,
.poll = phoenixfs_poll,
.ioctl = phoenixfs_ioctl,
#endif
.destroy = phoenixfs_destroy,
};
/* phoenixfs mount <path> <mountpoint> */
/* argv[2] is fsback and argv[3] is the mountpoint */
int phoenixfs_fuse(int argc, char *argv[])
{
char *nargv[4];
FILE *infile;
void *record;
struct stat st;
register int i;
struct dir_record *dr;
struct node *iter, *iter_root;
struct env_t rootenv;
/* Sanitize fsback */
if (!realpath(argv[2], rootenv.fsback))
die("Invalid fsback: %s", argv[2]);
if ((lstat(rootenv.fsback, &st) < 0) ||
(access(rootenv.fsback, R_OK | W_OK | X_OK) < 0))
die("fsback doesn't have rwx permissions: %s",
rootenv.fsback);
if (!S_ISDIR(st.st_mode))
die("fsback not a directory: %s", rootenv.fsback);
/* Sanitize mountpoint */
if (!realpath(argv[3], rootenv.mountpoint))
die("Invalid mountpoint: %s", argv[3]);
if ((lstat(rootenv.mountpoint, &st) < 0) ||
(access(rootenv.mountpoint, R_OK | W_OK | X_OK) < 0))
die("mountpoint doesn't have rwx permissions: %s",
rootenv.mountpoint);
if (!S_ISDIR(st.st_mode))
die("mountpoint not a directory: %s", rootenv.mountpoint);
/* Check for .git directory */
sprintf(xpath, "%s/.git", rootenv.fsback);
mkdir(xpath, S_IRUSR | S_IWUSR | S_IXUSR);
if ((lstat(xpath, &st) < 0) ||
(access(xpath, R_OK | W_OK | X_OK) < 0))
die(".git doesn't have rwx permissions: %s", xpath);
if (!S_ISDIR(st.st_mode))
die(".git not a directory: %s", xpath);
/* Check for .git/loose directory */
sprintf(xpath, "%s/.git/loose", rootenv.fsback);
mkdir(xpath, S_IRUSR | S_IWUSR | S_IXUSR);
if ((lstat(xpath, &st) < 0) ||
(access(xpath, R_OK | W_OK | X_OK) < 0))
die(".git/loose doesn't have rwx permissions: %s", xpath);
if (!S_ISDIR(st.st_mode))
die(".git/loose not a directory: %s", xpath);
PHOENIXFS_DBG("phoenixfs_fuse:: fsback: %s, mountpoint: %s",
rootenv.fsback, rootenv.mountpoint);
/* Check for .git/fstree to load tree */
sprintf(xpath, "%s/.git/fstree", rootenv.fsback);
if (!access(xpath, F_OK) &&
(infile = fopen(xpath, "rb"))) {
PHOENIXFS_DBG("phoenixfs_fuse:: loading fstree");
fstree_load_tree(infile);
fclose(infile);
}
/* Re-create dr tree */
iter_root = get_fsroot();
iter = get_fsroot();
if (!iter)
goto END;
while (!iter->is_leaf)
iter = iter->pointers[0];
while (1) {
for (i = 0; i < iter->num_keys; i++) {
if (!(record = find(iter_root, iter->keys[i], 0)))
PHOENIXFS_DBG("readdir:: key listing issue");
dr = (struct dir_record *) record;
PHOENIXFS_DBG("phoenixfs_fuse:: mkdir: %s",
(const char *) dr->name);
sprintf(xpath, "%s%s", rootenv.fsback,
(const char *) dr->name);
mkdir(xpath, S_IRUSR | S_IWUSR | S_IXUSR);
}
if (iter->pointers && iter->pointers[BTREE_ORDER - 1] != NULL)
iter = iter->pointers[BTREE_ORDER - 1];
else
break;
}
END:
/* Check for .git/master.pack and .git/master.idx */
sprintf(xpath, "%s/.git/master.pack", rootenv.fsback);
sprintf(openpath, "%s/.git/master.idx", rootenv.fsback);
if ((access(xpath, F_OK) < 0) ||
(access(openpath, F_OK) < 0)) {
PHOENIXFS_DBG("phoenixfs_fuse:: not loading packing info");
load_packing_info(xpath, openpath, false);
}
else {
PHOENIXFS_DBG("phoenixfs_fuse:: loading packing info");
load_packing_info(xpath, openpath, 1);
}
nargv[0] = argv[0];
nargv[1] = "-d";
nargv[2] = "-odefault_permissions";
nargv[3] = argv[3];
return fuse_main(4, nargv, &phoenixfs_oper, &rootenv);
}