/* Try to ensure free_size bytes of storage are available. * Returns 0 on success. * This is rather simple-minded because doing a full LRU would * be potentially memory-intensive, and without atime it would * also require that apps constantly modify file metadata even * when just reading from the cache, which is pretty awful. */ int free_cache(int64_t free_size) { const char *name; int dfd, subfd; DIR *d; struct dirent *de; int64_t avail; char datadir[PKG_PATH_MAX];//ALPS00106329 + avail = disk_free(); if (avail < 0) return -1; LOGI("free_cache(%" PRId64 ") avail %" PRId64 "\n", free_size, avail); if (avail >= free_size) return 0; //ALPS00106329 + if (create_persona_path(datadir, 0)) { LOGE("couldn't get directory for persona 0"); return -1; } d = opendir(datadir); //ALPS00106329 - if (d == NULL) { LOGE("cannot open %s: %s\n", datadir, strerror(errno));//ALPS00106329 + return -1; } dfd = dirfd(d); while ((de = readdir(d))) { if (de->d_type != DT_DIR) continue; name = de->d_name; /* always skip "." and ".." */ if (name[0] == '.') { if (name[1] == 0) continue; if ((name[1] == '.') && (name[2] == 0)) continue; } subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY); if (subfd < 0) continue; delete_dir_contents_fd(subfd, "cache"); close(subfd); avail = disk_free(); if (avail >= free_size) { closedir(d); return 0; } } closedir(d); /* Fail case - not possible to free space */ return -1; }
/* Try to ensure free_size bytes of storage are available. * Returns 0 on success. * This is rather simple-minded because doing a full LRU would * be potentially memory-intensive, and without atime it would * also require that apps constantly modify file metadata even * when just reading from the cache, which is pretty awful. */ int free_cache(int free_size) { const char *name; int dfd, subfd; DIR *d; struct dirent *de; int avail; avail = disk_free(); if (avail < 0) return -1; LOGI("free_cache(%d) avail %d\n", free_size, avail); if (avail >= free_size) return 0; d = opendir(PKG_DIR_PREFIX); if (d == NULL) { LOGE("cannot open %s\n", PKG_DIR_PREFIX); return -1; } dfd = dirfd(d); while ((de = readdir(d))) { if (de->d_type != DT_DIR) continue; name = de->d_name; /* always skip "." and ".." */ if (name[0] == '.') { if (name[1] == 0) continue; if ((name[1] == '.') && (name[2] == 0)) continue; } subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY); if (subfd < 0) continue; delete_dir_contents_fd(subfd, "cache"); close(subfd); avail = disk_free(); if (avail >= free_size) { closedir(d); return 0; } } closedir(d); /* Fail case - not possible to free space */ return -1; }
/* free a GPtrArray containing pointer on struct t_disk elements */ void disks_free(GPtrArray * * pdisks) { if (*pdisks != NULL) { int i ; t_disk * pdisk ; for (i=0; i < (*pdisks)->len ; i++) { pdisk = (t_disk*)(g_ptr_array_index((*pdisks),i)) ; disk_free( &pdisk ) ; } g_ptr_array_free((*pdisks), TRUE); (*pdisks) = NULL ; } }
/** * dir_footer - generate the directory footer * @buf: buffer to be used * * This is the final callback used during directory generation. It generates * the "BLOCKS FREE" message and indicates that this is the final buffer to * be sent. Always returns 0 for success. */ static uint8_t dir_footer(buffer_t *buf) { uint16_t blocks; /* Copy the "BLOCKS FREE" message */ memcpy_P(buf->data, dirfooter, sizeof(dirfooter)); blocks = disk_free(buf->pvt.dir.dh.part); buf->data[2] = blocks & 0xff; buf->data[3] = blocks >> 8; buf->position = 0; buf->lastused = 31; buf->sendeoi = 1; return 0; }
/**************************************************************************** wrap it to get filenames right ****************************************************************************/ SMB_BIG_UINT sys_disk_free(const char *path, BOOL small_query, SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize) { return disk_free(path,small_query, bsize,dfree,dsize); }
/**************************************************************************** wrap it to get filenames right ****************************************************************************/ SMB_BIG_UINT sys_disk_free(char *path, BOOL small_query, SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize) { return(disk_free(dos_to_unix(path,False),small_query, bsize,dfree,dsize)); }