Skip to content
Open
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
74 changes: 37 additions & 37 deletions libraries/Adafruit_LittleFS/src/littlefs/lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ static int lfs_dir_find(lfs_t *lfs, lfs_dir_t *dir,
}

// check that entry has not been moved
if (entry->d.type & 0x80) {
if (!lfs->moving && entry->d.type & 0x80) {
int moved = lfs_moved(lfs, &entry->d.u);
if (moved < 0 || moved) {
return (moved < 0) ? moved : LFS_ERR_NOENT;
Expand Down Expand Up @@ -1644,6 +1644,11 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file,
file->pos = file->size;
}

if (file->pos + size > LFS_FILE_MAX) {
// larger than file limit?
return LFS_ERR_FBIG;
}

if (!(file->flags & LFS_F_WRITING) && file->pos > file->size) {
// fill with zeros
lfs_off_t pos = file->pos;
Expand Down Expand Up @@ -1730,24 +1735,24 @@ lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file,
return err;
}

// update pos
// find new pos
lfs_soff_t npos = file->pos;
if (whence == LFS_SEEK_SET) {
file->pos = off;
npos = off;
} else if (whence == LFS_SEEK_CUR) {
if (off < 0 && (lfs_off_t)-off > file->pos) {
return LFS_ERR_INVAL;
}

file->pos = file->pos + off;
npos = file->pos + off;
} else if (whence == LFS_SEEK_END) {
if (off < 0 && (lfs_off_t)-off > file->size) {
return LFS_ERR_INVAL;
}
npos = file->size + off;
}

file->pos = file->size + off;
if (npos < 0 || npos > LFS_FILE_MAX) {
// file position out of range
return LFS_ERR_INVAL;
}

return file->pos;
// update pos
file->pos = npos;
return npos;
}

int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) {
Expand Down Expand Up @@ -1879,11 +1884,9 @@ int lfs_remove(lfs_t *lfs, const char *path) {
err = lfs_dir_fetch(lfs, &dir, entry.d.u.dir);
if (err) {
return err;
} /* else if (dir.d.size != sizeof(dir.d)+4) {
} else if (dir.d.size != sizeof(dir.d)+4) {
return LFS_ERR_NOTEMPTY;
} adafruit: allow to remove non-empty folder,
According to below issue, comment these 2 line won't corrupt filesystem
https://github.com/ARMmbed/littlefs/issues/43 */
}
}

// remove the entry
Expand Down Expand Up @@ -1924,7 +1927,14 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) {
// find old entry
lfs_dir_t oldcwd;
lfs_entry_t oldentry;
int err = lfs_dir_find(lfs, &oldcwd, &oldentry, &oldpath);
int err = lfs_dir_find(lfs, &oldcwd, &oldentry, &(const char *){oldpath});
if (err) {
return err;
}

// mark as moving
oldentry.d.type |= 0x80;
err = lfs_dir_update(lfs, &oldcwd, &oldentry, NULL);
if (err) {
return err;
}
Expand All @@ -1937,11 +1947,9 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) {
return err;
}

bool prevexists = (err != LFS_ERR_NOENT);
bool samepair = (lfs_paircmp(oldcwd.pair, newcwd.pair) == 0);

// must have same type
if (prevexists && preventry.d.type != oldentry.d.type) {
bool prevexists = (err != LFS_ERR_NOENT);
if (prevexists && preventry.d.type != (0x7f & oldentry.d.type)) {
return LFS_ERR_ISDIR;
}

Expand All @@ -1958,18 +1966,6 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) {
}
}

// mark as moving
oldentry.d.type |= 0x80;
err = lfs_dir_update(lfs, &oldcwd, &oldentry, NULL);
if (err) {
return err;
}

// update pair if newcwd == oldcwd
if (samepair) {
newcwd = oldcwd;
}

// move to new location
lfs_entry_t newentry = preventry;
newentry.d = oldentry.d;
Expand All @@ -1988,9 +1984,12 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) {
}
}

