Skip to content

Commit

Permalink
fs: sysfs: return EGBIG on write if offset is larger than file size
Browse files Browse the repository at this point in the history
According to the user expectations common utilities like dd or sh
redirection operator > should work correctly over binary files from
sysfs. At the moment doing excessive write can not be completed:

  write(1, "\0\0\0\0\0\0\0\0", 8)         = 4
  write(1, "\0\0\0\0", 4)                 = 0
  write(1, "\0\0\0\0", 4)                 = 0
  write(1, "\0\0\0\0", 4)                 = 0
  ...

Fix the problem by returning EFBIG described in man 2 write.

Signed-off-by: Vladimir Zapolskiy <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Vladimir Zapolskiy authored and gregkh committed Nov 7, 2014
1 parent 41fb96a commit 0936896
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fs/sysfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static ssize_t sysfs_kf_bin_write(struct kernfs_open_file *of, char *buf,

if (size) {
if (size <= pos)
return 0;
return -EFBIG;
count = min_t(ssize_t, count, size - pos);
}
if (!count)
Expand Down

0 comments on commit 0936896

Please sign in to comment.