/* return filesystem space info */ static NTSTATUS svfs_fsinfo(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_fsinfo *fs) { struct svfs_private *p = ntvfs->private_data; struct stat st; if (fs->generic.level != RAW_QFS_GENERIC) { return ntvfs_map_fsinfo(ntvfs, req, fs); } if (sys_fsusage(p->connectpath, &fs->generic.out.blocks_free, &fs->generic.out.blocks_total) == -1) { return map_nt_error_from_unix(errno); } fs->generic.out.block_size = 512; if (stat(p->connectpath, &st) != 0) { return NT_STATUS_DISK_CORRUPT_ERROR; } fs->generic.out.fs_id = st.st_ino; unix_to_nt_time(&fs->generic.out.create_time, st.st_ctime); fs->generic.out.serial_number = st.st_ino; fs->generic.out.fs_attr = 0; fs->generic.out.max_file_component_length = 255; fs->generic.out.device_type = 0; fs->generic.out.device_characteristics = 0; fs->generic.out.quota_soft = 0; fs->generic.out.quota_hard = 0; fs->generic.out.quota_flags = 0; fs->generic.out.volume_name = talloc_strdup(req, ntvfs->ctx->config->name); fs->generic.out.fs_type = ntvfs->ctx->fs_type; return NT_STATUS_OK; }
SMB_BIG_UINT sys_disk_free(connection_struct *conn, const char *path, bool small_query, SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize) { SMB_BIG_UINT dfree_retval; SMB_BIG_UINT dfree_q = 0; SMB_BIG_UINT bsize_q = 0; SMB_BIG_UINT dsize_q = 0; const char *dfree_command; (*dfree) = (*dsize) = 0; (*bsize) = 512; /* * If external disk calculation specified, use it. */ dfree_command = lp_dfree_command(SNUM(conn)); if (dfree_command && *dfree_command) { const char *p; char **lines = NULL; char *syscmd = NULL; syscmd = talloc_asprintf(talloc_tos(), "%s %s", dfree_command, path); if (!syscmd) { return (SMB_BIG_UINT)-1; } DEBUG (3, ("disk_free: Running command %s\n", syscmd)); lines = file_lines_pload(syscmd, NULL); if (lines) { char *line = lines[0]; DEBUG (3, ("Read input from dfree, \"%s\"\n", line)); *dsize = STR_TO_SMB_BIG_UINT(line, &p); while (p && *p && isspace(*p)) p++; if (p && *p) *dfree = STR_TO_SMB_BIG_UINT(p, &p); while (p && *p && isspace(*p)) p++; if (p && *p) *bsize = STR_TO_SMB_BIG_UINT(p, NULL); else *bsize = 1024; file_lines_free(lines); DEBUG (3, ("Parsed output of dfree, dsize=%u, dfree=%u, bsize=%u\n", (unsigned int)*dsize, (unsigned int)*dfree, (unsigned int)*bsize)); if (!*dsize) *dsize = 2048; if (!*dfree) *dfree = 1024; } else { DEBUG (0, ("disk_free: sys_popen() failed for command %s. Error was : %s\n", syscmd, strerror(errno) )); if (sys_fsusage(path, dfree, dsize) != 0) { DEBUG (0, ("disk_free: sys_fsusage() failed. Error was : %s\n", strerror(errno) )); return (SMB_BIG_UINT)-1; } } } else { if (sys_fsusage(path, dfree, dsize) != 0) { DEBUG (0, ("disk_free: sys_fsusage() failed. Error was : %s\n", strerror(errno) )); return (SMB_BIG_UINT)-1; } } if (disk_quotas(path, &bsize_q, &dfree_q, &dsize_q)) { (*bsize) = bsize_q; (*dfree) = MIN(*dfree,dfree_q); (*dsize) = MIN(*dsize,dsize_q); } /* FIXME : Any reason for this assumption ? */ if (*bsize < 256) { DEBUG(5,("disk_free:Warning: bsize == %d < 256 . Changing to assumed correct bsize = 512\n",(int)*bsize)); *bsize = 512; } if ((*dsize)<1) { static bool done = false; if (!done) { DEBUG(0,("WARNING: dfree is broken on this system\n")); done=true; } *dsize = 20*1024*1024/(*bsize); *dfree = MAX(1,*dfree); } disk_norm(small_query,bsize,dfree,dsize); if ((*bsize) < 1024) { dfree_retval = (*dfree)/(1024/(*bsize)); } else { dfree_retval = ((*bsize)/1024)*(*dfree); } return(dfree_retval); }