1*502e0f15Sguenther /* $OpenBSD: direntry.h,v 1.3 2023/08/11 04:51:36 guenther Exp $ */ 272290da1Snatano /* $NetBSD: direntry.h,v 1.13 1997/10/17 11:23:45 ws Exp $ */ 372290da1Snatano 472290da1Snatano /*- 572290da1Snatano * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. 672290da1Snatano * Copyright (C) 1994, 1995, 1997 TooLs GmbH. 772290da1Snatano * All rights reserved. 872290da1Snatano * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). 972290da1Snatano * 1072290da1Snatano * Redistribution and use in source and binary forms, with or without 1172290da1Snatano * modification, are permitted provided that the following conditions 1272290da1Snatano * are met: 1372290da1Snatano * 1. Redistributions of source code must retain the above copyright 1472290da1Snatano * notice, this list of conditions and the following disclaimer. 1572290da1Snatano * 2. Redistributions in binary form must reproduce the above copyright 1672290da1Snatano * notice, this list of conditions and the following disclaimer in the 1772290da1Snatano * documentation and/or other materials provided with the distribution. 1872290da1Snatano * 3. All advertising materials mentioning features or use of this software 1972290da1Snatano * must display the following acknowledgement: 2072290da1Snatano * This product includes software developed by TooLs GmbH. 2172290da1Snatano * 4. The name of TooLs GmbH may not be used to endorse or promote products 2272290da1Snatano * derived from this software without specific prior written permission. 2372290da1Snatano * 2472290da1Snatano * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 2572290da1Snatano * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2672290da1Snatano * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2772290da1Snatano * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2872290da1Snatano * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2972290da1Snatano * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 3072290da1Snatano * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 3172290da1Snatano * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 3272290da1Snatano * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 3372290da1Snatano * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3472290da1Snatano */ 3572290da1Snatano /* 3672290da1Snatano * Written by Paul Popelka (paulp@uts.amdahl.com) 3772290da1Snatano * 3872290da1Snatano * You can do anything you want with this software, just don't say you wrote 3972290da1Snatano * it, and don't remove this notice. 4072290da1Snatano * 4172290da1Snatano * This software is provided "as is". 4272290da1Snatano * 4372290da1Snatano * The author supplies this software to be publicly redistributed on the 4472290da1Snatano * understanding that the author is not responsible for the correct 4572290da1Snatano * functioning of this software in any circumstances and is not liable for 4672290da1Snatano * any damages caused by this software. 4772290da1Snatano * 4872290da1Snatano * October 1992 4972290da1Snatano */ 5072290da1Snatano 5172290da1Snatano /* 5272290da1Snatano * Structure of a dos directory entry. 5372290da1Snatano */ 5472290da1Snatano struct direntry { 5572290da1Snatano u_int8_t deName[8]; /* filename, blank filled */ 5672290da1Snatano #define SLOT_EMPTY 0x00 /* slot has never been used */ 5772290da1Snatano #define SLOT_E5 0x05 /* the real value is 0xe5 */ 5872290da1Snatano #define SLOT_DELETED 0xe5 /* file in this slot deleted */ 5972290da1Snatano u_int8_t deExtension[3]; /* extension, blank filled */ 6072290da1Snatano u_int8_t deAttributes; /* file attributes */ 6172290da1Snatano #define ATTR_NORMAL 0x00 /* normal file */ 6272290da1Snatano #define ATTR_READONLY 0x01 /* file is readonly */ 6372290da1Snatano #define ATTR_HIDDEN 0x02 /* file is hidden */ 6472290da1Snatano #define ATTR_SYSTEM 0x04 /* file is a system file */ 6572290da1Snatano #define ATTR_VOLUME 0x08 /* entry is a volume label */ 6672290da1Snatano #define ATTR_DIRECTORY 0x10 /* entry is a directory name */ 6772290da1Snatano #define ATTR_ARCHIVE 0x20 /* file is new or modified */ 6872290da1Snatano u_int8_t deLowerCase; /* case for base and extension */ 6972290da1Snatano #define CASE_LOWER_BASE 0x08 /* base is lower case */ 7072290da1Snatano #define CASE_LOWER_EXT 0x10 /* extension is lower case */ 7172290da1Snatano u_int8_t deCTimeHundredth; /* create time, 1/100th of a sec */ 7272290da1Snatano u_int8_t deCTime[2]; /* create time */ 7372290da1Snatano u_int8_t deCDate[2]; /* create date */ 7472290da1Snatano u_int8_t deADate[2]; /* access date */ 7572290da1Snatano u_int8_t deHighClust[2]; /* high byte of cluster number */ 7672290da1Snatano u_int8_t deMTime[2]; /* last update time */ 7772290da1Snatano u_int8_t deMDate[2]; /* last update date */ 7872290da1Snatano u_int8_t deStartCluster[2]; /* starting cluster of file */ 7972290da1Snatano u_int8_t deFileSize[4]; /* size of file in bytes */ 8072290da1Snatano }; 8172290da1Snatano 8272290da1Snatano /* 8372290da1Snatano * Structure of a Win95 long name directory entry 8472290da1Snatano */ 8572290da1Snatano struct winentry { 8672290da1Snatano u_int8_t weCnt; 8772290da1Snatano #define WIN_LAST 0x40 8872290da1Snatano #define WIN_CNT 0x3f 8972290da1Snatano u_int8_t wePart1[10]; 9072290da1Snatano u_int8_t weAttributes; 9172290da1Snatano #define ATTR_WIN95 0x0f 9272290da1Snatano u_int8_t weReserved1; 9372290da1Snatano u_int8_t weChksum; 9472290da1Snatano u_int8_t wePart2[12]; 9572290da1Snatano u_int16_t weReserved2; 9672290da1Snatano u_int8_t wePart3[4]; 9772290da1Snatano }; 9872290da1Snatano #define WIN_CHARS 13 /* Number of chars per winentry */ 9972290da1Snatano 10072290da1Snatano /* 10172290da1Snatano * This is the format of the contents of the deTime field in the direntry 10272290da1Snatano * structure. 10372290da1Snatano * We don't use bitfields because we don't know how compilers for 10472290da1Snatano * arbitrary machines will lay them out. 10572290da1Snatano */ 10672290da1Snatano #define DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */ 10772290da1Snatano #define DT_2SECONDS_SHIFT 0 10872290da1Snatano #define DT_MINUTES_MASK 0x7E0 /* minutes */ 10972290da1Snatano #define DT_MINUTES_SHIFT 5 11072290da1Snatano #define DT_HOURS_MASK 0xF800 /* hours */ 11172290da1Snatano #define DT_HOURS_SHIFT 11 11272290da1Snatano 11372290da1Snatano /* 11472290da1Snatano * This is the format of the contents of the deDate field in the direntry 11572290da1Snatano * structure. 11672290da1Snatano */ 11772290da1Snatano #define DD_DAY_MASK 0x1F /* day of month */ 11872290da1Snatano #define DD_DAY_SHIFT 0 11972290da1Snatano #define DD_MONTH_MASK 0x1E0 /* month */ 12072290da1Snatano #define DD_MONTH_SHIFT 5 12172290da1Snatano #define DD_YEAR_MASK 0xFE00 /* year - 1980 */ 12272290da1Snatano #define DD_YEAR_SHIFT 9 12372290da1Snatano 124*502e0f15Sguenther void unix2dostime(const struct timespec *tsp, int minuteswest, 125*502e0f15Sguenther u_int16_t *ddp, u_int16_t *dtp, u_int8_t *dhp); 126d51bca00Sjsg int unix2dosfn(u_char *un, u_char dn[11], int unlen, u_int gen); 12772290da1Snatano int unix2winfn(u_char *un, int unlen, struct winentry *wep, int cnt, 12872290da1Snatano int chksum); 12972290da1Snatano int winChkName(u_char *un, int unlen, struct winentry *wep, int chksum); 13072290da1Snatano u_int8_t winChksum(u_int8_t *name); 13172290da1Snatano int winSlotCnt(u_char *un, int unlen); 132