Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
fd6b84fd
Commit
fd6b84fd
authored
Feb 02, 2016
by
Mike Hibler
Browse files
Untested support for Linux erase operation.
parent
9ab53c28
Changes
1
Hide whitespace changes
Inline
Side-by-side
clientside/os/imagezip/erase.c
View file @
fd6b84fd
...
...
@@ -30,9 +30,13 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdint.h>
#ifdef __FreeBSD__
#include <sys/disk.h>
#endif
#ifdef __linux__
#include <linux/fs.h>
#endif
#define SECSIZE 512
#define SECALIGN(p) (void *)(((uintptr_t)(p) + (SECSIZE-1)) & ~(SECSIZE-1))
...
...
@@ -41,34 +45,41 @@
#define ERASEMINSIZE 4096
#define ZEROSIZE (256*1024)
static
off_t
ebsize
=
-
1
;
static
off_t
erased
=
0
;
static
off_t
zeroed
=
0
;
#ifdef DIOCGDELETE
typedef
off_t
blk_t
;
int
cmd
=
DIOCGDELETE
;
#endif
#ifdef BLKDISCARD
typedef
uint64_t
blk_t
;
int
cmd
=
BLKDISCARD
;
#endif
static
blk_t
ebsize
=
-
1
;
static
int
zeroit
(
int
fd
,
off
_t
offset
,
off
_t
count
);
static
int
zeroit
(
int
fd
,
blk
_t
offset
,
blk
_t
count
);
off
_t
blk
_t
erasebsize
(
void
)
{
if
(
ebsize
<
0
)
{
#ifdef DIOCGDELETE
/* XXX this seems to be the minimum */
ebsize
=
ERASEMINSIZE
;
#else
ebsize
=
0
;
#if defined(DIOCGDELETE) || defined(BLKDISCARD)
/* XXX this seems to be the minimum for DIOCGDELETE */
/* XXX actually only needs to be 512 for BLKDISCARD */
ebsize
=
ERASEMINSIZE
;
#endif
}
return
ebsize
;
}
#ifdef
DIOCGDELETE
#if
def
ined(
DIOCGDELETE
) || defined(BLKDISCARD)
int
erasedata
(
int
fd
,
off
_t
offset
,
off
_t
ecount
,
int
zeroonfail
)
erasedata
(
int
fd
,
blk
_t
offset
,
blk
_t
ecount
,
int
zeroonfail
)
{
off
_t
args
[
2
];
off
_t
toff
,
tend
,
tcnt
;
off
_t
bsize
=
erasebsize
();
blk
_t
args
[
2
];
blk
_t
toff
,
tend
,
tcnt
;
blk
_t
bsize
=
erasebsize
();
if
(
bsize
==
0
)
{
if
(
zeroonfail
)
...
...
@@ -105,9 +116,9 @@ erasedata(int fd, off_t offset, off_t ecount, int zeroonfail)
args
[
0
]
=
toff
;
args
[
1
]
=
tcnt
;
if
(
ioctl
(
fd
,
DIOCGDELETE
,
args
)
<
0
)
{
if
(
ioctl
(
fd
,
cmd
,
args
)
<
0
)
{
fprintf
(
stderr
,
"
DIOCGDELETE
of [%lld-%lld] failed (%d)
\n
"
,
"
erase ioctl
of [%lld-%lld] failed (%d)
\n
"
,
(
long
long
)
args
[
0
],
(
long
long
)
args
[
0
]
+
args
[
1
]
-
1
,
errno
);
if
(
zeroonfail
)
...
...
@@ -132,14 +143,14 @@ erasedata(int fd, off_t offset, off_t ecount, int zeroonfail)
}
#else
int
erasedata
(
int
fd
,
off
_t
offset
,
off
_t
ecount
,
int
zeroonfail
)
erasedata
(
int
fd
,
blk
_t
offset
,
blk
_t
ecount
,
int
zeroonfail
)
{
return
-
1
;
}
#endif
static
int
zeroit
(
int
fd
,
off
_t
offset
,
off
_t
count
)
zeroit
(
int
fd
,
blk
_t
offset
,
blk
_t
count
)
{
char
*
buf
,
*
_buf
;
size_t
bsize
,
wsize
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment