Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libfatx/fatx_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ int fatx_create_dirent(struct fatx_fs *fs, char const *path, struct fatx_dir *di

/* Check basename is not too long */
path_basename = fatx_basename(path);
if (strlen(path_basename) >= FATX_MAX_FILENAME_LEN)
if (strlen(path_basename) > FATX_MAX_FILENAME_LEN)
{
free(path_basename);
fatx_error(fs, "filename is too long\n");
Expand Down
4 changes: 2 additions & 2 deletions libfatx/fatx_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,15 @@ int fatx_rename(struct fatx_fs *fs, char const *from, char const *to, bool excha

/* Check that the new filename is not too long */
to_basename = fatx_basename(to);
if (strlen(to_basename) >= FATX_MAX_FILENAME_LEN)
if (strlen(to_basename) > FATX_MAX_FILENAME_LEN)
{
fatx_error(fs, "destination name too long\n");
status = FATX_STATUS_ERROR;
goto done;
}

from_basename = fatx_basename(from);
if (strlen(from_basename) >= FATX_MAX_FILENAME_LEN)
if (strlen(from_basename) > FATX_MAX_FILENAME_LEN)
{
fatx_error(fs, "source name too long\n");
status = FATX_STATUS_ERROR;
Expand Down
26 changes: 26 additions & 0 deletions pyfatx/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,31 @@ def test_rename_no_replace_with_nonexistent_destination_works(self, path):
assert d2 == b1


@with_formatted_disk
def test_filename_max_length(self, path):
fs = Fatx(path)

# 42 characters is the longest name a FATX directory entry holds
name42 = '/' + 'a' * 38 + '.bin'
fs.write(name42, b'42')
assert fs.read(name42) == b'42'
assert [a.filename for a in fs.listdir('/')] == [name42[1:]]

renamed42 = '/' + 'b' * 38 + '.bin'
fs.rename(name42, renamed42)
assert fs.read(renamed42) == b'42'

name43 = '/' + 'c' * 39 + '.bin'
created = False
try:
fs.write(name43, b'43')
created = True
except AssertionError:
pass
assert not created

fs.unlink(renamed42)


if __name__ == '__main__':
unittest.main()
Loading