// update pair if newcwd == oldcwd
if (samepair) {
oldcwd = newcwd;
// fetch old pair again in case dir block changed
lfs->moving = true;
err = lfs_dir_find(lfs, &oldcwd, &oldentry, &oldpath);
lfs->moving = false;
if (err) {
return err;
}

// remove old entry
Expand Down Expand Up @@ -2089,6 +2088,7 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
lfs->files = NULL;
lfs->dirs = NULL;
lfs->deorphaned = false;
lfs->moving = false;

return 0;

Expand Down
9 changes: 8 additions & 1 deletion libraries/Adafruit_LittleFS/src/littlefs/lfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern "C"
// Software library version
// Major (top-nibble), incremented on backwards incompatible changes
// Minor (bottom-nibble), incremented on feature additions
#define LFS_VERSION 0x00010006
#define LFS_VERSION 0x00010007
#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))

Expand Down Expand Up @@ -49,6 +49,11 @@ typedef uint32_t lfs_block_t;
#define LFS_NAME_MAX 255
#endif

// Max file size in bytes
#ifndef LFS_FILE_MAX
#define LFS_FILE_MAX 2147483647
#endif

// Possible error codes, these are negative to allow
// valid positive return values
enum lfs_error {
Expand All @@ -61,6 +66,7 @@ enum lfs_error {
LFS_ERR_ISDIR = -21, // Entry is a dir
LFS_ERR_NOTEMPTY = -39, // Dir is not empty
LFS_ERR_BADF = -9, // Bad file number
LFS_ERR_FBIG = -27, // File too large
LFS_ERR_INVAL = -22, // Invalid parameter
LFS_ERR_NOSPC = -28, // No space left on device
LFS_ERR_NOMEM = -12, // No more memory available
Expand Down Expand Up @@ -280,6 +286,7 @@ typedef struct lfs {

lfs_free_t free;
bool deorphaned;
bool moving;
} lfs_t;


Expand Down
13 changes: 2 additions & 11 deletions libraries/Adafruit_LittleFS/src/littlefs/lfs_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@
#ifndef LFS_NO_ASSERT
#include <assert.h>
#endif

#if !CFG_DEBUG
#define LFS_NO_DEBUG
#define LFS_NO_WARN
#define LFS_NO_ERROR
#endif

#if !defined(LFS_NO_DEBUG) || !defined(LFS_NO_WARN) || !defined(LFS_NO_ERROR)
#include <stdio.h>
#endif
Expand Down Expand Up @@ -168,8 +161,7 @@ void lfs_crc(uint32_t *crc, const void *buffer, size_t size);
// Allocate memory, only used if buffers are not provided to littlefs
static inline void *lfs_malloc(size_t size) {
#ifndef LFS_NO_MALLOC
extern void *pvPortMalloc( size_t xWantedSize );
return pvPortMalloc(size);
return malloc(size);
#else
(void)size;
return NULL;
Expand All @@ -179,8 +171,7 @@ static inline void *lfs_malloc(size_t size) {
// Deallocate memory, only used if buffers are not provided to littlefs
static inline void lfs_free(void *p) {
#ifndef LFS_NO_MALLOC
extern void vPortFree( void *pv );
vPortFree(p);
free(p);
#else
(void)p;
#endif
Expand Down
11 changes: 11 additions & 0 deletions libraries/Bluefruit52Lib/src/BLEConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ BLEConnection::BLEConnection(uint16_t conn_hdl, ble_gap_evt_connected_t const* e
_peer_addr = evt_connected->peer_addr;
_role = evt_connected->role;

_hvn_qsize = hvn_qsize;
_hvn_sem = xSemaphoreCreateCounting(hvn_qsize, hvn_qsize);
_wrcmd_sem = xSemaphoreCreateCounting(wrcmd_qsize, wrcmd_qsize);

Expand Down Expand Up @@ -304,6 +305,16 @@ void BLEConnection::_eventHandler(ble_evt_t* evt)
switch(evt->header.evt_id)
{
case BLE_GAP_EVT_DISCONNECTED:
// Restore notification semaphore to full count
// This fixes lockup when disconnect occurs with notifications in flight
while (uxSemaphoreGetCount(_hvn_sem) < _hvn_qsize) {
xSemaphoreGive(_hvn_sem);
}
// Release indication semaphore if waiting
if (_hvc_sem) {
_hvc_received = false;
xSemaphoreGive(_hvc_sem);
}
// mark as disconnected
_connected = false;
break;
Expand Down
1 change: 1 addition & 0 deletions libraries/Bluefruit52Lib/src/BLEConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class BLEConnection
uint16_t _sup_timeout;
uint16_t _data_length;
uint8_t _phy;
uint8_t _hvn_qsize;

uint8_t _role;
uint16_t _ediv;
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "framework-arduinoadafruitnrf52",
"version": "1.10700.1",
"description": "Arduino framework for Adafruit nRF52 boards (MeshCore fork with LittleFS v1.7.2 and Bluefruit fixes)"
}