* fs/fat/fs_fat32attrib.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#include <errno.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/fat.h>
#include "inode/inode.h"
#include "fs_fat32.h"
* Private Functions
****************************************************************************/
* Name: fat_attrib
****************************************************************************/
static int fat_attrib(const char *path, fat_attrib_t *retattrib,
fat_attrib_t setbits, fat_attrib_t clearbits)
{
FAR struct fat_mountpt_s *fs;
struct fat_dirinfo_s dirinfo;
struct inode_search_s desc;
FAR struct inode *inode;
FAR uint8_t *direntry;
uint8_t oldattributes;
uint8_t newattributes;
int ret;
SETUP_SEARCH(&desc, path, false);
ret = inode_find(&desc);
if (ret < 0)
{
goto errout;
}
inode = desc.node;
if (!INODE_IS_MOUNTPT(inode) || !inode->u.i_mops || !inode->i_private)
{
ret = -ENXIO;
goto errout_with_inode;
}
fs = inode->i_private;
ret = nxmutex_lock(&fs->fs_lock);
if (ret < 0)
{
goto errout_with_inode;
}
ret = fat_checkmount(fs);
if (ret != OK)
{
goto errout_with_lock;
}
ret = fat_finddirentry(fs, &dirinfo, desc.relpath);
if (ret != OK)
{
goto errout_with_lock;
}
if (dirinfo.fd_root)
{
ret = -EACCES;
goto errout_with_lock;
}
direntry = &fs->fs_buffer[dirinfo.fd_seq.ds_offset];
oldattributes = DIR_GETATTRIBUTES(direntry);
newattributes = oldattributes;
newattributes &= ~(clearbits & (FATATTR_READONLY | FATATTR_HIDDEN |
FATATTR_SYSTEM | FATATTR_ARCHIVE));
newattributes |= (setbits & (FATATTR_READONLY | FATATTR_HIDDEN |
FATATTR_SYSTEM | FATATTR_ARCHIVE));
if (newattributes != oldattributes)
{
DIR_PUTATTRIBUTES(direntry, newattributes);
fs->fs_dirty = true;
ret = fat_updatefsinfo(fs);
if (ret != OK)
{
goto errout_with_lock;
}
}
if (retattrib)
{
*retattrib = newattributes;
}
nxmutex_unlock(&fs->fs_lock);
inode_release(inode);
RELEASE_SEARCH(&desc);
return OK;
errout_with_lock:
nxmutex_unlock(&fs->fs_lock);
errout_with_inode:
inode_release(inode);
errout:
RELEASE_SEARCH(&desc);
return ret;
}
* Public Functions
****************************************************************************/
* Name: fat_getattrib
****************************************************************************/
int fat_getattrib(FAR const char *path, FAR fat_attrib_t *attrib)
{
return fat_attrib(path, attrib, 0, 0);
}
* Name: fat_setattrib
****************************************************************************/
int fat_setattrib(FAR const char *path, fat_attrib_t setbits,
fat_attrib_t clearbits)
{
return fat_attrib(path, NULL, setbits, clearbits);
}