Skip to content

Commit d1aec14

Browse files
committed
Updating return/variable types
After running Clang’s analyzer on it there were quite a few places where there were mis-matched store sizes and signs. I updated them so that the underlying code more closely-matches the OS APIs and the type change happens at the FUSE connection. In this way, if FUSE ever updates the API to actually match the APIs of modern OSes, it’s a fix in one place. Also, I updated read/write to return the total read/write value the OS returned rather than blindly return the request count.
1 parent 39b7772 commit d1aec14

22 files changed

+151
-146
lines changed

src/fs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ namespace fs
151151
return -1;
152152

153153
dev = st.st_dev;
154-
for(int i = 0, ei = srcmounts.size(); i != ei; i++)
154+
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
155155
{
156156
fs::path::make(&srcmounts[i],fusepath,fullpath);
157157

@@ -241,7 +241,7 @@ namespace fs
241241
if(spaceavail <= mfs)
242242
continue;
243243

244-
mfs = spaceavail;
244+
mfs = (fsblkcnt_t)spaceavail;
245245
mfsbasepath = &basepaths[i];
246246
}
247247

src/fs_acl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace fs
3030
bool
3131
dir_has_defaults(const std::string &fullpath)
3232
{
33-
int rv;
33+
ssize_t rv;
3434
std::string dirpath = fullpath;
3535

3636
fs::path::dirname(dirpath);

src/fs_base_getxattr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace fs
2828
{
2929
static
3030
inline
31-
int
31+
ssize_t
3232
lgetxattr(const std::string &path,
3333
const char *attrname,
3434
void *value,

src/fs_base_ioctl.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ namespace fs
2626
static
2727
inline
2828
int
29-
ioctl(const int fd,
30-
const int request,
31-
void *data)
29+
ioctl(const int fd,
30+
const unsigned long request,
31+
void *data)
3232
{
3333
return ::ioctl(fd,request,data);
3434
}

src/fs_base_listxattr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace fs
2828
{
2929
static
3030
inline
31-
int
31+
ssize_t
3232
llistxattr(const std::string &path,
3333
char *list,
3434
const size_t size)

src/fs_base_readlink.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace fs
2727
{
2828
static
2929
inline
30-
int
30+
ssize_t
3131
readlink(const std::string &path,
3232
char *buf,
3333
const size_t bufsiz)

src/fs_clonefile.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848
using std::string;
4949
using std::vector;
5050

51-
int
51+
ssize_t
5252
writen(const int fd,
5353
const char *buf,
5454
const size_t count)
5555
{
5656
size_t nleft;
57-
ssize_t nwritten;
57+
ssize_t nwritten = 0;
5858

5959
nleft = count;
6060
while(nleft > 0)
@@ -67,24 +67,24 @@ writen(const int fd,
6767
return -1;
6868
}
6969

70-
nleft -= nwritten;
71-
buf += nwritten;
70+
nleft -= (size_t)nwritten;
71+
buf += (size_t)nwritten;
7272
}
7373

74-
return count;
74+
return nwritten;
7575
}
7676

7777
static
78-
int
78+
ssize_t
7979
copyfile_rw(const int fdin,
8080
const int fdout,
8181
const size_t count,
8282
const size_t blocksize)
8383
{
8484
ssize_t nr;
8585
ssize_t nw;
86-
ssize_t bufsize;
87-
size_t totalwritten;
86+
size_t bufsize;
87+
ssize_t totalwritten;
8888
vector<char> buf;
8989

9090
bufsize = (blocksize * 16);
@@ -93,7 +93,7 @@ copyfile_rw(const int fdin,
9393
fs::lseek(fdin,0,SEEK_SET);
9494

9595
totalwritten = 0;
96-
while(totalwritten < count)
96+
while(totalwritten < (ssize_t)count)
9797
{
9898
nr = fs::read(fdin,&buf[0],bufsize);
9999
if(nr == -1)
@@ -103,29 +103,30 @@ copyfile_rw(const int fdin,
103103
return -1;
104104
}
105105

106-
nw = writen(fdout,&buf[0],nr);
106+
nw = writen(fdout,&buf[0],(size_t)nr);
107107
if(nw == -1)
108108
return -1;
109109

110110
totalwritten += nw;
111111
}
112112

113-
return count;
113+
return totalwritten;
114114
}
115115

116116
static
117-
int
117+
ssize_t
118118
copydata(const int fdin,
119119
const int fdout,
120120
const size_t count,
121121
const size_t blocksize)
122122
{
123-
int rv;
123+
ssize_t rv;
124+
off_t scount = (off_t)count;
125+
126+
fs::fadvise(fdin,0,scount,POSIX_FADV_WILLNEED);
127+
fs::fadvise(fdin,0,scount,POSIX_FADV_SEQUENTIAL);
124128

125-
fs::fadvise(fdin,0,count,POSIX_FADV_WILLNEED);
126-
fs::fadvise(fdin,0,count,POSIX_FADV_SEQUENTIAL);
127-
128-
fs::fallocate(fdout,0,0,count);
129+
fs::fallocate(fdout,0,0,scount);
129130

130131
rv = fs::sendfile(fdin,fdout,count);
131132
if((rv == -1) && ((errno == EINVAL) || (errno == ENOSYS)))
@@ -153,18 +154,18 @@ ignorable_error(const int err)
153154

154155
namespace fs
155156
{
156-
int
157+
ssize_t
157158
clonefile(const int fdin,
158159
const int fdout)
159160
{
160-
int rv;
161+
ssize_t rv;
161162
struct stat stin;
162163

163164
rv = fs::fstat(fdin,stin);
164165
if(rv == -1)
165166
return -1;
166167

167-
rv = ::copydata(fdin,fdout,stin.st_size,stin.st_blksize);
168+
rv = ::copydata(fdin,fdout,(size_t)stin.st_size,(size_t)stin.st_blksize);
168169
if(rv == -1)
169170
return -1;
170171

@@ -191,11 +192,11 @@ namespace fs
191192
return 0;
192193
}
193194

194-
int
195+
ssize_t
195196
clonefile(const string &in,
196197
const string &out)
197198
{
198-
int rv;
199+
ssize_t rv;
199200
int fdin;
200201
int fdout;
201202
int error;

src/fs_inode.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ namespace fs
3434
void
3535
recompute(struct stat &st)
3636
{
37-
uint64_t st_dev = st.st_dev; /* Mac OS has a 32-bit device ID */
37+
/*
38+
Some OSes have 32-bit device IDs, so box this up first.
39+
This does also presume a 64-bit inode value.
40+
*/
41+
uint64_t st_dev = (uint64_t)st.st_dev;
3842
st.st_ino |= (st_dev << 32);
3943
}
4044
}

src/fs_movefile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace fs
6666
return -1;
6767

6868
fdin_st.st_size += additional_size;
69-
rv = fs::mfs(basepaths,fdin_st.st_size,fdout_path);
69+
rv = fs::mfs(basepaths,(uint64_t)fdin_st.st_size,fdout_path);
7070
if(rv == -1)
7171
return -1;
7272

0 commit comments

Comments
 (0)