Also pass buffer size to relevant functions when required.
char s[80];
char hostname[80];
gethostname(hostname, 79);
- sprintf(s,"clients.%s.%d", hostname, getpid());
+ snprintf(s, sizeof(s), "clients.%s.%d", hostname, getpid());
client_logger = new Logger(s, &client_logtype);
}
client_logger_lock.Unlock();
// now we need to turn it into a string
char foo[30];
__u8 *quad = (__u8*) &addr.in4_addr().sin_addr;
- sprintf(foo, "%d.%d.%d.%d", (int)quad[0], (int)quad[1], (int)quad[2], (int)quad[3]);
+ snprintf(foo, sizeof(foo), "%d.%d.%d.%d", (int)quad[0], (int)quad[1], (int)quad[2], (int)quad[3]);
address = foo;
return 0;
}
}
if (a.length() == 0 || a == "~") {
char s[30];
- sprintf(s,"syn.%lld.%d", (long long)client->whoami.v, seq);
+ snprintf(s, sizeof(s), "syn.%lld.%d", (long long)client->whoami.v, seq);
a = s;
}
return a;
int playdata = iargs.front(); iargs.pop_front();
string prefix = get_sarg(0);
char realtfile[100];
- sprintf(realtfile, tfile.c_str(), (int)client->get_nodeid().v);
+ snprintf(realtfile, sizeof(realtfile), tfile.c_str(), (int)client->get_nodeid().v);
if (run_me()) {
dout(-2) << "trace " << tfile << " prefix=" << prefix << " count=" << iarg1 << " data=" << playdata << dendl;
char d[500];
dout(3) << "make_dirs " << basedir << " dirs " << dirs << " files " << files << " depth " << depth << dendl;
for (int i=0; i<files; i++) {
- sprintf(d,"%s/file.%d", basedir, i);
+ snprintf(d, sizeof(d), "%s/file.%d", basedir, i);
client->mknod(d, 0644);
}
if (depth == 0) return 0;
for (int i=0; i<dirs; i++) {
- sprintf(d, "%s/dir.%d", basedir, i);
+ snprintf(d, sizeof(d), "%s/dir.%d", basedir, i);
make_dirs(d, dirs, files, depth-1);
}
char d[500];
dout(3) << "stat_dirs " << basedir << " dirs " << dirs << " files " << files << " depth " << depth << dendl;
for (int i=0; i<files; i++) {
- sprintf(d,"%s/file.%d", basedir, i);
+ snprintf(d, sizeof(d), "%s/file.%d", basedir, i);
client->lstat(d, &st);
}
if (depth == 0) return 0;
for (int i=0; i<dirs; i++) {
- sprintf(d, "%s/dir.%d", basedir, i);
+ snprintf(d, sizeof(d), "%s/dir.%d", basedir, i);
stat_dirs(d, dirs, files, depth-1);
}
}
for (int i=0; i<files; i++) {
- sprintf(d,"%s/file.%d", basedir, i);
+ snprintf(d, sizeof(d), "%s/file.%d", basedir, i);
utime_t s = g_clock.now();
if (client->lstat(d, &st) < 0) {
dout(2) << "read_dirs failed stat on " << d << ", stopping" << dendl;
if (depth > 0)
for (int i=0; i<dirs; i++) {
- sprintf(d, "%s/dir.%d", basedir, i);
+ snprintf(d, sizeof(d), "%s/dir.%d", basedir, i);
if (read_dirs(d, dirs, files, depth-1) < 0) return -1;
}
if (priv) {
for (int c=0; c<count; c++) {
- sprintf(d,"dir.%d.run%d", whoami, c);
+ snprintf(d, sizeof(d), "dir.%d.run%d", whoami, c);
client->mkdir(d, 0755);
}
} else {
// shared
if (true || whoami == 0) {
for (int c=0; c<count; c++) {
- sprintf(d,"dir.%d.run%d", 0, c);
+ snprintf(d, sizeof(d), "dir.%d.run%d", 0, c);
client->mkdir(d, 0755);
}
} else {
utime_t start = g_clock.now();
for (int c=0; c<count; c++) {
for (int n=0; n<num; n++) {
- sprintf(d,"dir.%d.run%d/file.client%d.%d", priv ? whoami:0, c, whoami, n);
+ snprintf(d, sizeof(d), "dir.%d.run%d/file.client%d.%d", priv ? whoami:0, c, whoami, n);
client->mknod(d, 0644);
utime_t start = g_clock.now();
for (int i=0; i<num; i++) {
- sprintf(d,"orig/file.%d", i);
+ snprintf(d, sizeof(d), "orig/file.%d", i);
client->mknod(d, 0755);
}
utime_t end = g_clock.now();
// link
start = g_clock.now();
for (int i=0; i<num; i++) {
- sprintf(d,"orig/file.%d", i);
- sprintf(e,"copy/file.%d", i);
+ snprintf(d, sizeof(d), "orig/file.%d", i);
+ snprintf(e, sizeof(e), "copy/file.%d", i);
client->link(d, e);
}
end = g_clock.now();
char d[255];
client->mkdir("test", 0755);
for (int n=0; n<num; n++) {
- sprintf(d,"test/file.%d", n);
+ snprintf(d, sizeof(d), "test/file.%d", n);
client->mknod(d, 0644);
}
// open
list<int> fds;
for (int n=0; n<num; n++) {
- sprintf(d,"test/file.%d", n);
+ snprintf(d, sizeof(d), "test/file.%d", n);
int fd = client->open(d,O_RDONLY);
if (fd > 0) fds.push_back(fd);
}
if (false && client->get_nodeid() == 0)
for (int n=0; n<num; n++) {
- sprintf(d,"test/file.%d", n);
+ snprintf(d, sizeof(d), "test/file.%d", n);
client->unlink(d);
}
client->mkdir("/a", 0755);
client->mkdir("/b", 0755);
for (int i=0; i<10; i++) {
- sprintf(a, "/a/%d", i);
+ snprintf(a, sizeof(a), "/a/%d", i);
client->mknod(a, 0644);
}
while (1) {
for (int i=0; i<10; i++) {
- sprintf(a, "/a/%d", i);
- sprintf(b, "/b/%d", i);
+ snprintf(a, sizeof(a), "/a/%d", i);
+ snprintf(b, sizeof(b), "/b/%d", i);
client->link(a, b);
}
for (int i=0; i<10; i++) {
- sprintf(b, "/b/%d", i);
+ snprintf(b, sizeof(b), "/b/%d", i);
client->unlink(b);
}
}
int b = rand() % s;
int c = rand() % s;
char src[80];
- sprintf(src, "syn.0.0/dir.%d/dir.%d/file.%d", a, b, c);
+ snprintf(src, sizeof(src), "syn.0.0/dir.%d/dir.%d/file.%d", a, b, c);
//int fd =
client->open(src, O_RDONLY);
}
int f = rand() % s;
char src[80];
char dst[80];
- sprintf(src, "syn.0.0/dir.%d/dir.%d/file.%d", a, b, c);
- sprintf(dst, "syn.0.0/dir.%d/dir.%d/file.%d", d, e, f);
+ snprintf(src, sizeof(src), "syn.0.0/dir.%d/dir.%d/file.%d", a, b, c);
+ snprintf(dst, sizeof(dst), "syn.0.0/dir.%d/dir.%d/file.%d", d, e, f);
client->rename(src, dst);
}
return;
int f = rand() % s;
char src[80];
char dst[80];
- sprintf(src, "syn.0.0/dir.%d/dir.%d/file.%d", a, b, c);
- sprintf(dst, "syn.0.0/dir.%d/dir.%d/newlink.%d", d, e, f);
+ snprintf(src, sizeof(src), "syn.0.0/dir.%d/dir.%d/file.%d", a, b, c);
+ snprintf(dst, sizeof(dst), "syn.0.0/dir.%d/dir.%d/newlink.%d", d, e, f);
client->link(src, dst);
}
srand(0);
int f = rand() % s;
char src[80];
char dst[80];
- sprintf(src, "syn.0.0/dir.%d/dir.%d/file.%d", a, b, c);
- sprintf(dst, "syn.0.0/dir.%d/dir.%d/newlink.%d", d, e, f);
+ snprintf(src, sizeof(src), "syn.0.0/dir.%d/dir.%d/file.%d", a, b, c);
+ snprintf(dst, sizeof(dst), "syn.0.0/dir.%d/dir.%d/newlink.%d", d, e, f);
client->unlink(dst);
}
char t[80];
for (int d=0; d<dep; d++) {
int a = rand() % dirs;
- sprintf(t, "/dir.%d", a);
+ snprintf(t, sizeof(t), "/dir.%d", a);
src += t;
}
}
char t[80];
for (int d=0; d<dep; d++) {
int a = rand() % dirs;
- sprintf(t, "/dir.%d", a);
+ snprintf(t, sizeof(t), "/dir.%d", a);
dst += t;
}
}
char t[80];
for (int d=0; d<depth; d++) {
int a = rand() % dirs;
- sprintf(t, "/dir.%d", a);
+ snprintf(t, sizeof(t), "/dir.%d", a);
src += t;
}
int a = rand() % files;
- sprintf(t, "/file.%d", a);
+ snprintf(t, sizeof(t), "/file.%d", a);
src += t;
}
string dst = basedir;
char t[80];
for (int d=0; d<depth; d++) {
int a = rand() % dirs;
- sprintf(t, "/dir.%d", a);
+ snprintf(t, sizeof(t), "/dir.%d", a);
dst += t;
}
int a = rand() % files;
- sprintf(t, "/file.%d", a);
+ snprintf(t, sizeof(t), "/file.%d", a);
dst += t;
}
if (depth) {
int d = rand() % (depth+1);
for (int k=0; k<d; k++) {
- sprintf(f, "/dir.%d", rand() % dirs);
+ snprintf(f, sizeof(f), "/dir.%d", rand() % dirs);
file += f;
}
}
- sprintf(f, "/file.%d", rand() % files);
+ snprintf(f, sizeof(f), "/file.%d", rand() % files);
file += f;
// pick a dir for our link
if (depth) {
int d = rand() % (depth+1);
for (int k=0; k<d; k++) {
- sprintf(f, "/dir.%d", rand() % dirs);
+ snprintf(f, sizeof(f), "/dir.%d", rand() % dirs);
ln += f;
}
}
- sprintf(f, "/ln.%d", i);
+ snprintf(f, sizeof(f), "/ln.%d", i);
ln += f;
client->link(file.c_str(), ln.c_str());
if (!m_open_file_map.get(fd, fdata)) {
char errbuf[32];
- sprintf(errbuf, "%d", fd);
+ snprintf(errbuf, sizeof(errbuf), "%d", fd);
cb->error(Error::DFSBROKER_BAD_FILE_HANDLE, errbuf);
HT_ERRORF("bad file handle: %d", fd);
return;
if (!m_open_file_map.get(fd, fdata)) {
char errbuf[32];
- sprintf(errbuf, "%d", fd);
+ snprintf(errbuf, sizeof(errbuf), "%d", fd);
cb->error(Error::DFSBROKER_BAD_FILE_HANDLE, errbuf);
return;
}
if (!m_open_file_map.get(fd, fdata)) {
char errbuf[32];
- sprintf(errbuf, "%d", fd);
+ snprintf(errbuf, sizeof(errbuf), "%d", fd);
cb->error(Error::DFSBROKER_BAD_FILE_HANDLE, errbuf);
return;
}
if (!m_open_file_map.get(fd, fdata)) {
char errbuf[32];
- sprintf(errbuf, "%d", fd);
+ snprintf(errbuf, sizeof(errbuf), "%d", fd);
cb->error(Error::DFSBROKER_BAD_FILE_HANDLE, errbuf);
return;
}
if (!m_open_file_map.get(fd, fdata)) {
char errbuf[32];
- sprintf(errbuf, "%d", fd);
+ snprintf(errbuf, sizeof(errbuf), "%d", fd);
cb->error(Error::DFSBROKER_BAD_FILE_HANDLE, errbuf);
return;
}
// cd on exit, so that gmon.out (if any) goes into a separate directory for each node.
char s[20];
- sprintf(s, "gmon/%d", getpid());
+ snprintf(s, sizeof(s), "gmon/%d", getpid());
if (mkdir(s, 0755) == 0)
chdir(s);
// cd on exit, so that gmon.out (if any) goes into a separate directory for each node.
char s[20];
- sprintf(s, "gmon/%d", getpid());
+ snprintf(s, sizeof(s), "gmon/%d", getpid());
if (mkdir(s, 0755) == 0)
chdir(s);
char hostname[80];
gethostname(hostname, 79);
- sprintf(_dout_path, "%s/%s.%d", _dout_dir, hostname, getpid());
- sprintf(_dout_file, "%s.%d", hostname, getpid());
+ snprintf(_dout_path, sizeof(_dout_path), "%s/%s.%d", _dout_dir, hostname, getpid());
+ snprintf(_dout_file, sizeof(_dout_file), "%s.%d", hostname, getpid());
}
_dout_out.close();
gethostname(hostname, 79);
strcpy(oldpath, _dout_path);
- sprintf(_dout_path, "%s/%s.%d", _dout_dir, hostname, getpid());
- sprintf(_dout_file, "%s.%d", hostname, getpid());
+ snprintf(_dout_path, sizeof(_dout_path), "%s/%s.%d", _dout_dir, hostname, getpid());
+ snprintf(_dout_file, sizeof(_dout_file), "%s.%d", hostname, getpid());
dout(0) << "---- renamed log " << oldpath << " -> " << _dout_path << " ----" << dendl;
::rename(oldpath, _dout_path);
if (_dout_need_open)
_dout_open_log();
- sprintf(_dout_symlink_path, "%s/%s%lld", _dout_symlink_dir, type, (long long)n);
+ snprintf(_dout_symlink_path, sizeof(_dout_symlink_path), "%s/%s%lld", _dout_symlink_dir, type, (long long)n);
// rotate out old symlink
int n = 0;
while (1) {
char fn[200];
struct stat st;
- sprintf(fn, "%s.%lld", _dout_symlink_path, (long long)n);
+ snprintf(fn, sizeof(fn), "%s.%lld", _dout_symlink_path, (long long)n);
if (::stat(fn, &st) != 0)
break;
n++;
while (n >= 0) {
char a[200], b[200];
if (n)
- sprintf(a, "%s.%lld", _dout_symlink_path, (long long)n-1);
+ snprintf(a, sizeof(a), "%s.%lld", _dout_symlink_path, (long long)n-1);
else
- sprintf(a, "%s", _dout_symlink_path);
- sprintf(b, "%s.%lld", _dout_symlink_path, (long long)n);
+ snprintf(a, sizeof(a), "%s", _dout_symlink_path);
+ snprintf(b, sizeof(b), "%s.%lld", _dout_symlink_path, (long long)n);
::rename(a, b);
dout(0) << "---- renamed symlink " << a << " -> " << b << " ----" << dendl;
n--;
g_conf.type = strdup(module_type);
if (g_conf.id) {
- g_conf.name = (char *)malloc(strlen(module_type) + strlen(g_conf.id) + 2);
- sprintf(g_conf.name, "%s.%s", g_conf.type, g_conf.id);
- g_conf.alt_name = (char *)malloc(strlen(module_type) + strlen(g_conf.id) + 1);
- sprintf(g_conf.alt_name, "%s%s", module_type, g_conf.id);
+ int len = strlen(module_type) + strlen(g_conf.id) + 2;
+ g_conf.name = (char *)malloc(len);
+ snprintf(g_conf.name, len, "%s.%s", g_conf.type, g_conf.id);
+ g_conf.alt_name = (char *)malloc(len - 1);
+ snprintf(g_conf.alt_name, len - 1, "%s%s", module_type, g_conf.id);
} else {
g_conf.name = g_conf.type;
}
// cd on exit, so that gmon.out (if any) goes into a separate directory for each node.
char s[20];
- sprintf(s, "gmon/%d", getpid());
+ snprintf(s, sizeof(s), "gmon/%d", getpid());
if (mkdir(s, 0755) == 0)
chdir(s);
void print_fixedpoint(ostream& out, int i)
{
char s[20];
- sprintf(s, "%.3f", (float)i / (float)0x10000);
+ snprintf(s, sizeof(s), "%.3f", (float)i / (float)0x10000);
out << s;
}
char format[20];
if (l.size)
- sprintf(format, "%s%%d", l.name);
+ snprintf(format, sizeof(format), "%s%%d", l.name);
else
strcpy(format, l.name);
char name[20];
- sprintf(name, format, i);
+ snprintf(name, sizeof(name), format, i);
crush.set_item_name(id, name);
dout(0) << " in bucket " << id << " '" << name << "' size " << j << " weight " << weight << dendl;
static char s[20];
float sz = b*4.0;
if (sz > (10 << 20))
- sprintf(s,"%.1f GB", sz / (1024.0*1024.0));
+ snprintf(s, sizeof(s), "%.1f GB", sz / (1024.0*1024.0));
else if (sz > (10 << 10))
- sprintf(s,"%.1f MB", sz / (1024.0));
+ snprintf(s, sizeof(s), "%.1f MB", sz / (1024.0));
else
- sprintf(s,"%llu KB", b*4ULL);
+ snprintf(s, sizeof(s), "%llu KB", b*4ULL);
return s;
}
Monitor *mon[g_conf.num_mon];
for (int i=0; i<g_conf.num_mon; i++) {
char fn[100];
- sprintf(fn, "mondata/mon%d", i);
+ snprintf(fn, sizeof(fn), "mondata/mon%d", i);
MonitorStore *store = new MonitorStore(fn);
mon[i] = new Monitor(i, store, new FakeMessenger(entity_name_t::MON(i)), monmap);
mon[i]->mkfs();
Monitor *mon[g_conf.num_mon];
for (int i=0; i<g_conf.num_mon; i++) {
char fn[100];
- sprintf(fn, "mondata/mon%d", i);
+ snprintf(fn, sizeof(fn), "mondata/mon%d", i);
MonitorStore *store = new MonitorStore(fn);
mon[i] = new Monitor(i, store, new FakeMessenger(entity_name_t::MON(i)), monmap);
mon[i]->mkfs();
}
else {
char n[20];
- sprintf(n, "#%llx", (unsigned long long)(ino()));
+ snprintf(n, sizeof(n), "#%llx", (unsigned long long)(ino()));
s += n;
}
}
void CInode::name_stray_dentry(string& dname)
{
char s[20];
- sprintf(s, "%llx", (unsigned long long)inode.ino.val);
+ snprintf(s, sizeof(s), "%llx", (unsigned long long)inode.ino.val);
dname = s;
}
m.setxattr("inode", bl);
char n[30];
- sprintf(n, "%llx.%08llx", (long long unsigned)ino(), (long long unsigned)frag_t());
+ snprintf(n, sizeof(n), "%llx.%08llx", (long long unsigned)ino(), (long long unsigned)frag_t());
object_t oid(n);
OSDMap *osdmap = mdcache->mds->objecter->osdmap;
ceph_object_layout ol = osdmap->make_object_layout(oid,
C_Inode_Fetched *c = new C_Inode_Fetched(this, fin);
char n[30];
- sprintf(n, "%llx.%08llx", (long long unsigned)ino(), (long long unsigned)frag_t());
+ snprintf(n, sizeof(n), "%llx.%08llx", (long long unsigned)ino(), (long long unsigned)frag_t());
object_t oid(n);
ObjectOperation rd;
SnapContext snapc;
char n[30];
- sprintf(n, "%llx.%08llx", (long long unsigned)ino(), (long long unsigned)frag_t());
+ snprintf(n, sizeof(n), "%llx.%08llx", (long long unsigned)ino(), (long long unsigned)frag_t());
object_t oid(n);
OSDMap *osdmap = mdcache->mds->objecter->osdmap;
ceph_object_layout ol = osdmap->make_object_layout(oid,
return; // this is dumb
- char fn[20];
- sprintf(fn, "popdump.%d.mds%d", beat_epoch, mds->get_nodeid());
+ char fn[32];
+ snprintf(fn, sizeof(fn), "popdump.%d.mds%d", beat_epoch, mds->get_nodeid());
dout(1) << "dump_pop_map to " << fn << dendl;
// create mds dir
char myname[10];
- sprintf(myname, "mds%d", mds->whoami);
+ snprintf(myname, sizeof(myname), "mds%d", mds->whoami);
CInode *my = create_system_inode(MDS_INO_MDSDIR(mds->whoami), S_IFDIR);
CDir *mydir = my->get_or_open_dirfrag(this, frag_t());
cephdir->add_primary_dentry(myname, my);
}
char n[10];
- sprintf(n, "mds%d", mds->whoami);
+ snprintf(n, sizeof(n), "mds%d", mds->whoami);
CDentry *mydn = cephdir->lookup(n);
assert(mydn);
}
char n[10];
- sprintf(n, "mds%d", mds->whoami);
+ snprintf(n, sizeof(n), "mds%d", mds->whoami);
CDentry *mydn = cephdir->lookup(n);
if (!mydn) {
filepath fp;
void MDCache::purge_prealloc_ino(inodeno_t ino, Context *fin)
{
char n[30];
- sprintf(n, "%llx.%08llx", (long long unsigned)ino, 0ull);
+ snprintf(n, sizeof(n), "%llx.%08llx", (long long unsigned)ino, 0ull);
object_t oid(n);
dout(10) << "purge_prealloc_ino " << ino << " oid " << oid << dendl;
ceph_object_layout ol = mds->osdmap->make_object_layout(oid,
// is this a new mds dir?
if (curdir->ino() == MDS_INO_CEPH) {
char t[10];
- sprintf(t, "mds%d", from);
+ snprintf(t, sizeof(t), "mds%d", from);
if (t == dis->get_dentry(i)) {
// yes.
_create_system_file(curdir, t, create_system_inode(MDS_INO_MDSDIR(from), S_IFDIR),
char s[10];
if (dir->get_dir_auth().second == CDIR_AUTH_UNKNOWN)
- sprintf(s, "%2d ", dir->get_dir_auth().first);
+ snprintf(s, sizeof(s), "%2d ", dir->get_dir_auth().first);
else
- sprintf(s, "%2d,%2d", dir->get_dir_auth().first, dir->get_dir_auth().second);
+ snprintf(s, sizeof(s), "%2d,%2d", dir->get_dir_auth().first, dir->get_dir_auth().second);
// print
dout(dbl) << indent << "|_" << pad << s << " " << auth << *dir << dendl;
char deffn[200];
if (!fn) {
- sprintf(deffn, "cachedump.%d.mds%d", (int)mds->mdsmap->get_epoch(), mds->get_nodeid());
+ snprintf(deffn, sizeof(deffn), "cachedump.%d.mds%d", (int)mds->mdsmap->get_epoch(), mds->get_nodeid());
fn = deffn;
}
{
// logger
char name[80];
- sprintf(name, "mds%d.log", mds->get_nodeid());
+ snprintf(name, sizeof(name), "mds%d.log", mds->get_nodeid());
logger = new Logger(name, &mdlog_logtype, append);
logger->set_start(start);
// log
char name[80];
- sprintf(name, "mds%d", whoami);
+ snprintf(name, sizeof(name), "mds%d", whoami);
bool append = mdsmap->get_inc(whoami) > 1;
logger = new Logger(name, (LogType*)&mds_logtype, append);
logger->set_start(start);
- sprintf(name, "mds%d.mem", whoami);
+ snprintf(name, sizeof(name), "mds%d.mem", whoami);
mlogger = new Logger(name, (LogType*)&mdm_logtype, append);
mdlog->reopen_logger(start, append);
{
char n[50];
if (per_mds)
- sprintf(n, "mds%d_%s", mds->whoami, table_name);
+ snprintf(n, sizeof(n), "mds%d_%s", mds->whoami, table_name);
else
- sprintf(n, "mds_%s", table_name);
+ snprintf(n, sizeof(n), "mds_%s", table_name);
return object_t(n);
}
// logger
char name[80];
- sprintf(name, "mds%d.server", mds->get_nodeid());
+ snprintf(name, sizeof(name), "mds%d.server", mds->get_nodeid());
logger = new Logger(name, &mdserver_logtype, append);
logger->set_start(start);
}
object_t SessionMap::get_object_name()
{
char s[30];
- sprintf(s, "mds%d_sessionmap", mds->whoami);
+ snprintf(s, sizeof(s), "mds%d_sessionmap", mds->whoami);
return object_t(s);
}
{
if (long_name.length() == 0) {
char nm[80];
- sprintf(nm, "_%s_%llu", name.c_str(), (unsigned long long)ino);
+ snprintf(nm, sizeof(nm), "_%s_%llu", name.c_str(), (unsigned long long)ino);
long_name = nm;
}
return long_name;
for (int i=0; i<15; i++) {
char monname[20];
char *val = 0;
- sprintf(monname, "mon%d", i);
+ snprintf(monname, sizeof(monname), "mon%d", i);
c.read(monname, "mon addr", &val, 0);
if (!val || !val[0])
break;
int MonitorStore::mount()
{
- char t[200];
+ char t[1024];
dout(1) << "mount" << dendl;
// verify dir exists
::closedir(d);
// open lockfile
- sprintf(t, "%s/lock", dir.c_str());
+ snprintf(t, sizeof(t), "%s/lock", dir.c_str());
lock_fd = ::open(t, O_CREAT|O_RDWR, 0600);
if (lock_fd < 0)
return -errno;
if (g_conf.chdir && g_conf.chdir[0] && dir[0] != '/') {
// combine it with the cwd, in case fuse screws things up (i.e. fakefuse)
string old = dir;
- char cwd[200];
- getcwd(cwd, 200);
+ char cwd[1024];
+ getcwd(cwd, sizeof(cwd));
dir = cwd;
dir += "/";
dir += old;
{
dout(1) << "mkfs" << dendl;
- char cmd[200];
- sprintf(cmd, "test -d %s && /bin/rm -r %s ; mkdir -p %s", dir.c_str(), dir.c_str(), dir.c_str());
+ char cmd[1024];
+ snprintf(cmd, sizeof(cmd), "test -d %s && /bin/rm -r %s ; mkdir -p %s", dir.c_str(), dir.c_str(), dir.c_str());
dout(1) << cmd << dendl;
int r = system(cmd);
return r;
version_t MonitorStore::get_int(const char *a, const char *b)
{
- char fn[200];
+ char fn[1024];
if (b)
- sprintf(fn, "%s/%s/%s", dir.c_str(), a, b);
+ snprintf(fn, sizeof(fn), "%s/%s/%s", dir.c_str(), a, b);
else
- sprintf(fn, "%s/%s", dir.c_str(), a);
+ snprintf(fn, sizeof(fn), "%s/%s", dir.c_str(), a);
FILE *f = ::fopen(fn, "r");
if (!f)
void MonitorStore::put_int(version_t val, const char *a, const char *b, bool sync)
{
- char fn[200];
- sprintf(fn, "%s/%s", dir.c_str(), a);
+ char fn[1024];
+ snprintf(fn, sizeof(fn), "%s/%s", dir.c_str(), a);
if (b) {
::mkdir(fn, 0755);
dout(15) << "set_int " << a << "/" << b << " = " << val << dendl;
- sprintf(fn, "%s/%s/%s", dir.c_str(), a, b);
+ snprintf(fn, sizeof(fn), "%s/%s/%s", dir.c_str(), a, b);
} else {
dout(15) << "set_int " << a << " = " << val << dendl;
}
char vs[30];
- sprintf(vs, "%lld\n", (unsigned long long)val);
+ snprintf(vs, sizeof(vs), "%lld\n", (unsigned long long)val);
- char tfn[200];
- sprintf(tfn, "%s.new", fn);
+ char tfn[1024];
+ snprintf(tfn, sizeof(tfn), "%s.new", fn);
int fd = ::open(tfn, O_WRONLY|O_CREAT, 0644);
assert(fd >= 0);
bool MonitorStore::exists_bl_ss(const char *a, const char *b)
{
- char fn[200];
+ char fn[1024];
if (b) {
dout(15) << "exists_bl " << a << "/" << b << dendl;
- sprintf(fn, "%s/%s/%s", dir.c_str(), a, b);
+ snprintf(fn, sizeof(fn), "%s/%s/%s", dir.c_str(), a, b);
} else {
dout(15) << "exists_bl " << a << dendl;
- sprintf(fn, "%s/%s", dir.c_str(), a);
+ snprintf(fn, sizeof(fn), "%s/%s", dir.c_str(), a);
}
struct stat st;
int MonitorStore::erase_ss(const char *a, const char *b)
{
- char fn[200];
+ char fn[1024];
if (b) {
dout(15) << "erase_ss " << a << "/" << b << dendl;
- sprintf(fn, "%s/%s/%s", dir.c_str(), a, b);
+ snprintf(fn, sizeof(fn), "%s/%s/%s", dir.c_str(), a, b);
} else {
dout(15) << "erase_ss " << a << dendl;
- sprintf(fn, "%s/%s", dir.c_str(), a);
+ snprintf(fn, sizeof(fn), "%s/%s", dir.c_str(), a);
}
return ::unlink(fn);
}
int MonitorStore::get_bl_ss(bufferlist& bl, const char *a, const char *b)
{
- char fn[200];
+ char fn[1024];
if (b) {
- sprintf(fn, "%s/%s/%s", dir.c_str(), a, b);
+ snprintf(fn, sizeof(fn), "%s/%s/%s", dir.c_str(), a, b);
} else {
- sprintf(fn, "%s/%s", dir.c_str(), a);
+ snprintf(fn, sizeof(fn), "%s/%s", dir.c_str(), a);
}
int fd = ::open(fn, O_RDONLY);
int MonitorStore::write_bl_ss(bufferlist& bl, const char *a, const char *b, bool append, bool sync)
{
- char fn[200];
- sprintf(fn, "%s/%s", dir.c_str(), a);
+ char fn[1024];
+ snprintf(fn, sizeof(fn), "%s/%s", dir.c_str(), a);
if (b) {
::mkdir(fn, 0755);
dout(15) << "put_bl " << a << "/" << b << " = " << bl.length() << " bytes" << dendl;
- sprintf(fn, "%s/%s/%s", dir.c_str(), a, b);
+ snprintf(fn, sizeof(fn), "%s/%s/%s", dir.c_str(), a, b);
} else {
dout(15) << "put_bl " << a << " = " << bl.length() << " bytes" << dendl;
}
- char tfn[200];
+ char tfn[1024];
int err = 0;
int fd;
if (append) {
fd = ::open(fn, O_WRONLY|O_CREAT|O_APPEND, 0644);
} else {
- sprintf(tfn, "%s.new", fn);
+ snprintf(tfn, sizeof(tfn), "%s.new", fn);
fd = ::open(tfn, O_WRONLY|O_CREAT, 0644);
}
assert(fd >= 0);
signals_have_been_setup = 1;
}
- sprintf(linktargetfile, MOUNTLOCK_LINKTARGET, getpid ());
+ snprintf(linktargetfile, sizeof(linktargetfile), MOUNTLOCK_LINKTARGET,
+ getpid ());
i = open (linktargetfile, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
if (i < 0) {
loggers[dest]->inc("-recv",1);
char s[20];
- sprintf(s,"+%s", m->get_type_name());
+ snprintf(s, sizeof(s), "+%s", m->get_type_name());
loggers[get_myaddr()]->inc(s);
- sprintf(s,"-%s", m->get_type_name());
+ snprintf(s, sizeof(s), ,"-%s", m->get_type_name());
loggers[dest]->inc(s);
#endif
char buf[20];
while (left > 0) {
if (col == 0) {
- sprintf(buf, "%05x : ", pos);
+ snprintf(buf, sizeof(buf), "%05x : ", pos);
*_dout << buf;
}
- sprintf(buf, " %02x", ((unsigned char*)v->iov_base)[vpos]);
+ snprintf(buf, sizeof(buf), " %02x", ((unsigned char*)v->iov_base)[vpos]);
*_dout << buf;
left--;
if (!left)
int fd = ::open(g_conf.pid_file, O_CREAT|O_TRUNC|O_WRONLY, 0644);
if (fd >= 0) {
char buf[20];
- int len = sprintf(buf, "%d\n", pid);
+ int len = snprintf(buf, sizeof(buf), "%d\n", pid);
::write(fd, buf, len);
::close(fd);
}
// .............
-void get_attrname(const char *name, char *buf)
+static void get_attrname(const char *name, char *buf, int len)
{
- sprintf(buf, "user.ceph.%s", name);
+ snprintf(buf, len, "user.ceph.%s", name);
}
bool parse_attrname(char **name)
{
// 012345678901234567890123456789012345678901234567890123456789
// yyyyyyyyyyyyyyyy.zzzzzzzz.a_s
-void FileStore::append_oname(const sobject_t &oid, char *s)
+void FileStore::append_oname(const sobject_t &oid, char *s, int len)
{
//assert(sizeof(oid) == 28);
char *t = s + strlen(s);
}
if (oid.snap == CEPH_NOSNAP)
- sprintf(t, "_head");
+ snprintf(t, len, "_head");
else if (oid.snap == CEPH_SNAPDIR)
- sprintf(t, "_snapdir");
+ snprintf(t, len, "_snapdir");
else
- sprintf(t, "_%llx", (long long unsigned)oid.snap);
+ snprintf(t, len, "_%llx", (long long unsigned)oid.snap);
//parse_object(t+1);
}
return r;
}
-void FileStore::get_cdir(coll_t cid, char *s)
+void FileStore::get_cdir(coll_t cid, char *s, int len)
{
- s += sprintf(s, "%s/current/", basedir.c_str());
- s += cid.print(s);
+ int ret = snprintf(s, len, "%s/current/", basedir.c_str());
+ s += ret;
+ len -= ret;
+ s += cid.print(s, len);
}
-void FileStore::get_coname(coll_t cid, const sobject_t& oid, char *s)
+void FileStore::get_coname(coll_t cid, const sobject_t& oid, char *s, int len)
{
- get_cdir(cid, s);
- append_oname(oid, s);
+ get_cdir(cid, s, len);
+ append_oname(oid, s, len);
}
int FileStore::open_journal()
char cmd[PATH_MAX];
if (g_conf.filestore_dev) {
dout(0) << "mounting" << dendl;
- sprintf(cmd,"mount %s", g_conf.filestore_dev);
+ snprintf(cmd, sizeof(cmd), "mount %s", g_conf.filestore_dev);
system(cmd);
}
dout(1) << "mkfs in " << basedir << dendl;
char fn[PATH_MAX];
- sprintf(fn, "%s/fsid", basedir.c_str());
+ snprintf(fn, sizeof(fn), "%s/fsid", basedir.c_str());
fsid_fd = ::open(fn, O_CREAT|O_RDWR, 0644);
if (lock_fsid() < 0)
return -EBUSY;
// wipe
- sprintf(cmd, "test -d %s && ( test -d %s/current && rm -r %s/current/* %s/fsid || rm -r %s/* ) ; mkdir -p %s",
+ snprintf(cmd, sizeof(cmd), "test -d %s && ( test -d %s/current && rm -r %s/current/* %s/fsid || rm -r %s/* ) ; mkdir -p %s",
basedir.c_str(), basedir.c_str(), basedir.c_str(), basedir.c_str(), basedir.c_str(), basedir.c_str());
dout(5) << "wipe: " << cmd << dendl;
strcpy(volargs.name, "current");
int r = ::ioctl(fd, BTRFS_IOC_SUBVOL_CREATE, (unsigned long int)&volargs);
char current_fn[PATH_MAX];
- sprintf(current_fn, "%s/current", basedir.c_str());
+ snprintf(current_fn, sizeof(current_fn), "%s/current", basedir.c_str());
if (r == 0) {
// yay
dout(2) << " created btrfs subvol " << current_fn << dendl;
if (g_conf.filestore_dev) {
char cmd[PATH_MAX];
dout(0) << "umounting" << dendl;
- sprintf(cmd,"umount %s", g_conf.filestore_dev);
+ snprintf(cmd, sizeof(cmd), "umount %s", g_conf.filestore_dev);
//system(cmd);
}
if (g_conf.filestore_dev) {
dout(0) << "mounting" << dendl;
char cmd[100];
- sprintf(cmd,"mount %s", g_conf.filestore_dev);
+ snprintf(cmd, sizeof(cmd), "mount %s", g_conf.filestore_dev);
//system(cmd);
}
// get fsid
char fn[PATH_MAX];
- sprintf(fn, "%s/fsid", basedir.c_str());
+ snprintf(fn, sizeof(fn), "%s/fsid", basedir.c_str());
// fake attrs?
// let's test to see if they work.
dout(10) << "mount fsid is " << fsid << dendl;
// get epoch
- sprintf(fn, "%s/current/commit_op_seq", basedir.c_str());
+ snprintf(fn, sizeof(fn), "%s/current/commit_op_seq", basedir.c_str());
op_fd = ::open(fn, O_CREAT|O_RDWR, 0644);
assert(op_fd >= 0);
op_seq = 0;
if (g_conf.filestore_dev) {
char cmd[PATH_MAX];
dout(0) << "umounting" << dendl;
- sprintf(cmd,"umount %s", g_conf.filestore_dev);
+ snprintf(cmd, sizeof(cmd), "umount %s", g_conf.filestore_dev);
//system(cmd);
}
dout(10) << "transaction_start " << fd << dendl;
char fn[PATH_MAX];
- sprintf(fn, "%s/current/trans.%d", basedir.c_str(), fd);
+ snprintf(fn, sizeof(fn), "%s/current/trans.%d", basedir.c_str(), fd);
::mknod(fn, 0644, 0);
return fd;
return;
char fn[PATH_MAX];
- sprintf(fn, "%s/current/trans.%d", basedir.c_str(), fd);
+ snprintf(fn, sizeof(fn), "%s/current/trans.%d", basedir.c_str(), fd);
::unlink(fn);
dout(10) << "transaction_finish " << fd << dendl;
int FileStore::stat(coll_t cid, const sobject_t& oid, struct stat *st)
{
char fn[PATH_MAX];
- get_coname(cid, oid, fn);
+ get_coname(cid, oid, fn, sizeof(fn));
int r = ::stat(fn, st);
dout(10) << "stat " << fn << " = " << r << dendl;
return r < 0 ? -errno:r;
__u64 offset, size_t len,
bufferlist& bl) {
char fn[PATH_MAX];
- get_coname(cid, oid, fn);
+ get_coname(cid, oid, fn, sizeof(fn));
dout(15) << "read " << fn << " " << offset << "~" << len << dendl;
int FileStore::_remove(coll_t cid, const sobject_t& oid)
{
char fn[PATH_MAX];
- get_coname(cid, oid, fn);
+ get_coname(cid, oid, fn, sizeof(fn));
dout(15) << "remove " << fn << dendl;
int r = ::unlink(fn);
if (r < 0) r = -errno;
int FileStore::_truncate(coll_t cid, const sobject_t& oid, __u64 size)
{
char fn[PATH_MAX];
- get_coname(cid, oid, fn);
+ get_coname(cid, oid, fn, sizeof(fn));
dout(15) << "truncate " << fn << " size " << size << dendl;
int r = ::truncate(fn, size);
if (r < 0) r = -errno;
int FileStore::_touch(coll_t cid, const sobject_t& oid)
{
char fn[PATH_MAX];
- get_coname(cid, oid, fn);
+ get_coname(cid, oid, fn, sizeof(fn));
dout(15) << "touch " << fn << dendl;
const bufferlist& bl)
{
char fn[PATH_MAX];
- get_coname(cid, oid, fn);
+ get_coname(cid, oid, fn, sizeof(fn));
dout(15) << "write " << fn << " " << offset << "~" << len << dendl;
int r;
int FileStore::_clone(coll_t cid, const sobject_t& oldoid, const sobject_t& newoid)
{
char ofn[PATH_MAX], nfn[PATH_MAX];
- get_coname(cid, oldoid, ofn);
- get_coname(cid, newoid, nfn);
+ get_coname(cid, oldoid, ofn, sizeof(ofn));
+ get_coname(cid, newoid, nfn, sizeof(nfn));
dout(15) << "clone " << ofn << " -> " << nfn << dendl;
int FileStore::_clone_range(coll_t cid, const sobject_t& oldoid, const sobject_t& newoid, __u64 off, __u64 len)
{
char ofn[PATH_MAX], nfn[PATH_MAX];
- get_coname(cid, oldoid, ofn);
- get_coname(cid, newoid, nfn);
+ get_coname(cid, oldoid, ofn, sizeof(ofn));
+ get_coname(cid, newoid, nfn, sizeof(ofn));
dout(15) << "clone_range " << ofn << " -> " << nfn << " " << off << "~" << len << dendl;
if (btrfs_snap) {
btrfs_ioctl_vol_args snapargs;
snapargs.fd = snapdir_fd;
- sprintf(snapargs.name, COMMIT_SNAP_ITEM, (long long unsigned)cp);
+ snprintf(snapargs.name, sizeof(snapargs.name), COMMIT_SNAP_ITEM, (long long unsigned)cp);
dout(0) << "taking snap '" << snapargs.name << "'" << dendl;
int r = ::ioctl(snapargs.fd, BTRFS_IOC_SNAP_CREATE, &snapargs);
char buf[100];
while (snaps.size() > 2) {
btrfs_ioctl_vol_args snapargs;
snapargs.fd = snapdir_fd;
- sprintf(snapargs.name, COMMIT_SNAP_ITEM, (long long unsigned)snaps.front());
+ snprintf(snapargs.name, sizeof(snapargs.name), COMMIT_SNAP_ITEM, (long long unsigned)snaps.front());
snaps.pop_front();
dout(0) << "removing snap '" << snapargs.name << "'" << dendl;
int r = ::ioctl(snapargs.fd, BTRFS_IOC_SNAP_DESTROY, &snapargs);
if (fake_attrs) return attrs.getattr(cid, oid, name, value, size);
char fn[PATH_MAX];
- get_coname(cid, oid, fn);
+ get_coname(cid, oid, fn, sizeof(fn));
dout(15) << "getattr " << fn << " '" << name << "' len " << size << dendl;
char n[ATTR_MAX];
- get_attrname(name, n);
+ get_attrname(name, n, ATTR_MAX);
int r = do_getxattr(fn, n, value, size);
dout(10) << "getattr " << fn << " '" << name << "' len " << size << " = " << r << dendl;
return r;
if (fake_attrs) return attrs.getattr(cid, oid, name, bp);
char fn[PATH_MAX];
- get_coname(cid, oid, fn);
+ get_coname(cid, oid, fn, sizeof(fn));
dout(15) << "getattr " << fn << " '" << name << "'" << dendl;
char n[ATTR_MAX];
- get_attrname(name, n);
+ get_attrname(name, n, ATTR_MAX);
int r = _getattr(fn, n, bp);
dout(10) << "getattr " << fn << " '" << name << "' = " << r << dendl;
return r;
if (fake_attrs) return attrs.getattrs(cid, oid, aset);
char fn[PATH_MAX];
- get_coname(cid, oid, fn);
+ get_coname(cid, oid, fn, sizeof(fn));
dout(15) << "getattrs " << fn << dendl;
int r = _getattrs(fn, aset, user_only);
dout(10) << "getattrs " << fn << " = " << r << dendl;
if (fake_attrs) return attrs.setattr(cid, oid, name, value, size);
char fn[PATH_MAX];
- get_coname(cid, oid, fn);
+ get_coname(cid, oid, fn, sizeof(fn));
dout(15) << "setattr " << fn << " '" << name << "' len " << size << dendl;
char n[ATTR_MAX];
- get_attrname(name, n);
+ get_attrname(name, n, ATTR_MAX);
int r = do_setxattr(fn, n, value, size);
dout(10) << "setattr " << fn << " '" << name << "' len " << size << " = " << r << dendl;
return r;
if (fake_attrs) return attrs.setattrs(cid, oid, aset);
char fn[PATH_MAX];
- get_coname(cid, oid, fn);
+ get_coname(cid, oid, fn, sizeof(fn));
dout(15) << "setattrs " << fn << dendl;
int r = 0;
for (map<nstring,bufferptr>::iterator p = aset.begin();
p != aset.end();
++p) {
char n[ATTR_MAX];
- get_attrname(p->first.c_str(), n);
+ get_attrname(p->first.c_str(), n, ATTR_MAX);
const char *val;
if (p->second.length())
val = p->second.c_str();
if (fake_attrs) return attrs.rmattr(cid, oid, name);
char fn[PATH_MAX];
- get_coname(cid, oid, fn);
+ get_coname(cid, oid, fn, sizeof(fn));
dout(15) << "rmattr " << fn << " '" << name << "'" << dendl;
char n[ATTR_MAX];
- get_attrname(name, n);
+ get_attrname(name, n, ATTR_MAX);
int r = do_removexattr(fn, n);
dout(10) << "rmattr " << fn << " '" << name << "' = " << r << dendl;
return r;
//if (fake_attrs) return attrs.rmattrs(cid, oid);
char fn[PATH_MAX];
- get_coname(cid, oid, fn);
+ get_coname(cid, oid, fn, sizeof(fn));
dout(15) << "rmattrs " << fn << dendl;
if (r >= 0) {
for (map<nstring,bufferptr>::iterator p = aset.begin(); p != aset.end(); p++) {
char n[ATTR_MAX];
- get_attrname(p->first.c_str(), n);
+ get_attrname(p->first.c_str(), n, ATTR_MAX);
r = do_removexattr(fn, n);
if (r < 0)
break;
if (fake_attrs) return attrs.collection_getattr(c, name, value, size);
char fn[PATH_MAX];
- get_cdir(c, fn);
+ get_cdir(c, fn, sizeof(fn));
dout(15) << "collection_getattr " << fn << " '" << name << "' len " << size << dendl;
char n[PATH_MAX];
- get_attrname(name, n);
+ get_attrname(name, n, PATH_MAX);
int r = do_getxattr(fn, n, value, size);
dout(10) << "collection_getattr " << fn << " '" << name << "' len " << size << " = " << r << dendl;
return r;
if (fake_attrs) return attrs.collection_getattr(c, name, bl);
char fn[PATH_MAX];
- get_cdir(c, fn);
+ get_cdir(c, fn, sizeof(fn));
dout(15) << "collection_getattr " << fn << " '" << name << "'" << dendl;
char n[PATH_MAX];
- get_attrname(name, n);
+ get_attrname(name, n, PATH_MAX);
buffer::ptr bp;
int r = _getattr(fn, n, bp);
if (fake_attrs) return attrs.collection_getattrs(cid, aset);
char fn[PATH_MAX];
- get_cdir(cid, fn);
+ get_cdir(cid, fn, sizeof(fn));
dout(10) << "collection_getattrs " << fn << dendl;
int r = _getattrs(fn, aset);
dout(10) << "collection_getattrs " << fn << " = " << r << dendl;
if (fake_attrs) return attrs.collection_setattr(c, name, value, size);
char fn[PATH_MAX];
- get_cdir(c, fn);
+ get_cdir(c, fn, sizeof(fn));
dout(10) << "collection_setattr " << fn << " '" << name << "' len " << size << dendl;
char n[PATH_MAX];
- get_attrname(name, n);
+ get_attrname(name, n, PATH_MAX);
int r = do_setxattr(fn, n, value, size);
dout(10) << "collection_setattr " << fn << " '" << name << "' len " << size << " = " << r << dendl;
return r;
if (fake_attrs) return attrs.collection_rmattr(c, name);
char fn[PATH_MAX];
- get_cdir(c, fn);
+ get_cdir(c, fn, sizeof(fn));
dout(15) << "collection_rmattr " << fn << dendl;
char n[PATH_MAX];
- get_attrname(name, n);
+ get_attrname(name, n, PATH_MAX);
int r = do_removexattr(fn, n);
dout(10) << "collection_rmattr " << fn << " = " << r << dendl;
return r;
if (fake_attrs) return attrs.collection_setattrs(cid, aset);
char fn[PATH_MAX];
- get_cdir(cid, fn);
+ get_cdir(cid, fn, sizeof(fn));
dout(15) << "collection_setattrs " << fn << dendl;
int r = 0;
for (map<nstring,bufferptr>::iterator p = aset.begin();
p != aset.end();
++p) {
char n[PATH_MAX];
- get_attrname(p->first.c_str(), n);
+ get_attrname(p->first.c_str(), n, PATH_MAX);
r = do_setxattr(fn, n, p->second.c_str(), p->second.length());
if (r < 0) break;
}
dout(10) << "list_collections" << dendl;
char fn[PATH_MAX];
- sprintf(fn, "%s/current", basedir.c_str());
+ snprintf(fn, sizeof(fn), "%s/current", basedir.c_str());
DIR *dir = ::opendir(fn);
if (!dir)
if (fake_collections) return collections.collection_stat(c, st);
char fn[PATH_MAX];
- get_cdir(c, fn);
+ get_cdir(c, fn, sizeof(fn));
dout(15) << "collection_stat " << fn << dendl;
int r = ::stat(fn, st);
if (r < 0) r = -errno;
if (fake_collections) return collections.collection_empty(c);
char fn[PATH_MAX];
- get_cdir(c, fn);
+ get_cdir(c, fn, sizeof(fn));
dout(15) << "collection_empty " << fn << dendl;
DIR *dir = ::opendir(fn);
if (fake_collections) return collections.collection_list(c, ls);
char fn[PATH_MAX];
- get_cdir(c, fn);
+ get_cdir(c, fn, sizeof(fn));
DIR *dir = NULL;
struct dirent sde, *de;
if (fake_collections) return collections.collection_list(c, ls);
char fn[PATH_MAX];
- get_cdir(c, fn);
+ get_cdir(c, fn, sizeof(fn));
dout(10) << "collection_list " << fn << dendl;
DIR *dir = ::opendir(fn);
if (fake_collections) return collections.create_collection(c);
char fn[PATH_MAX];
- get_cdir(c, fn);
+ get_cdir(c, fn, sizeof(fn));
dout(15) << "create_collection " << fn << dendl;
int r = ::mkdir(fn, 0755);
if (r < 0) r = -errno;
if (fake_collections) return collections.destroy_collection(c);
char fn[PATH_MAX];
- get_cdir(c, fn);
+ get_cdir(c, fn, sizeof(fn));
dout(15) << "_destroy_collection " << fn << dendl;
int r = ::rmdir(fn);
//char cmd[PATH_MAX];
- //sprintf(cmd, "test -d %s && rm -r %s", fn, fn);
+ //snprintf(cmd, sizeof(cmd), "test -d %s && rm -r %s", fn, fn);
//system(cmd);
if (r < 0) r = -errno;
dout(10) << "_destroy_collection " << fn << " = " << r << dendl;
if (fake_collections) return collections.collection_add(c, o);
char cof[PATH_MAX];
- get_coname(c, o, cof);
+ get_coname(c, o, cof, sizeof(cof));
char of[PATH_MAX];
- get_coname(cid, o, of);
+ get_coname(cid, o, of, sizeof(of));
dout(15) << "collection_add " << cof << " " << of << dendl;
int r = ::link(of, cof);
if (r < 0) r = -errno;
if (fake_collections) return collections.collection_remove(c, o);
char cof[PATH_MAX];
- get_coname(c, o, cof);
+ get_coname(c, o, cof, sizeof(cof));
dout(15) << "collection_remove " << cof << dendl;
int r = ::unlink(cof);
if (r < 0) r = -errno;
bool fake_collections;
// helper fns
- void append_oname(const sobject_t &oid, char *s);
+ void append_oname(const sobject_t &oid, char *s, int len);
//void get_oname(sobject_t oid, char *s);
- void get_cdir(coll_t cid, char *s);
- void get_coname(coll_t cid, const sobject_t& oid, char *s);
+ void get_cdir(coll_t cid, char *s, int len);
+ void get_coname(coll_t cid, const sobject_t& oid, char *s, int len);
bool parse_object(char *s, sobject_t& o);
bool parse_coll(char *s, coll_t& c);
{
generic_dout(1) << "save_freelist " << el << dendl;
char s[100];
- sprintf(s, "ebofs.freelist.%d", el);
+ snprintf(s, sizeof(s), "ebofs.freelist.%d", el);
bufferlist bl;
((Ebofs*)store)->_export_freelist(bl);
::unlink(s);
// log
static LogType osd_logtype(l_osd_first, l_osd_last);
char name[80];
- sprintf(name, "osd%d", whoami);
+ snprintf(name, sizeof(name), "osd%d", whoami);
logger = new Logger(name, (LogType*)&osd_logtype);
osd_logtype.add_set(l_osd_opq, "opq");
osd_logtype.add_inc(l_osd_op, "op");
dout(20) << "added domain bucket i " << ritems[i] << " of size " << j << dendl;
char bname[10];
- sprintf(bname, "dom%d", i);
+ snprintf(bname, sizeof(bname), "dom%d", i);
crush.set_item_name(ritems[i], bname);
}
return coll_t(u.pg64, sn);
}*/
- int print(char *o) {
+ int print(char *o, int maxlen) {
if (preferred() >= 0)
- return sprintf(o, "%d.%xp%d", pool(), ps(), preferred());
+ return snprintf(o, maxlen, "%d.%xp%d", pool(), ps(), preferred());
else
- return sprintf(o, "%d.%x", pool(), ps());
+ return snprintf(o, maxlen, "%d.%x", pool(), ps());
}
bool parse(const char *s) {
int pool;
return coll_t(p, s);
}
- int print(char *o) {
+ int print(char *o, int maxlen) {
if (pgid == pg_t() && snap == 0)
- return sprintf(o, "meta");
- int len = pgid.print(o);
+ return snprintf(o, maxlen, "meta");
+ int len = pgid.print(o, maxlen);
if (snap != CEPH_NOSNAP)
- len += sprintf(o+len, "_%llx", (long long unsigned)snap);
+ len += snprintf(o + len, maxlen - len, "_%llx", (long long unsigned)snap);
else {
- strcat(o+len, "_head");
+ strncat(o + len, "_head", maxlen - len);
len += 5;
}
return len;
for (int f = 0; f < 50000; f++) { // files
for (int b = 0; b < 4; b++) { // blocks
char foo[20];
- sprintf(foo, "%d.%d", f, b);
+ snprintf(foo, sizeof(foo), "%d.%d", f, b);
object_t oid(foo);
ceph_object_layout l = osdmap.make_object_layout(oid, 0);
//osdmap.file_to_object_layout(oid, g_default_file_layout);