155
155
sprintf(statename, "%s/.__alloc", dirname);
156
if(cfs->file_size(statename) >= 0) {
156
if(cfs_file_size(statename) >= 0) {
157
157
return xstrdup(dirname);
159
159
s = strrchr(dirname, '/');
231
231
static void recover(const char *path)
233
233
char newpath[CHIRP_PATH_MAX];
234
struct chirp_stat info;
235
234
struct alloc_state *a, *b;
235
struct chirp_dir *dir;
236
struct chirp_dirent *d;
240
238
a = alloc_state_cache_exact(path);
246
244
fatal("couldn't open %s: %s\n", path, strerror(errno));
248
246
while((d = cfs->readdir(dir))) {
253
if(!strncmp(d, ".__", 3))
256
sprintf(newpath, "%s/%s", path, d);
258
result = cfs->lstat(newpath, &info);
260
fatal("couldn't stat %s: %s\n", path, strerror(errno));
262
if(S_ISDIR(info.cst_mode)) {
247
if(!strcmp(d->name, "."))
249
if(!strcmp(d->name, ".."))
251
if(!strncmp(d->name, ".__", 3))
254
sprintf(newpath, "%s/%s", path, d->name);
256
if(S_ISDIR(d->info.cst_mode)) {
263
257
recover(newpath);
264
258
b = alloc_state_cache_exact(newpath);
266
260
alloc_state_update(a, b->size);
267
} else if(S_ISREG(info.cst_mode)) {
268
alloc_state_update(a, space_consumed(info.cst_size));
261
} else if(S_ISREG(d->info.cst_mode)) {
262
alloc_state_update(a, space_consumed(d->info.cst_size));
270
264
debug(D_ALLOC, "warning: unknown file type: %s\n", newpath);
423
417
a = alloc_state_cache(itable_lookup(fd_table, fd));
425
INT64_T filesize = cfs->fd_size(fd);
419
INT64_T filesize = cfs_fd_size(fd);
426
420
if(filesize >= 0) {
427
421
INT64_T newfilesize = MAX(length + offset, filesize);
428
422
INT64_T alloc_change = space_consumed(newfilesize) - space_consumed(filesize);
509
503
a = alloc_state_cache(itable_lookup(fd_table, fd));
511
INT64_T filesize = cfs->fd_size(fd);
505
INT64_T filesize = cfs_fd_size(fd);
512
506
if(filesize >= 0) {
513
507
INT64_T alloc_change = space_consumed(length) - space_consumed(filesize);
514
508
if(a->avail >= alloc_change) {
533
527
return cfs->fsync(fd);
536
void *chirp_alloc_opendir(const char *path)
530
struct chirp_dir * chirp_alloc_opendir( const char *path )
538
532
return cfs->opendir(path);
541
char *chirp_alloc_readdir(void *dir)
535
struct chirp_dirent * chirp_alloc_readdir( struct chirp_dir *dir )
543
537
return cfs->readdir(dir);
546
void chirp_alloc_closedir(void *dir)
540
void chirp_alloc_closedir( struct chirp_dir *dir )
548
542
return cfs->closedir(dir);
701
695
result = rename(oldpath, newpath);
703
INT64_T filesize = cfs->file_size(oldpath);
697
INT64_T filesize = cfs_file_size(oldpath);
704
698
if(filesize >= 0) {
705
699
if(b->avail >= filesize) {
706
700
result = cfs->rename(oldpath, newpath);
752
746
INT64_T chirp_alloc_rmall(const char *path)
748
if(!alloc_enabled) return cfs->rmall(path);
756
result = chirp_alloc_unlink(path);
750
int result = chirp_alloc_unlink(path);
757
751
if(result == 0) {
759
753
} else if(errno != EISDIR) {
756
struct chirp_dir *dir;
757
struct chirp_dirent *d;
764
758
char subpath[CHIRP_PATH_MAX];
766
760
dir = chirp_alloc_opendir(path);
772
766
while((d = chirp_alloc_readdir(dir))) {
777
if(!strncmp(d, ".__ ", 3))
779
sprintf(subpath, "%s/%s", path, d);
767
if(!strcmp(d->name, "."))
769
if(!strcmp(d->name, ".."))
771
if(!strncmp(d->name, ".__ ", 3))
773
sprintf(subpath, "%s/%s", path, d->name);
780
774
result = chirp_alloc_rmall(subpath);
859
INT64_T chirp_alloc_mkfifo(const char *path)
861
return cfs->mkfifo(path);
864
853
INT64_T chirp_alloc_access(const char *path, INT64_T mode)
866
855
return cfs->access(path, mode);
892
881
a = alloc_state_cache(path);
894
INT64_T filesize = cfs->file_size(path);
883
INT64_T filesize = cfs_file_size(path);
895
884
if(filesize >= 0) {
896
885
INT64_T alloc_change = space_consumed(newsize) - space_consumed(filesize);
897
886
if(a->avail >= alloc_change) {
921
910
return cfs->md5(path, digest);
913
INT64_T chirp_alloc_setrep(const char *path, int nreps)
915
return cfs->setrep(path,nreps);
924
918
INT64_T chirp_alloc_lsalloc(const char *path, char *alloc_path, INT64_T * total, INT64_T * inuse)