* @brief Verify read/write area parameters and limit count size * * This function checks the validity of read/write parameters and limits the count * to a maximum value (MAX_RW_COUNT) to prevent overflow. It ensures the position * and count values are within valid ranges. * * @param[in] file Pointer to the file structure (unused in current implementation) * @param[in] ppos Pointer to the po
| 236 | * so that others won't have to do range checks all the time. |
| 237 | */ |
| 238 | ssize_t rw_verify_area(struct dfs_file *file, off_t *ppos, size_t count) |
| 239 | { |
| 240 | off_t pos; |
| 241 | ssize_t retval = -EINVAL; |
| 242 | |
| 243 | if ((size_t)count < 0) |
| 244 | return retval; |
| 245 | pos = *ppos; |
| 246 | if (pos < 0) |
| 247 | { |
| 248 | if (count >= -pos) /* both values are in 0..LLONG_MAX */ |
| 249 | return -EOVERFLOW; |
| 250 | } |
| 251 | |
| 252 | return count > MAX_RW_COUNT ? MAX_RW_COUNT : count; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * @brief Get the current file position |
no outgoing calls
no test coverage detected