Changeset c213219 in rtems


Ignore:
Timestamp:
08/05/03 14:08:04 (21 years ago)
Author:
Jennifer Averett <Jennifer.Averett@…>
Children:
b008fdc
Parents:
d5fa273e
Message:

2003-08-04 Thomas Doerfler <Thomas.Doerfler@…>

PR 441/filesystem
*src/dosfs/msdos.h: add rename support to DOSFS
*src/dosfs/msdos_create.c: add rename support to DOSFS
*src/dosfs/msdos_file.c: add rename support to DOSFS
*src/dosfs/msdos_init.c: add rename support to DOSFS
*src/dosfs/msdos_mknod.c: add rename support to DOSFS

Location:
cpukit/libfs/src/dosfs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libfs/src/dosfs/msdos.h

    rd5fa273e rc213219  
    7878#define MSDOS_DIRECTORY     RTEMS_FILESYSTEM_DIRECTORY
    7979#define MSDOS_REGULAR_FILE  RTEMS_FILESYSTEM_MEMORY_FILE
     80#define MSDOS_HARD_LINK     RTEMS_FILESYSTEM_HARD_LINK /* pseudo type */
    8081   
    8182typedef rtems_filesystem_node_types_t msdos_node_type_t;
     
    302303 
    303304int
     305msdos_file_link(rtems_filesystem_location_info_t *to_loc,
     306                rtems_filesystem_location_info_t *pa_loc,
     307                const char                       *token);
     308
     309int
    304310msdos_dir_open(
    305311  rtems_libio_t *iop,             /* IN  */
     
    342348                 msdos_node_type_t                  type,
    343349                 char                              *name,
    344                  mode_t                             mode);
     350                 mode_t                             mode,
     351                 const fat_file_fd_t               *link_fd);
    345352
    346353/* Misc prototypes */
  • cpukit/libfs/src/dosfs/msdos_create.c

    rd5fa273e rc213219  
    4141 *     name       - new node name
    4242 *     mode       - mode
     43 *     link_info  - fs_info of existing node for a pseudo "hard-link"
     44 *                  (see msdos_file.c, msdos_link for documentation)
    4345 *
    4446 * RETURNS:
     
    5153    msdos_node_type_t                  type,
    5254    char                              *name,
    53     mode_t                             mode
     55    mode_t                             mode,
     56    const fat_file_fd_t               *link_fd
    5457    )
    5558{
     
    6366    unsigned16       date = 0;
    6467    fat_auxiliary_t  aux;
    65     unsigned char    new_node[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE];
     68    unsigned char    new_node  [MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE];
    6669    unsigned char    dot_dotdot[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE * 2];
     70    unsigned char    link_node [MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE];
     71    unsigned32       sec = 0;
     72    unsigned32       byte = 0;
    6773   
    6874    memset(new_node, 0, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE);
     
    8793    *MSDOS_DIR_FILE_SIZE(new_node) = MSDOS_INIT_DIR_SIZE;
    8894
    89     if (type == MSDOS_DIRECTORY)
     95    if (type == MSDOS_DIRECTORY) {
    9096        *MSDOS_DIR_ATTR(new_node) |= MSDOS_ATTR_DIRECTORY;
    91     else
     97    }
     98    else if (type == MSDOS_HARD_LINK) {
     99      /*
     100       * when we establish a (temporary) hard link,
     101       * we must copy some information from the original
     102       * node to the newly created
     103       */     
     104      /*
     105       * read the original directory entry
     106       */
     107      sec = fat_cluster_num_to_sector_num(parent_loc->mt_entry,
     108                                          link_fd->info_cln);
     109      sec += (link_fd->info_ofs >> fs_info->fat.vol.sec_log2);
     110      byte = (link_fd->info_ofs & (fs_info->fat.vol.bps - 1));
     111         
     112      ret = _fat_block_read(parent_loc->mt_entry,
     113                            sec, byte, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE,
     114                            link_node);
     115      if (ret < 0) {
     116        return -1;
     117      }
     118      /*
     119       * copy various attributes
     120       */
     121      *MSDOS_DIR_ATTR(new_node)          =*MSDOS_DIR_ATTR(link_node);
     122      *MSDOS_DIR_CRT_TIME_TENTH(new_node)=*MSDOS_DIR_CRT_TIME_TENTH(link_node);
     123      *MSDOS_DIR_CRT_TIME(new_node)      =*MSDOS_DIR_CRT_TIME(link_node);
     124      *MSDOS_DIR_CRT_DATE(new_node)      =*MSDOS_DIR_CRT_DATE(link_node);
     125
     126      /*
     127       * copy/set "file size", "first cluster"
     128       */
     129      *MSDOS_DIR_FILE_SIZE(new_node)     =*MSDOS_DIR_FILE_SIZE(link_node);
     130
     131      *MSDOS_DIR_FIRST_CLUSTER_LOW(new_node) =
     132        *MSDOS_DIR_FIRST_CLUSTER_LOW(link_node);
     133      *MSDOS_DIR_FIRST_CLUSTER_HI(new_node) =
     134        *MSDOS_DIR_FIRST_CLUSTER_HI(link_node);
     135      /*
     136       * set "archive bit" due to changes
     137       */
     138      *MSDOS_DIR_ATTR(new_node) |= MSDOS_ATTR_ARCHIVE;
     139      /*
     140       * set "last access" date to today
     141       */
     142      *MSDOS_DIR_LAST_ACCESS_DATE(new_node) = CT_LE_W(date);
     143    }
     144    else { /* regular file... */
    92145        *MSDOS_DIR_ATTR(new_node) |= MSDOS_ATTR_ARCHIVE;
     146    }
    93147
    94148    /*
     
    205259    return rc;
    206260}
     261
     262/* msdos_file_link --
     263 *     Replacement for a file "link" operation.
     264 *     MSDOS FAT FS does not support links, but this call is needed to
     265 *     allow "rename" operations. The current NEWLIB rename performs a link
     266 *     from the old to the new name and then deletes the old filename.
     267 *
     268 *     This pseudo-"link" operation will create a new directory entry,
     269 *     copy the file size and cluster information from the "old"
     270 *     to the "new" directory entry and then clear the file size and cluster
     271 *     info from the "old" filename, leaving this file as
     272 *     a valid, but empty entry.
     273 *
     274 *     When this "link" call is part of a "rename" sequence, the "old"
     275 *     entry will be deleted in a subsequent "rmnod" call
     276 *
     277 *     This function has been implemented by Thomas Doerfler,
     278 *     <Thomas.Doerfler@imd-systems.de>
     279 *
     280 * PARAMETERS:
     281 *     to_loc     - node description for "existing" node
     282 *     par_loc    - node description for "new" node
     283 *     token      - name of new node
     284 *
     285 * RETURNS:
     286 *     RC_OK on success, or -1 if error occured (errno set appropriately)
     287 */
     288int
     289msdos_file_link(rtems_filesystem_location_info_t *to_loc,
     290                rtems_filesystem_location_info_t *par_loc,
     291                const char                       *token
     292)
     293{
     294    int                rc = RC_OK;
     295    rtems_status_code  sc = RTEMS_SUCCESSFUL;
     296    msdos_fs_info_t   *fs_info     = to_loc->mt_entry->fs_info;
     297    fat_file_fd_t     *to_fat_fd   = to_loc->node_access;
     298    fat_file_fd_t     *par_fat_fd  = par_loc->node_access;
     299    char                 new_name[ MSDOS_NAME_MAX + 1 ];
     300    int                  len;
     301
     302    /*
     303     * check spelling and format new node name
     304     */
     305    if (MSDOS_NAME != msdos_get_token(token, new_name, &len)) {
     306      set_errno_and_return_minus_one(ENAMETOOLONG);     
     307    }
     308    /*
     309     * verify, that the existing node can be linked to
     310     * check that nodes are in same FS/volume?
     311     */
     312    if (to_loc->mt_entry->fs_info != par_loc->mt_entry->fs_info) {
     313      set_errno_and_return_minus_one(EXDEV);
     314    }
     315    /*
     316     * lock volume
     317     */
     318    sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
     319                                MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
     320    if (sc != RTEMS_SUCCESSFUL)
     321        set_errno_and_return_minus_one(EIO);
     322
     323
     324    /*
     325     * create new directory entry as "hard link",
     326     * copying relevant info from existing file
     327     */
     328    rc = msdos_creat_node(par_loc,MSDOS_HARD_LINK,new_name,S_IFREG,
     329                          to_loc->node_access);
     330    /*
     331     * set file size and first cluster number of old entry to 0
     332     */
     333    if (rc == RC_OK) {
     334      to_fat_fd->fat_file_size = 0;
     335      to_fat_fd->cln           = FAT_EOF;
     336      rc = msdos_set_first_cluster_num(to_loc->mt_entry, to_fat_fd);
     337      if (rc == RC_OK) {
     338        rc = msdos_set_file_size(par_loc->mt_entry, to_fat_fd);
     339      }
     340    }
     341    /*
     342     * FIXME: check error/abort handling
     343     */
     344    rtems_semaphore_release(fs_info->vol_sema);
     345    return rc;
     346}
     347
  • cpukit/libfs/src/dosfs/msdos_init.c

    rd5fa273e rc213219  
    2222    msdos_eval_path,
    2323    msdos_eval4make,
    24     NULL,                 /* msdos_link */
     24#if 0
     25     NULL,                 /* msdos_link */
     26#else
     27    msdos_file_link,      /* msdos_link (pseudo-functionality) */
     28#endif
    2529    msdos_file_rmnod,   
    2630    msdos_node_type,
  • cpukit/libfs/src/dosfs/msdos_mknod.c

    rd5fa273e rc213219  
    8484
    8585    /* Create an MSDOS node */
    86     rc = msdos_creat_node(pathloc, type, new_name, mode);
     86    rc = msdos_creat_node(pathloc, type, new_name, mode, NULL);
    8787
    8888    rtems_semaphore_release(fs_info->vol_sema);
Note: See TracChangeset for help on using the changeset viewer.