Skip to content

Commit e260ea7

Browse files
committed
add sectors.go; add fat.datetime
1 parent 950a59a commit e260ea7

File tree

4 files changed

+579
-389
lines changed

4 files changed

+579
-389
lines changed

Diff for: exported.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,7 @@ func (finfo *FileInfo) Size() int64 {
182182

183183
// ModTime returns the modification time of the file.
184184
func (finfo *FileInfo) ModTime() time.Time {
185-
// https://www.win.tue.nl/~aeb/linux/fs/fat/fat-1.html
186-
hour := int(finfo.ftime >> 11)
187-
min := int((finfo.ftime >> 5) & 0x3f)
188-
doubleSeconds := int(finfo.ftime & 0x1f)
189-
yearSince1980 := int(finfo.fdate >> 9)
190-
month := int((finfo.fdate >> 5) & 0xf)
191-
day := int(finfo.fdate & 0x1f)
192-
return time.Date(yearSince1980+1980, time.Month(month), day, hour, min, 2*doubleSeconds, 0, time.UTC)
185+
return finfo.datetime.Time()
193186
}
194187

195188
// IsDir returns true if the file is a directory.

Diff for: fat.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,11 @@ const (
108108
)
109109

110110
type FileInfo struct {
111-
fsize int64 // File Size.
112-
fdate uint16
113-
ftime uint16
114-
fattrib byte
115-
altname [sfnBufSize + 1]byte
116-
fname [lfnBufSize + 1]byte
111+
fsize int64 // File Size.
112+
datetime datetime
113+
fattrib byte
114+
altname [sfnBufSize + 1]byte
115+
fname [lfnBufSize + 1]byte
117116
}
118117

119118
type mkfsParam struct {
@@ -1447,7 +1446,7 @@ func (dp *dir) alloc(nent int) (fr fileResult) {
14471446
}
14481447
isEx := fsys.fstype == fstypeExFAT
14491448
dname := dp.dir[dirNameOff]
1450-
if (isEx && dp.dir[xdirType]&0x80 == 0) || (!isEx && (dname == mskDDEM || dname == 0)) {
1449+
if (!isEx && (dname == mskDDEM || dname == 0)) || (isEx && dp.dir[xdirType]&0x80 == 0) {
14511450
// Entry is free.
14521451
n++
14531452
if n == nent {
@@ -1975,8 +1974,8 @@ func (dp *dir) get_fileinfo(fno *FileInfo) {
19751974
}
19761975
fno.fattrib = dp.dir[dirAttrOff] & amMASK
19771976
fno.fsize = int64(binary.LittleEndian.Uint32(dp.dir[dirFileSizeOff:]))
1978-
fno.ftime = binary.LittleEndian.Uint16(dp.dir[dirModTimeOff:])
1979-
fno.fdate = binary.LittleEndian.Uint16(dp.dir[dirModTimeOff+2:])
1977+
fno.datetime.time = binary.LittleEndian.Uint16(dp.dir[dirModTimeOff:])
1978+
fno.datetime.date = binary.LittleEndian.Uint16(dp.dir[dirModTimeOff+2:])
19801979
}
19811980

19821981
func put_utf8(r rune, buf []byte) int {

0 commit comments

Comments
 (0)